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

📄 p_saveg.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 5 页
字号:
// Emacs style mode select   -*- C++ -*-//-----------------------------------------------------------------------------//// $Id: p_saveg.c,v 1.18 2001/03/03 06:17:33 bpereira Exp $//// Copyright (C) 1993-1996 by id Software, Inc.// Portions Copyright (C) 1998-2000 by DooM Legacy Team.//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.////// $Log: p_saveg.c,v $// Revision 1.18  2001/03/03 06:17:33  bpereira// no message//// Revision 1.17  2001/02/24 13:35:20  bpereira// no message//// Revision 1.16  2001/02/10 12:27:14  bpereira// no message//// Revision 1.15  2001/01/25 22:15:43  bpereira// added heretic support//// Revision 1.14  2000/11/11 13:59:45  bpereira// no message//// Revision 1.13  2000/11/04 16:23:43  bpereira// no message//// Revision 1.12  2000/11/02 17:50:08  stroggonmeth// Big 3Dfloors & FraggleScript commit!!//// Revision 1.11  2000/09/28 20:57:16  bpereira// no message//// Revision 1.10  2000/08/31 14:30:56  bpereira// no message//// Revision 1.9  2000/07/01 09:23:49  bpereira// no message//// Revision 1.8  2000/04/16 18:38:07  bpereira// no message//// Revision 1.7  2000/04/15 22:12:57  stroggonmeth// Minor bug fixes//// Revision 1.6  2000/04/11 19:07:24  stroggonmeth// Finished my logs, fixed a crashing bug.//// Revision 1.5  2000/04/04 00:32:47  stroggonmeth// Initial Boom compatability plus few misc changes all around.//// Revision 1.4  2000/02/27 16:30:28  hurdler// dead player bug fix + add allowmlook <yes|no>//// Revision 1.3  2000/02/27 00:42:10  hurdler// fix CR+LF problem//// Revision 1.2  2000/02/26 00:28:42  hurdler// Mostly bug fix (see borislog.txt 23-2-2000, 24-2-2000)////// DESCRIPTION://      Archiving: SaveGame I/O.////-----------------------------------------------------------------------------#include "doomdef.h"#include "g_game.h"#include "p_local.h"#include "r_state.h"#include "z_zone.h"#include "w_wad.h"#include "p_setup.h"#include "byteptr.h"#include "t_vari.h"#include "t_script.h"#include "t_func.h"#include "m_random.h"byte*           save_p;// Pads save_p to a 4-byte boundary//  so that the load/save works on SGI&Gecko.#ifdef SGI// BP: this stuff isn't be removed but i think it will no more work//     anyway what processor can't read/write unaligned data ?#define PADSAVEP()      save_p += (4 - ((int) save_p & 3)) & 3#else#define PADSAVEP()#endif// BP: damned this #if don't work ! why ?#if NUMWEAPONS > 8#error please update the player_saveflags enum#endiftypedef enum { // weapons   = 0x01ff,    BACKPACK  = 0x0200,    ORIGNWEAP = 0x0400,    AUTOAIM   = 0x0800,    ATTACKDWN = 0x1000,    USEDWN    = 0x2000,    JMPDWN    = 0x4000,    DIDSECRET = 0x8000,} player_saveflags;typedef enum {   // powers      = 0x00ff   PD_REFIRE      = 0x0100,   PD_KILLCOUNT   = 0x0200,   PD_ITEMCOUNT   = 0x0400,   PD_SECRETCOUNT = 0x0800,   PD_DAMAGECOUNT = 0x1000,   PD_BONUSCOUNT  = 0x2000,    PD_CHICKENTICS = 0x4000,   PD_CHICKEPECK  = 0x8000,   PD_FLAMECOUNT  =0x10000,   PD_FLYHEIGHT   =0x20000,} player_diff;//// P_ArchivePlayers//void P_ArchivePlayers (void){    int         i,j;    int         flags;    ULONG       diff;    for (i=0 ; i<MAXPLAYERS ; i++)    {        if (!playeringame[i])            continue;        PADSAVEP();        flags = 0;        diff = 0;        for(j=0;j<NUMPOWERS;j++)            if( players[i].powers[j] )                diff |= 1<<j;        if( players[i].refire      )  diff |= PD_REFIRE;        if( players[i].killcount   )  diff |= PD_KILLCOUNT;        if( players[i].itemcount   )  diff |= PD_ITEMCOUNT;        if( players[i].secretcount )  diff |= PD_SECRETCOUNT;        if( players[i].damagecount )  diff |= PD_DAMAGECOUNT;        if( players[i].bonuscount  )  diff |= PD_BONUSCOUNT;         if( players[i].chickenTics )  diff |= PD_CHICKENTICS;        if( players[i].chickenPeck )  diff |= PD_CHICKEPECK;        if( players[i].flamecount  )  diff |= PD_FLAMECOUNT;        if( players[i].flyheight   )  diff |= PD_FLYHEIGHT;        WRITEULONG(save_p, diff );        WRITEANGLE(save_p, players[i].aiming);        WRITEUSHORT(save_p, players[i].health);        WRITEUSHORT(save_p, players[i].armorpoints);        WRITEBYTE(save_p, players[i].armortype);        for(j=0;j<NUMPOWERS;j++)            if( diff & (1<<j))                WRITELONG(save_p, players[i].powers[j]);        WRITEBYTE(save_p, players[i].cards);        WRITEBYTE(save_p, players[i].readyweapon);        WRITEBYTE(save_p, players[i].pendingweapon);        WRITEBYTE(save_p, players[i].playerstate);        WRITEUSHORT(save_p, players[i].addfrags);        for(j=0;j<MAXPLAYERS;j++)            if(playeringame[i])                WRITEUSHORT(save_p, players[i].frags[j]);        for(j=0;j<NUMWEAPONS;j++)        {            WRITEBYTE(save_p, players[i].favoritweapon[j]);            if( players[i].weaponowned[j] )                flags |= 1<<j;        }        for(j=0;j<NUMAMMO;j++)        {            WRITEUSHORT(save_p, players[i].ammo[j]);            WRITEUSHORT(save_p, players[i].maxammo[j]);        }        if(players[i].backpack)              flags |= BACKPACK;        if(players[i].originalweaponswitch)  flags |= ORIGNWEAP;        if(players[i].autoaim_toggle)        flags |= AUTOAIM;        if(players[i].attackdown)            flags |= ATTACKDWN;        if(players[i].usedown)               flags |= USEDWN;        if(players[i].jumpdown)              flags |= JMPDWN;        if(players[i].didsecret)             flags |= DIDSECRET;        if(diff & PD_REFIRE     ) WRITELONG(save_p, players[i].refire);        if(diff & PD_KILLCOUNT  ) WRITELONG(save_p, players[i].killcount);        if(diff & PD_ITEMCOUNT  ) WRITELONG(save_p, players[i].itemcount);        if(diff & PD_SECRETCOUNT) WRITELONG(save_p, players[i].secretcount);        if(diff & PD_DAMAGECOUNT) WRITELONG(save_p, players[i].damagecount);        if(diff & PD_BONUSCOUNT ) WRITELONG(save_p, players[i].bonuscount);        if(diff & PD_CHICKENTICS) WRITELONG(save_p, players[i].chickenTics);        if(diff & PD_CHICKEPECK ) WRITELONG(save_p, players[i].chickenPeck);         if(diff & PD_FLAMECOUNT ) WRITELONG(save_p, players[i].flamecount);         if(diff & PD_FLYHEIGHT  ) WRITELONG(save_p, players[i].flyheight);         WRITEBYTE(save_p, players[i].skincolor);        for (j=0 ; j<NUMPSPRITES ; j++)        {            if (players[i].psprites[j].state)                WRITEUSHORT(save_p, (players[i].psprites[j].state-states)+1);            else                WRITEUSHORT(save_p, 0);            WRITELONG(save_p, players[i].psprites[j].tics);            WRITEFIXED(save_p, players[i].psprites[j].sx);            WRITEFIXED(save_p, players[i].psprites[j].sy);        }        WRITEUSHORT(save_p, flags);        if( inventory )        {            WRITEBYTE( save_p, players[i].inventorySlotNum );            for( j=0; j<players[i].inventorySlotNum ; j++ )            {                 WRITEMEM( save_p, &players[i].inventory[j], sizeof(players[i].inventory[j]));            }        }    }}//// P_UnArchivePlayers//void P_UnArchivePlayers (void){    int     i,j;    int     flags;    ULONG   diff;    for (i=0 ; i<MAXPLAYERS ; i++)    {        memset (&players[i],0 , sizeof(player_t));        if (!playeringame[i])            continue;        PADSAVEP();        diff = READULONG(save_p);        players[i].aiming = READANGLE(save_p);        players[i].health = READUSHORT(save_p);        players[i].armorpoints = READUSHORT(save_p);        players[i].armortype = READBYTE(save_p);        for(j=0;j<NUMPOWERS;j++)            if( diff & (1<<j)) players[i].powers[j] = READLONG(save_p);        players[i].cards = READBYTE(save_p);        players[i].readyweapon = READBYTE(save_p);        players[i].pendingweapon = READBYTE(save_p);        players[i].playerstate = READBYTE(save_p);        players[i].addfrags = READUSHORT(save_p);        for(j=0;j<MAXPLAYERS;j++)            if(playeringame[i])                players[i].frags[j] = READUSHORT(save_p);        for(j=0;j<NUMWEAPONS;j++)            players[i].favoritweapon[j] = READBYTE(save_p);        for(j=0;j<NUMAMMO;j++)        {            players[i].ammo[j] = READUSHORT(save_p);            players[i].maxammo[j] = READUSHORT(save_p);        }        if(diff & PD_REFIRE     )  players[i].refire      = READLONG(save_p);        if(diff & PD_KILLCOUNT  )  players[i].killcount   = READLONG(save_p);        if(diff & PD_ITEMCOUNT  )  players[i].itemcount   = READLONG(save_p);        if(diff & PD_SECRETCOUNT)  players[i].secretcount = READLONG(save_p);        if(diff & PD_DAMAGECOUNT)  players[i].damagecount = READLONG(save_p);        if(diff & PD_BONUSCOUNT )  players[i].bonuscount  = READLONG(save_p);        if(diff & PD_CHICKENTICS)  players[i].chickenTics = READLONG(save_p);        if(diff & PD_CHICKEPECK )  players[i].chickenPeck = READLONG(save_p);         if(diff & PD_FLAMECOUNT )  players[i].flamecount  = READLONG(save_p);         if(diff & PD_FLYHEIGHT  )  players[i].flyheight   = READLONG(save_p);         players[i].skincolor = READBYTE(save_p);        for (j=0 ; j<NUMPSPRITES ; j++)        {            flags = READUSHORT(save_p);            if (flags)                players[i].psprites[j].state = &states[flags-1];            players[i].psprites[j].tics = READLONG(save_p);            players[i].psprites[j].sx = READFIXED(save_p);            players[i].psprites[j].sy = READFIXED(save_p);        }        flags = READUSHORT(save_p);        if( inventory )        {            players[i].inventorySlotNum = READBYTE( save_p );            for( j=0; j<players[i].inventorySlotNum ; j++ )            {                 READMEM( save_p, &players[i].inventory[j], sizeof(players[i].inventory[j]));            }        }        for(j=0;j<NUMWEAPONS;j++)            players[i].weaponowned[j] = (flags & (1<<j))!=0;        players[i].backpack = (flags & BACKPACK) !=0;        players[i].originalweaponswitch = (flags & ORIGNWEAP) !=0;        players[i].autoaim_toggle       = (flags & AUTOAIM) !=0;        players[i].attackdown = (flags & ATTACKDWN) !=0;        players[i].usedown = (flags & USEDWN) !=0;        players[i].jumpdown = (flags & JMPDWN) !=0;        players[i].didsecret = (flags & DIDSECRET) !=0;        players[i].viewheight = cv_viewheight.value<<FRACBITS;        if( gamemode == heretic )        {            if( players[i].powers[pw_weaponlevel2] )                players[i].weaponinfo = wpnlev2info;            else                players[i].weaponinfo = wpnlev1info;        }        else            players[i].weaponinfo = doomweaponinfo;    }}#define SD_FLOORHT     0x01#define SD_CEILHT      0x02#define SD_FLOORPIC    0x04#define SD_CEILPIC     0x08#define SD_LIGHT       0x10#define SD_SPECIAL     0x20#define SD_DIFF2       0x40//SoM: 4/10/2000: Fix sector related savegame bugs// diff2 flags#define SD_FXOFFS     0x01#define SD_FYOFFS     0x02#define SD_CXOFFS     0x04#define SD_CYOFFS     0x08#define SD_STAIRLOCK  0x10#define SD_PREVSEC    0x20#define SD_NEXTSEC    0x40#define LD_FLAG     0x01#define LD_SPECIAL  0x02//#define LD_TAG      0x04#define LD_S1TEXOFF 0x08#define LD_S1TOPTEX 0x10#define LD_S1BOTTEX 0x20#define LD_S1MIDTEX 0x40#define LD_DIFF2    0x80// diff2 flags#define LD_S2TEXOFF 0x01#define LD_S2TOPTEX 0x02#define LD_S2BOTTEX 0x04#define LD_S2MIDTEX 0x08//// P_ArchiveWorld//void P_ArchiveWorld (void){    int                 i;    int           statsec=0,statline=0;    line_t*       li;    side_t*       si;    byte*         put;    // reload the map just to see difference    mapsector_t   *ms;

⌨️ 快捷键说明

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