Subversion Repositories Kolibri OS

Rev

Rev 8597 | Rev 9097 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8557 maxcodehac 1
////////////////////////////////////////////////////////////////////
2
//
3
// WL_MENU.C
4
// by John Romero (C) 1992 Id Software, Inc.
5
//
6
////////////////////////////////////////////////////////////////////
7
 
8
#include 
9
#include 
10
#ifdef _WIN32
11
    #include 
12
    #include 
13
#else
14
    #include 
15
#endif
16
 
17
#include "wl_def.h"
18
#pragma hdrstop
19
 
20
extern int lastgamemusicoffset;
21
extern int numEpisodesMissing;
22
 
23
//
24
// PRIVATE PROTOTYPES
25
//
26
int CP_ReadThis (int);
27
 
28
#ifdef SPEAR
29
#define STARTITEM       newgame
30
 
31
#else
32
#ifdef GOODTIMES
33
#define STARTITEM       newgame
34
 
35
#else
36
#define STARTITEM       readthis
37
#endif
38
#endif
39
 
40
// ENDSTRx constants are defined in foreign.h
41
char endStrings[9][80] = {
42
    ENDSTR1,
43
    ENDSTR2,
44
    ENDSTR3,
45
    ENDSTR4,
46
    ENDSTR5,
47
    ENDSTR6,
48
    ENDSTR7,
49
    ENDSTR8,
50
    ENDSTR9
51
};
52
 
53
CP_itemtype MainMenu[] = {
54
#ifdef JAPAN
55
    {1, "", CP_NewGame},
56
    {1, "", CP_Sound},
57
    {1, "", CP_Control},
58
    {1, "", CP_LoadGame},
59
    {0, "", CP_SaveGame},
60
    {1, "", CP_ChangeView},
61
    {2, "", CP_ReadThis},
62
    {1, "", CP_ViewScores},
63
    {1, "", 0},
64
    {1, "", 0}
65
#else
66
 
67
    {1, STR_NG, CP_NewGame},
68
    {1, STR_SD, CP_Sound},
69
    {1, STR_CL, CP_Control},
70
    {1, STR_LG, CP_LoadGame},
71
    {0, STR_SG, CP_SaveGame},
72
    {1, STR_CV, CP_ChangeView},
73
 
74
#ifndef GOODTIMES
75
#ifndef SPEAR
76
 
77
#ifdef SPANISH
78
    {2, "Ve esto!", CP_ReadThis},
79
#else
80
    {2, "Read This!", CP_ReadThis},
81
#endif
82
 
83
#endif
84
#endif
85
 
86
    {1, STR_VS, CP_ViewScores},
87
    {1, STR_BD, 0},
88
    {1, STR_QT, 0}
89
#endif
90
};
91
 
92
CP_itemtype SndMenu[] = {
93
#ifdef JAPAN
94
    {1, "", 0},
95
    {1, "", 0},
96
    {1, "", 0},
97
    {0, "", 0},
98
    {0, "", 0},
99
    {1, "", 0},
100
    {1, "", 0},
101
    {1, "", 0},
102
    {0, "", 0},
103
    {0, "", 0},
104
    {1, "", 0},
105
    {1, "", 0},
106
#else
107
    {1, STR_NONE, 0},
108
    {0, STR_PC, 0},
109
    {1, STR_ALSB, 0},
110
    {0, "", 0},
111
    {0, "", 0},
112
    {1, STR_NONE, 0},
113
    {0, STR_DISNEY, 0},
114
    {1, STR_SB, 0},
115
    {0, "", 0},
116
    {0, "", 0},
117
    {1, STR_NONE, 0},
118
    {1, STR_ALSB, 0}
119
#endif
120
};
121
 
122
#ifdef JAPAN
123
enum { CTL_MOUSEENABLE, CTL_JOYENABLE, CTL_JOY2BUTTONUNKNOWN, CTL_GAMEPADUNKONWN, CTL_MOUSESENS, CTL_CUSTOMIZE };
124
#else
125
enum { CTL_MOUSEENABLE, CTL_MOUSESENS, CTL_JOYENABLE, CTL_CUSTOMIZE };
126
#endif
127
 
128
CP_itemtype CtlMenu[] = {
129
#ifdef JAPAN
130
    {0, "", 0},
131
    {0, "", 0},
132
    {0, "", 0},
133
    {0, "", 0},
134
    {0, "", MouseSensitivity},
135
    {1, "", CustomControls}
136
#else
137
    {0, STR_MOUSEEN, 0},
138
    {0, STR_SENS, MouseSensitivity},
139
    {0, STR_JOYEN, 0},
140
    {1, STR_CUSTOM, CustomControls}
141
#endif
142
};
143
 
144
#ifndef SPEAR
145
CP_itemtype NewEmenu[] = {
146
#ifdef JAPAN
147
#ifdef JAPDEMO
148
    {1, "", 0},
149
    {0, "", 0},
150
    {0, "", 0},
151
    {0, "", 0},
152
    {0, "", 0},
153
    {0, "", 0},
154
    {0, "", 0},
155
    {0, "", 0},
156
    {0, "", 0},
157
    {0, "", 0},
158
    {0, "", 0},
159
    {0, "", 0},
160
#else
161
    {1, "", 0},
162
    {0, "", 0},
163
    {1, "", 0},
164
    {0, "", 0},
165
    {1, "", 0},
166
    {0, "", 0},
167
    {1, "", 0},
168
    {0, "", 0},
169
    {1, "", 0},
170
    {0, "", 0},
171
    {1, "", 0},
172
    {0, "", 0}
173
#endif
174
#else
175
#ifdef SPANISH
176
    {1, "Episodio 1\n" "Fuga desde Wolfenstein", 0},
177
    {0, "", 0},
178
    {3, "Episodio 2\n" "Operacion Eisenfaust", 0},
179
    {0, "", 0},
180
    {3, "Episodio 3\n" "Muere, Fuhrer, Muere!", 0},
181
    {0, "", 0},
182
    {3, "Episodio 4\n" "Un Negro Secreto", 0},
183
    {0, "", 0},
184
    {3, "Episodio 5\n" "Huellas del Loco", 0},
185
    {0, "", 0},
186
    {3, "Episodio 6\n" "Confrontacion", 0}
187
#else
188
    {1, "Episode 1\n" "Escape from Wolfenstein", 0},
189
    {0, "", 0},
190
    {3, "Episode 2\n" "Operation: Eisenfaust", 0},
191
    {0, "", 0},
192
    {3, "Episode 3\n" "Die, Fuhrer, Die!", 0},
193
    {0, "", 0},
194
    {3, "Episode 4\n" "A Dark Secret", 0},
195
    {0, "", 0},
196
    {3, "Episode 5\n" "Trail of the Madman", 0},
197
    {0, "", 0},
198
    {3, "Episode 6\n" "Confrontation", 0}
199
#endif
200
#endif
201
};
202
#endif
203
 
204
 
205
CP_itemtype NewMenu[] = {
206
#ifdef JAPAN
207
    {1, "", 0},
208
    {1, "", 0},
209
    {1, "", 0},
210
    {1, "", 0}
211
#else
212
    {1, STR_DADDY, 0},
213
    {1, STR_HURTME, 0},
214
    {1, STR_BRINGEM, 0},
215
    {1, STR_DEATH, 0}
216
#endif
217
};
218
 
219
CP_itemtype LSMenu[] = {
220
    {1, "", 0},
221
    {1, "", 0},
222
    {1, "", 0},
223
    {1, "", 0},
224
    {1, "", 0},
225
    {1, "", 0},
226
    {1, "", 0},
227
    {1, "", 0},
228
    {1, "", 0},
229
    {1, "", 0}
230
};
231
 
232
CP_itemtype CusMenu[] = {
233
    {1, "", 0},
234
    {0, "", 0},
235
    {0, "", 0},
236
    {1, "", 0},
237
    {0, "", 0},
238
    {0, "", 0},
239
    {1, "", 0},
240
    {0, "", 0},
241
    {1, "", 0}
242
};
243
 
244
// CP_iteminfo struct format: short x, y, amount, curpos, indent;
245
CP_iteminfo MainItems = { MENU_X, MENU_Y, lengthof(MainMenu), STARTITEM, 24 },
246
            SndItems  = { SM_X, SM_Y1, lengthof(SndMenu), 0, 52 },
247
            LSItems   = { LSM_X, LSM_Y, lengthof(LSMenu), 0, 24 },
248
            CtlItems  = { CTL_X, CTL_Y, lengthof(CtlMenu), -1, 56 },
249
            CusItems  = { 8, CST_Y + 13 * 2, lengthof(CusMenu), -1, 0},
250
#ifndef SPEAR
251
            NewEitems = { NE_X, NE_Y, lengthof(NewEmenu), 0, 88 },
252
#endif
253
            NewItems  = { NM_X, NM_Y, lengthof(NewMenu), 2, 24 };
254
 
255
int color_hlite[] = {
256
    DEACTIVE,
257
    HIGHLIGHT,
258
    READHCOLOR,
259
    0x67
260
};
261
 
262
int color_norml[] = {
263
    DEACTIVE,
264
    TEXTCOLOR,
265
    READCOLOR,
266
    0x6b
267
};
268
 
269
int EpisodeSelect[6] = { 1 };
270
 
271
 
272
static int SaveGamesAvail[10];
273
static int StartGame;
274
static int SoundStatus = 1;
275
static int pickquick;
276
static char SaveGameNames[10][32];
277
static char SaveName[13] = "savegam?.";
278
 
279
 
280
////////////////////////////////////////////////////////////////////
281
//
282
// INPUT MANAGER SCANCODE TABLES
283
//
284
////////////////////////////////////////////////////////////////////
285
 
286
#if 0
287
static const char *ScanNames[] =      // Scan code names with single chars
288
{
289
    "?", "?", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "+", "?", "?",
290
    "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "|", "?", "A", "S",
291
    "D", "F", "G", "H", "J", "K", "L", ";", "\"", "?", "?", "?", "Z", "X", "C", "V",
292
    "B", "N", "M", ",", ".", "/", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?",
293
    "?", "?", "?", "?", "?", "?", "?", "?", "\xf", "?", "-", "\x15", "5", "\x11", "+", "?",
294
    "\x13", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?",
295
    "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?",
296
    "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?"
297
};                              // DEBUG - consolidate these
298
static ScanCode ExtScanCodes[] =        // Scan codes with >1 char names
299
{
300
    1, 0xe, 0xf, 0x1d, 0x2a, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e,
301
    0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x57, 0x59, 0x46, 0x1c, 0x36,
302
    0x37, 0x38, 0x47, 0x49, 0x4f, 0x51, 0x52, 0x53, 0x45, 0x48,
303
    0x50, 0x4b, 0x4d, 0x00
304
};
305
static const char *ExtScanNames[] =   // Names corresponding to ExtScanCodes
306
{
307
    "Esc", "BkSp", "Tab", "Ctrl", "LShft", "Space", "CapsLk", "F1", "F2", "F3", "F4",
308
    "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "ScrlLk", "Enter", "RShft",
309
    "PrtSc", "Alt", "Home", "PgUp", "End", "PgDn", "Ins", "Del", "NumLk", "Up",
310
    "Down", "Left", "Right", ""
311
};
312
 
313
/*#pragma warning 737 9
314
static byte
315
                                        *ScanNames[] =          // Scan code names with single chars
316
                                        {
317
        "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",
318
        "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",
319
        "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",
320
        "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",
321
        "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",
322
        "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
323
        "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
324
        "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
325
                                        };      // DEBUG - consolidate these
326
static byte ExtScanCodes[] =    // Scan codes with >1 char names
327
                                        {
328
        1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,
329
        0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,
330
        0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,
331
        0x50,0x4b,0x4d,0x00
332
                                        };
333
static byte *ExtScanNames[] =   // Names corresponding to ExtScanCodes
334
                                        {
335
        "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",
336
        "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",
337
        "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",
338
        "Down","Left","Right",""
339
                                        };*/
340
 
341
#else
342
static const char* const ScanNames[SDLK_LAST] =
343
    {
344
        "?","?","?","?","?","?","?","?",                                //   0
345
        "BkSp","Tab","?","?","?","Return","?","?",                      //   8
346
        "?","?","?","Pause","?","?","?","?",                            //  16
347
        "?","?","?","Esc","?","?","?","?",                              //  24
348
        "Space","!","\"","#","$","?","&","'",                           //  32
349
        "(",")","*","+",",","-",".","/",                                //  40
350
        "0","1","2","3","4","5","6","7",                                //  48
351
        "8","9",":",";","<","=",">","?",                                //  56
352
        "@","A","B","C","D","E","F","G",                                //  64
353
        "H","I","J","K","L","M","N","O",                                //  72
354
        "P","Q","R","S","T","U","V","W",                                //  80
355
        "X","Y","Z","[","\\","]","^","_",                               //  88
356
        "`","a","b","c","d","e","f","h",                                //  96
357
        "h","i","j","k","l","m","n","o",                                // 104
358
        "p","q","r","s","t","u","v","w",                                // 112
359
        "x","y","z","{","|","}","~","?",                                // 120
360
        "?","?","?","?","?","?","?","?",                                // 128
361
        "?","?","?","?","?","?","?","?",                                // 136
362
        "?","?","?","?","?","?","?","?",                                // 144
363
        "?","?","?","?","?","?","?","?",                                // 152
364
        "?","?","?","?","?","?","?","?",                                // 160
365
        "?","?","?","?","?","?","?","?",                                // 168
366
        "?","?","?","?","?","?","?","?",                                // 176
367
        "?","?","?","?","?","?","?","?",                                // 184
368
        "?","?","?","?","?","?","?","?",                                // 192
369
        "?","?","?","?","?","?","?","?",                                // 200
370
        "?","?","?","?","?","?","?","?",                                // 208
371
        "?","?","?","?","?","?","?","?",                                // 216
372
        "?","?","?","?","?","?","?","?",                                // 224
373
        "?","?","?","?","?","?","?","?",                                // 232
374
        "?","?","?","?","?","?","?","?",                                // 240
375
        "?","?","?","?","?","?","?","?",                                // 248
376
        "?","?","?","?","?","?","?","?",                                // 256
377
        "?","?","?","?","?","?","?","Enter",                            // 264
378
        "?","Up","Down","Right","Left","Ins","Home","End",              // 272
379
        "PgUp","PgDn","F1","F2","F3","F4","F5","F6",                    // 280
380
        "F7","F8","F9","F10","F11","F12","?","?",                       // 288
381
        "?","?","?","?","NumLk","CapsLk","ScrlLk","RShft",              // 296
382
        "Shift","RCtrl","Ctrl","RAlt","Alt","?","?","?",                // 304
383
        "?","?","?","?","PrtSc","?","?","?",                            // 312
384
        "?","?"                                                         // 320
385
    };
386
 
387
#endif
388
 
389
////////////////////////////////////////////////////////////////////
390
//
391
// Wolfenstein Control Panel!  Ta Da!
392
//
393
////////////////////////////////////////////////////////////////////
394
void
395
US_ControlPanel (ScanCode scancode)
396
{
397
    int which;
398
 
399
#ifdef _arch_dreamcast
400
    DC_StatusClearLCD();
401
#endif
402
 
403
    if (ingame)
404
    {
405
        if (CP_CheckQuick (scancode))
406
            return;
407
        lastgamemusicoffset = StartCPMusic (MENUSONG);
408
    }
409
    else
410
        StartCPMusic (MENUSONG);
411
    SetupControlPanel ();
412
 
413
    //
414
    // F-KEYS FROM WITHIN GAME
415
    //
416
    switch (scancode)
417
    {
418
        case sc_F1:
419
#ifdef SPEAR
420
            BossKey ();
421
#else
422
#ifdef GOODTIMES
423
            BossKey ();
424
#else
425
            HelpScreens ();
426
#endif
427
#endif
428
            goto finishup;
429
 
430
        case sc_F2:
431
            CP_SaveGame (0);
432
            goto finishup;
433
 
434
        case sc_F3:
435
            CP_LoadGame (0);
436
            goto finishup;
437
 
438
        case sc_F4:
439
            CP_Sound (0);
440
            goto finishup;
441
 
442
        case sc_F5:
443
            CP_ChangeView (0);
444
            goto finishup;
445
 
446
        case sc_F6:
447
            CP_Control (0);
448
            goto finishup;
449
 
450
        finishup:
451
            CleanupControlPanel ();
452
#ifdef SPEAR
453
            UnCacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
454
#endif
455
            return;
456
    }
457
 
458
#ifdef SPEAR
459
    CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
460
#endif
461
 
462
    DrawMainMenu ();
463
    MenuFadeIn ();
464
    StartGame = 0;
465
 
466
    //
467
    // MAIN MENU LOOP
468
    //
469
    do
470
    {
471
        which = HandleMenu (&MainItems, &MainMenu[0], NULL);
472
 
473
#ifdef SPEAR
474
#ifndef SPEARDEMO
475
        IN_ProcessEvents();
476
 
477
        //
478
        // EASTER EGG FOR SPEAR OF DESTINY!
479
        //
480
        if (Keyboard[sc_I] && Keyboard[sc_D])
481
        {
482
            VW_FadeOut ();
483
            StartCPMusic (XJAZNAZI_MUS);
484
            UnCacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
485
            UnCacheLump (BACKDROP_LUMP_START, BACKDROP_LUMP_END);
486
            ClearMemory ();
487
 
488
 
489
            CA_CacheGrChunk (IDGUYS1PIC);
490
            VWB_DrawPic (0, 0, IDGUYS1PIC);
491
            UNCACHEGRCHUNK (IDGUYS1PIC);
492
 
493
            CA_CacheGrChunk (IDGUYS2PIC);
494
            VWB_DrawPic (0, 80, IDGUYS2PIC);
495
            UNCACHEGRCHUNK (IDGUYS2PIC);
496
 
497
            VW_UpdateScreen ();
498
 
499
            SDL_Color pal[256];
500
            CA_CacheGrChunk (IDGUYSPALETTE);
501
            VL_ConvertPalette(grsegs[IDGUYSPALETTE], pal, 256);
502
            VL_FadeIn (0, 255, pal, 30);
503
            UNCACHEGRCHUNK (IDGUYSPALETTE);
504
 
505
            while (Keyboard[sc_I] || Keyboard[sc_D])
506
                IN_WaitAndProcessEvents();
507
            IN_ClearKeysDown ();
508
            IN_Ack ();
509
 
510
            VW_FadeOut ();
511
 
512
            CacheLump (BACKDROP_LUMP_START, BACKDROP_LUMP_END);
513
            CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
514
            DrawMainMenu ();
515
            StartCPMusic (MENUSONG);
516
            MenuFadeIn ();
517
        }
518
#endif
519
#endif
520
 
521
        switch (which)
522
        {
523
            case viewscores:
524
                if (MainMenu[viewscores].routine == NULL)
525
                {
526
                    if (CP_EndGame (0))
527
                        StartGame = 1;
528
                }
529
                else
530
                {
531
                    DrawMainMenu();
532
                    MenuFadeIn ();
533
                }
534
                break;
535
 
536
            case backtodemo:
537
                StartGame = 1;
538
                if (!ingame)
539
                    StartCPMusic (INTROSONG);
540
                VL_FadeOut (0, 255, 0, 0, 0, 10);
541
                break;
542
 
543
            case -1:
544
            case quit:
545
                CP_Quit (0);
546
                break;
547
 
548
            default:
549
                if (!StartGame)
550
                {
551
                    DrawMainMenu ();
552
                    MenuFadeIn ();
553
                }
554
        }
555
 
556
        //
557
        // "EXIT OPTIONS" OR "NEW GAME" EXITS
558
        //
559
    }
560
    while (!StartGame);
561
 
562
    //
563
    // DEALLOCATE EVERYTHING
564
    //
565
    CleanupControlPanel ();
566
 
567
    //
568
    // CHANGE MAINMENU ITEM
569
    //
570
    if (startgame || loadedgame)
571
        EnableEndGameMenuItem();
572
 
573
    // RETURN/START GAME EXECUTION
574
 
575
#ifdef SPEAR
576
    UnCacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
577
#endif
578
}
579
 
580
void EnableEndGameMenuItem()
581
{
582
    MainMenu[viewscores].routine = NULL;
583
#ifndef JAPAN
584
    strcpy (MainMenu[viewscores].string, STR_EG);
585
#endif
586
}
587
 
588
////////////////////////
589
//
590
// DRAW MAIN MENU SCREEN
591
//
592
void
593
DrawMainMenu (void)
594
{
595
#ifdef JAPAN
596
    CA_CacheScreen (S_OPTIONSPIC);
597
#else
598
    ClearMScreen ();
599
 
600
    VWB_DrawPic (112, 184, C_MOUSELBACKPIC);
601
    DrawStripes (10);
602
    VWB_DrawPic (84, 0, C_OPTIONSPIC);
603
 
604
#ifdef SPANISH
605
    DrawWindow (MENU_X - 8, MENU_Y - 3, MENU_W + 8, MENU_H, BKGDCOLOR);
606
#else
607
    DrawWindow (MENU_X - 8, MENU_Y - 3, MENU_W, MENU_H, BKGDCOLOR);
608
#endif
609
#endif
610
 
611
    //
612
    // CHANGE "GAME" AND "DEMO"
613
    //
614
    if (ingame)
615
    {
616
#ifndef JAPAN
617
 
618
#ifdef SPANISH
619
        strcpy (&MainMenu[backtodemo].string, STR_GAME);
620
#else
621
        strcpy (&MainMenu[backtodemo].string[8], STR_GAME);
622
#endif
623
 
624
#else
625
        CA_CacheGrChunk (C_MRETGAMEPIC);
626
        VWB_DrawPic (12 * 8, 20 * 8, C_MRETGAMEPIC);
627
        UNCACHEGRCHUNK (C_MRETGAMEPIC);
628
        CA_CacheGrChunk (C_MENDGAMEPIC);
629
        VWB_DrawPic (12 * 8, 18 * 8, C_MENDGAMEPIC);
630
        UNCACHEGRCHUNK (C_MENDGAMEPIC);
631
#endif
632
        MainMenu[backtodemo].active = 2;
633
    }
634
    else
635
    {
636
#ifndef JAPAN
637
#ifdef SPANISH
638
        strcpy (&MainMenu[backtodemo].string, STR_BD);
639
#else
640
        strcpy (&MainMenu[backtodemo].string[8], STR_DEMO);
641
#endif
642
#else
643
        CA_CacheGrChunk (C_MRETDEMOPIC);
644
        VWB_DrawPic (12 * 8, 20 * 8, C_MRETDEMOPIC);
645
        UNCACHEGRCHUNK (C_MRETDEMOPIC);
646
        CA_CacheGrChunk (C_MSCORESPIC);
647
        VWB_DrawPic (12 * 8, 18 * 8, C_MSCORESPIC);
648
        UNCACHEGRCHUNK (C_MSCORESPIC);
649
#endif
650
        MainMenu[backtodemo].active = 1;
651
    }
652
 
653
    DrawMenu (&MainItems, &MainMenu[0]);
654
    VW_UpdateScreen ();
655
}
656
 
657
#ifndef GOODTIMES
658
#ifndef SPEAR
659
////////////////////////////////////////////////////////////////////
660
//
661
// READ THIS!
662
//
663
////////////////////////////////////////////////////////////////////
664
int
665
CP_ReadThis (int)
666
{
667
    StartCPMusic (CORNER_MUS);
668
    HelpScreens ();
669
    StartCPMusic (MENUSONG);
670
    return true;
671
}
672
#endif
673
#endif
674
 
675
 
676
#ifdef GOODTIMES
677
////////////////////////////////////////////////////////////////////
678
//
679
// BOSS KEY
680
//
681
////////////////////////////////////////////////////////////////////
682
void
683
BossKey (void)
684
{
685
#ifdef NOTYET
686
    byte palette1[256][3];
687
    SD_MusicOff ();
688
/*       _AX = 3;
689
        geninterrupt(0x10); */
690
    _asm
691
    {
692
    mov eax, 3 int 0x10}
693
    puts ("C>");
694
    SetTextCursor (2, 0);
695
//      while (!Keyboard[sc_Escape])
696
    IN_Ack ();
697
    IN_ClearKeysDown ();
698
 
699
    SD_MusicOn ();
700
    VL_SetVGAPlaneMode ();
701
    for (int i = 0; i < 768; i++)
702
        palette1[0][i] = 0;
703
 
704
    VL_SetPalette (&palette1[0][0]);
705
    LoadLatchMem ();
706
#endif
707
}
708
#else
709
#ifdef SPEAR
710
void
711
BossKey (void)
712
{
713
#ifdef NOTYET
714
    byte palette1[256][3];
715
    SD_MusicOff ();
716
/*       _AX = 3;
717
        geninterrupt(0x10); */
718
    _asm
719
    {
720
    mov eax, 3 int 0x10}
721
    puts ("C>");
722
    SetTextCursor (2, 0);
723
//      while (!Keyboard[sc_Escape])
724
    IN_Ack ();
725
    IN_ClearKeysDown ();
726
 
727
    SD_MusicOn ();
728
    VL_SetVGAPlaneMode ();
729
    for (int i = 0; i < 768; i++)
730
        palette1[0][i] = 0;
731
 
732
    VL_SetPalette (&palette1[0][0]);
733
    LoadLatchMem ();
734
#endif
735
}
736
#endif
737
#endif
738
 
739
 
740
////////////////////////////////////////////////////////////////////
741
//
742
// CHECK QUICK-KEYS & QUIT (WHILE IN A GAME)
743
//
744
////////////////////////////////////////////////////////////////////
745
int
746
CP_CheckQuick (ScanCode scancode)
747
{
748
    switch (scancode)
749
    {
750
        //
751
        // END GAME
752
        //
753
        case sc_F7:
754
            CA_CacheGrChunk (STARTFONT + 1);
755
 
756
            WindowH = 160;
757
#ifdef JAPAN
758
            if (GetYorN (7, 8, C_JAPQUITPIC))
759
#else
760
            if (Confirm (ENDGAMESTR))
761
#endif
762
            {
763
                playstate = ex_died;
764
                killerobj = NULL;
765
                pickquick = gamestate.lives = 0;
766
            }
767
 
768
            WindowH = 200;
769
            fontnumber = 0;
770
            MainMenu[savegame].active = 0;
771
            return 1;
772
 
773
        //
774
        // QUICKSAVE
775
        //
776
        case sc_F8:
777
            if (SaveGamesAvail[LSItems.curpos] && pickquick)
778
            {
779
                CA_CacheGrChunk (STARTFONT + 1);
780
                fontnumber = 1;
781
                Message (STR_SAVING "...");
782
                CP_SaveGame (1);
783
                fontnumber = 0;
784
            }
785
            else
786
            {
787
#ifndef SPEAR
788
                CA_CacheGrChunk (STARTFONT + 1);
789
                CA_CacheGrChunk (C_CURSOR1PIC);
790
                CA_CacheGrChunk (C_CURSOR2PIC);
791
                CA_CacheGrChunk (C_DISKLOADING1PIC);
792
                CA_CacheGrChunk (C_DISKLOADING2PIC);
793
                CA_CacheGrChunk (C_SAVEGAMEPIC);
794
                CA_CacheGrChunk (C_MOUSELBACKPIC);
795
#else
796
                CacheLump (BACKDROP_LUMP_START, BACKDROP_LUMP_END);
797
                CA_CacheGrChunk (C_CURSOR1PIC);
798
#endif
799
 
800
                VW_FadeOut ();
801
                if(screenHeight % 200 != 0)
802
                    VL_ClearScreen(0);
803
 
804
                lastgamemusicoffset = StartCPMusic (MENUSONG);
805
                pickquick = CP_SaveGame (0);
806
 
807
                SETFONTCOLOR (0, 15);
808
                IN_ClearKeysDown ();
809
                VW_FadeOut();
810
                if(viewsize != 21)
811
                    DrawPlayScreen ();
812
 
813
                if (!startgame && !loadedgame)
814
                    ContinueMusic (lastgamemusicoffset);
815
 
816
                if (loadedgame)
817
                    playstate = ex_abort;
818
                lasttimecount = GetTimeCount ();
819
 
820
                if (MousePresent && IN_IsInputGrabbed())
821
                    IN_CenterMouse();     // Clear accumulated mouse movement
822
 
823
#ifndef SPEAR
824
                UNCACHEGRCHUNK (C_CURSOR1PIC);
825
                UNCACHEGRCHUNK (C_CURSOR2PIC);
826
                UNCACHEGRCHUNK (C_DISKLOADING1PIC);
827
                UNCACHEGRCHUNK (C_DISKLOADING2PIC);
828
                UNCACHEGRCHUNK (C_SAVEGAMEPIC);
829
                UNCACHEGRCHUNK (C_MOUSELBACKPIC);
830
#else
831
                UnCacheLump (BACKDROP_LUMP_START, BACKDROP_LUMP_END);
832
#endif
833
            }
834
            return 1;
835
 
836
        //
837
        // QUICKLOAD
838
        //
839
        case sc_F9:
840
            if (SaveGamesAvail[LSItems.curpos] && pickquick)
841
            {
842
                char string[100] = STR_LGC;
843
 
844
 
845
                CA_CacheGrChunk (STARTFONT + 1);
846
                fontnumber = 1;
847
 
848
                strcat (string, SaveGameNames[LSItems.curpos]);
849
                strcat (string, "\"?");
850
 
851
                if (Confirm (string))
852
                    CP_LoadGame (1);
853
 
854
                fontnumber = 0;
855
            }
856
            else
857
            {
858
#ifndef SPEAR
859
                CA_CacheGrChunk (STARTFONT + 1);
860
                CA_CacheGrChunk (C_CURSOR1PIC);
861
                CA_CacheGrChunk (C_CURSOR2PIC);
862
                CA_CacheGrChunk (C_DISKLOADING1PIC);
863
                CA_CacheGrChunk (C_DISKLOADING2PIC);
864
                CA_CacheGrChunk (C_LOADGAMEPIC);
865
                CA_CacheGrChunk (C_MOUSELBACKPIC);
866
#else
867
                CA_CacheGrChunk (C_CURSOR1PIC);
868
                CacheLump (BACKDROP_LUMP_START, BACKDROP_LUMP_END);
869
#endif
870
 
871
                VW_FadeOut ();
872
                if(screenHeight % 200 != 0)
873
                    VL_ClearScreen(0);
874
 
875
                lastgamemusicoffset = StartCPMusic (MENUSONG);
876
                pickquick = CP_LoadGame (0);    // loads lastgamemusicoffs
877
 
878
                SETFONTCOLOR (0, 15);
879
                IN_ClearKeysDown ();
880
                VW_FadeOut();
881
                if(viewsize != 21)
882
                    DrawPlayScreen ();
883
 
884
                if (!startgame && !loadedgame)
885
                    ContinueMusic (lastgamemusicoffset);
886
 
887
                if (loadedgame)
888
                    playstate = ex_abort;
889
 
890
                lasttimecount = GetTimeCount ();
891
 
892
                if (MousePresent && IN_IsInputGrabbed())
893
                    IN_CenterMouse();     // Clear accumulated mouse movement
894
 
895
#ifndef SPEAR
896
                UNCACHEGRCHUNK (C_CURSOR1PIC);
897
                UNCACHEGRCHUNK (C_CURSOR2PIC);
898
                UNCACHEGRCHUNK (C_DISKLOADING1PIC);
899
                UNCACHEGRCHUNK (C_DISKLOADING2PIC);
900
                UNCACHEGRCHUNK (C_LOADGAMEPIC);
901
                UNCACHEGRCHUNK (C_MOUSELBACKPIC);
902
#else
903
                UnCacheLump (BACKDROP_LUMP_START, BACKDROP_LUMP_END);
904
#endif
905
            }
906
            return 1;
907
 
908
        //
909
        // QUIT
910
        //
911
        case sc_F10:
912
            CA_CacheGrChunk (STARTFONT + 1);
913
 
914
            WindowX = WindowY = 0;
915
            WindowW = 320;
916
            WindowH = 160;
917
#ifdef JAPAN
918
            if (GetYorN (7, 8, C_QUITMSGPIC))
919
#else
920
#ifdef SPANISH
921
            if (Confirm (ENDGAMESTR))
922
#else
923
            if (Confirm (endStrings[US_RndT () & 0x7 + (US_RndT () & 1)]))
924
#endif
925
#endif
926
            {
927
                VW_UpdateScreen ();
928
                SD_MusicOff ();
929
                SD_StopSound ();
930
                MenuFadeOut ();
931
 
932
                Quit (NULL);
933
            }
934
 
935
            DrawPlayBorder ();
936
            WindowH = 200;
937
            fontnumber = 0;
938
            return 1;
939
    }
940
 
941
    return 0;
942
}
943
 
944
 
945
////////////////////////////////////////////////////////////////////
946
//
947
// END THE CURRENT GAME
948
//
949
////////////////////////////////////////////////////////////////////
950
int
951
CP_EndGame (int)
952
{
953
    int res;
954
#ifdef JAPAN
955
    res = GetYorN (7, 8, C_JAPQUITPIC);
956
#else
957
    res = Confirm (ENDGAMESTR);
958
#endif
959
    DrawMainMenu();
960
    if(!res) return 0;
961
 
962
    pickquick = gamestate.lives = 0;
963
    playstate = ex_died;
964
    killerobj = NULL;
965
 
966
    MainMenu[savegame].active = 0;
967
    MainMenu[viewscores].routine = CP_ViewScores;
968
#ifndef JAPAN
969
    strcpy (MainMenu[viewscores].string, STR_VS);
970
#endif
971
 
972
    return 1;
973
}
974
 
975
 
976
////////////////////////////////////////////////////////////////////
977
//
978
// VIEW THE HIGH SCORES
979
//
980
////////////////////////////////////////////////////////////////////
981
int
982
CP_ViewScores (int)
983
{
984
    fontnumber = 0;
985
 
986
#ifdef SPEAR
987
    UnCacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
988
    StartCPMusic (XAWARD_MUS);
989
#else
990
    StartCPMusic (ROSTER_MUS);
991
#endif
992
 
993
    DrawHighScores ();
994
    VW_UpdateScreen ();
995
    MenuFadeIn ();
996
    fontnumber = 1;
997
 
998
    IN_Ack ();
999
 
1000
    StartCPMusic (MENUSONG);
1001
    MenuFadeOut ();
1002
 
1003
#ifdef SPEAR
1004
    CacheLump (BACKDROP_LUMP_START, BACKDROP_LUMP_END);
1005
    CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1006
#endif
1007
    return 0;
1008
}
1009
 
1010
 
1011
////////////////////////////////////////////////////////////////////
1012
//
1013
// START A NEW GAME
1014
//
1015
////////////////////////////////////////////////////////////////////
1016
int
1017
CP_NewGame (int)
1018
{
1019
    int which, episode;
1020
 
1021
#ifdef SPEAR
1022
    UnCacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1023
#endif
1024
 
1025
 
1026
#ifndef SPEAR
1027
  firstpart:
1028
 
1029
    DrawNewEpisode ();
1030
    do
1031
    {
1032
        which = HandleMenu (&NewEitems, &NewEmenu[0], NULL);
1033
        switch (which)
1034
        {
1035
            case -1:
1036
                MenuFadeOut ();
1037
                return 0;
1038
 
1039
            default:
1040
                if (!EpisodeSelect[which / 2])
1041
                {
1042
                    SD_PlaySound (NOWAYSND);
1043
                    Message ("Please select \"Read This!\"\n"
1044
                             "from the Options menu to\n"
1045
                             "find out how to order this\n" "episode from Apogee.");
1046
                    IN_ClearKeysDown ();
1047
                    IN_Ack ();
1048
                    DrawNewEpisode ();
1049
                    which = 0;
1050
                }
1051
                else
1052
                {
1053
                    episode = which / 2;
1054
                    which = 1;
1055
                }
1056
                break;
1057
        }
1058
 
1059
    }
1060
    while (!which);
1061
 
1062
    ShootSnd ();
1063
 
1064
    //
1065
    // ALREADY IN A GAME?
1066
    //
1067
    if (ingame)
1068
#ifdef JAPAN
1069
        if (!GetYorN (7, 8, C_JAPNEWGAMEPIC))
1070
#else
1071
        if (!Confirm (CURGAME))
1072
#endif
1073
        {
1074
            MenuFadeOut ();
1075
            return 0;
1076
        }
1077
 
1078
    MenuFadeOut ();
1079
 
1080
#else
1081
    episode = 0;
1082
 
1083
    //
1084
    // ALREADY IN A GAME?
1085
    //
1086
    CacheLump (NEWGAME_LUMP_START, NEWGAME_LUMP_END);
1087
    DrawNewGame ();
1088
    if (ingame)
1089
        if (!Confirm (CURGAME))
1090
        {
1091
            MenuFadeOut ();
1092
            UnCacheLump (NEWGAME_LUMP_START, NEWGAME_LUMP_END);
1093
            CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1094
            return 0;
1095
        }
1096
 
1097
#endif
1098
 
1099
    DrawNewGame ();
1100
    which = HandleMenu (&NewItems, &NewMenu[0], DrawNewGameDiff);
1101
    if (which < 0)
1102
    {
1103
        MenuFadeOut ();
1104
#ifndef SPEAR
1105
        goto firstpart;
1106
#else
1107
        UnCacheLump (NEWGAME_LUMP_START, NEWGAME_LUMP_END);
1108
        CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1109
        return 0;
1110
#endif
1111
    }
1112
 
1113
    ShootSnd ();
1114
    NewGame (which, episode);
1115
    StartGame = 1;
1116
    MenuFadeOut ();
1117
 
1118
    //
1119
    // CHANGE "READ THIS!" TO NORMAL COLOR
1120
    //
1121
#ifndef SPEAR
1122
#ifndef GOODTIMES
1123
    MainMenu[readthis].active = 1;
1124
#endif
1125
#endif
1126
 
1127
    pickquick = 0;
1128
 
1129
#ifdef SPEAR
1130
    UnCacheLump (NEWGAME_LUMP_START, NEWGAME_LUMP_END);
1131
    CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1132
#endif
1133
 
1134
    return 0;
1135
}
1136
 
1137
 
1138
#ifndef SPEAR
1139
/////////////////////
1140
//
1141
// DRAW NEW EPISODE MENU
1142
//
1143
void
1144
DrawNewEpisode (void)
1145
{
1146
    int i;
1147
 
1148
#ifdef JAPAN
1149
    CA_CacheScreen (S_EPISODEPIC);
1150
#else
1151
    ClearMScreen ();
1152
    VWB_DrawPic (112, 184, C_MOUSELBACKPIC);
1153
 
1154
    DrawWindow (NE_X - 4, NE_Y - 4, NE_W + 8, NE_H + 8, BKGDCOLOR);
1155
    SETFONTCOLOR (READHCOLOR, BKGDCOLOR);
1156
    PrintY = 2;
1157
    WindowX = 0;
1158
#ifdef SPANISH
1159
    US_CPrint ("Cual episodio jugar?");
1160
#else
1161
    US_CPrint ("Which episode to play?");
1162
#endif
1163
#endif
1164
 
1165
    SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
1166
    DrawMenu (&NewEitems, &NewEmenu[0]);
1167
 
1168
    for (i = 0; i < 6; i++)
1169
        VWB_DrawPic (NE_X + 32, NE_Y + i * 26, C_EPISODE1PIC + i);
1170
 
1171
    VW_UpdateScreen ();
1172
    MenuFadeIn ();
1173
    WaitKeyUp ();
1174
}
1175
#endif
1176
 
1177
/////////////////////
1178
//
1179
// DRAW NEW GAME MENU
1180
//
1181
void
1182
DrawNewGame (void)
1183
{
1184
#ifdef JAPAN
1185
    CA_CacheScreen (S_SKILLPIC);
1186
#else
1187
    ClearMScreen ();
1188
    VWB_DrawPic (112, 184, C_MOUSELBACKPIC);
1189
 
1190
    SETFONTCOLOR (READHCOLOR, BKGDCOLOR);
1191
    PrintX = NM_X + 20;
1192
    PrintY = NM_Y - 32;
1193
 
1194
#ifndef SPEAR
1195
#ifdef SPANISH
1196
    US_Print ("Eres macho?");
1197
#else
1198
    US_Print ("How tough are you?");
1199
#endif
1200
#else
1201
    VWB_DrawPic (PrintX, PrintY, C_HOWTOUGHPIC);
1202
#endif
1203
 
1204
    DrawWindow (NM_X - 5, NM_Y - 10, NM_W, NM_H, BKGDCOLOR);
1205
#endif
1206
 
1207
    DrawMenu (&NewItems, &NewMenu[0]);
1208
    DrawNewGameDiff (NewItems.curpos);
1209
    VW_UpdateScreen ();
1210
    MenuFadeIn ();
1211
    WaitKeyUp ();
1212
}
1213
 
1214
 
1215
////////////////////////
1216
//
1217
// DRAW NEW GAME GRAPHIC
1218
//
1219
void
1220
DrawNewGameDiff (int w)
1221
{
1222
    VWB_DrawPic (NM_X + 185, NM_Y + 7, w + C_BABYMODEPIC);
1223
}
1224
 
1225
 
1226
////////////////////////////////////////////////////////////////////
1227
//
1228
// HANDLE SOUND MENU
1229
//
1230
////////////////////////////////////////////////////////////////////
1231
int
1232
CP_Sound (int)
1233
{
1234
    int which;
1235
 
1236
 
1237
#ifdef SPEAR
1238
    UnCacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1239
    CacheLump (SOUND_LUMP_START, SOUND_LUMP_END);
1240
#endif
1241
 
1242
    DrawSoundMenu ();
1243
    MenuFadeIn ();
1244
    WaitKeyUp ();
1245
 
1246
    do
1247
    {
1248
        which = HandleMenu (&SndItems, &SndMenu[0], NULL);
1249
        //
1250
        // HANDLE MENU CHOICES
1251
        //
1252
        switch (which)
1253
        {
1254
                //
1255
                // SOUND EFFECTS
1256
                //
1257
            case 0:
1258
                if (SoundMode != sdm_Off)
1259
                {
1260
                    SD_WaitSoundDone ();
1261
                    SD_SetSoundMode (sdm_Off);
1262
                    DrawSoundMenu ();
1263
                }
1264
                break;
1265
            case 1:
1266
                if (SoundMode != sdm_PC)
1267
                {
1268
                    SD_WaitSoundDone ();
1269
                    SD_SetSoundMode (sdm_PC);
1270
                    CA_LoadAllSounds ();
1271
                    DrawSoundMenu ();
1272
                    ShootSnd ();
1273
                }
1274
                break;
1275
            case 2:
1276
                if (SoundMode != sdm_AdLib)
1277
                {
1278
                    SD_WaitSoundDone ();
1279
                    SD_SetSoundMode (sdm_AdLib);
1280
                    CA_LoadAllSounds ();
1281
                    DrawSoundMenu ();
1282
                    ShootSnd ();
1283
                }
1284
                break;
1285
 
1286
                //
1287
                // DIGITIZED SOUND
1288
                //
1289
            case 5:
1290
                if (DigiMode != sds_Off)
1291
                {
1292
                    SD_SetDigiDevice (sds_Off);
1293
                    DrawSoundMenu ();
1294
                }
1295
                break;
1296
            case 6:
1297
/*                if (DigiMode != sds_SoundSource)
1298
                {
1299
                    SD_SetDigiDevice (sds_SoundSource);
1300
                    DrawSoundMenu ();
1301
                    ShootSnd ();
1302
                }*/
1303
                break;
1304
            case 7:
1305
                if (DigiMode != sds_SoundBlaster)
1306
                {
1307
                    SD_SetDigiDevice (sds_SoundBlaster);
1308
                    DrawSoundMenu ();
1309
                    ShootSnd ();
1310
                }
1311
                break;
1312
 
1313
                //
1314
                // MUSIC
1315
                //
1316
            case 10:
1317
                if (MusicMode != smm_Off)
1318
                {
1319
                    SD_SetMusicMode (smm_Off);
1320
                    DrawSoundMenu ();
1321
                    ShootSnd ();
1322
                }
1323
                break;
1324
            case 11:
1325
                if (MusicMode != smm_AdLib)
1326
                {
1327
                    SD_SetMusicMode (smm_AdLib);
1328
                    DrawSoundMenu ();
1329
                    ShootSnd ();
1330
                    StartCPMusic (MENUSONG);
1331
                }
1332
                break;
1333
        }
1334
    }
1335
    while (which >= 0);
1336
 
1337
    MenuFadeOut ();
1338
 
1339
#ifdef SPEAR
1340
    UnCacheLump (SOUND_LUMP_START, SOUND_LUMP_END);
1341
    CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1342
#endif
1343
    return 0;
1344
}
1345
 
1346
 
1347
//////////////////////
1348
//
1349
// DRAW THE SOUND MENU
1350
//
1351
void
1352
DrawSoundMenu (void)
1353
{
1354
    int i, on;
1355
 
1356
 
1357
#ifdef JAPAN
1358
    CA_CacheScreen (S_SOUNDPIC);
1359
#else
1360
    //
1361
    // DRAW SOUND MENU
1362
    //
1363
    ClearMScreen ();
1364
    VWB_DrawPic (112, 184, C_MOUSELBACKPIC);
1365
 
1366
    DrawWindow (SM_X - 8, SM_Y1 - 3, SM_W, SM_H1, BKGDCOLOR);
1367
    DrawWindow (SM_X - 8, SM_Y2 - 3, SM_W, SM_H2, BKGDCOLOR);
1368
    DrawWindow (SM_X - 8, SM_Y3 - 3, SM_W, SM_H3, BKGDCOLOR);
1369
#endif
1370
 
1371
    //
1372
    // IF NO ADLIB, NON-CHOOSENESS!
1373
    //
1374
    if (!AdLibPresent && !SoundBlasterPresent)
1375
    {
1376
        SndMenu[2].active = SndMenu[10].active = SndMenu[11].active = 0;
1377
    }
1378
 
1379
    if (!SoundBlasterPresent)
1380
        SndMenu[7].active = 0;
1381
 
1382
    if (!SoundBlasterPresent)
1383
        SndMenu[5].active = 0;
1384
 
1385
    DrawMenu (&SndItems, &SndMenu[0]);
1386
#ifndef JAPAN
1387
    VWB_DrawPic (100, SM_Y1 - 20, C_FXTITLEPIC);
1388
    VWB_DrawPic (100, SM_Y2 - 20, C_DIGITITLEPIC);
1389
    VWB_DrawPic (100, SM_Y3 - 20, C_MUSICTITLEPIC);
1390
#endif
1391
 
1392
    for (i = 0; i < SndItems.amount; i++)
1393
#ifdef JAPAN
1394
        if (i != 3 && i != 4 && i != 8 && i != 9)
1395
#else
1396
        if (SndMenu[i].string[0])
1397
#endif
1398
        {
1399
            //
1400
            // DRAW SELECTED/NOT SELECTED GRAPHIC BUTTONS
1401
            //
1402
            on = 0;
1403
            switch (i)
1404
            {
1405
                    //
1406
                    // SOUND EFFECTS
1407
                    //
1408
                case 0:
1409
                    if (SoundMode == sdm_Off)
1410
                        on = 1;
1411
                    break;
1412
                case 1:
1413
                    if (SoundMode == sdm_PC)
1414
                        on = 1;
1415
                    break;
1416
                case 2:
1417
                    if (SoundMode == sdm_AdLib)
1418
                        on = 1;
1419
                    break;
1420
 
1421
                    //
1422
                    // DIGITIZED SOUND
1423
                    //
1424
                case 5:
1425
                    if (DigiMode == sds_Off)
1426
                        on = 1;
1427
                    break;
1428
                case 6:
1429
//                    if (DigiMode == sds_SoundSource)
1430
//                        on = 1;
1431
                    break;
1432
                case 7:
1433
                    if (DigiMode == sds_SoundBlaster)
1434
                        on = 1;
1435
                    break;
1436
 
1437
                    //
1438
                    // MUSIC
1439
                    //
1440
                case 10:
1441
                    if (MusicMode == smm_Off)
1442
                        on = 1;
1443
                    break;
1444
                case 11:
1445
                    if (MusicMode == smm_AdLib)
1446
                        on = 1;
1447
                    break;
1448
            }
1449
 
1450
            if (on)
1451
                VWB_DrawPic (SM_X + 24, SM_Y1 + i * 13 + 2, C_SELECTEDPIC);
1452
            else
1453
                VWB_DrawPic (SM_X + 24, SM_Y1 + i * 13 + 2, C_NOTSELECTEDPIC);
1454
        }
1455
 
1456
    DrawMenuGun (&SndItems);
1457
    VW_UpdateScreen ();
1458
}
1459
 
1460
 
1461
//
1462
// DRAW LOAD/SAVE IN PROGRESS
1463
//
1464
void
1465
DrawLSAction (int which)
1466
{
1467
#define LSA_X   96
1468
#define LSA_Y   80
1469
#define LSA_W   130
1470
#define LSA_H   42
1471
 
1472
    DrawWindow (LSA_X, LSA_Y, LSA_W, LSA_H, TEXTCOLOR);
1473
    DrawOutline (LSA_X, LSA_Y, LSA_W, LSA_H, 0, HIGHLIGHT);
1474
    VWB_DrawPic (LSA_X + 8, LSA_Y + 5, C_DISKLOADING1PIC);
1475
 
1476
    fontnumber = 1;
1477
    SETFONTCOLOR (0, TEXTCOLOR);
1478
    PrintX = LSA_X + 46;
1479
    PrintY = LSA_Y + 13;
1480
 
1481
    if (!which)
1482
        US_Print (STR_LOADING "...");
1483
    else
1484
        US_Print (STR_SAVING "...");
1485
 
1486
    VW_UpdateScreen ();
1487
}
1488
 
1489
 
1490
////////////////////////////////////////////////////////////////////
1491
//
1492
// LOAD SAVED GAMES
1493
//
1494
////////////////////////////////////////////////////////////////////
1495
int
1496
CP_LoadGame (int quick)
1497
{
1498
    FILE *file;
1499
    int which, exit = 0;
1500
    char name[13];
1501
    char loadpath[300];
1502
 
1503
    strcpy (name, SaveName);
1504
 
1505
    //
1506
    // QUICKLOAD?
1507
    //
1508
    if (quick)
1509
    {
1510
        which = LSItems.curpos;
1511
 
1512
        if (SaveGamesAvail[which])
1513
        {
1514
            name[7] = which + '0';
1515
 
1516
#ifdef _arch_dreamcast
1517
            DC_LoadFromVMU(name);
1518
#endif
1519
 
1520
            if(configdir[0])
1521
                snprintf(loadpath, sizeof(loadpath), "%s/%s", configdir, name);
1522
            else
1523
                strcpy(loadpath, name);
1524
 
1525
            file = fopen (loadpath, "rb");
1526
            fseek (file, 32, SEEK_SET);
1527
            loadedgame = true;
1528
            LoadTheGame (file, 0, 0);
1529
            loadedgame = false;
1530
            fclose (file);
1531
 
1532
            DrawFace ();
1533
            DrawHealth ();
1534
            DrawLives ();
1535
            DrawLevel ();
1536
            DrawAmmo ();
1537
            DrawKeys ();
1538
            DrawWeapon ();
1539
            DrawScore ();
1540
            ContinueMusic (lastgamemusicoffset);
1541
            return 1;
1542
        }
1543
    }
1544
 
1545
 
1546
#ifdef SPEAR
1547
    UnCacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1548
    CacheLump (LOADSAVE_LUMP_START, LOADSAVE_LUMP_END);
1549
#endif
1550
 
1551
    DrawLoadSaveScreen (0);
1552
 
1553
    do
1554
    {
1555
        which = HandleMenu (&LSItems, &LSMenu[0], TrackWhichGame);
1556
        if (which >= 0 && SaveGamesAvail[which])
1557
        {
1558
            ShootSnd ();
1559
            name[7] = which + '0';
1560
 
1561
#ifdef _arch_dreamcast
1562
            DC_LoadFromVMU(name);
1563
#endif
1564
 
1565
            if(configdir[0])
1566
                snprintf(loadpath, sizeof(loadpath), "%s/%s", configdir, name);
1567
            else
1568
                strcpy(loadpath, name);
1569
 
1570
            file = fopen (loadpath, "rb");
1571
            fseek (file, 32, SEEK_SET);
1572
 
1573
            DrawLSAction (0);
1574
            loadedgame = true;
1575
 
1576
            LoadTheGame (file, LSA_X + 8, LSA_Y + 5);
1577
            fclose (file);
1578
 
1579
            StartGame = 1;
1580
            ShootSnd ();
1581
            //
1582
            // CHANGE "READ THIS!" TO NORMAL COLOR
1583
            //
1584
 
1585
#ifndef SPEAR
1586
#ifndef GOODTIMES
1587
            MainMenu[readthis].active = 1;
1588
#endif
1589
#endif
1590
 
1591
            exit = 1;
1592
            break;
1593
        }
1594
 
1595
    }
1596
    while (which >= 0);
1597
 
1598
    MenuFadeOut ();
1599
 
1600
#ifdef SPEAR
1601
    UnCacheLump (LOADSAVE_LUMP_START, LOADSAVE_LUMP_END);
1602
    CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1603
#endif
1604
 
1605
    return exit;
1606
}
1607
 
1608
 
1609
///////////////////////////////////
1610
//
1611
// HIGHLIGHT CURRENT SELECTED ENTRY
1612
//
1613
void
1614
TrackWhichGame (int w)
1615
{
1616
    static int lastgameon = 0;
1617
 
1618
    PrintLSEntry (lastgameon, TEXTCOLOR);
1619
    PrintLSEntry (w, HIGHLIGHT);
1620
 
1621
    lastgameon = w;
1622
}
1623
 
1624
 
1625
////////////////////////////
1626
//
1627
// DRAW THE LOAD/SAVE SCREEN
1628
//
1629
void
1630
DrawLoadSaveScreen (int loadsave)
1631
{
1632
#define DISKX   100
1633
#define DISKY   0
1634
 
1635
    int i;
1636
 
1637
 
1638
    ClearMScreen ();
1639
    fontnumber = 1;
1640
    VWB_DrawPic (112, 184, C_MOUSELBACKPIC);
1641
    DrawWindow (LSM_X - 10, LSM_Y - 5, LSM_W, LSM_H, BKGDCOLOR);
1642
    DrawStripes (10);
1643
 
1644
    if (!loadsave)
1645
        VWB_DrawPic (60, 0, C_LOADGAMEPIC);
1646
    else
1647
        VWB_DrawPic (60, 0, C_SAVEGAMEPIC);
1648
 
1649
    for (i = 0; i < 10; i++)
1650
        PrintLSEntry (i, TEXTCOLOR);
1651
 
1652
    DrawMenu (&LSItems, &LSMenu[0]);
1653
    VW_UpdateScreen ();
1654
    MenuFadeIn ();
1655
    WaitKeyUp ();
1656
}
1657
 
1658
 
1659
///////////////////////////////////////////
1660
//
1661
// PRINT LOAD/SAVE GAME ENTRY W/BOX OUTLINE
1662
//
1663
void
1664
PrintLSEntry (int w, int color)
1665
{
1666
    SETFONTCOLOR (color, BKGDCOLOR);
1667
    DrawOutline (LSM_X + LSItems.indent, LSM_Y + w * 13, LSM_W - LSItems.indent - 15, 11, color,
1668
                 color);
1669
    PrintX = LSM_X + LSItems.indent + 2;
1670
    PrintY = LSM_Y + w * 13 + 1;
1671
    fontnumber = 0;
1672
 
1673
    if (SaveGamesAvail[w])
1674
        US_Print (SaveGameNames[w]);
1675
    else
1676
        US_Print ("      - " STR_EMPTY " -");
1677
 
1678
    fontnumber = 1;
1679
}
1680
 
1681
 
1682
////////////////////////////////////////////////////////////////////
1683
//
1684
// SAVE CURRENT GAME
1685
//
1686
////////////////////////////////////////////////////////////////////
1687
int
1688
CP_SaveGame (int quick)
1689
{
1690
    int which, exit = 0;
1691
    FILE *file;
1692
    char name[13];
1693
    char savepath[300];
1694
    char input[32];
1695
 
1696
    strcpy (name, SaveName);
1697
 
1698
    //
1699
    // QUICKSAVE?
1700
    //
1701
    if (quick)
1702
    {
1703
        which = LSItems.curpos;
1704
 
1705
        if (SaveGamesAvail[which])
1706
        {
1707
            name[7] = which + '0';
1708
 
1709
            if(configdir[0])
1710
                snprintf(savepath, sizeof(savepath), "%s/%s", configdir, name);
1711
            else
1712
                strcpy(savepath, name);
1713
 
1714
            unlink (savepath);
1715
            file = fopen (savepath, "wb");
1716
 
1717
            strcpy (input, &SaveGameNames[which][0]);
1718
 
1719
            fwrite (input, 1, 32, file);
1720
            fseek (file, 32, SEEK_SET);
1721
            SaveTheGame (file, 0, 0);
1722
            fclose (file);
1723
 
1724
#ifdef _arch_dreamcast
1725
            DC_SaveToVMU(name, input);
1726
#endif
1727
 
1728
            return 1;
1729
        }
1730
    }
1731
 
1732
 
1733
#ifdef SPEAR
1734
    UnCacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1735
    CacheLump (LOADSAVE_LUMP_START, LOADSAVE_LUMP_END);
1736
#endif
1737
 
1738
    DrawLoadSaveScreen (1);
1739
 
1740
    do
1741
    {
1742
        which = HandleMenu (&LSItems, &LSMenu[0], TrackWhichGame);
1743
        if (which >= 0)
1744
        {
1745
            //
1746
            // OVERWRITE EXISTING SAVEGAME?
1747
            //
1748
            if (SaveGamesAvail[which])
1749
            {
1750
#ifdef JAPAN
1751
                if (!GetYorN (7, 8, C_JAPSAVEOVERPIC))
1752
#else
1753
                if (!Confirm (GAMESVD))
1754
#endif
1755
                {
1756
                    DrawLoadSaveScreen (1);
1757
                    continue;
1758
                }
1759
                else
1760
                {
1761
                    DrawLoadSaveScreen (1);
1762
                    PrintLSEntry (which, HIGHLIGHT);
1763
                    VW_UpdateScreen ();
1764
                }
1765
            }
1766
 
1767
            ShootSnd ();
1768
 
1769
            strcpy (input, &SaveGameNames[which][0]);
1770
            name[7] = which + '0';
1771
 
1772
            fontnumber = 0;
1773
            if (!SaveGamesAvail[which])
1774
                VWB_Bar (LSM_X + LSItems.indent + 1, LSM_Y + which * 13 + 1,
1775
                         LSM_W - LSItems.indent - 16, 10, BKGDCOLOR);
1776
            VW_UpdateScreen ();
1777
 
1778
            if (US_LineInput
1779
                (LSM_X + LSItems.indent + 2, LSM_Y + which * 13 + 1, input, input, true, 31,
1780
                 LSM_W - LSItems.indent - 30))
1781
            {
1782
                SaveGamesAvail[which] = 1;
1783
                strcpy (&SaveGameNames[which][0], input);
1784
 
1785
                if(configdir[0])
1786
                    snprintf(savepath, sizeof(savepath), "%s/%s", configdir, name);
1787
                else
1788
                    strcpy(savepath, name);
1789
 
1790
                unlink (savepath);
1791
                file = fopen (savepath, "wb");
1792
                fwrite (input, 32, 1, file);
1793
                fseek (file, 32, SEEK_SET);
1794
 
1795
                DrawLSAction (1);
1796
                SaveTheGame (file, LSA_X + 8, LSA_Y + 5);
1797
 
1798
                fclose (file);
1799
 
1800
#ifdef _arch_dreamcast
1801
                DC_SaveToVMU(name, input);
1802
#endif
1803
 
1804
                ShootSnd ();
1805
                exit = 1;
1806
            }
1807
            else
1808
            {
1809
                VWB_Bar (LSM_X + LSItems.indent + 1, LSM_Y + which * 13 + 1,
1810
                         LSM_W - LSItems.indent - 16, 10, BKGDCOLOR);
1811
                PrintLSEntry (which, HIGHLIGHT);
1812
                VW_UpdateScreen ();
1813
                SD_PlaySound (ESCPRESSEDSND);
1814
                continue;
1815
            }
1816
 
1817
            fontnumber = 1;
1818
            break;
1819
        }
1820
 
1821
    }
1822
    while (which >= 0);
1823
 
1824
    MenuFadeOut ();
1825
 
1826
#ifdef SPEAR
1827
    UnCacheLump (LOADSAVE_LUMP_START, LOADSAVE_LUMP_END);
1828
    CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1829
#endif
1830
 
1831
    return exit;
1832
}
1833
 
1834
////////////////////////////////////////////////////////////////////
1835
//
1836
// DEFINE CONTROLS
1837
//
1838
////////////////////////////////////////////////////////////////////
1839
int
1840
CP_Control (int)
1841
{
1842
    int which;
1843
 
1844
#ifdef SPEAR
1845
    UnCacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1846
    CacheLump (CONTROL_LUMP_START, CONTROL_LUMP_END);
1847
#endif
1848
 
1849
    DrawCtlScreen ();
1850
    MenuFadeIn ();
1851
    WaitKeyUp ();
1852
 
1853
    do
1854
    {
1855
        which = HandleMenu (&CtlItems, CtlMenu, NULL);
1856
        switch (which)
1857
        {
1858
            case CTL_MOUSEENABLE:
1859
                mouseenabled ^= 1;
1860
                if(IN_IsInputGrabbed())
1861
                    IN_CenterMouse();
1862
                DrawCtlScreen ();
1863
                CusItems.curpos = -1;
1864
                ShootSnd ();
1865
                break;
1866
 
1867
            case CTL_JOYENABLE:
1868
                joystickenabled ^= 1;
1869
                DrawCtlScreen ();
1870
                CusItems.curpos = -1;
1871
                ShootSnd ();
1872
                break;
1873
 
1874
            case CTL_MOUSESENS:
1875
            case CTL_CUSTOMIZE:
1876
                DrawCtlScreen ();
1877
                MenuFadeIn ();
1878
                WaitKeyUp ();
1879
                break;
1880
        }
1881
    }
1882
    while (which >= 0);
1883
 
1884
    MenuFadeOut ();
1885
 
1886
#ifdef SPEAR
1887
    UnCacheLump (CONTROL_LUMP_START, CONTROL_LUMP_END);
1888
    CacheLump (OPTIONS_LUMP_START, OPTIONS_LUMP_END);
1889
#endif
1890
    return 0;
1891
}
1892
 
1893
 
1894
////////////////////////////////
1895
//
1896
// DRAW MOUSE SENSITIVITY SCREEN
1897
//
1898
void
1899
DrawMouseSens (void)
1900
{
1901
#ifdef JAPAN
1902
    CA_CacheScreen (S_MOUSESENSPIC);
1903
#else
1904
    ClearMScreen ();
1905
    VWB_DrawPic (112, 184, C_MOUSELBACKPIC);
1906
#ifdef SPANISH
1907
    DrawWindow (10, 80, 300, 43, BKGDCOLOR);
1908
#else
1909
    DrawWindow (10, 80, 300, 30, BKGDCOLOR);
1910
#endif
1911
 
1912
    WindowX = 0;
1913
    WindowW = 320;
1914
    PrintY = 82;
1915
    SETFONTCOLOR (READCOLOR, BKGDCOLOR);
1916
    US_CPrint (STR_MOUSEADJ);
1917
 
1918
    SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
1919
#ifdef SPANISH
1920
    PrintX = 14;
1921
    PrintY = 95 + 13;
1922
    US_Print (STR_SLOW);
1923
    PrintX = 252;
1924
    US_Print (STR_FAST);
1925
#else
1926
    PrintX = 14;
1927
    PrintY = 95;
1928
    US_Print (STR_SLOW);
1929
    PrintX = 269;
1930
    US_Print (STR_FAST);
1931
#endif
1932
#endif
1933
 
1934
    VWB_Bar (60, 97, 200, 10, TEXTCOLOR);
1935
    DrawOutline (60, 97, 200, 10, 0, HIGHLIGHT);
1936
    DrawOutline (60 + 20 * mouseadjustment, 97, 20, 10, 0, READCOLOR);
1937
    VWB_Bar (61 + 20 * mouseadjustment, 98, 19, 9, READHCOLOR);
1938
 
1939
    VW_UpdateScreen ();
1940
    MenuFadeIn ();
1941
}
1942
 
1943
 
1944
///////////////////////////
1945
//
1946
// ADJUST MOUSE SENSITIVITY
1947
//
1948
int
1949
MouseSensitivity (int)
1950
{
1951
    ControlInfo ci;
1952
    int exit = 0, oldMA;
1953
 
1954
 
1955
    oldMA = mouseadjustment;
1956
    DrawMouseSens ();
1957
    do
1958
    {
1959
        SDL_Delay(5);
1960
        ReadAnyControl (&ci);
1961
        switch (ci.dir)
1962
        {
1963
            case dir_North:
1964
            case dir_West:
1965
                if (mouseadjustment)
1966
                {
1967
                    mouseadjustment--;
1968
                    VWB_Bar (60, 97, 200, 10, TEXTCOLOR);
1969
                    DrawOutline (60, 97, 200, 10, 0, HIGHLIGHT);
1970
                    DrawOutline (60 + 20 * mouseadjustment, 97, 20, 10, 0, READCOLOR);
1971
                    VWB_Bar (61 + 20 * mouseadjustment, 98, 19, 9, READHCOLOR);
1972
                    VW_UpdateScreen ();
1973
                    SD_PlaySound (MOVEGUN1SND);
1974
                    TicDelay(20);
1975
                }
1976
                break;
1977
 
1978
            case dir_South:
1979
            case dir_East:
1980
                if (mouseadjustment < 9)
1981
                {
1982
                    mouseadjustment++;
1983
                    VWB_Bar (60, 97, 200, 10, TEXTCOLOR);
1984
                    DrawOutline (60, 97, 200, 10, 0, HIGHLIGHT);
1985
                    DrawOutline (60 + 20 * mouseadjustment, 97, 20, 10, 0, READCOLOR);
1986
                    VWB_Bar (61 + 20 * mouseadjustment, 98, 19, 9, READHCOLOR);
1987
                    VW_UpdateScreen ();
1988
                    SD_PlaySound (MOVEGUN1SND);
1989
                    TicDelay(20);
1990
                }
1991
                break;
1992
        }
1993
 
1994
        if (ci.button0 || Keyboard[sc_Space] || Keyboard[sc_Enter])
1995
            exit = 1;
1996
        else if (ci.button1 || Keyboard[sc_Escape])
1997
            exit = 2;
1998
 
1999
    }
2000
    while (!exit);
2001
 
2002
    if (exit == 2)
2003
    {
2004
        mouseadjustment = oldMA;
2005
        SD_PlaySound (ESCPRESSEDSND);
2006
    }
2007
    else
2008
        SD_PlaySound (SHOOTSND);
2009
 
2010
    WaitKeyUp ();
2011
    MenuFadeOut ();
2012
 
2013
    return 0;
2014
}
2015
 
2016
 
2017
///////////////////////////
2018
//
2019
// DRAW CONTROL MENU SCREEN
2020
//
2021
void
2022
DrawCtlScreen (void)
2023
{
2024
    int i, x, y;
2025
 
2026
#ifdef JAPAN
2027
    CA_CacheScreen (S_CONTROLPIC);
2028
#else
2029
    ClearMScreen ();
2030
    DrawStripes (10);
2031
    VWB_DrawPic (80, 0, C_CONTROLPIC);
2032
    VWB_DrawPic (112, 184, C_MOUSELBACKPIC);
2033
    DrawWindow (CTL_X - 8, CTL_Y - 5, CTL_W, CTL_H, BKGDCOLOR);
2034
#endif
2035
    WindowX = 0;
2036
    WindowW = 320;
2037
    SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
2038
 
2039
    if (IN_JoyPresent())
2040
        CtlMenu[CTL_JOYENABLE].active = 1;
2041
 
2042
    if (MousePresent)
2043
    {
2044
        CtlMenu[CTL_MOUSESENS].active = CtlMenu[CTL_MOUSEENABLE].active = 1;
2045
    }
2046
 
2047
    CtlMenu[CTL_MOUSESENS].active = mouseenabled;
2048
 
2049
 
2050
    DrawMenu (&CtlItems, CtlMenu);
2051
 
2052
 
2053
    x = CTL_X + CtlItems.indent - 24;
2054
    y = CTL_Y + 3;
2055
    if (mouseenabled)
2056
        VWB_DrawPic (x, y, C_SELECTEDPIC);
2057
    else
2058
        VWB_DrawPic (x, y, C_NOTSELECTEDPIC);
2059
 
2060
    y = CTL_Y + 29;
2061
    if (joystickenabled)
2062
        VWB_DrawPic (x, y, C_SELECTEDPIC);
2063
    else
2064
        VWB_DrawPic (x, y, C_NOTSELECTEDPIC);
2065
 
2066
    //
2067
    // PICK FIRST AVAILABLE SPOT
2068
    //
2069
    if (CtlItems.curpos < 0 || !CtlMenu[CtlItems.curpos].active)
2070
    {
2071
        for (i = 0; i < CtlItems.amount; i++)
2072
        {
2073
            if (CtlMenu[i].active)
2074
            {
2075
                CtlItems.curpos = i;
2076
                break;
2077
            }
2078
        }
2079
    }
2080
 
2081
    DrawMenuGun (&CtlItems);
2082
    VW_UpdateScreen ();
2083
}
2084
 
2085
 
2086
////////////////////////////////////////////////////////////////////
2087
//
2088
// CUSTOMIZE CONTROLS
2089
//
2090
////////////////////////////////////////////////////////////////////
2091
enum
2092
{ FIRE, STRAFE, RUN, OPEN };
2093
char mbarray[4][3] = { "b0", "b1", "b2", "b3" };
2094
int8_t order[4] = { RUN, OPEN, FIRE, STRAFE };
2095
 
2096
 
2097
int
2098
CustomControls (int)
2099
{
2100
    int which;
2101
 
2102
    DrawCustomScreen ();
2103
    do
2104
    {
2105
        which = HandleMenu (&CusItems, &CusMenu[0], FixupCustom);
2106
        switch (which)
2107
        {
2108
            case 0:
2109
                DefineMouseBtns ();
2110
                DrawCustMouse (1);
2111
                break;
2112
            case 3:
2113
                DefineJoyBtns ();
2114
                DrawCustJoy (0);
2115
                break;
2116
            case 6:
2117
                DefineKeyBtns ();
2118
                DrawCustKeybd (0);
2119
                break;
2120
            case 8:
2121
                DefineKeyMove ();
2122
                DrawCustKeys (0);
2123
        }
2124
    }
2125
    while (which >= 0);
2126
 
2127
    MenuFadeOut ();
2128
 
2129
    return 0;
2130
}
2131
 
2132
 
2133
////////////////////////
2134
//
2135
// DEFINE THE MOUSE BUTTONS
2136
//
2137
void
2138
DefineMouseBtns (void)
2139
{
2140
    CustomCtrls mouseallowed = { 0, 1, 1, 1 };
2141
    EnterCtrlData (2, &mouseallowed, DrawCustMouse, PrintCustMouse, MOUSE);
2142
}
2143
 
2144
 
2145
////////////////////////
2146
//
2147
// DEFINE THE JOYSTICK BUTTONS
2148
//
2149
void
2150
DefineJoyBtns (void)
2151
{
2152
    CustomCtrls joyallowed = { 1, 1, 1, 1 };
2153
    EnterCtrlData (5, &joyallowed, DrawCustJoy, PrintCustJoy, JOYSTICK);
2154
}
2155
 
2156
 
2157
////////////////////////
2158
//
2159
// DEFINE THE KEYBOARD BUTTONS
2160
//
2161
void
2162
DefineKeyBtns (void)
2163
{
2164
    CustomCtrls keyallowed = { 1, 1, 1, 1 };
2165
    EnterCtrlData (8, &keyallowed, DrawCustKeybd, PrintCustKeybd, KEYBOARDBTNS);
2166
}
2167
 
2168
 
2169
////////////////////////
2170
//
2171
// DEFINE THE KEYBOARD BUTTONS
2172
//
2173
void
2174
DefineKeyMove (void)
2175
{
2176
    CustomCtrls keyallowed = { 1, 1, 1, 1 };
2177
    EnterCtrlData (10, &keyallowed, DrawCustKeys, PrintCustKeys, KEYBOARDMOVE);
2178
}
2179
 
2180
 
2181
////////////////////////
2182
//
2183
// ENTER CONTROL DATA FOR ANY TYPE OF CONTROL
2184
//
2185
enum
2186
{ FWRD, RIGHT, BKWD, LEFT };
2187
int moveorder[4] = { LEFT, RIGHT, FWRD, BKWD };
2188
 
2189
void
2190
EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*PrintRtn) (int),
2191
               int type)
2192
{
2193
    int j, exit, tick, redraw, which, x, picked, lastFlashTime;
2194
    ControlInfo ci;
2195
 
2196
 
2197
    ShootSnd ();
2198
    PrintY = CST_Y + 13 * index;
2199
    IN_ClearKeysDown ();
2200
    exit = 0;
2201
    redraw = 1;
2202
    //
2203
    // FIND FIRST SPOT IN ALLOWED ARRAY
2204
    //
2205
    for (j = 0; j < 4; j++)
2206
        if (cust->allowed[j])
2207
        {
2208
            which = j;
2209
            break;
2210
        }
2211
 
2212
    do
2213
    {
2214
        if (redraw)
2215
        {
2216
            x = CST_START + CST_SPC * which;
2217
            DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2218
 
2219
            DrawRtn (1);
2220
            DrawWindow (x - 2, PrintY, CST_SPC, 11, TEXTCOLOR);
2221
            DrawOutline (x - 2, PrintY, CST_SPC, 11, 0, HIGHLIGHT);
2222
            SETFONTCOLOR (0, TEXTCOLOR);
2223
            PrintRtn (which);
2224
            PrintX = x;
2225
            SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
2226
            VW_UpdateScreen ();
2227
            WaitKeyUp ();
2228
            redraw = 0;
2229
        }
2230
 
2231
        SDL_Delay(5);
2232
        ReadAnyControl (&ci);
2233
 
2234
        if (type == MOUSE || type == JOYSTICK)
2235
            if (IN_KeyDown (sc_Enter) || IN_KeyDown (sc_Control) || IN_KeyDown (sc_Alt))
2236
            {
2237
                IN_ClearKeysDown ();
2238
                ci.button0 = ci.button1 = false;
2239
            }
2240
 
2241
        //
2242
        // CHANGE BUTTON VALUE?
2243
        //
2244
        if ((type != KEYBOARDBTNS && type != KEYBOARDMOVE) && (ci.button0 | ci.button1 | ci.button2 | ci.button3) ||
2245
            ((type == KEYBOARDBTNS || type == KEYBOARDMOVE) && LastScan == sc_Enter))
2246
        {
2247
            lastFlashTime = GetTimeCount();
2248
            tick = picked = 0;
2249
            SETFONTCOLOR (0, TEXTCOLOR);
2250
 
2251
            if (type == KEYBOARDBTNS || type == KEYBOARDMOVE)
2252
                IN_ClearKeysDown ();
2253
 
2254
            while(1)
2255
            {
2256
                int button, result = 0;
2257
 
2258
                //
2259
                // FLASH CURSOR
2260
                //
2261
                if (GetTimeCount() - lastFlashTime > 10)
2262
                {
2263
                    switch (tick)
2264
                    {
2265
                        case 0:
2266
                            VWB_Bar (x, PrintY + 1, CST_SPC - 2, 10, TEXTCOLOR);
2267
                            break;
2268
                        case 1:
2269
                            PrintX = x;
2270
                            US_Print ("?");
2271
                            SD_PlaySound (HITWALLSND);
2272
                    }
2273
                    tick ^= 1;
2274
                    lastFlashTime = GetTimeCount();
2275
                    VW_UpdateScreen ();
2276
                }
2277
                else SDL_Delay(5);
2278
 
2279
                //
2280
                // WHICH TYPE OF INPUT DO WE PROCESS?
2281
                //
2282
                switch (type)
2283
                {
2284
                    case MOUSE:
2285
                        button = IN_MouseButtons();
2286
                        switch (button)
2287
                        {
2288
                            case 1:
2289
                                result = 1;
2290
                                break;
2291
                            case 2:
2292
                                result = 2;
2293
                                break;
2294
                            case 4:
2295
                                result = 3;
2296
                                break;
2297
                        }
2298
 
2299
                        if (result)
2300
                        {
2301
                            for (int z = 0; z < 4; z++)
2302
                                if (order[which] == buttonmouse[z])
2303
                                {
2304
                                    buttonmouse[z] = bt_nobutton;
2305
                                    break;
2306
                                }
2307
 
2308
                            buttonmouse[result - 1] = order[which];
2309
                            picked = 1;
2310
                            SD_PlaySound (SHOOTDOORSND);
2311
                        }
2312
                        break;
2313
 
2314
                    case JOYSTICK:
2315
                        if (ci.button0)
2316
                            result = 1;
2317
                        else if (ci.button1)
2318
                            result = 2;
2319
                        else if (ci.button2)
2320
                            result = 3;
2321
                        else if (ci.button3)
2322
                            result = 4;
2323
 
2324
                        if (result)
2325
                        {
2326
                            for (int z = 0; z < 4; z++)
2327
                            {
2328
                                if (order[which] == buttonjoy[z])
2329
                                {
2330
                                    buttonjoy[z] = bt_nobutton;
2331
                                    break;
2332
                                }
2333
                            }
2334
 
2335
                            buttonjoy[result - 1] = order[which];
2336
                            picked = 1;
2337
                            SD_PlaySound (SHOOTDOORSND);
2338
                        }
2339
                        break;
2340
 
2341
                    case KEYBOARDBTNS:
2342
                        if (LastScan && LastScan != sc_Escape)
2343
                        {
2344
                            buttonscan[order[which]] = LastScan;
2345
                            picked = 1;
2346
                            ShootSnd ();
2347
                            IN_ClearKeysDown ();
2348
                        }
2349
                        break;
2350
 
2351
                    case KEYBOARDMOVE:
2352
                        if (LastScan && LastScan != sc_Escape)
2353
                        {
2354
                            dirscan[moveorder[which]] = LastScan;
2355
                            picked = 1;
2356
                            ShootSnd ();
2357
                            IN_ClearKeysDown ();
2358
                        }
2359
                        break;
2360
                }
2361
 
2362
                //
2363
                // EXIT INPUT?
2364
                //
2365
                if (IN_KeyDown (sc_Escape) || type != JOYSTICK && ci.button1)
2366
                {
2367
                    picked = 1;
2368
                    SD_PlaySound (ESCPRESSEDSND);
2369
                }
2370
 
2371
                if(picked) break;
2372
 
2373
                ReadAnyControl (&ci);
2374
            }
2375
 
2376
            SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
2377
            redraw = 1;
2378
            WaitKeyUp ();
2379
            continue;
2380
        }
2381
 
2382
        if (ci.button1 || IN_KeyDown (sc_Escape))
2383
            exit = 1;
2384
 
2385
        //
2386
        // MOVE TO ANOTHER SPOT?
2387
        //
2388
        switch (ci.dir)
2389
        {
2390
            case dir_West:
2391
                do
2392
                {
2393
                    which--;
2394
                    if (which < 0)
2395
                        which = 3;
2396
                }
2397
                while (!cust->allowed[which]);
2398
                redraw = 1;
2399
                SD_PlaySound (MOVEGUN1SND);
2400
                while (ReadAnyControl (&ci), ci.dir != dir_None) SDL_Delay(5);
2401
                IN_ClearKeysDown ();
2402
                break;
2403
 
2404
            case dir_East:
2405
                do
2406
                {
2407
                    which++;
2408
                    if (which > 3)
2409
                        which = 0;
2410
                }
2411
                while (!cust->allowed[which]);
2412
                redraw = 1;
2413
                SD_PlaySound (MOVEGUN1SND);
2414
                while (ReadAnyControl (&ci), ci.dir != dir_None) SDL_Delay(5);
2415
                IN_ClearKeysDown ();
2416
                break;
2417
            case dir_North:
2418
            case dir_South:
2419
                exit = 1;
2420
        }
2421
    }
2422
    while (!exit);
2423
 
2424
    SD_PlaySound (ESCPRESSEDSND);
2425
    WaitKeyUp ();
2426
    DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2427
}
2428
 
2429
 
2430
////////////////////////
2431
//
2432
// FIXUP GUN CURSOR OVERDRAW SHIT
2433
//
2434
void
2435
FixupCustom (int w)
2436
{
2437
    static int lastwhich = -1;
2438
    int y = CST_Y + 26 + w * 13;
2439
 
2440
 
2441
    VWB_Hlin (7, 32, y - 1, DEACTIVE);
2442
    VWB_Hlin (7, 32, y + 12, BORD2COLOR);
2443
#ifndef SPEAR
2444
    VWB_Hlin (7, 32, y - 2, BORDCOLOR);
2445
    VWB_Hlin (7, 32, y + 13, BORDCOLOR);
2446
#else
2447
    VWB_Hlin (7, 32, y - 2, BORD2COLOR);
2448
    VWB_Hlin (7, 32, y + 13, BORD2COLOR);
2449
#endif
2450
 
2451
    switch (w)
2452
    {
2453
        case 0:
2454
            DrawCustMouse (1);
2455
            break;
2456
        case 3:
2457
            DrawCustJoy (1);
2458
            break;
2459
        case 6:
2460
            DrawCustKeybd (1);
2461
            break;
2462
        case 8:
2463
            DrawCustKeys (1);
2464
    }
2465
 
2466
 
2467
    if (lastwhich >= 0)
2468
    {
2469
        y = CST_Y + 26 + lastwhich * 13;
2470
        VWB_Hlin (7, 32, y - 1, DEACTIVE);
2471
        VWB_Hlin (7, 32, y + 12, BORD2COLOR);
2472
#ifndef SPEAR
2473
        VWB_Hlin (7, 32, y - 2, BORDCOLOR);
2474
        VWB_Hlin (7, 32, y + 13, BORDCOLOR);
2475
#else
2476
        VWB_Hlin (7, 32, y - 2, BORD2COLOR);
2477
        VWB_Hlin (7, 32, y + 13, BORD2COLOR);
2478
#endif
2479
 
2480
        if (lastwhich != w)
2481
            switch (lastwhich)
2482
            {
2483
                case 0:
2484
                    DrawCustMouse (0);
2485
                    break;
2486
                case 3:
2487
                    DrawCustJoy (0);
2488
                    break;
2489
                case 6:
2490
                    DrawCustKeybd (0);
2491
                    break;
2492
                case 8:
2493
                    DrawCustKeys (0);
2494
            }
2495
    }
2496
 
2497
    lastwhich = w;
2498
}
2499
 
2500
 
2501
////////////////////////
2502
//
2503
// DRAW CUSTOMIZE SCREEN
2504
//
2505
void
2506
DrawCustomScreen (void)
2507
{
2508
    int i;
2509
 
2510
 
2511
#ifdef JAPAN
2512
    CA_CacheScreen (S_CUSTOMPIC);
2513
    fontnumber = 1;
2514
 
2515
    PrintX = CST_START;
2516
    PrintY = CST_Y + 26;
2517
    DrawCustMouse (0);
2518
 
2519
    PrintX = CST_START;
2520
    US_Print ("\n\n\n");
2521
    DrawCustJoy (0);
2522
 
2523
    PrintX = CST_START;
2524
    US_Print ("\n\n\n");
2525
    DrawCustKeybd (0);
2526
 
2527
    PrintX = CST_START;
2528
    US_Print ("\n\n\n");
2529
    DrawCustKeys (0);
2530
#else
2531
    ClearMScreen ();
2532
    WindowX = 0;
2533
    WindowW = 320;
2534
    VWB_DrawPic (112, 184, C_MOUSELBACKPIC);
2535
    DrawStripes (10);
2536
    VWB_DrawPic (80, 0, C_CUSTOMIZEPIC);
2537
 
2538
    //
2539
    // MOUSE
2540
    //
2541
    SETFONTCOLOR (READCOLOR, BKGDCOLOR);
2542
    WindowX = 0;
2543
    WindowW = 320;
2544
 
2545
#ifndef SPEAR
2546
    PrintY = CST_Y;
2547
    US_CPrint ("Mouse\n");
2548
#else
2549
    PrintY = CST_Y + 13;
2550
    VWB_DrawPic (128, 48, C_MOUSEPIC);
2551
#endif
2552
 
2553
    SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
2554
#ifdef SPANISH
2555
    PrintX = CST_START - 16;
2556
    US_Print (STR_CRUN);
2557
    PrintX = CST_START - 16 + CST_SPC * 1;
2558
    US_Print (STR_COPEN);
2559
    PrintX = CST_START - 16 + CST_SPC * 2;
2560
    US_Print (STR_CFIRE);
2561
    PrintX = CST_START - 16 + CST_SPC * 3;
2562
    US_Print (STR_CSTRAFE "\n");
2563
#else
2564
    PrintX = CST_START;
2565
    US_Print (STR_CRUN);
2566
    PrintX = CST_START + CST_SPC * 1;
2567
    US_Print (STR_COPEN);
2568
    PrintX = CST_START + CST_SPC * 2;
2569
    US_Print (STR_CFIRE);
2570
    PrintX = CST_START + CST_SPC * 3;
2571
    US_Print (STR_CSTRAFE "\n");
2572
#endif
2573
 
2574
    DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2575
    DrawCustMouse (0);
2576
    US_Print ("\n");
2577
 
2578
 
2579
    //
2580
    // JOYSTICK/PAD
2581
    //
2582
#ifndef SPEAR
2583
    SETFONTCOLOR (READCOLOR, BKGDCOLOR);
2584
    US_CPrint ("Joystick/Gravis GamePad\n");
2585
#else
2586
    PrintY += 13;
2587
    VWB_DrawPic (40, 88, C_JOYSTICKPIC);
2588
#endif
2589
 
2590
#ifdef SPEAR
2591
    VWB_DrawPic (112, 120, C_KEYBOARDPIC);
2592
#endif
2593
 
2594
    SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
2595
#ifdef SPANISH
2596
    PrintX = CST_START - 16;
2597
    US_Print (STR_CRUN);
2598
    PrintX = CST_START - 16 + CST_SPC * 1;
2599
    US_Print (STR_COPEN);
2600
    PrintX = CST_START - 16 + CST_SPC * 2;
2601
    US_Print (STR_CFIRE);
2602
    PrintX = CST_START - 16 + CST_SPC * 3;
2603
    US_Print (STR_CSTRAFE "\n");
2604
#else
2605
    PrintX = CST_START;
2606
    US_Print (STR_CRUN);
2607
    PrintX = CST_START + CST_SPC * 1;
2608
    US_Print (STR_COPEN);
2609
    PrintX = CST_START + CST_SPC * 2;
2610
    US_Print (STR_CFIRE);
2611
    PrintX = CST_START + CST_SPC * 3;
2612
    US_Print (STR_CSTRAFE "\n");
2613
#endif
2614
    DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2615
    DrawCustJoy (0);
2616
    US_Print ("\n");
2617
 
2618
 
2619
    //
2620
    // KEYBOARD
2621
    //
2622
#ifndef SPEAR
2623
    SETFONTCOLOR (READCOLOR, BKGDCOLOR);
2624
    US_CPrint ("Keyboard\n");
2625
#else
2626
    PrintY += 13;
2627
#endif
2628
    SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
2629
#ifdef SPANISH
2630
    PrintX = CST_START - 16;
2631
    US_Print (STR_CRUN);
2632
    PrintX = CST_START - 16 + CST_SPC * 1;
2633
    US_Print (STR_COPEN);
2634
    PrintX = CST_START - 16 + CST_SPC * 2;
2635
    US_Print (STR_CFIRE);
2636
    PrintX = CST_START - 16 + CST_SPC * 3;
2637
    US_Print (STR_CSTRAFE "\n");
2638
#else
2639
    PrintX = CST_START;
2640
    US_Print (STR_CRUN);
2641
    PrintX = CST_START + CST_SPC * 1;
2642
    US_Print (STR_COPEN);
2643
    PrintX = CST_START + CST_SPC * 2;
2644
    US_Print (STR_CFIRE);
2645
    PrintX = CST_START + CST_SPC * 3;
2646
    US_Print (STR_CSTRAFE "\n");
2647
#endif
2648
    DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2649
    DrawCustKeybd (0);
2650
    US_Print ("\n");
2651
 
2652
 
2653
    //
2654
    // KEYBOARD MOVE KEYS
2655
    //
2656
    SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
2657
#ifdef SPANISH
2658
    PrintX = 4;
2659
    US_Print (STR_LEFT);
2660
    US_Print ("/");
2661
    US_Print (STR_RIGHT);
2662
    US_Print ("/");
2663
    US_Print (STR_FRWD);
2664
    US_Print ("/");
2665
    US_Print (STR_BKWD "\n");
2666
#else
2667
    PrintX = CST_START;
2668
    US_Print (STR_LEFT);
2669
    PrintX = CST_START + CST_SPC * 1;
2670
    US_Print (STR_RIGHT);
2671
    PrintX = CST_START + CST_SPC * 2;
2672
    US_Print (STR_FRWD);
2673
    PrintX = CST_START + CST_SPC * 3;
2674
    US_Print (STR_BKWD "\n");
2675
#endif
2676
    DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2677
    DrawCustKeys (0);
2678
#endif
2679
    //
2680
    // PICK STARTING POINT IN MENU
2681
    //
2682
    if (CusItems.curpos < 0)
2683
        for (i = 0; i < CusItems.amount; i++)
2684
            if (CusMenu[i].active)
2685
            {
2686
                CusItems.curpos = i;
2687
                break;
2688
            }
2689
 
2690
 
2691
    VW_UpdateScreen ();
2692
    MenuFadeIn ();
2693
}
2694
 
2695
 
2696
void
2697
PrintCustMouse (int i)
2698
{
2699
    int j;
2700
 
2701
    for (j = 0; j < 4; j++)
2702
        if (order[i] == buttonmouse[j])
2703
        {
2704
            PrintX = CST_START + CST_SPC * i;
2705
            US_Print (mbarray[j]);
2706
            break;
2707
        }
2708
}
2709
 
2710
void
2711
DrawCustMouse (int hilight)
2712
{
2713
    int i, color;
2714
 
2715
 
2716
    color = TEXTCOLOR;
2717
    if (hilight)
2718
        color = HIGHLIGHT;
2719
    SETFONTCOLOR (color, BKGDCOLOR);
2720
 
2721
    if (!mouseenabled)
2722
    {
2723
        SETFONTCOLOR (DEACTIVE, BKGDCOLOR);
2724
        CusMenu[0].active = 0;
2725
    }
2726
    else
2727
        CusMenu[0].active = 1;
2728
 
2729
    PrintY = CST_Y + 13 * 2;
2730
    for (i = 0; i < 4; i++)
2731
        PrintCustMouse (i);
2732
}
2733
 
2734
void
2735
PrintCustJoy (int i)
2736
{
2737
    for (int j = 0; j < 4; j++)
2738
    {
2739
        if (order[i] == buttonjoy[j])
2740
        {
2741
            PrintX = CST_START + CST_SPC * i;
2742
            US_Print (mbarray[j]);
2743
            break;
2744
        }
2745
    }
2746
}
2747
 
2748
void
2749
DrawCustJoy (int hilight)
2750
{
2751
    int i, color;
2752
 
2753
    color = TEXTCOLOR;
2754
    if (hilight)
2755
        color = HIGHLIGHT;
2756
    SETFONTCOLOR (color, BKGDCOLOR);
2757
 
2758
    if (!joystickenabled)
2759
    {
2760
        SETFONTCOLOR (DEACTIVE, BKGDCOLOR);
2761
        CusMenu[3].active = 0;
2762
    }
2763
    else
2764
        CusMenu[3].active = 1;
2765
 
2766
    PrintY = CST_Y + 13 * 5;
2767
    for (i = 0; i < 4; i++)
2768
        PrintCustJoy (i);
2769
}
2770
 
2771
 
2772
void
2773
PrintCustKeybd (int i)
2774
{
2775
    PrintX = CST_START + CST_SPC * i;
2776
    US_Print ((const char *) IN_GetScanName (buttonscan[order[i]]));
2777
}
2778
 
2779
void
2780
DrawCustKeybd (int hilight)
2781
{
2782
    int i, color;
2783
 
2784
 
2785
    color = TEXTCOLOR;
2786
    if (hilight)
2787
        color = HIGHLIGHT;
2788
    SETFONTCOLOR (color, BKGDCOLOR);
2789
 
2790
    PrintY = CST_Y + 13 * 8;
2791
    for (i = 0; i < 4; i++)
2792
        PrintCustKeybd (i);
2793
}
2794
 
2795
void
2796
PrintCustKeys (int i)
2797
{
2798
    PrintX = CST_START + CST_SPC * i;
2799
    US_Print ((const char *) IN_GetScanName (dirscan[moveorder[i]]));
2800
}
2801
 
2802
void
2803
DrawCustKeys (int hilight)
2804
{
2805
    int i, color;
2806
 
2807
 
2808
    color = TEXTCOLOR;
2809
    if (hilight)
2810
        color = HIGHLIGHT;
2811
    SETFONTCOLOR (color, BKGDCOLOR);
2812
 
2813
    PrintY = CST_Y + 13 * 10;
2814
    for (i = 0; i < 4; i++)
2815
        PrintCustKeys (i);
2816
}
2817
 
2818
 
2819
////////////////////////////////////////////////////////////////////
2820
//
2821
// CHANGE SCREEN VIEWING SIZE
2822
//
2823
////////////////////////////////////////////////////////////////////
2824
int
2825
CP_ChangeView (int)
2826
{
2827
    int exit = 0, oldview, newview;
2828
    ControlInfo ci;
2829
 
2830
    WindowX = WindowY = 0;
2831
    WindowW = 320;
2832
    WindowH = 200;
2833
    newview = oldview = viewsize;
2834
    DrawChangeView (oldview);
2835
    MenuFadeIn ();
2836
 
2837
    do
2838
    {
2839
        CheckPause ();
2840
        SDL_Delay(5);
2841
        ReadAnyControl (&ci);
2842
        switch (ci.dir)
2843
        {
2844
            case dir_South:
2845
            case dir_West:
2846
                newview--;
2847
                if (newview < 4)
2848
                    newview = 4;
2849
                if(newview >= 19) DrawChangeView(newview);
2850
                else ShowViewSize (newview);
2851
                VW_UpdateScreen ();
2852
                SD_PlaySound (HITWALLSND);
2853
                TicDelay (10);
2854
                break;
2855
 
2856
            case dir_North:
2857
            case dir_East:
2858
                newview++;
2859
                if (newview >= 21)
2860
                {
2861
                    newview = 21;
2862
                    DrawChangeView(newview);
2863
                }
2864
                else ShowViewSize (newview);
2865
                VW_UpdateScreen ();
2866
                SD_PlaySound (HITWALLSND);
2867
                TicDelay (10);
2868
                break;
2869
        }
2870
 
2871
        if (ci.button0 || Keyboard[sc_Enter])
2872
            exit = 1;
2873
        else if (ci.button1 || Keyboard[sc_Escape])
2874
        {
2875
            SD_PlaySound (ESCPRESSEDSND);
2876
            MenuFadeOut ();
2877
            if(screenHeight % 200 != 0)
2878
                VL_ClearScreen(0);
2879
            return 0;
2880
        }
2881
    }
2882
    while (!exit);
2883
 
2884
    if (oldview != newview)
2885
    {
2886
        SD_PlaySound (SHOOTSND);
2887
        Message (STR_THINK "...");
2888
        NewViewSize (newview);
2889
    }
2890
 
2891
    ShootSnd ();
2892
    MenuFadeOut ();
2893
    if(screenHeight % 200 != 0)
2894
        VL_ClearScreen(0);
2895
 
2896
    return 0;
2897
}
2898
 
2899
 
2900
/////////////////////////////
2901
//
2902
// DRAW THE CHANGEVIEW SCREEN
2903
//
2904
void
2905
DrawChangeView (int view)
2906
{
2907
    int rescaledHeight = screenHeight / scaleFactor;
2908
    if(view != 21) VWB_Bar (0, rescaledHeight - 40, 320, 40, bordercol);
2909
 
2910
#ifdef JAPAN
2911
    CA_CacheScreen (S_CHANGEPIC);
2912
 
2913
    ShowViewSize (view);
2914
#else
2915
    ShowViewSize (view);
2916
 
2917
    PrintY = (screenHeight / scaleFactor) - 39;
2918
    WindowX = 0;
2919
    WindowY = 320;                                  // TODO: Check this!
2920
    SETFONTCOLOR (HIGHLIGHT, BKGDCOLOR);
2921
 
2922
    US_CPrint (STR_SIZE1 "\n");
2923
    US_CPrint (STR_SIZE2 "\n");
2924
    US_CPrint (STR_SIZE3);
2925
#endif
2926
    VW_UpdateScreen ();
2927
}
2928
 
2929
 
2930
////////////////////////////////////////////////////////////////////
2931
//
2932
// QUIT THIS INFERNAL GAME!
2933
//
2934
////////////////////////////////////////////////////////////////////
2935
int
2936
CP_Quit (int)
2937
{
2938
#ifdef JAPAN
2939
    if (GetYorN (7, 11, C_QUITMSGPIC))
2940
#else
2941
 
2942
#ifdef SPANISH
2943
    if (Confirm (ENDGAMESTR))
2944
#else
2945
    if (Confirm (endStrings[US_RndT () & 0x7 + (US_RndT () & 1)]))
2946
#endif
2947
 
2948
#endif
2949
    {
2950
        VW_UpdateScreen ();
2951
        SD_MusicOff ();
2952
        SD_StopSound ();
2953
        MenuFadeOut ();
2954
        Quit (NULL);
2955
    }
2956
 
2957
    DrawMainMenu ();
2958
    return 0;
2959
}
2960
 
2961
 
2962
////////////////////////////////////////////////////////////////////
2963
//
2964
// HANDLE INTRO SCREEN (SYSTEM CONFIG)
2965
//
2966
////////////////////////////////////////////////////////////////////
2967
void
2968
IntroScreen (void)
2969
{
2970
#ifdef SPEAR
2971
 
2972
#define MAINCOLOR       0x4f
2973
#define EMSCOLOR        0x4f
2974
#define XMSCOLOR        0x4f
2975
 
2976
#else
2977
 
2978
#define MAINCOLOR       0x6c
2979
#define EMSCOLOR        0x6c    // 0x4f
2980
#define XMSCOLOR        0x6c    // 0x7f
2981
 
2982
#endif
2983
#define FILLCOLOR       14
2984
 
2985
//      long memory;
2986
//      long emshere,xmshere;
2987
    int i;
2988
/*      int ems[10]={100,200,300,400,500,600,700,800,900,1000},
2989
                xms[10]={100,200,300,400,500,600,700,800,900,1000};
2990
        int main[10]={32,64,96,128,160,192,224,256,288,320};*/
2991
 
2992
 
2993
    //
2994
    // DRAW MAIN MEMORY
2995
    //
2996
#ifdef ABCAUS
2997
    memory = (1023l + mminfo.nearheap + mminfo.farheap) / 1024l;
2998
    for (i = 0; i < 10; i++)
2999
        if (memory >= main[i])
3000
            VWB_Bar (49, 163 - 8 * i, 6, 5, MAINCOLOR - i);
3001
 
3002
    //
3003
    // DRAW EMS MEMORY
3004
    //
3005
    if (EMSPresent)
3006
    {
3007
        emshere = 4l * EMSPagesAvail;
3008
        for (i = 0; i < 10; i++)
3009
            if (emshere >= ems[i])
3010
                VWB_Bar (89, 163 - 8 * i, 6, 5, EMSCOLOR - i);
3011
    }
3012
 
3013
    //
3014
    // DRAW XMS MEMORY
3015
    //
3016
    if (XMSPresent)
3017
    {
3018
        xmshere = 4l * XMSPagesAvail;
3019
        for (i = 0; i < 10; i++)
3020
            if (xmshere >= xms[i])
3021
                VWB_Bar (129, 163 - 8 * i, 6, 5, XMSCOLOR - i);
3022
    }
3023
#else
3024
    for (i = 0; i < 10; i++)
3025
        VWB_Bar (49, 163 - 8 * i, 6, 5, MAINCOLOR - i);
3026
    for (i = 0; i < 10; i++)
3027
        VWB_Bar (89, 163 - 8 * i, 6, 5, EMSCOLOR - i);
3028
    for (i = 0; i < 10; i++)
3029
        VWB_Bar (129, 163 - 8 * i, 6, 5, XMSCOLOR - i);
3030
#endif
3031
 
3032
 
3033
    //
3034
    // FILL BOXES
3035
    //
3036
    if (MousePresent)
3037
        VWB_Bar (164, 82, 12, 2, FILLCOLOR);
3038
 
3039
    if (IN_JoyPresent())
3040
        VWB_Bar (164, 105, 12, 2, FILLCOLOR);
3041
 
3042
    if (AdLibPresent && !SoundBlasterPresent)
3043
        VWB_Bar (164, 128, 12, 2, FILLCOLOR);
3044
 
3045
    if (SoundBlasterPresent)
3046
        VWB_Bar (164, 151, 12, 2, FILLCOLOR);
3047
 
3048
//    if (SoundSourcePresent)
3049
//        VWB_Bar (164, 174, 12, 2, FILLCOLOR);
3050
}
3051
 
3052
 
3053
////////////////////////////////////////////////////////////////////
3054
////////////////////////////////////////////////////////////////////
3055
//
3056
// SUPPORT ROUTINES
3057
//
3058
////////////////////////////////////////////////////////////////////
3059
////////////////////////////////////////////////////////////////////
3060
 
3061
////////////////////////////////////////////////////////////////////
3062
//
3063
// Clear Menu screens to dark red
3064
//
3065
////////////////////////////////////////////////////////////////////
3066
void
3067
ClearMScreen (void)
3068
{
3069
#ifndef SPEAR
3070
    VWB_Bar (0, 0, 320, 200, BORDCOLOR);
3071
#else
3072
    VWB_DrawPic (0, 0, C_BACKDROPPIC);
3073
#endif
3074
}
3075
 
3076
 
3077
////////////////////////////////////////////////////////////////////
3078
//
3079
// Un/Cache a LUMP of graphics
3080
//
3081
////////////////////////////////////////////////////////////////////
3082
void
3083
CacheLump (int lumpstart, int lumpend)
3084
{
3085
    int i;
3086
 
3087
    for (i = lumpstart; i <= lumpend; i++)
3088
        CA_CacheGrChunk (i);
3089
}
3090
 
3091
 
3092
void
3093
UnCacheLump (int lumpstart, int lumpend)
3094
{
3095
    int i;
3096
 
3097
    for (i = lumpstart; i <= lumpend; i++)
3098
        if (grsegs[i])
3099
            UNCACHEGRCHUNK (i);
3100
}
3101
 
3102
 
3103
////////////////////////////////////////////////////////////////////
3104
//
3105
// Draw a window for a menu
3106
//
3107
////////////////////////////////////////////////////////////////////
3108
void
3109
DrawWindow (int x, int y, int w, int h, int wcolor)
3110
{
3111
    VWB_Bar (x, y, w, h, wcolor);
3112
    DrawOutline (x, y, w, h, BORD2COLOR, DEACTIVE);
3113
}
3114
 
3115
 
3116
void
3117
DrawOutline (int x, int y, int w, int h, int color1, int color2)
3118
{
3119
    VWB_Hlin (x, x + w, y, color2);
3120
    VWB_Vlin (y, y + h, x, color2);
3121
    VWB_Hlin (x, x + w, y + h, color1);
3122
    VWB_Vlin (y, y + h, x + w, color1);
3123
}
3124
 
3125
 
3126
////////////////////////////////////////////////////////////////////
3127
//
3128
// Setup Control Panel stuff - graphics, etc.
3129
//
3130
////////////////////////////////////////////////////////////////////
3131
void
3132
SetupControlPanel (void)
3133
{
3134
    //
3135
    // CACHE GRAPHICS & SOUNDS
3136
    //
3137
    CA_CacheGrChunk (STARTFONT + 1);
3138
#ifndef SPEAR
3139
    CacheLump (CONTROLS_LUMP_START, CONTROLS_LUMP_END);
3140
#else
3141
    CacheLump (BACKDROP_LUMP_START, BACKDROP_LUMP_END);
3142
#endif
3143
 
3144
    SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
3145
    fontnumber = 1;
3146
    WindowH = 200;
3147
    if(screenHeight % 200 != 0)
3148
        VL_ClearScreen(0);
3149
 
3150
    if (!ingame)
3151
        CA_LoadAllSounds ();
3152
    else
3153
        MainMenu[savegame].active = 1;
3154
 
3155
    //
3156
    // CENTER MOUSE
3157
    //
3158
    if(IN_IsInputGrabbed())
3159
        IN_CenterMouse();
3160
}
3161
 
3162
////////////////////////////////////////////////////////////////////
3163
//
3164
// SEE WHICH SAVE GAME FILES ARE AVAILABLE & READ STRING IN
3165
//
3166
////////////////////////////////////////////////////////////////////
3167
void SetupSaveGames()
3168
{
3169
    char name[13];
3170
    char savepath[300];
3171
 
3172
    strcpy(name, SaveName);
3173
    for(int i = 0; i < 10; i++)
3174
    {
3175
        name[7] = '0' + i;
3176
#ifdef _arch_dreamcast
3177
        // Try to unpack file
3178
        if(DC_LoadFromVMU(name))
3179
        {
3180
#endif
3181
            if(configdir[0])
3182
                snprintf(savepath, sizeof(savepath), "%s/%s", configdir, name);
3183
            else
3184
                strcpy(savepath, name);
3185
 
3186
            const int handle = open(savepath, O_RDONLY | O_BINARY);
3187
            if(handle >= 0)
3188
            {
3189
                char temp[32];
3190
 
3191
                SaveGamesAvail[i] = 1;
3192
                read(handle, temp, 32);
3193
                close(handle);
3194
                strcpy(&SaveGameNames[i][0], temp);
3195
            }
3196
#ifdef _arch_dreamcast
3197
            // Remove unpacked version of file
3198
            fs_unlink(name);
3199
        }
3200
#endif
3201
    }
3202
}
3203
 
3204
////////////////////////////////////////////////////////////////////
3205
//
3206
// Clean up all the Control Panel stuff
3207
//
3208
////////////////////////////////////////////////////////////////////
3209
void
3210
CleanupControlPanel (void)
3211
{
3212
#ifndef SPEAR
3213
    UnCacheLump (CONTROLS_LUMP_START, CONTROLS_LUMP_END);
3214
#else
3215
    UnCacheLump (BACKDROP_LUMP_START, BACKDROP_LUMP_END);
3216
#endif
3217
 
3218
    fontnumber = 0;
3219
}
3220
 
3221
 
3222
////////////////////////////////////////////////////////////////////
3223
//
3224
// Handle moving gun around a menu
3225
//
3226
////////////////////////////////////////////////////////////////////
3227
int
3228
HandleMenu (CP_iteminfo * item_i, CP_itemtype * items, void (*routine) (int w))
3229
{
3230
    char key;
3231
    static int redrawitem = 1, lastitem = -1;
3232
    int i, x, y, basey, exit, which, shape;
3233
    int32_t lastBlinkTime, timer;
3234
    ControlInfo ci;
3235
 
3236
 
3237
    which = item_i->curpos;
3238
    x = item_i->x & -8;
3239
    basey = item_i->y - 2;
3240
    y = basey + which * 13;
3241
 
3242
    VWB_DrawPic (x, y, C_CURSOR1PIC);
3243
    SetTextColor (items + which, 1);
3244
    if (redrawitem)
3245
    {
3246
        PrintX = item_i->x + item_i->indent;
3247
        PrintY = item_i->y + which * 13;
3248
        US_Print ((items + which)->string);
3249
    }
3250
    //
3251
    // CALL CUSTOM ROUTINE IF IT IS NEEDED
3252
    //
3253
    if (routine)
3254
        routine (which);
3255
    VW_UpdateScreen ();
3256
 
3257
    shape = C_CURSOR1PIC;
3258
    timer = 8;
3259
    exit = 0;
3260
    lastBlinkTime = GetTimeCount ();
3261
    IN_ClearKeysDown ();
3262
 
3263
 
3264
    do
3265
    {
3266
        //
3267
        // CHANGE GUN SHAPE
3268
        //
3269
        if ((int32_t)GetTimeCount () - lastBlinkTime > timer)
3270
        {
3271
            lastBlinkTime = GetTimeCount ();
3272
            if (shape == C_CURSOR1PIC)
3273
            {
3274
                shape = C_CURSOR2PIC;
3275
                timer = 8;
3276
            }
3277
            else
3278
            {
3279
                shape = C_CURSOR1PIC;
3280
                timer = 70;
3281
            }
3282
            VWB_DrawPic (x, y, shape);
3283
            if (routine)
3284
                routine (which);
3285
            VW_UpdateScreen ();
3286
        }
3287
        else SDL_Delay(5);
3288
 
3289
        CheckPause ();
3290
 
3291
        //
3292
        // SEE IF ANY KEYS ARE PRESSED FOR INITIAL CHAR FINDING
3293
        //
3294
        key = LastASCII;
3295
        if (key)
3296
        {
3297
            int ok = 0;
3298
 
3299
            if (key >= 'a')
3300
                key -= 'a' - 'A';
3301
 
3302
            for (i = which + 1; i < item_i->amount; i++)
3303
                if ((items + i)->active && (items + i)->string[0] == key)
3304
                {
3305
                    EraseGun (item_i, items, x, y, which);
3306
                    which = i;
3307
                    DrawGun (item_i, items, x, &y, which, basey, routine);
3308
                    ok = 1;
3309
                    IN_ClearKeysDown ();
3310
                    break;
3311
                }
3312
 
3313
            //
3314
            // DIDN'T FIND A MATCH FIRST TIME THRU. CHECK AGAIN.
3315
            //
3316
            if (!ok)
3317
            {
3318
                for (i = 0; i < which; i++)
3319
                    if ((items + i)->active && (items + i)->string[0] == key)
3320
                    {
3321
                        EraseGun (item_i, items, x, y, which);
3322
                        which = i;
3323
                        DrawGun (item_i, items, x, &y, which, basey, routine);
3324
                        IN_ClearKeysDown ();
3325
                        break;
3326
                    }
3327
            }
3328
        }
3329
 
3330
        //
3331
        // GET INPUT
3332
        //
3333
        ReadAnyControl (&ci);
3334
        switch (ci.dir)
3335
        {
3336
                ////////////////////////////////////////////////
3337
                //
3338
                // MOVE UP
3339
                //
3340
            case dir_North:
3341
 
3342
                EraseGun (item_i, items, x, y, which);
3343
 
3344
                //
3345
                // ANIMATE HALF-STEP
3346
                //
3347
                if (which && (items + which - 1)->active)
3348
                {
3349
                    y -= 6;
3350
                    DrawHalfStep (x, y);
3351
                }
3352
 
3353
                //
3354
                // MOVE TO NEXT AVAILABLE SPOT
3355
                //
3356
                do
3357
                {
3358
                    if (!which)
3359
                        which = item_i->amount - 1;
3360
                    else
3361
                        which--;
3362
                }
3363
                while (!(items + which)->active);
3364
 
3365
                DrawGun (item_i, items, x, &y, which, basey, routine);
3366
                //
3367
                // WAIT FOR BUTTON-UP OR DELAY NEXT MOVE
3368
                //
3369
                TicDelay (20);
3370
                break;
3371
 
3372
                ////////////////////////////////////////////////
3373
                //
3374
                // MOVE DOWN
3375
                //
3376
            case dir_South:
3377
 
3378
                EraseGun (item_i, items, x, y, which);
3379
                //
3380
                // ANIMATE HALF-STEP
3381
                //
3382
                if (which != item_i->amount - 1 && (items + which + 1)->active)
3383
                {
3384
                    y += 6;
3385
                    DrawHalfStep (x, y);
3386
                }
3387
 
3388
                do
3389
                {
3390
                    if (which == item_i->amount - 1)
3391
                        which = 0;
3392
                    else
3393
                        which++;
3394
                }
3395
                while (!(items + which)->active);
3396
 
3397
                DrawGun (item_i, items, x, &y, which, basey, routine);
3398
 
3399
                //
3400
                // WAIT FOR BUTTON-UP OR DELAY NEXT MOVE
3401
                //
3402
                TicDelay (20);
3403
                break;
3404
        }
3405
 
3406
        if (ci.button0 || Keyboard[sc_Space] || Keyboard[sc_Enter])
3407
            exit = 1;
3408
 
3409
        if (ci.button1 && !Keyboard[sc_Alt] || Keyboard[sc_Escape])
3410
            exit = 2;
3411
 
3412
    }
3413
    while (!exit);
3414
 
3415
 
3416
    IN_ClearKeysDown ();
3417
 
3418
    //
3419
    // ERASE EVERYTHING
3420
    //
3421
    if (lastitem != which)
3422
    {
3423
        VWB_Bar (x - 1, y, 25, 16, BKGDCOLOR);
3424
        PrintX = item_i->x + item_i->indent;
3425
        PrintY = item_i->y + which * 13;
3426
        US_Print ((items + which)->string);
3427
        redrawitem = 1;
3428
    }
3429
    else
3430
        redrawitem = 0;
3431
 
3432
    if (routine)
3433
        routine (which);
3434
    VW_UpdateScreen ();
3435
 
3436
    item_i->curpos = which;
3437
 
3438
    lastitem = which;
3439
    switch (exit)
3440
    {
3441
        case 1:
3442
            //
3443
            // CALL THE ROUTINE
3444
            //
3445
            if ((items + which)->routine != NULL)
3446
            {
3447
                ShootSnd ();
3448
                MenuFadeOut ();
3449
                (items + which)->routine (0);
3450
            }
3451
            return which;
3452
 
3453
        case 2:
3454
            SD_PlaySound (ESCPRESSEDSND);
3455
            return -1;
3456
    }
3457
 
3458
    return 0;                   // JUST TO SHUT UP THE ERROR MESSAGES!
3459
}
3460
 
3461
 
3462
//
3463
// ERASE GUN & DE-HIGHLIGHT STRING
3464
//
3465
void
3466
EraseGun (CP_iteminfo * item_i, CP_itemtype * items, int x, int y, int which)
3467
{
3468
    VWB_Bar (x - 1, y, 25, 16, BKGDCOLOR);
3469
    SetTextColor (items + which, 0);
3470
 
3471
    PrintX = item_i->x + item_i->indent;
3472
    PrintY = item_i->y + which * 13;
3473
    US_Print ((items + which)->string);
3474
    VW_UpdateScreen ();
3475
}
3476
 
3477
 
3478
//
3479
// DRAW HALF STEP OF GUN TO NEXT POSITION
3480
//
3481
void
3482
DrawHalfStep (int x, int y)
3483
{
3484
    VWB_DrawPic (x, y, C_CURSOR1PIC);
3485
    VW_UpdateScreen ();
3486
    SD_PlaySound (MOVEGUN1SND);
8597 turbocat 3487
    SDL_Delay(1);  //Fixed too long delay in the menu
8557 maxcodehac 3488
}
3489
 
3490
 
3491
//
3492
// DRAW GUN AT NEW POSITION
3493
//
3494
void
3495
DrawGun (CP_iteminfo * item_i, CP_itemtype * items, int x, int *y, int which, int basey,
3496
         void (*routine) (int w))
3497
{
3498
    VWB_Bar (x - 1, *y, 25, 16, BKGDCOLOR);
3499
    *y = basey + which * 13;
3500
    VWB_DrawPic (x, *y, C_CURSOR1PIC);
3501
    SetTextColor (items + which, 1);
3502
 
3503
    PrintX = item_i->x + item_i->indent;
3504
    PrintY = item_i->y + which * 13;
3505
    US_Print ((items + which)->string);
3506
 
3507
    //
3508
    // CALL CUSTOM ROUTINE IF IT IS NEEDED
3509
    //
3510
    if (routine)
3511
        routine (which);
3512
    VW_UpdateScreen ();
3513
    SD_PlaySound (MOVEGUN2SND);
3514
}
3515
 
3516
////////////////////////////////////////////////////////////////////
3517
//
3518
// DELAY FOR AN AMOUNT OF TICS OR UNTIL CONTROLS ARE INACTIVE
3519
//
3520
////////////////////////////////////////////////////////////////////
3521
void
3522
TicDelay (int count)
3523
{
3524
    ControlInfo ci;
3525
 
3526
    int32_t startTime = GetTimeCount ();
3527
    do
3528
    {
3529
        SDL_Delay(5);
3530
        ReadAnyControl (&ci);
3531
    }
3532
    while ((int32_t) GetTimeCount () - startTime < count && ci.dir != dir_None);
3533
}
3534
 
3535
 
3536
////////////////////////////////////////////////////////////////////
3537
//
3538
// Draw a menu
3539
//
3540
////////////////////////////////////////////////////////////////////
3541
void
3542
DrawMenu (CP_iteminfo * item_i, CP_itemtype * items)
3543
{
3544
    int i, which = item_i->curpos;
3545
 
3546
 
3547
    WindowX = PrintX = item_i->x + item_i->indent;
3548
    WindowY = PrintY = item_i->y;
3549
    WindowW = 320;
3550
    WindowH = 200;
3551
 
3552
    for (i = 0; i < item_i->amount; i++)
3553
    {
3554
        SetTextColor (items + i, which == i);
3555
 
3556
        PrintY = item_i->y + i * 13;
3557
        if ((items + i)->active)
3558
            US_Print ((items + i)->string);
3559
        else
3560
        {
3561
            SETFONTCOLOR (DEACTIVE, BKGDCOLOR);
3562
            US_Print ((items + i)->string);
3563
            SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
3564
        }
3565
 
3566
        US_Print ("\n");
3567
    }
3568
}
3569
 
3570
 
3571
////////////////////////////////////////////////////////////////////
3572
//
3573
// SET TEXT COLOR (HIGHLIGHT OR NO)
3574
//
3575
////////////////////////////////////////////////////////////////////
3576
void
3577
SetTextColor (CP_itemtype * items, int hlight)
3578
{
3579
    if (hlight)
3580
    {
3581
        SETFONTCOLOR (color_hlite[items->active], BKGDCOLOR);
3582
    }
3583
    else
3584
    {
3585
        SETFONTCOLOR (color_norml[items->active], BKGDCOLOR);
3586
    }
3587
}
3588
 
3589
 
3590
////////////////////////////////////////////////////////////////////
3591
//
3592
// WAIT FOR CTRLKEY-UP OR BUTTON-UP
3593
//
3594
////////////////////////////////////////////////////////////////////
3595
void
3596
WaitKeyUp (void)
3597
{
3598
    ControlInfo ci;
3599
    while (ReadAnyControl (&ci), ci.button0 |
3600
           ci.button1 |
3601
           ci.button2 | ci.button3 | Keyboard[sc_Space] | Keyboard[sc_Enter] | Keyboard[sc_Escape])
3602
    {
3603
        IN_WaitAndProcessEvents();
3604
    }
3605
}
3606
 
3607
 
3608
////////////////////////////////////////////////////////////////////
3609
//
3610
// READ KEYBOARD, JOYSTICK AND MOUSE FOR INPUT
3611
//
3612
////////////////////////////////////////////////////////////////////
3613
void
3614
ReadAnyControl (ControlInfo * ci)
3615
{
3616
    int mouseactive = 0;
3617
 
3618
    IN_ReadControl (0, ci);
3619
 
3620
    if (mouseenabled && IN_IsInputGrabbed())
3621
    {
3622
        int mousex, mousey, buttons;
3623
        buttons = SDL_GetMouseState(&mousex, &mousey);
3624
        int middlePressed = buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE);
3625
        int rightPressed = buttons & SDL_BUTTON(SDL_BUTTON_RIGHT);
3626
        buttons &= ~(SDL_BUTTON(SDL_BUTTON_MIDDLE) | SDL_BUTTON(SDL_BUTTON_RIGHT));
3627
        if(middlePressed) buttons |= 1 << 2;
3628
        if(rightPressed) buttons |= 1 << 1;
3629
 
3630
        if(mousey - CENTERY < -SENSITIVE)
3631
        {
3632
            ci->dir = dir_North;
3633
            mouseactive = 1;
3634
        }
3635
        else if(mousey - CENTERY > SENSITIVE)
3636
        {
3637
            ci->dir = dir_South;
3638
            mouseactive = 1;
3639
        }
3640
 
3641
        if(mousex - CENTERX < -SENSITIVE)
3642
        {
3643
            ci->dir = dir_West;
3644
            mouseactive = 1;
3645
        }
3646
        else if(mousex - CENTERX > SENSITIVE)
3647
        {
3648
            ci->dir = dir_East;
3649
            mouseactive = 1;
3650
        }
3651
 
3652
        if(mouseactive)
3653
            IN_CenterMouse();
3654
 
3655
        if (buttons)
3656
        {
3657
            ci->button0 = buttons & 1;
3658
            ci->button1 = buttons & 2;
3659
            ci->button2 = buttons & 4;
3660
            ci->button3 = false;
3661
            mouseactive = 1;
3662
        }
3663
    }
3664
 
3665
    if (joystickenabled && !mouseactive)
3666
    {
3667
        int jx, jy, jb;
3668
 
3669
        IN_GetJoyDelta (&jx, &jy);
3670
        if (jy < -SENSITIVE)
3671
            ci->dir = dir_North;
3672
        else if (jy > SENSITIVE)
3673
            ci->dir = dir_South;
3674
 
3675
        if (jx < -SENSITIVE)
3676
            ci->dir = dir_West;
3677
        else if (jx > SENSITIVE)
3678
            ci->dir = dir_East;
3679
 
3680
        jb = IN_JoyButtons ();
3681
        if (jb)
3682
        {
3683
            ci->button0 = jb & 1;
3684
            ci->button1 = jb & 2;
3685
            ci->button2 = jb & 4;
3686
            ci->button3 = jb & 8;
3687
        }
3688
    }
3689
}
3690
 
3691
 
3692
////////////////////////////////////////////////////////////////////
3693
//
3694
// DRAW DIALOG AND CONFIRM YES OR NO TO QUESTION
3695
//
3696
////////////////////////////////////////////////////////////////////
3697
int
3698
Confirm (const char *string)
3699
{
3700
    int xit = 0, x, y, tick = 0, lastBlinkTime;
3701
    int whichsnd[2] = { ESCPRESSEDSND, SHOOTSND };
3702
    ControlInfo ci;
3703
 
3704
    Message (string);
3705
    IN_ClearKeysDown ();
3706
    WaitKeyUp ();
3707
 
3708
    //
3709
    // BLINK CURSOR
3710
    //
3711
    x = PrintX;
3712
    y = PrintY;
3713
    lastBlinkTime = GetTimeCount();
3714
 
3715
    do
3716
    {
3717
        ReadAnyControl(&ci);
3718
 
3719
        if (GetTimeCount() - lastBlinkTime >= 10)
3720
        {
3721
            switch (tick)
3722
            {
3723
                case 0:
3724
                    VWB_Bar (x, y, 8, 13, TEXTCOLOR);
3725
                    break;
3726
                case 1:
3727
                    PrintX = x;
3728
                    PrintY = y;
3729
                    US_Print ("_");
3730
            }
3731
            VW_UpdateScreen ();
3732
            tick ^= 1;
3733
            lastBlinkTime = GetTimeCount();
3734
        }
3735
        else SDL_Delay(5);
3736
 
3737
#ifdef SPANISH
3738
    }
3739
    while (!Keyboard[sc_S] && !Keyboard[sc_N] && !Keyboard[sc_Escape]);
3740
#else
3741
    }
3742
    while (!Keyboard[sc_Y] && !Keyboard[sc_N] && !Keyboard[sc_Escape] && !ci.button0 && !ci.button1);
3743
#endif
3744
 
3745
#ifdef SPANISH
3746
    if (Keyboard[sc_S] || ci.button0)
3747
    {
3748
        xit = 1;
3749
        ShootSnd ();
3750
    }
3751
#else
3752
    if (Keyboard[sc_Y] || ci.button0)
3753
    {
3754
        xit = 1;
3755
        ShootSnd ();
3756
    }
3757
#endif
3758
 
3759
    IN_ClearKeysDown ();
3760
    WaitKeyUp ();
3761
 
3762
    SD_PlaySound ((soundnames) whichsnd[xit]);
3763
 
3764
    return xit;
3765
}
3766
 
3767
#ifdef JAPAN
3768
////////////////////////////////////////////////////////////////////
3769
//
3770
// DRAW MESSAGE & GET Y OR N
3771
//
3772
////////////////////////////////////////////////////////////////////
3773
int
3774
GetYorN (int x, int y, int pic)
3775
{
3776
    int xit = 0;
3777
    soundnames whichsnd[2] = { ESCPRESSEDSND, SHOOTSND };
3778
 
3779
 
3780
    CA_CacheGrChunk (pic);
3781
    VWB_DrawPic (x * 8, y * 8, pic);
3782
    UNCACHEGRCHUNK (pic);
3783
    VW_UpdateScreen ();
3784
    IN_ClearKeysDown ();
3785
 
3786
    do
3787
    {
3788
        IN_WaitAndProcessEvents();
3789
    }
3790
#ifdef SPANISH
3791
    while (!Keyboard[sc_S] && !Keyboard[sc_N] && !Keyboard[sc_Escape]);
3792
#else
3793
    while (!Keyboard[sc_Y] && !Keyboard[sc_N] && !Keyboard[sc_Escape]);
3794
#endif
3795
 
3796
#ifdef SPANISH
3797
    if (Keyboard[sc_S])
3798
    {
3799
        xit = 1;
3800
        ShootSnd ();
3801
    }
3802
 
3803
    while (Keyboard[sc_S] || Keyboard[sc_N] || Keyboard[sc_Escape])
3804
        IN_WaitAndProcessEvents();
3805
 
3806
#else
3807
 
3808
    if (Keyboard[sc_Y])
3809
    {
3810
        xit = 1;
3811
        ShootSnd ();
3812
    }
3813
 
3814
    while (Keyboard[sc_Y] || Keyboard[sc_N] || Keyboard[sc_Escape])
3815
        IN_WaitAndProcessEvents();
3816
#endif
3817
 
3818
    IN_ClearKeysDown ();
3819
    SD_PlaySound (whichsnd[xit]);
3820
    return xit;
3821
}
3822
#endif
3823
 
3824
 
3825
////////////////////////////////////////////////////////////////////
3826
//
3827
// PRINT A MESSAGE IN A WINDOW
3828
//
3829
////////////////////////////////////////////////////////////////////
3830
void
3831
Message (const char *string)
3832
{
3833
    int h = 0, w = 0, mw = 0, i, len = (int) strlen(string);
3834
    fontstruct *font;
3835
 
3836
 
3837
    CA_CacheGrChunk (STARTFONT + 1);
3838
    fontnumber = 1;
3839
    font = (fontstruct *) grsegs[STARTFONT + fontnumber];
3840
    h = font->height;
3841
    for (i = 0; i < len; i++)
3842
    {
3843
        if (string[i] == '\n')
3844
        {
3845
            if (w > mw)
3846
                mw = w;
3847
            w = 0;
3848
            h += font->height;
3849
        }
3850
        else
3851
            w += font->width[string[i]];
3852
    }
3853
 
3854
    if (w + 10 > mw)
3855
        mw = w + 10;
3856
 
3857
    PrintY = (WindowH / 2) - h / 2;
3858
    PrintX = WindowX = 160 - mw / 2;
3859
 
3860
    DrawWindow (WindowX - 5, PrintY - 5, mw + 10, h + 10, TEXTCOLOR);
3861
    DrawOutline (WindowX - 5, PrintY - 5, mw + 10, h + 10, 0, HIGHLIGHT);
3862
    SETFONTCOLOR (0, TEXTCOLOR);
3863
    US_Print (string);
3864
    VW_UpdateScreen ();
3865
}
3866
 
3867
////////////////////////////////////////////////////////////////////
3868
//
3869
// THIS MAY BE FIXED A LITTLE LATER...
3870
//
3871
////////////////////////////////////////////////////////////////////
3872
static int lastmusic;
3873
 
3874
int
3875
StartCPMusic (int song)
3876
{
3877
    int lastoffs;
3878
 
3879
    lastmusic = song;
3880
    lastoffs = SD_MusicOff ();
3881
    UNCACHEAUDIOCHUNK (STARTMUSIC + lastmusic);
3882
 
3883
    SD_StartMusic(STARTMUSIC + song);
3884
    return lastoffs;
3885
}
3886
 
3887
void
3888
FreeMusic (void)
3889
{
3890
    UNCACHEAUDIOCHUNK (STARTMUSIC + lastmusic);
3891
}
3892
 
3893
 
3894
///////////////////////////////////////////////////////////////////////////
3895
//
3896
//      IN_GetScanName() - Returns a string containing the name of the
3897
//              specified scan code
3898
//
3899
///////////////////////////////////////////////////////////////////////////
3900
const char *
3901
IN_GetScanName (ScanCode scan)
3902
{
3903
/*    const char **p;
3904
    ScanCode *s;
3905
 
3906
    for (s = ExtScanCodes, p = ExtScanNames; *s; p++, s++)
3907
        if (*s == scan)
3908
            return (*p);*/
3909
 
3910
    return (ScanNames[scan]);
3911
}
3912
 
3913
 
3914
///////////////////////////////////////////////////////////////////////////
3915
//
3916
// CHECK FOR PAUSE KEY (FOR MUSIC ONLY)
3917
//
3918
///////////////////////////////////////////////////////////////////////////
3919
void
3920
CheckPause (void)
3921
{
3922
    if (Paused)
3923
    {
3924
        switch (SoundStatus)
3925
        {
3926
            case 0:
3927
                SD_MusicOn ();
3928
                break;
3929
            case 1:
3930
                SD_MusicOff ();
3931
                break;
3932
        }
3933
 
3934
        SoundStatus ^= 1;
3935
        VW_WaitVBL (3);
3936
        IN_ClearKeysDown ();
3937
        Paused = false;
3938
    }
3939
}
3940
 
3941
 
3942
///////////////////////////////////////////////////////////////////////////
3943
//
3944
// DRAW GUN CURSOR AT CORRECT POSITION IN MENU
3945
//
3946
///////////////////////////////////////////////////////////////////////////
3947
void
3948
DrawMenuGun (CP_iteminfo * iteminfo)
3949
{
3950
    int x, y;
3951
 
3952
 
3953
    x = iteminfo->x;
3954
    y = iteminfo->y + iteminfo->curpos * 13 - 2;
3955
    VWB_DrawPic (x, y, C_CURSOR1PIC);
3956
}
3957
 
3958
 
3959
///////////////////////////////////////////////////////////////////////////
3960
//
3961
// DRAW SCREEN TITLE STRIPES
3962
//
3963
///////////////////////////////////////////////////////////////////////////
3964
void
3965
DrawStripes (int y)
3966
{
3967
#ifndef SPEAR
3968
    VWB_Bar (0, y, 320, 24, 0);
3969
    VWB_Hlin (0, 319, y + 22, STRIPE);
3970
#else
3971
    VWB_Bar (0, y, 320, 22, 0);
3972
    VWB_Hlin (0, 319, y + 23, 0);
3973
#endif
3974
}
3975
 
3976
void
3977
ShootSnd (void)
3978
{
3979
    SD_PlaySound (SHOOTSND);
3980
}
3981
 
3982
 
3983
///////////////////////////////////////////////////////////////////////////
3984
//
3985
// CHECK FOR EPISODES
3986
//
3987
///////////////////////////////////////////////////////////////////////////
3988
void
3989
CheckForEpisodes (void)
3990
{
3991
    struct stat statbuf;
8655 turbocat 3992
 
8557 maxcodehac 3993
    // On Linux like systems, the configdir defaults to $HOME/.wolf4sdl
8655 turbocat 3994
    #if !defined(_WIN32) && !defined(_arch_dreamcast)
8557 maxcodehac 3995
    if(configdir[0] == 0)
3996
    {
8655 turbocat 3997
    #ifdef _KOLIBRI
3998
        strcpy(configdir, "/tmp0/1/wolf4sdl");
3999
    #else
8557 maxcodehac 4000
        // Set config location to home directory for multi-user support
4001
        char *homedir = getenv("HOME");
4002
        if(homedir == NULL)
4003
        {
4004
            Quit("Your $HOME directory is not defined. You must set this before playing.");
4005
        }
4006
        #define WOLFDIR "/.wolf4sdl"
4007
        if(strlen(homedir) + sizeof(WOLFDIR) > sizeof(configdir))
4008
        {
4009
            Quit("Your $HOME directory path is too long. It cannot be used for saving games.");
4010
        }
4011
        snprintf(configdir, sizeof(configdir), "%s" WOLFDIR, homedir);
8655 turbocat 4012
    #endif
8557 maxcodehac 4013
    }
8655 turbocat 4014
#endif
8557 maxcodehac 4015
 
4016
    if(configdir[0] != 0)
4017
    {
4018
        // Ensure config directory exists and create if necessary
4019
        if(stat(configdir, &statbuf) != 0)
4020
        {
4021
#ifdef _WIN32
4022
            if(_mkdir(configdir) != 0)
4023
#else
4024
            if(mkdir(configdir, 0755) != 0)
4025
#endif
4026
            {
4027
                Quit("The configuration directory \"%s\" could not be created.", configdir);
4028
            }
4029
        }
4030
    }
4031
 
4032
//
4033
// JAPANESE VERSION
4034
//
4035
#ifdef JAPAN
4036
#ifdef JAPDEMO
4037
    if(!stat("vswap.wj1", &statbuf))
4038
    {
4039
        strcpy (extension, "wj1");
4040
        numEpisodesMissing = 5;
4041
#else
4042
    if(!stat("vswap.wj6", &statbuf))
4043
    {
4044
        strcpy (extension, "wj6");
4045
#endif
4046
        strcat (configname, extension);
4047
        strcat (SaveName, extension);
4048
        strcat (demoname, extension);
4049
        EpisodeSelect[1] =
4050
            EpisodeSelect[2] = EpisodeSelect[3] = EpisodeSelect[4] = EpisodeSelect[5] = 1;
4051
    }
4052
    else
4053
        Quit ("NO JAPANESE WOLFENSTEIN 3-D DATA FILES to be found!");
4054
    strcpy (graphext, extension);
4055
    strcpy (audioext, extension);
4056
#else
4057
 
4058
//
4059
// ENGLISH
4060
//
4061
#ifdef UPLOAD
4062
    if(!stat("vswap.wl1", &statbuf))
4063
    {
4064
        strcpy (extension, "wl1");
4065
        numEpisodesMissing = 5;
4066
    }
4067
    else
4068
        Quit ("NO WOLFENSTEIN 3-D DATA FILES to be found!");
4069
#else
4070
#ifndef SPEAR
4071
    if(!stat("vswap.wl6", &statbuf))
4072
    {
4073
        strcpy (extension, "wl6");
4074
        NewEmenu[2].active =
4075
            NewEmenu[4].active =
4076
            NewEmenu[6].active =
4077
            NewEmenu[8].active =
4078
            NewEmenu[10].active =
4079
            EpisodeSelect[1] =
4080
            EpisodeSelect[2] = EpisodeSelect[3] = EpisodeSelect[4] = EpisodeSelect[5] = 1;
4081
    }
4082
    else
4083
    {
4084
        if(!stat("vswap.wl3", &statbuf))
4085
        {
4086
            strcpy (extension, "wl3");
4087
            numEpisodesMissing = 3;
4088
            NewEmenu[2].active = NewEmenu[4].active = EpisodeSelect[1] = EpisodeSelect[2] = 1;
4089
        }
4090
        else
4091
        {
4092
            if(!stat("vswap.wl1", &statbuf))
4093
            {
4094
                strcpy (extension, "wl1");
4095
                numEpisodesMissing = 5;
4096
            }
4097
            else
4098
                Quit ("NO WOLFENSTEIN 3-D DATA FILES to be found!");
4099
        }
4100
    }
4101
#endif
4102
#endif
4103
 
4104
 
4105
#ifdef SPEAR
4106
#ifndef SPEARDEMO
4107
    if(param_mission == 0)
4108
    {
4109
        if(!stat("vswap.sod", &statbuf))
4110
            strcpy (extension, "sod");
4111
        else
4112
            Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
4113
    }
4114
    else if(param_mission == 1)
4115
    {
4116
        if(!stat("vswap.sd1", &statbuf))
4117
            strcpy (extension, "sd1");
4118
        else
4119
            Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
4120
    }
4121
    else if(param_mission == 2)
4122
    {
4123
        if(!stat("vswap.sd2", &statbuf))
4124
            strcpy (extension, "sd2");
4125
        else
4126
            Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
4127
    }
4128
    else if(param_mission == 3)
4129
    {
4130
        if(!stat("vswap.sd3", &statbuf))
4131
            strcpy (extension, "sd3");
4132
        else
4133
            Quit ("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
4134
    }
4135
    else
4136
        Quit ("UNSUPPORTED MISSION!");
4137
    strcpy (graphext, "sod");
4138
    strcpy (audioext, "sod");
4139
#else
4140
    if(!stat("vswap.sdm", &statbuf))
4141
    {
4142
        strcpy (extension, "sdm");
4143
    }
4144
    else
4145
        Quit ("NO SPEAR OF DESTINY DEMO DATA FILES TO BE FOUND!");
4146
    strcpy (graphext, "sdm");
4147
    strcpy (audioext, "sdm");
4148
#endif
4149
#else
4150
    strcpy (graphext, extension);
4151
    strcpy (audioext, extension);
4152
#endif
4153
 
4154
    strcat (configname, extension);
4155
    strcat (SaveName, extension);
4156
    strcat (demoname, extension);
4157
 
4158
#ifndef SPEAR
4159
#ifndef GOODTIMES
4160
    strcat (helpfilename, extension);
4161
#endif
4162
    strcat (endfilename, extension);
4163
#endif
4164
#endif
4165
}