MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SaveGameState

Function SaveGameState

Descent3/gamesave.cpp:722–828  ·  view source on GitHub ↗

give a description and slot number (0 to GAMESAVE_SLOTS-1)

Source from the content-addressed store, hash-verified

720
721// give a description and slot number (0 to GAMESAVE_SLOTS-1)
722bool SaveGameState(const char *pathname, const char *description) {
723 CFILE *fp;
724 char buf[GAMESAVE_DESCLEN + 1];
725 int16_t pending_music_region;
726
727 fp = cfopen(pathname, "wb");
728 if (!fp)
729 return false;
730
731 // Delete the old games restored count.
732 char countpath[_MAX_PATH * 2];
733 strcpy(countpath, pathname);
734 strcat(countpath, ".cnt");
735 CFILE *countfp;
736 countfp = cfopen(countpath, "wb");
737 if (countfp) {
738 cf_WriteInt(countfp, Times_game_restored);
739 cfclose(countfp);
740 }
741
742 // save out header
743 START_VERIFY_SAVEFILE(fp);
744 ASSERT(strlen(description) < sizeof(buf));
745 strcpy(buf, description);
746 cf_WriteBytes((uint8_t *)buf, sizeof(buf), fp);
747 cf_WriteShort(fp, GAMESAVE_VERSION);
748
749 SGSSnapshot(fp); // Save snapshot? MUST KEEP THIS HERE.
750
751 // write out translation tables
752 SGSXlateTables(fp);
753
754 // write out gamemode information
755
756 // write out mission level information
757 cf_WriteShort(fp, (int16_t)Current_mission.cur_level);
758
759 if (Current_mission.filename && (stricmp("d3_2.mn3", Current_mission.filename) == 0)) {
760 cf_WriteString(fp, "d3.mn3");
761 } else {
762 cf_WriteString(fp, Current_mission.filename ? Current_mission.filename : "");
763 }
764
765 cf_WriteInt(fp, Current_mission.game_state_flags);
766
767 cf_WriteFloat(fp, Gametime);
768 cf_WriteInt(fp, FrameCount);
769 cf_WriteInt(fp, Current_waypoint);
770
771 pending_music_region = D3MusicGetPendingRegion();
772 if (pending_music_region < 0) {
773 pending_music_region = D3MusicGetRegion();
774 }
775 cf_WriteShort(fp, pending_music_region);
776
777 // cf_WriteInt(fp,Times_game_restored);
778 // Save weather
779 cf_WriteInt(fp, sizeof(Weather));

Callers 2

QuickSaveGameFunction · 0.85
SaveGameDialogFunction · 0.85

Calls 15

cfopenFunction · 0.85
cf_WriteIntFunction · 0.85
cfcloseFunction · 0.85
cf_WriteBytesFunction · 0.85
cf_WriteShortFunction · 0.85
SGSSnapshotFunction · 0.85
SGSXlateTablesFunction · 0.85
cf_WriteStringFunction · 0.85
cf_WriteFloatFunction · 0.85
D3MusicGetPendingRegionFunction · 0.85
D3MusicGetRegionFunction · 0.85
SGSRoomsFunction · 0.85

Tested by

no test coverage detected