save an object chain; sets head of list to Null when done; handles release_data() for each object in the list */
| 759 | /* save an object chain; sets head of list to Null when done; |
| 760 | handles release_data() for each object in the list */ |
| 761 | staticfn void |
| 762 | saveobjchn(NHFILE *nhfp, struct obj **obj_p) |
| 763 | { |
| 764 | struct obj *otmp = *obj_p; |
| 765 | struct obj *otmp2; |
| 766 | boolean is_invent = (otmp && otmp == gi.invent); |
| 767 | int minusone = -1; |
| 768 | |
| 769 | while (otmp) { |
| 770 | otmp2 = otmp->nobj; |
| 771 | if (update_file(nhfp)) { |
| 772 | saveobj(nhfp, otmp); |
| 773 | } |
| 774 | if (Has_contents(otmp)) |
| 775 | saveobjchn(nhfp, &otmp->cobj); |
| 776 | if (release_data(nhfp)) { |
| 777 | /* |
| 778 | * If these are on the floor, the discarding could be |
| 779 | * due to game save, or we could just be changing levels. |
| 780 | * Always invalidate the pointer, but ensure that we have |
| 781 | * the o_id in order to restore the pointer on reload. |
| 782 | */ |
| 783 | if (otmp == svc.context.victual.piece) { |
| 784 | svc.context.victual.o_id = otmp->o_id; |
| 785 | svc.context.victual.piece = (struct obj *) 0; |
| 786 | } |
| 787 | if (otmp == svc.context.tin.tin) { |
| 788 | svc.context.tin.o_id = otmp->o_id; |
| 789 | svc.context.tin.tin = (struct obj *) 0; |
| 790 | } |
| 791 | if (otmp == svc.context.spbook.book) { |
| 792 | svc.context.spbook.o_id = otmp->o_id; |
| 793 | svc.context.spbook.book = (struct obj *) 0; |
| 794 | } |
| 795 | otmp->where = OBJ_FREE; /* set to free so dealloc will work */ |
| 796 | otmp->nobj = NULL; /* nobj saved into otmp2 */ |
| 797 | otmp->cobj = NULL; /* contents handled above */ |
| 798 | otmp->timed = 0; /* not timed any more */ |
| 799 | otmp->lamplit = 0; /* caller handled lights */ |
| 800 | otmp->leashmon = 0; /* mon->mleashed could still be set; |
| 801 | * unfortunately, we can't clear that |
| 802 | * until after the monster is saved */ |
| 803 | /* clear 'uball' and 'uchain' pointers if resetting their mask; |
| 804 | could also do same for other worn items but don't need to */ |
| 805 | if ((otmp->owornmask & (W_BALL | W_CHAIN)) != 0) |
| 806 | setworn((struct obj *) 0, |
| 807 | otmp->owornmask & (W_BALL | W_CHAIN)); |
| 808 | otmp->owornmask = 0L; /* no longer care */ |
| 809 | program_state.freeingdata++; |
| 810 | dealloc_obj(otmp); |
| 811 | program_state.freeingdata--; |
| 812 | } |
| 813 | otmp = otmp2; |
| 814 | } |
| 815 | if (update_file(nhfp)) { |
| 816 | Sfo_int(nhfp, &minusone, "obj-obj_length"); |
| 817 | } |
| 818 | if (release_data(nhfp)) { |
no test coverage detected