3 * @brief セーブファイル読み込み処理 / Purpose: support for loading savefiles -BEN-
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
12 * This file loads savefiles from Angband 2.7.X and 2.8.X
14 * Ancient savefiles (pre-2.7.0) are loaded by another file.
16 * Note that Angband 2.7.0 through 2.7.3 are now officially obsolete,
17 * and savefiles from those versions may not be successfully converted.
19 * We attempt to prevent corrupt savefiles from inducing memory errors.
21 * Note that this file should not use the random number generator, the
22 * object flavors, the visual attr/char mappings, or anything else which
23 * is initialized *after* or *during* the "load character" function.
25 * This file assumes that the monster/object records are initialized
26 * to zero, and the race/kind tables have been loaded correctly. The
27 * order of object stacks is currently not saved in the savefiles, but
28 * the "next" pointers are saved, so all necessary knowledge is present.
30 * We should implement simple "savefile extenders" using some form of
31 * "sized" chunks of bytes, with a {size,type,data} format, so everyone
32 * can know the size, interested people can know the type, and the actual
33 * data is available to the parsing routines that acknowledge the type.
35 * Consider changing the "globe of invulnerability" code so that it
36 * takes some form of "maximum damage to protect from" in addition to
37 * the existing "number of turns to protect for", and where each hit
38 * by a monster will reduce the shield by that amount.
47 * Maximum number of tries for selection of a proper quest monster
53 * Local "savefile" pointer
58 * Hack -- old "encryption" byte
63 * Hack -- simple "checksum" on the actual values
65 static u32b v_check = 0L;
68 * Hack -- simple "checksum" on the encoded bytes
70 static u32b x_check = 0L;
73 * Hack -- Japanese Kanji code
79 static byte kanji_code = 0;
82 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
83 * @param major メジャーバージョン値
84 * @param minor マイナーバージョン値
85 * @param patch パッチバージョン値
86 * @param extra エクストラパージョン値
87 * @return 現在のバージョンより値が古いならtrue
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 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
114 * @param x メジャーバージョン値
115 * @param y マイナーバージョン値
117 * @return 現在のバージョンより値が古いならtrue
119 static bool z_older_than(byte x, byte y, byte z)
121 /* Much older, or much more recent */
122 if (z_major < x) return (TRUE);
123 if (z_major > x) return (FALSE);
125 /* Distinctly older, or distinctly more recent */
126 if (z_minor < y) return (TRUE);
127 if (z_minor > y) return (FALSE);
129 /* Barely older, or barely more recent */
130 if (z_patch < z) return (TRUE);
131 if (z_patch > z) return (FALSE);
133 /* Identical versions */
139 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
143 * Avoid the top two lines, to avoid interference with "msg_print()".
145 static void note(cptr msg)
149 /* Draw the message */
152 /* Advance one line (wrap if needed) */
153 if (++y >= 24) y = 2;
161 * @brief ロードファイルポインタから1バイトを読み込む
164 * The following functions are used to load the basic building blocks
165 * of savefiles. They also maintain the "checksum" info for 2.7.0+
167 static byte sf_get(void)
171 /* Get a character, decode the value */
172 c = getc(fff) & 0xFF;
176 /* Maintain the checksum info */
180 /* Return the value */
185 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
189 static void rd_byte(byte *ip)
195 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
199 static void rd_u16b(u16b *ip)
202 (*ip) |= ((u16b)(sf_get()) << 8);
206 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
210 static void rd_s16b(s16b *ip)
216 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
220 static void rd_u32b(u32b *ip)
223 (*ip) |= ((u32b)(sf_get()) << 8);
224 (*ip) |= ((u32b)(sf_get()) << 16);
225 (*ip) |= ((u32b)(sf_get()) << 24);
229 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
233 static void rd_s32b(s32b *ip)
240 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
241 * @param str 読み込みポインタ
242 * @param max 最大読み取りバイト数
245 static void rd_string(char *str, int max)
249 /* Read the string */
250 for (i = 0; TRUE; i++)
257 /* Collect string while legal */
258 if (i < max) str[i] = tmp8u;
269 /* Convert Kanji code */
288 /* 不明の漢字コードからシステムの漢字コードに変換 */
289 byte code = codeconv(str);
291 /* 漢字コードが判明したら、それを記録 */
292 if (code) kanji_code = code;
297 /* No conversion needed */
305 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
309 static void strip_bytes(int n)
313 /* Strip the bytes */
314 while (n--) rd_byte(&tmp8u);
317 #define OLD_MAX_MANE 22
320 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
321 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
324 * This function attempts to "repair" old savefiles, and to extract
325 * the most up to date values for various object fields.
327 * Note that Angband 2.7.9 introduced a new method for object "flags"
328 * in which the "flags" on an object are actually extracted when they
329 * are needed from the object kind, artifact index, ego-item index,
330 * and two special "xtra" fields which are used to encode any "extra"
331 * power of certain ego-items. This had the side effect that items
332 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
333 * may have had, and also, all "uncursed" items will become "cursed"
334 * again, including Calris, even if it is being worn at the time. As
335 * a complete hack, items which are inscribed with "uncursed" will be
336 * "uncursed" when imported from pre-2.7.9 savefiles.
338 static void rd_item_old(object_type *o_ptr)
346 rd_s16b(&o_ptr->k_idx);
350 o_ptr->iy = (POSITION)tmp8u;
352 o_ptr->ix = (POSITION)tmp8u;
360 if (z_older_than(10, 4, 4))
362 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
363 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
364 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
368 rd_s16b(&o_ptr->pval);
370 rd_byte(&o_ptr->discount);
372 o_ptr->number = (ITEM_NUMBER)tmp8u;
373 rd_s16b(&o_ptr->weight);
376 o_ptr->name1 = tmp8u;
379 o_ptr->name2 = tmp8u;
381 rd_s16b(&o_ptr->timeout);
383 rd_s16b(&o_ptr->to_h);
386 o_ptr->to_d = tmp16s;
387 rd_s16b(&o_ptr->to_a);
396 rd_byte(&o_ptr->ident);
398 rd_byte(&o_ptr->marked);
401 rd_u32b(&o_ptr->art_flags[0]);
402 rd_u32b(&o_ptr->art_flags[1]);
403 rd_u32b(&o_ptr->art_flags[2]);
404 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
405 else rd_u32b(&o_ptr->art_flags[3]);
407 if (h_older_than(1, 3, 0, 0))
409 if (o_ptr->name2 == EGO_TELEPATHY)
410 add_flag(o_ptr->art_flags, TR_TELEPATHY);
413 if (z_older_than(11, 0, 11))
415 o_ptr->curse_flags = 0L;
416 if (o_ptr->ident & 0x40)
418 o_ptr->curse_flags |= TRC_CURSED;
419 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
420 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
421 if (object_is_fixed_artifact(o_ptr))
423 artifact_type *a_ptr = &a_info[o_ptr->name1];
424 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
425 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
427 else if (object_is_ego(o_ptr))
429 ego_item_type *e_ptr = &e_info[o_ptr->name2];
430 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
431 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
434 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
438 rd_u32b(&o_ptr->curse_flags);
441 /* Monster holding object */
442 rd_s16b(&o_ptr->held_m_idx);
445 rd_byte(&o_ptr->xtra1);
446 rd_byte(&o_ptr->xtra2);
448 if (z_older_than(11, 0, 10))
450 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
452 switch (o_ptr->xtra2 % 6)
454 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
455 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
456 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
457 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
458 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
459 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
463 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
465 switch (o_ptr->xtra2 % 11)
467 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
468 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
469 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
470 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
471 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
472 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
473 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
474 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
475 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
476 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
477 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
481 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
483 switch (o_ptr->xtra2 % 8)
485 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
486 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
487 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
488 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
489 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
490 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
491 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
492 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
499 if (z_older_than(10, 2, 3))
504 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
506 o_ptr->xtra3 = o_ptr->xtra1;
509 if (o_ptr->tval == TV_CAPTURE)
511 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
512 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
514 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
515 if (ironman_nightmare)
517 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
519 o_ptr->xtra4 = o_ptr->xtra5;
524 rd_byte(&o_ptr->xtra3);
525 if (h_older_than(1, 3, 0, 1))
527 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
528 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
531 rd_s16b(&o_ptr->xtra4);
532 rd_s16b(&o_ptr->xtra5);
535 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)))
537 o_ptr->xtra4 = o_ptr->pval;
541 rd_byte(&o_ptr->feeling);
544 rd_string(buf, sizeof(buf));
546 /* Save the inscription */
547 if (buf[0]) o_ptr->inscription = quark_add(buf);
549 rd_string(buf, sizeof(buf));
550 if (buf[0]) o_ptr->art_name = quark_add(buf);
552 /* The Python object */
560 /* Mega-Hack -- handle "dungeon objects" later */
561 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
563 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
565 if (z_older_than(10, 4, 9))
567 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
569 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
570 add_flag(o_ptr->art_flags, TR_DEC_MANA);
575 if (object_is_fixed_artifact(o_ptr))
577 artifact_type *a_ptr;
579 /* Obtain the artifact info */
580 a_ptr = &a_info[o_ptr->name1];
582 /* Verify that artifact */
583 if (!a_ptr->name) o_ptr->name1 = 0;
587 if (object_is_ego(o_ptr))
589 ego_item_type *e_ptr;
591 /* Obtain the ego-item info */
592 e_ptr = &e_info[o_ptr->name2];
594 /* Verify that ego-item */
595 if (!e_ptr->name) o_ptr->name2 = 0;
602 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
603 * @param o_ptr アイテムオブジェクト保存先ポインタ
606 static void rd_item(object_type *o_ptr)
614 if (h_older_than(1, 5, 0, 0))
620 /*** Item save flags ***/
623 /*** Read un-obvious elements ***/
625 rd_s16b(&o_ptr->k_idx);
629 o_ptr->iy = (POSITION)tmp8u;
631 o_ptr->ix = (POSITION)tmp8u;
634 k_ptr = &k_info[o_ptr->k_idx];
635 o_ptr->tval = k_ptr->tval;
636 o_ptr->sval = k_ptr->sval;
639 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
640 else o_ptr->pval = 0;
642 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
643 else o_ptr->discount = 0;
644 if (flags & SAVE_ITEM_NUMBER) {
646 o_ptr->number = tmp8u;
648 else o_ptr->number = 1;
650 rd_s16b(&o_ptr->weight);
652 if (flags & SAVE_ITEM_NAME1)
655 o_ptr->name1 = tmp8u;
657 else o_ptr->name1 = 0;
658 if (flags & SAVE_ITEM_NAME2)
661 o_ptr->name2 = tmp8u;
663 else o_ptr->name2 = 0;
664 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
665 else o_ptr->timeout = 0;
667 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
668 else o_ptr->to_h = 0;
669 if (flags & SAVE_ITEM_TO_D)
672 o_ptr->to_d = tmp16s;
674 else o_ptr->to_d = 0;
675 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
676 else o_ptr->to_a = 0;
678 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
681 if (flags & SAVE_ITEM_DD)
687 if (flags & SAVE_ITEM_DS)
694 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
695 else o_ptr->ident = 0;
697 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
698 else o_ptr->marked = 0;
701 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
702 else o_ptr->art_flags[0] = 0;
703 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
704 else o_ptr->art_flags[1] = 0;
705 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
706 else o_ptr->art_flags[2] = 0;
707 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
708 else o_ptr->art_flags[3] = 0;
709 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
710 else o_ptr->art_flags[4] = 0;
712 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
713 else o_ptr->curse_flags = 0;
715 /* Monster holding object */
716 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
717 else o_ptr->held_m_idx = 0;
720 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
721 else o_ptr->xtra1 = 0;
722 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
723 else o_ptr->xtra2 = 0;
725 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
726 else o_ptr->xtra3 = 0;
728 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
729 else o_ptr->xtra4 = 0;
730 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
731 else o_ptr->xtra5 = 0;
733 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
734 else o_ptr->feeling = 0;
736 if (flags & SAVE_ITEM_INSCRIPTION)
738 rd_string(buf, sizeof(buf));
739 o_ptr->inscription = quark_add(buf);
741 else o_ptr->inscription = 0;
743 if (flags & SAVE_ITEM_ART_NAME)
745 rd_string(buf, sizeof(buf));
746 o_ptr->art_name = quark_add(buf);
748 else o_ptr->art_name = 0;
750 if(h_older_than(2,1,2,4))
752 u32b flgs[TR_FLAG_SIZE];
753 object_flags(o_ptr, flgs);
755 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
757 add_flag(o_ptr->art_flags, TR_LITE_M1);
758 remove_flag(o_ptr->art_flags, TR_LITE_1);
759 remove_flag(o_ptr->art_flags, TR_LITE_2);
760 remove_flag(o_ptr->art_flags, TR_LITE_3);
762 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
764 if (o_ptr->tval == TV_LITE)
766 if (o_ptr->sval == SV_LITE_TORCH)
768 add_flag(o_ptr->art_flags, TR_LITE_M1);
770 else if (o_ptr->sval == SV_LITE_LANTERN)
772 add_flag(o_ptr->art_flags, TR_LITE_M2);
774 else if (o_ptr->sval == SV_LITE_FEANOR)
776 add_flag(o_ptr->art_flags, TR_LITE_M3);
782 add_flag(o_ptr->art_flags, TR_LITE_M1);
785 else if (o_ptr->tval == TV_LITE)
787 if (object_is_fixed_artifact(o_ptr))
789 add_flag(o_ptr->art_flags, TR_LITE_3);
791 else if (o_ptr->sval == SV_LITE_TORCH)
793 add_flag(o_ptr->art_flags, TR_LITE_1);
794 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
796 else if (o_ptr->sval == SV_LITE_LANTERN)
798 add_flag(o_ptr->art_flags, TR_LITE_2);
799 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
801 else if (o_ptr->sval == SV_LITE_FEANOR)
803 add_flag(o_ptr->art_flags, TR_LITE_2);
811 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
812 * @param m_ptr モンスター保存先ポインタ
815 static void rd_monster_old(monster_type *m_ptr)
822 /* Read the monster race */
823 rd_s16b(&m_ptr->r_idx);
825 if (z_older_than(11, 0, 12))
826 m_ptr->ap_r_idx = m_ptr->r_idx;
828 rd_s16b(&m_ptr->ap_r_idx);
830 if (z_older_than(11, 0, 14))
832 monster_race *r_ptr = &r_info[m_ptr->r_idx];
834 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
835 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
836 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
839 rd_byte(&m_ptr->sub_align);
841 /* Read the other information */
843 m_ptr->fy = (POSITION)tmp8u;
845 m_ptr->fx = (POSITION)tmp8u;
850 m_ptr->maxhp = tmp16s;
852 if (z_older_than(11, 0, 5))
854 m_ptr->max_maxhp = m_ptr->maxhp;
859 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
861 if(h_older_than(2, 1, 2, 1))
863 m_ptr->dealt_damage = 0;
867 rd_u32b(&m_ptr->dealt_damage);
870 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
871 rd_byte(&m_ptr->mspeed);
872 if (z_older_than(10, 4, 2))
875 m_ptr->energy_need = (s16b)tmp8u;
877 else rd_s16b(&m_ptr->energy_need);
879 if (z_older_than(11, 0, 13))
880 m_ptr->energy_need = 100 - m_ptr->energy_need;
882 if (z_older_than(10,0,7))
884 m_ptr->mtimed[MTIMED_FAST] = 0;
885 m_ptr->mtimed[MTIMED_SLOW] = 0;
890 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
892 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
895 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
897 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
899 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
901 if (z_older_than(10,0,10))
905 else if (z_older_than(10,0,11))
913 m_ptr->target_y = (POSITION)tmp16s;
915 m_ptr->target_x = (POSITION)tmp16s;
919 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
921 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
922 rd_u32b(&m_ptr->smart);
926 if (z_older_than(10, 4, 5))
932 if (z_older_than(10, 2, 2))
934 if (m_ptr->r_idx < 0)
936 m_ptr->r_idx = (0-m_ptr->r_idx);
937 m_ptr->mflag2 |= MFLAG2_KAGE;
942 rd_byte(&m_ptr->mflag2);
945 if (z_older_than(11, 0, 12))
947 if (m_ptr->mflag2 & MFLAG2_KAGE)
948 m_ptr->ap_r_idx = MON_KAGE;
951 if (z_older_than(10, 1, 3))
957 rd_string(buf, sizeof(buf));
958 if (buf[0]) m_ptr->nickname = quark_add(buf);
966 * @brief モンスターを読み込む(現版) / Read a monster (New method)
967 * @param m_ptr モンスター保存先ポインタ
970 static void rd_monster(monster_type *m_ptr)
978 if (h_older_than(1, 5, 0, 0))
980 rd_monster_old(m_ptr);
984 /*** Monster save flags ***/
987 /*** Read un-obvious elements ***/
989 /* Read the monster race */
990 rd_s16b(&m_ptr->r_idx);
992 /* Read the other information */
994 m_ptr->fy = (POSITION)tmp8u;
996 m_ptr->fx = (POSITION)tmp8u;
999 m_ptr->hp = (HIT_POINT)tmp16s;
1001 m_ptr->maxhp = (HIT_POINT)tmp16s;
1003 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1005 if(h_older_than(2, 1, 2, 1))
1007 m_ptr->dealt_damage = 0;
1011 rd_u32b(&m_ptr->dealt_damage);
1014 /* Monster race index of its appearance */
1015 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1016 else m_ptr->ap_r_idx = m_ptr->r_idx;
1018 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1019 else m_ptr->sub_align = 0;
1021 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1022 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1024 rd_byte(&m_ptr->mspeed);
1026 rd_s16b(&m_ptr->energy_need);
1028 if (flags & SAVE_MON_FAST)
1031 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1033 else m_ptr->mtimed[MTIMED_FAST] = 0;
1034 if (flags & SAVE_MON_SLOW)
1037 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1039 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1040 if (flags & SAVE_MON_STUNNED)
1043 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1045 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1046 if (flags & SAVE_MON_CONFUSED)
1049 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1051 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1052 if (flags & SAVE_MON_MONFEAR)
1055 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1057 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1059 if (flags & SAVE_MON_TARGET_Y)
1062 m_ptr->target_y = (POSITION)tmp16s;
1064 else m_ptr->target_y = 0;
1065 if (flags & SAVE_MON_TARGET_X)
1068 m_ptr->target_x = (POSITION)tmp16s;
1070 else m_ptr->target_x = 0;
1072 if (flags & SAVE_MON_INVULNER)
1075 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1077 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1079 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1080 else m_ptr->smart = 0;
1082 if (flags & SAVE_MON_EXP)
1085 m_ptr->exp = (EXP)tmp32u;
1087 else m_ptr->exp = 0;
1089 m_ptr->mflag = 0; /* Not saved */
1091 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1092 else m_ptr->mflag2 = 0;
1094 if (flags & SAVE_MON_NICKNAME)
1096 rd_string(buf, sizeof(buf));
1097 m_ptr->nickname = quark_add(buf);
1099 else m_ptr->nickname = 0;
1101 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1102 else m_ptr->parent_m_idx = 0;
1107 * Old monster bit flags of racial resistances
1109 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1110 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1111 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1112 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1113 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1114 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1115 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1116 #define RF3_RES_WATE 0x00800000 /* Resist water */
1117 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1118 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1119 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1120 #define RF3_RES_ALL 0x08000000 /* Resist all */
1122 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1124 if ((R_PTR)->r_flags3 & (RF3)) \
1126 (R_PTR)->r_flags3 &= ~(RF3); \
1127 (R_PTR)->r_flagsr |= (RFR); \
1131 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1133 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1135 (R_PTR)->r_flagsr |= (RFR); \
1139 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1140 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1141 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1142 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1143 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1144 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1145 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1146 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1147 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1148 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1151 * @brief モンスターの思い出を読み込む / Read the monster lore
1152 * @param r_idx 読み込み先モンスターID
1155 static void rd_lore(MONRACE_IDX r_idx)
1159 monster_race *r_ptr = &r_info[r_idx];
1161 /* Count sights/deaths/kills */
1162 rd_s16b(&r_ptr->r_sights);
1163 rd_s16b(&r_ptr->r_deaths);
1164 rd_s16b(&r_ptr->r_pkills);
1165 if (h_older_than(1, 7, 0, 5))
1167 r_ptr->r_akills = r_ptr->r_pkills;
1171 rd_s16b(&r_ptr->r_akills);
1173 rd_s16b(&r_ptr->r_tkills);
1175 /* Count wakes and ignores */
1176 rd_byte(&r_ptr->r_wake);
1177 rd_byte(&r_ptr->r_ignore);
1180 rd_byte(&r_ptr->r_xtra1);
1181 rd_byte(&r_ptr->r_xtra2);
1184 rd_byte(&r_ptr->r_drop_gold);
1185 rd_byte(&r_ptr->r_drop_item);
1189 rd_byte(&r_ptr->r_cast_spell);
1191 /* Count blows of each type */
1192 rd_byte(&r_ptr->r_blows[0]);
1193 rd_byte(&r_ptr->r_blows[1]);
1194 rd_byte(&r_ptr->r_blows[2]);
1195 rd_byte(&r_ptr->r_blows[3]);
1197 /* Memorize flags */
1198 rd_u32b(&r_ptr->r_flags1);
1199 rd_u32b(&r_ptr->r_flags2);
1200 rd_u32b(&r_ptr->r_flags3);
1201 rd_u32b(&r_ptr->r_flags4);
1202 rd_u32b(&r_ptr->r_flags5);
1203 rd_u32b(&r_ptr->r_flags6);
1204 if (h_older_than(1, 5, 0, 3))
1206 r_ptr->r_flagsr = 0L;
1208 /* Move RF3 resistance flags to RFR */
1209 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1210 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1211 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1212 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1213 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1214 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1215 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1216 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1217 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1218 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1219 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1220 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1222 /* Separate breathers resistance from RF4 to RFR */
1223 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1224 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1225 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1226 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1227 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1228 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1229 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1230 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1231 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1233 /* Resist confusion is merged to RF3_NO_CONF */
1234 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1236 /* Misc resistance hack to RFR */
1237 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1238 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1242 rd_u32b(&r_ptr->r_flagsr);
1245 /* Read the "Racial" monster limit per level */
1246 rd_byte(&r_ptr->max_num);
1248 /* Location in saved floor */
1249 rd_s16b(&r_ptr->floor_id);
1254 /* Repair the lore flags */
1255 r_ptr->r_flags1 &= r_ptr->flags1;
1256 r_ptr->r_flags2 &= r_ptr->flags2;
1257 r_ptr->r_flags3 &= r_ptr->flags3;
1258 r_ptr->r_flags4 &= r_ptr->flags4;
1259 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1260 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1261 r_ptr->r_flagsr &= r_ptr->flagsr;
1265 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1266 * @param st_ptr 店舗の参照ポインタ
1267 * @param o_ptr アイテムオブジェクト参照ポインタ
1270 * In all cases, return the slot (or -1) where the object was placed
1272 * Note that this is a hacked up version of "inven_carry()".
1274 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1275 * known, the player may have to pick stuff up and drop it again.
1277 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1285 /* Check each existing item (try to combine) */
1286 for (slot = 0; slot < st_ptr->stock_num; slot++)
1288 /* Get the existing item */
1289 j_ptr = &st_ptr->stock[slot];
1291 /* The home acts just like the player */
1292 if (object_similar(j_ptr, o_ptr))
1294 /* Save the new number of items */
1295 object_absorb(j_ptr, o_ptr);
1303 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1307 /* Determine the "value" of the item */
1308 value = object_value(o_ptr);
1310 /* Check existing slots to see if we must "slide" */
1311 for (slot = 0; slot < st_ptr->stock_num; slot++)
1313 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1316 /* Slide the others up */
1317 for (i = st_ptr->stock_num; i > slot; i--)
1319 st_ptr->stock[i] = st_ptr->stock[i-1];
1322 /* More stuff now */
1323 st_ptr->stock_num++;
1325 /* Insert the new item */
1326 st_ptr->stock[slot] = *o_ptr;
1328 chg_virtue(V_SACRIFICE, -1);
1330 /* Return the location */
1335 * @brief 店舗情報を読み込む / Read a store
1336 * @param town_number 街ID
1337 * @param store_number 店舗ID
1340 static errr rd_store(int town_number, int store_number)
1352 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1354 st_ptr = &town[1].store[store_number];
1355 if (st_ptr->stock_num) sort = TRUE;
1359 st_ptr = &town[town_number].store[store_number];
1362 /* Read the basic info */
1363 rd_s32b(&st_ptr->store_open);
1364 rd_s16b(&st_ptr->insult_cur);
1366 if (z_older_than(11, 0, 4))
1375 rd_s16b(&st_ptr->good_buy);
1376 rd_s16b(&st_ptr->bad_buy);
1378 /* Read last visit */
1379 rd_s32b(&st_ptr->last_visit);
1381 /* Extract the owner (see above) */
1382 st_ptr->owner = own;
1384 /* Read the items */
1385 for (j = 0; j < num; j++)
1390 /* Get local object */
1393 /* Wipe the object */
1399 /* Acquire valid items */
1400 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1405 home_carry(st_ptr, q_ptr);
1409 k = st_ptr->stock_num++;
1411 /* Acquire the item */
1412 object_copy(&st_ptr->stock[k], q_ptr);
1423 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1426 static void rd_randomizer(void)
1436 rd_u16b(&Rand_place);
1439 for (i = 0; i < RAND_DEG; i++)
1441 rd_u32b(&Rand_state[i]);
1448 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1451 * Note that the normal options are now stored as a set of 256 bit flags,
1452 * plus a set of 256 bit masks to indicate which bit flags were defined
1453 * at the time the savefile was created. This will allow new options
1454 * to be added, and old options to be removed, at any time, without
1455 * hurting old savefiles.
1457 * The window options are stored in the same way, but note that each
1458 * window gets 32 options, and their order is fixed by certain defines.
1460 static void rd_options(void)
1474 /* Ignore old options */
1478 /*** Special info */
1480 /* Read "delay_factor" */
1484 /* Read "hitpoint_warn" */
1488 /* Read "mana_warn" */
1489 if(h_older_than(1, 7, 0, 0))
1500 /*** Cheating options ***/
1504 if (c & 0x0002) p_ptr->wizard = TRUE;
1506 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1507 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1508 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1509 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1510 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1511 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1512 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1513 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1514 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1516 rd_byte((byte *)&autosave_l);
1517 rd_byte((byte *)&autosave_t);
1518 rd_s16b(&autosave_freq);
1521 /*** Normal Options ***/
1523 /* Read the option flags */
1524 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1526 /* Read the option masks */
1527 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1529 /* Analyze the options */
1530 for (n = 0; n < 8; n++)
1532 /* Analyze the options */
1533 for (i = 0; i < 32; i++)
1535 /* Process valid flags */
1536 if (mask[n] & (1L << i))
1538 /* Process valid flags */
1539 if (option_mask[n] & (1L << i))
1542 if (flag[n] & (1L << i))
1545 option_flag[n] |= (1L << i);
1552 option_flag[n] &= ~(1L << i);
1559 if (z_older_than(10, 4, 5))
1561 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1562 else option_flag[5] |= (0x00000001 << 4);
1563 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1564 else option_flag[2] |= (0x00000001 << 5);
1565 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1566 else option_flag[4] |= (0x00000001 << 5);
1567 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1568 else option_flag[5] |= (0x00000001 << 0);
1569 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1570 else option_flag[5] |= (0x00000001 << 12);
1571 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1572 else option_flag[1] |= (0x00000001 << 0);
1573 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1574 else option_flag[1] |= (0x00000001 << 18);
1575 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1576 else option_flag[1] |= (0x00000001 << 19);
1577 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1578 else option_flag[5] |= (0x00000001 << 3);
1581 /* Extract the options */
1582 extract_option_vars();
1585 /*** Window Options ***/
1587 /* Read the window flags */
1588 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1590 /* Read the window masks */
1591 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1593 /* Analyze the options */
1594 for (n = 0; n < 8; n++)
1596 /* Analyze the options */
1597 for (i = 0; i < 32; i++)
1599 /* Process valid flags */
1600 if (mask[n] & (1L << i))
1602 /* Process valid flags */
1603 if (window_mask[n] & (1L << i))
1606 if (flag[n] & (1L << i))
1609 window_flag[n] |= (1L << i);
1616 window_flag[n] &= ~(1L << i);
1627 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1630 * XXX XXX XXX This is such a nasty hack it hurts.
1632 static void rd_ghost(void)
1637 rd_string(buf, sizeof(buf));
1639 /* Strip old data */
1645 * @brief クイックスタート情報を読み込む / Load quick start data
1648 static void load_quick_start(void)
1654 if (z_older_than(11, 0, 13))
1656 previous_char.quick_ok = FALSE;
1660 rd_byte(&previous_char.psex);
1661 rd_byte(&previous_char.prace);
1662 rd_byte(&previous_char.pclass);
1663 rd_byte(&previous_char.pseikaku);
1665 previous_char.realm1 = (REALM_IDX)tmp8u;
1667 previous_char.realm2 = (REALM_IDX)tmp8u;
1669 rd_s16b(&previous_char.age);
1670 rd_s16b(&previous_char.ht);
1671 rd_s16b(&previous_char.wt);
1672 rd_s16b(&previous_char.sc);
1673 rd_s32b(&previous_char.au);
1675 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1676 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1678 for (i = 0; i < PY_MAX_LEVEL; i++)
1681 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1684 rd_s16b(&previous_char.chaos_patron);
1686 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1688 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1690 /* UNUSED : Was number of random quests */
1694 previous_char.quick_ok = (bool)tmp8u;
1698 * @brief その他の情報を読み込む / Read the "extra" information
1701 static void rd_extra(void)
1710 rd_string(p_ptr->name, sizeof(p_ptr->name));
1712 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1714 if (!h_older_than(1, 7, 0, 1))
1718 /* Read the message */
1719 rd_string(buf, sizeof buf);
1720 if (buf[0]) p_ptr->last_message = string_make(buf);
1725 for (i = 0; i < 4; i++)
1727 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1730 /* Class/Race/Seikaku/Gender/Spells */
1731 rd_byte(&p_ptr->prace);
1732 rd_byte(&p_ptr->pclass);
1733 rd_byte(&p_ptr->pseikaku);
1734 rd_byte(&p_ptr->psex);
1736 p_ptr->realm1 = (REALM_IDX)tmp8u;
1738 p_ptr->realm2 = (REALM_IDX)tmp8u;
1739 rd_byte(&tmp8u); /* oops */
1741 if (z_older_than(10, 4, 4))
1743 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1744 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1745 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1746 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1749 /* Special Race/Class info */
1751 p_ptr->hitdie = tmp8u;
1752 rd_u16b(&p_ptr->expfact);
1754 /* Age/Height/Weight */
1755 rd_s16b(&p_ptr->age);
1756 rd_s16b(&p_ptr->ht);
1757 rd_s16b(&p_ptr->wt);
1759 /* Read the stat info */
1760 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1761 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1762 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1764 strip_bytes(24); /* oops */
1766 rd_s32b(&p_ptr->au);
1768 rd_s32b(&p_ptr->max_exp);
1769 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1770 else rd_s32b(&p_ptr->max_max_exp);
1771 rd_s32b(&p_ptr->exp);
1773 if (h_older_than(1, 7, 0, 3))
1776 p_ptr->exp_frac = (u32b)tmp16u;
1780 rd_u32b(&p_ptr->exp_frac);
1783 rd_s16b(&p_ptr->lev);
1785 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1786 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1788 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1790 if (z_older_than(10, 3, 6))
1791 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1793 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1794 for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1795 if (z_older_than(10, 4, 1))
1797 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1798 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1800 if (z_older_than(10, 3, 14))
1802 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1803 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1807 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1808 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1809 if (h_older_than(1, 3, 0, 1))
1811 if (p_ptr->pclass == CLASS_SMITH)
1813 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1814 p_ptr->magic_num1[96] = 0;
1815 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1816 p_ptr->magic_num1[97] = 0;
1820 if (music_singing_any()) p_ptr->action = ACTION_SING;
1822 if (z_older_than(11, 0, 7))
1824 p_ptr->start_race = p_ptr->prace;
1825 p_ptr->old_race1 = 0L;
1826 p_ptr->old_race2 = 0L;
1827 p_ptr->old_realm = 0;
1831 rd_byte(&p_ptr->start_race);
1833 p_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1835 p_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1836 rd_s16b(&p_ptr->old_realm);
1839 if (z_older_than(10, 0, 1))
1841 for (i = 0; i < MAX_MANE; i++)
1843 p_ptr->mane_spell[i] = -1;
1844 p_ptr->mane_dam[i] = 0;
1846 p_ptr->mane_num = 0;
1848 else if (z_older_than(10, 2, 3))
1850 for (i = 0; i < OLD_MAX_MANE; i++)
1855 for (i = 0; i < MAX_MANE; i++)
1857 p_ptr->mane_spell[i] = -1;
1858 p_ptr->mane_dam[i] = 0;
1861 p_ptr->mane_num = 0;
1865 for (i = 0; i < MAX_MANE; i++)
1868 p_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1870 p_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1872 rd_s16b(&p_ptr->mane_num);
1875 if (z_older_than(10, 0, 3))
1877 determine_bounty_uniques();
1879 for (i = 0; i < MAX_KUBI; i++)
1881 /* Is this bounty unique already dead? */
1882 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1887 for (i = 0; i < MAX_KUBI; i++)
1889 rd_s16b(&kubi_r_idx[i]);
1893 if (z_older_than(10, 0, 3))
1899 for (i = 0; i < 4; i++)
1901 rd_s16b(&battle_mon[i]);
1902 if (z_older_than(10, 3, 4))
1905 mon_odds[i] = tmp16s;
1907 else rd_u32b(&mon_odds[i]);
1911 rd_s16b(&p_ptr->town_num);
1913 /* Read arena and rewards information */
1914 rd_s16b(&p_ptr->arena_number);
1915 if (h_older_than(1, 5, 0, 1))
1917 /* Arena loser of previous version was marked number 99 */
1918 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1921 p_ptr->inside_arena = (bool)tmp16s;
1922 rd_s16b(&p_ptr->inside_quest);
1923 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1927 p_ptr->inside_battle = (bool)tmp16s;
1929 rd_byte(&p_ptr->exit_bldg);
1933 p_ptr->oldpx = (POSITION)tmp16s;
1935 p_ptr->oldpy = (POSITION)tmp16s;
1937 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1939 /* Was p_ptr->rewards[MAX_BACT] */
1941 for (i = 0; i < tmp16s; i++)
1947 if (h_older_than(1, 7, 0, 3))
1950 p_ptr->mhp = tmp16s;
1953 p_ptr->chp = tmp16s;
1956 p_ptr->chp_frac = (u32b)tmp16u;
1960 rd_s32b(&p_ptr->mhp);
1961 rd_s32b(&p_ptr->chp);
1962 rd_u32b(&p_ptr->chp_frac);
1965 if (h_older_than(1, 7, 0, 3))
1968 p_ptr->msp = tmp16s;
1971 p_ptr->csp = tmp16s;
1974 p_ptr->csp_frac = (u32b)tmp16u;
1978 rd_s32b(&p_ptr->msp);
1979 rd_s32b(&p_ptr->csp);
1980 rd_u32b(&p_ptr->csp_frac);
1983 rd_s16b(&p_ptr->max_plv);
1984 if (z_older_than(10, 3, 8))
1987 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1991 byte max = (byte)max_d_idx;
1995 for(i = 0; i < max; i++)
1998 max_dlv[i] = tmp16s;
1999 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
2003 /* Repair maximum player level XXX XXX XXX */
2004 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
2008 rd_s16b(&p_ptr->sc);
2009 rd_s16b(&p_ptr->concent);
2011 /* Read the flags */
2012 strip_bytes(2); /* Old "rest" */
2013 rd_s16b(&p_ptr->blind);
2014 rd_s16b(&p_ptr->paralyzed);
2015 rd_s16b(&p_ptr->confused);
2016 rd_s16b(&p_ptr->food);
2017 strip_bytes(4); /* Old "food_digested" / "protection" */
2019 rd_s16b(&p_ptr->energy_need);
2020 if (z_older_than(11, 0, 13))
2021 p_ptr->energy_need = 100 - p_ptr->energy_need;
2022 if (h_older_than(2, 1, 2, 0))
2023 p_ptr->enchant_energy_need = 0;
2025 rd_s16b(&p_ptr->enchant_energy_need);
2027 rd_s16b(&p_ptr->fast);
2028 rd_s16b(&p_ptr->slow);
2029 rd_s16b(&p_ptr->afraid);
2030 rd_s16b(&p_ptr->cut);
2031 rd_s16b(&p_ptr->stun);
2032 rd_s16b(&p_ptr->poisoned);
2033 rd_s16b(&p_ptr->image);
2034 rd_s16b(&p_ptr->protevil);
2035 rd_s16b(&p_ptr->invuln);
2036 if(z_older_than(10, 0, 0))
2039 rd_s16b(&p_ptr->ult_res);
2040 rd_s16b(&p_ptr->hero);
2041 rd_s16b(&p_ptr->shero);
2042 rd_s16b(&p_ptr->shield);
2043 rd_s16b(&p_ptr->blessed);
2044 rd_s16b(&p_ptr->tim_invis);
2045 rd_s16b(&p_ptr->word_recall);
2046 if (z_older_than(10, 3, 8))
2047 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2051 p_ptr->recall_dungeon = (byte)tmp16s;
2054 if (h_older_than(1, 5, 0, 0))
2055 p_ptr->alter_reality = 0;
2057 rd_s16b(&p_ptr->alter_reality);
2059 rd_s16b(&p_ptr->see_infra);
2060 rd_s16b(&p_ptr->tim_infra);
2061 rd_s16b(&p_ptr->oppose_fire);
2062 rd_s16b(&p_ptr->oppose_cold);
2063 rd_s16b(&p_ptr->oppose_acid);
2064 rd_s16b(&p_ptr->oppose_elec);
2065 rd_s16b(&p_ptr->oppose_pois);
2066 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2067 else rd_s16b(&p_ptr->tsuyoshi);
2069 /* Old savefiles do not have the following fields... */
2070 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2073 p_ptr->wraith_form = 0;
2074 p_ptr->resist_magic = 0;
2075 p_ptr->tim_regen = 0;
2076 p_ptr->kabenuke = 0;
2077 p_ptr->tim_stealth = 0;
2078 p_ptr->tim_levitation = 0;
2079 p_ptr->tim_sh_touki = 0;
2080 p_ptr->lightspeed = 0;
2081 p_ptr->tsubureru = 0;
2082 p_ptr->tim_res_nether = 0;
2083 p_ptr->tim_res_time = 0;
2084 p_ptr->mimic_form = 0;
2085 p_ptr->tim_mimic = 0;
2086 p_ptr->tim_sh_fire = 0;
2089 p_ptr->tim_reflect = 0;
2090 p_ptr->multishadow = 0;
2091 p_ptr->dustrobe = 0;
2093 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2101 rd_s16b(&p_ptr->tim_esp);
2102 rd_s16b(&p_ptr->wraith_form);
2103 rd_s16b(&p_ptr->resist_magic);
2104 rd_s16b(&p_ptr->tim_regen);
2105 rd_s16b(&p_ptr->kabenuke);
2106 rd_s16b(&p_ptr->tim_stealth);
2107 rd_s16b(&p_ptr->tim_levitation);
2108 rd_s16b(&p_ptr->tim_sh_touki);
2109 rd_s16b(&p_ptr->lightspeed);
2110 rd_s16b(&p_ptr->tsubureru);
2111 if (z_older_than(10, 4, 7))
2112 p_ptr->magicdef = 0;
2114 rd_s16b(&p_ptr->magicdef);
2115 rd_s16b(&p_ptr->tim_res_nether);
2116 if (z_older_than(10, 4, 11))
2118 p_ptr->tim_res_time = 0;
2119 p_ptr->mimic_form = 0;
2120 p_ptr->tim_mimic = 0;
2121 p_ptr->tim_sh_fire = 0;
2125 rd_s16b(&p_ptr->tim_res_time);
2127 p_ptr->mimic_form = (IDX)tmp8u;
2128 rd_s16b(&p_ptr->tim_mimic);
2129 rd_s16b(&p_ptr->tim_sh_fire);
2132 if (z_older_than(11, 0, 99))
2134 p_ptr->tim_sh_holy = 0;
2135 p_ptr->tim_eyeeye = 0;
2139 rd_s16b(&p_ptr->tim_sh_holy);
2140 rd_s16b(&p_ptr->tim_eyeeye);
2144 if ( z_older_than(11,0,3) ){
2145 p_ptr->tim_reflect=0;
2146 p_ptr->multishadow=0;
2150 rd_s16b(&p_ptr->tim_reflect);
2151 rd_s16b(&p_ptr->multishadow);
2152 rd_s16b(&p_ptr->dustrobe);
2155 rd_s16b(&p_ptr->chaos_patron);
2156 rd_u32b(&p_ptr->muta1);
2157 rd_u32b(&p_ptr->muta2);
2158 rd_u32b(&p_ptr->muta3);
2160 for (i = 0; i < 8; i++)
2161 rd_s16b(&p_ptr->virtues[i]);
2162 for (i = 0; i < 8; i++)
2163 rd_s16b(&p_ptr->vir_types[i]);
2166 /* Calc the regeneration modifier for mutations */
2167 mutant_regenerate_mod = calc_mutant_regenerate_mod();
2169 if (z_older_than(10,0,9))
2172 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2173 p_ptr->ele_attack = 0;
2177 rd_s16b(&p_ptr->ele_attack);
2178 rd_u32b(&p_ptr->special_attack);
2180 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2181 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2182 if (z_older_than(10,0,12))
2184 p_ptr->ele_immune = 0;
2185 p_ptr->special_defense = 0;
2189 rd_s16b(&p_ptr->ele_immune);
2190 rd_u32b(&p_ptr->special_defense);
2192 rd_byte(&p_ptr->knowledge);
2195 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2197 rd_byte(&tmp8u); /* oops */
2198 rd_byte(&p_ptr->action);
2199 if (!z_older_than(10, 4, 3))
2202 if (tmp8u) p_ptr->action = ACTION_LEARN;
2204 rd_byte((byte *)&preserve_mode);
2205 rd_byte((byte *)&p_ptr->wait_report_score);
2208 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2210 /* Skip the flags */
2214 /* Hack -- the two "special seeds" */
2215 rd_u32b(&seed_flavor);
2216 rd_u32b(&seed_town);
2220 rd_u16b(&p_ptr->panic_save);
2221 rd_u16b(&p_ptr->total_winner);
2222 rd_u16b(&p_ptr->noscore);
2227 p_ptr->is_dead = tmp8u;
2229 /* Read "feeling" */
2230 rd_byte(&p_ptr->feeling);
2232 switch (p_ptr->start_race)
2238 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2241 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2244 dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2246 /* Turn when level began */
2249 if (h_older_than(1, 7, 0, 4))
2251 p_ptr->feeling_turn = old_turn;
2255 /* Turn of last "feeling" */
2256 rd_s32b(&p_ptr->feeling_turn);
2262 if (z_older_than(10, 3, 12))
2264 dungeon_turn = turn;
2266 else rd_s32b(&dungeon_turn);
2268 if (z_older_than(11, 0, 13))
2271 p_ptr->feeling_turn /= 2;
2276 if (z_older_than(10, 3, 13))
2280 else rd_s32b(&old_battle);
2282 if (z_older_than(10,0,3))
2284 determine_today_mon(TRUE);
2288 rd_s16b(&today_mon);
2289 rd_s16b(&p_ptr->today_mon);
2292 if (z_older_than(10,0,7))
2298 rd_s16b(&p_ptr->riding);
2301 /* Current floor_id */
2302 if (h_older_than(1, 5, 0, 0))
2304 p_ptr->floor_id = 0;
2308 rd_s16b(&p_ptr->floor_id);
2311 if (h_older_than(1, 5, 0, 2))
2317 /* Get number of party_mon array */
2320 /* Strip old temporary preserved pets */
2321 for (i = 0; i < tmp16s; i++)
2323 monster_type dummy_mon;
2325 rd_monster(&dummy_mon);
2329 if (z_older_than(10,1,2))
2338 if (z_older_than(10,3,9))
2342 else if (z_older_than(10, 3, 10))
2350 p_ptr->visit = (BIT_FLAGS)tmp32s;
2352 if (!z_older_than(11, 0, 5))
2354 rd_u32b(&p_ptr->count);
2360 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2363 * Note that the inventory changed in Angband 2.7.4. Two extra
2364 * pack slots were added and the equipment was rearranged. Note
2365 * that these two features combine when parsing old save-files, in
2366 * which items from the old "aux" slot are "carried", perhaps into
2367 * one of the two new "inventory" slots.
2369 * Note that the inventory is "re-sorted" later by "dungeon()".
2371 static errr rd_inventory(void)
2379 p_ptr->total_weight = 0;
2385 /* Read until done */
2390 /* Get the next item index */
2393 /* Nope, we reached the end */
2394 if (n == 0xFFFF) break;
2396 /* Get local object */
2399 /* Wipe the object */
2405 /* Hack -- verify item */
2406 if (!q_ptr->k_idx) return (53);
2408 /* Wield equipment */
2409 if (n >= INVEN_RARM)
2411 /* Player touches it */
2412 q_ptr->marked |= OM_TOUCHED;
2415 object_copy(&inventory[n], q_ptr);
2417 /* Add the weight */
2418 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2424 /* Warning -- backpack is full */
2425 else if (inven_cnt == INVEN_PACK)
2428 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
2434 /* Carry inventory */
2440 /* Player touches it */
2441 q_ptr->marked |= OM_TOUCHED;
2444 object_copy(&inventory[n], q_ptr);
2446 /* Add the weight */
2447 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2460 * @brief メッセージログを読み込む / Read the saved messages
2463 static void rd_messages(void)
2469 if (h_older_than(2, 2, 0, 75))
2475 /* Read the messages */
2476 for (i = 0; i < num; i++)
2478 /* Read the message */
2479 rd_string(buf, sizeof(buf));
2481 /* Save the message */
2491 /* Read the messages */
2492 for (i = 0; i < num; i++)
2494 /* Read the message */
2495 rd_string(buf, sizeof(buf));
2497 /* Save the message */
2506 /* Old hidden trap flag */
2507 #define CAVE_TRAP 0x8000
2509 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2510 #define OLD_FEAT_INVIS 0x02
2511 #define OLD_FEAT_GLYPH 0x03
2512 #define OLD_FEAT_QUEST_ENTER 0x08
2513 #define OLD_FEAT_QUEST_EXIT 0x09
2514 #define OLD_FEAT_MINOR_GLYPH 0x40
2515 #define OLD_FEAT_BLDG_1 0x81
2516 #define OLD_FEAT_MIRROR 0xc3
2519 #define OLD_QUEST_WATER_CAVE 18
2521 /* Quest constants */
2522 #define QUEST_OLD_CASTLE 27
2523 #define QUEST_ROYAL_CRYPT 28
2526 * @brief メッセージログを読み込む / Read the dungeon (old method)
2529 * The monsters/objects must be loaded in the same order
2530 * that they were stored, since the actual indexes matter.
2532 static errr rd_dungeon_old(void)
2543 /*** Basic info ***/
2547 dun_level = (DEPTH)tmp16s;
2548 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2552 dungeon_type = (IDX)tmp8u;
2555 /* Set the base level for old versions */
2556 base_level = dun_level;
2559 base_level = (DEPTH)tmp16s;
2561 rd_s16b(&num_repro);
2563 p_ptr->y = (POSITION)tmp16s;
2565 p_ptr->x = (POSITION)tmp16s;
2566 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2568 cur_hgt = (POSITION)tmp16s;
2570 cur_wid = (POSITION)tmp16s;
2571 rd_s16b(&tmp16s); /* max_panel_rows */
2572 rd_s16b(&tmp16s); /* max_panel_cols */
2575 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2583 /*** Run length decoding ***/
2585 /* Load the dungeon data */
2586 for (x = y = 0; y < ymax; )
2592 if (z_older_than(10,3,6))
2601 /* Decline invalid flags */
2602 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2605 /* Apply the RLE info */
2606 for (i = count; i > 0; i--)
2608 /* Access the cave */
2609 c_ptr = &cave[y][x];
2611 /* Extract "info" */
2621 if (++y >= ymax) break;
2627 /*** Run length decoding ***/
2629 /* Load the dungeon data */
2630 for (x = y = 0; y < ymax; )
2636 /* Apply the RLE info */
2637 for (i = count; i > 0; i--)
2639 /* Access the cave */
2640 c_ptr = &cave[y][x];
2642 /* Extract "feat" */
2643 c_ptr->feat = (s16b)tmp8u;
2652 if (++y >= ymax) break;
2657 /*** Run length decoding ***/
2659 /* Load the dungeon data */
2660 for (x = y = 0; y < ymax; )
2666 /* Apply the RLE info */
2667 for (i = count; i > 0; i--)
2669 /* Access the cave */
2670 c_ptr = &cave[y][x];
2672 /* Extract "mimic" */
2673 c_ptr->mimic = (s16b)tmp8u;
2682 if (++y >= ymax) break;
2687 /*** Run length decoding ***/
2689 /* Load the dungeon data */
2690 for (x = y = 0; y < ymax; )
2696 /* Apply the RLE info */
2697 for (i = count; i > 0; i--)
2699 /* Access the cave */
2700 c_ptr = &cave[y][x];
2702 /* Extract "feat" */
2703 c_ptr->special = tmp16s;
2712 if (++y >= ymax) break;
2717 /* Convert cave data */
2718 if (z_older_than(11, 0, 99))
2720 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2722 /* Wipe old unused flags */
2723 cave[y][x].info &= ~(CAVE_MASK);
2727 if (h_older_than(1, 1, 1, 0))
2729 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2731 /* Access the cave */
2732 c_ptr = &cave[y][x];
2735 if (c_ptr->feat == OLD_FEAT_INVIS)
2737 c_ptr->feat = feat_floor;
2738 c_ptr->info |= CAVE_TRAP;
2741 /* Older than 1.1.1 */
2742 if (c_ptr->feat == OLD_FEAT_MIRROR)
2744 c_ptr->feat = feat_floor;
2745 c_ptr->info |= CAVE_OBJECT;
2750 if (h_older_than(1, 3, 1, 0))
2752 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2754 /* Access the cave */
2755 c_ptr = &cave[y][x];
2757 /* Old CAVE_IN_MIRROR flag */
2758 if (c_ptr->info & CAVE_OBJECT)
2760 c_ptr->mimic = feat_mirror;
2763 /* Runes will be mimics and flags */
2764 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2765 (c_ptr->feat == OLD_FEAT_GLYPH))
2767 c_ptr->info |= CAVE_OBJECT;
2768 c_ptr->mimic = c_ptr->feat;
2769 c_ptr->feat = feat_floor;
2772 /* Hidden traps will be trap terrains mimicing floor */
2773 else if (c_ptr->info & CAVE_TRAP)
2775 c_ptr->info &= ~CAVE_TRAP;
2776 c_ptr->mimic = c_ptr->feat;
2777 c_ptr->feat = choose_random_trap();
2780 /* Another hidden trap */
2781 else if (c_ptr->feat == OLD_FEAT_INVIS)
2783 c_ptr->mimic = feat_floor;
2784 c_ptr->feat = feat_trap_open;
2789 /* Quest 18 was removed */
2790 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2792 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2794 /* Access the cave */
2795 c_ptr = &cave[y][x];
2797 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2799 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2801 c_ptr->feat = feat_tree;
2804 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2806 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2809 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2810 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2812 c_ptr->feat = feat_up_stair;
2820 /* Read the item count */
2823 /* Verify maximum */
2824 if (limit > max_o_idx)
2826 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2830 /* Read the dungeon items */
2831 for (i = 1; i < limit; i++)
2838 /* Get a new record */
2844 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2850 o_ptr = &o_list[o_idx];
2856 /* XXX XXX XXX XXX XXX */
2859 if (o_ptr->held_m_idx)
2861 monster_type *m_ptr;
2864 m_ptr = &m_list[o_ptr->held_m_idx];
2867 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2869 /* Place the object */
2870 m_ptr->hold_o_idx = o_idx;
2876 /* Access the item location */
2877 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2880 o_ptr->next_o_idx = c_ptr->o_idx;
2882 /* Place the object */
2883 c_ptr->o_idx = o_idx;
2890 /* Read the monster count */
2893 /* Hack -- verify */
2894 if (limit > max_m_idx)
2896 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2900 /* Read the monsters */
2901 for (i = 1; i < limit; i++)
2904 monster_type *m_ptr;
2906 /* Get a new record */
2912 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2917 /* Acquire monster */
2918 m_ptr = &m_list[m_idx];
2920 /* Read the monster */
2925 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2927 /* Mark the location */
2928 c_ptr->m_idx = m_idx;
2931 real_r_ptr(m_ptr)->cur_num++;
2936 /* The dungeon is ready */
2937 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2938 character_dungeon = FALSE;
2940 character_dungeon = TRUE;
2948 * @brief 保存されたフロアを読み込む / Read the saved floor
2951 * The monsters/objects must be loaded in the same order
2952 * that they were stored, since the actual indexes matter.
2954 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2966 cave_template_type *templates;
2969 /*** Wipe all cave ***/
2973 /*** Basic info ***/
2975 /* Dungeon floor specific info follows */
2979 /*** Not a saved floor ***/
2982 dun_level = (DEPTH)tmp16s;
2983 base_level = dun_level;
2987 /*** The saved floor ***/
2990 if (tmp16s != sf_ptr->floor_id) return 171;
2993 if (tmp8u != sf_ptr->savefile_id) return 171;
2996 if (tmp16s != sf_ptr->dun_level) return 171;
2997 dun_level = sf_ptr->dun_level;
3000 if (tmp32s != sf_ptr->last_visit) return 171;
3003 if (tmp32u != sf_ptr->visit_mark) return 171;
3006 if (tmp16s != sf_ptr->upper_floor_id) return 171;
3009 if (tmp16s != sf_ptr->lower_floor_id) return 171;
3013 base_level = (DEPTH)tmp16s;
3014 rd_s16b(&num_repro);
3017 p_ptr->y = (int)tmp16u;
3020 p_ptr->x = (int)tmp16u;
3023 cur_hgt = (POSITION)tmp16s;
3025 cur_wid = (POSITION)tmp16s;
3027 rd_byte(&p_ptr->feeling);
3031 /*** Read template for cave_type ***/
3033 /* Read the template count */
3036 /* Allocate the "template" array */
3037 C_MAKE(templates, limit, cave_template_type);
3039 /* Read the templates */
3040 for (i = 0; i < limit; i++)
3042 cave_template_type *ct_ptr = &templates[i];
3045 rd_u16b(&ct_ptr->info);
3046 if (h_older_than(1, 7, 0, 2))
3049 ct_ptr->feat = (s16b)tmp8u;
3051 ct_ptr->mimic = (s16b)tmp8u;
3055 rd_s16b(&ct_ptr->feat);
3056 rd_s16b(&ct_ptr->mimic);
3058 rd_s16b(&ct_ptr->special);
3066 /*** Run length decoding ***/
3068 /* Load the dungeon data */
3069 for (x = y = 0; y < ymax; )
3081 } while (tmp8u == MAX_UCHAR);
3083 /* Apply the RLE info */
3084 for (i = count; i > 0; i--)
3086 /* Access the cave */
3087 cave_type *c_ptr = &cave[y][x];
3089 /* Extract cave data */
3090 c_ptr->info = templates[id].info;
3091 c_ptr->feat = templates[id].feat;
3092 c_ptr->mimic = templates[id].mimic;
3093 c_ptr->special = templates[id].special;
3102 if (++y >= ymax) break;
3107 /* Quest 18 was removed */
3108 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3110 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3112 /* Access the cave */
3113 cave_type *c_ptr = &cave[y][x];
3115 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
3117 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
3119 c_ptr->feat = feat_tree;
3122 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
3124 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3127 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3128 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3130 c_ptr->feat = feat_up_stair;
3136 /* Free the "template" array */
3137 C_KILL(templates, limit, cave_template_type);
3142 /* Read the item count */
3145 /* Verify maximum */
3146 if (limit > max_o_idx) return 151;
3149 /* Read the dungeon items */
3150 for (i = 1; i < limit; i++)
3156 /* Get a new record */
3160 if (i != o_idx) return 152;
3163 o_ptr = &o_list[o_idx];
3170 if (o_ptr->held_m_idx)
3172 monster_type *m_ptr;
3175 m_ptr = &m_list[o_ptr->held_m_idx];
3178 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3180 /* Place the object */
3181 m_ptr->hold_o_idx = o_idx;
3187 /* Access the item location */
3188 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3191 o_ptr->next_o_idx = c_ptr->o_idx;
3193 /* Place the object */
3194 c_ptr->o_idx = o_idx;
3201 /* Read the monster count */
3204 /* Hack -- verify */
3205 if (limit > max_m_idx) return 161;
3207 /* Read the monsters */
3208 for (i = 1; i < limit; i++)
3212 monster_type *m_ptr;
3214 /* Get a new record */
3218 if (i != m_idx) return 162;
3221 /* Acquire monster */
3222 m_ptr = &m_list[m_idx];
3224 /* Read the monster */
3229 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3231 /* Mark the location */
3232 c_ptr->m_idx = m_idx;
3235 real_r_ptr(m_ptr)->cur_num++;
3244 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3247 * The monsters/objects must be loaded in the same order
3248 * that they were stored, since the actual indexes matter.
3250 static errr rd_dungeon(void)
3258 /* Initialize saved_floors array and temporal files */
3259 init_saved_floors(FALSE);
3262 if (h_older_than(1, 5, 0, 0))
3264 err = rd_dungeon_old();
3266 /* Prepare floor_id of current floor */
3269 p_ptr->floor_id = get_new_floor_id();
3270 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3279 /* Number of floor_id used from birth */
3280 rd_s16b(&max_floor_id);
3282 /* Current dungeon type */
3284 dungeon_type = (DUNGEON_IDX)tmp8u;
3286 /* Number of the saved_floors array elements */
3289 /*** No saved floor (On the surface etc.) ***/
3292 /* Read the current floor data */
3293 err = rd_saved_floor(NULL);
3296 /*** In the dungeon ***/
3300 /* Read the saved_floors array */
3301 for (i = 0; i < num; i++)
3303 saved_floor_type *sf_ptr = &saved_floors[i];
3305 rd_s16b(&sf_ptr->floor_id);
3306 rd_byte(&sf_ptr->savefile_id);
3309 sf_ptr->dun_level = (DEPTH)tmp16s;
3311 rd_s32b(&sf_ptr->last_visit);
3312 rd_u32b(&sf_ptr->visit_mark);
3313 rd_s16b(&sf_ptr->upper_floor_id);
3314 rd_s16b(&sf_ptr->lower_floor_id);
3318 /* Move saved floors data to temporal files */
3319 for (i = 0; i < num; i++)
3321 saved_floor_type *sf_ptr = &saved_floors[i];
3323 /* Unused element */
3324 if (!sf_ptr->floor_id) continue;
3326 /* Read the failure mark */
3328 if (tmp8u) continue;
3330 /* Read from the save file */
3331 err = rd_saved_floor(sf_ptr);
3336 /* Re-save as temporal saved floor file */
3337 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3343 /* Finally load current floor data from temporal file */
3346 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3351 /*** Error messages ***/
3355 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3359 note(_("アイテム配置エラー", "Object allocation error"));
3363 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3367 note(_("モンスター配置エラー", "Monster allocation error"));
3371 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3375 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3379 note(_("Error 183", "Error 183"));
3383 /* The dungeon is ready */
3384 character_dungeon = TRUE;
3386 /* Success or Error */
3392 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3395 static errr rd_savefile_new_aux(void)
3408 #ifdef VERIFY_CHECKSUMS
3409 u32b n_x_check, n_v_check;
3410 u32b o_x_check, o_v_check;
3414 /* Strip the version bytes */
3417 /* Hack -- decrypt */
3418 xor_byte = sf_extra;
3421 /* Clear the checksums */
3425 /* Read the version number of the savefile */
3426 /* Old savefile will be version 0.0.0.3 */
3427 rd_byte(&h_ver_extra);
3428 rd_byte(&h_ver_patch);
3429 rd_byte(&h_ver_minor);
3430 rd_byte(&h_ver_major);
3432 /* Mention the savefile version */
3434 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3435 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3438 /* Operating system info */
3439 rd_u32b(&sf_system);
3441 /* Time of savefile creation */
3444 /* Number of resurrections */
3447 /* Number of times played */
3451 /* Later use (always zero) */
3454 /* Later use (always zero) */
3457 /* Later use (always zero) */
3461 rd_byte(&kanji_code);
3463 /* Read RNG state */
3465 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3467 /* Then the options */
3469 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3471 /* Then the "messages" */
3473 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3475 for (i = 0; i < max_r_idx; i++)
3477 /* Access that monster */
3478 monster_race *r_ptr = &r_info[i];
3480 /* Hack -- Reset the death counter */
3481 r_ptr->max_num = 100;
3483 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3485 /* Hack -- Non-unique Nazguls are semi-unique */
3486 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3489 /* Monster Memory */
3492 /* Incompatible save files */
3493 if (tmp16u > max_r_idx)
3495 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3499 /* Read the available records */
3500 for (i = 0; i < tmp16u; i++)
3503 rd_lore((MONRACE_IDX)i);
3506 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3511 /* Incompatible save files */
3512 if (tmp16u > max_k_idx)
3514 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3518 /* Read the object memory */
3519 for (i = 0; i < tmp16u; i++)
3521 object_kind *k_ptr = &k_info[i];
3525 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3526 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3528 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3530 /* 2.1.3 or newer version */
3532 u16b max_towns_load;
3533 u16b max_quests_load;
3534 byte max_rquests_load;
3535 s16b old_inside_quest = p_ptr->inside_quest;
3537 /* Number of towns */
3538 rd_u16b(&max_towns_load);
3540 /* Incompatible save files */
3541 if (max_towns_load > max_towns)
3543 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3547 /* Number of quests */
3548 rd_u16b(&max_quests_load);
3550 if (z_older_than(11, 0, 7))
3552 max_rquests_load = 10;
3556 rd_byte(&max_rquests_load);
3559 /* Incompatible save files */
3560 if (max_quests_load > max_quests)
3562 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3566 for (i = 0; i < max_quests_load; i++)
3570 quest_type* const q_ptr = &quest[i];
3572 rd_s16b(&q_ptr->status);
3574 q_ptr->level = tmp16s;
3576 if (z_older_than(11, 0, 6))
3582 rd_byte(&q_ptr->complev);
3584 if(h_older_than(2, 1, 2, 2))
3586 q_ptr->comptime = 0;
3590 rd_u32b(&q_ptr->comptime);
3593 /* Load quest status if quest is running */
3594 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3595 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3596 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3599 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3601 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3602 rd_s16b(&q_ptr->type);
3604 /* Load quest monster index */
3605 rd_s16b(&q_ptr->r_idx);
3607 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3609 determine_random_questor(&quest[i]);
3612 /* Load quest item index */
3613 rd_s16b(&q_ptr->k_idx);
3616 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3618 rd_byte(&q_ptr->flags);
3620 if (z_older_than(10, 3, 11))
3622 if (q_ptr->flags & QUEST_FLAG_PRESET)
3628 init_flags = INIT_ASSIGN;
3629 p_ptr->inside_quest = (QUEST_IDX)i;
3631 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3632 p_ptr->inside_quest = old_inside_quest;
3637 rd_byte(&q_ptr->dungeon);
3640 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3641 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3642 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3645 /* Ignore the empty quests from old versions */
3648 /* Ignore quest status */
3651 /* Ignore quest level */
3655 * We don't have to care about the other info,
3656 * since status should be 0 for these quests anyway
3661 /* Quest 18 was removed */
3662 if (h_older_than(1, 7, 0, 6))
3664 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3665 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3668 /* Position in the wilderness */
3669 rd_s32b(&p_ptr->wilderness_x);
3670 rd_s32b(&p_ptr->wilderness_y);
3671 if (z_older_than(10, 3, 13))
3673 p_ptr->wilderness_x = 5;
3674 p_ptr->wilderness_y = 48;
3677 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3678 else rd_byte((byte *)&p_ptr->wild_mode);
3679 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3680 else rd_byte((byte *)&ambush_flag);
3682 /* Size of the wilderness */
3683 rd_s32b(&wild_x_size);
3684 rd_s32b(&wild_y_size);
3686 /* Incompatible save files */
3687 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3689 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3693 /* Load the wilderness seeds */
3694 for (i = 0; i < wild_x_size; i++)
3696 for (j = 0; j < wild_y_size; j++)
3698 rd_u32b(&wilderness[j][i].seed);
3703 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3705 /* Load the Artifacts */
3708 /* Incompatible save files */
3709 if (tmp16u > max_a_idx)
3711 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3715 /* Read the artifact flags */
3716 for (i = 0; i < tmp16u; i++)
3718 artifact_type *a_ptr = &a_info[i];
3721 a_ptr->cur_num = tmp8u;
3723 if (h_older_than(1, 5, 0, 0))
3725 a_ptr->floor_id = 0;
3733 rd_s16b(&a_ptr->floor_id);
3736 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3738 /* Read the extra stuff */
3740 if (p_ptr->energy_need < -999) world_player = TRUE;
3742 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3745 /* Read the player_hp array */
3748 /* Incompatible save files */
3749 if (tmp16u > PY_MAX_LEVEL)
3751 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3755 /* Read the player_hp array */
3756 for (i = 0; i < tmp16u; i++)
3759 p_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3762 /* Important -- Initialize the sex */
3763 sp_ptr = &sex_info[p_ptr->psex];
3765 /* Important -- Initialize the race/class */
3766 rp_ptr = &race_info[p_ptr->prace];
3767 cp_ptr = &class_info[p_ptr->pclass];
3768 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3770 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3772 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3773 do_cmd_rerate(FALSE);
3775 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3777 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3778 do_cmd_rerate(FALSE);
3780 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3782 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3783 do_cmd_rerate(FALSE);
3785 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3787 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3788 do_cmd_rerate(FALSE);
3791 /* Important -- Initialize the magic */
3792 mp_ptr = &m_info[p_ptr->pclass];
3795 /* Read spell info */
3796 rd_u32b(&p_ptr->spell_learned1);
3797 rd_u32b(&p_ptr->spell_learned2);
3798 rd_u32b(&p_ptr->spell_worked1);
3799 rd_u32b(&p_ptr->spell_worked2);
3800 rd_u32b(&p_ptr->spell_forgotten1);
3801 rd_u32b(&p_ptr->spell_forgotten2);
3803 if (z_older_than(10,0,5))
3805 p_ptr->learned_spells = 0;
3806 for (i = 0; i < 64; i++)
3808 /* Count known spells */
3810 (p_ptr->spell_learned1 & (1L << i)) :
3811 (p_ptr->spell_learned2 & (1L << (i - 32))))
3813 p_ptr->learned_spells++;
3817 else rd_s16b(&p_ptr->learned_spells);
3819 if (z_older_than(10,0,6))
3821 p_ptr->add_spells = 0;
3823 else rd_s16b(&p_ptr->add_spells);
3824 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3826 for (i = 0; i < 64; i++)
3829 p_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3833 /* Read the inventory */
3836 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3840 /* Read number of towns */
3842 town_count = tmp16u;
3844 /* Read the stores */
3846 for (i = 1; i < town_count; i++)
3848 for (j = 0; j < tmp16u; j++)
3850 if (rd_store(i, j)) return (22);
3854 rd_s16b(&p_ptr->pet_follow_distance);
3855 if (z_older_than(10, 4, 10))
3857 p_ptr->pet_extra_flags = 0;
3859 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3861 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3863 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3867 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3870 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3874 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3877 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3881 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3884 if (!z_older_than(10,0,8))
3887 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3892 rd_s16b(&p_ptr->pet_extra_flags);
3895 if (!z_older_than(11, 0, 9))
3897 char buf[SCREEN_BUF_SIZE];
3898 rd_string(buf, sizeof(buf));
3899 if (buf[0]) screen_dump = string_make(buf);
3904 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3906 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3911 /* I'm not dead yet... */
3912 if (!p_ptr->is_dead)
3914 /* Dead players have no dungeon */
3915 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3919 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3923 /* Read the ghost info */
3930 strip_bytes(tmp32s);
3934 /* Quest 18 was removed */
3935 if (h_older_than(1, 7, 0, 6))
3937 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3939 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3941 p_ptr->inside_quest = 0;
3946 #ifdef VERIFY_CHECKSUMS
3948 /* Save the checksum */
3949 n_v_check = v_check;
3951 /* Read the old checksum */
3952 rd_u32b(&o_v_check);
3955 if (o_v_check != n_v_check)
3957 note(_("チェックサムがおかしい", "Invalid checksum"));
3962 /* Save the encoded checksum */
3963 n_x_check = x_check;
3965 /* Read the checksum */
3966 rd_u32b(&o_x_check);
3970 if (o_x_check != n_x_check)
3972 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3983 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3986 errr rd_savefile_new(void)
3990 /* Grab permissions */
3993 /* The savefile is a binary file */
3994 fff = my_fopen(savefile, "rb");
3996 /* Drop permissions */
4000 if (!fff) return (-1);
4002 /* Call the sub-function */
4003 err = rd_savefile_new_aux();
4005 /* Check for errors */
4006 if (ferror(fff)) err = -1;
4008 /* Close the file */
4017 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
4018 * @param sf_ptr 保存フロア読み込み先
4021 static bool load_floor_aux(saved_floor_type *sf_ptr)
4026 #ifdef VERIFY_CHECKSUMS
4027 u32b n_x_check, n_v_check;
4028 u32b o_x_check, o_v_check;
4031 /* Hack -- decrypt (read xor_byte) */
4035 /* Clear the checksums */
4039 /* Set the version number to current version */
4040 /* Never load old temporal files */
4041 h_ver_extra = H_VER_EXTRA;
4042 h_ver_patch = H_VER_PATCH;
4043 h_ver_minor = H_VER_MINOR;
4044 h_ver_major = H_VER_MAJOR;
4046 /* Verify the sign */
4048 if (saved_floor_file_sign != tmp32u) return FALSE;
4050 /* Read -- have error? */
4051 if (rd_saved_floor(sf_ptr)) return FALSE;
4054 #ifdef VERIFY_CHECKSUMS
4055 /* Save the checksum */
4056 n_v_check = v_check;
4058 /* Read the old checksum */
4059 rd_u32b(&o_v_check);
4062 if (o_v_check != n_v_check) return FALSE;
4064 /* Save the encoded checksum */
4065 n_x_check = x_check;
4067 /* Read the checksum */
4068 rd_u32b(&o_x_check);
4071 if (o_x_check != n_x_check) return FALSE;
4080 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4081 * @param sf_ptr 保存フロア読み込み先
4085 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
4087 FILE *old_fff = NULL;
4088 byte old_xor_byte = 0;
4089 u32b old_v_check = 0;
4090 u32b old_x_check = 0;
4091 byte old_h_ver_major = 0;
4092 byte old_h_ver_minor = 0;
4093 byte old_h_ver_patch = 0;
4094 byte old_h_ver_extra = 0;
4097 char floor_savefile[1024];
4099 byte old_kanji_code = kanji_code;
4102 * Temporal files are always written in system depended kanji
4107 /* EUC kanji code */
4111 /* SJIS kanji code */
4120 /* We have one file already opened */
4121 if (mode & SLF_SECOND)
4123 /* Backup original values */
4125 old_xor_byte = xor_byte;
4126 old_v_check = v_check;
4127 old_x_check = x_check;
4128 old_h_ver_major = h_ver_major;
4129 old_h_ver_minor = h_ver_minor;
4130 old_h_ver_patch = h_ver_patch;
4131 old_h_ver_extra = h_ver_extra;
4134 /* floor savefile */
4135 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4137 /* Grab permissions */
4140 /* The savefile is a binary file */
4141 fff = my_fopen(floor_savefile, "rb");
4143 /* Drop permissions */
4147 if (!fff) ok = FALSE;
4149 /* Attempt to load */
4152 /* Load saved floor data from file */
4153 ok = load_floor_aux(sf_ptr);
4155 /* Check for errors */
4156 if (ferror(fff)) ok = FALSE;
4158 /* Close the file */
4161 /* Grab permissions */
4164 /* Delete the file */
4165 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4167 /* Drop permissions */
4171 /* We have one file already opened */
4172 if (mode & SLF_SECOND)
4174 /* Restore original values */
4176 xor_byte = old_xor_byte;
4177 v_check = old_v_check;
4178 x_check = old_x_check;
4179 h_ver_major = old_h_ver_major;
4180 h_ver_minor = old_h_ver_minor;
4181 h_ver_patch = old_h_ver_patch;
4182 h_ver_extra = old_h_ver_extra;
4185 /* Restore old knowledge */
4186 kanji_code = old_kanji_code;