⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p_setup.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 3 页
字号:
    }    // count number of lines in each sector    li = lines;    total = 0;    for (i=0 ; i<numlines ; i++, li++)    {        total++;        li->frontsector->linecount++;        if (li->backsector && li->backsector != li->frontsector)        {            li->backsector->linecount++;            total++;        }    }    // build line tables for each sector    linebuffer = Z_Malloc (total*4, PU_LEVEL, 0);    sector = sectors;    for (i=0 ; i<numsectors ; i++, sector++)    {        M_ClearBox (bbox);        sector->lines = linebuffer;        li = lines;        for (j=0 ; j<numlines ; j++, li++)        {            if (li->frontsector == sector || li->backsector == sector)            {                *linebuffer++ = li;                M_AddToBox (bbox, li->v1->x, li->v1->y);                M_AddToBox (bbox, li->v2->x, li->v2->y);            }        }        if (linebuffer - sector->lines != sector->linecount)            I_Error ("P_GroupLines: miscounted");        // set the degenmobj_t to the middle of the bounding box        sector->soundorg.x = (bbox[BOXRIGHT]+bbox[BOXLEFT])/2;        sector->soundorg.y = (bbox[BOXTOP]+bbox[BOXBOTTOM])/2;        // adjust bounding box to map blocks        block = (bbox[BOXTOP]-bmaporgy+MAXRADIUS)>>MAPBLOCKSHIFT;        block = block >= bmapheight ? bmapheight-1 : block;        sector->blockbox[BOXTOP]=block;        block = (bbox[BOXBOTTOM]-bmaporgy-MAXRADIUS)>>MAPBLOCKSHIFT;        block = block < 0 ? 0 : block;        sector->blockbox[BOXBOTTOM]=block;        block = (bbox[BOXRIGHT]-bmaporgx+MAXRADIUS)>>MAPBLOCKSHIFT;        block = block >= bmapwidth ? bmapwidth-1 : block;        sector->blockbox[BOXRIGHT]=block;        block = (bbox[BOXLEFT]-bmaporgx-MAXRADIUS)>>MAPBLOCKSHIFT;        block = block < 0 ? 0 : block;        sector->blockbox[BOXLEFT]=block;    }}// SoM: 6/27: Don't restrict maps to MAPxx/ExMx any more!char *levellumps[] ={  "label",        // ML_LABEL,    A separator, name, ExMx or MAPxx  "THINGS",       // ML_THINGS,   Monsters, items..  "LINEDEFS",     // ML_LINEDEFS, LineDefs, from editing  "SIDEDEFS",     // ML_SIDEDEFS, SideDefs, from editing  "VERTEXES",     // ML_VERTEXES, Vertices, edited and BSP splits generated  "SEGS",         // ML_SEGS,     LineSegs, from LineDefs split by BSP  "SSECTORS",     // ML_SSECTORS, SubSectors, list of LineSegs  "NODES",        // ML_NODES,    BSP nodes  "SECTORS",      // ML_SECTORS,  Sectors, from editing  "REJECT",       // ML_REJECT,   LUT, sector-sector visibility  "BLOCKMAP"      // ML_BLOCKMAP  LUT, motion clipping, walls/grid element};//// P_CheckLevel// Checks a lump and returns weather or not it is a level header lump.boolean P_CheckLevel(int lumpnum){  int  i;  int  file, lump;    for(i=ML_THINGS; i<=ML_BLOCKMAP; i++)    {      file = lumpnum >> 16;      lump = (lumpnum & 0xffff) + i;      if(file > numwadfiles || lump > wadfiles[file]->numlumps ||         strncmp(wadfiles[file]->lumpinfo[lump].name, levellumps[i], 8) )        return false;    }  return true;    // all right}//// Setup sky texture to use for the level, actually moved the code// from G_DoLoadLevel() which had nothing to do there.//// - in future, each level may use a different sky.//// The sky texture to be used instead of the F_SKY1 dummy.void P_SetupLevelSky (void){    char       skytexname[12];    // DOOM determines the sky texture to be used    // depending on the current episode, and the game version.    if(*info_skyname)      skytexture = R_TextureNumForName(info_skyname);    else    if ( (gamemode == commercial) )      // || (gamemode == pack_tnt) he ! is not a mode is a episode !      //    || ( gamemode == pack_plut )    {        if (gamemap < 12)            skytexture = R_TextureNumForName ("SKY1");        else        if (gamemap < 21)            skytexture = R_TextureNumForName ("SKY2");        else            skytexture = R_TextureNumForName ("SKY3");    }    else    if ( (gamemode==retail) ||         (gamemode==registered) )    {        if (gameepisode<1 || gameepisode>4)     // useful??            gameepisode = 1;        sprintf (skytexname,"SKY%d",gameepisode);        skytexture = R_TextureNumForName (skytexname);    }    else // who knows?    if (gamemode==heretic)    {        static char *skyLumpNames[5] = {            "SKY1", "SKY2", "SKY3", "SKY1", "SKY3" };        if(gameepisode > 5)            skytexture = R_TextureNumForName("SKY1");        else            skytexture = R_TextureNumForName(skyLumpNames[gameepisode-1]);    }    else        skytexture = R_TextureNumForName ("SKY1");    // scale up the old skies, if needed    R_SetupSkyDraw ();}//// P_SetupLevel//// added comment : load the level from a lump file or from a external wad !extern int numtextures;char       *maplumpname;int        lastloadedmaplumpnum; // for comparative savegameboolean P_SetupLevel (int           episode,                      int           map,                      skill_t       skill,                      char*         wadname)      // for wad files{    int         i;    //Initialize sector node list.    P_Initsecnode();    totalkills = totalitems = totalsecret = wminfo.maxfrags = 0;    wminfo.partime = 180;    for (i=0 ; i<MAXPLAYERS ; i++)    {        players[i].killcount = players[i].secretcount            = players[i].itemcount = 0;        players[i].mo = NULL;#ifdef CLIENTPREDICTION2        players[i].spirit = NULL;#endif    }    // Initial height of PointOfView    // will be set by player think.    players[consoleplayer].viewz = 1;    // Make sure all sounds are stopped before Z_FreeTags.    S_StopSounds();#if 0 // UNUSED    if (debugfile)    {        Z_FreeTags (PU_LEVEL, MAXINT);        Z_FileDumpHeap (debugfile);    }    else#endif        Z_FreeTags (PU_LEVEL, PU_PURGELEVEL-1);#ifdef WALLSPLATS    // clear the splats from previous level    R_ClearLevelSplats ();#endif    script_camera_on = false;    HU_ClearTips();    if (camera.chase)        camera.mo = NULL;    // UNUSED W_Profile ();        P_InitThinkers ();    // if working with a devlopment map, reload it    W_Reload ();    //    //  load the map from internal game resource or external wad file    //    if (wadname)    {        char *firstmap=NULL;        // go back to title screen if no map is loaded        if (!P_AddWadFile (wadname,&firstmap) ||            firstmap==NULL)            // no maps were found        {            return false;        }        // P_AddWadFile() sets lumpname        lastloadedmaplumpnum = W_GetNumForName(firstmap);        maplumpname = firstmap;    }    else    {        // internal game map        lastloadedmaplumpnum = W_GetNumForName (maplumpname = G_BuildMapName(episode,map));    }    if(levelmapname) Z_Free(levelmapname);    levelmapname = Z_Strdup(maplumpname, PU_STATIC, 0);    leveltime = 0;    // textures are needed first//    R_LoadTextures ();//    R_FlushTextureCache();    R_ClearColormaps();#ifdef FRAGGLESCRIPT    P_LoadLevelInfo (lastloadedmaplumpnum);    // load level lump info(level name etc)#endif    //SoM: We've loaded the music lump, start the music.    S_Start();    //faB: now part of level loading since in future each level may have    //     its own anim texture sequences, switches etc.    P_InitSwitchList ();    P_InitPicAnims ();    P_InitLava ();    P_SetupLevelSky ();    // SoM: WOO HOO!    R_InitPortals ();    // note: most of this ordering is important    P_LoadBlockMap (lastloadedmaplumpnum+ML_BLOCKMAP);    P_LoadVertexes (lastloadedmaplumpnum+ML_VERTEXES);    P_LoadSectors  (lastloadedmaplumpnum+ML_SECTORS);    P_LoadSideDefs (lastloadedmaplumpnum+ML_SIDEDEFS);    P_LoadLineDefs (lastloadedmaplumpnum+ML_LINEDEFS);    P_LoadSideDefs2(lastloadedmaplumpnum+ML_SIDEDEFS);    P_LoadLineDefs2();    P_LoadSubsectors (lastloadedmaplumpnum+ML_SSECTORS);    P_LoadNodes (lastloadedmaplumpnum+ML_NODES);    P_LoadSegs (lastloadedmaplumpnum+ML_SEGS);    rejectmatrix = W_CacheLumpNum (lastloadedmaplumpnum+ML_REJECT,PU_LEVEL);    P_GroupLines ();#ifdef HWRENDER // not win32 only 19990829 by Kin    if (rendermode != render_soft)    {        // BP: reset light between levels (we draw preview frame lights on current frame)        HWR_ResetLights();        // Correct missing sidedefs & deep water trick        HWR_CorrectSWTricks();        HWR_CreatePlanePolygons (numnodes-1);    }#endif    bodyqueslot = 0;    numdmstarts = 0;    // added 25-4-98 : reset the players starts    //SoM: Set pointers to NULL    for(i=0;i<MAXPLAYERS;i++)       playerstarts[i] = NULL;    P_InitAmbientSound ();    P_InitMonsters ();    P_OpenWeapons ();    P_LoadThings (lastloadedmaplumpnum+ML_THINGS);    P_CloseWeapons ();    // set up world state    P_SpawnSpecials ();    // spawnplayers now (beffor all structure are not inititialized)    for (i=0 ; i<MAXPLAYERS ; i++)        if (playeringame[i])        {            if (cv_deathmatch.value)            {                players[i].mo = NULL;                G_DoReborn(i);            }            else                if( demoversion>=128 )                {                    players[i].mo = NULL;                    G_CoopSpawnPlayer (i);                }        }    // clear special respawning que    iquehead = iquetail = 0;    // build subsector connect matrix    //  UNUSED P_ConnectSubsectors ();    //Fab:19-07-98:start cd music for this level (note: can be remapped)    if (gamemode==commercial)        I_PlayCD (map, true);                // Doom2, 32 maps    else        I_PlayCD ((episode-1)*9+map, true);  // Doom1, 9maps per episode    // preload graphics#ifdef HWRENDER // not win32 only 19990829 by Kin    if (rendermode != render_soft)    {        HWR_PrepLevelCache (numtextures);#ifdef TANDL        HWR_CreateStaticLightmaps (numnodes-1);#endif    }#endif    if (precache)        R_PrecacheLevel ();#ifdef FRAGGLESCRIPT    T_PreprocessScripts();        // preprocess FraggleScript scripts#endif    script_camera_on = false;    //CONS_Printf("%d vertexs %d segs %d subsector\n",numvertexes,numsegs,numsubsectors);    return true;}//// Add a wadfile to the active wad files,// replace sounds, musics, patches, textures, sprites and maps//boolean P_AddWadFile (char* wadfilename,char **firstmapname){    int         firstmapreplaced;    wadfile_t*  wadfile;    char*       name;    int         i,j,num,wadfilenum;    lumpinfo_t* lumpinfo;    int         replaces;    boolean     texturechange;    if ((wadfilenum = W_LoadWadFile (wadfilename))==-1)    {        CONS_Printf ("couldn't load wad file %s\n", COM_Argv(1));        return false;    }    wadfile = wadfiles[wadfilenum];    //    // search for sound replacements    //    lumpinfo = wadfile->lumpinfo;    replaces = 0;    texturechange=false;    for (i=0; i<wadfile->numlumps; i++,lumpinfo++)    {        name = lumpinfo->name;        if (name[0]=='D' && name[1]=='S')        {            for (j=1 ; j<NUMSFX ; j++)            {                if ( S_sfx[j].name &&                    !S_sfx[j].link &&                    !strnicmp(S_sfx[j].name,name+2,6) )                {                    // the sound will be reloaded when needed,                    // since sfx->data will be NULL                    if (devparm)                        CONS_Printf ("Sound %.8s replaced\n", name);                    I_FreeSfx (&S_sfx[j]);                    replaces++;                }            }        }        else        if( memcmp(name,"TEXTURE1",8)==0    // find texture replesement too         || memcmp(name,"TEXTURE2",8)==0         || memcmp(name,"PNAMES",6)==0)            texturechange=true;    }    if (!devparm && replaces)        CONS_Printf ("%d sounds replaced\n", replaces);    //    // search for music replacements    //    lumpinfo = wadfile->lumpinfo;    replaces = 0;    for (i=0; i<wadfile->numlumps; i++,lumpinfo++)    {        name = lumpinfo->name;        if (name[0]=='D' && name[1]=='_')        {            if (devparm)                CONS_Printf ("Music %.8s replaced\n", name);            replaces++;        }    }    if (!devparm && replaces)        CONS_Printf ("%d musics replaced\n", replaces);    //    // search for sprite replacements    //    R_AddSpriteDefs (sprnames, numwadfiles-1);    //    // search for texturechange replacements    //    if( texturechange ) // inited in the sound check        R_LoadTextures();       // numtexture changes    else        R_FlushTextureCache();  // just reload it from file    //    // look for skins    //    R_AddSkins (wadfilenum);      //faB: wadfile index in wadfiles[]    //    // search for maps    //    lumpinfo = wadfile->lumpinfo;    firstmapreplaced = 0;    for (i=0; i<wadfile->numlumps; i++,lumpinfo++)    {        name = lumpinfo->name;        num = firstmapreplaced;        if (gamemode==commercial)       // Doom2        {            if (name[0]=='M' &&                name[1]=='A' &&                name[2]=='P')            {                num = (name[3]-'0')*10 + (name[4]-'0');                CONS_Printf ("Map %d\n", num);            }        }        else        {            if (name[0]=='E' &&                ((unsigned)name[1]-'0')<='9' &&   // a digit                name[2]=='M' &&                ((unsigned)name[3]-'0')<='9' &&                name[4]==0)            {                num = ((name[1]-'0')<<16) + (name[3]-'0');                CONS_Printf ("Episode %d map %d\n", name[1]-'0',                                                    name[3]-'0');            }        }        if (num && (num<firstmapreplaced || !firstmapreplaced))        {            firstmapreplaced = num;            if(firstmapname) *firstmapname = name;        }    }    if (!firstmapreplaced)        CONS_Printf ("no maps added\n");    // reload status bar (warning should have valide player !)    if( gamestate == GS_LEVEL )        ST_Start();    return true;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -