MCPcopy Index your code
hub / github.com/NetHack/NetHack / savelev_core

Function savelev_core

src/save.c:451–567  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

449}
450
451staticfn void
452savelev_core(NHFILE *nhfp, xint8 lev)
453{
454#ifdef TOS
455 short tlev;
456#endif
457 int i, c, r;
458 coord *tmpc;
459
460 program_state.saving++; /* even if current mode is FREEING */
461
462 if (!nhfp)
463 panic("Save on bad file!"); /* impossible */
464 /*
465 * Level file contents:
466 * version info (handled by caller);
467 * save file info (compression type; also by caller);
468 * process ID;
469 * internal level number (ledger number);
470 * bones info;
471 * actual level data.
472 *
473 * If we're tearing down the current level without saving anything
474 * (which happens at end of game or upon entrance to endgame or
475 * after an aborted restore attempt) then we don't want to do any
476 * actual I/O. So when only freeing, we skip to the bones info
477 * portion (which has some freeing to do), then jump quite a bit
478 * further ahead to the middle of the 'actual level data' portion.
479 */
480 if (nhfp->mode != FREEING) {
481 /* WRITING (probably ORed with FREEING), or COUNTING */
482
483 /* purge any dead monsters (necessary if we're starting
484 a panic save rather than a normal one, or sometimes
485 when changing levels without taking time -- e.g.
486 create statue trap then immediately level teleport) */
487 if (iflags.purge_monsters)
488 dmonsfree();
489 /* clear objs_deleted list too */
490 if (go.objs_deleted)
491 dobjsfree(); /* really free deleted objects */
492
493 if (lev >= 0 && lev <= maxledgerno())
494 svl.level_info[lev].flags |= VISITED;
495 Sfo_int(nhfp, &svh.hackpid, "gamestate-hackpid");
496 Sfo_xint8(nhfp, &lev, "gamestate-dlvl");
497 }
498
499 /* bones info comes before level data; the intent is for an external
500 program ('hearse') to be able to match a bones file with the
501 corresponding log file entry--or perhaps just skip that?--without
502 the guessing that was needed in 3.4.3 and without having to
503 interpret level data to find where to start; unfortunately it
504 still needs to handle all the data compression schemes */
505 savecemetery(nhfp, &svl.level.bonesinfo);
506 if (nhfp->mode == FREEING) /* see above */
507 goto skip_lots;
508

Callers 1

savelevFunction · 0.85

Calls 15

dmonsfreeFunction · 0.85
dobjsfreeFunction · 0.85
maxledgernoFunction · 0.85
savecemeteryFunction · 0.85
savelevlFunction · 0.85
save_stairsFunction · 0.85
save_adjust_levelflagsFunction · 0.85
rest_adjust_levelflagsFunction · 0.85
save_roomsFunction · 0.85
save_timersFunction · 0.85
save_light_sourcesFunction · 0.85
savemonchnFunction · 0.85

Tested by

no test coverage detected