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;
355 rd_byte(&o_ptr->tval);
356 rd_byte(&o_ptr->sval);
358 if (z_older_than(10, 4, 4))
360 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
361 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
362 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
366 rd_s16b(&o_ptr->pval);
368 rd_byte(&o_ptr->discount);
370 o_ptr->number = (ITEM_NUMBER)tmp8u;
371 rd_s16b(&o_ptr->weight);
374 o_ptr->name1 = tmp8u;
377 o_ptr->name2 = tmp8u;
379 rd_s16b(&o_ptr->timeout);
381 rd_s16b(&o_ptr->to_h);
384 o_ptr->to_d = tmp16s;
385 rd_s16b(&o_ptr->to_a);
392 rd_byte(&o_ptr->ident);
394 rd_byte(&o_ptr->marked);
397 rd_u32b(&o_ptr->art_flags[0]);
398 rd_u32b(&o_ptr->art_flags[1]);
399 rd_u32b(&o_ptr->art_flags[2]);
400 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
401 else rd_u32b(&o_ptr->art_flags[3]);
403 if (h_older_than(1, 3, 0, 0))
405 if (o_ptr->name2 == EGO_TELEPATHY)
406 add_flag(o_ptr->art_flags, TR_TELEPATHY);
409 if (z_older_than(11, 0, 11))
411 o_ptr->curse_flags = 0L;
412 if (o_ptr->ident & 0x40)
414 o_ptr->curse_flags |= TRC_CURSED;
415 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
416 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
417 if (object_is_fixed_artifact(o_ptr))
419 artifact_type *a_ptr = &a_info[o_ptr->name1];
420 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
421 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
423 else if (object_is_ego(o_ptr))
425 ego_item_type *e_ptr = &e_info[o_ptr->name2];
426 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
427 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
430 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
434 rd_u32b(&o_ptr->curse_flags);
437 /* Monster holding object */
438 rd_s16b(&o_ptr->held_m_idx);
441 rd_byte(&o_ptr->xtra1);
442 rd_byte(&o_ptr->xtra2);
444 if (z_older_than(11, 0, 10))
446 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
448 switch (o_ptr->xtra2 % 6)
450 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
451 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
452 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
453 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
454 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
455 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
459 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
461 switch (o_ptr->xtra2 % 11)
463 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
464 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
465 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
466 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
467 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
468 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
469 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
470 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
471 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
472 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
473 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
477 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
479 switch (o_ptr->xtra2 % 8)
481 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
482 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
483 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
484 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
485 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
486 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
487 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
488 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
495 if (z_older_than(10, 2, 3))
500 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
502 o_ptr->xtra3 = o_ptr->xtra1;
505 if (o_ptr->tval == TV_CAPTURE)
507 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
508 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
510 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
511 if (ironman_nightmare)
513 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
515 o_ptr->xtra4 = o_ptr->xtra5;
520 rd_byte(&o_ptr->xtra3);
521 if (h_older_than(1, 3, 0, 1))
523 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
524 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
527 rd_s16b(&o_ptr->xtra4);
528 rd_s16b(&o_ptr->xtra5);
531 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)))
533 o_ptr->xtra4 = o_ptr->pval;
537 rd_byte(&o_ptr->feeling);
540 rd_string(buf, sizeof(buf));
542 /* Save the inscription */
543 if (buf[0]) o_ptr->inscription = quark_add(buf);
545 rd_string(buf, sizeof(buf));
546 if (buf[0]) o_ptr->art_name = quark_add(buf);
548 /* The Python object */
556 /* Mega-Hack -- handle "dungeon objects" later */
557 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
559 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
561 if (z_older_than(10, 4, 9))
563 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
565 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
566 add_flag(o_ptr->art_flags, TR_DEC_MANA);
571 if (object_is_fixed_artifact(o_ptr))
573 artifact_type *a_ptr;
575 /* Obtain the artifact info */
576 a_ptr = &a_info[o_ptr->name1];
578 /* Verify that artifact */
579 if (!a_ptr->name) o_ptr->name1 = 0;
583 if (object_is_ego(o_ptr))
585 ego_item_type *e_ptr;
587 /* Obtain the ego-item info */
588 e_ptr = &e_info[o_ptr->name2];
590 /* Verify that ego-item */
591 if (!e_ptr->name) o_ptr->name2 = 0;
598 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
599 * @param o_ptr アイテムオブジェクト保存先ポインタ
602 static void rd_item(object_type *o_ptr)
610 if (h_older_than(1, 5, 0, 0))
616 /*** Item save flags ***/
619 /*** Read un-obvious elements ***/
621 rd_s16b(&o_ptr->k_idx);
625 o_ptr->iy = (POSITION)tmp8u;
627 o_ptr->ix = (POSITION)tmp8u;
630 k_ptr = &k_info[o_ptr->k_idx];
631 o_ptr->tval = k_ptr->tval;
632 o_ptr->sval = k_ptr->sval;
635 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
636 else o_ptr->pval = 0;
638 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
639 else o_ptr->discount = 0;
640 if (flags & SAVE_ITEM_NUMBER) {
642 o_ptr->number = tmp8u;
644 else o_ptr->number = 1;
646 rd_s16b(&o_ptr->weight);
648 if (flags & SAVE_ITEM_NAME1)
651 o_ptr->name1 = tmp8u;
653 else o_ptr->name1 = 0;
654 if (flags & SAVE_ITEM_NAME2)
657 o_ptr->name2 = tmp8u;
659 else o_ptr->name2 = 0;
660 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
661 else o_ptr->timeout = 0;
663 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
664 else o_ptr->to_h = 0;
665 if (flags & SAVE_ITEM_TO_D)
668 o_ptr->to_d = tmp16s;
670 else o_ptr->to_d = 0;
671 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
672 else o_ptr->to_a = 0;
674 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
677 if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
679 if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
682 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
683 else o_ptr->ident = 0;
685 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
686 else o_ptr->marked = 0;
689 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
690 else o_ptr->art_flags[0] = 0;
691 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
692 else o_ptr->art_flags[1] = 0;
693 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
694 else o_ptr->art_flags[2] = 0;
695 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
696 else o_ptr->art_flags[3] = 0;
697 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
698 else o_ptr->art_flags[4] = 0;
700 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
701 else o_ptr->curse_flags = 0;
703 /* Monster holding object */
704 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
705 else o_ptr->held_m_idx = 0;
708 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
709 else o_ptr->xtra1 = 0;
710 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
711 else o_ptr->xtra2 = 0;
713 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
714 else o_ptr->xtra3 = 0;
716 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
717 else o_ptr->xtra4 = 0;
718 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
719 else o_ptr->xtra5 = 0;
721 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
722 else o_ptr->feeling = 0;
724 if (flags & SAVE_ITEM_INSCRIPTION)
726 rd_string(buf, sizeof(buf));
727 o_ptr->inscription = quark_add(buf);
729 else o_ptr->inscription = 0;
731 if (flags & SAVE_ITEM_ART_NAME)
733 rd_string(buf, sizeof(buf));
734 o_ptr->art_name = quark_add(buf);
736 else o_ptr->art_name = 0;
738 if(h_older_than(2,1,2,4))
740 u32b flgs[TR_FLAG_SIZE];
741 object_flags(o_ptr, flgs);
743 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
745 add_flag(o_ptr->art_flags, TR_LITE_M1);
746 remove_flag(o_ptr->art_flags, TR_LITE_1);
747 remove_flag(o_ptr->art_flags, TR_LITE_2);
748 remove_flag(o_ptr->art_flags, TR_LITE_3);
750 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
752 if (o_ptr->tval == TV_LITE)
754 if (o_ptr->sval == SV_LITE_TORCH)
756 add_flag(o_ptr->art_flags, TR_LITE_M1);
758 else if (o_ptr->sval == SV_LITE_LANTERN)
760 add_flag(o_ptr->art_flags, TR_LITE_M2);
762 else if (o_ptr->sval == SV_LITE_FEANOR)
764 add_flag(o_ptr->art_flags, TR_LITE_M3);
770 add_flag(o_ptr->art_flags, TR_LITE_M1);
773 else if (o_ptr->tval == TV_LITE)
775 if (object_is_fixed_artifact(o_ptr))
777 add_flag(o_ptr->art_flags, TR_LITE_3);
779 else if (o_ptr->sval == SV_LITE_TORCH)
781 add_flag(o_ptr->art_flags, TR_LITE_1);
782 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
784 else if (o_ptr->sval == SV_LITE_LANTERN)
786 add_flag(o_ptr->art_flags, TR_LITE_2);
787 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
789 else if (o_ptr->sval == SV_LITE_FEANOR)
791 add_flag(o_ptr->art_flags, TR_LITE_2);
799 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
800 * @param m_ptr モンスター保存先ポインタ
803 static void rd_monster_old(monster_type *m_ptr)
809 /* Read the monster race */
810 rd_s16b(&m_ptr->r_idx);
812 if (z_older_than(11, 0, 12))
813 m_ptr->ap_r_idx = m_ptr->r_idx;
815 rd_s16b(&m_ptr->ap_r_idx);
817 if (z_older_than(11, 0, 14))
819 monster_race *r_ptr = &r_info[m_ptr->r_idx];
821 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
822 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
823 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
826 rd_byte(&m_ptr->sub_align);
828 /* Read the other information */
830 m_ptr->fy = (POSITION)tmp8u;
832 m_ptr->fx = (POSITION)tmp8u;
837 m_ptr->maxhp = tmp16s;
839 if (z_older_than(11, 0, 5))
841 m_ptr->max_maxhp = m_ptr->maxhp;
846 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
848 if(h_older_than(2, 1, 2, 1))
850 m_ptr->dealt_damage = 0;
854 rd_u32b(&m_ptr->dealt_damage);
857 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
858 rd_byte(&m_ptr->mspeed);
859 if (z_older_than(10, 4, 2))
862 m_ptr->energy_need = (s16b)tmp8u;
864 else rd_s16b(&m_ptr->energy_need);
866 if (z_older_than(11, 0, 13))
867 m_ptr->energy_need = 100 - m_ptr->energy_need;
869 if (z_older_than(10,0,7))
871 m_ptr->mtimed[MTIMED_FAST] = 0;
872 m_ptr->mtimed[MTIMED_SLOW] = 0;
877 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
879 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
882 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
884 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
886 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
888 if (z_older_than(10,0,10))
892 else if (z_older_than(10,0,11))
900 m_ptr->target_y = (POSITION)tmp16s;
902 m_ptr->target_x = (POSITION)tmp16s;
906 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
908 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
909 rd_u32b(&m_ptr->smart);
913 if (z_older_than(10, 4, 5))
916 rd_u32b(&m_ptr->exp);
918 if (z_older_than(10, 2, 2))
920 if (m_ptr->r_idx < 0)
922 m_ptr->r_idx = (0-m_ptr->r_idx);
923 m_ptr->mflag2 |= MFLAG2_KAGE;
928 rd_byte(&m_ptr->mflag2);
931 if (z_older_than(11, 0, 12))
933 if (m_ptr->mflag2 & MFLAG2_KAGE)
934 m_ptr->ap_r_idx = MON_KAGE;
937 if (z_older_than(10, 1, 3))
943 rd_string(buf, sizeof(buf));
944 if (buf[0]) m_ptr->nickname = quark_add(buf);
952 * @brief モンスターを読み込む(現版) / Read a monster (New method)
953 * @param m_ptr モンスター保存先ポインタ
956 static void rd_monster(monster_type *m_ptr)
963 if (h_older_than(1, 5, 0, 0))
965 rd_monster_old(m_ptr);
969 /*** Monster save flags ***/
972 /*** Read un-obvious elements ***/
974 /* Read the monster race */
975 rd_s16b(&m_ptr->r_idx);
977 /* Read the other information */
979 m_ptr->fy = (POSITION)tmp8u;
981 m_ptr->fx = (POSITION)tmp8u;
984 m_ptr->hp = (HIT_POINT)tmp16s;
986 m_ptr->maxhp = (HIT_POINT)tmp16s;
988 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
990 if(h_older_than(2, 1, 2, 1))
992 m_ptr->dealt_damage = 0;
996 rd_u32b(&m_ptr->dealt_damage);
999 /* Monster race index of its appearance */
1000 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1001 else m_ptr->ap_r_idx = m_ptr->r_idx;
1003 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1004 else m_ptr->sub_align = 0;
1006 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1007 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1009 rd_byte(&m_ptr->mspeed);
1011 rd_s16b(&m_ptr->energy_need);
1013 if (flags & SAVE_MON_FAST)
1016 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1018 else m_ptr->mtimed[MTIMED_FAST] = 0;
1019 if (flags & SAVE_MON_SLOW)
1022 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1024 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1025 if (flags & SAVE_MON_STUNNED)
1028 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1030 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1031 if (flags & SAVE_MON_CONFUSED)
1034 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1036 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1037 if (flags & SAVE_MON_MONFEAR)
1040 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1042 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1044 if (flags & SAVE_MON_TARGET_Y)
1047 m_ptr->target_y = (POSITION)tmp16s;
1049 else m_ptr->target_y = 0;
1050 if (flags & SAVE_MON_TARGET_X)
1053 m_ptr->target_x = (POSITION)tmp16s;
1055 else m_ptr->target_x = 0;
1057 if (flags & SAVE_MON_INVULNER)
1060 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1062 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1064 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1065 else m_ptr->smart = 0;
1067 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
1068 else m_ptr->exp = 0;
1070 m_ptr->mflag = 0; /* Not saved */
1072 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1073 else m_ptr->mflag2 = 0;
1075 if (flags & SAVE_MON_NICKNAME)
1077 rd_string(buf, sizeof(buf));
1078 m_ptr->nickname = quark_add(buf);
1080 else m_ptr->nickname = 0;
1082 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1083 else m_ptr->parent_m_idx = 0;
1088 * Old monster bit flags of racial resistances
1090 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1091 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1092 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1093 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1094 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1095 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1096 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1097 #define RF3_RES_WATE 0x00800000 /* Resist water */
1098 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1099 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1100 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1101 #define RF3_RES_ALL 0x08000000 /* Resist all */
1103 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1105 if ((R_PTR)->r_flags3 & (RF3)) \
1107 (R_PTR)->r_flags3 &= ~(RF3); \
1108 (R_PTR)->r_flagsr |= (RFR); \
1112 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1114 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1116 (R_PTR)->r_flagsr |= (RFR); \
1120 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1121 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1122 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1123 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1124 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1125 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1126 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1127 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1128 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1129 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1132 * @brief モンスターの思い出を読み込む / Read the monster lore
1133 * @param r_idx 読み込み先モンスターID
1136 static void rd_lore(int r_idx)
1140 monster_race *r_ptr = &r_info[r_idx];
1142 /* Count sights/deaths/kills */
1143 rd_s16b(&r_ptr->r_sights);
1144 rd_s16b(&r_ptr->r_deaths);
1145 rd_s16b(&r_ptr->r_pkills);
1146 if (h_older_than(1, 7, 0, 5))
1148 r_ptr->r_akills = r_ptr->r_pkills;
1152 rd_s16b(&r_ptr->r_akills);
1154 rd_s16b(&r_ptr->r_tkills);
1156 /* Count wakes and ignores */
1157 rd_byte(&r_ptr->r_wake);
1158 rd_byte(&r_ptr->r_ignore);
1161 rd_byte(&r_ptr->r_xtra1);
1162 rd_byte(&r_ptr->r_xtra2);
1165 rd_byte(&r_ptr->r_drop_gold);
1166 rd_byte(&r_ptr->r_drop_item);
1170 rd_byte(&r_ptr->r_cast_spell);
1172 /* Count blows of each type */
1173 rd_byte(&r_ptr->r_blows[0]);
1174 rd_byte(&r_ptr->r_blows[1]);
1175 rd_byte(&r_ptr->r_blows[2]);
1176 rd_byte(&r_ptr->r_blows[3]);
1178 /* Memorize flags */
1179 rd_u32b(&r_ptr->r_flags1);
1180 rd_u32b(&r_ptr->r_flags2);
1181 rd_u32b(&r_ptr->r_flags3);
1182 rd_u32b(&r_ptr->r_flags4);
1183 rd_u32b(&r_ptr->r_flags5);
1184 rd_u32b(&r_ptr->r_flags6);
1185 if (h_older_than(1, 5, 0, 3))
1187 r_ptr->r_flagsr = 0L;
1189 /* Move RF3 resistance flags to RFR */
1190 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1191 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1192 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1193 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1194 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1195 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1196 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1197 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1198 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1199 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1200 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1201 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1203 /* Separate breathers resistance from RF4 to RFR */
1204 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1205 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1206 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1207 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1208 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1209 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1210 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1211 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1212 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1214 /* Resist confusion is merged to RF3_NO_CONF */
1215 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1217 /* Misc resistance hack to RFR */
1218 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1219 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1223 rd_u32b(&r_ptr->r_flagsr);
1226 /* Read the "Racial" monster limit per level */
1227 rd_byte(&r_ptr->max_num);
1229 /* Location in saved floor */
1230 rd_s16b(&r_ptr->floor_id);
1235 /* Repair the lore flags */
1236 r_ptr->r_flags1 &= r_ptr->flags1;
1237 r_ptr->r_flags2 &= r_ptr->flags2;
1238 r_ptr->r_flags3 &= r_ptr->flags3;
1239 r_ptr->r_flags4 &= r_ptr->flags4;
1240 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1241 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1242 r_ptr->r_flagsr &= r_ptr->flagsr;
1246 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1247 * @param st_ptr 店舗の参照ポインタ
1248 * @param o_ptr アイテムオブジェクト参照ポインタ
1251 * In all cases, return the slot (or -1) where the object was placed
1253 * Note that this is a hacked up version of "inven_carry()".
1255 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1256 * known, the player may have to pick stuff up and drop it again.
1258 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1266 /* Check each existing item (try to combine) */
1267 for (slot = 0; slot < st_ptr->stock_num; slot++)
1269 /* Get the existing item */
1270 j_ptr = &st_ptr->stock[slot];
1272 /* The home acts just like the player */
1273 if (object_similar(j_ptr, o_ptr))
1275 /* Save the new number of items */
1276 object_absorb(j_ptr, o_ptr);
1284 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1288 /* Determine the "value" of the item */
1289 value = object_value(o_ptr);
1291 /* Check existing slots to see if we must "slide" */
1292 for (slot = 0; slot < st_ptr->stock_num; slot++)
1294 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1297 /* Slide the others up */
1298 for (i = st_ptr->stock_num; i > slot; i--)
1300 st_ptr->stock[i] = st_ptr->stock[i-1];
1303 /* More stuff now */
1304 st_ptr->stock_num++;
1306 /* Insert the new item */
1307 st_ptr->stock[slot] = *o_ptr;
1309 chg_virtue(V_SACRIFICE, -1);
1311 /* Return the location */
1316 * @brief 店舗情報を読み込む / Read a store
1317 * @param town_number 街ID
1318 * @param store_number 店舗ID
1321 static errr rd_store(int town_number, int store_number)
1333 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1335 st_ptr = &town[1].store[store_number];
1336 if (st_ptr->stock_num) sort = TRUE;
1340 st_ptr = &town[town_number].store[store_number];
1343 /* Read the basic info */
1344 rd_s32b(&st_ptr->store_open);
1345 rd_s16b(&st_ptr->insult_cur);
1347 if (z_older_than(11, 0, 4))
1356 rd_s16b(&st_ptr->good_buy);
1357 rd_s16b(&st_ptr->bad_buy);
1359 /* Read last visit */
1360 rd_s32b(&st_ptr->last_visit);
1362 /* Extract the owner (see above) */
1363 st_ptr->owner = own;
1365 /* Read the items */
1366 for (j = 0; j < num; j++)
1371 /* Get local object */
1374 /* Wipe the object */
1380 /* Acquire valid items */
1381 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1386 home_carry(st_ptr, q_ptr);
1390 k = st_ptr->stock_num++;
1392 /* Acquire the item */
1393 object_copy(&st_ptr->stock[k], q_ptr);
1404 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1407 static void rd_randomizer(void)
1417 rd_u16b(&Rand_place);
1420 for (i = 0; i < RAND_DEG; i++)
1422 rd_u32b(&Rand_state[i]);
1429 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1432 * Note that the normal options are now stored as a set of 256 bit flags,
1433 * plus a set of 256 bit masks to indicate which bit flags were defined
1434 * at the time the savefile was created. This will allow new options
1435 * to be added, and old options to be removed, at any time, without
1436 * hurting old savefiles.
1438 * The window options are stored in the same way, but note that each
1439 * window gets 32 options, and their order is fixed by certain defines.
1441 static void rd_options(void)
1455 /* Ignore old options */
1459 /*** Special info */
1461 /* Read "delay_factor" */
1465 /* Read "hitpoint_warn" */
1469 /* Read "mana_warn" */
1470 if(h_older_than(1, 7, 0, 0))
1481 /*** Cheating options ***/
1485 if (c & 0x0002) p_ptr->wizard = TRUE;
1487 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1488 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1489 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1490 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1491 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1492 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1493 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1494 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1495 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1497 rd_byte((byte *)&autosave_l);
1498 rd_byte((byte *)&autosave_t);
1499 rd_s16b(&autosave_freq);
1502 /*** Normal Options ***/
1504 /* Read the option flags */
1505 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1507 /* Read the option masks */
1508 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1510 /* Analyze the options */
1511 for (n = 0; n < 8; n++)
1513 /* Analyze the options */
1514 for (i = 0; i < 32; i++)
1516 /* Process valid flags */
1517 if (mask[n] & (1L << i))
1519 /* Process valid flags */
1520 if (option_mask[n] & (1L << i))
1523 if (flag[n] & (1L << i))
1526 option_flag[n] |= (1L << i);
1533 option_flag[n] &= ~(1L << i);
1540 if (z_older_than(10, 4, 5))
1542 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1543 else option_flag[5] |= (0x00000001 << 4);
1544 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1545 else option_flag[2] |= (0x00000001 << 5);
1546 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1547 else option_flag[4] |= (0x00000001 << 5);
1548 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1549 else option_flag[5] |= (0x00000001 << 0);
1550 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1551 else option_flag[5] |= (0x00000001 << 12);
1552 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1553 else option_flag[1] |= (0x00000001 << 0);
1554 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1555 else option_flag[1] |= (0x00000001 << 18);
1556 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1557 else option_flag[1] |= (0x00000001 << 19);
1558 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1559 else option_flag[5] |= (0x00000001 << 3);
1562 /* Extract the options */
1563 extract_option_vars();
1566 /*** Window Options ***/
1568 /* Read the window flags */
1569 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1571 /* Read the window masks */
1572 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1574 /* Analyze the options */
1575 for (n = 0; n < 8; n++)
1577 /* Analyze the options */
1578 for (i = 0; i < 32; i++)
1580 /* Process valid flags */
1581 if (mask[n] & (1L << i))
1583 /* Process valid flags */
1584 if (window_mask[n] & (1L << i))
1587 if (flag[n] & (1L << i))
1590 window_flag[n] |= (1L << i);
1597 window_flag[n] &= ~(1L << i);
1608 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1611 * XXX XXX XXX This is such a nasty hack it hurts.
1613 static void rd_ghost(void)
1618 rd_string(buf, sizeof(buf));
1620 /* Strip old data */
1626 * @brief クイックスタート情報を読み込む / Load quick start data
1629 static void load_quick_start(void)
1634 if (z_older_than(11, 0, 13))
1636 previous_char.quick_ok = FALSE;
1640 rd_byte(&previous_char.psex);
1641 rd_byte(&previous_char.prace);
1642 rd_byte(&previous_char.pclass);
1643 rd_byte(&previous_char.pseikaku);
1644 rd_byte(&previous_char.realm1);
1645 rd_byte(&previous_char.realm2);
1647 rd_s16b(&previous_char.age);
1648 rd_s16b(&previous_char.ht);
1649 rd_s16b(&previous_char.wt);
1650 rd_s16b(&previous_char.sc);
1651 rd_s32b(&previous_char.au);
1653 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1654 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1656 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1658 rd_s16b(&previous_char.chaos_patron);
1660 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1662 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1664 /* UNUSED : Was number of random quests */
1668 previous_char.quick_ok = (bool)tmp8u;
1672 * @brief その他の情報を読み込む / Read the "extra" information
1675 static void rd_extra(void)
1683 rd_string(p_ptr->name, sizeof(p_ptr->name));
1685 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1687 if (!h_older_than(1, 7, 0, 1))
1691 /* Read the message */
1692 rd_string(buf, sizeof buf);
1693 if (buf[0]) p_ptr->last_message = string_make(buf);
1698 for (i = 0; i < 4; i++)
1700 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1703 /* Class/Race/Seikaku/Gender/Spells */
1704 rd_byte(&p_ptr->prace);
1705 rd_byte(&p_ptr->pclass);
1706 rd_byte(&p_ptr->pseikaku);
1707 rd_byte(&p_ptr->psex);
1708 rd_byte(&p_ptr->realm1);
1709 rd_byte(&p_ptr->realm2);
1710 rd_byte(&tmp8u); /* oops */
1712 if (z_older_than(10, 4, 4))
1714 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1715 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1716 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1717 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1720 /* Special Race/Class info */
1722 p_ptr->hitdie = tmp8u;
1723 rd_u16b(&p_ptr->expfact);
1725 /* Age/Height/Weight */
1726 rd_s16b(&p_ptr->age);
1727 rd_s16b(&p_ptr->ht);
1728 rd_s16b(&p_ptr->wt);
1730 /* Read the stat info */
1731 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1732 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1733 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1735 strip_bytes(24); /* oops */
1737 rd_s32b(&p_ptr->au);
1739 rd_s32b(&p_ptr->max_exp);
1740 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1741 else rd_s32b(&p_ptr->max_max_exp);
1742 rd_s32b(&p_ptr->exp);
1744 if (h_older_than(1, 7, 0, 3))
1747 p_ptr->exp_frac = (u32b)tmp16u;
1751 rd_u32b(&p_ptr->exp_frac);
1754 rd_s16b(&p_ptr->lev);
1756 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1757 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1759 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1761 if (z_older_than(10, 3, 6))
1762 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1764 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1765 for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1766 if (z_older_than(10, 4, 1))
1768 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1769 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1771 if (z_older_than(10, 3, 14))
1773 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1774 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1778 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1779 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1780 if (h_older_than(1, 3, 0, 1))
1782 if (p_ptr->pclass == CLASS_SMITH)
1784 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1785 p_ptr->magic_num1[96] = 0;
1786 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1787 p_ptr->magic_num1[97] = 0;
1791 if (music_singing_any()) p_ptr->action = ACTION_SING;
1793 if (z_older_than(11, 0, 7))
1795 p_ptr->start_race = p_ptr->prace;
1796 p_ptr->old_race1 = 0L;
1797 p_ptr->old_race2 = 0L;
1798 p_ptr->old_realm = 0;
1802 rd_byte(&p_ptr->start_race);
1803 rd_s32b(&p_ptr->old_race1);
1804 rd_s32b(&p_ptr->old_race2);
1805 rd_s16b(&p_ptr->old_realm);
1808 if (z_older_than(10, 0, 1))
1810 for (i = 0; i < MAX_MANE; i++)
1812 p_ptr->mane_spell[i] = -1;
1813 p_ptr->mane_dam[i] = 0;
1815 p_ptr->mane_num = 0;
1817 else if (z_older_than(10, 2, 3))
1819 for (i = 0; i < OLD_MAX_MANE; i++)
1824 for (i = 0; i < MAX_MANE; i++)
1826 p_ptr->mane_spell[i] = -1;
1827 p_ptr->mane_dam[i] = 0;
1830 p_ptr->mane_num = 0;
1834 for (i = 0; i < MAX_MANE; i++)
1836 rd_s16b(&p_ptr->mane_spell[i]);
1837 rd_s16b(&p_ptr->mane_dam[i]);
1839 rd_s16b(&p_ptr->mane_num);
1842 if (z_older_than(10, 0, 3))
1844 determine_bounty_uniques();
1846 for (i = 0; i < MAX_KUBI; i++)
1848 /* Is this bounty unique already dead? */
1849 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1854 for (i = 0; i < MAX_KUBI; i++)
1856 rd_s16b(&kubi_r_idx[i]);
1860 if (z_older_than(10, 0, 3))
1866 for (i = 0; i < 4; i++)
1868 rd_s16b(&battle_mon[i]);
1869 if (z_older_than(10, 3, 4))
1872 mon_odds[i] = tmp16s;
1874 else rd_u32b(&mon_odds[i]);
1878 rd_s16b(&p_ptr->town_num);
1880 /* Read arena and rewards information */
1881 rd_s16b(&p_ptr->arena_number);
1882 if (h_older_than(1, 5, 0, 1))
1884 /* Arena loser of previous version was marked number 99 */
1885 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1888 p_ptr->inside_arena = (bool)tmp16s;
1889 rd_s16b(&p_ptr->inside_quest);
1890 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1894 p_ptr->inside_battle = (bool)tmp16s;
1896 rd_byte(&p_ptr->exit_bldg);
1900 p_ptr->oldpx = (POSITION)tmp16s;
1902 p_ptr->oldpy = (POSITION)tmp16s;
1904 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1906 /* Was p_ptr->rewards[MAX_BACT] */
1908 for (i = 0; i < tmp16s; i++)
1914 if (h_older_than(1, 7, 0, 3))
1917 p_ptr->mhp = tmp16s;
1920 p_ptr->chp = tmp16s;
1923 p_ptr->chp_frac = (u32b)tmp16u;
1927 rd_s32b(&p_ptr->mhp);
1928 rd_s32b(&p_ptr->chp);
1929 rd_u32b(&p_ptr->chp_frac);
1932 if (h_older_than(1, 7, 0, 3))
1935 p_ptr->msp = tmp16s;
1938 p_ptr->csp = tmp16s;
1941 p_ptr->csp_frac = (u32b)tmp16u;
1945 rd_s32b(&p_ptr->msp);
1946 rd_s32b(&p_ptr->csp);
1947 rd_u32b(&p_ptr->csp_frac);
1950 rd_s16b(&p_ptr->max_plv);
1951 if (z_older_than(10, 3, 8))
1954 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1958 byte max = (byte)max_d_idx;
1962 for(i = 0; i < max; i++)
1965 max_dlv[i] = tmp16s;
1966 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1970 /* Repair maximum player level XXX XXX XXX */
1971 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1975 rd_s16b(&p_ptr->sc);
1976 rd_s16b(&p_ptr->concent);
1978 /* Read the flags */
1979 strip_bytes(2); /* Old "rest" */
1980 rd_s16b(&p_ptr->blind);
1981 rd_s16b(&p_ptr->paralyzed);
1982 rd_s16b(&p_ptr->confused);
1983 rd_s16b(&p_ptr->food);
1984 strip_bytes(4); /* Old "food_digested" / "protection" */
1986 rd_s16b(&p_ptr->energy_need);
1987 if (z_older_than(11, 0, 13))
1988 p_ptr->energy_need = 100 - p_ptr->energy_need;
1989 if (h_older_than(2, 1, 2, 0))
1990 p_ptr->enchant_energy_need = 0;
1992 rd_s16b(&p_ptr->enchant_energy_need);
1994 rd_s16b(&p_ptr->fast);
1995 rd_s16b(&p_ptr->slow);
1996 rd_s16b(&p_ptr->afraid);
1997 rd_s16b(&p_ptr->cut);
1998 rd_s16b(&p_ptr->stun);
1999 rd_s16b(&p_ptr->poisoned);
2000 rd_s16b(&p_ptr->image);
2001 rd_s16b(&p_ptr->protevil);
2002 rd_s16b(&p_ptr->invuln);
2003 if(z_older_than(10, 0, 0))
2006 rd_s16b(&p_ptr->ult_res);
2007 rd_s16b(&p_ptr->hero);
2008 rd_s16b(&p_ptr->shero);
2009 rd_s16b(&p_ptr->shield);
2010 rd_s16b(&p_ptr->blessed);
2011 rd_s16b(&p_ptr->tim_invis);
2012 rd_s16b(&p_ptr->word_recall);
2013 if (z_older_than(10, 3, 8))
2014 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2018 p_ptr->recall_dungeon = (byte)tmp16s;
2021 if (h_older_than(1, 5, 0, 0))
2022 p_ptr->alter_reality = 0;
2024 rd_s16b(&p_ptr->alter_reality);
2026 rd_s16b(&p_ptr->see_infra);
2027 rd_s16b(&p_ptr->tim_infra);
2028 rd_s16b(&p_ptr->oppose_fire);
2029 rd_s16b(&p_ptr->oppose_cold);
2030 rd_s16b(&p_ptr->oppose_acid);
2031 rd_s16b(&p_ptr->oppose_elec);
2032 rd_s16b(&p_ptr->oppose_pois);
2033 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2034 else rd_s16b(&p_ptr->tsuyoshi);
2036 /* Old savefiles do not have the following fields... */
2037 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2040 p_ptr->wraith_form = 0;
2041 p_ptr->resist_magic = 0;
2042 p_ptr->tim_regen = 0;
2043 p_ptr->kabenuke = 0;
2044 p_ptr->tim_stealth = 0;
2045 p_ptr->tim_levitation = 0;
2046 p_ptr->tim_sh_touki = 0;
2047 p_ptr->lightspeed = 0;
2048 p_ptr->tsubureru = 0;
2049 p_ptr->tim_res_nether = 0;
2050 p_ptr->tim_res_time = 0;
2051 p_ptr->mimic_form = 0;
2052 p_ptr->tim_mimic = 0;
2053 p_ptr->tim_sh_fire = 0;
2056 p_ptr->tim_reflect = 0;
2057 p_ptr->multishadow = 0;
2058 p_ptr->dustrobe = 0;
2060 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2068 rd_s16b(&p_ptr->tim_esp);
2069 rd_s16b(&p_ptr->wraith_form);
2070 rd_s16b(&p_ptr->resist_magic);
2071 rd_s16b(&p_ptr->tim_regen);
2072 rd_s16b(&p_ptr->kabenuke);
2073 rd_s16b(&p_ptr->tim_stealth);
2074 rd_s16b(&p_ptr->tim_levitation);
2075 rd_s16b(&p_ptr->tim_sh_touki);
2076 rd_s16b(&p_ptr->lightspeed);
2077 rd_s16b(&p_ptr->tsubureru);
2078 if (z_older_than(10, 4, 7))
2079 p_ptr->magicdef = 0;
2081 rd_s16b(&p_ptr->magicdef);
2082 rd_s16b(&p_ptr->tim_res_nether);
2083 if (z_older_than(10, 4, 11))
2085 p_ptr->tim_res_time = 0;
2086 p_ptr->mimic_form = 0;
2087 p_ptr->tim_mimic = 0;
2088 p_ptr->tim_sh_fire = 0;
2092 rd_s16b(&p_ptr->tim_res_time);
2093 rd_byte(&p_ptr->mimic_form);
2094 rd_s16b(&p_ptr->tim_mimic);
2095 rd_s16b(&p_ptr->tim_sh_fire);
2098 if (z_older_than(11, 0, 99))
2100 p_ptr->tim_sh_holy = 0;
2101 p_ptr->tim_eyeeye = 0;
2105 rd_s16b(&p_ptr->tim_sh_holy);
2106 rd_s16b(&p_ptr->tim_eyeeye);
2110 if ( z_older_than(11,0,3) ){
2111 p_ptr->tim_reflect=0;
2112 p_ptr->multishadow=0;
2116 rd_s16b(&p_ptr->tim_reflect);
2117 rd_s16b(&p_ptr->multishadow);
2118 rd_s16b(&p_ptr->dustrobe);
2121 rd_s16b(&p_ptr->chaos_patron);
2122 rd_u32b(&p_ptr->muta1);
2123 rd_u32b(&p_ptr->muta2);
2124 rd_u32b(&p_ptr->muta3);
2126 for (i = 0; i < 8; i++)
2127 rd_s16b(&p_ptr->virtues[i]);
2128 for (i = 0; i < 8; i++)
2129 rd_s16b(&p_ptr->vir_types[i]);
2132 /* Calc the regeneration modifier for mutations */
2133 mutant_regenerate_mod = calc_mutant_regenerate_mod();
2135 if (z_older_than(10,0,9))
2138 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2139 p_ptr->ele_attack = 0;
2143 rd_s16b(&p_ptr->ele_attack);
2144 rd_u32b(&p_ptr->special_attack);
2146 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2147 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2148 if (z_older_than(10,0,12))
2150 p_ptr->ele_immune = 0;
2151 p_ptr->special_defense = 0;
2155 rd_s16b(&p_ptr->ele_immune);
2156 rd_u32b(&p_ptr->special_defense);
2158 rd_byte(&p_ptr->knowledge);
2161 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2163 rd_byte(&tmp8u); /* oops */
2164 rd_byte(&p_ptr->action);
2165 if (!z_older_than(10, 4, 3))
2168 if (tmp8u) p_ptr->action = ACTION_LEARN;
2170 rd_byte((byte *)&preserve_mode);
2171 rd_byte((byte *)&p_ptr->wait_report_score);
2174 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2176 /* Skip the flags */
2180 /* Hack -- the two "special seeds" */
2181 rd_u32b(&seed_flavor);
2182 rd_u32b(&seed_town);
2186 rd_u16b(&p_ptr->panic_save);
2187 rd_u16b(&p_ptr->total_winner);
2188 rd_u16b(&p_ptr->noscore);
2193 p_ptr->is_dead = tmp8u;
2195 /* Read "feeling" */
2196 rd_byte(&p_ptr->feeling);
2198 switch (p_ptr->start_race)
2204 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2207 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2210 dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2212 /* Turn when level began */
2215 if (h_older_than(1, 7, 0, 4))
2217 p_ptr->feeling_turn = old_turn;
2221 /* Turn of last "feeling" */
2222 rd_s32b(&p_ptr->feeling_turn);
2228 if (z_older_than(10, 3, 12))
2230 dungeon_turn = turn;
2232 else rd_s32b(&dungeon_turn);
2234 if (z_older_than(11, 0, 13))
2237 p_ptr->feeling_turn /= 2;
2242 if (z_older_than(10, 3, 13))
2246 else rd_s32b(&old_battle);
2248 if (z_older_than(10,0,3))
2250 determine_today_mon(TRUE);
2254 rd_s16b(&today_mon);
2255 rd_s16b(&p_ptr->today_mon);
2258 if (z_older_than(10,0,7))
2264 rd_s16b(&p_ptr->riding);
2267 /* Current floor_id */
2268 if (h_older_than(1, 5, 0, 0))
2270 p_ptr->floor_id = 0;
2274 rd_s16b(&p_ptr->floor_id);
2277 if (h_older_than(1, 5, 0, 2))
2283 /* Get number of party_mon array */
2286 /* Strip old temporary preserved pets */
2287 for (i = 0; i < tmp16s; i++)
2289 monster_type dummy_mon;
2291 rd_monster(&dummy_mon);
2295 if (z_older_than(10,1,2))
2304 if (z_older_than(10,3,9))
2308 else if (z_older_than(10, 3, 10))
2316 rd_s32b(&p_ptr->visit);
2318 if (!z_older_than(11, 0, 5))
2320 rd_u32b(&p_ptr->count);
2326 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2329 * Note that the inventory changed in Angband 2.7.4. Two extra
2330 * pack slots were added and the equipment was rearranged. Note
2331 * that these two features combine when parsing old save-files, in
2332 * which items from the old "aux" slot are "carried", perhaps into
2333 * one of the two new "inventory" slots.
2335 * Note that the inventory is "re-sorted" later by "dungeon()".
2337 static errr rd_inventory(void)
2345 p_ptr->total_weight = 0;
2351 /* Read until done */
2356 /* Get the next item index */
2359 /* Nope, we reached the end */
2360 if (n == 0xFFFF) break;
2362 /* Get local object */
2365 /* Wipe the object */
2371 /* Hack -- verify item */
2372 if (!q_ptr->k_idx) return (53);
2374 /* Wield equipment */
2375 if (n >= INVEN_RARM)
2377 /* Player touches it */
2378 q_ptr->marked |= OM_TOUCHED;
2381 object_copy(&inventory[n], q_ptr);
2383 /* Add the weight */
2384 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2390 /* Warning -- backpack is full */
2391 else if (inven_cnt == INVEN_PACK)
2394 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
2400 /* Carry inventory */
2406 /* Player touches it */
2407 q_ptr->marked |= OM_TOUCHED;
2410 object_copy(&inventory[n], q_ptr);
2412 /* Add the weight */
2413 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2426 * @brief メッセージログを読み込む / Read the saved messages
2429 static void rd_messages(void)
2435 if (h_older_than(2, 2, 0, 75))
2441 /* Read the messages */
2442 for (i = 0; i < num; i++)
2444 /* Read the message */
2445 rd_string(buf, sizeof(buf));
2447 /* Save the message */
2457 /* Read the messages */
2458 for (i = 0; i < num; i++)
2460 /* Read the message */
2461 rd_string(buf, sizeof(buf));
2463 /* Save the message */
2472 /* Old hidden trap flag */
2473 #define CAVE_TRAP 0x8000
2475 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2476 #define OLD_FEAT_INVIS 0x02
2477 #define OLD_FEAT_GLYPH 0x03
2478 #define OLD_FEAT_QUEST_ENTER 0x08
2479 #define OLD_FEAT_QUEST_EXIT 0x09
2480 #define OLD_FEAT_MINOR_GLYPH 0x40
2481 #define OLD_FEAT_BLDG_1 0x81
2482 #define OLD_FEAT_MIRROR 0xc3
2485 #define OLD_QUEST_WATER_CAVE 18
2487 /* Quest constants */
2488 #define QUEST_OLD_CASTLE 27
2489 #define QUEST_ROYAL_CRYPT 28
2492 * @brief メッセージログを読み込む / Read the dungeon (old method)
2495 * The monsters/objects must be loaded in the same order
2496 * that they were stored, since the actual indexes matter.
2498 static errr rd_dungeon_old(void)
2509 /*** Basic info ***/
2513 dun_level = (DEPTH)tmp16s;
2514 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2515 else rd_byte(&dungeon_type);
2517 /* Set the base level for old versions */
2518 base_level = dun_level;
2521 base_level = (DEPTH)tmp16s;
2523 rd_s16b(&num_repro);
2525 p_ptr->y = (int)tmp16s;
2527 p_ptr->x = (int)tmp16s;
2528 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2530 cur_hgt = (POSITION)tmp16s;
2532 cur_wid = (POSITION)tmp16s;
2533 rd_s16b(&tmp16s); /* max_panel_rows */
2534 rd_s16b(&tmp16s); /* max_panel_cols */
2537 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2545 /*** Run length decoding ***/
2547 /* Load the dungeon data */
2548 for (x = y = 0; y < ymax; )
2554 if (z_older_than(10,3,6))
2563 /* Decline invalid flags */
2564 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2567 /* Apply the RLE info */
2568 for (i = count; i > 0; i--)
2570 /* Access the cave */
2571 c_ptr = &cave[y][x];
2573 /* Extract "info" */
2583 if (++y >= ymax) break;
2589 /*** Run length decoding ***/
2591 /* Load the dungeon data */
2592 for (x = y = 0; y < ymax; )
2598 /* Apply the RLE info */
2599 for (i = count; i > 0; i--)
2601 /* Access the cave */
2602 c_ptr = &cave[y][x];
2604 /* Extract "feat" */
2605 c_ptr->feat = (s16b)tmp8u;
2614 if (++y >= ymax) break;
2619 /*** Run length decoding ***/
2621 /* Load the dungeon data */
2622 for (x = y = 0; y < ymax; )
2628 /* Apply the RLE info */
2629 for (i = count; i > 0; i--)
2631 /* Access the cave */
2632 c_ptr = &cave[y][x];
2634 /* Extract "mimic" */
2635 c_ptr->mimic = (s16b)tmp8u;
2644 if (++y >= ymax) break;
2649 /*** Run length decoding ***/
2651 /* Load the dungeon data */
2652 for (x = y = 0; y < ymax; )
2658 /* Apply the RLE info */
2659 for (i = count; i > 0; i--)
2661 /* Access the cave */
2662 c_ptr = &cave[y][x];
2664 /* Extract "feat" */
2665 c_ptr->special = tmp16s;
2674 if (++y >= ymax) break;
2679 /* Convert cave data */
2680 if (z_older_than(11, 0, 99))
2682 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2684 /* Wipe old unused flags */
2685 cave[y][x].info &= ~(CAVE_MASK);
2689 if (h_older_than(1, 1, 1, 0))
2691 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2693 /* Access the cave */
2694 c_ptr = &cave[y][x];
2697 if (c_ptr->feat == OLD_FEAT_INVIS)
2699 c_ptr->feat = feat_floor;
2700 c_ptr->info |= CAVE_TRAP;
2703 /* Older than 1.1.1 */
2704 if (c_ptr->feat == OLD_FEAT_MIRROR)
2706 c_ptr->feat = feat_floor;
2707 c_ptr->info |= CAVE_OBJECT;
2712 if (h_older_than(1, 3, 1, 0))
2714 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2716 /* Access the cave */
2717 c_ptr = &cave[y][x];
2719 /* Old CAVE_IN_MIRROR flag */
2720 if (c_ptr->info & CAVE_OBJECT)
2722 c_ptr->mimic = feat_mirror;
2725 /* Runes will be mimics and flags */
2726 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2727 (c_ptr->feat == OLD_FEAT_GLYPH))
2729 c_ptr->info |= CAVE_OBJECT;
2730 c_ptr->mimic = c_ptr->feat;
2731 c_ptr->feat = feat_floor;
2734 /* Hidden traps will be trap terrains mimicing floor */
2735 else if (c_ptr->info & CAVE_TRAP)
2737 c_ptr->info &= ~CAVE_TRAP;
2738 c_ptr->mimic = c_ptr->feat;
2739 c_ptr->feat = choose_random_trap();
2742 /* Another hidden trap */
2743 else if (c_ptr->feat == OLD_FEAT_INVIS)
2745 c_ptr->mimic = feat_floor;
2746 c_ptr->feat = feat_trap_open;
2751 /* Quest 18 was removed */
2752 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2754 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2756 /* Access the cave */
2757 c_ptr = &cave[y][x];
2759 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2761 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2763 c_ptr->feat = feat_tree;
2766 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2768 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2771 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2772 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2774 c_ptr->feat = feat_up_stair;
2782 /* Read the item count */
2785 /* Verify maximum */
2786 if (limit > max_o_idx)
2788 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2792 /* Read the dungeon items */
2793 for (i = 1; i < limit; i++)
2800 /* Get a new record */
2806 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2812 o_ptr = &o_list[o_idx];
2818 /* XXX XXX XXX XXX XXX */
2821 if (o_ptr->held_m_idx)
2823 monster_type *m_ptr;
2826 m_ptr = &m_list[o_ptr->held_m_idx];
2829 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2831 /* Place the object */
2832 m_ptr->hold_o_idx = o_idx;
2838 /* Access the item location */
2839 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2842 o_ptr->next_o_idx = c_ptr->o_idx;
2844 /* Place the object */
2845 c_ptr->o_idx = o_idx;
2852 /* Read the monster count */
2855 /* Hack -- verify */
2856 if (limit > max_m_idx)
2858 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2862 /* Read the monsters */
2863 for (i = 1; i < limit; i++)
2866 monster_type *m_ptr;
2868 /* Get a new record */
2874 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2879 /* Acquire monster */
2880 m_ptr = &m_list[m_idx];
2882 /* Read the monster */
2887 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2889 /* Mark the location */
2890 c_ptr->m_idx = m_idx;
2893 real_r_ptr(m_ptr)->cur_num++;
2898 /* The dungeon is ready */
2899 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2900 character_dungeon = FALSE;
2902 character_dungeon = TRUE;
2910 * @brief 保存されたフロアを読み込む / Read the saved floor
2913 * The monsters/objects must be loaded in the same order
2914 * that they were stored, since the actual indexes matter.
2916 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2928 cave_template_type *templates;
2931 /*** Wipe all cave ***/
2935 /*** Basic info ***/
2937 /* Dungeon floor specific info follows */
2941 /*** Not a saved floor ***/
2944 dun_level = (DEPTH)tmp16s;
2945 base_level = dun_level;
2949 /*** The saved floor ***/
2952 if (tmp16s != sf_ptr->floor_id) return 171;
2955 if (tmp8u != sf_ptr->savefile_id) return 171;
2958 if (tmp16s != sf_ptr->dun_level) return 171;
2959 dun_level = sf_ptr->dun_level;
2962 if (tmp32s != sf_ptr->last_visit) return 171;
2965 if (tmp32u != sf_ptr->visit_mark) return 171;
2968 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2971 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2975 base_level = (DEPTH)tmp16s;
2976 rd_s16b(&num_repro);
2979 p_ptr->y = (int)tmp16u;
2982 p_ptr->x = (int)tmp16u;
2985 cur_hgt = (POSITION)tmp16s;
2987 cur_wid = (POSITION)tmp16s;
2989 rd_byte(&p_ptr->feeling);
2993 /*** Read template for cave_type ***/
2995 /* Read the template count */
2998 /* Allocate the "template" array */
2999 C_MAKE(templates, limit, cave_template_type);
3001 /* Read the templates */
3002 for (i = 0; i < limit; i++)
3004 cave_template_type *ct_ptr = &templates[i];
3007 rd_u16b(&ct_ptr->info);
3008 if (h_older_than(1, 7, 0, 2))
3011 ct_ptr->feat = (s16b)tmp8u;
3013 ct_ptr->mimic = (s16b)tmp8u;
3017 rd_s16b(&ct_ptr->feat);
3018 rd_s16b(&ct_ptr->mimic);
3020 rd_s16b(&ct_ptr->special);
3028 /*** Run length decoding ***/
3030 /* Load the dungeon data */
3031 for (x = y = 0; y < ymax; )
3043 } while (tmp8u == MAX_UCHAR);
3045 /* Apply the RLE info */
3046 for (i = count; i > 0; i--)
3048 /* Access the cave */
3049 cave_type *c_ptr = &cave[y][x];
3051 /* Extract cave data */
3052 c_ptr->info = templates[id].info;
3053 c_ptr->feat = templates[id].feat;
3054 c_ptr->mimic = templates[id].mimic;
3055 c_ptr->special = templates[id].special;
3064 if (++y >= ymax) break;
3069 /* Quest 18 was removed */
3070 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3072 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3074 /* Access the cave */
3075 cave_type *c_ptr = &cave[y][x];
3077 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
3079 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
3081 c_ptr->feat = feat_tree;
3084 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
3086 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3089 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3090 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3092 c_ptr->feat = feat_up_stair;
3098 /* Free the "template" array */
3099 C_KILL(templates, limit, cave_template_type);
3104 /* Read the item count */
3107 /* Verify maximum */
3108 if (limit > max_o_idx) return 151;
3111 /* Read the dungeon items */
3112 for (i = 1; i < limit; i++)
3118 /* Get a new record */
3122 if (i != o_idx) return 152;
3125 o_ptr = &o_list[o_idx];
3132 if (o_ptr->held_m_idx)
3134 monster_type *m_ptr;
3137 m_ptr = &m_list[o_ptr->held_m_idx];
3140 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3142 /* Place the object */
3143 m_ptr->hold_o_idx = o_idx;
3149 /* Access the item location */
3150 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3153 o_ptr->next_o_idx = c_ptr->o_idx;
3155 /* Place the object */
3156 c_ptr->o_idx = o_idx;
3163 /* Read the monster count */
3166 /* Hack -- verify */
3167 if (limit > max_m_idx) return 161;
3169 /* Read the monsters */
3170 for (i = 1; i < limit; i++)
3174 monster_type *m_ptr;
3176 /* Get a new record */
3180 if (i != m_idx) return 162;
3183 /* Acquire monster */
3184 m_ptr = &m_list[m_idx];
3186 /* Read the monster */
3191 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3193 /* Mark the location */
3194 c_ptr->m_idx = m_idx;
3197 real_r_ptr(m_ptr)->cur_num++;
3206 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3209 * The monsters/objects must be loaded in the same order
3210 * that they were stored, since the actual indexes matter.
3212 static errr rd_dungeon(void)
3219 /* Initialize saved_floors array and temporal files */
3220 init_saved_floors(FALSE);
3223 if (h_older_than(1, 5, 0, 0))
3225 err = rd_dungeon_old();
3227 /* Prepare floor_id of current floor */
3230 p_ptr->floor_id = get_new_floor_id();
3231 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3240 /* Number of floor_id used from birth */
3241 rd_s16b(&max_floor_id);
3243 /* Current dungeon type */
3244 rd_byte(&dungeon_type);
3247 /* Number of the saved_floors array elements */
3250 /*** No saved floor (On the surface etc.) ***/
3253 /* Read the current floor data */
3254 err = rd_saved_floor(NULL);
3257 /*** In the dungeon ***/
3261 /* Read the saved_floors array */
3262 for (i = 0; i < num; i++)
3264 saved_floor_type *sf_ptr = &saved_floors[i];
3266 rd_s16b(&sf_ptr->floor_id);
3267 rd_byte(&sf_ptr->savefile_id);
3270 sf_ptr->dun_level = (DEPTH)tmp16s;
3272 rd_s32b(&sf_ptr->last_visit);
3273 rd_u32b(&sf_ptr->visit_mark);
3274 rd_s16b(&sf_ptr->upper_floor_id);
3275 rd_s16b(&sf_ptr->lower_floor_id);
3279 /* Move saved floors data to temporal files */
3280 for (i = 0; i < num; i++)
3282 saved_floor_type *sf_ptr = &saved_floors[i];
3285 /* Unused element */
3286 if (!sf_ptr->floor_id) continue;
3288 /* Read the failure mark */
3290 if (tmp8u) continue;
3292 /* Read from the save file */
3293 err = rd_saved_floor(sf_ptr);
3298 /* Re-save as temporal saved floor file */
3299 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3305 /* Finally load current floor data from temporal file */
3308 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3313 /*** Error messages ***/
3317 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3321 note(_("アイテム配置エラー", "Object allocation error"));
3325 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3329 note(_("モンスター配置エラー", "Monster allocation error"));
3333 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3337 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3341 note(_("Error 183", "Error 183"));
3345 /* The dungeon is ready */
3346 character_dungeon = TRUE;
3348 /* Success or Error */
3354 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3357 static errr rd_savefile_new_aux(void)
3369 #ifdef VERIFY_CHECKSUMS
3370 u32b n_x_check, n_v_check;
3371 u32b o_x_check, o_v_check;
3375 /* Strip the version bytes */
3378 /* Hack -- decrypt */
3379 xor_byte = sf_extra;
3382 /* Clear the checksums */
3386 /* Read the version number of the savefile */
3387 /* Old savefile will be version 0.0.0.3 */
3388 rd_byte(&h_ver_extra);
3389 rd_byte(&h_ver_patch);
3390 rd_byte(&h_ver_minor);
3391 rd_byte(&h_ver_major);
3393 /* Mention the savefile version */
3395 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3396 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3399 /* Operating system info */
3400 rd_u32b(&sf_system);
3402 /* Time of savefile creation */
3405 /* Number of resurrections */
3408 /* Number of times played */
3412 /* Later use (always zero) */
3415 /* Later use (always zero) */
3418 /* Later use (always zero) */
3422 rd_byte(&kanji_code);
3424 /* Read RNG state */
3426 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3428 /* Then the options */
3430 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3432 /* Then the "messages" */
3434 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3436 for (i = 0; i < max_r_idx; i++)
3438 /* Access that monster */
3439 monster_race *r_ptr = &r_info[i];
3441 /* Hack -- Reset the death counter */
3442 r_ptr->max_num = 100;
3444 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3446 /* Hack -- Non-unique Nazguls are semi-unique */
3447 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3450 /* Monster Memory */
3453 /* Incompatible save files */
3454 if (tmp16u > max_r_idx)
3456 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3460 /* Read the available records */
3461 for (i = 0; i < tmp16u; i++)
3467 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3472 /* Incompatible save files */
3473 if (tmp16u > max_k_idx)
3475 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3479 /* Read the object memory */
3480 for (i = 0; i < tmp16u; i++)
3482 object_kind *k_ptr = &k_info[i];
3486 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3487 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3489 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3491 /* 2.1.3 or newer version */
3493 u16b max_towns_load;
3494 u16b max_quests_load;
3495 byte max_rquests_load;
3496 s16b old_inside_quest = p_ptr->inside_quest;
3498 /* Number of towns */
3499 rd_u16b(&max_towns_load);
3501 /* Incompatible save files */
3502 if (max_towns_load > max_towns)
3504 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3508 /* Number of quests */
3509 rd_u16b(&max_quests_load);
3511 if (z_older_than(11, 0, 7))
3513 max_rquests_load = 10;
3517 rd_byte(&max_rquests_load);
3520 /* Incompatible save files */
3521 if (max_quests_load > max_quests)
3523 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3527 for (i = 0; i < max_quests_load; i++)
3531 quest_type* const q_ptr = &quest[i];
3533 rd_s16b(&q_ptr->status);
3534 rd_s16b(&q_ptr->level);
3536 if (z_older_than(11, 0, 6))
3542 rd_byte(&q_ptr->complev);
3544 if(h_older_than(2, 1, 2, 2))
3546 q_ptr->comptime = 0;
3550 rd_u32b(&q_ptr->comptime);
3553 /* Load quest status if quest is running */
3554 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3555 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3556 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3558 rd_s16b(&q_ptr->cur_num);
3559 rd_s16b(&q_ptr->max_num);
3560 rd_s16b(&q_ptr->type);
3562 /* Load quest monster index */
3563 rd_s16b(&q_ptr->r_idx);
3565 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3567 determine_random_questor(&quest[i]);
3570 /* Load quest item index */
3571 rd_s16b(&q_ptr->k_idx);
3574 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3576 rd_byte(&q_ptr->flags);
3578 if (z_older_than(10, 3, 11))
3580 if (q_ptr->flags & QUEST_FLAG_PRESET)
3586 init_flags = INIT_ASSIGN;
3587 p_ptr->inside_quest = i;
3589 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3590 p_ptr->inside_quest = old_inside_quest;
3595 rd_byte(&q_ptr->dungeon);
3598 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3599 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3600 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3603 /* Ignore the empty quests from old versions */
3606 /* Ignore quest status */
3609 /* Ignore quest level */
3613 * We don't have to care about the other info,
3614 * since status should be 0 for these quests anyway
3619 /* Quest 18 was removed */
3620 if (h_older_than(1, 7, 0, 6))
3622 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3623 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3626 /* Position in the wilderness */
3627 rd_s32b(&p_ptr->wilderness_x);
3628 rd_s32b(&p_ptr->wilderness_y);
3629 if (z_older_than(10, 3, 13))
3631 p_ptr->wilderness_x = 5;
3632 p_ptr->wilderness_y = 48;
3635 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3636 else rd_byte((byte *)&p_ptr->wild_mode);
3637 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3638 else rd_byte((byte *)&ambush_flag);
3640 /* Size of the wilderness */
3641 rd_s32b(&wild_x_size);
3642 rd_s32b(&wild_y_size);
3644 /* Incompatible save files */
3645 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3647 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3651 /* Load the wilderness seeds */
3652 for (i = 0; i < wild_x_size; i++)
3654 for (j = 0; j < wild_y_size; j++)
3656 rd_u32b(&wilderness[j][i].seed);
3661 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3663 /* Load the Artifacts */
3666 /* Incompatible save files */
3667 if (tmp16u > max_a_idx)
3669 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3673 /* Read the artifact flags */
3674 for (i = 0; i < tmp16u; i++)
3676 artifact_type *a_ptr = &a_info[i];
3679 a_ptr->cur_num = tmp8u;
3681 if (h_older_than(1, 5, 0, 0))
3683 a_ptr->floor_id = 0;
3691 rd_s16b(&a_ptr->floor_id);
3694 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3696 /* Read the extra stuff */
3698 if (p_ptr->energy_need < -999) world_player = TRUE;
3700 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3703 /* Read the player_hp array */
3706 /* Incompatible save files */
3707 if (tmp16u > PY_MAX_LEVEL)
3709 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3713 /* Read the player_hp array */
3714 for (i = 0; i < tmp16u; i++)
3716 rd_s16b(&p_ptr->player_hp[i]);
3719 /* Important -- Initialize the sex */
3720 sp_ptr = &sex_info[p_ptr->psex];
3722 /* Important -- Initialize the race/class */
3723 rp_ptr = &race_info[p_ptr->prace];
3724 cp_ptr = &class_info[p_ptr->pclass];
3725 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3727 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3729 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3730 do_cmd_rerate(FALSE);
3732 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3734 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3735 do_cmd_rerate(FALSE);
3737 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3739 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3740 do_cmd_rerate(FALSE);
3742 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3744 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3745 do_cmd_rerate(FALSE);
3748 /* Important -- Initialize the magic */
3749 mp_ptr = &m_info[p_ptr->pclass];
3752 /* Read spell info */
3753 rd_u32b(&p_ptr->spell_learned1);
3754 rd_u32b(&p_ptr->spell_learned2);
3755 rd_u32b(&p_ptr->spell_worked1);
3756 rd_u32b(&p_ptr->spell_worked2);
3757 rd_u32b(&p_ptr->spell_forgotten1);
3758 rd_u32b(&p_ptr->spell_forgotten2);
3760 if (z_older_than(10,0,5))
3762 p_ptr->learned_spells = 0;
3763 for (i = 0; i < 64; i++)
3765 /* Count known spells */
3767 (p_ptr->spell_learned1 & (1L << i)) :
3768 (p_ptr->spell_learned2 & (1L << (i - 32))))
3770 p_ptr->learned_spells++;
3774 else rd_s16b(&p_ptr->learned_spells);
3776 if (z_older_than(10,0,6))
3778 p_ptr->add_spells = 0;
3780 else rd_s16b(&p_ptr->add_spells);
3781 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3783 for (i = 0; i < 64; i++)
3785 rd_byte(&p_ptr->spell_order[i]);
3789 /* Read the inventory */
3792 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3796 /* Read number of towns */
3798 town_count = tmp16u;
3800 /* Read the stores */
3802 for (i = 1; i < town_count; i++)
3804 for (j = 0; j < tmp16u; j++)
3806 if (rd_store(i, j)) return (22);
3810 rd_s16b(&p_ptr->pet_follow_distance);
3811 if (z_older_than(10, 4, 10))
3813 p_ptr->pet_extra_flags = 0;
3815 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3817 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3819 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3823 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3826 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3830 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3833 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3837 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3840 if (!z_older_than(10,0,8))
3843 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3848 rd_s16b(&p_ptr->pet_extra_flags);
3851 if (!z_older_than(11, 0, 9))
3853 char buf[SCREEN_BUF_SIZE];
3854 rd_string(buf, sizeof(buf));
3855 if (buf[0]) screen_dump = string_make(buf);
3860 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3862 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3867 /* I'm not dead yet... */
3868 if (!p_ptr->is_dead)
3870 /* Dead players have no dungeon */
3871 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3875 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3879 /* Read the ghost info */
3886 strip_bytes(tmp32s);
3890 /* Quest 18 was removed */
3891 if (h_older_than(1, 7, 0, 6))
3893 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3895 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3897 p_ptr->inside_quest = 0;
3902 #ifdef VERIFY_CHECKSUMS
3904 /* Save the checksum */
3905 n_v_check = v_check;
3907 /* Read the old checksum */
3908 rd_u32b(&o_v_check);
3911 if (o_v_check != n_v_check)
3913 note(_("チェックサムがおかしい", "Invalid checksum"));
3918 /* Save the encoded checksum */
3919 n_x_check = x_check;
3921 /* Read the checksum */
3922 rd_u32b(&o_x_check);
3926 if (o_x_check != n_x_check)
3928 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3939 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3942 errr rd_savefile_new(void)
3946 /* Grab permissions */
3949 /* The savefile is a binary file */
3950 fff = my_fopen(savefile, "rb");
3952 /* Drop permissions */
3956 if (!fff) return (-1);
3958 /* Call the sub-function */
3959 err = rd_savefile_new_aux();
3961 /* Check for errors */
3962 if (ferror(fff)) err = -1;
3964 /* Close the file */
3973 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3974 * @param sf_ptr 保存フロア読み込み先
3977 static bool load_floor_aux(saved_floor_type *sf_ptr)
3982 #ifdef VERIFY_CHECKSUMS
3983 u32b n_x_check, n_v_check;
3984 u32b o_x_check, o_v_check;
3987 /* Hack -- decrypt (read xor_byte) */
3991 /* Clear the checksums */
3995 /* Set the version number to current version */
3996 /* Never load old temporal files */
3997 h_ver_extra = H_VER_EXTRA;
3998 h_ver_patch = H_VER_PATCH;
3999 h_ver_minor = H_VER_MINOR;
4000 h_ver_major = H_VER_MAJOR;
4002 /* Verify the sign */
4004 if (saved_floor_file_sign != tmp32u) return FALSE;
4006 /* Read -- have error? */
4007 if (rd_saved_floor(sf_ptr)) return FALSE;
4010 #ifdef VERIFY_CHECKSUMS
4011 /* Save the checksum */
4012 n_v_check = v_check;
4014 /* Read the old checksum */
4015 rd_u32b(&o_v_check);
4018 if (o_v_check != n_v_check) return FALSE;
4020 /* Save the encoded checksum */
4021 n_x_check = x_check;
4023 /* Read the checksum */
4024 rd_u32b(&o_x_check);
4027 if (o_x_check != n_x_check) return FALSE;
4036 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4037 * @param sf_ptr 保存フロア読み込み先
4041 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
4043 FILE *old_fff = NULL;
4044 byte old_xor_byte = 0;
4045 u32b old_v_check = 0;
4046 u32b old_x_check = 0;
4047 byte old_h_ver_major = 0;
4048 byte old_h_ver_minor = 0;
4049 byte old_h_ver_patch = 0;
4050 byte old_h_ver_extra = 0;
4053 char floor_savefile[1024];
4055 byte old_kanji_code = kanji_code;
4058 * Temporal files are always written in system depended kanji
4063 /* EUC kanji code */
4067 /* SJIS kanji code */
4076 /* We have one file already opened */
4077 if (mode & SLF_SECOND)
4079 /* Backup original values */
4081 old_xor_byte = xor_byte;
4082 old_v_check = v_check;
4083 old_x_check = x_check;
4084 old_h_ver_major = h_ver_major;
4085 old_h_ver_minor = h_ver_minor;
4086 old_h_ver_patch = h_ver_patch;
4087 old_h_ver_extra = h_ver_extra;
4090 /* floor savefile */
4091 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4093 /* Grab permissions */
4096 /* The savefile is a binary file */
4097 fff = my_fopen(floor_savefile, "rb");
4099 /* Drop permissions */
4103 if (!fff) ok = FALSE;
4105 /* Attempt to load */
4108 /* Load saved floor data from file */
4109 ok = load_floor_aux(sf_ptr);
4111 /* Check for errors */
4112 if (ferror(fff)) ok = FALSE;
4114 /* Close the file */
4117 /* Grab permissions */
4120 /* Delete the file */
4121 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4123 /* Drop permissions */
4127 /* We have one file already opened */
4128 if (mode & SLF_SECOND)
4130 /* Restore original values */
4132 xor_byte = old_xor_byte;
4133 v_check = old_v_check;
4134 x_check = old_x_check;
4135 h_ver_major = old_h_ver_major;
4136 h_ver_minor = old_h_ver_minor;
4137 h_ver_patch = old_h_ver_patch;
4138 h_ver_extra = old_h_ver_extra;
4141 /* Restore old knowledge */
4142 kanji_code = old_kanji_code;