D_MAIN.C 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. // D_main.c
  2. #ifdef __WATCOMC__
  3. #include <dos.h>
  4. #include <graph.h>
  5. #include <sys\types.h>
  6. #include <direct.h>
  7. #endif
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "DoomDef.h"
  11. #include "P_local.h"
  12. #include "soundst.h"
  13. boolean shareware = false; // true if only episode 1 present
  14. boolean ExtendedWAD = false; // true if episodes 4 and 5 present
  15. boolean nomonsters; // checkparm of -nomonsters
  16. boolean respawnparm; // checkparm of -respawn
  17. boolean debugmode; // checkparm of -debug
  18. boolean ravpic; // checkparm of -ravpic
  19. boolean cdrom; // true if cd-rom mode active
  20. boolean singletics; // debug flag to cancel adaptiveness
  21. boolean noartiskip; // whether shift-enter skips an artifact
  22. skill_t startskill;
  23. int startepisode;
  24. int startmap;
  25. boolean autostart;
  26. extern boolean automapactive;
  27. boolean advancedemo;
  28. FILE *debugfile;
  29. void D_CheckNetGame(void);
  30. void D_ProcessEvents(void);
  31. void G_BuildTiccmd(ticcmd_t *cmd);
  32. void D_DoAdvanceDemo(void);
  33. void D_PageDrawer (void);
  34. void D_AdvanceDemo (void);
  35. void F_Drawer(void);
  36. boolean F_Responder(event_t *ev);
  37. //---------------------------------------------------------------------------
  38. //
  39. // FUNC FixedDiv
  40. //
  41. //---------------------------------------------------------------------------
  42. fixed_t FixedDiv(fixed_t a, fixed_t b)
  43. {
  44. if((abs(a)>>14) >= abs(b))
  45. {
  46. return((a^b)<0 ? MININT : MAXINT);
  47. }
  48. return(FixedDiv2(a, b));
  49. }
  50. /*
  51. ===============================================================================
  52. EVENT HANDLING
  53. Events are asyncronous inputs generally generated by the game user.
  54. Events can be discarded if no responder claims them
  55. ===============================================================================
  56. */
  57. event_t events[MAXEVENTS];
  58. int eventhead;
  59. int eventtail;
  60. //---------------------------------------------------------------------------
  61. //
  62. // PROC D_PostEvent
  63. //
  64. // Called by the I/O functions when input is detected.
  65. //
  66. //---------------------------------------------------------------------------
  67. void D_PostEvent(event_t *ev)
  68. {
  69. events[eventhead] = *ev;
  70. eventhead = (++eventhead)&(MAXEVENTS-1);
  71. }
  72. //---------------------------------------------------------------------------
  73. //
  74. // PROC D_ProcessEvents
  75. //
  76. // Send all the events of the given timestamp down the responder chain.
  77. //
  78. //---------------------------------------------------------------------------
  79. void D_ProcessEvents(void)
  80. {
  81. event_t *ev;
  82. for(; eventtail != eventhead; eventtail = (++eventtail)&(MAXEVENTS-1))
  83. {
  84. ev = &events[eventtail];
  85. if(F_Responder(ev))
  86. {
  87. continue;
  88. }
  89. if(MN_Responder(ev))
  90. {
  91. continue;
  92. }
  93. G_Responder(ev);
  94. }
  95. }
  96. //---------------------------------------------------------------------------
  97. //
  98. // PROC DrawMessage
  99. //
  100. //---------------------------------------------------------------------------
  101. void DrawMessage(void)
  102. {
  103. player_t *player;
  104. player = &players[consoleplayer];
  105. if(player->messageTics <= 0 || !player->message)
  106. { // No message
  107. return;
  108. }
  109. MN_DrTextA(player->message, 160-MN_TextAWidth(player->message)/2, 1);
  110. }
  111. //---------------------------------------------------------------------------
  112. //
  113. // PROC D_Display
  114. //
  115. // Draw current display, possibly wiping it from the previous.
  116. //
  117. //---------------------------------------------------------------------------
  118. void R_ExecuteSetViewSize(void);
  119. extern boolean finalestage;
  120. void D_Display(void)
  121. {
  122. extern boolean MenuActive;
  123. extern boolean askforquit;
  124. // Change the view size if needed
  125. if(setsizeneeded)
  126. {
  127. R_ExecuteSetViewSize();
  128. }
  129. //
  130. // do buffered drawing
  131. //
  132. switch (gamestate)
  133. {
  134. case GS_LEVEL:
  135. if (!gametic)
  136. break;
  137. if (automapactive)
  138. AM_Drawer ();
  139. else
  140. R_RenderPlayerView (&players[displayplayer]);
  141. CT_Drawer();
  142. UpdateState |= I_FULLVIEW;
  143. SB_Drawer();
  144. break;
  145. case GS_INTERMISSION:
  146. IN_Drawer ();
  147. break;
  148. case GS_FINALE:
  149. F_Drawer ();
  150. break;
  151. case GS_DEMOSCREEN:
  152. D_PageDrawer ();
  153. break;
  154. }
  155. if(paused && !MenuActive && !askforquit)
  156. {
  157. if(!netgame)
  158. {
  159. V_DrawPatch(160, viewwindowy+5, W_CacheLumpName("PAUSED",
  160. PU_CACHE));
  161. }
  162. else
  163. {
  164. V_DrawPatch(160, 70, W_CacheLumpName("PAUSED",
  165. PU_CACHE));
  166. }
  167. }
  168. // Handle player messages
  169. DrawMessage();
  170. // Menu drawing
  171. MN_Drawer();
  172. // Send out any new accumulation
  173. NetUpdate();
  174. // Flush buffered stuff to screen
  175. I_Update();
  176. }
  177. //---------------------------------------------------------------------------
  178. //
  179. // PROC D_DoomLoop
  180. //
  181. //---------------------------------------------------------------------------
  182. void D_DoomLoop(void)
  183. {
  184. if(M_CheckParm("-debugfile"))
  185. {
  186. char filename[20];
  187. sprintf(filename, "debug%i.txt", consoleplayer);
  188. debugfile = fopen(filename,"w");
  189. }
  190. I_InitGraphics();
  191. while(1)
  192. {
  193. // Frame syncronous IO operations
  194. I_StartFrame();
  195. // Process one or more tics
  196. if(singletics)
  197. {
  198. I_StartTic();
  199. D_ProcessEvents();
  200. G_BuildTiccmd(&netcmds[consoleplayer][maketic%BACKUPTICS]);
  201. if (advancedemo)
  202. D_DoAdvanceDemo ();
  203. G_Ticker();
  204. gametic++;
  205. maketic++;
  206. }
  207. else
  208. {
  209. // Will run at least one tic
  210. TryRunTics();
  211. }
  212. // Move positional sounds
  213. S_UpdateSounds(players[consoleplayer].mo);
  214. D_Display();
  215. }
  216. }
  217. /*
  218. ===============================================================================
  219. DEMO LOOP
  220. ===============================================================================
  221. */
  222. int demosequence;
  223. int pagetic;
  224. char *pagename;
  225. /*
  226. ================
  227. =
  228. = D_PageTicker
  229. =
  230. = Handles timing for warped projection
  231. =
  232. ================
  233. */
  234. void D_PageTicker (void)
  235. {
  236. if (--pagetic < 0)
  237. D_AdvanceDemo ();
  238. }
  239. /*
  240. ================
  241. =
  242. = D_PageDrawer
  243. =
  244. ================
  245. */
  246. extern boolean MenuActive;
  247. void D_PageDrawer(void)
  248. {
  249. V_DrawRawScreen(W_CacheLumpName(pagename, PU_CACHE));
  250. if(demosequence == 1)
  251. {
  252. V_DrawPatch(4, 160, W_CacheLumpName("ADVISOR", PU_CACHE));
  253. }
  254. UpdateState |= I_FULLSCRN;
  255. }
  256. /*
  257. =================
  258. =
  259. = D_AdvanceDemo
  260. =
  261. = Called after each demo or intro demosequence finishes
  262. =================
  263. */
  264. void D_AdvanceDemo (void)
  265. {
  266. advancedemo = true;
  267. }
  268. void D_DoAdvanceDemo (void)
  269. {
  270. players[consoleplayer].playerstate = PST_LIVE; // don't reborn
  271. advancedemo = false;
  272. usergame = false; // can't save / end game here
  273. paused = false;
  274. gameaction = ga_nothing;
  275. demosequence = (demosequence+1)%7;
  276. switch (demosequence)
  277. {
  278. case 0:
  279. pagetic = 210;
  280. gamestate = GS_DEMOSCREEN;
  281. pagename = "TITLE";
  282. S_StartSong(mus_titl, false);
  283. break;
  284. case 1:
  285. pagetic = 140;
  286. gamestate = GS_DEMOSCREEN;
  287. pagename = "TITLE";
  288. break;
  289. case 2:
  290. BorderNeedRefresh = true;
  291. UpdateState |= I_FULLSCRN;
  292. G_DeferedPlayDemo ("demo1");
  293. break;
  294. case 3:
  295. pagetic = 200;
  296. gamestate = GS_DEMOSCREEN;
  297. pagename = "CREDIT";
  298. break;
  299. case 4:
  300. BorderNeedRefresh = true;
  301. UpdateState |= I_FULLSCRN;
  302. G_DeferedPlayDemo ("demo2");
  303. break;
  304. case 5:
  305. pagetic = 200;
  306. gamestate = GS_DEMOSCREEN;
  307. if(shareware)
  308. {
  309. pagename = "ORDER";
  310. }
  311. else
  312. {
  313. pagename = "CREDIT";
  314. }
  315. break;
  316. case 6:
  317. BorderNeedRefresh = true;
  318. UpdateState |= I_FULLSCRN;
  319. G_DeferedPlayDemo ("demo3");
  320. break;
  321. }
  322. }
  323. /*
  324. =================
  325. =
  326. = D_StartTitle
  327. =
  328. =================
  329. */
  330. void D_StartTitle (void)
  331. {
  332. gameaction = ga_nothing;
  333. demosequence = -1;
  334. D_AdvanceDemo ();
  335. }
  336. /*
  337. ==============
  338. =
  339. = D_CheckRecordFrom
  340. =
  341. = -recordfrom <savegame num> <demoname>
  342. ==============
  343. */
  344. void D_CheckRecordFrom (void)
  345. {
  346. int p;
  347. char file[256];
  348. p = M_CheckParm ("-recordfrom");
  349. if (!p || p > myargc-2)
  350. return;
  351. if(cdrom)
  352. {
  353. sprintf(file, SAVEGAMENAMECD"%c.hsg",myargv[p+1][0]);
  354. }
  355. else
  356. {
  357. sprintf(file, SAVEGAMENAME"%c.hsg",myargv[p+1][0]);
  358. }
  359. G_LoadGame (file);
  360. G_DoLoadGame (); // load the gameskill etc info from savegame
  361. G_RecordDemo (gameskill, 1, gameepisode, gamemap, myargv[p+2]);
  362. D_DoomLoop (); // never returns
  363. }
  364. /*
  365. ===============
  366. =
  367. = D_AddFile
  368. =
  369. ===============
  370. */
  371. #define MAXWADFILES 20
  372. // MAPDIR should be defined as the directory that holds development maps
  373. // for the -wart # # command
  374. #ifdef __NeXT__
  375. #define MAPDIR "/Novell/Heretic/data/"
  376. #define SHAREWAREWADNAME "/Novell/Heretic/source/heretic1.wad"
  377. char *wadfiles[MAXWADFILES] =
  378. {
  379. "/Novell/Heretic/source/heretic.wad",
  380. "/Novell/Heretic/data/texture1.lmp",
  381. "/Novell/Heretic/data/texture2.lmp",
  382. "/Novell/Heretic/data/pnames.lmp"
  383. };
  384. #else
  385. #define MAPDIR "\\data\\"
  386. #define SHAREWAREWADNAME "heretic1.wad"
  387. char *wadfiles[MAXWADFILES] =
  388. {
  389. "heretic.wad",
  390. "texture1.lmp",
  391. "texture2.lmp",
  392. "pnames.lmp"
  393. };
  394. #endif
  395. char *basedefault = "heretic.cfg";
  396. char exrnwads[80];
  397. char exrnwads2[80];
  398. void wadprintf(void)
  399. {
  400. if(debugmode)
  401. {
  402. return;
  403. }
  404. #ifdef __WATCOMC__
  405. _settextposition(23, 2);
  406. _setbkcolor(1);
  407. _settextcolor(0);
  408. _outtext(exrnwads);
  409. _settextposition(24, 2);
  410. _outtext(exrnwads2);
  411. #endif
  412. }
  413. void D_AddFile(char *file)
  414. {
  415. int numwadfiles;
  416. char *new;
  417. // char text[256];
  418. for(numwadfiles = 0; wadfiles[numwadfiles]; numwadfiles++);
  419. new = malloc(strlen(file)+1);
  420. strcpy(new, file);
  421. if(strlen(exrnwads)+strlen(file) < 78)
  422. {
  423. if(strlen(exrnwads))
  424. {
  425. strcat(exrnwads, ", ");
  426. }
  427. else
  428. {
  429. strcpy(exrnwads, "External Wadfiles: ");
  430. }
  431. strcat(exrnwads, file);
  432. }
  433. else if(strlen(exrnwads2)+strlen(file) < 79)
  434. {
  435. if(strlen(exrnwads2))
  436. {
  437. strcat(exrnwads2, ", ");
  438. }
  439. else
  440. {
  441. strcpy(exrnwads2, " ");
  442. strcat(exrnwads, ",");
  443. }
  444. strcat(exrnwads2, file);
  445. }
  446. wadfiles[numwadfiles] = new;
  447. }
  448. //==========================================================
  449. //
  450. // Startup Thermo code
  451. //
  452. //==========================================================
  453. #define MSG_Y 9
  454. //#define THERM_X 15
  455. //#define THERM_Y 16
  456. //#define THERMCOLOR 3
  457. #define THERM_X 14
  458. #define THERM_Y 14
  459. int thermMax;
  460. int thermCurrent;
  461. char *startup; // * to text screen
  462. char smsg[80]; // status bar line
  463. //
  464. // Heretic startup screen shit
  465. //
  466. byte *hscreen;
  467. void hgotoxy(int x,int y)
  468. {
  469. hscreen = (byte *)(0xb8000 + y*160 + x*2);
  470. }
  471. void hput(unsigned char c, unsigned char a)
  472. {
  473. *hscreen++ = c;
  474. *hscreen++ = a;
  475. }
  476. void hprintf(char *string, unsigned char a)
  477. {
  478. #ifdef __WATCOMC__
  479. int i;
  480. if(debugmode)
  481. {
  482. puts(string);
  483. return;
  484. }
  485. for(i = 0; i < strlen(string); i++)
  486. {
  487. hput(string[i], a);
  488. }
  489. #endif
  490. }
  491. void drawstatus(void)
  492. {
  493. if(debugmode)
  494. {
  495. return;
  496. }
  497. #ifdef __WATCOMC__
  498. _settextposition(25, 2);
  499. _setbkcolor(1);
  500. _settextcolor(15);
  501. _outtext(smsg);
  502. _settextposition(25, 1);
  503. #endif
  504. }
  505. void status(char *string)
  506. {
  507. strcat(smsg,string);
  508. drawstatus();
  509. }
  510. void DrawThermo(void)
  511. {
  512. #ifdef __WATCOMC__
  513. unsigned char *screen;
  514. int progress;
  515. int i;
  516. if(debugmode)
  517. {
  518. return;
  519. }
  520. #if 0
  521. progress = (98*thermCurrent)/thermMax;
  522. screen = (char *)0xb8000 + (THERM_Y*160 + THERM_X*2);
  523. for (i = 0;i < progress/2; i++)
  524. {
  525. switch(i)
  526. {
  527. case 4:
  528. case 9:
  529. case 14:
  530. case 19:
  531. case 29:
  532. case 34:
  533. case 39:
  534. case 44:
  535. *screen++ = 0xb3;
  536. *screen++ = (THERMCOLOR<<4)+15;
  537. break;
  538. case 24:
  539. *screen++ = 0xba;
  540. *screen++ = (THERMCOLOR<<4)+15;
  541. break;
  542. default:
  543. *screen++ = 0xdb;
  544. *screen++ = 0x40 + THERMCOLOR;
  545. break;
  546. }
  547. }
  548. if (progress&1)
  549. {
  550. *screen++ = 0xdd;
  551. *screen++ = 0x40 + THERMCOLOR;
  552. }
  553. #else
  554. progress = (50*thermCurrent)/thermMax+2;
  555. // screen = (char *)0xb8000 + (THERM_Y*160 + THERM_X*2);
  556. hgotoxy(THERM_X,THERM_Y);
  557. for (i = 0; i < progress; i++)
  558. {
  559. // *screen++ = 0xdb;
  560. // *screen++ = 0x2a;
  561. hput(0xdb,0x2a);
  562. }
  563. #endif
  564. #endif
  565. }
  566. #ifdef __WATCOMC__
  567. void blitStartup(void)
  568. {
  569. byte *textScreen;
  570. if(debugmode)
  571. {
  572. return;
  573. }
  574. // Blit main screen
  575. textScreen = (byte *)0xb8000;
  576. memcpy(textScreen, startup, 4000);
  577. // Print version string
  578. _setbkcolor(4); // Red
  579. _settextcolor(14); // Yellow
  580. _settextposition(3, 47);
  581. _outtext(VERSION_TEXT);
  582. // Hide cursor
  583. _settextcursor(0x2000);
  584. }
  585. #endif
  586. char tmsg[300];
  587. void tprintf(char *msg,int initflag)
  588. {
  589. #if 0
  590. #ifdef __WATCOMC__
  591. char temp[80];
  592. int start;
  593. int add;
  594. int i;
  595. #endif
  596. if(debugmode)
  597. {
  598. printf(msg);
  599. return;
  600. }
  601. #ifdef __WATCOMC__
  602. if (initflag)
  603. tmsg[0] = 0;
  604. strcat(tmsg,msg);
  605. blitStartup();
  606. DrawThermo();
  607. _setbkcolor(4);
  608. _settextcolor(15);
  609. for (add = start = i = 0; i <= strlen(tmsg); i++)
  610. if ((tmsg[i] == '\n') || (!tmsg[i]))
  611. {
  612. memset(temp,0,80);
  613. strncpy(temp,tmsg+start,i-start);
  614. _settextposition(MSG_Y+add,40-strlen(temp)/2);
  615. _outtext(temp);
  616. start = i+1;
  617. add++;
  618. }
  619. _settextposition(25,1);
  620. drawstatus();
  621. #else
  622. printf(msg);
  623. #endif
  624. #endif
  625. }
  626. void CheckAbortStartup(void)
  627. {
  628. #ifdef __WATCOMC__
  629. extern int lastpress;
  630. if(lastpress == 1)
  631. { // Abort if escape pressed
  632. CleanExit();
  633. }
  634. #endif
  635. }
  636. void IncThermo(void)
  637. {
  638. thermCurrent++;
  639. DrawThermo();
  640. CheckAbortStartup();
  641. }
  642. void InitThermo(int max)
  643. {
  644. thermMax = max;
  645. thermCurrent = 0;
  646. }
  647. #ifdef __WATCOMC__
  648. void CleanExit(void)
  649. {
  650. union REGS regs;
  651. I_ShutdownKeyboard();
  652. regs.x.eax = 0x3;
  653. int386(0x10, &regs, &regs);
  654. printf("Exited from HERETIC.\n");
  655. exit(1);
  656. }
  657. #endif
  658. //---------------------------------------------------------------------------
  659. //
  660. // PROC D_DoomMain
  661. //
  662. //---------------------------------------------------------------------------
  663. void D_DoomMain(void)
  664. {
  665. int p;
  666. int e;
  667. int m;
  668. char file[256];
  669. FILE *fp;
  670. boolean devMap;
  671. //char *screen;
  672. M_FindResponseFile();
  673. setbuf(stdout, NULL);
  674. nomonsters = M_CheckParm("-nomonsters");
  675. respawnparm = M_CheckParm("-respawn");
  676. ravpic = M_CheckParm("-ravpic");
  677. noartiskip = M_CheckParm("-noartiskip");
  678. debugmode = M_CheckParm("-debug");
  679. startskill = sk_medium;
  680. startepisode = 1;
  681. startmap = 1;
  682. autostart = false;
  683. // wadfiles[0] is a char * to the main wad
  684. fp = fopen(wadfiles[0], "rb");
  685. if(fp)
  686. {
  687. fclose(fp);
  688. }
  689. else
  690. { // Change to look for shareware wad
  691. wadfiles[0] = SHAREWAREWADNAME;
  692. }
  693. // Check for -CDROM
  694. cdrom = false;
  695. #ifdef __WATCOMC__
  696. if(M_CheckParm("-cdrom"))
  697. {
  698. cdrom = true;
  699. mkdir("c:\\heretic.cd");
  700. }
  701. #endif
  702. // -FILE [filename] [filename] ...
  703. // Add files to the wad list.
  704. p = M_CheckParm("-file");
  705. if(p)
  706. { // the parms after p are wadfile/lump names, until end of parms
  707. // or another - preceded parm
  708. while(++p != myargc && myargv[p][0] != '-')
  709. {
  710. D_AddFile(myargv[p]);
  711. }
  712. }
  713. // -DEVMAP <episode> <map>
  714. // Adds a map wad from the development directory to the wad list,
  715. // and sets the start episode and the start map.
  716. devMap = false;
  717. p = M_CheckParm("-devmap");
  718. if(p && p < myargc-2)
  719. {
  720. e = myargv[p+1][0];
  721. m = myargv[p+2][0];
  722. sprintf(file, MAPDIR"E%cM%c.wad", e, m);
  723. D_AddFile(file);
  724. printf("DEVMAP: Episode %c, Map %c.\n", e, m);
  725. startepisode = e-'0';
  726. startmap = m-'0';
  727. autostart = true;
  728. devMap = true;
  729. }
  730. p = M_CheckParm("-playdemo");
  731. if(!p)
  732. {
  733. p = M_CheckParm("-timedemo");
  734. }
  735. if (p && p < myargc-1)
  736. {
  737. sprintf(file, "%s.lmp", myargv[p+1]);
  738. D_AddFile(file);
  739. printf("Playing demo %s.lmp.\n", myargv[p+1]);
  740. }
  741. //
  742. // get skill / episode / map from parms
  743. //
  744. if(M_CheckParm("-deathmatch"))
  745. {
  746. deathmatch = true;
  747. }
  748. p = M_CheckParm("-skill");
  749. if(p && p < myargc-1)
  750. {
  751. startskill = myargv[p+1][0]-'1';
  752. autostart = true;
  753. }
  754. p = M_CheckParm("-episode");
  755. if(p && p < myargc-1)
  756. {
  757. startepisode = myargv[p+1][0]-'0';
  758. startmap = 1;
  759. autostart = true;
  760. }
  761. p = M_CheckParm("-warp");
  762. if(p && p < myargc-2)
  763. {
  764. startepisode = myargv[p+1][0]-'0';
  765. startmap = myargv[p+2][0]-'0';
  766. autostart = true;
  767. }
  768. //
  769. // init subsystems
  770. //
  771. printf("V_Init: allocate screens.\n");
  772. V_Init();
  773. // Load defaults before initing other systems
  774. printf("M_LoadDefaults: Load system defaults.\n");
  775. M_LoadDefaults();
  776. printf("Z_Init: Init zone memory allocation daemon.\n");
  777. Z_Init();
  778. printf("W_Init: Init WADfiles.\n");
  779. W_InitMultipleFiles(wadfiles);
  780. if(W_CheckNumForName("E2M1") == -1)
  781. { // Can't find episode 2 maps, must be the shareware WAD
  782. shareware = true;
  783. }
  784. else if(W_CheckNumForName("EXTENDED") != -1)
  785. { // Found extended lump, must be the extended WAD
  786. ExtendedWAD = true;
  787. }
  788. #ifdef __WATCOMC__
  789. I_StartupKeyboard();
  790. I_StartupJoystick();
  791. #endif
  792. startup = W_CacheLumpName("LOADING", PU_CACHE);
  793. #ifdef __WATCOMC__
  794. blitStartup();
  795. #endif
  796. //
  797. // Build status bar line!
  798. //
  799. smsg[0] = 0;
  800. if (deathmatch)
  801. status("DeathMatch...");
  802. if (nomonsters)
  803. status("No Monsters...");
  804. if (respawnparm)
  805. status("Respawning...");
  806. if (autostart)
  807. {
  808. char temp[64];
  809. sprintf(temp, "Warp to Episode %d, Map %d, Skill %d ",
  810. startepisode, startmap, startskill+1);
  811. status(temp);
  812. }
  813. wadprintf(); // print the added wadfiles
  814. tprintf("MN_Init: Init menu system.\n",1);
  815. MN_Init();
  816. CT_Init();
  817. tprintf("R_Init: Init Heretic refresh daemon.",1);
  818. hgotoxy(17,7);
  819. hprintf("Loading graphics",0x3f);
  820. R_Init();
  821. tprintf("P_Init: Init Playloop state.",1);
  822. hgotoxy(17,8);
  823. hprintf("Init game engine.",0x3f);
  824. P_Init();
  825. IncThermo();
  826. tprintf("I_Init: Setting up machine state.\n",1);
  827. I_Init();
  828. IncThermo();
  829. tprintf("D_CheckNetGame: Checking network game status.\n",1);
  830. hgotoxy(17,9);
  831. hprintf("Checking network game status.", 0x3f);
  832. D_CheckNetGame();
  833. IncThermo();
  834. #ifdef __WATCOMC__
  835. I_CheckExternDriver(); // Check for an external device driver
  836. #endif
  837. tprintf("SB_Init: Loading patches.\n",1);
  838. SB_Init();
  839. IncThermo();
  840. //
  841. // start the apropriate game based on parms
  842. //
  843. D_CheckRecordFrom();
  844. p = M_CheckParm("-record");
  845. if(p && p < myargc-1)
  846. {
  847. G_RecordDemo(startskill, 1, startepisode, startmap, myargv[p+1]);
  848. D_DoomLoop(); // Never returns
  849. }
  850. p = M_CheckParm("-playdemo");
  851. if(p && p < myargc-1)
  852. {
  853. singledemo = true; // Quit after one demo
  854. G_DeferedPlayDemo(myargv[p+1]);
  855. D_DoomLoop(); // Never returns
  856. }
  857. p = M_CheckParm("-timedemo");
  858. if(p && p < myargc-1)
  859. {
  860. G_TimeDemo(myargv[p+1]);
  861. D_DoomLoop(); // Never returns
  862. }
  863. p = M_CheckParm("-loadgame");
  864. if(p && p < myargc-1)
  865. {
  866. if(cdrom)
  867. {
  868. sprintf(file, SAVEGAMENAMECD"%c.hsg", myargv[p+1][0]);
  869. }
  870. else
  871. {
  872. sprintf(file, SAVEGAMENAME"%c.hsg", myargv[p+1][0]);
  873. }
  874. G_LoadGame(file);
  875. }
  876. // Check valid episode and map
  877. if((autostart || netgame) && (devMap == false))
  878. {
  879. if(M_ValidEpisodeMap(startepisode, startmap) == false)
  880. {
  881. startepisode = 1;
  882. startmap = 1;
  883. }
  884. }
  885. if(gameaction != ga_loadgame)
  886. {
  887. UpdateState |= I_FULLSCRN;
  888. BorderNeedRefresh = true;
  889. if(autostart || netgame)
  890. {
  891. G_InitNew(startskill, startepisode, startmap);
  892. }
  893. else
  894. {
  895. D_StartTitle();
  896. }
  897. }
  898. #ifdef __WATCOMC__
  899. _settextcursor(0x0607); // bring the cursor back
  900. #endif
  901. D_DoomLoop(); // Never returns
  902. }