Annotation of doom/h2_main.c, revision 1.1.1.1

1.1       root        1: 
                      2: //**************************************************************************
                      3: //**
                      4: //** h2_main.c : Heretic 2 : Raven Software, Corp.
                      5: //**
                      6: //** $RCSfile: h2_main.c,v $
                      7: //** $Revision: 1.50 $
                      8: //** $Date: 96/01/16 13:02:28 $
                      9: //** $Author: bgokey $
                     10: //**
                     11: //**************************************************************************
                     12: 
                     13: // HEADER FILES ------------------------------------------------------------
                     14: 
                     15: #ifdef __WATCOMC__
                     16: #include <dos.h>
                     17: #include <sys\types.h>
                     18: #include <direct.h>
                     19: #endif
                     20: #include <stdio.h>
                     21: #include <stdlib.h>
                     22: #include <time.h>
                     23: #include "h2def.h"
                     24: #include "p_local.h"
                     25: #include "soundst.h"
                     26: 
                     27: // MACROS ------------------------------------------------------------------
                     28: 
                     29: #define CONFIG_FILE_NAME "hexen.cfg"
                     30: #define MAXWADFILES 20
                     31: 
                     32: // TYPES -------------------------------------------------------------------
                     33: 
                     34: typedef struct
                     35: {
                     36:        char *name;
                     37:        void (*func)(char **args, int tag);
                     38:        int requiredArgs;
                     39:        int tag;
                     40: } execOpt_t;
                     41: 
                     42: // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
                     43: 
                     44: void R_ExecuteSetViewSize(void);
                     45: void D_CheckNetGame(void);
                     46: void G_BuildTiccmd(ticcmd_t *cmd);
                     47: void F_Drawer(void);
                     48: boolean F_Responder(event_t *ev);
                     49: void I_StartupKeyboard(void);
                     50: void I_StartupJoystick(void);
                     51: void I_ShutdownKeyboard(void);
                     52: void S_InitScript(void);
                     53: 
                     54: // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
                     55: 
                     56: void H2_ProcessEvents(void);
                     57: void H2_DoAdvanceDemo(void);
                     58: void H2_AdvanceDemo(void);
                     59: void H2_StartTitle(void);
                     60: void H2_PageTicker(void);
                     61: 
                     62: // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
                     63: 
                     64: static void DrawMessage(void);
                     65: static void PageDrawer(void);
                     66: static void HandleArgs(void);
                     67: static void CheckRecordFrom(void);
                     68: static void AddWADFile(char *file);
                     69: static void DrawAndBlit(void);
                     70: static void ExecOptionFILE(char **args, int tag);
                     71: static void ExecOptionSCRIPTS(char **args, int tag);
                     72: static void ExecOptionDEVMAPS(char **args, int tag);
                     73: static void ExecOptionSKILL(char **args, int tag);
                     74: static void ExecOptionPLAYDEMO(char **args, int tag);
                     75: static void ExecOptionMAXZONE(char **args, int tag);
                     76: static void CreateSavePath(void);
                     77: static void WarpCheck(void);
                     78: 
                     79: #ifdef TIMEBOMB
                     80: static void DoTimeBomb(void);
                     81: #endif
                     82: 
                     83: // EXTERNAL DATA DECLARATIONS ----------------------------------------------
                     84: 
                     85: extern boolean automapactive;
                     86: extern boolean MenuActive;
                     87: extern boolean askforquit;
                     88: extern char *SavePath;
                     89: 
                     90: // PUBLIC DATA DEFINITIONS -------------------------------------------------
                     91: 
                     92: boolean DevMaps;                       // true = Map development mode
                     93: char *DevMapsDir = "";         // development maps directory
                     94: boolean shareware;                     // true if only episode 1 present
                     95: boolean nomonsters;                    // checkparm of -nomonsters
                     96: boolean respawnparm;           // checkparm of -respawn
                     97: boolean randomclass;           // checkparm of -randclass
                     98: boolean debugmode;                     // checkparm of -debug
                     99: boolean ravpic;                                // checkparm of -ravpic
                    100: boolean cdrom;                         // true if cd-rom mode active
                    101: boolean cmdfrag;                       // true if a CMD_FRAG packet should be sent out
                    102: boolean singletics;                    // debug flag to cancel adaptiveness
                    103: boolean artiskip;                      // whether shift-enter skips an artifact
                    104: int maxzone = 0x800000;                // Maximum allocated for zone heap (8meg default)
                    105: skill_t startskill;
                    106: int startepisode;
                    107: int startmap;
                    108: boolean autostart;
                    109: boolean advancedemo;
                    110: FILE *debugfile;
                    111: event_t events[MAXEVENTS];
                    112: int eventhead;
                    113: int eventtail;
                    114: 
                    115: // PRIVATE DATA DEFINITIONS ------------------------------------------------
                    116: 
                    117: static int WarpMap;
                    118: static int demosequence;
                    119: static int pagetic;
                    120: static char *pagename;
                    121: #ifdef __NeXT__
                    122: static char *wadfiles[MAXWADFILES] =
                    123: {
                    124:        "/Novell/H2/source/hexen.wad"
                    125: };
                    126: #else
                    127: static char *wadfiles[MAXWADFILES] =
                    128: {
                    129:        "hexen.wad"
                    130: };
                    131: #endif
                    132: static execOpt_t ExecOptions[] =
                    133: {
                    134:        { "-file", ExecOptionFILE, 1, 0 },
                    135:        { "-scripts", ExecOptionSCRIPTS, 1, 0 },
                    136:        { "-devmaps", ExecOptionDEVMAPS, 1, 0 },
                    137:        { "-skill", ExecOptionSKILL, 1, 0 },
                    138:        { "-playdemo", ExecOptionPLAYDEMO, 1, 0 },
                    139:        { "-timedemo", ExecOptionPLAYDEMO, 1, 0 },
                    140:        { "-maxzone", ExecOptionMAXZONE, 1, 0 },
                    141:        { NULL, NULL, 0, 0 } // Terminator
                    142: };
                    143: 
                    144: // CODE --------------------------------------------------------------------
                    145: 
                    146: //==========================================================================
                    147: //
                    148: // H2_Main
                    149: //
                    150: //==========================================================================
                    151: void InitMapMusicInfo(void);
                    152: 
                    153: void H2_Main(void)
                    154: {
                    155:        int p;
                    156: 
                    157:        M_FindResponseFile();
                    158:        setbuf(stdout, NULL);
                    159:        startepisode = 1;
                    160:        autostart = false;
                    161:        startskill = sk_medium;
                    162:        startmap = 1;
                    163:        shareware = false; // Always false for Hexen
                    164: 
                    165:        HandleArgs();
                    166: 
                    167:        // Initialize subsystems
                    168: 
                    169:        ST_Message("V_Init: allocate screens.\n");
                    170:        V_Init();
                    171: 
                    172:        // Load defaults before initing other systems
                    173:        ST_Message("M_LoadDefaults: Load system defaults.\n");
                    174:        M_LoadDefaults(CONFIG_FILE_NAME);
                    175: 
                    176:        // Now that the savedir is loaded from .CFG, make sure it exists
                    177:        CreateSavePath();
                    178: 
                    179:        // HEXEN MODIFICATION:
                    180:        // There is a realloc() in W_AddFile() that might fail if the zone
                    181:        // heap has been previously allocated, so we need to initialize the
                    182:        // WAD files BEFORE the zone memory initialization.
                    183:        ST_Message("W_Init: Init WADfiles.\n");
                    184:        W_InitMultipleFiles(wadfiles);
                    185: 
                    186: #ifdef TIMEBOMB
                    187:        DoTimeBomb();
                    188: #endif
                    189: 
                    190:        ST_Message("Z_Init: Init zone memory allocation daemon.\n");
                    191:        Z_Init();
                    192: 
                    193: #ifdef __WATCOMC__
                    194:        I_StartupKeyboard();
                    195:        I_StartupJoystick();
                    196: #endif
                    197: 
                    198:        ST_Message("MN_Init: Init menu system.\n");
                    199:        MN_Init();
                    200: 
                    201:        ST_Message("CT_Init: Init chat mode data.\n");
                    202:        CT_Init();
                    203: 
                    204:        InitMapMusicInfo();             // Init music fields in mapinfo
                    205: 
                    206: #ifdef __WATCOMC__
                    207:        ST_Message("S_InitScript\n");
                    208:        S_InitScript();
                    209: #endif
                    210: 
                    211:        ST_Message("SN_InitSequenceScript: Registering sound sequences.\n");
                    212:        SN_InitSequenceScript();
                    213:        ST_Message("I_Init: Setting up machine state.\n");
                    214:        I_Init();
                    215: 
                    216:        ST_Message("ST_Init: Init startup screen.\n");
                    217:        ST_Init();
                    218: 
                    219:        S_StartSongName("orb", true);
                    220: 
                    221:        // Show version message now, so it's visible during R_Init()
                    222:        ST_Message("Executable: "VERSIONTEXT".\n");
                    223: 
                    224:        ST_Message("R_Init: Init Hexen refresh daemon");
                    225:        R_Init();
                    226:        ST_Message("\n");
                    227: 
                    228:        if (M_CheckParm("-net")) ST_NetProgress();      // Console player found
                    229: 
                    230:        ST_Message("P_Init: Init Playloop state.\n");
                    231:        P_Init();
                    232: 
                    233:        // Check for command line warping. Follows P_Init() because the
                    234:        // MAPINFO.TXT script must be already processed.
                    235:        WarpCheck();
                    236: 
                    237:        if(autostart)
                    238:        {
                    239:                ST_Message("Warp to Map %d (\"%s\":%d), Skill %d\n",
                    240:                        WarpMap, P_GetMapName(startmap), startmap, startskill+1);
                    241:        }
                    242: 
                    243:        ST_Message("D_CheckNetGame: Checking network game status.\n");
                    244:        D_CheckNetGame();
                    245: 
                    246:        ST_Message("SB_Init: Loading patches.\n");
                    247:        SB_Init();
                    248:        
                    249:        CheckRecordFrom();
                    250: 
                    251:        p = M_CheckParm("-record");
                    252:        if(p && p < myargc-1)
                    253:        {
                    254:                G_RecordDemo(startskill, 1, startepisode, startmap, myargv[p+1]);
                    255:                H2_GameLoop(); // Never returns
                    256:        }
                    257: 
                    258:        p = M_CheckParm("-playdemo");
                    259:        if(p && p < myargc-1)
                    260:        {
                    261:                singledemo = true; // Quit after one demo
                    262:                G_DeferedPlayDemo(myargv[p+1]);
                    263:                H2_GameLoop(); // Never returns
                    264:        }
                    265: 
                    266:        p = M_CheckParm("-timedemo");
                    267:        if(p && p < myargc-1)
                    268:        {
                    269:                G_TimeDemo(myargv[p+1]);
                    270:                H2_GameLoop(); // Never returns
                    271:        }
                    272: 
                    273:        p = M_CheckParm("-loadgame");
                    274:        if(p && p < myargc-1)
                    275:        {
                    276:                G_LoadGame(atoi(myargv[p+1]));
                    277:        }
                    278: 
                    279:        if(gameaction != ga_loadgame)
                    280:        {
                    281:                UpdateState |= I_FULLSCRN;
                    282:                BorderNeedRefresh = true;
                    283:                if(autostart || netgame)
                    284:                {
                    285:                        G_StartNewInit();
                    286:                        G_InitNew(startskill, startepisode, startmap);
                    287:                }
                    288:                else
                    289:                {
                    290:                        H2_StartTitle();
                    291:                }
                    292:        }
                    293:        H2_GameLoop(); // Never returns
                    294: }
                    295: 
                    296: //==========================================================================
                    297: //
                    298: // HandleArgs
                    299: //
                    300: //==========================================================================
                    301: 
                    302: static void HandleArgs(void)
                    303: {
                    304:        int p;
                    305:        execOpt_t *opt;
                    306: 
                    307:        nomonsters = M_ParmExists("-nomonsters");
                    308:        respawnparm = M_ParmExists("-respawn");
                    309:        randomclass = M_ParmExists("-randclass");
                    310:        ravpic = M_ParmExists("-ravpic");
                    311:        artiskip = M_ParmExists("-artiskip");
                    312:        debugmode = M_ParmExists("-debug");
                    313:        deathmatch = M_ParmExists("-deathmatch");
                    314:        cdrom = M_ParmExists("-cdrom");
                    315:        cmdfrag = M_ParmExists("-cmdfrag");
                    316: 
                    317:        // Process command line options
                    318:        for(opt = ExecOptions; opt->name != NULL; opt++)
                    319:        {
                    320:                p = M_CheckParm(opt->name);
                    321:                if(p && p < myargc-opt->requiredArgs)
                    322:                {
                    323:                        opt->func(&myargv[p], opt->tag);
                    324:                }
                    325:        }
                    326: 
                    327:        // Look for an external device driver
                    328:        I_CheckExternDriver();
                    329: }
                    330: 
                    331: //==========================================================================
                    332: //
                    333: // WarpCheck
                    334: //
                    335: //==========================================================================
                    336: 
                    337: static void WarpCheck(void)
                    338: {
                    339:        int p;
                    340:        int map;
                    341: 
                    342:        p = M_CheckParm("-warp");
                    343:        if(p && p < myargc-1)
                    344:        {
                    345:                WarpMap = atoi(myargv[p+1]);
                    346:                map = P_TranslateMap(WarpMap);
                    347:                if(map == -1)
                    348:                { // Couldn't find real map number
                    349:                        startmap = 1;
                    350:                        ST_Message("-WARP: Invalid map number.\n");
                    351:                }
                    352:                else
                    353:                { // Found a valid startmap
                    354:                        startmap = map;
                    355:                        autostart = true;
                    356:                }
                    357:        }
                    358:        else
                    359:        {
                    360:                WarpMap = 1;
                    361:                startmap = P_TranslateMap(1);
                    362:                if(startmap == -1)
                    363:                {
                    364:                        startmap = 1;
                    365:                }
                    366:        }
                    367: }
                    368: 
                    369: //==========================================================================
                    370: //
                    371: // ExecOptionSKILL
                    372: //
                    373: //==========================================================================
                    374: 
                    375: static void ExecOptionSKILL(char **args, int tag)
                    376: {
                    377:        startskill = args[1][0]-'1';
                    378:        autostart = true;
                    379: }
                    380: 
                    381: //==========================================================================
                    382: //
                    383: // ExecOptionFILE
                    384: //
                    385: //==========================================================================
                    386: 
                    387: static void ExecOptionFILE(char **args, int tag)
                    388: {
                    389:        int p;
                    390: 
                    391:        p = M_CheckParm("-file");
                    392:        while(++p != myargc && myargv[p][0] != '-')
                    393:        {
                    394:                AddWADFile(myargv[p]);
                    395:        }
                    396: }
                    397: 
                    398: 
                    399: //==========================================================================
                    400: //
                    401: // ExecOptionPLAYDEMO
                    402: //
                    403: //==========================================================================
                    404: 
                    405: static void ExecOptionPLAYDEMO(char **args, int tag)
                    406: {
                    407:        char file[256];
                    408: 
                    409:        sprintf(file, "%s.lmp", args[1]);
                    410:        AddWADFile(file);
                    411:        ST_Message("Playing demo %s.lmp.\n", args[1]);
                    412: }
                    413: 
                    414: //==========================================================================
                    415: //
                    416: // ExecOptionSCRIPTS
                    417: //
                    418: //==========================================================================
                    419: 
                    420: static void ExecOptionSCRIPTS(char **args, int tag)
                    421: {
                    422:        sc_FileScripts = true;
                    423:        sc_ScriptsDir = args[1];
                    424: }
                    425: 
                    426: //==========================================================================
                    427: //
                    428: // ExecOptionDEVMAPS
                    429: //
                    430: //==========================================================================
                    431: 
                    432: static void ExecOptionDEVMAPS(char **args, int tag)
                    433: {
                    434:        DevMaps = true;
                    435:        ST_Message("Map development mode enabled:\n");
                    436:        ST_Message("[config    ] = %s\n", args[1]);
                    437:        SC_OpenFileCLib(args[1]);
                    438:        SC_MustGetStringName("mapsdir");
                    439:        SC_MustGetString();
                    440:        ST_Message("[mapsdir   ] = %s\n", sc_String);
                    441:        DevMapsDir = malloc(strlen(sc_String)+1);
                    442:        strcpy(DevMapsDir, sc_String);
                    443:        SC_MustGetStringName("scriptsdir");
                    444:        SC_MustGetString();
                    445:        ST_Message("[scriptsdir] = %s\n", sc_String);
                    446:        sc_FileScripts = true;
                    447:        sc_ScriptsDir = malloc(strlen(sc_String)+1);
                    448:        strcpy(sc_ScriptsDir, sc_String);
                    449:        while(SC_GetString())
                    450:        {
                    451:                if(SC_Compare("file"))
                    452:                {
                    453:                        SC_MustGetString();
                    454:                        AddWADFile(sc_String);
                    455:                }
                    456:                else
                    457:                {
                    458:                        SC_ScriptError(NULL);
                    459:                }
                    460:        }
                    461:        SC_Close();
                    462: }
                    463: 
                    464: 
                    465: long superatol(char *s)
                    466: {
                    467:        long int n=0, r=10, x, mul=1;
                    468:        char *c=s;
                    469: 
                    470:        for (; *c; c++)
                    471:        {
                    472:                x = (*c & 223) - 16;
                    473: 
                    474:                if (x == -3)
                    475:                {
                    476:                        mul = -mul;
                    477:                }
                    478:                else if (x == 72 && r == 10)
                    479:                {
                    480:                        n -= (r=n);
                    481:                        if (!r) r=16;
                    482:                        if (r<2 || r>36) return -1;
                    483:                }
                    484:                else
                    485:                {
                    486:                        if (x>10) x-=39;
                    487:                        if (x >= r) return -1;
                    488:                        n = (n*r) + x;
                    489:                }
                    490:        }
                    491:        return(mul*n);
                    492: }
                    493: 
                    494: 
                    495: static void ExecOptionMAXZONE(char **args, int tag)
                    496: {
                    497:        int size;
                    498:        
                    499:        size = superatol(args[1]);
                    500:        if (size < MINIMUM_HEAP_SIZE) size = MINIMUM_HEAP_SIZE;
                    501:        if (size > MAXIMUM_HEAP_SIZE) size = MAXIMUM_HEAP_SIZE;
                    502:        maxzone = size;
                    503: }
                    504: 
                    505: //==========================================================================
                    506: //
                    507: // H2_GameLoop
                    508: //
                    509: //==========================================================================
                    510: 
                    511: void H2_GameLoop(void)
                    512: {
                    513:        if(M_CheckParm("-debugfile"))
                    514:        {
                    515:                char filename[20];
                    516:                sprintf(filename, "debug%i.txt", consoleplayer);
                    517:                debugfile = fopen(filename,"w");
                    518:        }
                    519:        I_InitGraphics();
                    520:        while(1)
                    521:        {
                    522:                // Frame syncronous IO operations
                    523:                I_StartFrame();
                    524: 
                    525:                // Process one or more tics
                    526:                if(singletics)
                    527:                {
                    528:                        I_StartTic();
                    529:                        H2_ProcessEvents();
                    530:                        G_BuildTiccmd(&netcmds[consoleplayer][maketic%BACKUPTICS]);
                    531:                        if(advancedemo)
                    532:                        {
                    533:                                H2_DoAdvanceDemo();
                    534:                        }
                    535:                        G_Ticker();
                    536:                        gametic++;
                    537:                        maketic++;
                    538:                }
                    539:                else
                    540:                {
                    541:                        // Will run at least one tic
                    542:                        TryRunTics();
                    543:                }
                    544: 
                    545:                // Move positional sounds
                    546:                S_UpdateSounds(players[displayplayer].mo);
                    547: 
                    548:                DrawAndBlit();
                    549:        }
                    550: }
                    551: 
                    552: //==========================================================================
                    553: //
                    554: // H2_ProcessEvents
                    555: //
                    556: // Send all the events of the given timestamp down the responder chain.
                    557: //
                    558: //==========================================================================
                    559: 
                    560: void H2_ProcessEvents(void)
                    561: {
                    562:        event_t *ev;
                    563: 
                    564:        for(; eventtail != eventhead; eventtail = (++eventtail)&(MAXEVENTS-1))
                    565:        {
                    566:                ev = &events[eventtail];
                    567:                if(F_Responder(ev))
                    568:                {
                    569:                        continue;
                    570:                }
                    571:                if(MN_Responder(ev))
                    572:                {
                    573:                        continue;
                    574:                }
                    575:                G_Responder(ev);
                    576:        }
                    577: }
                    578: 
                    579: //==========================================================================
                    580: //
                    581: // H2_PostEvent
                    582: //
                    583: // Called by the I/O functions when input is detected.
                    584: //
                    585: //==========================================================================
                    586: 
                    587: void H2_PostEvent(event_t *ev)
                    588: {
                    589:        events[eventhead] = *ev;
                    590:        eventhead = (++eventhead)&(MAXEVENTS-1);
                    591: }
                    592: 
                    593: //==========================================================================
                    594: //
                    595: // DrawAndBlit
                    596: //
                    597: //==========================================================================
                    598: 
                    599: static void DrawAndBlit(void)
                    600: {
                    601:        // Change the view size if needed
                    602:        if(setsizeneeded)
                    603:        {
                    604:                R_ExecuteSetViewSize();
                    605:        }
                    606: 
                    607:        // Do buffered drawing
                    608:        switch(gamestate)
                    609:        {
                    610:                case GS_LEVEL:
                    611:                        if(!gametic)
                    612:                        {
                    613:                                break;
                    614:                        }
                    615:                        if(automapactive)
                    616:                        {
                    617:                                AM_Drawer();
                    618:                        }
                    619:                        else
                    620:                        {
                    621:                                R_RenderPlayerView(&players[displayplayer]);
                    622:                        }
                    623:                        CT_Drawer();
                    624:                        UpdateState |= I_FULLVIEW;
                    625:                        SB_Drawer();
                    626:                        break;
                    627:                case GS_INTERMISSION:
                    628:                        IN_Drawer();
                    629:                        break;
                    630:                case GS_FINALE:
                    631:                        F_Drawer();
                    632:                        break;
                    633:                case GS_DEMOSCREEN:
                    634:                        PageDrawer();
                    635:                        break;
                    636:        }
                    637: 
                    638:        if(paused && !MenuActive && !askforquit)
                    639:        {
                    640:                if(!netgame)
                    641:                {
                    642:                        V_DrawPatch(160, viewwindowy+5, W_CacheLumpName("PAUSED",
                    643:                                PU_CACHE));
                    644:                }
                    645:                else
                    646:                {
                    647:                        V_DrawPatch(160, 70, W_CacheLumpName("PAUSED",
                    648:                                PU_CACHE));
                    649:                }
                    650:        }
                    651: 
                    652:        // Draw current message
                    653:        DrawMessage();
                    654: 
                    655:        // Draw Menu
                    656:        MN_Drawer();
                    657: 
                    658:        // Send out any new accumulation
                    659:        NetUpdate();
                    660: 
                    661:        // Flush buffered stuff to screen
                    662:        I_Update();
                    663: }
                    664: 
                    665: //==========================================================================
                    666: //
                    667: // DrawMessage
                    668: //
                    669: //==========================================================================
                    670: 
                    671: static void DrawMessage(void)
                    672: {
                    673:        player_t *player;
                    674: 
                    675:        player = &players[consoleplayer];
                    676:        if(player->messageTics <= 0 || !player->message)
                    677:        { // No message
                    678:                return;
                    679:        }
                    680:        if(player->yellowMessage)
                    681:        {
                    682:                MN_DrTextAYellow(player->message, 
                    683:                        160-MN_TextAWidth(player->message)/2, 1);
                    684:        }
                    685:        else
                    686:        {
                    687:                MN_DrTextA(player->message, 160-MN_TextAWidth(player->message)/2, 1);
                    688:        }
                    689: }
                    690: 
                    691: //==========================================================================
                    692: //
                    693: // H2_PageTicker
                    694: //
                    695: //==========================================================================
                    696: 
                    697: void H2_PageTicker(void)
                    698: {
                    699:        if(--pagetic < 0)
                    700:        {
                    701:                H2_AdvanceDemo();
                    702:        }
                    703: }
                    704: 
                    705: //==========================================================================
                    706: //
                    707: // PageDrawer
                    708: //
                    709: //==========================================================================
                    710: 
                    711: static void PageDrawer(void)
                    712: {
                    713:        V_DrawRawScreen(W_CacheLumpName(pagename, PU_CACHE));
                    714:        if(demosequence == 1)
                    715:        {
                    716:                V_DrawPatch(4, 160, W_CacheLumpName("ADVISOR", PU_CACHE));
                    717:        }
                    718:        UpdateState |= I_FULLSCRN;
                    719: }
                    720: 
                    721: //==========================================================================
                    722: //
                    723: // H2_AdvanceDemo
                    724: //
                    725: // Called after each demo or intro demosequence finishes.
                    726: //
                    727: //==========================================================================
                    728: 
                    729: void H2_AdvanceDemo(void)
                    730: {
                    731:        advancedemo = true;
                    732: }
                    733: 
                    734: //==========================================================================
                    735: //
                    736: // H2_DoAdvanceDemo
                    737: //
                    738: //==========================================================================
                    739: 
                    740: void H2_DoAdvanceDemo(void)
                    741: {
                    742:        players[consoleplayer].playerstate = PST_LIVE; // don't reborn
                    743:        advancedemo = false;
                    744:        usergame = false; // can't save/end game here
                    745:        paused = false;
                    746:        gameaction = ga_nothing;
                    747:        demosequence = (demosequence+1)%7;
                    748:        switch(demosequence)
                    749:        {
                    750:                case 0:
                    751:                        pagetic = 280;
                    752:                        gamestate = GS_DEMOSCREEN;
                    753:                        pagename = "TITLE";
                    754:                        S_StartSongName("hexen", true);
                    755:                        break;
                    756:                case 1:
                    757:                        pagetic = 210;
                    758:                        gamestate = GS_DEMOSCREEN;
                    759:                        pagename = "TITLE";
                    760:                        break;
                    761:                case 2:
                    762:                        BorderNeedRefresh = true;
                    763:                        UpdateState |= I_FULLSCRN;
                    764:                        G_DeferedPlayDemo("demo1");
                    765:                        break;
                    766:                case 3:
                    767:                        pagetic = 200;
                    768:                        gamestate = GS_DEMOSCREEN;
                    769:                        pagename = "CREDIT";
                    770:                        break;
                    771:                case 4:
                    772:                        BorderNeedRefresh = true;
                    773:                        UpdateState |= I_FULLSCRN;
                    774:                        G_DeferedPlayDemo("demo2");
                    775:                        break;
                    776:                case 5:
                    777:                        pagetic = 200;
                    778:                        gamestate = GS_DEMOSCREEN;
                    779:                        pagename = "CREDIT";
                    780:                        break;
                    781:                case 6:
                    782:                        BorderNeedRefresh = true;
                    783:                        UpdateState |= I_FULLSCRN;
                    784:                        G_DeferedPlayDemo("demo3");
                    785:                        break;
                    786:        }
                    787: }
                    788: 
                    789: //==========================================================================
                    790: //
                    791: // H2_StartTitle
                    792: //
                    793: //==========================================================================
                    794: 
                    795: void H2_StartTitle(void)
                    796: {
                    797:        gameaction = ga_nothing;
                    798:        demosequence = -1;
                    799:        H2_AdvanceDemo();
                    800: }
                    801: 
                    802: //==========================================================================
                    803: //
                    804: // CheckRecordFrom
                    805: //
                    806: // -recordfrom <savegame num> <demoname>
                    807: //
                    808: //==========================================================================
                    809: 
                    810: static void CheckRecordFrom(void)
                    811: {
                    812:        int p;
                    813: 
                    814:        p = M_CheckParm("-recordfrom");
                    815:        if(!p || p > myargc-2)
                    816:        { // Bad args
                    817:                return;
                    818:        }
                    819:        G_LoadGame(atoi(myargv[p+1]));
                    820:        G_DoLoadGame(); // Load the gameskill etc info from savegame
                    821:        G_RecordDemo(gameskill, 1, gameepisode, gamemap, myargv[p+2]);
                    822:        H2_GameLoop(); // Never returns
                    823: }
                    824: 
                    825: //==========================================================================
                    826: //
                    827: // AddWADFile
                    828: //
                    829: //==========================================================================
                    830: 
                    831: static void AddWADFile(char *file)
                    832: {
                    833:        int i;
                    834:        char *new;
                    835: 
                    836:        ST_Message("Adding external file: %s\n", file);
                    837:        i = 0;
                    838:        while(wadfiles[i])
                    839:        {
                    840:                i++;
                    841:        }
                    842:        new = malloc(strlen(file)+1);
                    843:        strcpy(new, file);
                    844:        wadfiles[i] = new;
                    845: }
                    846: 
                    847: #ifdef __WATCOMC__
                    848: /*
                    849: void CleanExit(void)
                    850: {
                    851:        union REGS regs;
                    852: 
                    853:        I_ShutdownKeyboard();
                    854:        regs.x.eax = 0x3;
                    855:        int386(0x10, &regs, &regs);
                    856:        printf("Exited from HEXEN: Beyond Heretic.\n");
                    857:        exit(1);
                    858: }
                    859: */
                    860: #endif
                    861: 
                    862: //==========================================================================
                    863: //
                    864: // FixedDiv
                    865: //
                    866: //==========================================================================
                    867: 
                    868: fixed_t FixedDiv(fixed_t a, fixed_t b)
                    869: {
                    870:        if((abs(a)>>14) >= abs(b))
                    871:        {
                    872:                return((a^b)<0 ? MININT : MAXINT);
                    873:        }
                    874:        return(FixedDiv2(a, b));
                    875: }
                    876: 
                    877: 
                    878: //==========================================================================
                    879: //
                    880: // CreateSavePath
                    881: //
                    882: //==========================================================================
                    883: 
                    884: static void CreateSavePath(void)
                    885: {
                    886:        char creationPath[121];
                    887:        int len;
                    888: 
                    889:        if(cdrom == true)
                    890:        {
                    891:                SavePath = "c:\\hexndata\\";
                    892:        }
                    893:        len = strlen(SavePath);
                    894:        if (len >= 120) I_Error("Save path too long\n");
                    895:        strcpy(creationPath, SavePath);
                    896: #ifdef __WATCOMC__
                    897:        creationPath[len-1] = 0;
                    898:        mkdir(creationPath);
                    899: #endif
                    900: }
                    901: 
                    902: #ifdef TIMEBOMB
                    903: //==========================================================================
                    904: //
                    905: // DoTimeBomb
                    906: //
                    907: //==========================================================================
                    908: 
                    909: static void DoTimeBomb(void)
                    910: {
                    911: #ifdef __WATCOMC__
                    912:        time_t timeOfDay;
                    913:        struct tm timeBuffer;
                    914: 
                    915:        timeOfDay = time(NULL);
                    916:        _localtime(&timeOfDay, &timeBuffer);
                    917:        if(timeBuffer.tm_year != TIMEBOMB_YEAR 
                    918:        || timeBuffer.tm_yday < TIMEBOMB_STARTDATE 
                    919:        || timeBuffer.tm_yday > TIMEBOMB_ENDDATE)
                    920:        {
                    921:                I_Error("W_InitWadfiles:  Wad file doesn't have IWAD or PWAD id\n");
                    922:        }
                    923:  
                    924:        printf("\n===============================================================================\n");
                    925:        printf("                             Hexen:  Beyond Heretic\n\n");
                    926:        printf("                           Beta -- Do Not Distribute!\n");
                    927:        printf("                           Press any key to continue.\n");
                    928:        printf("===============================================================================\n");
                    929:        
                    930:        getch();
                    931:        printf("\n");
                    932: #endif
                    933: }
                    934: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.