/
d_main.c
2108 lines (1836 loc) · 56.1 KB
/
d_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Emacs style mode select -*- C++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2004 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
* Copyright 2005, 2006 by
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* DESCRIPTION:
* DOOM main program (D_DoomMain) and game loop (D_DoomLoop),
* plus functions to determine game mode (shareware, registered),
* parse command line parameters, configure game parameters (turbo),
* and call the startup functions.
*
*-----------------------------------------------------------------------------
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "SDL_timer.h"
#ifdef _MSC_VER
#include <io.h>
#include <direct.h>
#else
#include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "doomdef.h"
#include "doomtype.h"
#include "doomstat.h"
#include "d_net.h"
#include "dstrings.h"
#include "sounds.h"
#include "z_zone.h"
#include "w_wad.h"
#include "s_sound.h"
#include "v_video.h"
#include "f_finale.h"
#include "f_wipe.h"
#include "m_argv.h"
#include "m_misc.h"
#include "m_menu.h"
#include "p_checksum.h"
#include "i_main.h"
#include "i_system.h"
#include "i_sound.h"
#include "i_video.h"
#include "g_game.h"
#include "hu_stuff.h"
#include "wi_stuff.h"
#include "st_stuff.h"
#include "am_map.h"
#include "p_setup.h"
#include "r_draw.h"
#include "r_main.h"
#include "r_fps.h"
#include "d_main.h"
#include "d_deh.h" // Ty 04/08/98 - Externalizations
#include "lprintf.h" // jff 08/03/98 - declaration of lprintf
#include "am_map.h"
#include "umapinfo.h"
#include "statdump.h"
//e6y
#include "r_demo.h"
#include "e6y.h"
#ifdef USE_WINDOWS_LAUNCHER
#include "e6y_launcher.h"
#endif
#include "dsda/global.h"
#include "dsda/settings.h"
#include "heretic/mn_menu.h"
// NSM
#include "i_capture.h"
void GetFirstMap(int *ep, int *map); // Ty 08/29/98 - add "-warp x" functionality
static void D_PageDrawer(void);
// CPhipps - removed wadfiles[] stuff
dboolean devparm; // started game with -devparm
// jff 1/24/98 add new versions of these variables to remember command line
dboolean clnomonsters; // checkparm of -nomonsters
dboolean clrespawnparm; // checkparm of -respawn
dboolean clfastparm; // checkparm of -fast
// jff 1/24/98 end definition of command line version of play mode switches
dboolean nomonsters; // working -nomonsters
dboolean respawnparm; // working -respawn
dboolean fastparm; // working -fast
dboolean singletics = false; // debug flag to cancel adaptiveness
//jff 1/22/98 parms for disabling music and sound
dboolean nosfxparm;
dboolean nomusicparm;
dboolean umapinfo_loaded;
//jff 4/18/98
extern dboolean inhelpscreens;
extern dboolean BorderNeedRefresh;
skill_t startskill;
int startepisode;
int startmap;
dboolean autostart;
FILE *debugfile;
int ffmap;
dboolean advancedemo;
char *basesavegame; // killough 2/16/98: savegame directory
//jff 4/19/98 list of standard IWAD names
const char *const standard_iwads[]=
{
"doom2f.wad",
"doom2.wad",
"plutonia.wad",
"tnt.wad",
"doom.wad",
"doom1.wad",
"doomu.wad", /* CPhipps - alow doomu.wad */
"freedoom2.wad", /* wart@kobold.org: added freedoom for Fedora Extras */
"freedoom1.wad",
"freedm.wad",
"hacx.wad",
"chex.wad",
"bfgdoom2.wad",
"bfgdoom.wad",
"heretic.wad"
};
//e6y static
const int nstandard_iwads = sizeof standard_iwads/sizeof*standard_iwads;
/*
* D_PostEvent - Event handling
*
* Called by I/O functions when an event is received.
* Try event handlers for each code area in turn.
* cph - in the true spirit of the Boom source, let the
* short ciruit operator madness begin!
*/
void D_PostEvent(event_t *ev)
{
/* cph - suppress all input events at game start
* FIXME: This is a lousy kludge */
// e6y
// Is this condition needed here?
// Moved to I_StartTic()
// if (gametic < 3) return;
dsda_InputTrackEvent(ev);
// Allow only sensible keys during skipping
if (doSkip)
{
if (dsda_InputActivated(dsda_input_quit))
{
// Immediate exit if quit key is pressed in skip mode
I_SafeExit(0);
}
else
{
// use key is used for seeing the current frame
if (
!dsda_InputActivated(dsda_input_use) && !dsda_InputActivated(dsda_input_demo_skip) &&
(ev->type == ev_keydown || ev->type == ev_keyup) // is this condition important?
)
{
return;
}
}
}
if (M_Responder(ev))
dsda_InputFlushTick(); // If the menu used the event, make it invisible
else
G_Responder(ev);
}
//
// D_Wipe
//
// CPhipps - moved the screen wipe code from D_Display to here
// The screens to wipe between are already stored, this just does the timing
// and screen updating
static void D_Wipe(void)
{
dboolean done;
int wipestart = I_GetTime () - 1;
if (!render_wipescreen || dsda_SkipWipe()) return;//e6y
do
{
int nowtime, tics;
do
{
I_uSleep(5000); // CPhipps - don't thrash cpu in this loop
nowtime = I_GetTime();
tics = nowtime - wipestart;
}
while (!tics);
wipestart = nowtime;
done = wipe_ScreenWipe(tics);
I_UpdateNoBlit();
M_Drawer(); // menu is drawn even on top of wipes
I_FinishUpdate(); // page flip or blit buffer
}
while (!done);
}
//
// D_Display
// draw current display, possibly wiping it from the previous
//
// wipegamestate can be set to -1 to force a wipe on the next draw
gamestate_t wipegamestate = GS_DEMOSCREEN;
extern dboolean setsizeneeded;
extern int showMessages;
void D_Display (fixed_t frac)
{
static dboolean isborderstate = false;
static dboolean borderwillneedredraw = false;
static gamestate_t oldgamestate = -1;
dboolean wipe;
dboolean viewactive = false, isborder = false;
// e6y
if (doSkip)
{
if (HU_DrawDemoProgress(false))
I_FinishUpdate();
if (!dsda_InputActive(dsda_input_use))
return;
#ifdef GL_DOOM
if (V_GetMode() == VID_MODEGL)
{
gld_PreprocessLevel();
}
#endif
}
if (!doSkip || !dsda_InputActive(dsda_input_use))
if (nodrawers) // for comparative timing / profiling
return;
if (!I_StartDisplay())
return;
if (setsizeneeded) { // change the view size if needed
R_ExecuteSetViewSize();
oldgamestate = -1; // force background redraw
}
// save the current screen if about to wipe
if ((wipe = (gamestate != wipegamestate)))
{
wipe_StartScreen();
R_ResetViewInterpolation();
}
if (gamestate != GS_LEVEL) { // Not a level
switch (oldgamestate) {
case -1:
case GS_LEVEL:
V_SetPalette(0); // cph - use default (basic) palette
default:
break;
}
switch (gamestate) {
case GS_INTERMISSION:
WI_Drawer();
break;
case GS_FINALE:
F_Drawer();
break;
case GS_DEMOSCREEN:
D_PageDrawer();
break;
default:
break;
}
} else if (gametic != basetic) { // In a level
dboolean redrawborderstuff;
HU_Erase();
// Work out if the player view is visible, and if there is a border
viewactive = (!(automapmode & am_active) || (automapmode & am_overlay)) && !inhelpscreens;
isborder = viewactive ? (viewheight != SCREENHEIGHT) : (!inhelpscreens && (automapmode & am_active));
if (oldgamestate != GS_LEVEL) {
R_FillBackScreen (); // draw the pattern into the back screen
redrawborderstuff = isborder;
} else {
// CPhipps -
// If there is a border, and either there was no border last time,
// or the border might need refreshing, then redraw it.
redrawborderstuff = isborder && (!isborderstate || borderwillneedredraw);
// The border may need redrawing next time if the border surrounds the screen,
// and there is a menu being displayed
borderwillneedredraw = menuactive && isborder && viewactive;
// e6y
// I should do it because I call R_RenderPlayerView in all cases,
// not only if viewactive is true
borderwillneedredraw = (borderwillneedredraw) ||
(((automapmode & am_active) && !(automapmode & am_overlay)));
}
if (redrawborderstuff || (V_GetMode() == VID_MODEGL))
R_DrawViewBorder();
// e6y
// Boom colormaps should be applied for everything in R_RenderPlayerView
use_boom_cm=true;
R_InterpolateView(&players[displayplayer], frac);
R_ClearStats();
// Now do the drawing
if (viewactive || map_always_updates)
{
R_RenderPlayerView (&players[displayplayer]);
}
// IDRATE cheat
R_ShowStats();
// e6y
// but should NOT be applied for automap, statusbar and HUD
use_boom_cm=false;
frame_fixedcolormap = 0;
if (automapmode & am_active)
{
AM_Drawer();
}
R_RestoreInterpolations();
ST_Drawer(
((viewheight != SCREENHEIGHT)
|| ((automapmode & am_active) && !(automapmode & am_overlay))),
redrawborderstuff || BorderNeedRefresh,
(menuactive == mnact_full));
BorderNeedRefresh = false;
if (V_GetMode() != VID_MODEGL)
R_DrawViewBorder();
HU_Drawer();
}
isborderstate = isborder;
oldgamestate = wipegamestate = gamestate;
// draw pause pic
if (paused && (menuactive != mnact_full)) {
if (heretic)
MN_DrawPause();
else
// Simplified the "logic" here and no need for x-coord caching - POPE
V_DrawNamePatch(
(320 - V_NamePatchWidth("M_PAUSE"))/2, 4, 0,
"M_PAUSE", CR_DEFAULT, VPT_STRETCH
);
}
// menus go directly to the screen
M_Drawer(); // menu is drawn even on top of everything
#ifdef HAVE_NET
NetUpdate(); // send out any new accumulation
#else
D_BuildNewTiccmds();
#endif
HU_DrawDemoProgress(true); //e6y
// normal update
if (!wipe)
I_FinishUpdate (); // page flip or blit buffer
else {
// wipe update
wipe_EndScreen();
D_Wipe();
}
// e6y
// Don't thrash cpu during pausing or if the window doesnt have focus
if ( (paused && !walkcamera.type) || (!window_focused) ) {
I_uSleep(5000);
}
I_EndDisplay();
}
// CPhipps - Auto screenshot Variables
static int auto_shot_count, auto_shot_time;
static const char *auto_shot_fname;
//
// D_DoomLoop()
//
// Not a globally visible function,
// just included for source reference,
// called by D_DoomMain, never exits.
// Manages timing and IO,
// calls all ?_Responder, ?_Ticker, and ?_Drawer,
// calls I_GetTime, I_StartFrame, and I_StartTic
//
static void D_DoomLoop(void)
{
if (quickstart_window_ms > 0)
I_uSleep(quickstart_window_ms * 1000);
for (;;)
{
WasRenderedInTryRunTics = false;
// frame syncronous IO operations
I_StartFrame ();
if (ffmap == gamemap) ffmap = 0;
// process one or more tics
if (singletics)
{
I_StartTic ();
G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]);
if (advancedemo)
D_DoAdvanceDemo ();
M_Ticker ();
G_Ticker ();
P_Checksum(gametic);
gametic++;
maketic++;
}
else
TryRunTics (); // will run at least one tic
// killough 3/16/98: change consoleplayer to displayplayer
if (players[displayplayer].mo) // cph 2002/08/10
S_UpdateSounds(players[displayplayer].mo);// move positional sounds
// Update display, next frame, with current state.
if (!movement_smooth || !WasRenderedInTryRunTics || gamestate != wipegamestate)
{
// NSM
if (capturing_video && !doSkip)
{
dboolean first = true;
int cap_step = TICRATE * FRACUNIT / cap_fps;
cap_frac += cap_step;
while(cap_frac <= FRACUNIT)
{
isExtraDDisplay = !first;
first = false;
D_Display(cap_frac);
isExtraDDisplay = false;
I_CaptureFrame();
cap_frac += cap_step;
}
cap_frac -= FRACUNIT + cap_step;
}
else
{
D_Display(I_GetTimeFrac());
}
}
// CPhipps - auto screenshot
if (auto_shot_fname && !--auto_shot_count) {
auto_shot_count = auto_shot_time;
M_DoScreenShot(auto_shot_fname);
}
//e6y
if (avi_shot_fname && !doSkip)
{
int len;
char *avi_shot_curr_fname;
avi_shot_num++;
len = snprintf(NULL, 0, "%s%06d.tga", avi_shot_fname, avi_shot_num);
avi_shot_curr_fname = malloc(len+1);
sprintf(avi_shot_curr_fname, "%s%06d.tga", avi_shot_fname, avi_shot_num);
M_DoScreenShot(avi_shot_curr_fname);
free(avi_shot_curr_fname);
}
}
}
//
// DEMO LOOP
//
static int demosequence; // killough 5/2/98: made static
static int pagetic;
static const char *pagename; // CPhipps - const
dboolean bfgedition = 0;
//
// D_PageTicker
// Handles timing for warped projection
//
void D_PageTicker(void)
{
if (--pagetic < 0)
D_AdvanceDemo();
}
//
// D_PageDrawer
//
static void D_PageDrawer(void)
{
if (heretic)
{
const byte* lump = W_CacheLumpName(pagename);
V_DrawRawScreen(lump);
W_UnlockLumpName(pagename);
return;
}
// proff/nicolas 09/14/98 -- now stretchs bitmaps to fullscreen!
// CPhipps - updated for new patch drawing
// proff - added M_DrawCredits
if (pagename)
{
V_DrawNamePatch(0, 0, 0, pagename, CR_DEFAULT, VPT_STRETCH);
// e6y: wide-res
V_FillBorder(-1, 0);
}
else
M_DrawCredits();
}
//
// D_AdvanceDemo
// Called after each demo or intro demosequence finishes
//
void D_AdvanceDemo (void)
{
advancedemo = true;
}
/* killough 11/98: functions to perform demo sequences
* cphipps 10/99: constness fixes
*/
static void D_SetPageName(const char *name)
{
if ((bfgedition) && name && !strncmp(name,"TITLEPIC",8))
pagename = "DMENUPIC";
else
pagename = name;
}
void D_SetPage(const char* name, int tics, int music)
{
if (music)
S_StartMusic(music);
if (tics)
pagetic = tics;
D_SetPageName(name);
}
static void D_DrawTitle1(const char *name)
{
D_SetPage(name, TICRATE * 170 / 35, mus_intro);
}
static void D_DrawTitle2(const char *name)
{
D_SetPage(name, 0, mus_dm2ttl);
}
/* killough 11/98: tabulate demo sequences
*/
extern const demostate_t (*demostates)[4];
const demostate_t doom_demostates[][4] =
{
{
{D_DrawTitle1, "TITLEPIC"},
{D_DrawTitle1, "TITLEPIC"},
{D_DrawTitle2, "TITLEPIC"},
{D_DrawTitle1, "TITLEPIC"},
},
{
{G_DeferedPlayDemo, "demo1"},
{G_DeferedPlayDemo, "demo1"},
{G_DeferedPlayDemo, "demo1"},
{G_DeferedPlayDemo, "demo1"},
},
{
{D_SetPageName, NULL},
{D_SetPageName, NULL},
{D_SetPageName, NULL},
{D_SetPageName, NULL},
},
{
{G_DeferedPlayDemo, "demo2"},
{G_DeferedPlayDemo, "demo2"},
{G_DeferedPlayDemo, "demo2"},
{G_DeferedPlayDemo, "demo2"},
},
{
{D_SetPageName, "HELP2"},
{D_SetPageName, "HELP2"},
{D_SetPageName, "CREDIT"},
{D_DrawTitle1, "TITLEPIC"},
},
{
{G_DeferedPlayDemo, "demo3"},
{G_DeferedPlayDemo, "demo3"},
{G_DeferedPlayDemo, "demo3"},
{G_DeferedPlayDemo, "demo3"},
},
{
{NULL},
{NULL},
// e6y
// Both Plutonia and TNT are commercial like Doom2,
// but in difference from Doom2, they have demo4 in demo cycle.
{G_DeferedPlayDemo, "demo4"},
{D_SetPageName, "CREDIT"},
},
{
{NULL},
{NULL},
{NULL},
{G_DeferedPlayDemo, "demo4"},
},
{
{NULL},
{NULL},
{NULL},
{NULL},
}
};
/*
* This cycles through the demo sequences.
* killough 11/98: made table-driven
*/
void D_DoAdvanceDemo(void)
{
players[consoleplayer].playerstate = PST_LIVE; /* not reborn */
advancedemo = usergame = paused = false;
gameaction = ga_nothing;
pagetic = TICRATE * 11; /* killough 11/98: default behavior */
gamestate = GS_DEMOSCREEN;
if (netgame && !demoplayback)
demosequence = 0;
else if (!demostates[++demosequence][gamemode].func)
demosequence = 0;
demostates[demosequence][gamemode].func(demostates[demosequence][gamemode].name);
}
//
// D_StartTitle
//
void D_StartTitle (void)
{
gameaction = ga_nothing;
demosequence = -1;
D_AdvanceDemo();
}
//
// D_AddFile
//
// Rewritten by Lee Killough
//
// Ty 08/29/98 - add source parm to indicate where this came from
// CPhipps - static, const char* parameter
// - source is an enum
// - modified to allocate & use new wadfiles array
void D_AddFile (const char *file, wad_source_t source)
{
char *gwa_filename=NULL;
int len;
wadfiles = realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1));
wadfiles[numwadfiles].name =
AddDefaultExtension(strcpy(malloc(strlen(file)+5), file), ".wad");
wadfiles[numwadfiles].src = source; // Ty 08/29/98
wadfiles[numwadfiles].handle = 0;
// No Rest For The Living
len=strlen(wadfiles[numwadfiles].name);
if (len>=9 && !strnicmp(wadfiles[numwadfiles].name+len-9,"nerve.wad",9))
gamemission = pack_nerve;
numwadfiles++;
// proff: automatically try to add the gwa files
// proff - moved from w_wad.c
gwa_filename=AddDefaultExtension(strcpy(malloc(strlen(file)+5), file), ".wad");
if (strlen(gwa_filename)>4)
if (!strcasecmp(gwa_filename+(strlen(gwa_filename)-4),".wad"))
{
char *ext;
ext = &gwa_filename[strlen(gwa_filename)-4];
ext[1] = 'g'; ext[2] = 'w'; ext[3] = 'a';
wadfiles = realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1));
wadfiles[numwadfiles].name = gwa_filename;
wadfiles[numwadfiles].src = source; // Ty 08/29/98
wadfiles[numwadfiles].handle = 0;
numwadfiles++;
}
}
// killough 10/98: support -dehout filename
// cph - made const, don't cache results
//e6y static
const char *D_dehout(void)
{
int p = M_CheckParm("-dehout");
if (!p)
p = M_CheckParm("-bexout");
return (p && ++p < myargc ? myargv[p] : NULL);
}
//
// CheckIWAD
//
// Verify a file is indeed tagged as an IWAD
// Scan its lumps for levelnames and return gamemode as indicated
// Detect missing wolf levels in DOOM II
//
// The filename to check is passed in iwadname, the gamemode detected is
// returned in gmode, hassec returns the presence of secret levels
//
// jff 4/19/98 Add routine to test IWAD for validity and determine
// the gamemode from it. Also note if DOOM II, whether secret levels exist
// CPhipps - const char* for iwadname, made static
//e6y static
void CheckIWAD(const char *iwadname,GameMode_t *gmode,dboolean *hassec)
{
if ( !access (iwadname,R_OK) )
{
int ud=0,rg=0,sw=0,cm=0,sc=0,hx=0,cq=0;
dboolean noiwad=0;
FILE* fp;
// Identify IWAD correctly
if ((fp = fopen(iwadname, "rb")))
{
wadinfo_t header;
// read IWAD header
if (fread(&header, sizeof(header), 1, fp) == 1)
{
size_t length;
filelump_t *fileinfo;
if (strncmp(header.identification, "IWAD", 4)) // missing IWAD tag in header
{
noiwad++;
}
// read IWAD directory
header.numlumps = LittleLong(header.numlumps);
header.infotableofs = LittleLong(header.infotableofs);
length = header.numlumps;
fileinfo = malloc(length*sizeof(filelump_t));
if (fseek (fp, header.infotableofs, SEEK_SET) ||
fread (fileinfo, sizeof(filelump_t), length, fp) != length ||
fclose(fp))
I_Error("CheckIWAD: failed to read directory %s",iwadname);
// scan directory for levelname lumps
while (length--)
{
if (fileinfo[length].name[0] == 'E' &&
fileinfo[length].name[2] == 'M' &&
fileinfo[length].name[4] == 0)
{
if (fileinfo[length].name[1] == '4')
++ud;
else if (fileinfo[length].name[1] == '3')
++rg;
else if (fileinfo[length].name[1] == '2')
++rg;
else if (fileinfo[length].name[1] == '1')
++sw;
}
else if (fileinfo[length].name[0] == 'M' &&
fileinfo[length].name[1] == 'A' &&
fileinfo[length].name[2] == 'P' &&
fileinfo[length].name[5] == 0)
{
++cm;
if (fileinfo[length].name[3] == '3')
if (fileinfo[length].name[4] == '1' ||
fileinfo[length].name[4] == '2')
++sc;
}
if (!strncmp(fileinfo[length].name,"DMENUPIC",8))
bfgedition++;
if (!strncmp(fileinfo[length].name,"HACX",4))
hx++;
if (!strncmp(fileinfo[length].name,"W94_1",5) ||
!strncmp(fileinfo[length].name,"POSSH0M0",8))
cq++;
}
free(fileinfo);
if (noiwad && !bfgedition && cq < 2)
I_Error("CheckIWAD: IWAD tag %s not present", iwadname);
}
}
else // error from open call
I_Error("CheckIWAD: Can't open IWAD %s", iwadname);
// Determine game mode from levels present
// Must be a full set for whichever mode is present
// Lack of wolf-3d levels also detected here
*gmode = indetermined;
*hassec = false;
if (cm>=30 || (cm>=20 && hx))
{
*gmode = commercial;
*hassec = sc>=2;
}
else if (ud>=9)
*gmode = retail;
else if (rg>=18)
*gmode = registered;
else if (sw>=9)
*gmode = shareware;
}
else // error from access call
I_Error("CheckIWAD: IWAD %s not readable", iwadname);
}
//
// AddIWAD
//
void AddIWAD(const char *iwad)
{
size_t i;
if (!(iwad && *iwad))
return;
//jff 9/3/98 use logical output routine
lprintf(LO_CONFIRM,"IWAD found: %s\n",iwad); //jff 4/20/98 print only if found
CheckIWAD(iwad,&gamemode,&haswolflevels);
/* jff 8/23/98 set gamemission global appropriately in all cases
* cphipps 12/1999 - no version output here, leave that to the caller
*/
i = strlen(iwad);
if (i >= 11 && !strnicmp(iwad + i - 11, "heretic.wad", 11))
{
if (!M_CheckParm("-heretic"))
M_AddParam("-heretic");
}
switch(gamemode)
{
case retail:
case registered:
case shareware:
gamemission = doom;
if (i>=8 && !strnicmp(iwad+i-8,"chex.wad",8))
gamemission = chex;
break;
case commercial:
gamemission = doom2;
if (i>=10 && !strnicmp(iwad+i-10,"doom2f.wad",10))
language=french;
else if (i>=7 && !strnicmp(iwad+i-7,"tnt.wad",7))
gamemission = pack_tnt;
else if (i>=12 && !strnicmp(iwad+i-12,"plutonia.wad",12))
gamemission = pack_plut;
else if (i>=8 && !strnicmp(iwad+i-8,"hacx.wad",8))
gamemission = hacx;
break;
default:
gamemission = none;
break;
}
if (gamemode == indetermined)
//jff 9/3/98 use logical output routine
lprintf(LO_WARN,"Unknown Game Version, may not work\n");
D_AddFile(iwad,source_iwad);
}
// NormalizeSlashes
//
// Remove trailing slashes, translate backslashes to slashes
// The string to normalize is passed and returned in str
//
// jff 4/19/98 Make killoughs slash fixer a subroutine
//
static void NormalizeSlashes(char *str)
{
size_t l;
// killough 1/18/98: Neater / \ handling.
// Remove trailing / or \ to prevent // /\ \/ \\, and change \ to /
if (!str || !(l = strlen(str)))
return;
if (str[--l]=='/' || str[l]=='\\') // killough 1/18/98
str[l]=0;
while (l--)
if (str[l]=='\\')
str[l]='/';
}
/*
* FindIWADFIle
*
* Search for one of the standard IWADs
* CPhipps - static, proper prototype
* - 12/1999 - rewritten to use I_FindFile
*/
static char *FindIWADFile(void)
{
int i;
char * iwad = NULL;
i = M_CheckParm("-iwad");
if (i && (++i < myargc)) {
iwad = I_FindFile(myargv[i], ".wad");
} else {
for (i=0; !iwad && i<nstandard_iwads; i++)
iwad = I_FindFile(standard_iwads[i], ".wad");
}
return iwad;
}
//
// IdentifyVersion