void G_DoLoadGame(void) { int i; int a, b, c; char savestr[SAVESTRINGSIZE]; char vcheck[VERSIONSIZE], readversion[VERSIONSIZE]; gameaction = ga_nothing; SV_OpenRead(savename); free(savename); savename = NULL; // Skip the description field SV_Read(savestr, SAVESTRINGSIZE); memset(vcheck, 0, sizeof(vcheck)); DEH_snprintf(vcheck, VERSIONSIZE, "version %i", HERETIC_VERSION); SV_Read(readversion, VERSIONSIZE); if (strncmp(readversion, vcheck, VERSIONSIZE) != 0) { // Bad version return; } gameskill = SV_ReadByte(); gameepisode = SV_ReadByte(); gamemap = SV_ReadByte(); for (i = 0; i < MAXPLAYERS; i++) { playeringame[i] = SV_ReadByte(); } // Load a base level G_InitNew(gameskill, gameepisode, gamemap); // Create leveltime a = SV_ReadByte(); b = SV_ReadByte(); c = SV_ReadByte(); leveltime = (a << 16) + (b << 8) + c; // De-archive all the modifications P_UnArchivePlayers(); P_UnArchiveWorld(); P_UnArchiveThinkers(); P_UnArchiveSpecials(); if (SV_ReadByte() != SAVE_GAME_TERMINATOR) { // Missing savegame termination marker I_Error("Bad savegame"); } }
static void saveg_read_ticcmd_t(ticcmd_t *str) { // char forwardmove; str->forwardmove = SV_ReadByte(); // char sidemove; str->sidemove = SV_ReadByte(); // short angleturn; str->angleturn = SV_ReadWord(); // short consistancy; str->consistancy = SV_ReadWord(); // byte chatchar; str->chatchar = SV_ReadByte(); // byte buttons; str->buttons = SV_ReadByte(); // byte lookfly; str->lookfly = SV_ReadByte(); // byte arti; str->arti = SV_ReadByte(); }
void P_UnArchiveThinkers(void) { byte tclass; thinker_t *currentthinker, *next; mobj_t *mobj; // // remove all the current thinkers // currentthinker = thinkercap.next; while (currentthinker != &thinkercap) { next = currentthinker->next; if (currentthinker->function == P_MobjThinker) P_RemoveMobj((mobj_t *) currentthinker); else Z_Free(currentthinker); currentthinker = next; } P_InitThinkers(); // read in saved thinkers while (1) { tclass = SV_ReadByte(); switch (tclass) { case tc_end: return; // end of list case tc_mobj: mobj = Z_Malloc(sizeof(*mobj), PU_LEVEL, NULL); saveg_read_mobj_t(mobj); mobj->target = NULL; P_SetThingPosition(mobj); mobj->info = &mobjinfo[mobj->type]; mobj->floorz = mobj->subsector->sector->floorheight; mobj->ceilingz = mobj->subsector->sector->ceilingheight; mobj->thinker.function = P_MobjThinker; P_AddThinker(&mobj->thinker); break; default: I_Error("Unknown tclass %i in savegame", tclass); } } }
void P_UnArchiveSpecials(void) { byte tclass; ceiling_t *ceiling; vldoor_t *door; floormove_t *floor; plat_t *plat; lightflash_t *flash; strobe_t *strobe; glow_t *glow; // read in saved thinkers while (1) { tclass = SV_ReadByte(); switch (tclass) { case tc_endspecials: return; // end of list case tc_ceiling: ceiling = Z_Malloc(sizeof(*ceiling), PU_LEVEL, NULL); saveg_read_ceiling_t(ceiling); ceiling->sector->specialdata = T_MoveCeiling; // ??? ceiling->thinker.function = T_MoveCeiling; P_AddThinker(&ceiling->thinker); P_AddActiveCeiling(ceiling); break; case tc_door: door = Z_Malloc(sizeof(*door), PU_LEVEL, NULL); saveg_read_vldoor_t(door); door->sector->specialdata = door; door->thinker.function = T_VerticalDoor; P_AddThinker(&door->thinker); break; case tc_floor: floor = Z_Malloc(sizeof(*floor), PU_LEVEL, NULL); saveg_read_floormove_t(floor); floor->sector->specialdata = T_MoveFloor; floor->thinker.function = T_MoveFloor; P_AddThinker(&floor->thinker); break; case tc_plat: plat = Z_Malloc(sizeof(*plat), PU_LEVEL, NULL); saveg_read_plat_t(plat); plat->sector->specialdata = T_PlatRaise; // In the original Heretic code this was a conditional "fix" // of the thinker function, but the save code (above) decides // whether to save a T_PlatRaise based on thinker function // anyway, so it can't be NULL. Having the conditional causes // a bug, as our saveg_read_thinker_t sets these to NULL. // if (plat->thinker.function) plat->thinker.function = T_PlatRaise; P_AddThinker(&plat->thinker); P_AddActivePlat(plat); break; case tc_flash: flash = Z_Malloc(sizeof(*flash), PU_LEVEL, NULL); saveg_read_lightflash_t(flash); flash->thinker.function = T_LightFlash; P_AddThinker(&flash->thinker); break; case tc_strobe: strobe = Z_Malloc(sizeof(*strobe), PU_LEVEL, NULL); saveg_read_strobe_t(strobe); strobe->thinker.function = T_StrobeFlash; P_AddThinker(&strobe->thinker); break; case tc_glow: glow = Z_Malloc(sizeof(*glow), PU_LEVEL, NULL); saveg_read_glow_t(glow); glow->thinker.function = T_Glow; P_AddThinker(&glow->thinker); break; default: I_Error("P_UnarchiveSpecials:Unknown tclass %i " "in savegame", tclass); } } }