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

Function SaveLevel

Descent3/LoadLevel.cpp:5023–5319  ·  view source on GitHub ↗

Save a level file Returns 1 if file saved ok, else 0

Source from the content-addressed store, hash-verified

5021// Save a level file
5022// Returns 1 if file saved ok, else 0
5023int SaveLevel(char *filename, bool f_save_room_AABB) {
5024 CFILE *ofile;
5025 int i, highest_used_index;
5026 int chunk_start_pos;
5027 int count;
5028
5029 // Check for too many path portals
5030 for (int r = 0; r <= Highest_room_index; r++) {
5031 if (Rooms[r].num_portals > MAX_PATH_PORTALS)
5032 if (EditorMessageBox(MBOX_YESNO,
5033 "Room %d has %d portals, which is more than the %d portals that the path system allows."
5034 "\n\nDo you want to save anyway?",
5035 r, MAX_PATH_PORTALS) != IDYES)
5036 return 0;
5037 }
5038#ifndef NEWEDITOR
5039 // Get the level ready to save
5040 ClearTransientObjects(1); // 1 means clear proximity bombs
5041#endif
5042 // CompressMine(); //get rid of holes in room list
5043 MakeBOA();
5044 EBNode_VerifyGraph();
5045 ConsolidateMineMirrors();
5046
5047 if (f_save_room_AABB) {
5048 // Compute the bounding boxes
5049 ComputeAABB(true);
5050 }
5051
5052 // Find shells for all the rooms
5053 if (!FindArg("-noshells"))
5054 ComputeAllRoomShells();
5055
5056 ofile = cfopen(filename, "wb");
5057
5058 if (!ofile) {
5059 EditorMessageBox("Can't open file <%s> for writing: %s.", filename, sys_errlist[errno]);
5060 return 0;
5061 }
5062
5063 try { // catch cfile errors
5064
5065 // Write tag & version number
5066 cf_WriteBytes((uint8_t *)LEVEL_FILE_TAG, 4, ofile);
5067 cf_WriteInt(ofile, LEVEL_FILE_VERSION);
5068
5069 WriteGamePathsChunk(ofile);
5070
5071 // Write terrain sounds
5072 chunk_start_pos = StartChunk(ofile, CHUNK_TERRAIN_SOUND);
5073 int n_bands = 0, b;
5074 for (b = 0; b < NUM_TERRAIN_SOUND_BANDS; b++)
5075 if (Terrain_sound_bands[b].sound_index != -1)
5076 n_bands++;
5077 cf_WriteInt(ofile, n_bands);
5078 for (b = 0; b < NUM_TERRAIN_SOUND_BANDS; b++) {
5079 if (Terrain_sound_bands[b].sound_index != -1) {
5080 cf_WriteString(ofile, Sounds[Terrain_sound_bands[b].sound_index].name);

Callers 3

EditorSaveLevelFunction · 0.85
EditorToGameFunction · 0.85
DoRadiosityForRoomsFunction · 0.85

Calls 15

ClearTransientObjectsFunction · 0.85
MakeBOAFunction · 0.85
EBNode_VerifyGraphFunction · 0.85
ConsolidateMineMirrorsFunction · 0.85
ComputeAABBFunction · 0.85
ComputeAllRoomShellsFunction · 0.85
cfopenFunction · 0.85
cf_WriteBytesFunction · 0.85
cf_WriteIntFunction · 0.85
WriteGamePathsChunkFunction · 0.85
StartChunkFunction · 0.85
cf_WriteStringFunction · 0.85

Tested by

no test coverage detected