4 * Copyright (c) 1997 Ben Harrison, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: support for loading savefiles -BEN- */
17 * This file loads savefiles from Angband 2.7.X and 2.8.X
19 * Ancient savefiles (pre-2.7.0) are loaded by another file.
21 * Note that Angband 2.7.0 through 2.7.3 are now officially obsolete,
22 * and savefiles from those versions may not be successfully converted.
24 * We attempt to prevent corrupt savefiles from inducing memory errors.
26 * Note that this file should not use the random number generator, the
27 * object flavors, the visual attr/char mappings, or anything else which
28 * is initialized *after* or *during* the "load character" function.
30 * This file assumes that the monster/object records are initialized
31 * to zero, and the race/kind tables have been loaded correctly. The
32 * order of object stacks is currently not saved in the savefiles, but
33 * the "next" pointers are saved, so all necessary knowledge is present.
35 * We should implement simple "savefile extenders" using some form of
36 * "sized" chunks of bytes, with a {size,type,data} format, so everyone
37 * can know the size, interested people can know the type, and the actual
38 * data is available to the parsing routines that acknowledge the type.
40 * Consider changing the "globe of invulnerability" code so that it
41 * takes some form of "maximum damage to protect from" in addition to
42 * the existing "number of turns to protect for", and where each hit
43 * by a monster will reduce the shield by that amount.
51 * Maximum number of tries for selection of a proper quest monster
57 * Local "savefile" pointer
62 * Hack -- old "encryption" byte
67 * Hack -- simple "checksum" on the actual values
69 static u32b v_check = 0L;
72 * Hack -- simple "checksum" on the encoded bytes
74 static u32b x_check = 0L;
77 * Hack -- Japanese Kanji code
83 static byte kanji_code = 0;
86 * This function determines if the version of the savefile
87 * currently being read is older than version "major.minor.patch.extra".
89 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
91 /* Much older, or much more recent */
92 if (h_ver_major < major) return (TRUE);
93 if (h_ver_major > major) return (FALSE);
95 /* Distinctly older, or distinctly more recent */
96 if (h_ver_minor < minor) return (TRUE);
97 if (h_ver_minor > minor) return (FALSE);
99 /* Barely older, or barely more recent */
100 if (h_ver_patch < patch) return (TRUE);
101 if (h_ver_patch > patch) return (FALSE);
103 /* Barely older, or barely more recent */
104 if (h_ver_extra < extra) return (TRUE);
105 if (h_ver_extra > extra) return (FALSE);
107 /* Identical versions */
113 * The above function, adapted for Zangband
115 static bool z_older_than(byte x, byte y, byte z)
117 /* Much older, or much more recent */
118 if (z_major < x) return (TRUE);
119 if (z_major > x) return (FALSE);
121 /* Distinctly older, or distinctly more recent */
122 if (z_minor < y) return (TRUE);
123 if (z_minor > y) return (FALSE);
125 /* Barely older, or barely more recent */
126 if (z_patch < z) return (TRUE);
127 if (z_patch > z) return (FALSE);
129 /* Identical versions */
135 * Hack -- Show information on the screen, one line at a time.
137 * Avoid the top two lines, to avoid interference with "msg_print()".
139 static void note(cptr msg)
143 /* Draw the message */
146 /* Advance one line (wrap if needed) */
147 if (++y >= 24) y = 2;
155 * The following functions are used to load the basic building blocks
156 * of savefiles. They also maintain the "checksum" info for 2.7.0+
159 static byte sf_get(void)
163 /* Get a character, decode the value */
164 c = getc(fff) & 0xFF;
168 /* Maintain the checksum info */
172 /* Return the value */
176 static void rd_byte(byte *ip)
181 static void rd_u16b(u16b *ip)
184 (*ip) |= ((u16b)(sf_get()) << 8);
187 static void rd_s16b(s16b *ip)
192 static void rd_u32b(u32b *ip)
195 (*ip) |= ((u32b)(sf_get()) << 8);
196 (*ip) |= ((u32b)(sf_get()) << 16);
197 (*ip) |= ((u32b)(sf_get()) << 24);
200 static void rd_s32b(s32b *ip)
207 * Hack -- read a string
209 static void rd_string(char *str, int max)
213 /* Read the string */
214 for (i = 0; TRUE; i++)
221 /* Collect string while legal */
222 if (i < max) str[i] = tmp8u;
233 /* Convert Kanji code */
252 /* ÉÔÌÀ¤Î´Á»ú¥³¡¼¥É¤«¤é¥·¥¹¥Æ¥à¤Î´Á»ú¥³¡¼¥É¤ËÊÑ´¹ */
253 byte code = codeconv(str);
255 /* ´Á»ú¥³¡¼¥É¤¬È½ÌÀ¤·¤¿¤é¡¢¤½¤ì¤òµÏ¿ */
256 if (code) kanji_code = code;
261 /* No conversion needed */
269 * Hack -- strip some bytes
271 static void strip_bytes(int n)
275 /* Strip the bytes */
276 while (n--) rd_byte(&tmp8u);
279 #define OLD_MAX_MANE 22
282 * Read an object (Old method)
284 * This function attempts to "repair" old savefiles, and to extract
285 * the most up to date values for various object fields.
287 * Note that Angband 2.7.9 introduced a new method for object "flags"
288 * in which the "flags" on an object are actually extracted when they
289 * are needed from the object kind, artifact index, ego-item index,
290 * and two special "xtra" fields which are used to encode any "extra"
291 * power of certain ego-items. This had the side effect that items
292 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
293 * may have had, and also, all "uncursed" items will become "cursed"
294 * again, including Calris, even if it is being worn at the time. As
295 * a complete hack, items which are inscribed with "uncursed" will be
296 * "uncursed" when imported from pre-2.7.9 savefiles.
298 static void rd_item_old(object_type *o_ptr)
304 rd_s16b(&o_ptr->k_idx);
311 rd_byte(&o_ptr->tval);
312 rd_byte(&o_ptr->sval);
314 if (z_older_than(10, 4, 4))
316 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
317 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
318 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
322 rd_s16b(&o_ptr->pval);
324 rd_byte(&o_ptr->discount);
325 rd_byte(&o_ptr->number);
326 rd_s16b(&o_ptr->weight);
328 rd_byte(&o_ptr->name1);
329 rd_byte(&o_ptr->name2);
330 rd_s16b(&o_ptr->timeout);
332 rd_s16b(&o_ptr->to_h);
333 rd_s16b(&o_ptr->to_d);
334 rd_s16b(&o_ptr->to_a);
341 rd_byte(&o_ptr->ident);
343 rd_byte(&o_ptr->marked);
346 rd_u32b(&o_ptr->art_flags[0]);
347 rd_u32b(&o_ptr->art_flags[1]);
348 rd_u32b(&o_ptr->art_flags[2]);
349 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
350 else rd_u32b(&o_ptr->art_flags[3]);
352 if (h_older_than(1, 3, 0, 0))
354 if (o_ptr->name2 == EGO_TELEPATHY)
355 add_flag(o_ptr->art_flags, TR_TELEPATHY);
358 if (z_older_than(11, 0, 11))
360 o_ptr->curse_flags = 0L;
361 if (o_ptr->ident & 0x40)
363 o_ptr->curse_flags |= TRC_CURSED;
364 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
365 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
368 artifact_type *a_ptr = &a_info[o_ptr->name1];
369 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
370 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
372 else if (o_ptr->name2)
374 ego_item_type *e_ptr = &e_info[o_ptr->name2];
375 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
376 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
379 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
383 rd_u32b(&o_ptr->curse_flags);
386 /* Monster holding object */
387 rd_s16b(&o_ptr->held_m_idx);
390 rd_byte(&o_ptr->xtra1);
391 rd_byte(&o_ptr->xtra2);
393 if (z_older_than(11, 0, 10))
395 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
397 switch (o_ptr->xtra2 % 6)
399 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
400 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
401 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
402 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
403 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
404 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
408 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
410 switch (o_ptr->xtra2 % 11)
412 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
413 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
414 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
415 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
416 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
417 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
418 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
419 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
420 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
421 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
422 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
426 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
428 switch (o_ptr->xtra2 % 8)
430 case 0: add_flag(o_ptr->art_flags, TR_FEATHER); break;
431 case 1: add_flag(o_ptr->art_flags, TR_LITE); break;
432 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
433 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
434 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
435 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
436 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
437 case 7: add_flag(o_ptr->art_flags, TR_HOLD_LIFE); break;
444 if (z_older_than(10, 2, 3))
449 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
451 o_ptr->xtra3 = o_ptr->xtra1;
454 if (o_ptr->tval == TV_CAPTURE)
456 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
457 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
459 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
460 if (ironman_nightmare)
462 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
464 o_ptr->xtra4 = o_ptr->xtra5;
469 rd_byte(&o_ptr->xtra3);
470 if (h_older_than(1, 3, 0, 1))
472 if (item_tester_hook_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
473 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
476 rd_s16b(&o_ptr->xtra4);
477 rd_s16b(&o_ptr->xtra5);
480 if (z_older_than(11, 0, 5) && (((o_ptr->tval == TV_LITE) && ((o_ptr->sval == SV_LITE_TORCH) || (o_ptr->sval == SV_LITE_LANTERN))) || (o_ptr->tval == TV_FLASK)))
482 o_ptr->xtra4 = o_ptr->pval;
486 rd_byte(&o_ptr->feeling);
489 rd_string(buf, sizeof(buf));
491 /* Save the inscription */
492 if (buf[0]) o_ptr->inscription = quark_add(buf);
494 rd_string(buf, sizeof(buf));
495 if (buf[0]) o_ptr->art_name = quark_add(buf);
497 /* The Python object */
505 /* Mega-Hack -- handle "dungeon objects" later */
506 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
508 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
510 if (z_older_than(10, 4, 9))
512 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
514 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
515 add_flag(o_ptr->art_flags, TR_DEC_MANA);
522 artifact_type *a_ptr;
524 /* Obtain the artifact info */
525 a_ptr = &a_info[o_ptr->name1];
527 /* Verify that artifact */
528 if (!a_ptr->name) o_ptr->name1 = 0;
534 ego_item_type *e_ptr;
536 /* Obtain the ego-item info */
537 e_ptr = &e_info[o_ptr->name2];
539 /* Verify that ego-item */
540 if (!e_ptr->name) o_ptr->name2 = 0;
547 * Read an object (New method)
549 static void rd_item(object_type *o_ptr)
555 if (h_older_than(1, 5, 0, 0))
561 /*** Item save flags ***/
564 /*** Read un-obvious elements ***/
566 rd_s16b(&o_ptr->k_idx);
573 k_ptr = &k_info[o_ptr->k_idx];
574 o_ptr->tval = k_ptr->tval;
575 o_ptr->sval = k_ptr->sval;
578 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
579 else o_ptr->pval = 0;
581 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
582 else o_ptr->discount = 0;
583 if (flags & SAVE_ITEM_NUMBER) rd_byte(&o_ptr->number);
584 else o_ptr->number = 1;
586 rd_s16b(&o_ptr->weight);
588 if (flags & SAVE_ITEM_NAME1) rd_byte(&o_ptr->name1);
589 else o_ptr->name1 = 0;
590 if (flags & SAVE_ITEM_NAME2) rd_byte(&o_ptr->name2);
591 else o_ptr->name2 = 0;
592 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
593 else o_ptr->timeout = 0;
595 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
596 else o_ptr->to_h = 0;
597 if (flags & SAVE_ITEM_TO_D) rd_s16b(&o_ptr->to_d);
598 else o_ptr->to_d = 0;
599 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
600 else o_ptr->to_a = 0;
602 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
605 if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
607 if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
610 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
611 else o_ptr->ident = 0;
613 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
614 else o_ptr->marked = 0;
617 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
618 else o_ptr->art_flags[0] = 0;
619 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
620 else o_ptr->art_flags[1] = 0;
621 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
622 else o_ptr->art_flags[2] = 0;
623 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
624 else o_ptr->art_flags[3] = 0;
626 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
627 else o_ptr->curse_flags = 0;
629 /* Monster holding object */
630 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
631 else o_ptr->held_m_idx = 0;
634 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
635 else o_ptr->xtra1 = 0;
636 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
637 else o_ptr->xtra2 = 0;
639 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
640 else o_ptr->xtra3 = 0;
642 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
643 else o_ptr->xtra4 = 0;
644 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
645 else o_ptr->xtra5 = 0;
647 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
648 else o_ptr->feeling = 0;
650 if (flags & SAVE_ITEM_INSCRIPTION)
652 rd_string(buf, sizeof(buf));
653 if (buf[0]) o_ptr->inscription = quark_add(buf);
654 else o_ptr->inscription = 0;
656 else o_ptr->inscription = 0;
658 if (flags & SAVE_ITEM_ART_NAME)
660 rd_string(buf, sizeof(buf));
661 if (buf[0]) o_ptr->art_name = quark_add(buf);
662 else o_ptr->art_name = 0;
664 else o_ptr->art_name = 0;
669 * Read a monster (Old method)
671 static void rd_monster_old(monster_type *m_ptr)
676 /* Read the monster race */
677 rd_s16b(&m_ptr->r_idx);
679 if (z_older_than(11, 0, 12))
680 m_ptr->ap_r_idx = m_ptr->r_idx;
682 rd_s16b(&m_ptr->ap_r_idx);
684 if (z_older_than(11, 0, 14))
686 monster_race *r_ptr = &r_info[m_ptr->r_idx];
688 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
689 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
690 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
693 rd_byte(&m_ptr->sub_align);
695 /* Read the other information */
699 rd_s16b(&m_ptr->maxhp);
700 if (z_older_than(11, 0, 5))
702 m_ptr->max_maxhp = m_ptr->maxhp;
706 rd_s16b(&m_ptr->max_maxhp);
708 rd_s16b(&m_ptr->csleep);
709 rd_byte(&m_ptr->mspeed);
710 if (z_older_than(10, 4, 2))
713 m_ptr->energy_need = (s16b)tmp8u;
715 else rd_s16b(&m_ptr->energy_need);
717 if (z_older_than(11, 0, 13))
718 m_ptr->energy_need = 100 - m_ptr->energy_need;
720 if (z_older_than(10,0,7))
727 rd_byte(&m_ptr->fast);
728 rd_byte(&m_ptr->slow);
730 rd_byte(&m_ptr->stunned);
731 rd_byte(&m_ptr->confused);
732 rd_byte(&m_ptr->monfear);
734 if (z_older_than(10,0,10))
738 else if (z_older_than(10,0,11))
746 rd_s16b(&m_ptr->target_y);
747 rd_s16b(&m_ptr->target_x);
750 rd_byte(&m_ptr->invulner);
752 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
753 rd_u32b(&m_ptr->smart);
757 if (z_older_than(10, 4, 5))
760 rd_u32b(&m_ptr->exp);
762 if (z_older_than(10, 2, 2))
764 if (m_ptr->r_idx < 0)
766 m_ptr->r_idx = (0-m_ptr->r_idx);
767 m_ptr->mflag2 |= MFLAG2_KAGE;
772 rd_byte(&m_ptr->mflag2);
775 if (z_older_than(11, 0, 12))
777 if (m_ptr->mflag2 & MFLAG2_KAGE)
778 m_ptr->ap_r_idx = MON_KAGE;
781 if (z_older_than(10, 1, 3))
787 rd_string(buf, sizeof(buf));
788 if (buf[0]) m_ptr->nickname = quark_add(buf);
796 * Read a monster (New method)
798 static void rd_monster(monster_type *m_ptr)
803 if (h_older_than(1, 5, 0, 0))
805 rd_monster_old(m_ptr);
809 /*** Monster save flags ***/
812 /*** Read un-obvious elements ***/
814 /* Read the monster race */
815 rd_s16b(&m_ptr->r_idx);
817 /* Read the other information */
821 rd_s16b(&m_ptr->maxhp);
822 rd_s16b(&m_ptr->max_maxhp);
824 /* Monster race index of its appearance */
825 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
826 else m_ptr->ap_r_idx = m_ptr->r_idx;
828 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
829 else m_ptr->sub_align = 0;
831 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->csleep);
832 else m_ptr->csleep = 0;
834 rd_byte(&m_ptr->mspeed);
836 rd_s16b(&m_ptr->energy_need);
838 if (flags & SAVE_MON_FAST) rd_byte(&m_ptr->fast);
839 else m_ptr->fast = 0;
840 if (flags & SAVE_MON_SLOW) rd_byte(&m_ptr->slow);
841 else m_ptr->slow = 0;
842 if (flags & SAVE_MON_STUNNED) rd_byte(&m_ptr->stunned);
843 else m_ptr->stunned = 0;
844 if (flags & SAVE_MON_CONFUSED) rd_byte(&m_ptr->confused);
845 else m_ptr->confused = 0;
846 if (flags & SAVE_MON_MONFEAR) rd_byte(&m_ptr->monfear);
847 else m_ptr->monfear = 0;
849 if (flags & SAVE_MON_TARGET_Y) rd_s16b(&m_ptr->target_y);
850 else m_ptr->target_y = 0;
851 if (flags & SAVE_MON_TARGET_X) rd_s16b(&m_ptr->target_x);
852 else m_ptr->target_x = 0;
854 if (flags & SAVE_MON_INVULNER) rd_byte(&m_ptr->invulner);
855 else m_ptr->invulner = 0;
857 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
858 else m_ptr->smart = 0;
860 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
863 m_ptr->mflag = 0; /* Not saved */
865 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
866 else m_ptr->mflag2 = 0;
868 if (flags & SAVE_MON_NICKNAME)
870 rd_string(buf, sizeof(buf));
871 if (buf[0]) m_ptr->nickname = quark_add(buf);
872 else m_ptr->nickname = 0;
874 else m_ptr->nickname = 0;
876 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
877 else m_ptr->parent_m_idx = 0;
882 * Old monster bit flags of racial resistances
884 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
885 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
886 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
887 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
888 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
889 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
890 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
891 #define RF3_RES_WATE 0x00800000 /* Resist water */
892 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
893 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
894 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
895 #define RF3_RES_ALL 0x08000000 /* Resist all */
897 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
899 if ((R_PTR)->r_flags3 & (RF3)) \
901 (R_PTR)->r_flags3 &= ~(RF3); \
902 (R_PTR)->r_flagsr |= (RFR); \
906 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
908 if ((R_PTR)->r_flags4 & (RF4_BR)) \
910 (R_PTR)->r_flagsr |= (RFR); \
914 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
915 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
916 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
917 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
918 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
919 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
920 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
921 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
922 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
923 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
925 * Read the monster lore
927 static void rd_lore(int r_idx)
931 monster_race *r_ptr = &r_info[r_idx];
933 /* Count sights/deaths/kills */
934 rd_s16b(&r_ptr->r_sights);
935 rd_s16b(&r_ptr->r_deaths);
936 rd_s16b(&r_ptr->r_pkills);
937 rd_s16b(&r_ptr->r_tkills);
939 /* Count wakes and ignores */
940 rd_byte(&r_ptr->r_wake);
941 rd_byte(&r_ptr->r_ignore);
944 rd_byte(&r_ptr->r_xtra1);
945 rd_byte(&r_ptr->r_xtra2);
948 rd_byte(&r_ptr->r_drop_gold);
949 rd_byte(&r_ptr->r_drop_item);
953 rd_byte(&r_ptr->r_cast_spell);
955 /* Count blows of each type */
956 rd_byte(&r_ptr->r_blows[0]);
957 rd_byte(&r_ptr->r_blows[1]);
958 rd_byte(&r_ptr->r_blows[2]);
959 rd_byte(&r_ptr->r_blows[3]);
962 rd_u32b(&r_ptr->r_flags1);
963 rd_u32b(&r_ptr->r_flags2);
964 rd_u32b(&r_ptr->r_flags3);
965 rd_u32b(&r_ptr->r_flags4);
966 rd_u32b(&r_ptr->r_flags5);
967 rd_u32b(&r_ptr->r_flags6);
968 if (h_older_than(1, 5, 0, 3))
970 r_ptr->r_flagsr = 0L;
972 /* Move RF3 resistance flags to RFR */
973 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
974 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
975 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
976 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
977 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
978 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
979 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
980 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
981 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
982 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
983 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
984 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
986 /* Separate breathers resistance from RF4 to RFR */
987 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
988 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
989 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
990 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
991 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
992 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
993 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
994 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
995 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
997 /* Resist confusion is merged to RF3_NO_CONF */
998 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1000 /* Misc resistance hack to RFR */
1001 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1002 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1006 rd_u32b(&r_ptr->r_flagsr);
1009 /* Read the "Racial" monster limit per level */
1010 rd_byte(&r_ptr->max_num);
1012 /* Location in saved floor */
1013 rd_s16b(&r_ptr->floor_id);
1018 /* Repair the lore flags */
1019 r_ptr->r_flags1 &= r_ptr->flags1;
1020 r_ptr->r_flags2 &= r_ptr->flags2;
1021 r_ptr->r_flags3 &= r_ptr->flags3;
1022 r_ptr->r_flags4 &= r_ptr->flags4;
1023 r_ptr->r_flags5 &= r_ptr->flags5;
1024 r_ptr->r_flags6 &= r_ptr->flags6;
1025 r_ptr->r_flagsr &= r_ptr->flagsr;
1032 * Add the item "o_ptr" to the inventory of the "Home"
1034 * In all cases, return the slot (or -1) where the object was placed
1036 * Note that this is a hacked up version of "inven_carry()".
1038 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1039 * known, the player may have to pick stuff up and drop it again.
1041 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1044 s32b value, j_value;
1049 /* Check each existing item (try to combine) */
1050 for (slot = 0; slot < st_ptr->stock_num; slot++)
1052 /* Get the existing item */
1053 j_ptr = &st_ptr->stock[slot];
1055 /* The home acts just like the player */
1056 if (object_similar(j_ptr, o_ptr))
1058 /* Save the new number of items */
1059 object_absorb(j_ptr, o_ptr);
1067 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1071 /* Determine the "value" of the item */
1072 value = object_value(o_ptr);
1074 /* Check existing slots to see if we must "slide" */
1075 for (slot = 0; slot < st_ptr->stock_num; slot++)
1078 j_ptr = &st_ptr->stock[slot];
1080 /* Hack -- readable books always come first */
1081 if ((o_ptr->tval == mp_ptr->spell_book) &&
1082 (j_ptr->tval != mp_ptr->spell_book)) break;
1083 if ((j_ptr->tval == mp_ptr->spell_book) &&
1084 (o_ptr->tval != mp_ptr->spell_book)) continue;
1086 /* Objects sort by decreasing type */
1087 if (o_ptr->tval > j_ptr->tval) break;
1088 if (o_ptr->tval < j_ptr->tval) continue;
1090 /* Can happen in the home */
1091 if (!object_aware_p(o_ptr)) continue;
1092 if (!object_aware_p(j_ptr)) break;
1094 /* Objects sort by increasing sval */
1095 if (o_ptr->sval < j_ptr->sval) break;
1096 if (o_ptr->sval > j_ptr->sval) continue;
1098 /* Objects in the home can be unknown */
1099 if (!object_known_p(o_ptr)) continue;
1100 if (!object_known_p(j_ptr)) break;
1103 * Hack: otherwise identical rods sort by
1104 * increasing recharge time --dsb
1106 if (o_ptr->tval == TV_ROD)
1108 if (o_ptr->pval < j_ptr->pval) break;
1109 if (o_ptr->pval > j_ptr->pval) continue;
1112 /* Objects sort by decreasing value */
1113 j_value = object_value(j_ptr);
1114 if (value > j_value) break;
1115 if (value < j_value) continue;
1118 /* Slide the others up */
1119 for (i = st_ptr->stock_num; i > slot; i--)
1121 st_ptr->stock[i] = st_ptr->stock[i-1];
1124 /* More stuff now */
1125 st_ptr->stock_num++;
1127 /* Insert the new item */
1128 st_ptr->stock[slot] = *o_ptr;
1130 chg_virtue(V_SACRIFICE, -1);
1132 /* Return the location */
1140 static errr rd_store(int town_number, int store_number)
1152 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1154 st_ptr = &town[1].store[store_number];
1155 if (st_ptr->stock_num) sort = TRUE;
1159 st_ptr = &town[town_number].store[store_number];
1162 /* Read the basic info */
1163 rd_s32b(&st_ptr->store_open);
1164 rd_s16b(&st_ptr->insult_cur);
1166 if (z_older_than(11, 0, 4))
1175 rd_s16b(&st_ptr->good_buy);
1176 rd_s16b(&st_ptr->bad_buy);
1178 /* Read last visit */
1179 rd_s32b(&st_ptr->last_visit);
1181 /* Extract the owner (see above) */
1182 st_ptr->owner = own;
1184 /* Read the items */
1185 for (j = 0; j < num; j++)
1190 /* Get local object */
1193 /* Wipe the object */
1199 /* Acquire valid items */
1200 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1205 home_carry(st_ptr, q_ptr);
1209 k = st_ptr->stock_num++;
1211 /* Acquire the item */
1212 object_copy(&st_ptr->stock[k], q_ptr);
1224 * Read RNG state (added in 2.8.0)
1226 static void rd_randomizer(void)
1236 rd_u16b(&Rand_place);
1239 for (i = 0; i < RAND_DEG; i++)
1241 rd_u32b(&Rand_state[i]);
1251 * Read options (ignore most pre-2.8.0 options)
1253 * Note that the normal options are now stored as a set of 256 bit flags,
1254 * plus a set of 256 bit masks to indicate which bit flags were defined
1255 * at the time the savefile was created. This will allow new options
1256 * to be added, and old options to be removed, at any time, without
1257 * hurting old savefiles.
1259 * The window options are stored in the same way, but note that each
1260 * window gets 32 options, and their order is fixed by certain defines.
1262 static void rd_options(void)
1276 /* Ignore old options */
1280 /*** Special info */
1282 /* Read "delay_factor" */
1286 /* Read "hitpoint_warn" */
1290 /* Read "mana_warn" */
1291 if(h_older_than(1, 7, 0, 0))
1302 /*** Cheating options ***/
1306 if (c & 0x0002) p_ptr->wizard = TRUE;
1308 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1309 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1310 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1311 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1312 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1313 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1314 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1316 rd_byte((byte *)&autosave_l);
1317 rd_byte((byte *)&autosave_t);
1318 rd_s16b(&autosave_freq);
1321 /*** Normal Options ***/
1323 /* Read the option flags */
1324 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1326 /* Read the option masks */
1327 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1329 /* Analyze the options */
1330 for (n = 0; n < 8; n++)
1332 /* Analyze the options */
1333 for (i = 0; i < 32; i++)
1335 /* Process valid flags */
1336 if (mask[n] & (1L << i))
1338 /* Process valid flags */
1339 if (option_mask[n] & (1L << i))
1342 if (flag[n] & (1L << i))
1345 option_flag[n] |= (1L << i);
1352 option_flag[n] &= ~(1L << i);
1359 if (z_older_than(10, 4, 5))
1361 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1362 else option_flag[5] |= (0x00000001 << 4);
1363 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1364 else option_flag[2] |= (0x00000001 << 5);
1365 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1366 else option_flag[4] |= (0x00000001 << 5);
1367 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1368 else option_flag[5] |= (0x00000001 << 0);
1369 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1370 else option_flag[5] |= (0x00000001 << 12);
1371 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1372 else option_flag[1] |= (0x00000001 << 0);
1373 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1374 else option_flag[1] |= (0x00000001 << 18);
1375 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1376 else option_flag[1] |= (0x00000001 << 19);
1377 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1378 else option_flag[5] |= (0x00000001 << 3);
1381 /* Extract the options */
1382 extract_option_vars();
1385 /*** Window Options ***/
1387 /* Read the window flags */
1388 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1390 /* Read the window masks */
1391 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1393 /* Analyze the options */
1394 for (n = 0; n < 8; n++)
1396 /* Analyze the options */
1397 for (i = 0; i < 32; i++)
1399 /* Process valid flags */
1400 if (mask[n] & (1L << i))
1402 /* Process valid flags */
1403 if (window_mask[n] & (1L << i))
1406 if (flag[n] & (1L << i))
1409 window_flag[n] |= (1L << i);
1416 window_flag[n] &= ~(1L << i);
1429 * Hack -- strip the "ghost" info
1431 * XXX XXX XXX This is such a nasty hack it hurts.
1433 static void rd_ghost(void)
1438 rd_string(buf, sizeof(buf));
1440 /* Strip old data */
1446 * Save quick start data
1448 static void load_quick_start(void)
1453 if (z_older_than(11, 0, 13))
1455 previous_char.quick_ok = FALSE;
1459 rd_byte(&previous_char.psex);
1460 rd_byte(&previous_char.prace);
1461 rd_byte(&previous_char.pclass);
1462 rd_byte(&previous_char.pseikaku);
1463 rd_byte(&previous_char.realm1);
1464 rd_byte(&previous_char.realm2);
1466 rd_s16b(&previous_char.age);
1467 rd_s16b(&previous_char.ht);
1468 rd_s16b(&previous_char.wt);
1469 rd_s16b(&previous_char.sc);
1470 rd_s32b(&previous_char.au);
1472 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1473 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1475 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1477 rd_s16b(&previous_char.chaos_patron);
1479 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1481 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1483 /* UNUSED : Was number of random quests */
1487 previous_char.quick_ok = (bool)tmp8u;
1491 * Read the "extra" information
1493 static void rd_extra(void)
1500 rd_string(player_name, sizeof(player_name));
1502 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1504 if (!h_older_than(1, 7, 0, 1))
1508 /* Read the message */
1509 rd_string(buf, sizeof buf);
1510 if (buf[0]) p_ptr->last_message = string_make(buf);
1515 for (i = 0; i < 4; i++)
1517 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1520 /* Class/Race/Seikaku/Gender/Spells */
1521 rd_byte(&p_ptr->prace);
1522 rd_byte(&p_ptr->pclass);
1523 rd_byte(&p_ptr->pseikaku);
1524 rd_byte(&p_ptr->psex);
1525 rd_byte(&p_ptr->realm1);
1526 rd_byte(&p_ptr->realm2);
1527 rd_byte(&tmp8u); /* oops */
1529 if (z_older_than(10, 4, 4))
1531 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1532 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1533 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1534 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1537 /* Special Race/Class info */
1538 rd_byte(&p_ptr->hitdie);
1539 rd_u16b(&p_ptr->expfact);
1541 /* Age/Height/Weight */
1542 rd_s16b(&p_ptr->age);
1543 rd_s16b(&p_ptr->ht);
1544 rd_s16b(&p_ptr->wt);
1546 /* Read the stat info */
1547 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1548 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1549 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1551 strip_bytes(24); /* oops */
1553 rd_s32b(&p_ptr->au);
1555 rd_s32b(&p_ptr->max_exp);
1556 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1557 else rd_s32b(&p_ptr->max_max_exp);
1558 rd_s32b(&p_ptr->exp);
1559 rd_u16b(&p_ptr->exp_frac);
1561 rd_s16b(&p_ptr->lev);
1563 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1564 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1566 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1568 if (z_older_than(10, 3, 6))
1569 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1571 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1572 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1573 if (z_older_than(10, 4, 1))
1575 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1576 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1578 if (z_older_than(10, 3, 14))
1580 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1581 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1585 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1586 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1587 if (h_older_than(1, 3, 0, 1))
1589 if (p_ptr->pclass == CLASS_SMITH)
1591 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1592 p_ptr->magic_num1[96] = 0;
1593 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1594 p_ptr->magic_num1[97] = 0;
1598 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1600 if (z_older_than(11, 0, 7))
1602 p_ptr->start_race = p_ptr->prace;
1603 p_ptr->old_race1 = 0L;
1604 p_ptr->old_race2 = 0L;
1605 p_ptr->old_realm = 0;
1609 rd_byte(&p_ptr->start_race);
1610 rd_s32b(&p_ptr->old_race1);
1611 rd_s32b(&p_ptr->old_race2);
1612 rd_s16b(&p_ptr->old_realm);
1615 if (z_older_than(10, 0, 1))
1617 for (i = 0; i < OLD_MAX_MANE; i++)
1619 p_ptr->mane_spell[i] = -1;
1620 p_ptr->mane_dam[i] = 0;
1622 p_ptr->mane_num = 0;
1624 else if (z_older_than(10, 2, 3))
1626 for (i = 0; i < OLD_MAX_MANE; i++)
1631 for (i = 0; i < MAX_MANE; i++)
1633 p_ptr->mane_spell[i] = -1;
1634 p_ptr->mane_dam[i] = 0;
1637 p_ptr->mane_num = 0;
1641 for (i = 0; i < MAX_MANE; i++)
1643 rd_s16b(&p_ptr->mane_spell[i]);
1644 rd_s16b(&p_ptr->mane_dam[i]);
1646 rd_s16b(&p_ptr->mane_num);
1649 if (z_older_than(10, 0, 3))
1651 determine_bounty_uniques();
1653 for (i = 0; i < MAX_KUBI; i++)
1655 /* Is this bounty unique already dead? */
1656 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1661 for (i = 0; i < MAX_KUBI; i++)
1663 rd_s16b(&kubi_r_idx[i]);
1667 if (z_older_than(10, 0, 3))
1673 for (i = 0; i < 4; i++)
1675 rd_s16b(&battle_mon[i]);
1676 if (z_older_than(10, 3, 4))
1679 mon_odds[i] = tmp16s;
1681 else rd_u32b(&mon_odds[i]);
1685 rd_s16b(&p_ptr->town_num);
1687 /* Read arena and rewards information */
1688 rd_s16b(&p_ptr->arena_number);
1689 if (h_older_than(1, 5, 0, 1))
1691 /* Arena loser of previous version was marked number 99 */
1692 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1695 p_ptr->inside_arena = (bool)tmp16s;
1696 rd_s16b(&p_ptr->inside_quest);
1697 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1701 p_ptr->inside_battle = (bool)tmp16s;
1703 rd_byte(&p_ptr->exit_bldg);
1706 rd_s16b(&p_ptr->oldpx);
1707 rd_s16b(&p_ptr->oldpy);
1708 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1710 /* Was p_ptr->rewards[MAX_BACT] */
1712 for (i = 0; i < tmp16s; i++)
1718 rd_s16b(&p_ptr->mhp);
1719 rd_s16b(&p_ptr->chp);
1720 rd_u16b(&p_ptr->chp_frac);
1722 rd_s16b(&p_ptr->msp);
1723 rd_s16b(&p_ptr->csp);
1724 rd_u16b(&p_ptr->csp_frac);
1726 rd_s16b(&p_ptr->max_plv);
1727 if (z_older_than(10, 3, 8))
1729 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1733 byte max = (byte)max_d_idx;
1737 for(i = 0; i < max; i++)
1739 rd_s16b(&max_dlv[i]);
1740 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1744 /* Repair maximum player level XXX XXX XXX */
1745 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1749 rd_s16b(&p_ptr->sc);
1752 /* Read the flags */
1753 strip_bytes(2); /* Old "rest" */
1754 rd_s16b(&p_ptr->blind);
1755 rd_s16b(&p_ptr->paralyzed);
1756 rd_s16b(&p_ptr->confused);
1757 rd_s16b(&p_ptr->food);
1758 strip_bytes(4); /* Old "food_digested" / "protection" */
1760 rd_s16b(&p_ptr->energy_need);
1761 if (z_older_than(11, 0, 13))
1762 p_ptr->energy_need = 100 - p_ptr->energy_need;
1764 rd_s16b(&p_ptr->fast);
1765 rd_s16b(&p_ptr->slow);
1766 rd_s16b(&p_ptr->afraid);
1767 rd_s16b(&p_ptr->cut);
1768 rd_s16b(&p_ptr->stun);
1769 rd_s16b(&p_ptr->poisoned);
1770 rd_s16b(&p_ptr->image);
1771 rd_s16b(&p_ptr->protevil);
1772 rd_s16b(&p_ptr->invuln);
1773 if(z_older_than(10, 0, 0))
1776 rd_s16b(&p_ptr->ult_res);
1777 rd_s16b(&p_ptr->hero);
1778 rd_s16b(&p_ptr->shero);
1779 rd_s16b(&p_ptr->shield);
1780 rd_s16b(&p_ptr->blessed);
1781 rd_s16b(&p_ptr->tim_invis);
1782 rd_s16b(&p_ptr->word_recall);
1783 if (z_older_than(10, 3, 8))
1784 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1788 p_ptr->recall_dungeon = (byte)tmp16s;
1791 if (h_older_than(1, 5, 0, 0))
1792 p_ptr->alter_reality = 0;
1794 rd_s16b(&p_ptr->alter_reality);
1796 rd_s16b(&p_ptr->see_infra);
1797 rd_s16b(&p_ptr->tim_infra);
1798 rd_s16b(&p_ptr->oppose_fire);
1799 rd_s16b(&p_ptr->oppose_cold);
1800 rd_s16b(&p_ptr->oppose_acid);
1801 rd_s16b(&p_ptr->oppose_elec);
1802 rd_s16b(&p_ptr->oppose_pois);
1803 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1804 else rd_s16b(&p_ptr->tsuyoshi);
1806 /* Old savefiles do not have the following fields... */
1807 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1810 p_ptr->wraith_form = 0;
1811 p_ptr->resist_magic = 0;
1812 p_ptr->tim_regen = 0;
1813 p_ptr->kabenuke = 0;
1814 p_ptr->tim_stealth = 0;
1815 p_ptr->tim_ffall = 0;
1816 p_ptr->tim_sh_touki = 0;
1817 p_ptr->lightspeed = 0;
1818 p_ptr->tsubureru = 0;
1819 p_ptr->tim_res_nether = 0;
1820 p_ptr->tim_res_time = 0;
1821 p_ptr->mimic_form = 0;
1822 p_ptr->tim_mimic = 0;
1823 p_ptr->tim_sh_fire = 0;
1826 p_ptr->tim_reflect = 0;
1827 p_ptr->multishadow = 0;
1828 p_ptr->dustrobe = 0;
1830 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
1838 rd_s16b(&p_ptr->tim_esp);
1839 rd_s16b(&p_ptr->wraith_form);
1840 rd_s16b(&p_ptr->resist_magic);
1841 rd_s16b(&p_ptr->tim_regen);
1842 rd_s16b(&p_ptr->kabenuke);
1843 rd_s16b(&p_ptr->tim_stealth);
1844 rd_s16b(&p_ptr->tim_ffall);
1845 rd_s16b(&p_ptr->tim_sh_touki);
1846 rd_s16b(&p_ptr->lightspeed);
1847 rd_s16b(&p_ptr->tsubureru);
1848 if (z_older_than(10, 4, 7))
1849 p_ptr->magicdef = 0;
1851 rd_s16b(&p_ptr->magicdef);
1852 rd_s16b(&p_ptr->tim_res_nether);
1853 if (z_older_than(10, 4, 11))
1855 p_ptr->tim_res_time = 0;
1856 p_ptr->mimic_form = 0;
1857 p_ptr->tim_mimic = 0;
1858 p_ptr->tim_sh_fire = 0;
1862 rd_s16b(&p_ptr->tim_res_time);
1863 rd_byte(&p_ptr->mimic_form);
1864 rd_s16b(&p_ptr->tim_mimic);
1865 rd_s16b(&p_ptr->tim_sh_fire);
1868 if (z_older_than(11, 0, 99))
1870 p_ptr->tim_sh_holy = 0;
1871 p_ptr->tim_eyeeye = 0;
1875 rd_s16b(&p_ptr->tim_sh_holy);
1876 rd_s16b(&p_ptr->tim_eyeeye);
1880 if ( z_older_than(11,0,3) ){
1881 p_ptr->tim_reflect=0;
1882 p_ptr->multishadow=0;
1886 rd_s16b(&p_ptr->tim_reflect);
1887 rd_s16b(&p_ptr->multishadow);
1888 rd_s16b(&p_ptr->dustrobe);
1891 rd_s16b(&p_ptr->chaos_patron);
1892 rd_u32b(&p_ptr->muta1);
1893 rd_u32b(&p_ptr->muta2);
1894 rd_u32b(&p_ptr->muta3);
1896 for (i = 0; i < 8; i++)
1897 rd_s16b(&p_ptr->virtues[i]);
1898 for (i = 0; i < 8; i++)
1899 rd_s16b(&p_ptr->vir_types[i]);
1902 /* Calc the regeneration modifier for mutations */
1903 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1905 if (z_older_than(10,0,9))
1908 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1909 p_ptr->ele_attack = 0;
1913 rd_s16b(&p_ptr->ele_attack);
1914 rd_u32b(&p_ptr->special_attack);
1916 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1917 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1918 if (z_older_than(10,0,12))
1920 p_ptr->ele_immune = 0;
1921 p_ptr->special_defense = 0;
1925 rd_s16b(&p_ptr->ele_immune);
1926 rd_u32b(&p_ptr->special_defense);
1928 rd_byte(&p_ptr->knowledge);
1931 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
1933 rd_byte(&tmp8u); /* oops */
1934 rd_byte(&p_ptr->action);
1935 if (!z_older_than(10, 4, 3))
1938 if (tmp8u) p_ptr->action = ACTION_LEARN;
1940 rd_byte((byte *)&preserve_mode);
1941 rd_byte((byte *)&p_ptr->wait_report_score);
1944 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1946 /* Skip the flags */
1950 /* Hack -- the two "special seeds" */
1951 rd_u32b(&seed_flavor);
1952 rd_u32b(&seed_town);
1956 rd_u16b(&p_ptr->panic_save);
1957 rd_u16b(&p_ptr->total_winner);
1958 rd_u16b(&p_ptr->noscore);
1963 p_ptr->is_dead = tmp8u;
1965 /* Read "feeling" */
1969 /* Turn of last "feeling" */
1975 if (z_older_than(10, 3, 12))
1977 dungeon_turn = turn;
1979 else rd_s32b(&dungeon_turn);
1981 if (z_older_than(11, 0, 13))
1988 if (z_older_than(10, 3, 13))
1992 else rd_s32b(&old_battle);
1994 if (z_older_than(10,0,3))
1996 determine_today_mon(TRUE);
2000 rd_s16b(&today_mon);
2001 rd_s16b(&p_ptr->today_mon);
2004 if (z_older_than(10,0,7))
2010 rd_s16b(&p_ptr->riding);
2013 /* Current floor_id */
2014 if (h_older_than(1, 5, 0, 0))
2016 p_ptr->floor_id = 0;
2020 rd_s16b(&p_ptr->floor_id);
2023 if (h_older_than(1, 5, 0, 2))
2029 /* Get number of party_mon array */
2032 /* Strip old temporary preserved pets */
2033 for (i = 0; i < tmp16s; i++)
2035 monster_type dummy_mon;
2037 rd_monster(&dummy_mon);
2041 if (z_older_than(10,1,2))
2050 if (z_older_than(10,3,9))
2054 else if (z_older_than(10, 3, 10))
2062 rd_s32b(&p_ptr->visit);
2064 if (!z_older_than(11, 0, 5))
2066 rd_u32b(&p_ptr->count);
2074 * Read the player inventory
2076 * Note that the inventory changed in Angband 2.7.4. Two extra
2077 * pack slots were added and the equipment was rearranged. Note
2078 * that these two features combine when parsing old save-files, in
2079 * which items from the old "aux" slot are "carried", perhaps into
2080 * one of the two new "inventory" slots.
2082 * Note that the inventory is "re-sorted" later by "dungeon()".
2084 static errr rd_inventory(void)
2092 p_ptr->total_weight = 0;
2098 /* Read until done */
2103 /* Get the next item index */
2106 /* Nope, we reached the end */
2107 if (n == 0xFFFF) break;
2109 /* Get local object */
2112 /* Wipe the object */
2118 /* Hack -- verify item */
2119 if (!q_ptr->k_idx) return (53);
2121 /* Wield equipment */
2122 if (n >= INVEN_RARM)
2125 object_copy(&inventory[n], q_ptr);
2127 /* Add the weight */
2128 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2134 /* Warning -- backpack is full */
2135 else if (inven_cnt == INVEN_PACK)
2139 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
2141 note("Too many items in the inventory!");
2149 /* Carry inventory */
2156 object_copy(&inventory[n], q_ptr);
2158 /* Add the weight */
2159 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2173 * Read the saved messages
2175 static void rd_messages(void)
2185 /* Read the messages */
2186 for (i = 0; i < num; i++)
2188 /* Read the message */
2189 rd_string(buf, sizeof(buf));
2191 /* Save the message */
2198 /* Old hidden trap flag */
2199 #define CAVE_TRAP 0x8000
2202 * Read the dungeon (old method)
2204 * The monsters/objects must be loaded in the same order
2205 * that they were stored, since the actual indexes matter.
2207 static errr rd_dungeon_old(void)
2218 /*** Basic info ***/
2221 rd_s16b(&dun_level);
2222 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2223 else rd_byte(&dungeon_type);
2225 /* Set the base level for old versions */
2226 base_level = dun_level;
2228 rd_s16b(&base_level);
2230 rd_s16b(&num_repro);
2235 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2238 rd_s16b(&tmp16s); /* max_panel_rows */
2239 rd_s16b(&tmp16s); /* max_panel_cols */
2242 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
2250 /*** Run length decoding ***/
2252 /* Load the dungeon data */
2253 for (x = y = 0; y < ymax; )
2259 if (z_older_than(10,3,6))
2268 /* Decline invalid flags */
2269 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2272 /* Apply the RLE info */
2273 for (i = count; i > 0; i--)
2275 /* Access the cave */
2276 c_ptr = &cave[y][x];
2278 /* Extract "info" */
2288 if (++y >= ymax) break;
2294 /*** Run length decoding ***/
2296 /* Load the dungeon data */
2297 for (x = y = 0; y < ymax; )
2303 /* Apply the RLE info */
2304 for (i = count; i > 0; i--)
2306 /* Access the cave */
2307 c_ptr = &cave[y][x];
2309 /* Extract "feat" */
2310 c_ptr->feat = (s16b)tmp8u;
2319 if (++y >= ymax) break;
2324 /*** Run length decoding ***/
2326 /* Load the dungeon data */
2327 for (x = y = 0; y < ymax; )
2333 /* Apply the RLE info */
2334 for (i = count; i > 0; i--)
2336 /* Access the cave */
2337 c_ptr = &cave[y][x];
2339 /* Extract "mimic" */
2340 c_ptr->mimic = (s16b)tmp8u;
2349 if (++y >= ymax) break;
2354 /*** Run length decoding ***/
2356 /* Load the dungeon data */
2357 for (x = y = 0; y < ymax; )
2363 /* Apply the RLE info */
2364 for (i = count; i > 0; i--)
2366 /* Access the cave */
2367 c_ptr = &cave[y][x];
2369 /* Extract "feat" */
2370 c_ptr->special = tmp16s;
2379 if (++y >= ymax) break;
2384 /* Convert cave data */
2385 if (z_older_than(11, 0, 99))
2387 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2389 /* Wipe old unused flags */
2390 cave[y][x].info &= ~(CAVE_MASK);
2394 if (h_older_than(1, 1, 1, 0))
2396 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2398 /* Access the cave */
2399 c_ptr = &cave[y][x];
2402 if (c_ptr->feat == FEAT_INVIS)
2404 c_ptr->feat = FEAT_FLOOR;
2405 c_ptr->info |= CAVE_TRAP;
2408 /* Older than 1.1.1 */
2409 if (c_ptr->feat == FEAT_MIRROR)
2411 c_ptr->feat = FEAT_FLOOR;
2412 c_ptr->info |= CAVE_OBJECT;
2417 if (h_older_than(1, 3, 1, 0))
2419 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2421 /* Access the cave */
2422 c_ptr = &cave[y][x];
2424 /* Old CAVE_IN_MIRROR flag */
2425 if (c_ptr->info & CAVE_OBJECT)
2427 c_ptr->mimic = FEAT_MIRROR;
2430 /* Runes will be mimics and flags */
2431 else if (c_ptr->feat == FEAT_MINOR_GLYPH ||
2432 c_ptr->feat == FEAT_GLYPH)
2434 c_ptr->info |= CAVE_OBJECT;
2435 c_ptr->mimic = c_ptr->feat;
2436 c_ptr->feat = FEAT_FLOOR;
2439 /* Hidden traps will be trap terrains mimicing floor */
2440 else if (c_ptr->info & CAVE_TRAP)
2442 c_ptr->info &= ~CAVE_TRAP;
2443 c_ptr->mimic = c_ptr->feat;
2444 c_ptr->feat = choose_random_trap();
2447 /* Another hidden trap */
2448 else if (c_ptr->feat == FEAT_INVIS)
2450 c_ptr->mimic = FEAT_FLOOR;
2451 c_ptr->feat = FEAT_TRAP_OPEN;
2454 /* Hidden doors will be closed doors mimicing wall */
2455 else if (c_ptr->feat == FEAT_SECRET)
2457 place_closed_door(y, x);
2458 c_ptr->mimic = FEAT_WALL;
2465 /* Read the item count */
2468 /* Verify maximum */
2469 if (limit > max_o_idx)
2472 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2474 note(format("Too many (%d) object entries!", limit));
2480 /* Read the dungeon items */
2481 for (i = 1; i < limit; i++)
2488 /* Get a new record */
2495 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2497 note(format("Object allocation error (%d <> %d)", i, o_idx));
2505 o_ptr = &o_list[o_idx];
2511 /* XXX XXX XXX XXX XXX */
2514 if (o_ptr->held_m_idx)
2516 monster_type *m_ptr;
2519 m_ptr = &m_list[o_ptr->held_m_idx];
2522 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2524 /* Place the object */
2525 m_ptr->hold_o_idx = o_idx;
2531 /* Access the item location */
2532 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2535 o_ptr->next_o_idx = c_ptr->o_idx;
2537 /* Place the object */
2538 c_ptr->o_idx = o_idx;
2545 /* Read the monster count */
2548 /* Hack -- verify */
2549 if (limit > max_m_idx)
2552 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2554 note(format("Too many (%d) monster entries!", limit));
2560 /* Read the monsters */
2561 for (i = 1; i < limit; i++)
2564 monster_type *m_ptr;
2566 /* Get a new record */
2573 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2575 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2582 /* Acquire monster */
2583 m_ptr = &m_list[m_idx];
2585 /* Read the monster */
2590 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2592 /* Mark the location */
2593 c_ptr->m_idx = m_idx;
2596 real_r_ptr(m_ptr)->cur_num++;
2601 /* The dungeon is ready */
2602 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2603 character_dungeon = FALSE;
2605 character_dungeon = TRUE;
2614 * Read the saved floor
2616 * The monsters/objects must be loaded in the same order
2617 * that they were stored, since the actual indexes matter.
2619 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2631 cave_template_type *template;
2634 /*** Wipe all cave ***/
2638 /*** Basic info ***/
2640 /* Dungeon floor specific info follows */
2644 /*** Not a saved floor ***/
2646 rd_s16b(&dun_level);
2647 base_level = dun_level;
2651 /*** The saved floor ***/
2654 if (tmp16s != sf_ptr->floor_id) return 171;
2657 if (tmp8u != sf_ptr->savefile_id) return 171;
2660 if (tmp16s != sf_ptr->dun_level) return 171;
2661 dun_level = sf_ptr->dun_level;
2664 if (tmp32s != sf_ptr->last_visit) return 171;
2667 if (tmp32u != sf_ptr->visit_mark) return 171;
2670 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2673 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2676 rd_s16b(&base_level);
2677 rd_s16b(&num_repro);
2692 /*** Read template for cave_type ***/
2694 /* Read the template count */
2697 /* Allocate the "template" array */
2698 C_MAKE(template, limit, cave_template_type);
2700 /* Read the templates */
2701 for (i = 0; i < limit; i++)
2703 cave_template_type *ct_ptr = &template[i];
2706 rd_u16b(&ct_ptr->info);
2707 if (h_older_than(1, 7, 0, 2))
2710 ct_ptr->feat = (s16b)tmp8u;
2712 ct_ptr->mimic = (s16b)tmp8u;
2716 rd_s16b(&ct_ptr->feat);
2717 rd_s16b(&ct_ptr->mimic);
2719 rd_s16b(&ct_ptr->special);
2727 /*** Run length decoding ***/
2729 /* Load the dungeon data */
2730 for (x = y = 0; y < ymax; )
2742 } while (tmp8u == MAX_UCHAR);
2744 /* Apply the RLE info */
2745 for (i = count; i > 0; i--)
2747 /* Access the cave */
2748 cave_type *c_ptr = &cave[y][x];
2750 /* Extract cave data */
2751 c_ptr->info = template[id].info;
2752 c_ptr->feat = template[id].feat;
2753 c_ptr->mimic = template[id].mimic;
2754 c_ptr->special = template[id].special;
2763 if (++y >= ymax) break;
2768 /* Free the "template" array */
2769 C_FREE(template, limit, cave_template_type);
2774 /* Read the item count */
2777 /* Verify maximum */
2778 if (limit > max_o_idx) return 151;
2781 /* Read the dungeon items */
2782 for (i = 1; i < limit; i++)
2788 /* Get a new record */
2792 if (i != o_idx) return 152;
2795 o_ptr = &o_list[o_idx];
2802 if (o_ptr->held_m_idx)
2804 monster_type *m_ptr;
2807 m_ptr = &m_list[o_ptr->held_m_idx];
2810 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2812 /* Place the object */
2813 m_ptr->hold_o_idx = o_idx;
2819 /* Access the item location */
2820 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2823 o_ptr->next_o_idx = c_ptr->o_idx;
2825 /* Place the object */
2826 c_ptr->o_idx = o_idx;
2833 /* Read the monster count */
2836 /* Hack -- verify */
2837 if (limit > max_m_idx) return 161;
2839 /* Read the monsters */
2840 for (i = 1; i < limit; i++)
2844 monster_type *m_ptr;
2846 /* Get a new record */
2850 if (i != m_idx) return 162;
2853 /* Acquire monster */
2854 m_ptr = &m_list[m_idx];
2856 /* Read the monster */
2861 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2863 /* Mark the location */
2864 c_ptr->m_idx = m_idx;
2867 real_r_ptr(m_ptr)->cur_num++;
2876 * Read the dungeon (new method)
2878 * The monsters/objects must be loaded in the same order
2879 * that they were stored, since the actual indexes matter.
2881 static errr rd_dungeon(void)
2887 /* Initialize saved_floors array and temporal files */
2888 init_saved_floors(FALSE);
2891 if (h_older_than(1, 5, 0, 0))
2893 err = rd_dungeon_old();
2895 /* Prepare floor_id of current floor */
2898 p_ptr->floor_id = get_new_floor_id();
2899 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
2908 /* Number of floor_id used from birth */
2909 rd_s16b(&max_floor_id);
2911 /* Current dungeon type */
2912 rd_byte(&dungeon_type);
2915 /* Number of the saved_floors array elements */
2918 /*** No saved floor (On the surface etc.) ***/
2921 /* Read the current floor data */
2922 err = rd_saved_floor(NULL);
2925 /*** In the dungeon ***/
2929 /* Read the saved_floors array */
2930 for (i = 0; i < num; i++)
2932 saved_floor_type *sf_ptr = &saved_floors[i];
2934 rd_s16b(&sf_ptr->floor_id);
2935 rd_byte(&sf_ptr->savefile_id);
2936 rd_s16b(&sf_ptr->dun_level);
2937 rd_s32b(&sf_ptr->last_visit);
2938 rd_u32b(&sf_ptr->visit_mark);
2939 rd_s16b(&sf_ptr->upper_floor_id);
2940 rd_s16b(&sf_ptr->lower_floor_id);
2944 /* Move saved floors data to temporal files */
2945 for (i = 0; i < num; i++)
2947 saved_floor_type *sf_ptr = &saved_floors[i];
2950 /* Unused element */
2951 if (!sf_ptr->floor_id) continue;
2953 /* Read the failure mark */
2955 if (tmp8u) continue;
2957 /* Read from the save file */
2958 err = rd_saved_floor(sf_ptr);
2963 /* Re-save as temporal saved floor file */
2964 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
2970 /* Finally load current floor data from temporal file */
2973 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
2978 /*** Error messages ***/
2983 note("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
2985 note("Too many object entries!");
2991 note("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼");
2993 note("Object allocation error");
2999 note("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
3001 note("Too many monster entries!");
3007 note("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼");
3009 note("Monster allocation error");
3015 note("Êݸ¤µ¤ì¤¿¥Õ¥í¥¢¤Î¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡ª");
3017 note("Dungeon data of saved floors are broken!");
3023 note("¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
3025 note("Failed to make temporal files!");
3038 /* The dungeon is ready */
3039 character_dungeon = TRUE;
3041 /* Success or Error */
3047 * Actually read the savefile
3049 static errr rd_savefile_new_aux(void)
3061 #ifdef VERIFY_CHECKSUMS
3062 u32b n_x_check, n_v_check;
3063 u32b o_x_check, o_v_check;
3067 /* Mention the savefile version */
3070 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
3072 "Loading a %d.%d.%d savefile...",
3074 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
3077 /* Strip the version bytes */
3080 /* Hack -- decrypt */
3081 xor_byte = sf_extra;
3084 /* Clear the checksums */
3088 /* Read the version number of the savefile */
3089 /* Old savefile will be version 0.0.0.3 */
3090 rd_byte(&h_ver_extra);
3091 rd_byte(&h_ver_patch);
3092 rd_byte(&h_ver_minor);
3093 rd_byte(&h_ver_major);
3095 /* Operating system info */
3096 rd_u32b(&sf_system);
3098 /* Time of savefile creation */
3101 /* Number of resurrections */
3104 /* Number of times played */
3108 /* Later use (always zero) */
3111 /* Later use (always zero) */
3114 /* Later use (always zero) */
3118 rd_byte(&kanji_code);
3120 /* Read RNG state */
3123 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3125 if (arg_fiddle) note("Loaded Randomizer Info");
3130 /* Then the options */
3133 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3135 if (arg_fiddle) note("Loaded Option Flags");
3138 /* Then the "messages" */
3141 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3143 if (arg_fiddle) note("Loaded Messages");
3148 for (i = 0; i < max_r_idx; i++)
3150 /* Access that monster */
3151 monster_race *r_ptr = &r_info[i];
3153 /* Hack -- Reset the death counter */
3154 r_ptr->max_num = 100;
3156 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3158 /* Hack -- Non-unique Nazguls are semi-unique */
3159 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3162 /* Monster Memory */
3165 /* Incompatible save files */
3166 if (tmp16u > max_r_idx)
3169 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3171 note(format("Too many (%u) monster races!", tmp16u));
3177 /* Read the available records */
3178 for (i = 0; i < tmp16u; i++)
3185 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3187 if (arg_fiddle) note("Loaded Monster Memory");
3195 /* Incompatible save files */
3196 if (tmp16u > max_k_idx)
3199 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3201 note(format("Too many (%u) object kinds!", tmp16u));
3207 /* Read the object memory */
3208 for (i = 0; i < tmp16u; i++)
3211 object_kind *k_ptr = &k_info[i];
3215 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3216 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3219 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3221 if (arg_fiddle) note("Loaded Object Memory");
3225 /* Init the wilderness seeds */
3226 for (i = 0; i < max_wild_x; i++)
3228 for (j = 0; j < max_wild_y; j++)
3230 wilderness[j][i].seed = randint0(0x10000000);
3234 /* 2.1.3 or newer version */
3236 u16b max_towns_load;
3237 u16b max_quests_load;
3238 byte max_rquests_load;
3239 s16b old_inside_quest = p_ptr->inside_quest;
3241 /* Number of towns */
3242 rd_u16b(&max_towns_load);
3244 /* Incompatible save files */
3245 if (max_towns_load > max_towns)
3248 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
3250 note(format("Too many (%u) towns!", max_towns_load));
3256 /* Number of quests */
3257 rd_u16b(&max_quests_load);
3259 if (z_older_than(11, 0, 7))
3261 max_rquests_load = 10;
3265 rd_byte(&max_rquests_load);
3268 /* Incompatible save files */
3269 if (max_quests_load > max_quests)
3272 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
3274 note(format("Too many (%u) quests!", max_quests_load));
3280 for (i = 0; i < max_quests_load; i++)
3284 rd_s16b(&quest[i].status);
3285 rd_s16b(&quest[i].level);
3287 if (z_older_than(11, 0, 6))
3289 quest[i].complev = 0;
3293 rd_byte(&quest[i].complev);
3296 /* Load quest status if quest is running */
3297 if (quest[i].status == QUEST_STATUS_TAKEN || (!z_older_than(10, 3, 14) && (quest[i].status == QUEST_STATUS_COMPLETED)) || (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST+max_rquests_load))))
3299 rd_s16b(&quest[i].cur_num);
3300 rd_s16b(&quest[i].max_num);
3301 rd_s16b(&quest[i].type);
3303 /* Load quest monster index */
3304 rd_s16b(&quest[i].r_idx);
3306 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
3308 determine_random_questor(&quest[i]);
3311 /* Load quest item index */
3312 rd_s16b(&quest[i].k_idx);
3315 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
3317 rd_byte(&quest[i].flags);
3319 if (z_older_than(10, 3, 11))
3321 if (quest[i].flags & QUEST_FLAG_PRESET)
3323 quest[i].dungeon = 0;
3327 init_flags = INIT_ASSIGN;
3328 p_ptr->inside_quest = i;
3330 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3331 p_ptr->inside_quest = old_inside_quest;
3336 rd_byte(&quest[i].dungeon);
3339 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
3340 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
3341 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
3344 /* Ignore the empty quests from old versions */
3347 /* Ignore quest status */
3350 /* Ignore quest level */
3354 * We don't have to care about the other info,
3355 * since status should be 0 for these quests anyway
3360 /* Position in the wilderness */
3361 rd_s32b(&p_ptr->wilderness_x);
3362 rd_s32b(&p_ptr->wilderness_y);
3363 if (z_older_than(10, 3, 13))
3365 p_ptr->wilderness_x = 5;
3366 p_ptr->wilderness_y = 48;
3369 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3370 else rd_byte((byte *)&p_ptr->wild_mode);
3371 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3372 else rd_byte((byte *)&ambush_flag);
3374 /* Size of the wilderness */
3375 rd_s32b(&wild_x_size);
3376 rd_s32b(&wild_y_size);
3378 /* Incompatible save files */
3379 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3382 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
3384 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
3390 /* Load the wilderness seeds */
3391 for (i = 0; i < wild_x_size; i++)
3393 for (j = 0; j < wild_y_size; j++)
3395 rd_u32b(&wilderness[j][i].seed);
3401 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3403 if (arg_fiddle) note("Loaded Quests");
3406 /* Load the Artifacts */
3409 /* Incompatible save files */
3410 if (tmp16u > max_a_idx)
3413 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3415 note(format("Too many (%u) artifacts!", tmp16u));
3421 /* Read the artifact flags */
3422 for (i = 0; i < tmp16u; i++)
3424 artifact_type *a_ptr = &a_info[i];
3427 a_ptr->cur_num = tmp8u;
3429 if (h_older_than(1, 5, 0, 0))
3431 a_ptr->floor_id = 0;
3439 rd_s16b(&a_ptr->floor_id);
3443 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3445 if (arg_fiddle) note("Loaded Artifacts");
3450 /* Read the extra stuff */
3452 if (p_ptr->energy_need < -999) world_player = TRUE;
3455 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3457 if (arg_fiddle) note("Loaded extra information");
3461 /* Read the player_hp array */
3464 /* Incompatible save files */
3465 if (tmp16u > PY_MAX_LEVEL)
3468 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
3470 note(format("Too many (%u) hitpoint entries!", tmp16u));
3476 /* Read the player_hp array */
3477 for (i = 0; i < tmp16u; i++)
3479 rd_s16b(&p_ptr->player_hp[i]);
3482 /* Important -- Initialize the sex */
3483 sp_ptr = &sex_info[p_ptr->psex];
3485 /* Important -- Initialize the race/class */
3486 rp_ptr = &race_info[p_ptr->prace];
3487 cp_ptr = &class_info[p_ptr->pclass];
3488 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3490 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3492 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3493 do_cmd_rerate(FALSE);
3495 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3497 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3498 do_cmd_rerate(FALSE);
3500 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3502 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3503 do_cmd_rerate(FALSE);
3505 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3507 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3508 do_cmd_rerate(FALSE);
3511 /* Important -- Initialize the magic */
3512 mp_ptr = &m_info[p_ptr->pclass];
3515 /* Read spell info */
3516 rd_u32b(&p_ptr->spell_learned1);
3517 rd_u32b(&p_ptr->spell_learned2);
3518 rd_u32b(&p_ptr->spell_worked1);
3519 rd_u32b(&p_ptr->spell_worked2);
3520 rd_u32b(&p_ptr->spell_forgotten1);
3521 rd_u32b(&p_ptr->spell_forgotten2);
3523 if (z_older_than(10,0,5))
3525 p_ptr->learned_spells = 0;
3526 for (i = 0; i < 64; i++)
3528 /* Count known spells */
3530 (p_ptr->spell_learned1 & (1L << i)) :
3531 (p_ptr->spell_learned2 & (1L << (i - 32))))
3533 p_ptr->learned_spells++;
3537 else rd_s16b(&p_ptr->learned_spells);
3539 if (z_older_than(10,0,6))
3541 p_ptr->add_spells = 0;
3543 else rd_s16b(&p_ptr->add_spells);
3544 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3546 for (i = 0; i < 64; i++)
3548 rd_byte(&p_ptr->spell_order[i]);
3552 /* Read the inventory */
3556 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
3558 note("Unable to read inventory");
3564 /* Read number of towns */
3566 town_count = tmp16u;
3568 /* Read the stores */
3570 for (i = 1; i < town_count; i++)
3572 for (j = 0; j < tmp16u; j++)
3574 if (rd_store(i, j)) return (22);
3578 rd_s16b(&p_ptr->pet_follow_distance);
3579 if (z_older_than(10, 4, 10))
3581 p_ptr->pet_extra_flags = 0;
3583 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3585 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3587 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3591 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3594 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3598 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3601 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3605 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3608 if (!z_older_than(10,0,8))
3611 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3616 rd_s16b(&p_ptr->pet_extra_flags);
3619 if (!z_older_than(11, 0, 9))
3621 char buf[SCREEN_BUF_SIZE];
3622 rd_string(buf, sizeof(buf));
3623 if (buf[0]) screen_dump = string_make(buf);
3628 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3630 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3635 /* I'm not dead yet... */
3636 if (!p_ptr->is_dead)
3638 /* Dead players have no dungeon */
3640 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
3642 note("Restoring Dungeon...");
3648 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
3650 note("Error reading dungeon data");
3656 /* Read the ghost info */
3663 strip_bytes(tmp32s);
3668 #ifdef VERIFY_CHECKSUMS
3670 /* Save the checksum */
3671 n_v_check = v_check;
3673 /* Read the old checksum */
3674 rd_u32b(&o_v_check);
3677 if (o_v_check != n_v_check)
3680 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3682 note("Invalid checksum");
3689 /* Save the encoded checksum */
3690 n_x_check = x_check;
3692 /* Read the checksum */
3693 rd_u32b(&o_x_check);
3697 if (o_x_check != n_x_check)
3700 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3702 note("Invalid encoded checksum");
3716 * Actually read the savefile
3718 errr rd_savefile_new(void)
3722 /* Grab permissions */
3725 /* The savefile is a binary file */
3726 fff = my_fopen(savefile, "rb");
3728 /* Drop permissions */
3732 if (!fff) return (-1);
3734 /* Call the sub-function */
3735 err = rd_savefile_new_aux();
3737 /* Check for errors */
3738 if (ferror(fff)) err = -1;
3740 /* Close the file */
3749 * Actually load and verify a floor save data
3751 static bool load_floor_aux(saved_floor_type *sf_ptr)
3756 #ifdef VERIFY_CHECKSUMS
3757 u32b n_x_check, n_v_check;
3758 u32b o_x_check, o_v_check;
3761 /* Hack -- decrypt (read xor_byte) */
3765 /* Clear the checksums */
3769 /* Set the version number to current version */
3770 /* Never load old temporal files */
3771 h_ver_extra = H_VER_EXTRA;
3772 h_ver_patch = H_VER_PATCH;
3773 h_ver_minor = H_VER_MINOR;
3774 h_ver_major = H_VER_MAJOR;
3776 /* Verify the sign */
3778 if (saved_floor_file_sign != tmp32u) return FALSE;
3780 /* Read -- have error? */
3781 if (rd_saved_floor(sf_ptr)) return FALSE;
3784 #ifdef VERIFY_CHECKSUMS
3785 /* Save the checksum */
3786 n_v_check = v_check;
3788 /* Read the old checksum */
3789 rd_u32b(&o_v_check);
3792 if (o_v_check != n_v_check) return FALSE;
3794 /* Save the encoded checksum */
3795 n_x_check = x_check;
3797 /* Read the checksum */
3798 rd_u32b(&o_x_check);
3801 if (o_x_check != n_x_check) return FALSE;
3810 * Attempt to load the temporally saved-floor data
3812 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
3814 FILE *old_fff = NULL;
3815 byte old_xor_byte = 0;
3816 u32b old_v_check = 0;
3817 u32b old_x_check = 0;
3818 byte old_h_ver_major = 0;
3819 byte old_h_ver_minor = 0;
3820 byte old_h_ver_patch = 0;
3821 byte old_h_ver_extra = 0;
3824 char floor_savefile[1024];
3826 byte old_kanji_code = kanji_code;
3829 * Temporal files are always written in system depended kanji
3834 /* EUC kanji code */
3838 /* SJIS kanji code */
3847 /* We have one file already opened */
3848 if (mode & SLF_SECOND)
3850 /* Backup original values */
3852 old_xor_byte = xor_byte;
3853 old_v_check = v_check;
3854 old_x_check = x_check;
3855 old_h_ver_major = h_ver_major;
3856 old_h_ver_minor = h_ver_minor;
3857 old_h_ver_patch = h_ver_patch;
3858 old_h_ver_extra = h_ver_extra;
3861 /* floor savefile */
3862 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3864 /* Grab permissions */
3867 /* The savefile is a binary file */
3868 fff = my_fopen(floor_savefile, "rb");
3870 /* Drop permissions */
3874 if (!fff) ok = FALSE;
3876 /* Attempt to load */
3879 /* Load saved floor data from file */
3880 ok = load_floor_aux(sf_ptr);
3882 /* Check for errors */
3883 if (ferror(fff)) ok = FALSE;
3885 /* Close the file */
3888 /* Grab permissions */
3891 /* Delete the file */
3892 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3894 /* Drop permissions */
3898 /* We have one file already opened */
3899 if (mode & SLF_SECOND)
3901 /* Restore original values */
3903 xor_byte = old_xor_byte;
3904 v_check = old_v_check;
3905 x_check = old_x_check;
3906 h_ver_major = old_h_ver_major;
3907 h_ver_minor = old_h_ver_minor;
3908 h_ver_patch = old_h_ver_patch;
3909 h_ver_extra = old_h_ver_extra;
3912 /* Restore old knowledge */
3913 kanji_code = old_kanji_code;