| 449 | } |
| 450 | |
| 451 | staticfn void |
| 452 | savelev_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 |
no test coverage detected