| 522 | staticfn |
| 523 | #endif |
| 524 | boolean |
| 525 | restgamestate(NHFILE *nhfp) |
| 526 | { |
| 527 | int i; |
| 528 | struct flag newgameflags; |
| 529 | struct context_info newgamecontext; /* all 0, but has some pointers */ |
| 530 | struct obj *bc_obj; |
| 531 | char timebuf[15]; |
| 532 | unsigned long uid = 0; |
| 533 | #ifndef SFCTOOL |
| 534 | boolean defer_perm_invent, restoring_special; |
| 535 | struct obj *otmp; |
| 536 | #endif |
| 537 | |
| 538 | Sfi_ulong(nhfp, &uid, "gamestate-uid"); |
| 539 | Sfi_char(nhfp, &svn.nhuuid[0], "nhuuid", sizeof svn.nhuuid); |
| 540 | Sfi_long(nhfp, &svm.moves, "gamestate-moves"); |
| 541 | #ifndef SFCTOOL |
| 542 | if (SYSOPT_CHECK_SAVE_UID |
| 543 | && uid != (unsigned long) getuid()) { /* strange ... */ |
| 544 | if (!gc.converted_savefile_loaded) |
| 545 | /* for wizard mode, issue a reminder; for others, treat it |
| 546 | * as an attempt to cheat and refuse to restore this file */ |
| 547 | pline("Saved game was not yours."); |
| 548 | if (wizard || gc.converted_savefile_loaded) { |
| 549 | if (gc.converted_savefile_loaded) |
| 550 | gc.converted_savefile_loaded = FALSE; |
| 551 | } else { |
| 552 | return FALSE; |
| 553 | } |
| 554 | } |
| 555 | #endif /* SFCTOOL */ |
| 556 | newgamecontext = svc.context; /* copy statically init'd context */ |
| 557 | Sfi_context_info(nhfp, &svc.context, "gamestate-context"); |
| 558 | relative_time_to_moves(&svc.context.seer_turn); |
| 559 | relative_time_to_moves(&svc.context.digging.lastdigtime); |
| 560 | svc.context.warntype.species = (ismnum(svc.context.warntype.speciesidx)) |
| 561 | ? &mons[svc.context.warntype.speciesidx] |
| 562 | : (struct permonst *) 0; |
| 563 | /* context.victual.piece, .tin.tin, .spellbook.book, and .polearm.hitmon |
| 564 | are pointers which get set to Null during save and will be recovered |
| 565 | via corresponding o_id or m_id while objs or mons are being restored */ |
| 566 | |
| 567 | /* we want to be able to revert to command line/environment/config |
| 568 | file option values instead of keeping old save file option values |
| 569 | if partial restore fails and we resort to starting a new game */ |
| 570 | newgameflags = flags; |
| 571 | Sfi_flag(nhfp, &flags, "gamestate-flags"); |
| 572 | |
| 573 | #ifndef SFCTOOL |
| 574 | /* avoid keeping permanent inventory window up to date during restore |
| 575 | (setworn() calls update_inventory); attempting to include the cost |
| 576 | of unpaid items before shopkeeper's bill is available is a no-no; |
| 577 | named fruit names aren't accessible yet either |
| 578 | [3.6.2: moved perm_invent from flags to iflags to keep it out of |
| 579 | save files; retaining the override here is simpler than trying |
| 580 | to figure out where it really belongs now] */ |
| 581 | defer_perm_invent = iflags.perm_invent; |
no test coverage detected