Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 1 | /* Emacs style mode select -*- C++ -*- |
| 2 | *----------------------------------------------------------------------------- |
| 3 | * |
| 4 | * |
| 5 | * PrBoom a Doom port merged with LxDoom and LSDLDoom |
| 6 | * based on BOOM, a modified and improved DOOM engine |
| 7 | * Copyright (C) 1999 by |
| 8 | * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 | * Copyright (C) 1999-2000 by |
| 10 | * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 25 | * 02111-1307, USA. |
| 26 | * |
| 27 | * DESCRIPTION: |
| 28 | * DOOM main program (D_DoomMain) and game loop (D_DoomLoop), |
| 29 | * plus functions to determine game mode (shareware, registered), |
| 30 | * parse command line parameters, configure game parameters (turbo), |
| 31 | * and call the startup functions. |
| 32 | * |
| 33 | *----------------------------------------------------------------------------- |
| 34 | */ |
| 35 | |
| 36 | |
| 37 | #include "rockmacros.h" |
| 38 | |
| 39 | #include "doomdef.h" |
| 40 | #include "doomtype.h" |
| 41 | #include "doomstat.h" |
| 42 | #include "dstrings.h" |
| 43 | #include "sounds.h" |
| 44 | #include "z_zone.h" |
| 45 | #include "w_wad.h" |
| 46 | #include "s_sound.h" |
| 47 | #include "v_video.h" |
| 48 | #include "f_finale.h" |
| 49 | #include "f_wipe.h" |
| 50 | #include "m_argv.h" |
| 51 | #include "m_misc.h" |
| 52 | #include "m_menu.h" |
| 53 | #include "i_system.h" |
| 54 | #include "i_sound.h" |
| 55 | #include "i_video.h" |
| 56 | #include "g_game.h" |
| 57 | #include "hu_stuff.h" |
| 58 | #include "wi_stuff.h" |
| 59 | #include "st_stuff.h" |
| 60 | #include "am_map.h" |
| 61 | #include "p_setup.h" |
| 62 | #include "r_draw.h" |
| 63 | #include "r_main.h" |
| 64 | #include "d_main.h" |
Karl Kurbjun | 7e6f74e | 2006-12-13 04:44:17 +0000 | [diff] [blame] | 65 | #include "d_deh.h" // Ty 04/08/98 - Externalizations |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 66 | #include "m_swap.h" |
| 67 | |
Karl Kurbjun | 7e6f74e | 2006-12-13 04:44:17 +0000 | [diff] [blame] | 68 | // DEHacked support - Ty 03/09/97 // CPhipps - const char*'s |
| 69 | void ProcessDehFile(const char *filename, const char *outfilename, int lumpnum); |
| 70 | |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 71 | // CPhipps - removed wadfiles[] stuff |
| 72 | |
| 73 | boolean devparm; // started game with -devparm |
| 74 | |
| 75 | // jff 1/24/98 add new versions of these variables to remember command line |
| 76 | boolean clnomonsters; // checkparm of -nomonsters |
| 77 | boolean clrespawnparm; // checkparm of -respawn |
| 78 | boolean clfastparm; // checkparm of -fast |
| 79 | // jff 1/24/98 end definition of command line version of play mode switches |
| 80 | |
| 81 | boolean nomonsters; // working -nomonsters |
| 82 | boolean respawnparm; // working -respawn |
| 83 | boolean fastparm; // working -fast |
Karl Kurbjun | aec5814 | 2007-06-03 22:03:36 +0000 | [diff] [blame] | 84 | boolean dehout=true; |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 85 | |
| 86 | boolean singletics = false; // debug flag to cancel adaptiveness |
| 87 | |
Karl Kurbjun | 4e2a74c | 2006-04-15 22:08:36 +0000 | [diff] [blame] | 88 | bool doomexit; |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 89 | |
| 90 | //jff 1/22/98 parms for disabling music and sound |
Karl Kurbjun | 4e2a74c | 2006-04-15 22:08:36 +0000 | [diff] [blame] | 91 | boolean nomusicparm=0; |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 92 | |
| 93 | //jff 4/18/98 |
| 94 | extern boolean inhelpscreens; |
| 95 | |
| 96 | skill_t startskill; |
| 97 | int startepisode; |
| 98 | int startmap; |
| 99 | boolean autostart; |
| 100 | int debugfile; |
| 101 | int ffmap; |
| 102 | |
| 103 | boolean advancedemo; |
| 104 | |
| 105 | extern boolean timingdemo, singledemo, demoplayback, fastdemo; // killough |
| 106 | |
| 107 | int basetic; |
| 108 | |
| 109 | void D_DoAdvanceDemo (void); |
| 110 | |
| 111 | /* |
| 112 | * D_PostEvent - Event handling |
| 113 | * |
| 114 | * Called by I/O functions when an event is received. |
| 115 | * Try event handlers for each code area in turn. |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 116 | */ |
| 117 | |
| 118 | void D_PostEvent(event_t *ev) |
| 119 | { |
| 120 | /* cph - suppress all input events at game start |
| 121 | * FIXME: This is a lousy kludge */ |
Daniel Stenberg | 871be00 | 2006-08-16 13:31:40 +0000 | [diff] [blame] | 122 | if (gametic < 3) |
| 123 | return; |
| 124 | |
| 125 | if(!M_Responder(ev)) { |
| 126 | if(gamestate == GS_LEVEL && ( |
| 127 | HU_Responder(ev) || |
| 128 | ST_Responder(ev) || |
| 129 | AM_Responder(ev) |
| 130 | )) |
| 131 | return; |
| 132 | else |
| 133 | G_Responder(ev); |
| 134 | } |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // |
| 138 | // D_Wipe |
| 139 | // |
| 140 | // CPhipps - moved the screen wipe code from D_Display to here |
| 141 | // The screens to wipe between are already stored, this just does the timing |
| 142 | // and screen updating |
| 143 | |
| 144 | static void D_Wipe(void) |
| 145 | { |
| 146 | boolean done; |
| 147 | int wipestart = I_GetTime () - 1; |
| 148 | |
| 149 | do |
| 150 | { |
| 151 | int nowtime, tics; |
| 152 | do |
| 153 | { |
| 154 | //I_uSleep(5000); // CPhipps - don't thrash cpu in this loop |
| 155 | nowtime = I_GetTime(); |
| 156 | tics = nowtime - wipestart; |
| 157 | } |
| 158 | while (!tics); |
| 159 | wipestart = nowtime; |
| 160 | |
| 161 | done = wipe_ScreenWipe(0,0,SCREENWIDTH,SCREENHEIGHT,tics); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 162 | M_Drawer(); // menu is drawn even on top of wipes |
| 163 | I_FinishUpdate(); // page flip or blit buffer |
| 164 | } |
| 165 | while (!done); |
| 166 | } |
| 167 | |
| 168 | // |
| 169 | // D_Display |
| 170 | // draw current display, possibly wiping it from the previous |
| 171 | // |
| 172 | |
| 173 | // wipegamestate can be set to -1 to force a wipe on the next draw |
| 174 | gamestate_t wipegamestate = GS_DEMOSCREEN; |
| 175 | extern boolean setsizeneeded; |
| 176 | extern int showMessages; |
| 177 | |
| 178 | void D_Display (void) |
| 179 | { |
Karl Kurbjun | 4e2a74c | 2006-04-15 22:08:36 +0000 | [diff] [blame] | 180 | static boolean isborderstate IDATA_ATTR= false; |
| 181 | static boolean borderwillneedredraw IDATA_ATTR= false; |
| 182 | static boolean inhelpscreensstate IDATA_ATTR= false; |
| 183 | static gamestate_t oldgamestate IDATA_ATTR= -1; |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 184 | boolean wipe; |
| 185 | boolean viewactive = false, isborder = false; |
| 186 | |
| 187 | if (nodrawers) // for comparative timing / profiling |
| 188 | return; |
| 189 | |
| 190 | // save the current screen if about to wipe |
| 191 | if ((wipe = gamestate != wipegamestate)) |
| 192 | wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT); |
| 193 | |
| 194 | if (gamestate != GS_LEVEL) { // Not a level |
| 195 | switch (oldgamestate) { |
Andrew Mahone | d523d19 | 2009-11-20 02:51:17 +0000 | [diff] [blame] | 196 | case (gamestate_t)-1: |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 197 | case GS_LEVEL: |
| 198 | V_SetPalette(0); // cph - use default (basic) palette |
| 199 | default: |
| 200 | break; |
| 201 | } |
| 202 | |
| 203 | switch (gamestate) { |
| 204 | case GS_INTERMISSION: |
| 205 | WI_Drawer(); |
| 206 | break; |
| 207 | case GS_FINALE: |
| 208 | F_Drawer(); |
| 209 | break; |
| 210 | case GS_DEMOSCREEN: |
| 211 | D_PageDrawer(); |
| 212 | break; |
| 213 | default: |
| 214 | break; |
| 215 | } |
| 216 | } else if (gametic != basetic) { // In a level |
| 217 | boolean redrawborderstuff; |
| 218 | |
| 219 | HU_Erase(); |
| 220 | |
| 221 | if (setsizeneeded) { // change the view size if needed |
| 222 | R_ExecuteSetViewSize(); |
| 223 | oldgamestate = -1; // force background redraw |
| 224 | } |
| 225 | |
| 226 | // Work out if the player view is visible, and if there is a border |
| 227 | viewactive = (!(automapmode & am_active) || (automapmode & am_overlay)) && !inhelpscreens; |
| 228 | isborder = viewactive ? (viewheight != SCREENHEIGHT) : (!inhelpscreens && (automapmode & am_active)); |
| 229 | |
| 230 | if (oldgamestate != GS_LEVEL) { |
| 231 | R_FillBackScreen (); // draw the pattern into the back screen |
| 232 | redrawborderstuff = isborder; |
| 233 | } else { |
| 234 | // CPhipps - |
| 235 | // If there is a border, and either there was no border last time, |
| 236 | // or the border might need refreshing, then redraw it. |
| 237 | redrawborderstuff = isborder && (!isborderstate || borderwillneedredraw); |
| 238 | // The border may need redrawing next time if the border surrounds the screen, |
| 239 | // and there is a menu being displayed |
| 240 | borderwillneedredraw = menuactive && isborder && viewactive && (viewwidth != SCREENWIDTH); |
| 241 | } |
| 242 | |
| 243 | if (redrawborderstuff) |
| 244 | R_DrawViewBorder(); |
| 245 | |
| 246 | // Now do the drawing |
| 247 | if (viewactive) |
| 248 | R_RenderPlayerView (&players[displayplayer]); |
| 249 | if (automapmode & am_active) |
| 250 | AM_Drawer(); |
| 251 | ST_Drawer((viewheight != SCREENHEIGHT) || ((automapmode & am_active) && !(automapmode & am_overlay)), redrawborderstuff); |
| 252 | R_DrawViewBorder(); |
| 253 | |
| 254 | HU_Drawer(); |
| 255 | } |
| 256 | |
| 257 | inhelpscreensstate = inhelpscreens; |
| 258 | isborderstate = isborder; |
| 259 | oldgamestate = wipegamestate = gamestate; |
| 260 | |
| 261 | // draw pause pic |
| 262 | if (paused) { |
| 263 | static int x; |
| 264 | |
| 265 | if (!x) { // Cache results of x pos calc |
| 266 | int lump = W_GetNumForName("M_PAUSE"); |
| 267 | const patch_t* p = W_CacheLumpNum(lump); |
| 268 | x = (320 - SHORT(p->width))/2; |
| 269 | W_UnlockLumpNum(lump); |
| 270 | } |
| 271 | |
| 272 | // CPhipps - updated for new patch drawing |
| 273 | V_DrawNamePatch(x, (!(automapmode & am_active) || (automapmode & am_overlay)) |
| 274 | ? 4+(viewwindowy*200/SCREENHEIGHT) : 4, // cph - Must un-stretch viewwindowy |
| 275 | 0, "M_PAUSE", CR_DEFAULT, VPT_STRETCH); |
| 276 | } |
| 277 | |
| 278 | // menus go directly to the screen |
| 279 | M_Drawer(); // menu is drawn even on top of everything |
| 280 | D_BuildNewTiccmds(); |
| 281 | |
| 282 | // normal update |
| 283 | if (!wipe) |
| 284 | I_FinishUpdate (); // page flip or blit buffer |
| 285 | else { |
| 286 | // wipe update |
| 287 | wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT); |
| 288 | D_Wipe(); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | // |
| 293 | // D_DoomLoop() |
| 294 | // |
| 295 | // Not a globally visible function, |
| 296 | // just included for source reference, |
| 297 | // called by D_DoomMain, never exits. |
| 298 | // Manages timing and IO, |
| 299 | // calls all ?_Responder, ?_Ticker, and ?_Drawer, |
| 300 | // calls I_GetTime, I_StartFrame, and I_StartTic |
| 301 | // |
| 302 | |
| 303 | extern boolean demorecording; |
| 304 | |
| 305 | static void D_DoomLoop (void) |
| 306 | { |
| 307 | basetic = gametic; |
| 308 | |
| 309 | I_SubmitSound(); |
| 310 | |
| 311 | while (!doomexit) |
| 312 | { |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 313 | // process one or more tics |
| 314 | if (singletics) |
| 315 | { |
| 316 | I_StartTic (); |
| 317 | G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]); |
| 318 | if (advancedemo) |
| 319 | D_DoAdvanceDemo (); |
| 320 | M_Ticker (); |
| 321 | G_Ticker (); |
| 322 | gametic++; |
| 323 | maketic++; |
| 324 | } |
| 325 | else |
| 326 | TryRunTics (); // will run at least one tic |
| 327 | |
| 328 | // killough 3/16/98: change consoleplayer to displayplayer |
| 329 | if (players[displayplayer].mo) // cph 2002/08/10 |
| 330 | S_UpdateSounds(players[displayplayer].mo);// move positional sounds |
| 331 | |
| 332 | // Update display, next frame, with current state. |
| 333 | D_Display(); |
| 334 | |
Karl Kurbjun | 4e2a74c | 2006-04-15 22:08:36 +0000 | [diff] [blame] | 335 | // Give the system some time |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 336 | rb->yield(); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | // |
| 341 | // DEMO LOOP |
| 342 | // |
| 343 | |
| 344 | static int demosequence; // killough 5/2/98: made static |
| 345 | static int pagetic; |
| 346 | static const char *pagename; // CPhipps - const |
| 347 | |
| 348 | // |
| 349 | // D_PageTicker |
| 350 | // Handles timing for warped projection |
| 351 | // |
| 352 | void D_PageTicker(void) |
| 353 | { |
| 354 | if (--pagetic < 0) |
| 355 | D_AdvanceDemo(); |
| 356 | } |
| 357 | |
| 358 | // |
| 359 | // D_PageDrawer |
| 360 | // |
| 361 | void D_PageDrawer(void) |
| 362 | { |
| 363 | // CPhipps - updated for new patch drawing |
| 364 | V_DrawNamePatch(0, 0, 0, pagename, CR_DEFAULT, VPT_STRETCH); |
| 365 | } |
| 366 | |
| 367 | // |
| 368 | // D_AdvanceDemo |
| 369 | // Called after each demo or intro demosequence finishes |
| 370 | // |
| 371 | void D_AdvanceDemo (void) |
| 372 | { |
| 373 | advancedemo = true; |
| 374 | } |
| 375 | |
| 376 | /* killough 11/98: functions to perform demo sequences |
| 377 | * cphipps 10/99: constness fixes |
| 378 | */ |
| 379 | |
| 380 | static void D_SetPageName(const char *name) |
| 381 | { |
| 382 | pagename = name; |
| 383 | } |
| 384 | |
| 385 | static void D_DrawTitle1(const char *name) |
| 386 | { |
| 387 | S_StartMusic(mus_intro); |
| 388 | pagetic = (TICRATE*170)/35; |
| 389 | D_SetPageName(name); |
| 390 | } |
| 391 | |
| 392 | static void D_DrawTitle2(const char *name) |
| 393 | { |
| 394 | S_StartMusic(mus_dm2ttl); |
| 395 | D_SetPageName(name); |
| 396 | } |
| 397 | |
| 398 | /* killough 11/98: tabulate demo sequences |
| 399 | */ |
| 400 | |
| 401 | static struct |
| 402 | { |
| 403 | void (*func)(const char *); |
| 404 | const char *name; |
| 405 | } const demostates[][4] = |
| 406 | { |
| 407 | { |
| 408 | {D_DrawTitle1, "TITLEPIC"}, |
| 409 | {D_DrawTitle1, "TITLEPIC"}, |
| 410 | {D_DrawTitle2, "TITLEPIC"}, |
| 411 | {D_DrawTitle1, "TITLEPIC"}, |
| 412 | }, |
| 413 | |
| 414 | { |
| 415 | {G_DeferedPlayDemo, "demo1"}, |
| 416 | {G_DeferedPlayDemo, "demo1"}, |
| 417 | {G_DeferedPlayDemo, "demo1"}, |
| 418 | {G_DeferedPlayDemo, "demo1"}, |
| 419 | }, |
| 420 | { |
| 421 | {D_SetPageName, "CREDIT"}, |
| 422 | {D_SetPageName, "CREDIT"}, |
| 423 | {D_SetPageName, "CREDIT"}, |
| 424 | {D_SetPageName, "CREDIT"}, |
| 425 | }, |
| 426 | |
| 427 | { |
| 428 | {G_DeferedPlayDemo, "demo2"}, |
| 429 | {G_DeferedPlayDemo, "demo2"}, |
| 430 | {G_DeferedPlayDemo, "demo2"}, |
| 431 | {G_DeferedPlayDemo, "demo2"}, |
| 432 | }, |
| 433 | |
| 434 | { |
| 435 | {D_SetPageName, "HELP2"}, |
| 436 | {D_SetPageName, "HELP2"}, |
| 437 | {D_SetPageName, "CREDIT"}, |
| 438 | {D_DrawTitle1, "TITLEPIC"}, |
| 439 | }, |
| 440 | |
| 441 | { |
| 442 | {G_DeferedPlayDemo, "demo3"}, |
| 443 | {G_DeferedPlayDemo, "demo3"}, |
| 444 | {G_DeferedPlayDemo, "demo3"}, |
| 445 | {G_DeferedPlayDemo, "demo3"}, |
| 446 | }, |
| 447 | |
| 448 | { |
| 449 | {NULL,0}, |
| 450 | {NULL,0}, |
| 451 | {NULL,0}, |
| 452 | {D_SetPageName, "CREDIT"}, |
| 453 | }, |
| 454 | |
| 455 | { |
| 456 | {NULL,0}, |
| 457 | {NULL,0}, |
| 458 | {NULL,0}, |
| 459 | {G_DeferedPlayDemo, "demo4"}, |
| 460 | }, |
| 461 | |
| 462 | { |
| 463 | {NULL,0}, |
| 464 | {NULL,0}, |
| 465 | {NULL,0}, |
| 466 | {NULL,0}, |
| 467 | } |
| 468 | }; |
| 469 | |
| 470 | /* |
| 471 | * This cycles through the demo sequences. |
| 472 | * killough 11/98: made table-driven |
| 473 | */ |
| 474 | |
| 475 | void D_DoAdvanceDemo(void) |
| 476 | { |
| 477 | players[consoleplayer].playerstate = PST_LIVE; /* not reborn */ |
| 478 | advancedemo = usergame = paused = false; |
| 479 | gameaction = ga_nothing; |
| 480 | |
| 481 | pagetic = TICRATE * 11; /* killough 11/98: default behavior */ |
| 482 | gamestate = GS_DEMOSCREEN; |
| 483 | |
| 484 | if (netgame && !demoplayback) { |
| 485 | demosequence = 0; |
| 486 | } else |
| 487 | if (!demostates[++demosequence][gamemode].func) |
| 488 | demosequence = 0; |
| 489 | demostates[demosequence][gamemode].func(demostates[demosequence][gamemode].name); |
| 490 | } |
| 491 | |
| 492 | // |
| 493 | // D_StartTitle |
| 494 | // |
| 495 | void D_StartTitle (void) |
| 496 | { |
| 497 | gameaction = ga_nothing; |
| 498 | demosequence = -1; |
| 499 | D_AdvanceDemo(); |
| 500 | } |
| 501 | |
| 502 | // |
| 503 | // D_AddFile |
| 504 | // |
| 505 | // Rewritten by Lee Killough |
| 506 | // |
| 507 | // Ty 08/29/98 - add source parm to indicate where this came from |
| 508 | // CPhipps - static, const char* parameter |
| 509 | // - source is an enum |
| 510 | // - modified to allocate & use new wadfiles array |
| 511 | void D_AddFile (const char *file, wad_source_t source) |
| 512 | { |
| 513 | wadfiles = realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1)); |
| 514 | wadfiles[numwadfiles].name = |
| 515 | AddDefaultExtension(strcpy(malloc(strlen(file)+5), file), ".wad"); |
| 516 | wadfiles[numwadfiles].src = source; // Ty 08/29/98 |
| 517 | numwadfiles++; |
| 518 | } |
| 519 | |
| 520 | // |
| 521 | // CheckIWAD |
| 522 | // |
| 523 | // Verify a file is indeed tagged as an IWAD |
| 524 | // Scan its lumps for levelnames and return gamemode as indicated |
| 525 | // Detect missing wolf levels in DOOM II |
| 526 | // |
| 527 | // The filename to check is passed in iwadname, the gamemode detected is |
| 528 | // returned in gmode, hassec returns the presence of secret levels |
| 529 | // |
| 530 | // jff 4/19/98 Add routine to test IWAD for validity and determine |
| 531 | // the gamemode from it. Also note if DOOM II, whether secret levels exist |
| 532 | // CPhipps - const char* for iwadname, made static |
| 533 | #if 0 |
| 534 | static void CheckIWAD(const char *iwadname,GameMode_t *gmode,boolean *hassec) |
| 535 | { |
| 536 | if ( !fileexists (iwadname) ) |
| 537 | { |
| 538 | int ud=0,rg=0,sw=0,cm=0,sc=0; |
| 539 | int handle; |
| 540 | |
| 541 | // Identify IWAD correctly |
| 542 | if ( (handle = open (iwadname,O_RDONLY)) != -1) |
| 543 | { |
| 544 | wadinfo_t header; |
| 545 | |
| 546 | // read IWAD header |
| 547 | read (handle, &header, sizeof(header)); |
| 548 | if (!strncmp(header.identification,"IWAD",4)) |
| 549 | { |
| 550 | size_t length; |
| 551 | filelump_t *fileinfo; |
| 552 | |
| 553 | // read IWAD directory |
| 554 | header.numlumps = LONG(header.numlumps); |
| 555 | header.infotableofs = LONG(header.infotableofs); |
| 556 | length = header.numlumps; |
| 557 | fileinfo = malloc(length*sizeof(filelump_t)); |
| 558 | lseek (handle, header.infotableofs, SEEK_SET); |
| 559 | read (handle, fileinfo, length*sizeof(filelump_t)); |
| 560 | close(handle); |
| 561 | |
| 562 | // scan directory for levelname lumps |
| 563 | while (length--) |
| 564 | if (fileinfo[length].name[0] == 'E' && |
| 565 | fileinfo[length].name[2] == 'M' && |
| 566 | fileinfo[length].name[4] == 0) |
| 567 | { |
| 568 | if (fileinfo[length].name[1] == '4') |
| 569 | ++ud; |
| 570 | else if (fileinfo[length].name[1] == '3') |
| 571 | ++rg; |
| 572 | else if (fileinfo[length].name[1] == '2') |
| 573 | ++rg; |
| 574 | else if (fileinfo[length].name[1] == '1') |
| 575 | ++sw; |
| 576 | } |
| 577 | else if (fileinfo[length].name[0] == 'M' && |
| 578 | fileinfo[length].name[1] == 'A' && |
| 579 | fileinfo[length].name[2] == 'P' && |
| 580 | fileinfo[length].name[5] == 0) |
| 581 | { |
| 582 | ++cm; |
| 583 | if (fileinfo[length].name[3] == '3') |
| 584 | if (fileinfo[length].name[4] == '1' || |
| 585 | fileinfo[length].name[4] == '2') |
| 586 | ++sc; |
| 587 | } |
| 588 | |
| 589 | free(fileinfo); |
| 590 | } |
| 591 | else // missing IWAD tag in header |
| 592 | I_Error("CheckIWAD: IWAD tag %s not present", iwadname); |
| 593 | } |
| 594 | else // error from open call |
| 595 | I_Error("CheckIWAD: Can't open IWAD %s", iwadname); |
| 596 | |
| 597 | // Determine game mode from levels present |
| 598 | // Must be a full set for whichever mode is present |
| 599 | // Lack of wolf-3d levels also detected here |
| 600 | |
| 601 | *gmode = indetermined; |
| 602 | *hassec = false; |
| 603 | if (cm>=30) |
| 604 | { |
| 605 | *gmode = commercial; |
| 606 | *hassec = sc>=2; |
| 607 | } |
| 608 | else if (ud>=9) |
| 609 | *gmode = retail; |
| 610 | else if (rg>=18) |
| 611 | *gmode = registered; |
| 612 | else if (sw>=9) |
| 613 | *gmode = shareware; |
| 614 | } |
| 615 | else // error from access call |
| 616 | I_Error("CheckIWAD: IWAD %s not readable", iwadname); |
| 617 | } |
| 618 | #endif |
| 619 | void D_DoomMainSetup(void) |
| 620 | { |
| 621 | int p; |
| 622 | |
| 623 | nomonsters = M_CheckParm ("-nomonsters"); |
| 624 | respawnparm = M_CheckParm ("-respawn"); |
| 625 | fastparm = M_CheckParm ("-fast"); |
| 626 | devparm = M_CheckParm ("-devparm"); |
| 627 | if (M_CheckParm ("-altdeath")) |
| 628 | deathmatch = 2; |
| 629 | else if (M_CheckParm ("-deathmatch")) |
| 630 | deathmatch = 1; |
| 631 | |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 632 | printf("Welcome to Rockdoom\n"); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 633 | |
| 634 | switch ( gamemode ) |
| 635 | { |
| 636 | case retail: |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 637 | printf ("The Ultimate DOOM Startup v%d.%d\n",DVERSION/100,DVERSION%100); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 638 | break; |
| 639 | case shareware: |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 640 | printf ("DOOM Shareware Startup v%d.%d\n",DVERSION/100,DVERSION%100); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 641 | break; |
| 642 | case registered: |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 643 | printf ("DOOM Registered Startup v%d.%d\n",DVERSION/100,DVERSION%100); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 644 | break; |
| 645 | case commercial: |
| 646 | switch (gamemission) |
| 647 | { |
| 648 | case pack_plut: |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 649 | printf ("DOOM 2: Plutonia Experiment v%d.%d\n",DVERSION/100,DVERSION%100); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 650 | break; |
| 651 | case pack_tnt: |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 652 | printf ("DOOM 2: TNT - Evilution v%d.%d\n",DVERSION/100,DVERSION%100); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 653 | break; |
| 654 | default: |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 655 | printf ("DOOM 2: Hell on Earth v%d.%d\n",DVERSION/100,DVERSION%100); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 656 | break; |
| 657 | } |
| 658 | break; |
| 659 | default: |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 660 | printf ("Public DOOM v%d.%d\n",DVERSION/100,DVERSION%100); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 661 | break; |
| 662 | } |
| 663 | |
| 664 | if (devparm) |
| 665 | printf(D_DEVSTR); |
| 666 | |
| 667 | // turbo option |
| 668 | if ((p=M_CheckParm ("-turbo"))) |
| 669 | { |
| 670 | int scale = 200; |
| 671 | extern int forwardmove[2]; |
| 672 | extern int sidemove[2]; |
| 673 | |
| 674 | if (p<myargc-1) |
| 675 | scale = atoi (myargv[p+1]); |
| 676 | if (scale < 10) |
| 677 | scale = 10; |
| 678 | if (scale > 400) |
| 679 | scale = 400; |
| 680 | printf ("turbo scale: %d%%\n",scale); |
| 681 | forwardmove[0] = forwardmove[0]*scale/100; |
| 682 | forwardmove[1] = forwardmove[1]*scale/100; |
| 683 | sidemove[0] = sidemove[0]*scale/100; |
| 684 | sidemove[1] = sidemove[1]*scale/100; |
| 685 | } |
| 686 | |
| 687 | // get skill / episode / map from parms |
| 688 | startskill = sk_medium; |
| 689 | startepisode = 1; |
| 690 | startmap = 1; |
| 691 | autostart = false; |
| 692 | |
| 693 | p = M_CheckParm ("-skill"); |
| 694 | if (p && p < myargc-1) |
| 695 | { |
| 696 | startskill = myargv[p+1][0]-'1'; |
| 697 | autostart = true; |
| 698 | } |
| 699 | |
| 700 | p = M_CheckParm ("-episode"); |
| 701 | if (p && p < myargc-1) |
| 702 | { |
| 703 | startepisode = myargv[p+1][0]-'0'; |
| 704 | startmap = 1; |
| 705 | autostart = true; |
| 706 | } |
| 707 | |
| 708 | p = M_CheckParm ("-warp"); |
| 709 | if (p && p < myargc-1) |
| 710 | { |
| 711 | if (gamemode == commercial) |
| 712 | startmap = atoi (myargv[p+1]); |
| 713 | else |
| 714 | { |
| 715 | startepisode = myargv[p+1][0]-'0'; |
| 716 | startmap = myargv[p+2][0]-'0'; |
| 717 | } |
| 718 | autostart = true; |
| 719 | } |
| 720 | |
| 721 | // CPhipps - move up netgame init |
| 722 | printf("D_InitNetGame: Checking for network game.\n"); |
| 723 | D_InitNetGame(); |
| 724 | |
| 725 | // init subsystems |
| 726 | printf ("V_Init: allocate screens.\n"); |
| 727 | V_Init (); |
| 728 | |
| 729 | printf ("W_Init: Init WADfiles.\n"); |
| 730 | W_Init(); |
| 731 | |
Karl Kurbjun | 7e6f74e | 2006-12-13 04:44:17 +0000 | [diff] [blame] | 732 | if ((p = W_CheckNumForName("DEHACKED")) != -1) // cph - add dehacked-in-a-wad support |
Karl Kurbjun | aec5814 | 2007-06-03 22:03:36 +0000 | [diff] [blame] | 733 | ProcessDehFile(NULL, dehout ? "/dehlog.txt" : NULL, p); |
Karl Kurbjun | 7e6f74e | 2006-12-13 04:44:17 +0000 | [diff] [blame] | 734 | |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 735 | V_InitColorTranslation(); //jff 4/24/98 load color translation lumps |
| 736 | |
| 737 | // Check for -file in shareware |
| 738 | if (modifiedgame) |
| 739 | { |
| 740 | // These are the lumps that will be checked in IWAD, |
| 741 | // if any one is not present, execution will be aborted. |
Thom Johansen | cf23618 | 2006-04-06 20:44:33 +0000 | [diff] [blame] | 742 | const char name[23][8]= |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 743 | { |
| 744 | "e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9", |
| 745 | "e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9", |
| 746 | "dphoof","bfgga0","heada1","cybra1","spida1d1" |
| 747 | }; |
| 748 | int i; |
| 749 | |
| 750 | if ( gamemode == shareware) |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 751 | I_Error("\nYou cannot -file with the shareware version. Register!\n"); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 752 | |
| 753 | // Check for fake IWAD with right name, |
| 754 | // but w/o all the lumps of the registered version. |
| 755 | if (gamemode == registered) |
| 756 | for (i = 0;i < 23; i++) |
| 757 | if (W_CheckNumForName(name[i])<0) |
Karl Kurbjun | 51db2d3 | 2006-04-02 01:52:44 +0000 | [diff] [blame] | 758 | I_Error("This is not the registered version.\n"); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | // Iff additonal PWAD files are used, print modified banner |
| 762 | if (modifiedgame) |
| 763 | printf ("ATTENTION: This version of DOOM has been modified.\n"); |
| 764 | |
| 765 | // Check and print which version is executed. |
| 766 | switch ( gamemode ) |
| 767 | { |
| 768 | case shareware: |
| 769 | case indetermined: |
| 770 | printf ("Shareware!\n"); |
| 771 | break; |
| 772 | case registered: |
| 773 | case retail: |
| 774 | case commercial: |
| 775 | printf ("Commercial product - do not distribute!\n"); |
| 776 | break; |
| 777 | default: |
| 778 | // Ouch. |
| 779 | break; |
| 780 | } |
| 781 | |
| 782 | printf ("M_Init: Init miscellaneous info.\n"); |
| 783 | M_Init (); |
| 784 | |
| 785 | printf ("R_Init: Init DOOM refresh daemon - "); |
| 786 | R_Init (); |
| 787 | |
| 788 | printf ("P_Init: Init Playloop state.\n"); |
| 789 | P_Init (); |
| 790 | |
| 791 | printf ("I_Init: Setting up machine state.\n"); |
| 792 | I_Init (); |
| 793 | |
| 794 | printf ("S_Init: Setting up sound.\n"); |
| 795 | S_Init (snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/ ); |
| 796 | |
| 797 | printf ("HU_Init: Setting up heads up display.\n"); |
| 798 | HU_Init (); |
| 799 | |
| 800 | I_InitGraphics (); |
| 801 | |
| 802 | printf ("ST_Init: Init status bar.\n"); |
| 803 | ST_Init (); |
| 804 | |
| 805 | // check for a driver that wants intermission stats |
| 806 | p = M_CheckParm ("-statcopy"); |
| 807 | if (p && p<myargc-1) |
| 808 | { |
| 809 | // for statistics driver |
| 810 | extern void* statcopy; |
| 811 | |
Dave Chapman | 5293ea1 | 2006-03-28 17:42:57 +0000 | [diff] [blame] | 812 | statcopy = (void*)(long)atoi(myargv[p+1]); |
Dave Chapman | 47f4a45 | 2006-03-28 15:44:01 +0000 | [diff] [blame] | 813 | printf ("External statistics registered.\n"); |
| 814 | } |
| 815 | |
| 816 | // start the apropriate game based on parms |
| 817 | p = M_CheckParm ("-record"); |
| 818 | if (p && p < myargc-1) |
| 819 | { |
| 820 | G_RecordDemo (myargv[p+1]); |
| 821 | autostart = true; |
| 822 | } |
| 823 | |
| 824 | p = M_CheckParm ("-loadgame"); |
| 825 | if (p && p < myargc-1) |
| 826 | G_LoadGame (atoi(myargv[p+1]), false); |
| 827 | |
| 828 | if ( gameaction != ga_loadgame ) |
| 829 | { |
| 830 | if (!singledemo) { /* killough 12/98 */ |
| 831 | if (autostart || netgame) |
| 832 | G_InitNew (startskill, startepisode, startmap); |
| 833 | else |
| 834 | D_StartTitle (); // start up intro loop |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | // |
| 840 | // D_DoomMain |
| 841 | // |
| 842 | void D_DoomMain (void) |
| 843 | { |
| 844 | D_DoomMainSetup(); // get this crap off the stack |
| 845 | |
| 846 | D_DoomLoop (); // never returns |
| 847 | } |