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)
821 /* Read the monster race */
822 rd_s16b(&m_ptr->r_idx);
824 if (z_older_than(11, 0, 12))
825 m_ptr->ap_r_idx = m_ptr->r_idx;
827 rd_s16b(&m_ptr->ap_r_idx);
829 if (z_older_than(11, 0, 14))
831 monster_race *r_ptr = &r_info[m_ptr->r_idx];
833 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
834 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
835 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
838 rd_byte(&m_ptr->sub_align);
840 /* Read the other information */
842 m_ptr->fy = (POSITION)tmp8u;
844 m_ptr->fx = (POSITION)tmp8u;
849 m_ptr->maxhp = tmp16s;
851 if (z_older_than(11, 0, 5))
853 m_ptr->max_maxhp = m_ptr->maxhp;
858 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
860 if(h_older_than(2, 1, 2, 1))
862 m_ptr->dealt_damage = 0;
866 rd_u32b(&m_ptr->dealt_damage);
869 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
870 rd_byte(&m_ptr->mspeed);
871 if (z_older_than(10, 4, 2))
874 m_ptr->energy_need = (s16b)tmp8u;
876 else rd_s16b(&m_ptr->energy_need);
878 if (z_older_than(11, 0, 13))
879 m_ptr->energy_need = 100 - m_ptr->energy_need;
881 if (z_older_than(10,0,7))
883 m_ptr->mtimed[MTIMED_FAST] = 0;
884 m_ptr->mtimed[MTIMED_SLOW] = 0;
889 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
891 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
894 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
896 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
898 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
900 if (z_older_than(10,0,10))
904 else if (z_older_than(10,0,11))
912 m_ptr->target_y = (POSITION)tmp16s;
914 m_ptr->target_x = (POSITION)tmp16s;
918 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
920 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
921 rd_u32b(&m_ptr->smart);
925 if (z_older_than(10, 4, 5))
928 rd_u32b(&m_ptr->exp);
930 if (z_older_than(10, 2, 2))
932 if (m_ptr->r_idx < 0)
934 m_ptr->r_idx = (0-m_ptr->r_idx);
935 m_ptr->mflag2 |= MFLAG2_KAGE;
940 rd_byte(&m_ptr->mflag2);
943 if (z_older_than(11, 0, 12))
945 if (m_ptr->mflag2 & MFLAG2_KAGE)
946 m_ptr->ap_r_idx = MON_KAGE;
949 if (z_older_than(10, 1, 3))
955 rd_string(buf, sizeof(buf));
956 if (buf[0]) m_ptr->nickname = quark_add(buf);
964 * @brief モンスターを読み込む(現版) / Read a monster (New method)
965 * @param m_ptr モンスター保存先ポインタ
968 static void rd_monster(monster_type *m_ptr)
975 if (h_older_than(1, 5, 0, 0))
977 rd_monster_old(m_ptr);
981 /*** Monster save flags ***/
984 /*** Read un-obvious elements ***/
986 /* Read the monster race */
987 rd_s16b(&m_ptr->r_idx);
989 /* Read the other information */
991 m_ptr->fy = (POSITION)tmp8u;
993 m_ptr->fx = (POSITION)tmp8u;
996 m_ptr->hp = (HIT_POINT)tmp16s;
998 m_ptr->maxhp = (HIT_POINT)tmp16s;
1000 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1002 if(h_older_than(2, 1, 2, 1))
1004 m_ptr->dealt_damage = 0;
1008 rd_u32b(&m_ptr->dealt_damage);
1011 /* Monster race index of its appearance */
1012 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1013 else m_ptr->ap_r_idx = m_ptr->r_idx;
1015 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1016 else m_ptr->sub_align = 0;
1018 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1019 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1021 rd_byte(&m_ptr->mspeed);
1023 rd_s16b(&m_ptr->energy_need);
1025 if (flags & SAVE_MON_FAST)
1028 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1030 else m_ptr->mtimed[MTIMED_FAST] = 0;
1031 if (flags & SAVE_MON_SLOW)
1034 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1036 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1037 if (flags & SAVE_MON_STUNNED)
1040 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1042 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1043 if (flags & SAVE_MON_CONFUSED)
1046 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1048 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1049 if (flags & SAVE_MON_MONFEAR)
1052 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1054 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1056 if (flags & SAVE_MON_TARGET_Y)
1059 m_ptr->target_y = (POSITION)tmp16s;
1061 else m_ptr->target_y = 0;
1062 if (flags & SAVE_MON_TARGET_X)
1065 m_ptr->target_x = (POSITION)tmp16s;
1067 else m_ptr->target_x = 0;
1069 if (flags & SAVE_MON_INVULNER)
1072 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1074 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1076 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1077 else m_ptr->smart = 0;
1079 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
1080 else m_ptr->exp = 0;
1082 m_ptr->mflag = 0; /* Not saved */
1084 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1085 else m_ptr->mflag2 = 0;
1087 if (flags & SAVE_MON_NICKNAME)
1089 rd_string(buf, sizeof(buf));
1090 m_ptr->nickname = quark_add(buf);
1092 else m_ptr->nickname = 0;
1094 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1095 else m_ptr->parent_m_idx = 0;
1100 * Old monster bit flags of racial resistances
1102 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1103 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1104 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1105 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1106 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1107 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1108 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1109 #define RF3_RES_WATE 0x00800000 /* Resist water */
1110 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1111 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1112 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1113 #define RF3_RES_ALL 0x08000000 /* Resist all */
1115 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1117 if ((R_PTR)->r_flags3 & (RF3)) \
1119 (R_PTR)->r_flags3 &= ~(RF3); \
1120 (R_PTR)->r_flagsr |= (RFR); \
1124 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1126 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1128 (R_PTR)->r_flagsr |= (RFR); \
1132 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1133 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1134 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1135 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1136 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1137 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1138 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1139 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1140 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1141 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1144 * @brief モンスターの思い出を読み込む / Read the monster lore
1145 * @param r_idx 読み込み先モンスターID
1148 static void rd_lore(IDX r_idx)
1152 monster_race *r_ptr = &r_info[r_idx];
1154 /* Count sights/deaths/kills */
1155 rd_s16b(&r_ptr->r_sights);
1156 rd_s16b(&r_ptr->r_deaths);
1157 rd_s16b(&r_ptr->r_pkills);
1158 if (h_older_than(1, 7, 0, 5))
1160 r_ptr->r_akills = r_ptr->r_pkills;
1164 rd_s16b(&r_ptr->r_akills);
1166 rd_s16b(&r_ptr->r_tkills);
1168 /* Count wakes and ignores */
1169 rd_byte(&r_ptr->r_wake);
1170 rd_byte(&r_ptr->r_ignore);
1173 rd_byte(&r_ptr->r_xtra1);
1174 rd_byte(&r_ptr->r_xtra2);
1177 rd_byte(&r_ptr->r_drop_gold);
1178 rd_byte(&r_ptr->r_drop_item);
1182 rd_byte(&r_ptr->r_cast_spell);
1184 /* Count blows of each type */
1185 rd_byte(&r_ptr->r_blows[0]);
1186 rd_byte(&r_ptr->r_blows[1]);
1187 rd_byte(&r_ptr->r_blows[2]);
1188 rd_byte(&r_ptr->r_blows[3]);
1190 /* Memorize flags */
1191 rd_u32b(&r_ptr->r_flags1);
1192 rd_u32b(&r_ptr->r_flags2);
1193 rd_u32b(&r_ptr->r_flags3);
1194 rd_u32b(&r_ptr->r_flags4);
1195 rd_u32b(&r_ptr->r_flags5);
1196 rd_u32b(&r_ptr->r_flags6);
1197 if (h_older_than(1, 5, 0, 3))
1199 r_ptr->r_flagsr = 0L;
1201 /* Move RF3 resistance flags to RFR */
1202 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1203 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1204 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1205 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1206 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1207 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1208 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1209 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1210 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1211 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1212 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1213 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1215 /* Separate breathers resistance from RF4 to RFR */
1216 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1217 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1218 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1219 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1220 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1221 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1222 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1223 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1224 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1226 /* Resist confusion is merged to RF3_NO_CONF */
1227 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1229 /* Misc resistance hack to RFR */
1230 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1231 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1235 rd_u32b(&r_ptr->r_flagsr);
1238 /* Read the "Racial" monster limit per level */
1239 rd_byte(&r_ptr->max_num);
1241 /* Location in saved floor */
1242 rd_s16b(&r_ptr->floor_id);
1247 /* Repair the lore flags */
1248 r_ptr->r_flags1 &= r_ptr->flags1;
1249 r_ptr->r_flags2 &= r_ptr->flags2;
1250 r_ptr->r_flags3 &= r_ptr->flags3;
1251 r_ptr->r_flags4 &= r_ptr->flags4;
1252 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1253 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1254 r_ptr->r_flagsr &= r_ptr->flagsr;
1258 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1259 * @param st_ptr 店舗の参照ポインタ
1260 * @param o_ptr アイテムオブジェクト参照ポインタ
1263 * In all cases, return the slot (or -1) where the object was placed
1265 * Note that this is a hacked up version of "inven_carry()".
1267 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1268 * known, the player may have to pick stuff up and drop it again.
1270 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1278 /* Check each existing item (try to combine) */
1279 for (slot = 0; slot < st_ptr->stock_num; slot++)
1281 /* Get the existing item */
1282 j_ptr = &st_ptr->stock[slot];
1284 /* The home acts just like the player */
1285 if (object_similar(j_ptr, o_ptr))
1287 /* Save the new number of items */
1288 object_absorb(j_ptr, o_ptr);
1296 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1300 /* Determine the "value" of the item */
1301 value = object_value(o_ptr);
1303 /* Check existing slots to see if we must "slide" */
1304 for (slot = 0; slot < st_ptr->stock_num; slot++)
1306 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1309 /* Slide the others up */
1310 for (i = st_ptr->stock_num; i > slot; i--)
1312 st_ptr->stock[i] = st_ptr->stock[i-1];
1315 /* More stuff now */
1316 st_ptr->stock_num++;
1318 /* Insert the new item */
1319 st_ptr->stock[slot] = *o_ptr;
1321 chg_virtue(V_SACRIFICE, -1);
1323 /* Return the location */
1328 * @brief 店舗情報を読み込む / Read a store
1329 * @param town_number 街ID
1330 * @param store_number 店舗ID
1333 static errr rd_store(int town_number, int store_number)
1345 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1347 st_ptr = &town[1].store[store_number];
1348 if (st_ptr->stock_num) sort = TRUE;
1352 st_ptr = &town[town_number].store[store_number];
1355 /* Read the basic info */
1356 rd_s32b(&st_ptr->store_open);
1357 rd_s16b(&st_ptr->insult_cur);
1359 if (z_older_than(11, 0, 4))
1368 rd_s16b(&st_ptr->good_buy);
1369 rd_s16b(&st_ptr->bad_buy);
1371 /* Read last visit */
1372 rd_s32b(&st_ptr->last_visit);
1374 /* Extract the owner (see above) */
1375 st_ptr->owner = own;
1377 /* Read the items */
1378 for (j = 0; j < num; j++)
1383 /* Get local object */
1386 /* Wipe the object */
1392 /* Acquire valid items */
1393 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1398 home_carry(st_ptr, q_ptr);
1402 k = st_ptr->stock_num++;
1404 /* Acquire the item */
1405 object_copy(&st_ptr->stock[k], q_ptr);
1416 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1419 static void rd_randomizer(void)
1429 rd_u16b(&Rand_place);
1432 for (i = 0; i < RAND_DEG; i++)
1434 rd_u32b(&Rand_state[i]);
1441 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1444 * Note that the normal options are now stored as a set of 256 bit flags,
1445 * plus a set of 256 bit masks to indicate which bit flags were defined
1446 * at the time the savefile was created. This will allow new options
1447 * to be added, and old options to be removed, at any time, without
1448 * hurting old savefiles.
1450 * The window options are stored in the same way, but note that each
1451 * window gets 32 options, and their order is fixed by certain defines.
1453 static void rd_options(void)
1467 /* Ignore old options */
1471 /*** Special info */
1473 /* Read "delay_factor" */
1477 /* Read "hitpoint_warn" */
1481 /* Read "mana_warn" */
1482 if(h_older_than(1, 7, 0, 0))
1493 /*** Cheating options ***/
1497 if (c & 0x0002) p_ptr->wizard = TRUE;
1499 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1500 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1501 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1502 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1503 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1504 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1505 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1506 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1507 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1509 rd_byte((byte *)&autosave_l);
1510 rd_byte((byte *)&autosave_t);
1511 rd_s16b(&autosave_freq);
1514 /*** Normal Options ***/
1516 /* Read the option flags */
1517 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1519 /* Read the option masks */
1520 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1522 /* Analyze the options */
1523 for (n = 0; n < 8; n++)
1525 /* Analyze the options */
1526 for (i = 0; i < 32; i++)
1528 /* Process valid flags */
1529 if (mask[n] & (1L << i))
1531 /* Process valid flags */
1532 if (option_mask[n] & (1L << i))
1535 if (flag[n] & (1L << i))
1538 option_flag[n] |= (1L << i);
1545 option_flag[n] &= ~(1L << i);
1552 if (z_older_than(10, 4, 5))
1554 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1555 else option_flag[5] |= (0x00000001 << 4);
1556 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1557 else option_flag[2] |= (0x00000001 << 5);
1558 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1559 else option_flag[4] |= (0x00000001 << 5);
1560 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1561 else option_flag[5] |= (0x00000001 << 0);
1562 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1563 else option_flag[5] |= (0x00000001 << 12);
1564 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1565 else option_flag[1] |= (0x00000001 << 0);
1566 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1567 else option_flag[1] |= (0x00000001 << 18);
1568 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1569 else option_flag[1] |= (0x00000001 << 19);
1570 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1571 else option_flag[5] |= (0x00000001 << 3);
1574 /* Extract the options */
1575 extract_option_vars();
1578 /*** Window Options ***/
1580 /* Read the window flags */
1581 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1583 /* Read the window masks */
1584 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1586 /* Analyze the options */
1587 for (n = 0; n < 8; n++)
1589 /* Analyze the options */
1590 for (i = 0; i < 32; i++)
1592 /* Process valid flags */
1593 if (mask[n] & (1L << i))
1595 /* Process valid flags */
1596 if (window_mask[n] & (1L << i))
1599 if (flag[n] & (1L << i))
1602 window_flag[n] |= (1L << i);
1609 window_flag[n] &= ~(1L << i);
1620 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1623 * XXX XXX XXX This is such a nasty hack it hurts.
1625 static void rd_ghost(void)
1630 rd_string(buf, sizeof(buf));
1632 /* Strip old data */
1638 * @brief クイックスタート情報を読み込む / Load quick start data
1641 static void load_quick_start(void)
1646 if (z_older_than(11, 0, 13))
1648 previous_char.quick_ok = FALSE;
1652 rd_byte(&previous_char.psex);
1653 rd_byte(&previous_char.prace);
1654 rd_byte(&previous_char.pclass);
1655 rd_byte(&previous_char.pseikaku);
1656 rd_byte(&previous_char.realm1);
1657 rd_byte(&previous_char.realm2);
1659 rd_s16b(&previous_char.age);
1660 rd_s16b(&previous_char.ht);
1661 rd_s16b(&previous_char.wt);
1662 rd_s16b(&previous_char.sc);
1663 rd_s32b(&previous_char.au);
1665 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1666 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1668 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1670 rd_s16b(&previous_char.chaos_patron);
1672 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1674 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1676 /* UNUSED : Was number of random quests */
1680 previous_char.quick_ok = (bool)tmp8u;
1684 * @brief その他の情報を読み込む / Read the "extra" information
1687 static void rd_extra(void)
1696 rd_string(p_ptr->name, sizeof(p_ptr->name));
1698 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1700 if (!h_older_than(1, 7, 0, 1))
1704 /* Read the message */
1705 rd_string(buf, sizeof buf);
1706 if (buf[0]) p_ptr->last_message = string_make(buf);
1711 for (i = 0; i < 4; i++)
1713 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1716 /* Class/Race/Seikaku/Gender/Spells */
1717 rd_byte(&p_ptr->prace);
1718 rd_byte(&p_ptr->pclass);
1719 rd_byte(&p_ptr->pseikaku);
1720 rd_byte(&p_ptr->psex);
1721 rd_byte(&p_ptr->realm1);
1722 rd_byte(&p_ptr->realm2);
1723 rd_byte(&tmp8u); /* oops */
1725 if (z_older_than(10, 4, 4))
1727 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1728 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1729 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1730 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1733 /* Special Race/Class info */
1735 p_ptr->hitdie = tmp8u;
1736 rd_u16b(&p_ptr->expfact);
1738 /* Age/Height/Weight */
1739 rd_s16b(&p_ptr->age);
1740 rd_s16b(&p_ptr->ht);
1741 rd_s16b(&p_ptr->wt);
1743 /* Read the stat info */
1744 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1745 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1746 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1748 strip_bytes(24); /* oops */
1750 rd_s32b(&p_ptr->au);
1752 rd_s32b(&p_ptr->max_exp);
1753 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1754 else rd_s32b(&p_ptr->max_max_exp);
1755 rd_s32b(&p_ptr->exp);
1757 if (h_older_than(1, 7, 0, 3))
1760 p_ptr->exp_frac = (u32b)tmp16u;
1764 rd_u32b(&p_ptr->exp_frac);
1767 rd_s16b(&p_ptr->lev);
1769 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1770 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1772 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1774 if (z_older_than(10, 3, 6))
1775 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1777 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1778 for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1779 if (z_older_than(10, 4, 1))
1781 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1782 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1784 if (z_older_than(10, 3, 14))
1786 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1787 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1791 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1792 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1793 if (h_older_than(1, 3, 0, 1))
1795 if (p_ptr->pclass == CLASS_SMITH)
1797 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1798 p_ptr->magic_num1[96] = 0;
1799 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1800 p_ptr->magic_num1[97] = 0;
1804 if (music_singing_any()) p_ptr->action = ACTION_SING;
1806 if (z_older_than(11, 0, 7))
1808 p_ptr->start_race = p_ptr->prace;
1809 p_ptr->old_race1 = 0L;
1810 p_ptr->old_race2 = 0L;
1811 p_ptr->old_realm = 0;
1815 rd_byte(&p_ptr->start_race);
1817 p_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1819 p_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1820 rd_s16b(&p_ptr->old_realm);
1823 if (z_older_than(10, 0, 1))
1825 for (i = 0; i < MAX_MANE; i++)
1827 p_ptr->mane_spell[i] = -1;
1828 p_ptr->mane_dam[i] = 0;
1830 p_ptr->mane_num = 0;
1832 else if (z_older_than(10, 2, 3))
1834 for (i = 0; i < OLD_MAX_MANE; i++)
1839 for (i = 0; i < MAX_MANE; i++)
1841 p_ptr->mane_spell[i] = -1;
1842 p_ptr->mane_dam[i] = 0;
1845 p_ptr->mane_num = 0;
1849 for (i = 0; i < MAX_MANE; i++)
1851 rd_s16b(&p_ptr->mane_spell[i]);
1852 rd_s16b(&p_ptr->mane_dam[i]);
1854 rd_s16b(&p_ptr->mane_num);
1857 if (z_older_than(10, 0, 3))
1859 determine_bounty_uniques();
1861 for (i = 0; i < MAX_KUBI; i++)
1863 /* Is this bounty unique already dead? */
1864 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1869 for (i = 0; i < MAX_KUBI; i++)
1871 rd_s16b(&kubi_r_idx[i]);
1875 if (z_older_than(10, 0, 3))
1881 for (i = 0; i < 4; i++)
1883 rd_s16b(&battle_mon[i]);
1884 if (z_older_than(10, 3, 4))
1887 mon_odds[i] = tmp16s;
1889 else rd_u32b(&mon_odds[i]);
1893 rd_s16b(&p_ptr->town_num);
1895 /* Read arena and rewards information */
1896 rd_s16b(&p_ptr->arena_number);
1897 if (h_older_than(1, 5, 0, 1))
1899 /* Arena loser of previous version was marked number 99 */
1900 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1903 p_ptr->inside_arena = (bool)tmp16s;
1904 rd_s16b(&p_ptr->inside_quest);
1905 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1909 p_ptr->inside_battle = (bool)tmp16s;
1911 rd_byte(&p_ptr->exit_bldg);
1915 p_ptr->oldpx = (POSITION)tmp16s;
1917 p_ptr->oldpy = (POSITION)tmp16s;
1919 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1921 /* Was p_ptr->rewards[MAX_BACT] */
1923 for (i = 0; i < tmp16s; i++)
1929 if (h_older_than(1, 7, 0, 3))
1932 p_ptr->mhp = tmp16s;
1935 p_ptr->chp = tmp16s;
1938 p_ptr->chp_frac = (u32b)tmp16u;
1942 rd_s32b(&p_ptr->mhp);
1943 rd_s32b(&p_ptr->chp);
1944 rd_u32b(&p_ptr->chp_frac);
1947 if (h_older_than(1, 7, 0, 3))
1950 p_ptr->msp = tmp16s;
1953 p_ptr->csp = tmp16s;
1956 p_ptr->csp_frac = (u32b)tmp16u;
1960 rd_s32b(&p_ptr->msp);
1961 rd_s32b(&p_ptr->csp);
1962 rd_u32b(&p_ptr->csp_frac);
1965 rd_s16b(&p_ptr->max_plv);
1966 if (z_older_than(10, 3, 8))
1969 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1973 byte max = (byte)max_d_idx;
1977 for(i = 0; i < max; i++)
1980 max_dlv[i] = tmp16s;
1981 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1985 /* Repair maximum player level XXX XXX XXX */
1986 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1990 rd_s16b(&p_ptr->sc);
1991 rd_s16b(&p_ptr->concent);
1993 /* Read the flags */
1994 strip_bytes(2); /* Old "rest" */
1995 rd_s16b(&p_ptr->blind);
1996 rd_s16b(&p_ptr->paralyzed);
1997 rd_s16b(&p_ptr->confused);
1998 rd_s16b(&p_ptr->food);
1999 strip_bytes(4); /* Old "food_digested" / "protection" */
2001 rd_s16b(&p_ptr->energy_need);
2002 if (z_older_than(11, 0, 13))
2003 p_ptr->energy_need = 100 - p_ptr->energy_need;
2004 if (h_older_than(2, 1, 2, 0))
2005 p_ptr->enchant_energy_need = 0;
2007 rd_s16b(&p_ptr->enchant_energy_need);
2009 rd_s16b(&p_ptr->fast);
2010 rd_s16b(&p_ptr->slow);
2011 rd_s16b(&p_ptr->afraid);
2012 rd_s16b(&p_ptr->cut);
2013 rd_s16b(&p_ptr->stun);
2014 rd_s16b(&p_ptr->poisoned);
2015 rd_s16b(&p_ptr->image);
2016 rd_s16b(&p_ptr->protevil);
2017 rd_s16b(&p_ptr->invuln);
2018 if(z_older_than(10, 0, 0))
2021 rd_s16b(&p_ptr->ult_res);
2022 rd_s16b(&p_ptr->hero);
2023 rd_s16b(&p_ptr->shero);
2024 rd_s16b(&p_ptr->shield);
2025 rd_s16b(&p_ptr->blessed);
2026 rd_s16b(&p_ptr->tim_invis);
2027 rd_s16b(&p_ptr->word_recall);
2028 if (z_older_than(10, 3, 8))
2029 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2033 p_ptr->recall_dungeon = (byte)tmp16s;
2036 if (h_older_than(1, 5, 0, 0))
2037 p_ptr->alter_reality = 0;
2039 rd_s16b(&p_ptr->alter_reality);
2041 rd_s16b(&p_ptr->see_infra);
2042 rd_s16b(&p_ptr->tim_infra);
2043 rd_s16b(&p_ptr->oppose_fire);
2044 rd_s16b(&p_ptr->oppose_cold);
2045 rd_s16b(&p_ptr->oppose_acid);
2046 rd_s16b(&p_ptr->oppose_elec);
2047 rd_s16b(&p_ptr->oppose_pois);
2048 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2049 else rd_s16b(&p_ptr->tsuyoshi);
2051 /* Old savefiles do not have the following fields... */
2052 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2055 p_ptr->wraith_form = 0;
2056 p_ptr->resist_magic = 0;
2057 p_ptr->tim_regen = 0;
2058 p_ptr->kabenuke = 0;
2059 p_ptr->tim_stealth = 0;
2060 p_ptr->tim_levitation = 0;
2061 p_ptr->tim_sh_touki = 0;
2062 p_ptr->lightspeed = 0;
2063 p_ptr->tsubureru = 0;
2064 p_ptr->tim_res_nether = 0;
2065 p_ptr->tim_res_time = 0;
2066 p_ptr->mimic_form = 0;
2067 p_ptr->tim_mimic = 0;
2068 p_ptr->tim_sh_fire = 0;
2071 p_ptr->tim_reflect = 0;
2072 p_ptr->multishadow = 0;
2073 p_ptr->dustrobe = 0;
2075 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2083 rd_s16b(&p_ptr->tim_esp);
2084 rd_s16b(&p_ptr->wraith_form);
2085 rd_s16b(&p_ptr->resist_magic);
2086 rd_s16b(&p_ptr->tim_regen);
2087 rd_s16b(&p_ptr->kabenuke);
2088 rd_s16b(&p_ptr->tim_stealth);
2089 rd_s16b(&p_ptr->tim_levitation);
2090 rd_s16b(&p_ptr->tim_sh_touki);
2091 rd_s16b(&p_ptr->lightspeed);
2092 rd_s16b(&p_ptr->tsubureru);
2093 if (z_older_than(10, 4, 7))
2094 p_ptr->magicdef = 0;
2096 rd_s16b(&p_ptr->magicdef);
2097 rd_s16b(&p_ptr->tim_res_nether);
2098 if (z_older_than(10, 4, 11))
2100 p_ptr->tim_res_time = 0;
2101 p_ptr->mimic_form = 0;
2102 p_ptr->tim_mimic = 0;
2103 p_ptr->tim_sh_fire = 0;
2107 rd_s16b(&p_ptr->tim_res_time);
2109 p_ptr->mimic_form = (IDX)tmp8u;
2110 rd_s16b(&p_ptr->tim_mimic);
2111 rd_s16b(&p_ptr->tim_sh_fire);
2114 if (z_older_than(11, 0, 99))
2116 p_ptr->tim_sh_holy = 0;
2117 p_ptr->tim_eyeeye = 0;
2121 rd_s16b(&p_ptr->tim_sh_holy);
2122 rd_s16b(&p_ptr->tim_eyeeye);
2126 if ( z_older_than(11,0,3) ){
2127 p_ptr->tim_reflect=0;
2128 p_ptr->multishadow=0;
2132 rd_s16b(&p_ptr->tim_reflect);
2133 rd_s16b(&p_ptr->multishadow);
2134 rd_s16b(&p_ptr->dustrobe);
2137 rd_s16b(&p_ptr->chaos_patron);
2138 rd_u32b(&p_ptr->muta1);
2139 rd_u32b(&p_ptr->muta2);
2140 rd_u32b(&p_ptr->muta3);
2142 for (i = 0; i < 8; i++)
2143 rd_s16b(&p_ptr->virtues[i]);
2144 for (i = 0; i < 8; i++)
2145 rd_s16b(&p_ptr->vir_types[i]);
2148 /* Calc the regeneration modifier for mutations */
2149 mutant_regenerate_mod = calc_mutant_regenerate_mod();
2151 if (z_older_than(10,0,9))
2154 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2155 p_ptr->ele_attack = 0;
2159 rd_s16b(&p_ptr->ele_attack);
2160 rd_u32b(&p_ptr->special_attack);
2162 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2163 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2164 if (z_older_than(10,0,12))
2166 p_ptr->ele_immune = 0;
2167 p_ptr->special_defense = 0;
2171 rd_s16b(&p_ptr->ele_immune);
2172 rd_u32b(&p_ptr->special_defense);
2174 rd_byte(&p_ptr->knowledge);
2177 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2179 rd_byte(&tmp8u); /* oops */
2180 rd_byte(&p_ptr->action);
2181 if (!z_older_than(10, 4, 3))
2184 if (tmp8u) p_ptr->action = ACTION_LEARN;
2186 rd_byte((byte *)&preserve_mode);
2187 rd_byte((byte *)&p_ptr->wait_report_score);
2190 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2192 /* Skip the flags */
2196 /* Hack -- the two "special seeds" */
2197 rd_u32b(&seed_flavor);
2198 rd_u32b(&seed_town);
2202 rd_u16b(&p_ptr->panic_save);
2203 rd_u16b(&p_ptr->total_winner);
2204 rd_u16b(&p_ptr->noscore);
2209 p_ptr->is_dead = tmp8u;
2211 /* Read "feeling" */
2212 rd_byte(&p_ptr->feeling);
2214 switch (p_ptr->start_race)
2220 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2223 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2226 dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2228 /* Turn when level began */
2231 if (h_older_than(1, 7, 0, 4))
2233 p_ptr->feeling_turn = old_turn;
2237 /* Turn of last "feeling" */
2238 rd_s32b(&p_ptr->feeling_turn);
2244 if (z_older_than(10, 3, 12))
2246 dungeon_turn = turn;
2248 else rd_s32b(&dungeon_turn);
2250 if (z_older_than(11, 0, 13))
2253 p_ptr->feeling_turn /= 2;
2258 if (z_older_than(10, 3, 13))
2262 else rd_s32b(&old_battle);
2264 if (z_older_than(10,0,3))
2266 determine_today_mon(TRUE);
2270 rd_s16b(&today_mon);
2271 rd_s16b(&p_ptr->today_mon);
2274 if (z_older_than(10,0,7))
2280 rd_s16b(&p_ptr->riding);
2283 /* Current floor_id */
2284 if (h_older_than(1, 5, 0, 0))
2286 p_ptr->floor_id = 0;
2290 rd_s16b(&p_ptr->floor_id);
2293 if (h_older_than(1, 5, 0, 2))
2299 /* Get number of party_mon array */
2302 /* Strip old temporary preserved pets */
2303 for (i = 0; i < tmp16s; i++)
2305 monster_type dummy_mon;
2307 rd_monster(&dummy_mon);
2311 if (z_older_than(10,1,2))
2320 if (z_older_than(10,3,9))
2324 else if (z_older_than(10, 3, 10))
2333 p_ptr->visit = (BIT_FLAGS)tmp32s;
2335 if (!z_older_than(11, 0, 5))
2337 rd_u32b(&p_ptr->count);
2343 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2346 * Note that the inventory changed in Angband 2.7.4. Two extra
2347 * pack slots were added and the equipment was rearranged. Note
2348 * that these two features combine when parsing old save-files, in
2349 * which items from the old "aux" slot are "carried", perhaps into
2350 * one of the two new "inventory" slots.
2352 * Note that the inventory is "re-sorted" later by "dungeon()".
2354 static errr rd_inventory(void)
2362 p_ptr->total_weight = 0;
2368 /* Read until done */
2373 /* Get the next item index */
2376 /* Nope, we reached the end */
2377 if (n == 0xFFFF) break;
2379 /* Get local object */
2382 /* Wipe the object */
2388 /* Hack -- verify item */
2389 if (!q_ptr->k_idx) return (53);
2391 /* Wield equipment */
2392 if (n >= INVEN_RARM)
2394 /* Player touches it */
2395 q_ptr->marked |= OM_TOUCHED;
2398 object_copy(&inventory[n], q_ptr);
2400 /* Add the weight */
2401 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2407 /* Warning -- backpack is full */
2408 else if (inven_cnt == INVEN_PACK)
2411 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
2417 /* Carry inventory */
2423 /* Player touches it */
2424 q_ptr->marked |= OM_TOUCHED;
2427 object_copy(&inventory[n], q_ptr);
2429 /* Add the weight */
2430 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2443 * @brief メッセージログを読み込む / Read the saved messages
2446 static void rd_messages(void)
2452 if (h_older_than(2, 2, 0, 75))
2458 /* Read the messages */
2459 for (i = 0; i < num; i++)
2461 /* Read the message */
2462 rd_string(buf, sizeof(buf));
2464 /* Save the message */
2474 /* Read the messages */
2475 for (i = 0; i < num; i++)
2477 /* Read the message */
2478 rd_string(buf, sizeof(buf));
2480 /* Save the message */
2489 /* Old hidden trap flag */
2490 #define CAVE_TRAP 0x8000
2492 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2493 #define OLD_FEAT_INVIS 0x02
2494 #define OLD_FEAT_GLYPH 0x03
2495 #define OLD_FEAT_QUEST_ENTER 0x08
2496 #define OLD_FEAT_QUEST_EXIT 0x09
2497 #define OLD_FEAT_MINOR_GLYPH 0x40
2498 #define OLD_FEAT_BLDG_1 0x81
2499 #define OLD_FEAT_MIRROR 0xc3
2502 #define OLD_QUEST_WATER_CAVE 18
2504 /* Quest constants */
2505 #define QUEST_OLD_CASTLE 27
2506 #define QUEST_ROYAL_CRYPT 28
2509 * @brief メッセージログを読み込む / Read the dungeon (old method)
2512 * The monsters/objects must be loaded in the same order
2513 * that they were stored, since the actual indexes matter.
2515 static errr rd_dungeon_old(void)
2526 /*** Basic info ***/
2530 dun_level = (DEPTH)tmp16s;
2531 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2535 dungeon_type = (IDX)tmp8u;
2538 /* Set the base level for old versions */
2539 base_level = dun_level;
2542 base_level = (DEPTH)tmp16s;
2544 rd_s16b(&num_repro);
2546 p_ptr->y = (int)tmp16s;
2548 p_ptr->x = (int)tmp16s;
2549 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2551 cur_hgt = (POSITION)tmp16s;
2553 cur_wid = (POSITION)tmp16s;
2554 rd_s16b(&tmp16s); /* max_panel_rows */
2555 rd_s16b(&tmp16s); /* max_panel_cols */
2558 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2566 /*** Run length decoding ***/
2568 /* Load the dungeon data */
2569 for (x = y = 0; y < ymax; )
2575 if (z_older_than(10,3,6))
2584 /* Decline invalid flags */
2585 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2588 /* Apply the RLE info */
2589 for (i = count; i > 0; i--)
2591 /* Access the cave */
2592 c_ptr = &cave[y][x];
2594 /* Extract "info" */
2604 if (++y >= ymax) break;
2610 /*** Run length decoding ***/
2612 /* Load the dungeon data */
2613 for (x = y = 0; y < ymax; )
2619 /* Apply the RLE info */
2620 for (i = count; i > 0; i--)
2622 /* Access the cave */
2623 c_ptr = &cave[y][x];
2625 /* Extract "feat" */
2626 c_ptr->feat = (s16b)tmp8u;
2635 if (++y >= ymax) break;
2640 /*** Run length decoding ***/
2642 /* Load the dungeon data */
2643 for (x = y = 0; y < ymax; )
2649 /* Apply the RLE info */
2650 for (i = count; i > 0; i--)
2652 /* Access the cave */
2653 c_ptr = &cave[y][x];
2655 /* Extract "mimic" */
2656 c_ptr->mimic = (s16b)tmp8u;
2665 if (++y >= ymax) break;
2670 /*** Run length decoding ***/
2672 /* Load the dungeon data */
2673 for (x = y = 0; y < ymax; )
2679 /* Apply the RLE info */
2680 for (i = count; i > 0; i--)
2682 /* Access the cave */
2683 c_ptr = &cave[y][x];
2685 /* Extract "feat" */
2686 c_ptr->special = tmp16s;
2695 if (++y >= ymax) break;
2700 /* Convert cave data */
2701 if (z_older_than(11, 0, 99))
2703 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2705 /* Wipe old unused flags */
2706 cave[y][x].info &= ~(CAVE_MASK);
2710 if (h_older_than(1, 1, 1, 0))
2712 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2714 /* Access the cave */
2715 c_ptr = &cave[y][x];
2718 if (c_ptr->feat == OLD_FEAT_INVIS)
2720 c_ptr->feat = feat_floor;
2721 c_ptr->info |= CAVE_TRAP;
2724 /* Older than 1.1.1 */
2725 if (c_ptr->feat == OLD_FEAT_MIRROR)
2727 c_ptr->feat = feat_floor;
2728 c_ptr->info |= CAVE_OBJECT;
2733 if (h_older_than(1, 3, 1, 0))
2735 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2737 /* Access the cave */
2738 c_ptr = &cave[y][x];
2740 /* Old CAVE_IN_MIRROR flag */
2741 if (c_ptr->info & CAVE_OBJECT)
2743 c_ptr->mimic = feat_mirror;
2746 /* Runes will be mimics and flags */
2747 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2748 (c_ptr->feat == OLD_FEAT_GLYPH))
2750 c_ptr->info |= CAVE_OBJECT;
2751 c_ptr->mimic = c_ptr->feat;
2752 c_ptr->feat = feat_floor;
2755 /* Hidden traps will be trap terrains mimicing floor */
2756 else if (c_ptr->info & CAVE_TRAP)
2758 c_ptr->info &= ~CAVE_TRAP;
2759 c_ptr->mimic = c_ptr->feat;
2760 c_ptr->feat = choose_random_trap();
2763 /* Another hidden trap */
2764 else if (c_ptr->feat == OLD_FEAT_INVIS)
2766 c_ptr->mimic = feat_floor;
2767 c_ptr->feat = feat_trap_open;
2772 /* Quest 18 was removed */
2773 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2775 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2777 /* Access the cave */
2778 c_ptr = &cave[y][x];
2780 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2782 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2784 c_ptr->feat = feat_tree;
2787 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2789 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2792 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2793 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2795 c_ptr->feat = feat_up_stair;
2803 /* Read the item count */
2806 /* Verify maximum */
2807 if (limit > max_o_idx)
2809 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2813 /* Read the dungeon items */
2814 for (i = 1; i < limit; i++)
2821 /* Get a new record */
2827 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2833 o_ptr = &o_list[o_idx];
2839 /* XXX XXX XXX XXX XXX */
2842 if (o_ptr->held_m_idx)
2844 monster_type *m_ptr;
2847 m_ptr = &m_list[o_ptr->held_m_idx];
2850 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2852 /* Place the object */
2853 m_ptr->hold_o_idx = o_idx;
2859 /* Access the item location */
2860 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2863 o_ptr->next_o_idx = c_ptr->o_idx;
2865 /* Place the object */
2866 c_ptr->o_idx = o_idx;
2873 /* Read the monster count */
2876 /* Hack -- verify */
2877 if (limit > max_m_idx)
2879 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2883 /* Read the monsters */
2884 for (i = 1; i < limit; i++)
2887 monster_type *m_ptr;
2889 /* Get a new record */
2895 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2900 /* Acquire monster */
2901 m_ptr = &m_list[m_idx];
2903 /* Read the monster */
2908 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2910 /* Mark the location */
2911 c_ptr->m_idx = m_idx;
2914 real_r_ptr(m_ptr)->cur_num++;
2919 /* The dungeon is ready */
2920 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2921 character_dungeon = FALSE;
2923 character_dungeon = TRUE;
2931 * @brief 保存されたフロアを読み込む / Read the saved floor
2934 * The monsters/objects must be loaded in the same order
2935 * that they were stored, since the actual indexes matter.
2937 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2949 cave_template_type *templates;
2952 /*** Wipe all cave ***/
2956 /*** Basic info ***/
2958 /* Dungeon floor specific info follows */
2962 /*** Not a saved floor ***/
2965 dun_level = (DEPTH)tmp16s;
2966 base_level = dun_level;
2970 /*** The saved floor ***/
2973 if (tmp16s != sf_ptr->floor_id) return 171;
2976 if (tmp8u != sf_ptr->savefile_id) return 171;
2979 if (tmp16s != sf_ptr->dun_level) return 171;
2980 dun_level = sf_ptr->dun_level;
2983 if (tmp32s != sf_ptr->last_visit) return 171;
2986 if (tmp32u != sf_ptr->visit_mark) return 171;
2989 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2992 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2996 base_level = (DEPTH)tmp16s;
2997 rd_s16b(&num_repro);
3000 p_ptr->y = (int)tmp16u;
3003 p_ptr->x = (int)tmp16u;
3006 cur_hgt = (POSITION)tmp16s;
3008 cur_wid = (POSITION)tmp16s;
3010 rd_byte(&p_ptr->feeling);
3014 /*** Read template for cave_type ***/
3016 /* Read the template count */
3019 /* Allocate the "template" array */
3020 C_MAKE(templates, limit, cave_template_type);
3022 /* Read the templates */
3023 for (i = 0; i < limit; i++)
3025 cave_template_type *ct_ptr = &templates[i];
3028 rd_u16b(&ct_ptr->info);
3029 if (h_older_than(1, 7, 0, 2))
3032 ct_ptr->feat = (s16b)tmp8u;
3034 ct_ptr->mimic = (s16b)tmp8u;
3038 rd_s16b(&ct_ptr->feat);
3039 rd_s16b(&ct_ptr->mimic);
3041 rd_s16b(&ct_ptr->special);
3049 /*** Run length decoding ***/
3051 /* Load the dungeon data */
3052 for (x = y = 0; y < ymax; )
3064 } while (tmp8u == MAX_UCHAR);
3066 /* Apply the RLE info */
3067 for (i = count; i > 0; i--)
3069 /* Access the cave */
3070 cave_type *c_ptr = &cave[y][x];
3072 /* Extract cave data */
3073 c_ptr->info = templates[id].info;
3074 c_ptr->feat = templates[id].feat;
3075 c_ptr->mimic = templates[id].mimic;
3076 c_ptr->special = templates[id].special;
3085 if (++y >= ymax) break;
3090 /* Quest 18 was removed */
3091 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3093 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3095 /* Access the cave */
3096 cave_type *c_ptr = &cave[y][x];
3098 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
3100 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
3102 c_ptr->feat = feat_tree;
3105 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
3107 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3110 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3111 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3113 c_ptr->feat = feat_up_stair;
3119 /* Free the "template" array */
3120 C_KILL(templates, limit, cave_template_type);
3125 /* Read the item count */
3128 /* Verify maximum */
3129 if (limit > max_o_idx) return 151;
3132 /* Read the dungeon items */
3133 for (i = 1; i < limit; i++)
3139 /* Get a new record */
3143 if (i != o_idx) return 152;
3146 o_ptr = &o_list[o_idx];
3153 if (o_ptr->held_m_idx)
3155 monster_type *m_ptr;
3158 m_ptr = &m_list[o_ptr->held_m_idx];
3161 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3163 /* Place the object */
3164 m_ptr->hold_o_idx = o_idx;
3170 /* Access the item location */
3171 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3174 o_ptr->next_o_idx = c_ptr->o_idx;
3176 /* Place the object */
3177 c_ptr->o_idx = o_idx;
3184 /* Read the monster count */
3187 /* Hack -- verify */
3188 if (limit > max_m_idx) return 161;
3190 /* Read the monsters */
3191 for (i = 1; i < limit; i++)
3195 monster_type *m_ptr;
3197 /* Get a new record */
3201 if (i != m_idx) return 162;
3204 /* Acquire monster */
3205 m_ptr = &m_list[m_idx];
3207 /* Read the monster */
3212 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3214 /* Mark the location */
3215 c_ptr->m_idx = m_idx;
3218 real_r_ptr(m_ptr)->cur_num++;
3227 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3230 * The monsters/objects must be loaded in the same order
3231 * that they were stored, since the actual indexes matter.
3233 static errr rd_dungeon(void)
3240 /* Initialize saved_floors array and temporal files */
3241 init_saved_floors(FALSE);
3244 if (h_older_than(1, 5, 0, 0))
3246 err = rd_dungeon_old();
3248 /* Prepare floor_id of current floor */
3251 p_ptr->floor_id = get_new_floor_id();
3252 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3261 /* Number of floor_id used from birth */
3262 rd_s16b(&max_floor_id);
3264 /* Current dungeon type */
3265 rd_byte(&dungeon_type);
3268 /* Number of the saved_floors array elements */
3271 /*** No saved floor (On the surface etc.) ***/
3274 /* Read the current floor data */
3275 err = rd_saved_floor(NULL);
3278 /*** In the dungeon ***/
3282 /* Read the saved_floors array */
3283 for (i = 0; i < num; i++)
3285 saved_floor_type *sf_ptr = &saved_floors[i];
3287 rd_s16b(&sf_ptr->floor_id);
3288 rd_byte(&sf_ptr->savefile_id);
3291 sf_ptr->dun_level = (DEPTH)tmp16s;
3293 rd_s32b(&sf_ptr->last_visit);
3294 rd_u32b(&sf_ptr->visit_mark);
3295 rd_s16b(&sf_ptr->upper_floor_id);
3296 rd_s16b(&sf_ptr->lower_floor_id);
3300 /* Move saved floors data to temporal files */
3301 for (i = 0; i < num; i++)
3303 saved_floor_type *sf_ptr = &saved_floors[i];
3306 /* Unused element */
3307 if (!sf_ptr->floor_id) continue;
3309 /* Read the failure mark */
3311 if (tmp8u) continue;
3313 /* Read from the save file */
3314 err = rd_saved_floor(sf_ptr);
3319 /* Re-save as temporal saved floor file */
3320 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3326 /* Finally load current floor data from temporal file */
3329 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3334 /*** Error messages ***/
3338 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3342 note(_("アイテム配置エラー", "Object allocation error"));
3346 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3350 note(_("モンスター配置エラー", "Monster allocation error"));
3354 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3358 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3362 note(_("Error 183", "Error 183"));
3366 /* The dungeon is ready */
3367 character_dungeon = TRUE;
3369 /* Success or Error */
3375 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3378 static errr rd_savefile_new_aux(void)
3391 #ifdef VERIFY_CHECKSUMS
3392 u32b n_x_check, n_v_check;
3393 u32b o_x_check, o_v_check;
3397 /* Strip the version bytes */
3400 /* Hack -- decrypt */
3401 xor_byte = sf_extra;
3404 /* Clear the checksums */
3408 /* Read the version number of the savefile */
3409 /* Old savefile will be version 0.0.0.3 */
3410 rd_byte(&h_ver_extra);
3411 rd_byte(&h_ver_patch);
3412 rd_byte(&h_ver_minor);
3413 rd_byte(&h_ver_major);
3415 /* Mention the savefile version */
3417 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3418 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3421 /* Operating system info */
3422 rd_u32b(&sf_system);
3424 /* Time of savefile creation */
3427 /* Number of resurrections */
3430 /* Number of times played */
3434 /* Later use (always zero) */
3437 /* Later use (always zero) */
3440 /* Later use (always zero) */
3444 rd_byte(&kanji_code);
3446 /* Read RNG state */
3448 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3450 /* Then the options */
3452 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3454 /* Then the "messages" */
3456 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3458 for (i = 0; i < max_r_idx; i++)
3460 /* Access that monster */
3461 monster_race *r_ptr = &r_info[i];
3463 /* Hack -- Reset the death counter */
3464 r_ptr->max_num = 100;
3466 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3468 /* Hack -- Non-unique Nazguls are semi-unique */
3469 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3472 /* Monster Memory */
3475 /* Incompatible save files */
3476 if (tmp16u > max_r_idx)
3478 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3482 /* Read the available records */
3483 for (i = 0; i < tmp16u; i++)
3489 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3494 /* Incompatible save files */
3495 if (tmp16u > max_k_idx)
3497 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3501 /* Read the object memory */
3502 for (i = 0; i < tmp16u; i++)
3504 object_kind *k_ptr = &k_info[i];
3508 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3509 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3511 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3513 /* 2.1.3 or newer version */
3515 u16b max_towns_load;
3516 u16b max_quests_load;
3517 byte max_rquests_load;
3518 s16b old_inside_quest = p_ptr->inside_quest;
3520 /* Number of towns */
3521 rd_u16b(&max_towns_load);
3523 /* Incompatible save files */
3524 if (max_towns_load > max_towns)
3526 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3530 /* Number of quests */
3531 rd_u16b(&max_quests_load);
3533 if (z_older_than(11, 0, 7))
3535 max_rquests_load = 10;
3539 rd_byte(&max_rquests_load);
3542 /* Incompatible save files */
3543 if (max_quests_load > max_quests)
3545 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3549 for (i = 0; i < max_quests_load; i++)
3553 quest_type* const q_ptr = &quest[i];
3555 rd_s16b(&q_ptr->status);
3557 q_ptr->level = tmp16s;
3559 if (z_older_than(11, 0, 6))
3565 rd_byte(&q_ptr->complev);
3567 if(h_older_than(2, 1, 2, 2))
3569 q_ptr->comptime = 0;
3573 rd_u32b(&q_ptr->comptime);
3576 /* Load quest status if quest is running */
3577 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3578 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3579 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3581 rd_s16b(&q_ptr->cur_num);
3582 rd_s16b(&q_ptr->max_num);
3583 rd_s16b(&q_ptr->type);
3585 /* Load quest monster index */
3586 rd_s16b(&q_ptr->r_idx);
3588 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3590 determine_random_questor(&quest[i]);
3593 /* Load quest item index */
3594 rd_s16b(&q_ptr->k_idx);
3597 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3599 rd_byte(&q_ptr->flags);
3601 if (z_older_than(10, 3, 11))
3603 if (q_ptr->flags & QUEST_FLAG_PRESET)
3609 init_flags = INIT_ASSIGN;
3610 p_ptr->inside_quest = i;
3612 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3613 p_ptr->inside_quest = old_inside_quest;
3618 rd_byte(&q_ptr->dungeon);
3621 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3622 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3623 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3626 /* Ignore the empty quests from old versions */
3629 /* Ignore quest status */
3632 /* Ignore quest level */
3636 * We don't have to care about the other info,
3637 * since status should be 0 for these quests anyway
3642 /* Quest 18 was removed */
3643 if (h_older_than(1, 7, 0, 6))
3645 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3646 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3649 /* Position in the wilderness */
3650 rd_s32b(&p_ptr->wilderness_x);
3651 rd_s32b(&p_ptr->wilderness_y);
3652 if (z_older_than(10, 3, 13))
3654 p_ptr->wilderness_x = 5;
3655 p_ptr->wilderness_y = 48;
3658 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3659 else rd_byte((byte *)&p_ptr->wild_mode);
3660 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3661 else rd_byte((byte *)&ambush_flag);
3663 /* Size of the wilderness */
3664 rd_s32b(&wild_x_size);
3665 rd_s32b(&wild_y_size);
3667 /* Incompatible save files */
3668 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3670 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3674 /* Load the wilderness seeds */
3675 for (i = 0; i < wild_x_size; i++)
3677 for (j = 0; j < wild_y_size; j++)
3679 rd_u32b(&wilderness[j][i].seed);
3684 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3686 /* Load the Artifacts */
3689 /* Incompatible save files */
3690 if (tmp16u > max_a_idx)
3692 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3696 /* Read the artifact flags */
3697 for (i = 0; i < tmp16u; i++)
3699 artifact_type *a_ptr = &a_info[i];
3702 a_ptr->cur_num = tmp8u;
3704 if (h_older_than(1, 5, 0, 0))
3706 a_ptr->floor_id = 0;
3714 rd_s16b(&a_ptr->floor_id);
3717 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3719 /* Read the extra stuff */
3721 if (p_ptr->energy_need < -999) world_player = TRUE;
3723 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3726 /* Read the player_hp array */
3729 /* Incompatible save files */
3730 if (tmp16u > PY_MAX_LEVEL)
3732 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3736 /* Read the player_hp array */
3737 for (i = 0; i < tmp16u; i++)
3739 rd_s16b(&p_ptr->player_hp[i]);
3742 /* Important -- Initialize the sex */
3743 sp_ptr = &sex_info[p_ptr->psex];
3745 /* Important -- Initialize the race/class */
3746 rp_ptr = &race_info[p_ptr->prace];
3747 cp_ptr = &class_info[p_ptr->pclass];
3748 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3750 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3752 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3753 do_cmd_rerate(FALSE);
3755 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3757 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3758 do_cmd_rerate(FALSE);
3760 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3762 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3763 do_cmd_rerate(FALSE);
3765 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3767 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3768 do_cmd_rerate(FALSE);
3771 /* Important -- Initialize the magic */
3772 mp_ptr = &m_info[p_ptr->pclass];
3775 /* Read spell info */
3776 rd_u32b(&p_ptr->spell_learned1);
3777 rd_u32b(&p_ptr->spell_learned2);
3778 rd_u32b(&p_ptr->spell_worked1);
3779 rd_u32b(&p_ptr->spell_worked2);
3780 rd_u32b(&p_ptr->spell_forgotten1);
3781 rd_u32b(&p_ptr->spell_forgotten2);
3783 if (z_older_than(10,0,5))
3785 p_ptr->learned_spells = 0;
3786 for (i = 0; i < 64; i++)
3788 /* Count known spells */
3790 (p_ptr->spell_learned1 & (1L << i)) :
3791 (p_ptr->spell_learned2 & (1L << (i - 32))))
3793 p_ptr->learned_spells++;
3797 else rd_s16b(&p_ptr->learned_spells);
3799 if (z_older_than(10,0,6))
3801 p_ptr->add_spells = 0;
3803 else rd_s16b(&p_ptr->add_spells);
3804 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3806 for (i = 0; i < 64; i++)
3808 rd_byte(&p_ptr->spell_order[i]);
3812 /* Read the inventory */
3815 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3819 /* Read number of towns */
3821 town_count = tmp16u;
3823 /* Read the stores */
3825 for (i = 1; i < town_count; i++)
3827 for (j = 0; j < tmp16u; j++)
3829 if (rd_store(i, j)) return (22);
3833 rd_s16b(&p_ptr->pet_follow_distance);
3834 if (z_older_than(10, 4, 10))
3836 p_ptr->pet_extra_flags = 0;
3838 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3840 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3842 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3846 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3849 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3853 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3856 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3860 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3863 if (!z_older_than(10,0,8))
3866 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3871 rd_s16b(&p_ptr->pet_extra_flags);
3874 if (!z_older_than(11, 0, 9))
3876 char buf[SCREEN_BUF_SIZE];
3877 rd_string(buf, sizeof(buf));
3878 if (buf[0]) screen_dump = string_make(buf);
3883 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3885 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3890 /* I'm not dead yet... */
3891 if (!p_ptr->is_dead)
3893 /* Dead players have no dungeon */
3894 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3898 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3902 /* Read the ghost info */
3909 strip_bytes(tmp32s);
3913 /* Quest 18 was removed */
3914 if (h_older_than(1, 7, 0, 6))
3916 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3918 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3920 p_ptr->inside_quest = 0;
3925 #ifdef VERIFY_CHECKSUMS
3927 /* Save the checksum */
3928 n_v_check = v_check;
3930 /* Read the old checksum */
3931 rd_u32b(&o_v_check);
3934 if (o_v_check != n_v_check)
3936 note(_("チェックサムがおかしい", "Invalid checksum"));
3941 /* Save the encoded checksum */
3942 n_x_check = x_check;
3944 /* Read the checksum */
3945 rd_u32b(&o_x_check);
3949 if (o_x_check != n_x_check)
3951 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3962 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3965 errr rd_savefile_new(void)
3969 /* Grab permissions */
3972 /* The savefile is a binary file */
3973 fff = my_fopen(savefile, "rb");
3975 /* Drop permissions */
3979 if (!fff) return (-1);
3981 /* Call the sub-function */
3982 err = rd_savefile_new_aux();
3984 /* Check for errors */
3985 if (ferror(fff)) err = -1;
3987 /* Close the file */
3996 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3997 * @param sf_ptr 保存フロア読み込み先
4000 static bool load_floor_aux(saved_floor_type *sf_ptr)
4005 #ifdef VERIFY_CHECKSUMS
4006 u32b n_x_check, n_v_check;
4007 u32b o_x_check, o_v_check;
4010 /* Hack -- decrypt (read xor_byte) */
4014 /* Clear the checksums */
4018 /* Set the version number to current version */
4019 /* Never load old temporal files */
4020 h_ver_extra = H_VER_EXTRA;
4021 h_ver_patch = H_VER_PATCH;
4022 h_ver_minor = H_VER_MINOR;
4023 h_ver_major = H_VER_MAJOR;
4025 /* Verify the sign */
4027 if (saved_floor_file_sign != tmp32u) return FALSE;
4029 /* Read -- have error? */
4030 if (rd_saved_floor(sf_ptr)) return FALSE;
4033 #ifdef VERIFY_CHECKSUMS
4034 /* Save the checksum */
4035 n_v_check = v_check;
4037 /* Read the old checksum */
4038 rd_u32b(&o_v_check);
4041 if (o_v_check != n_v_check) return FALSE;
4043 /* Save the encoded checksum */
4044 n_x_check = x_check;
4046 /* Read the checksum */
4047 rd_u32b(&o_x_check);
4050 if (o_x_check != n_x_check) return FALSE;
4059 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4060 * @param sf_ptr 保存フロア読み込み先
4064 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
4066 FILE *old_fff = NULL;
4067 byte old_xor_byte = 0;
4068 u32b old_v_check = 0;
4069 u32b old_x_check = 0;
4070 byte old_h_ver_major = 0;
4071 byte old_h_ver_minor = 0;
4072 byte old_h_ver_patch = 0;
4073 byte old_h_ver_extra = 0;
4076 char floor_savefile[1024];
4078 byte old_kanji_code = kanji_code;
4081 * Temporal files are always written in system depended kanji
4086 /* EUC kanji code */
4090 /* SJIS kanji code */
4099 /* We have one file already opened */
4100 if (mode & SLF_SECOND)
4102 /* Backup original values */
4104 old_xor_byte = xor_byte;
4105 old_v_check = v_check;
4106 old_x_check = x_check;
4107 old_h_ver_major = h_ver_major;
4108 old_h_ver_minor = h_ver_minor;
4109 old_h_ver_patch = h_ver_patch;
4110 old_h_ver_extra = h_ver_extra;
4113 /* floor savefile */
4114 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4116 /* Grab permissions */
4119 /* The savefile is a binary file */
4120 fff = my_fopen(floor_savefile, "rb");
4122 /* Drop permissions */
4126 if (!fff) ok = FALSE;
4128 /* Attempt to load */
4131 /* Load saved floor data from file */
4132 ok = load_floor_aux(sf_ptr);
4134 /* Check for errors */
4135 if (ferror(fff)) ok = FALSE;
4137 /* Close the file */
4140 /* Grab permissions */
4143 /* Delete the file */
4144 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4146 /* Drop permissions */
4150 /* We have one file already opened */
4151 if (mode & SLF_SECOND)
4153 /* Restore original values */
4155 xor_byte = old_xor_byte;
4156 v_check = old_v_check;
4157 x_check = old_x_check;
4158 h_ver_major = old_h_ver_major;
4159 h_ver_minor = old_h_ver_minor;
4160 h_ver_patch = old_h_ver_patch;
4161 h_ver_extra = old_h_ver_extra;
4164 /* Restore old knowledge */
4165 kanji_code = old_kanji_code;