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);
369 rd_byte(&o_ptr->number);
370 rd_s16b(&o_ptr->weight);
373 o_ptr->name1 = tmp8u;
376 o_ptr->name2 = tmp8u;
378 rd_s16b(&o_ptr->timeout);
380 rd_s16b(&o_ptr->to_h);
383 o_ptr->to_d = tmp16s;
384 rd_s16b(&o_ptr->to_a);
391 rd_byte(&o_ptr->ident);
393 rd_byte(&o_ptr->marked);
396 rd_u32b(&o_ptr->art_flags[0]);
397 rd_u32b(&o_ptr->art_flags[1]);
398 rd_u32b(&o_ptr->art_flags[2]);
399 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
400 else rd_u32b(&o_ptr->art_flags[3]);
402 if (h_older_than(1, 3, 0, 0))
404 if (o_ptr->name2 == EGO_TELEPATHY)
405 add_flag(o_ptr->art_flags, TR_TELEPATHY);
408 if (z_older_than(11, 0, 11))
410 o_ptr->curse_flags = 0L;
411 if (o_ptr->ident & 0x40)
413 o_ptr->curse_flags |= TRC_CURSED;
414 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
415 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
416 if (object_is_fixed_artifact(o_ptr))
418 artifact_type *a_ptr = &a_info[o_ptr->name1];
419 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
420 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
422 else if (object_is_ego(o_ptr))
424 ego_item_type *e_ptr = &e_info[o_ptr->name2];
425 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
426 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
429 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
433 rd_u32b(&o_ptr->curse_flags);
436 /* Monster holding object */
437 rd_s16b(&o_ptr->held_m_idx);
440 rd_byte(&o_ptr->xtra1);
441 rd_byte(&o_ptr->xtra2);
443 if (z_older_than(11, 0, 10))
445 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
447 switch (o_ptr->xtra2 % 6)
449 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
450 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
451 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
452 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
453 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
454 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
458 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
460 switch (o_ptr->xtra2 % 11)
462 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
463 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
464 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
465 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
466 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
467 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
468 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
469 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
470 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
471 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
472 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
476 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
478 switch (o_ptr->xtra2 % 8)
480 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
481 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
482 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
483 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
484 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
485 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
486 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
487 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
494 if (z_older_than(10, 2, 3))
499 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
501 o_ptr->xtra3 = o_ptr->xtra1;
504 if (o_ptr->tval == TV_CAPTURE)
506 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
507 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
509 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
510 if (ironman_nightmare)
512 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
514 o_ptr->xtra4 = o_ptr->xtra5;
519 rd_byte(&o_ptr->xtra3);
520 if (h_older_than(1, 3, 0, 1))
522 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
523 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
526 rd_s16b(&o_ptr->xtra4);
527 rd_s16b(&o_ptr->xtra5);
530 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)))
532 o_ptr->xtra4 = o_ptr->pval;
536 rd_byte(&o_ptr->feeling);
539 rd_string(buf, sizeof(buf));
541 /* Save the inscription */
542 if (buf[0]) o_ptr->inscription = quark_add(buf);
544 rd_string(buf, sizeof(buf));
545 if (buf[0]) o_ptr->art_name = quark_add(buf);
547 /* The Python object */
555 /* Mega-Hack -- handle "dungeon objects" later */
556 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
558 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
560 if (z_older_than(10, 4, 9))
562 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
564 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
565 add_flag(o_ptr->art_flags, TR_DEC_MANA);
570 if (object_is_fixed_artifact(o_ptr))
572 artifact_type *a_ptr;
574 /* Obtain the artifact info */
575 a_ptr = &a_info[o_ptr->name1];
577 /* Verify that artifact */
578 if (!a_ptr->name) o_ptr->name1 = 0;
582 if (object_is_ego(o_ptr))
584 ego_item_type *e_ptr;
586 /* Obtain the ego-item info */
587 e_ptr = &e_info[o_ptr->name2];
589 /* Verify that ego-item */
590 if (!e_ptr->name) o_ptr->name2 = 0;
597 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
598 * @param o_ptr アイテムオブジェクト保存先ポインタ
601 static void rd_item(object_type *o_ptr)
609 if (h_older_than(1, 5, 0, 0))
615 /*** Item save flags ***/
618 /*** Read un-obvious elements ***/
620 rd_s16b(&o_ptr->k_idx);
624 o_ptr->iy = (POSITION)tmp8u;
626 o_ptr->ix = (POSITION)tmp8u;
629 k_ptr = &k_info[o_ptr->k_idx];
630 o_ptr->tval = k_ptr->tval;
631 o_ptr->sval = k_ptr->sval;
634 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
635 else o_ptr->pval = 0;
637 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
638 else o_ptr->discount = 0;
639 if (flags & SAVE_ITEM_NUMBER) rd_byte(&o_ptr->number);
640 else o_ptr->number = 1;
642 rd_s16b(&o_ptr->weight);
644 if (flags & SAVE_ITEM_NAME1)
647 o_ptr->name1 = tmp8u;
649 else o_ptr->name1 = 0;
650 if (flags & SAVE_ITEM_NAME2)
653 o_ptr->name2 = tmp8u;
655 else o_ptr->name2 = 0;
656 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
657 else o_ptr->timeout = 0;
659 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
660 else o_ptr->to_h = 0;
661 if (flags & SAVE_ITEM_TO_D)
664 o_ptr->to_d = tmp16s;
666 else o_ptr->to_d = 0;
667 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
668 else o_ptr->to_a = 0;
670 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
673 if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
675 if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
678 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
679 else o_ptr->ident = 0;
681 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
682 else o_ptr->marked = 0;
685 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
686 else o_ptr->art_flags[0] = 0;
687 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
688 else o_ptr->art_flags[1] = 0;
689 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
690 else o_ptr->art_flags[2] = 0;
691 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
692 else o_ptr->art_flags[3] = 0;
693 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
694 else o_ptr->art_flags[4] = 0;
696 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
697 else o_ptr->curse_flags = 0;
699 /* Monster holding object */
700 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
701 else o_ptr->held_m_idx = 0;
704 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
705 else o_ptr->xtra1 = 0;
706 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
707 else o_ptr->xtra2 = 0;
709 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
710 else o_ptr->xtra3 = 0;
712 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
713 else o_ptr->xtra4 = 0;
714 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
715 else o_ptr->xtra5 = 0;
717 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
718 else o_ptr->feeling = 0;
720 if (flags & SAVE_ITEM_INSCRIPTION)
722 rd_string(buf, sizeof(buf));
723 o_ptr->inscription = quark_add(buf);
725 else o_ptr->inscription = 0;
727 if (flags & SAVE_ITEM_ART_NAME)
729 rd_string(buf, sizeof(buf));
730 o_ptr->art_name = quark_add(buf);
732 else o_ptr->art_name = 0;
734 if(h_older_than(2,1,2,4))
736 u32b flgs[TR_FLAG_SIZE];
737 object_flags(o_ptr, flgs);
739 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
741 add_flag(o_ptr->art_flags, TR_LITE_M1);
742 remove_flag(o_ptr->art_flags, TR_LITE_1);
743 remove_flag(o_ptr->art_flags, TR_LITE_2);
744 remove_flag(o_ptr->art_flags, TR_LITE_3);
746 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
748 if (o_ptr->tval == TV_LITE)
750 if (o_ptr->sval == SV_LITE_TORCH)
752 add_flag(o_ptr->art_flags, TR_LITE_M1);
754 else if (o_ptr->sval == SV_LITE_LANTERN)
756 add_flag(o_ptr->art_flags, TR_LITE_M2);
758 else if (o_ptr->sval == SV_LITE_FEANOR)
760 add_flag(o_ptr->art_flags, TR_LITE_M3);
766 add_flag(o_ptr->art_flags, TR_LITE_M1);
769 else if (o_ptr->tval == TV_LITE)
771 if (object_is_fixed_artifact(o_ptr))
773 add_flag(o_ptr->art_flags, TR_LITE_3);
775 else if (o_ptr->sval == SV_LITE_TORCH)
777 add_flag(o_ptr->art_flags, TR_LITE_1);
778 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
780 else if (o_ptr->sval == SV_LITE_LANTERN)
782 add_flag(o_ptr->art_flags, TR_LITE_2);
783 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
785 else if (o_ptr->sval == SV_LITE_FEANOR)
787 add_flag(o_ptr->art_flags, TR_LITE_2);
795 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
796 * @param m_ptr モンスター保存先ポインタ
799 static void rd_monster_old(monster_type *m_ptr)
805 /* Read the monster race */
806 rd_s16b(&m_ptr->r_idx);
808 if (z_older_than(11, 0, 12))
809 m_ptr->ap_r_idx = m_ptr->r_idx;
811 rd_s16b(&m_ptr->ap_r_idx);
813 if (z_older_than(11, 0, 14))
815 monster_race *r_ptr = &r_info[m_ptr->r_idx];
817 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
818 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
819 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
822 rd_byte(&m_ptr->sub_align);
824 /* Read the other information */
826 m_ptr->fy = (POSITION)tmp8u;
828 m_ptr->fx = (POSITION)tmp8u;
833 m_ptr->maxhp = tmp16s;
835 if (z_older_than(11, 0, 5))
837 m_ptr->max_maxhp = m_ptr->maxhp;
842 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
844 if(h_older_than(2, 1, 2, 1))
846 m_ptr->dealt_damage = 0;
850 rd_u32b(&m_ptr->dealt_damage);
853 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
854 rd_byte(&m_ptr->mspeed);
855 if (z_older_than(10, 4, 2))
858 m_ptr->energy_need = (s16b)tmp8u;
860 else rd_s16b(&m_ptr->energy_need);
862 if (z_older_than(11, 0, 13))
863 m_ptr->energy_need = 100 - m_ptr->energy_need;
865 if (z_older_than(10,0,7))
867 m_ptr->mtimed[MTIMED_FAST] = 0;
868 m_ptr->mtimed[MTIMED_SLOW] = 0;
873 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
875 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
878 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
880 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
882 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
884 if (z_older_than(10,0,10))
888 else if (z_older_than(10,0,11))
896 m_ptr->target_y = (POSITION)tmp16s;
898 m_ptr->target_x = (POSITION)tmp16s;
902 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
904 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
905 rd_u32b(&m_ptr->smart);
909 if (z_older_than(10, 4, 5))
912 rd_u32b(&m_ptr->exp);
914 if (z_older_than(10, 2, 2))
916 if (m_ptr->r_idx < 0)
918 m_ptr->r_idx = (0-m_ptr->r_idx);
919 m_ptr->mflag2 |= MFLAG2_KAGE;
924 rd_byte(&m_ptr->mflag2);
927 if (z_older_than(11, 0, 12))
929 if (m_ptr->mflag2 & MFLAG2_KAGE)
930 m_ptr->ap_r_idx = MON_KAGE;
933 if (z_older_than(10, 1, 3))
939 rd_string(buf, sizeof(buf));
940 if (buf[0]) m_ptr->nickname = quark_add(buf);
948 * @brief モンスターを読み込む(現版) / Read a monster (New method)
949 * @param m_ptr モンスター保存先ポインタ
952 static void rd_monster(monster_type *m_ptr)
959 if (h_older_than(1, 5, 0, 0))
961 rd_monster_old(m_ptr);
965 /*** Monster save flags ***/
968 /*** Read un-obvious elements ***/
970 /* Read the monster race */
971 rd_s16b(&m_ptr->r_idx);
973 /* Read the other information */
975 m_ptr->fy = (POSITION)tmp8u;
977 m_ptr->fx = (POSITION)tmp8u;
980 m_ptr->hp = (HIT_POINT)tmp16s;
982 m_ptr->maxhp = (HIT_POINT)tmp16s;
984 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
986 if(h_older_than(2, 1, 2, 1))
988 m_ptr->dealt_damage = 0;
992 rd_u32b(&m_ptr->dealt_damage);
995 /* Monster race index of its appearance */
996 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
997 else m_ptr->ap_r_idx = m_ptr->r_idx;
999 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1000 else m_ptr->sub_align = 0;
1002 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1003 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1005 rd_byte(&m_ptr->mspeed);
1007 rd_s16b(&m_ptr->energy_need);
1009 if (flags & SAVE_MON_FAST)
1012 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1014 else m_ptr->mtimed[MTIMED_FAST] = 0;
1015 if (flags & SAVE_MON_SLOW)
1018 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1020 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1021 if (flags & SAVE_MON_STUNNED)
1024 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1026 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1027 if (flags & SAVE_MON_CONFUSED)
1030 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1032 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1033 if (flags & SAVE_MON_MONFEAR)
1036 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1038 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1040 if (flags & SAVE_MON_TARGET_Y)
1043 m_ptr->target_y = (POSITION)tmp16s;
1045 else m_ptr->target_y = 0;
1046 if (flags & SAVE_MON_TARGET_X)
1049 m_ptr->target_x = (POSITION)tmp16s;
1051 else m_ptr->target_x = 0;
1053 if (flags & SAVE_MON_INVULNER)
1056 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1058 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1060 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1061 else m_ptr->smart = 0;
1063 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
1064 else m_ptr->exp = 0;
1066 m_ptr->mflag = 0; /* Not saved */
1068 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1069 else m_ptr->mflag2 = 0;
1071 if (flags & SAVE_MON_NICKNAME)
1073 rd_string(buf, sizeof(buf));
1074 m_ptr->nickname = quark_add(buf);
1076 else m_ptr->nickname = 0;
1078 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1079 else m_ptr->parent_m_idx = 0;
1084 * Old monster bit flags of racial resistances
1086 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1087 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1088 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1089 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1090 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1091 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1092 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1093 #define RF3_RES_WATE 0x00800000 /* Resist water */
1094 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1095 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1096 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1097 #define RF3_RES_ALL 0x08000000 /* Resist all */
1099 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1101 if ((R_PTR)->r_flags3 & (RF3)) \
1103 (R_PTR)->r_flags3 &= ~(RF3); \
1104 (R_PTR)->r_flagsr |= (RFR); \
1108 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1110 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1112 (R_PTR)->r_flagsr |= (RFR); \
1116 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1117 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1118 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1119 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1120 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1121 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1122 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1123 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1124 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1125 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1128 * @brief モンスターの思い出を読み込む / Read the monster lore
1129 * @param r_idx 読み込み先モンスターID
1132 static void rd_lore(int r_idx)
1136 monster_race *r_ptr = &r_info[r_idx];
1138 /* Count sights/deaths/kills */
1139 rd_s16b(&r_ptr->r_sights);
1140 rd_s16b(&r_ptr->r_deaths);
1141 rd_s16b(&r_ptr->r_pkills);
1142 if (h_older_than(1, 7, 0, 5))
1144 r_ptr->r_akills = r_ptr->r_pkills;
1148 rd_s16b(&r_ptr->r_akills);
1150 rd_s16b(&r_ptr->r_tkills);
1152 /* Count wakes and ignores */
1153 rd_byte(&r_ptr->r_wake);
1154 rd_byte(&r_ptr->r_ignore);
1157 rd_byte(&r_ptr->r_xtra1);
1158 rd_byte(&r_ptr->r_xtra2);
1161 rd_byte(&r_ptr->r_drop_gold);
1162 rd_byte(&r_ptr->r_drop_item);
1166 rd_byte(&r_ptr->r_cast_spell);
1168 /* Count blows of each type */
1169 rd_byte(&r_ptr->r_blows[0]);
1170 rd_byte(&r_ptr->r_blows[1]);
1171 rd_byte(&r_ptr->r_blows[2]);
1172 rd_byte(&r_ptr->r_blows[3]);
1174 /* Memorize flags */
1175 rd_u32b(&r_ptr->r_flags1);
1176 rd_u32b(&r_ptr->r_flags2);
1177 rd_u32b(&r_ptr->r_flags3);
1178 rd_u32b(&r_ptr->r_flags4);
1179 rd_u32b(&r_ptr->r_flags5);
1180 rd_u32b(&r_ptr->r_flags6);
1181 if (h_older_than(1, 5, 0, 3))
1183 r_ptr->r_flagsr = 0L;
1185 /* Move RF3 resistance flags to RFR */
1186 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1187 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1188 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1189 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1190 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1191 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1192 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1193 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1194 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1195 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1196 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1197 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1199 /* Separate breathers resistance from RF4 to RFR */
1200 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1201 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1202 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1203 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1204 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1205 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1206 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1207 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1208 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1210 /* Resist confusion is merged to RF3_NO_CONF */
1211 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1213 /* Misc resistance hack to RFR */
1214 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1215 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1219 rd_u32b(&r_ptr->r_flagsr);
1222 /* Read the "Racial" monster limit per level */
1223 rd_byte(&r_ptr->max_num);
1225 /* Location in saved floor */
1226 rd_s16b(&r_ptr->floor_id);
1231 /* Repair the lore flags */
1232 r_ptr->r_flags1 &= r_ptr->flags1;
1233 r_ptr->r_flags2 &= r_ptr->flags2;
1234 r_ptr->r_flags3 &= r_ptr->flags3;
1235 r_ptr->r_flags4 &= r_ptr->flags4;
1236 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1237 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1238 r_ptr->r_flagsr &= r_ptr->flagsr;
1242 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1243 * @param st_ptr 店舗の参照ポインタ
1244 * @param o_ptr アイテムオブジェクト参照ポインタ
1247 * In all cases, return the slot (or -1) where the object was placed
1249 * Note that this is a hacked up version of "inven_carry()".
1251 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1252 * known, the player may have to pick stuff up and drop it again.
1254 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1262 /* Check each existing item (try to combine) */
1263 for (slot = 0; slot < st_ptr->stock_num; slot++)
1265 /* Get the existing item */
1266 j_ptr = &st_ptr->stock[slot];
1268 /* The home acts just like the player */
1269 if (object_similar(j_ptr, o_ptr))
1271 /* Save the new number of items */
1272 object_absorb(j_ptr, o_ptr);
1280 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1284 /* Determine the "value" of the item */
1285 value = object_value(o_ptr);
1287 /* Check existing slots to see if we must "slide" */
1288 for (slot = 0; slot < st_ptr->stock_num; slot++)
1290 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1293 /* Slide the others up */
1294 for (i = st_ptr->stock_num; i > slot; i--)
1296 st_ptr->stock[i] = st_ptr->stock[i-1];
1299 /* More stuff now */
1300 st_ptr->stock_num++;
1302 /* Insert the new item */
1303 st_ptr->stock[slot] = *o_ptr;
1305 chg_virtue(V_SACRIFICE, -1);
1307 /* Return the location */
1312 * @brief 店舗情報を読み込む / Read a store
1313 * @param town_number 街ID
1314 * @param store_number 店舗ID
1317 static errr rd_store(int town_number, int store_number)
1329 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1331 st_ptr = &town[1].store[store_number];
1332 if (st_ptr->stock_num) sort = TRUE;
1336 st_ptr = &town[town_number].store[store_number];
1339 /* Read the basic info */
1340 rd_s32b(&st_ptr->store_open);
1341 rd_s16b(&st_ptr->insult_cur);
1343 if (z_older_than(11, 0, 4))
1352 rd_s16b(&st_ptr->good_buy);
1353 rd_s16b(&st_ptr->bad_buy);
1355 /* Read last visit */
1356 rd_s32b(&st_ptr->last_visit);
1358 /* Extract the owner (see above) */
1359 st_ptr->owner = own;
1361 /* Read the items */
1362 for (j = 0; j < num; j++)
1367 /* Get local object */
1370 /* Wipe the object */
1376 /* Acquire valid items */
1377 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1382 home_carry(st_ptr, q_ptr);
1386 k = st_ptr->stock_num++;
1388 /* Acquire the item */
1389 object_copy(&st_ptr->stock[k], q_ptr);
1400 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1403 static void rd_randomizer(void)
1413 rd_u16b(&Rand_place);
1416 for (i = 0; i < RAND_DEG; i++)
1418 rd_u32b(&Rand_state[i]);
1425 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1428 * Note that the normal options are now stored as a set of 256 bit flags,
1429 * plus a set of 256 bit masks to indicate which bit flags were defined
1430 * at the time the savefile was created. This will allow new options
1431 * to be added, and old options to be removed, at any time, without
1432 * hurting old savefiles.
1434 * The window options are stored in the same way, but note that each
1435 * window gets 32 options, and their order is fixed by certain defines.
1437 static void rd_options(void)
1451 /* Ignore old options */
1455 /*** Special info */
1457 /* Read "delay_factor" */
1461 /* Read "hitpoint_warn" */
1465 /* Read "mana_warn" */
1466 if(h_older_than(1, 7, 0, 0))
1477 /*** Cheating options ***/
1481 if (c & 0x0002) p_ptr->wizard = TRUE;
1483 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1484 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1485 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1486 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1487 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1488 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1489 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1490 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1491 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1493 rd_byte((byte *)&autosave_l);
1494 rd_byte((byte *)&autosave_t);
1495 rd_s16b(&autosave_freq);
1498 /*** Normal Options ***/
1500 /* Read the option flags */
1501 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1503 /* Read the option masks */
1504 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1506 /* Analyze the options */
1507 for (n = 0; n < 8; n++)
1509 /* Analyze the options */
1510 for (i = 0; i < 32; i++)
1512 /* Process valid flags */
1513 if (mask[n] & (1L << i))
1515 /* Process valid flags */
1516 if (option_mask[n] & (1L << i))
1519 if (flag[n] & (1L << i))
1522 option_flag[n] |= (1L << i);
1529 option_flag[n] &= ~(1L << i);
1536 if (z_older_than(10, 4, 5))
1538 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1539 else option_flag[5] |= (0x00000001 << 4);
1540 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1541 else option_flag[2] |= (0x00000001 << 5);
1542 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1543 else option_flag[4] |= (0x00000001 << 5);
1544 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1545 else option_flag[5] |= (0x00000001 << 0);
1546 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1547 else option_flag[5] |= (0x00000001 << 12);
1548 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1549 else option_flag[1] |= (0x00000001 << 0);
1550 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1551 else option_flag[1] |= (0x00000001 << 18);
1552 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1553 else option_flag[1] |= (0x00000001 << 19);
1554 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1555 else option_flag[5] |= (0x00000001 << 3);
1558 /* Extract the options */
1559 extract_option_vars();
1562 /*** Window Options ***/
1564 /* Read the window flags */
1565 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1567 /* Read the window masks */
1568 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1570 /* Analyze the options */
1571 for (n = 0; n < 8; n++)
1573 /* Analyze the options */
1574 for (i = 0; i < 32; i++)
1576 /* Process valid flags */
1577 if (mask[n] & (1L << i))
1579 /* Process valid flags */
1580 if (window_mask[n] & (1L << i))
1583 if (flag[n] & (1L << i))
1586 window_flag[n] |= (1L << i);
1593 window_flag[n] &= ~(1L << i);
1604 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1607 * XXX XXX XXX This is such a nasty hack it hurts.
1609 static void rd_ghost(void)
1614 rd_string(buf, sizeof(buf));
1616 /* Strip old data */
1622 * @brief クイックスタート情報を読み込む / Load quick start data
1625 static void load_quick_start(void)
1630 if (z_older_than(11, 0, 13))
1632 previous_char.quick_ok = FALSE;
1636 rd_byte(&previous_char.psex);
1637 rd_byte(&previous_char.prace);
1638 rd_byte(&previous_char.pclass);
1639 rd_byte(&previous_char.pseikaku);
1640 rd_byte(&previous_char.realm1);
1641 rd_byte(&previous_char.realm2);
1643 rd_s16b(&previous_char.age);
1644 rd_s16b(&previous_char.ht);
1645 rd_s16b(&previous_char.wt);
1646 rd_s16b(&previous_char.sc);
1647 rd_s32b(&previous_char.au);
1649 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1650 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1652 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1654 rd_s16b(&previous_char.chaos_patron);
1656 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1658 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1660 /* UNUSED : Was number of random quests */
1664 previous_char.quick_ok = (bool)tmp8u;
1668 * @brief その他の情報を読み込む / Read the "extra" information
1671 static void rd_extra(void)
1679 rd_string(p_ptr->name, sizeof(p_ptr->name));
1681 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1683 if (!h_older_than(1, 7, 0, 1))
1687 /* Read the message */
1688 rd_string(buf, sizeof buf);
1689 if (buf[0]) p_ptr->last_message = string_make(buf);
1694 for (i = 0; i < 4; i++)
1696 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1699 /* Class/Race/Seikaku/Gender/Spells */
1700 rd_byte(&p_ptr->prace);
1701 rd_byte(&p_ptr->pclass);
1702 rd_byte(&p_ptr->pseikaku);
1703 rd_byte(&p_ptr->psex);
1704 rd_byte(&p_ptr->realm1);
1705 rd_byte(&p_ptr->realm2);
1706 rd_byte(&tmp8u); /* oops */
1708 if (z_older_than(10, 4, 4))
1710 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1711 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1712 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1713 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1716 /* Special Race/Class info */
1718 p_ptr->hitdie = tmp8u;
1719 rd_u16b(&p_ptr->expfact);
1721 /* Age/Height/Weight */
1722 rd_s16b(&p_ptr->age);
1723 rd_s16b(&p_ptr->ht);
1724 rd_s16b(&p_ptr->wt);
1726 /* Read the stat info */
1727 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1728 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1729 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1731 strip_bytes(24); /* oops */
1733 rd_s32b(&p_ptr->au);
1735 rd_s32b(&p_ptr->max_exp);
1736 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1737 else rd_s32b(&p_ptr->max_max_exp);
1738 rd_s32b(&p_ptr->exp);
1740 if (h_older_than(1, 7, 0, 3))
1743 p_ptr->exp_frac = (u32b)tmp16u;
1747 rd_u32b(&p_ptr->exp_frac);
1750 rd_s16b(&p_ptr->lev);
1752 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1753 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1755 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1757 if (z_older_than(10, 3, 6))
1758 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1760 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1761 for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1762 if (z_older_than(10, 4, 1))
1764 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1765 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1767 if (z_older_than(10, 3, 14))
1769 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1770 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1774 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1775 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1776 if (h_older_than(1, 3, 0, 1))
1778 if (p_ptr->pclass == CLASS_SMITH)
1780 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1781 p_ptr->magic_num1[96] = 0;
1782 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1783 p_ptr->magic_num1[97] = 0;
1787 if (music_singing_any()) p_ptr->action = ACTION_SING;
1789 if (z_older_than(11, 0, 7))
1791 p_ptr->start_race = p_ptr->prace;
1792 p_ptr->old_race1 = 0L;
1793 p_ptr->old_race2 = 0L;
1794 p_ptr->old_realm = 0;
1798 rd_byte(&p_ptr->start_race);
1799 rd_s32b(&p_ptr->old_race1);
1800 rd_s32b(&p_ptr->old_race2);
1801 rd_s16b(&p_ptr->old_realm);
1804 if (z_older_than(10, 0, 1))
1806 for (i = 0; i < MAX_MANE; i++)
1808 p_ptr->mane_spell[i] = -1;
1809 p_ptr->mane_dam[i] = 0;
1811 p_ptr->mane_num = 0;
1813 else if (z_older_than(10, 2, 3))
1815 for (i = 0; i < OLD_MAX_MANE; i++)
1820 for (i = 0; i < MAX_MANE; i++)
1822 p_ptr->mane_spell[i] = -1;
1823 p_ptr->mane_dam[i] = 0;
1826 p_ptr->mane_num = 0;
1830 for (i = 0; i < MAX_MANE; i++)
1832 rd_s16b(&p_ptr->mane_spell[i]);
1833 rd_s16b(&p_ptr->mane_dam[i]);
1835 rd_s16b(&p_ptr->mane_num);
1838 if (z_older_than(10, 0, 3))
1840 determine_bounty_uniques();
1842 for (i = 0; i < MAX_KUBI; i++)
1844 /* Is this bounty unique already dead? */
1845 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1850 for (i = 0; i < MAX_KUBI; i++)
1852 rd_s16b(&kubi_r_idx[i]);
1856 if (z_older_than(10, 0, 3))
1862 for (i = 0; i < 4; i++)
1864 rd_s16b(&battle_mon[i]);
1865 if (z_older_than(10, 3, 4))
1868 mon_odds[i] = tmp16s;
1870 else rd_u32b(&mon_odds[i]);
1874 rd_s16b(&p_ptr->town_num);
1876 /* Read arena and rewards information */
1877 rd_s16b(&p_ptr->arena_number);
1878 if (h_older_than(1, 5, 0, 1))
1880 /* Arena loser of previous version was marked number 99 */
1881 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1884 p_ptr->inside_arena = (bool)tmp16s;
1885 rd_s16b(&p_ptr->inside_quest);
1886 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1890 p_ptr->inside_battle = (bool)tmp16s;
1892 rd_byte(&p_ptr->exit_bldg);
1896 p_ptr->oldpx = (POSITION)tmp16s;
1898 p_ptr->oldpy = (POSITION)tmp16s;
1900 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1902 /* Was p_ptr->rewards[MAX_BACT] */
1904 for (i = 0; i < tmp16s; i++)
1910 if (h_older_than(1, 7, 0, 3))
1913 p_ptr->mhp = tmp16s;
1916 p_ptr->chp = tmp16s;
1919 p_ptr->chp_frac = (u32b)tmp16u;
1923 rd_s32b(&p_ptr->mhp);
1924 rd_s32b(&p_ptr->chp);
1925 rd_u32b(&p_ptr->chp_frac);
1928 if (h_older_than(1, 7, 0, 3))
1931 p_ptr->msp = tmp16s;
1934 p_ptr->csp = tmp16s;
1937 p_ptr->csp_frac = (u32b)tmp16u;
1941 rd_s32b(&p_ptr->msp);
1942 rd_s32b(&p_ptr->csp);
1943 rd_u32b(&p_ptr->csp_frac);
1946 rd_s16b(&p_ptr->max_plv);
1947 if (z_older_than(10, 3, 8))
1950 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1954 byte max = (byte)max_d_idx;
1958 for(i = 0; i < max; i++)
1961 max_dlv[i] = tmp16s;
1962 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1966 /* Repair maximum player level XXX XXX XXX */
1967 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1971 rd_s16b(&p_ptr->sc);
1972 rd_s16b(&p_ptr->concent);
1974 /* Read the flags */
1975 strip_bytes(2); /* Old "rest" */
1976 rd_s16b(&p_ptr->blind);
1977 rd_s16b(&p_ptr->paralyzed);
1978 rd_s16b(&p_ptr->confused);
1979 rd_s16b(&p_ptr->food);
1980 strip_bytes(4); /* Old "food_digested" / "protection" */
1982 rd_s16b(&p_ptr->energy_need);
1983 if (z_older_than(11, 0, 13))
1984 p_ptr->energy_need = 100 - p_ptr->energy_need;
1985 if (h_older_than(2, 1, 2, 0))
1986 p_ptr->enchant_energy_need = 0;
1988 rd_s16b(&p_ptr->enchant_energy_need);
1990 rd_s16b(&p_ptr->fast);
1991 rd_s16b(&p_ptr->slow);
1992 rd_s16b(&p_ptr->afraid);
1993 rd_s16b(&p_ptr->cut);
1994 rd_s16b(&p_ptr->stun);
1995 rd_s16b(&p_ptr->poisoned);
1996 rd_s16b(&p_ptr->image);
1997 rd_s16b(&p_ptr->protevil);
1998 rd_s16b(&p_ptr->invuln);
1999 if(z_older_than(10, 0, 0))
2002 rd_s16b(&p_ptr->ult_res);
2003 rd_s16b(&p_ptr->hero);
2004 rd_s16b(&p_ptr->shero);
2005 rd_s16b(&p_ptr->shield);
2006 rd_s16b(&p_ptr->blessed);
2007 rd_s16b(&p_ptr->tim_invis);
2008 rd_s16b(&p_ptr->word_recall);
2009 if (z_older_than(10, 3, 8))
2010 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2014 p_ptr->recall_dungeon = (byte)tmp16s;
2017 if (h_older_than(1, 5, 0, 0))
2018 p_ptr->alter_reality = 0;
2020 rd_s16b(&p_ptr->alter_reality);
2022 rd_s16b(&p_ptr->see_infra);
2023 rd_s16b(&p_ptr->tim_infra);
2024 rd_s16b(&p_ptr->oppose_fire);
2025 rd_s16b(&p_ptr->oppose_cold);
2026 rd_s16b(&p_ptr->oppose_acid);
2027 rd_s16b(&p_ptr->oppose_elec);
2028 rd_s16b(&p_ptr->oppose_pois);
2029 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2030 else rd_s16b(&p_ptr->tsuyoshi);
2032 /* Old savefiles do not have the following fields... */
2033 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2036 p_ptr->wraith_form = 0;
2037 p_ptr->resist_magic = 0;
2038 p_ptr->tim_regen = 0;
2039 p_ptr->kabenuke = 0;
2040 p_ptr->tim_stealth = 0;
2041 p_ptr->tim_levitation = 0;
2042 p_ptr->tim_sh_touki = 0;
2043 p_ptr->lightspeed = 0;
2044 p_ptr->tsubureru = 0;
2045 p_ptr->tim_res_nether = 0;
2046 p_ptr->tim_res_time = 0;
2047 p_ptr->mimic_form = 0;
2048 p_ptr->tim_mimic = 0;
2049 p_ptr->tim_sh_fire = 0;
2052 p_ptr->tim_reflect = 0;
2053 p_ptr->multishadow = 0;
2054 p_ptr->dustrobe = 0;
2056 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2064 rd_s16b(&p_ptr->tim_esp);
2065 rd_s16b(&p_ptr->wraith_form);
2066 rd_s16b(&p_ptr->resist_magic);
2067 rd_s16b(&p_ptr->tim_regen);
2068 rd_s16b(&p_ptr->kabenuke);
2069 rd_s16b(&p_ptr->tim_stealth);
2070 rd_s16b(&p_ptr->tim_levitation);
2071 rd_s16b(&p_ptr->tim_sh_touki);
2072 rd_s16b(&p_ptr->lightspeed);
2073 rd_s16b(&p_ptr->tsubureru);
2074 if (z_older_than(10, 4, 7))
2075 p_ptr->magicdef = 0;
2077 rd_s16b(&p_ptr->magicdef);
2078 rd_s16b(&p_ptr->tim_res_nether);
2079 if (z_older_than(10, 4, 11))
2081 p_ptr->tim_res_time = 0;
2082 p_ptr->mimic_form = 0;
2083 p_ptr->tim_mimic = 0;
2084 p_ptr->tim_sh_fire = 0;
2088 rd_s16b(&p_ptr->tim_res_time);
2089 rd_byte(&p_ptr->mimic_form);
2090 rd_s16b(&p_ptr->tim_mimic);
2091 rd_s16b(&p_ptr->tim_sh_fire);
2094 if (z_older_than(11, 0, 99))
2096 p_ptr->tim_sh_holy = 0;
2097 p_ptr->tim_eyeeye = 0;
2101 rd_s16b(&p_ptr->tim_sh_holy);
2102 rd_s16b(&p_ptr->tim_eyeeye);
2106 if ( z_older_than(11,0,3) ){
2107 p_ptr->tim_reflect=0;
2108 p_ptr->multishadow=0;
2112 rd_s16b(&p_ptr->tim_reflect);
2113 rd_s16b(&p_ptr->multishadow);
2114 rd_s16b(&p_ptr->dustrobe);
2117 rd_s16b(&p_ptr->chaos_patron);
2118 rd_u32b(&p_ptr->muta1);
2119 rd_u32b(&p_ptr->muta2);
2120 rd_u32b(&p_ptr->muta3);
2122 for (i = 0; i < 8; i++)
2123 rd_s16b(&p_ptr->virtues[i]);
2124 for (i = 0; i < 8; i++)
2125 rd_s16b(&p_ptr->vir_types[i]);
2128 /* Calc the regeneration modifier for mutations */
2129 mutant_regenerate_mod = calc_mutant_regenerate_mod();
2131 if (z_older_than(10,0,9))
2134 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2135 p_ptr->ele_attack = 0;
2139 rd_s16b(&p_ptr->ele_attack);
2140 rd_u32b(&p_ptr->special_attack);
2142 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2143 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2144 if (z_older_than(10,0,12))
2146 p_ptr->ele_immune = 0;
2147 p_ptr->special_defense = 0;
2151 rd_s16b(&p_ptr->ele_immune);
2152 rd_u32b(&p_ptr->special_defense);
2154 rd_byte(&p_ptr->knowledge);
2157 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2159 rd_byte(&tmp8u); /* oops */
2160 rd_byte(&p_ptr->action);
2161 if (!z_older_than(10, 4, 3))
2164 if (tmp8u) p_ptr->action = ACTION_LEARN;
2166 rd_byte((byte *)&preserve_mode);
2167 rd_byte((byte *)&p_ptr->wait_report_score);
2170 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2172 /* Skip the flags */
2176 /* Hack -- the two "special seeds" */
2177 rd_u32b(&seed_flavor);
2178 rd_u32b(&seed_town);
2182 rd_u16b(&p_ptr->panic_save);
2183 rd_u16b(&p_ptr->total_winner);
2184 rd_u16b(&p_ptr->noscore);
2189 p_ptr->is_dead = tmp8u;
2191 /* Read "feeling" */
2192 rd_byte(&p_ptr->feeling);
2194 switch (p_ptr->start_race)
2200 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2203 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2206 dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2208 /* Turn when level began */
2211 if (h_older_than(1, 7, 0, 4))
2213 p_ptr->feeling_turn = old_turn;
2217 /* Turn of last "feeling" */
2218 rd_s32b(&p_ptr->feeling_turn);
2224 if (z_older_than(10, 3, 12))
2226 dungeon_turn = turn;
2228 else rd_s32b(&dungeon_turn);
2230 if (z_older_than(11, 0, 13))
2233 p_ptr->feeling_turn /= 2;
2238 if (z_older_than(10, 3, 13))
2242 else rd_s32b(&old_battle);
2244 if (z_older_than(10,0,3))
2246 determine_today_mon(TRUE);
2250 rd_s16b(&today_mon);
2251 rd_s16b(&p_ptr->today_mon);
2254 if (z_older_than(10,0,7))
2260 rd_s16b(&p_ptr->riding);
2263 /* Current floor_id */
2264 if (h_older_than(1, 5, 0, 0))
2266 p_ptr->floor_id = 0;
2270 rd_s16b(&p_ptr->floor_id);
2273 if (h_older_than(1, 5, 0, 2))
2279 /* Get number of party_mon array */
2282 /* Strip old temporary preserved pets */
2283 for (i = 0; i < tmp16s; i++)
2285 monster_type dummy_mon;
2287 rd_monster(&dummy_mon);
2291 if (z_older_than(10,1,2))
2300 if (z_older_than(10,3,9))
2304 else if (z_older_than(10, 3, 10))
2312 rd_s32b(&p_ptr->visit);
2314 if (!z_older_than(11, 0, 5))
2316 rd_u32b(&p_ptr->count);
2322 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2325 * Note that the inventory changed in Angband 2.7.4. Two extra
2326 * pack slots were added and the equipment was rearranged. Note
2327 * that these two features combine when parsing old save-files, in
2328 * which items from the old "aux" slot are "carried", perhaps into
2329 * one of the two new "inventory" slots.
2331 * Note that the inventory is "re-sorted" later by "dungeon()".
2333 static errr rd_inventory(void)
2341 p_ptr->total_weight = 0;
2347 /* Read until done */
2352 /* Get the next item index */
2355 /* Nope, we reached the end */
2356 if (n == 0xFFFF) break;
2358 /* Get local object */
2361 /* Wipe the object */
2367 /* Hack -- verify item */
2368 if (!q_ptr->k_idx) return (53);
2370 /* Wield equipment */
2371 if (n >= INVEN_RARM)
2373 /* Player touches it */
2374 q_ptr->marked |= OM_TOUCHED;
2377 object_copy(&inventory[n], q_ptr);
2379 /* Add the weight */
2380 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2386 /* Warning -- backpack is full */
2387 else if (inven_cnt == INVEN_PACK)
2390 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
2396 /* Carry inventory */
2402 /* Player touches it */
2403 q_ptr->marked |= OM_TOUCHED;
2406 object_copy(&inventory[n], q_ptr);
2408 /* Add the weight */
2409 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2422 * @brief メッセージログを読み込む / Read the saved messages
2425 static void rd_messages(void)
2431 if (h_older_than(2, 2, 0, 75))
2437 /* Read the messages */
2438 for (i = 0; i < num; i++)
2440 /* Read the message */
2441 rd_string(buf, sizeof(buf));
2443 /* Save the message */
2453 /* Read the messages */
2454 for (i = 0; i < num; i++)
2456 /* Read the message */
2457 rd_string(buf, sizeof(buf));
2459 /* Save the message */
2468 /* Old hidden trap flag */
2469 #define CAVE_TRAP 0x8000
2471 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2472 #define OLD_FEAT_INVIS 0x02
2473 #define OLD_FEAT_GLYPH 0x03
2474 #define OLD_FEAT_QUEST_ENTER 0x08
2475 #define OLD_FEAT_QUEST_EXIT 0x09
2476 #define OLD_FEAT_MINOR_GLYPH 0x40
2477 #define OLD_FEAT_BLDG_1 0x81
2478 #define OLD_FEAT_MIRROR 0xc3
2481 #define OLD_QUEST_WATER_CAVE 18
2483 /* Quest constants */
2484 #define QUEST_OLD_CASTLE 27
2485 #define QUEST_ROYAL_CRYPT 28
2488 * @brief メッセージログを読み込む / Read the dungeon (old method)
2491 * The monsters/objects must be loaded in the same order
2492 * that they were stored, since the actual indexes matter.
2494 static errr rd_dungeon_old(void)
2505 /*** Basic info ***/
2509 dun_level = (DEPTH)tmp16s;
2510 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2511 else rd_byte(&dungeon_type);
2513 /* Set the base level for old versions */
2514 base_level = dun_level;
2517 base_level = (DEPTH)tmp16s;
2519 rd_s16b(&num_repro);
2521 p_ptr->y = (int)tmp16s;
2523 p_ptr->x = (int)tmp16s;
2524 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2526 cur_hgt = (POSITION)tmp16s;
2528 cur_wid = (POSITION)tmp16s;
2529 rd_s16b(&tmp16s); /* max_panel_rows */
2530 rd_s16b(&tmp16s); /* max_panel_cols */
2533 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2541 /*** Run length decoding ***/
2543 /* Load the dungeon data */
2544 for (x = y = 0; y < ymax; )
2550 if (z_older_than(10,3,6))
2559 /* Decline invalid flags */
2560 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2563 /* Apply the RLE info */
2564 for (i = count; i > 0; i--)
2566 /* Access the cave */
2567 c_ptr = &cave[y][x];
2569 /* Extract "info" */
2579 if (++y >= ymax) break;
2585 /*** Run length decoding ***/
2587 /* Load the dungeon data */
2588 for (x = y = 0; y < ymax; )
2594 /* Apply the RLE info */
2595 for (i = count; i > 0; i--)
2597 /* Access the cave */
2598 c_ptr = &cave[y][x];
2600 /* Extract "feat" */
2601 c_ptr->feat = (s16b)tmp8u;
2610 if (++y >= ymax) break;
2615 /*** Run length decoding ***/
2617 /* Load the dungeon data */
2618 for (x = y = 0; y < ymax; )
2624 /* Apply the RLE info */
2625 for (i = count; i > 0; i--)
2627 /* Access the cave */
2628 c_ptr = &cave[y][x];
2630 /* Extract "mimic" */
2631 c_ptr->mimic = (s16b)tmp8u;
2640 if (++y >= ymax) break;
2645 /*** Run length decoding ***/
2647 /* Load the dungeon data */
2648 for (x = y = 0; y < ymax; )
2654 /* Apply the RLE info */
2655 for (i = count; i > 0; i--)
2657 /* Access the cave */
2658 c_ptr = &cave[y][x];
2660 /* Extract "feat" */
2661 c_ptr->special = tmp16s;
2670 if (++y >= ymax) break;
2675 /* Convert cave data */
2676 if (z_older_than(11, 0, 99))
2678 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2680 /* Wipe old unused flags */
2681 cave[y][x].info &= ~(CAVE_MASK);
2685 if (h_older_than(1, 1, 1, 0))
2687 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2689 /* Access the cave */
2690 c_ptr = &cave[y][x];
2693 if (c_ptr->feat == OLD_FEAT_INVIS)
2695 c_ptr->feat = feat_floor;
2696 c_ptr->info |= CAVE_TRAP;
2699 /* Older than 1.1.1 */
2700 if (c_ptr->feat == OLD_FEAT_MIRROR)
2702 c_ptr->feat = feat_floor;
2703 c_ptr->info |= CAVE_OBJECT;
2708 if (h_older_than(1, 3, 1, 0))
2710 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2712 /* Access the cave */
2713 c_ptr = &cave[y][x];
2715 /* Old CAVE_IN_MIRROR flag */
2716 if (c_ptr->info & CAVE_OBJECT)
2718 c_ptr->mimic = feat_mirror;
2721 /* Runes will be mimics and flags */
2722 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2723 (c_ptr->feat == OLD_FEAT_GLYPH))
2725 c_ptr->info |= CAVE_OBJECT;
2726 c_ptr->mimic = c_ptr->feat;
2727 c_ptr->feat = feat_floor;
2730 /* Hidden traps will be trap terrains mimicing floor */
2731 else if (c_ptr->info & CAVE_TRAP)
2733 c_ptr->info &= ~CAVE_TRAP;
2734 c_ptr->mimic = c_ptr->feat;
2735 c_ptr->feat = choose_random_trap();
2738 /* Another hidden trap */
2739 else if (c_ptr->feat == OLD_FEAT_INVIS)
2741 c_ptr->mimic = feat_floor;
2742 c_ptr->feat = feat_trap_open;
2747 /* Quest 18 was removed */
2748 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2750 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2752 /* Access the cave */
2753 c_ptr = &cave[y][x];
2755 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2757 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2759 c_ptr->feat = feat_tree;
2762 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2764 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2767 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2768 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2770 c_ptr->feat = feat_up_stair;
2778 /* Read the item count */
2781 /* Verify maximum */
2782 if (limit > max_o_idx)
2784 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2788 /* Read the dungeon items */
2789 for (i = 1; i < limit; i++)
2796 /* Get a new record */
2802 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2808 o_ptr = &o_list[o_idx];
2814 /* XXX XXX XXX XXX XXX */
2817 if (o_ptr->held_m_idx)
2819 monster_type *m_ptr;
2822 m_ptr = &m_list[o_ptr->held_m_idx];
2825 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2827 /* Place the object */
2828 m_ptr->hold_o_idx = o_idx;
2834 /* Access the item location */
2835 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2838 o_ptr->next_o_idx = c_ptr->o_idx;
2840 /* Place the object */
2841 c_ptr->o_idx = o_idx;
2848 /* Read the monster count */
2851 /* Hack -- verify */
2852 if (limit > max_m_idx)
2854 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2858 /* Read the monsters */
2859 for (i = 1; i < limit; i++)
2862 monster_type *m_ptr;
2864 /* Get a new record */
2870 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2875 /* Acquire monster */
2876 m_ptr = &m_list[m_idx];
2878 /* Read the monster */
2883 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2885 /* Mark the location */
2886 c_ptr->m_idx = m_idx;
2889 real_r_ptr(m_ptr)->cur_num++;
2894 /* The dungeon is ready */
2895 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2896 character_dungeon = FALSE;
2898 character_dungeon = TRUE;
2906 * @brief 保存されたフロアを読み込む / Read the saved floor
2909 * The monsters/objects must be loaded in the same order
2910 * that they were stored, since the actual indexes matter.
2912 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2924 cave_template_type *templates;
2927 /*** Wipe all cave ***/
2931 /*** Basic info ***/
2933 /* Dungeon floor specific info follows */
2937 /*** Not a saved floor ***/
2940 dun_level = (DEPTH)tmp16s;
2941 base_level = dun_level;
2945 /*** The saved floor ***/
2948 if (tmp16s != sf_ptr->floor_id) return 171;
2951 if (tmp8u != sf_ptr->savefile_id) return 171;
2954 if (tmp16s != sf_ptr->dun_level) return 171;
2955 dun_level = sf_ptr->dun_level;
2958 if (tmp32s != sf_ptr->last_visit) return 171;
2961 if (tmp32u != sf_ptr->visit_mark) return 171;
2964 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2967 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2971 base_level = (DEPTH)tmp16s;
2972 rd_s16b(&num_repro);
2975 p_ptr->y = (int)tmp16u;
2978 p_ptr->x = (int)tmp16u;
2981 cur_hgt = (POSITION)tmp16s;
2983 cur_wid = (POSITION)tmp16s;
2985 rd_byte(&p_ptr->feeling);
2989 /*** Read template for cave_type ***/
2991 /* Read the template count */
2994 /* Allocate the "template" array */
2995 C_MAKE(templates, limit, cave_template_type);
2997 /* Read the templates */
2998 for (i = 0; i < limit; i++)
3000 cave_template_type *ct_ptr = &templates[i];
3003 rd_u16b(&ct_ptr->info);
3004 if (h_older_than(1, 7, 0, 2))
3007 ct_ptr->feat = (s16b)tmp8u;
3009 ct_ptr->mimic = (s16b)tmp8u;
3013 rd_s16b(&ct_ptr->feat);
3014 rd_s16b(&ct_ptr->mimic);
3016 rd_s16b(&ct_ptr->special);
3024 /*** Run length decoding ***/
3026 /* Load the dungeon data */
3027 for (x = y = 0; y < ymax; )
3039 } while (tmp8u == MAX_UCHAR);
3041 /* Apply the RLE info */
3042 for (i = count; i > 0; i--)
3044 /* Access the cave */
3045 cave_type *c_ptr = &cave[y][x];
3047 /* Extract cave data */
3048 c_ptr->info = templates[id].info;
3049 c_ptr->feat = templates[id].feat;
3050 c_ptr->mimic = templates[id].mimic;
3051 c_ptr->special = templates[id].special;
3060 if (++y >= ymax) break;
3065 /* Quest 18 was removed */
3066 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3068 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3070 /* Access the cave */
3071 cave_type *c_ptr = &cave[y][x];
3073 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
3075 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
3077 c_ptr->feat = feat_tree;
3080 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
3082 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3085 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3086 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3088 c_ptr->feat = feat_up_stair;
3094 /* Free the "template" array */
3095 C_KILL(templates, limit, cave_template_type);
3100 /* Read the item count */
3103 /* Verify maximum */
3104 if (limit > max_o_idx) return 151;
3107 /* Read the dungeon items */
3108 for (i = 1; i < limit; i++)
3114 /* Get a new record */
3118 if (i != o_idx) return 152;
3121 o_ptr = &o_list[o_idx];
3128 if (o_ptr->held_m_idx)
3130 monster_type *m_ptr;
3133 m_ptr = &m_list[o_ptr->held_m_idx];
3136 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3138 /* Place the object */
3139 m_ptr->hold_o_idx = o_idx;
3145 /* Access the item location */
3146 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3149 o_ptr->next_o_idx = c_ptr->o_idx;
3151 /* Place the object */
3152 c_ptr->o_idx = o_idx;
3159 /* Read the monster count */
3162 /* Hack -- verify */
3163 if (limit > max_m_idx) return 161;
3165 /* Read the monsters */
3166 for (i = 1; i < limit; i++)
3170 monster_type *m_ptr;
3172 /* Get a new record */
3176 if (i != m_idx) return 162;
3179 /* Acquire monster */
3180 m_ptr = &m_list[m_idx];
3182 /* Read the monster */
3187 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3189 /* Mark the location */
3190 c_ptr->m_idx = m_idx;
3193 real_r_ptr(m_ptr)->cur_num++;
3202 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3205 * The monsters/objects must be loaded in the same order
3206 * that they were stored, since the actual indexes matter.
3208 static errr rd_dungeon(void)
3215 /* Initialize saved_floors array and temporal files */
3216 init_saved_floors(FALSE);
3219 if (h_older_than(1, 5, 0, 0))
3221 err = rd_dungeon_old();
3223 /* Prepare floor_id of current floor */
3226 p_ptr->floor_id = get_new_floor_id();
3227 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3236 /* Number of floor_id used from birth */
3237 rd_s16b(&max_floor_id);
3239 /* Current dungeon type */
3240 rd_byte(&dungeon_type);
3243 /* Number of the saved_floors array elements */
3246 /*** No saved floor (On the surface etc.) ***/
3249 /* Read the current floor data */
3250 err = rd_saved_floor(NULL);
3253 /*** In the dungeon ***/
3257 /* Read the saved_floors array */
3258 for (i = 0; i < num; i++)
3260 saved_floor_type *sf_ptr = &saved_floors[i];
3262 rd_s16b(&sf_ptr->floor_id);
3263 rd_byte(&sf_ptr->savefile_id);
3266 sf_ptr->dun_level = (DEPTH)tmp16s;
3268 rd_s32b(&sf_ptr->last_visit);
3269 rd_u32b(&sf_ptr->visit_mark);
3270 rd_s16b(&sf_ptr->upper_floor_id);
3271 rd_s16b(&sf_ptr->lower_floor_id);
3275 /* Move saved floors data to temporal files */
3276 for (i = 0; i < num; i++)
3278 saved_floor_type *sf_ptr = &saved_floors[i];
3281 /* Unused element */
3282 if (!sf_ptr->floor_id) continue;
3284 /* Read the failure mark */
3286 if (tmp8u) continue;
3288 /* Read from the save file */
3289 err = rd_saved_floor(sf_ptr);
3294 /* Re-save as temporal saved floor file */
3295 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3301 /* Finally load current floor data from temporal file */
3304 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3309 /*** Error messages ***/
3313 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3317 note(_("アイテム配置エラー", "Object allocation error"));
3321 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3325 note(_("モンスター配置エラー", "Monster allocation error"));
3329 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3333 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3337 note(_("Error 183", "Error 183"));
3341 /* The dungeon is ready */
3342 character_dungeon = TRUE;
3344 /* Success or Error */
3350 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3353 static errr rd_savefile_new_aux(void)
3365 #ifdef VERIFY_CHECKSUMS
3366 u32b n_x_check, n_v_check;
3367 u32b o_x_check, o_v_check;
3371 /* Strip the version bytes */
3374 /* Hack -- decrypt */
3375 xor_byte = sf_extra;
3378 /* Clear the checksums */
3382 /* Read the version number of the savefile */
3383 /* Old savefile will be version 0.0.0.3 */
3384 rd_byte(&h_ver_extra);
3385 rd_byte(&h_ver_patch);
3386 rd_byte(&h_ver_minor);
3387 rd_byte(&h_ver_major);
3389 /* Mention the savefile version */
3391 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3392 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3395 /* Operating system info */
3396 rd_u32b(&sf_system);
3398 /* Time of savefile creation */
3401 /* Number of resurrections */
3404 /* Number of times played */
3408 /* Later use (always zero) */
3411 /* Later use (always zero) */
3414 /* Later use (always zero) */
3418 rd_byte(&kanji_code);
3420 /* Read RNG state */
3422 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3424 /* Then the options */
3426 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3428 /* Then the "messages" */
3430 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3432 for (i = 0; i < max_r_idx; i++)
3434 /* Access that monster */
3435 monster_race *r_ptr = &r_info[i];
3437 /* Hack -- Reset the death counter */
3438 r_ptr->max_num = 100;
3440 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3442 /* Hack -- Non-unique Nazguls are semi-unique */
3443 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3446 /* Monster Memory */
3449 /* Incompatible save files */
3450 if (tmp16u > max_r_idx)
3452 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3456 /* Read the available records */
3457 for (i = 0; i < tmp16u; i++)
3463 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3468 /* Incompatible save files */
3469 if (tmp16u > max_k_idx)
3471 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3475 /* Read the object memory */
3476 for (i = 0; i < tmp16u; i++)
3478 object_kind *k_ptr = &k_info[i];
3482 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3483 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3485 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3487 /* 2.1.3 or newer version */
3489 u16b max_towns_load;
3490 u16b max_quests_load;
3491 byte max_rquests_load;
3492 s16b old_inside_quest = p_ptr->inside_quest;
3494 /* Number of towns */
3495 rd_u16b(&max_towns_load);
3497 /* Incompatible save files */
3498 if (max_towns_load > max_towns)
3500 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3504 /* Number of quests */
3505 rd_u16b(&max_quests_load);
3507 if (z_older_than(11, 0, 7))
3509 max_rquests_load = 10;
3513 rd_byte(&max_rquests_load);
3516 /* Incompatible save files */
3517 if (max_quests_load > max_quests)
3519 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3523 for (i = 0; i < max_quests_load; i++)
3527 quest_type* const q_ptr = &quest[i];
3529 rd_s16b(&q_ptr->status);
3530 rd_s16b(&q_ptr->level);
3532 if (z_older_than(11, 0, 6))
3538 rd_byte(&q_ptr->complev);
3540 if(h_older_than(2, 1, 2, 2))
3542 q_ptr->comptime = 0;
3546 rd_u32b(&q_ptr->comptime);
3549 /* Load quest status if quest is running */
3550 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3551 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3552 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3554 rd_s16b(&q_ptr->cur_num);
3555 rd_s16b(&q_ptr->max_num);
3556 rd_s16b(&q_ptr->type);
3558 /* Load quest monster index */
3559 rd_s16b(&q_ptr->r_idx);
3561 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3563 determine_random_questor(&quest[i]);
3566 /* Load quest item index */
3567 rd_s16b(&q_ptr->k_idx);
3570 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3572 rd_byte(&q_ptr->flags);
3574 if (z_older_than(10, 3, 11))
3576 if (q_ptr->flags & QUEST_FLAG_PRESET)
3582 init_flags = INIT_ASSIGN;
3583 p_ptr->inside_quest = i;
3585 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3586 p_ptr->inside_quest = old_inside_quest;
3591 rd_byte(&q_ptr->dungeon);
3594 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3595 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3596 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3599 /* Ignore the empty quests from old versions */
3602 /* Ignore quest status */
3605 /* Ignore quest level */
3609 * We don't have to care about the other info,
3610 * since status should be 0 for these quests anyway
3615 /* Quest 18 was removed */
3616 if (h_older_than(1, 7, 0, 6))
3618 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3619 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3622 /* Position in the wilderness */
3623 rd_s32b(&p_ptr->wilderness_x);
3624 rd_s32b(&p_ptr->wilderness_y);
3625 if (z_older_than(10, 3, 13))
3627 p_ptr->wilderness_x = 5;
3628 p_ptr->wilderness_y = 48;
3631 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3632 else rd_byte((byte *)&p_ptr->wild_mode);
3633 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3634 else rd_byte((byte *)&ambush_flag);
3636 /* Size of the wilderness */
3637 rd_s32b(&wild_x_size);
3638 rd_s32b(&wild_y_size);
3640 /* Incompatible save files */
3641 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3643 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3647 /* Load the wilderness seeds */
3648 for (i = 0; i < wild_x_size; i++)
3650 for (j = 0; j < wild_y_size; j++)
3652 rd_u32b(&wilderness[j][i].seed);
3657 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3659 /* Load the Artifacts */
3662 /* Incompatible save files */
3663 if (tmp16u > max_a_idx)
3665 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3669 /* Read the artifact flags */
3670 for (i = 0; i < tmp16u; i++)
3672 artifact_type *a_ptr = &a_info[i];
3675 a_ptr->cur_num = tmp8u;
3677 if (h_older_than(1, 5, 0, 0))
3679 a_ptr->floor_id = 0;
3687 rd_s16b(&a_ptr->floor_id);
3690 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3692 /* Read the extra stuff */
3694 if (p_ptr->energy_need < -999) world_player = TRUE;
3696 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3699 /* Read the player_hp array */
3702 /* Incompatible save files */
3703 if (tmp16u > PY_MAX_LEVEL)
3705 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3709 /* Read the player_hp array */
3710 for (i = 0; i < tmp16u; i++)
3712 rd_s16b(&p_ptr->player_hp[i]);
3715 /* Important -- Initialize the sex */
3716 sp_ptr = &sex_info[p_ptr->psex];
3718 /* Important -- Initialize the race/class */
3719 rp_ptr = &race_info[p_ptr->prace];
3720 cp_ptr = &class_info[p_ptr->pclass];
3721 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3723 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3725 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3726 do_cmd_rerate(FALSE);
3728 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3730 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3731 do_cmd_rerate(FALSE);
3733 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3735 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3736 do_cmd_rerate(FALSE);
3738 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3740 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3741 do_cmd_rerate(FALSE);
3744 /* Important -- Initialize the magic */
3745 mp_ptr = &m_info[p_ptr->pclass];
3748 /* Read spell info */
3749 rd_u32b(&p_ptr->spell_learned1);
3750 rd_u32b(&p_ptr->spell_learned2);
3751 rd_u32b(&p_ptr->spell_worked1);
3752 rd_u32b(&p_ptr->spell_worked2);
3753 rd_u32b(&p_ptr->spell_forgotten1);
3754 rd_u32b(&p_ptr->spell_forgotten2);
3756 if (z_older_than(10,0,5))
3758 p_ptr->learned_spells = 0;
3759 for (i = 0; i < 64; i++)
3761 /* Count known spells */
3763 (p_ptr->spell_learned1 & (1L << i)) :
3764 (p_ptr->spell_learned2 & (1L << (i - 32))))
3766 p_ptr->learned_spells++;
3770 else rd_s16b(&p_ptr->learned_spells);
3772 if (z_older_than(10,0,6))
3774 p_ptr->add_spells = 0;
3776 else rd_s16b(&p_ptr->add_spells);
3777 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3779 for (i = 0; i < 64; i++)
3781 rd_byte(&p_ptr->spell_order[i]);
3785 /* Read the inventory */
3788 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3792 /* Read number of towns */
3794 town_count = tmp16u;
3796 /* Read the stores */
3798 for (i = 1; i < town_count; i++)
3800 for (j = 0; j < tmp16u; j++)
3802 if (rd_store(i, j)) return (22);
3806 rd_s16b(&p_ptr->pet_follow_distance);
3807 if (z_older_than(10, 4, 10))
3809 p_ptr->pet_extra_flags = 0;
3811 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3813 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3815 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3819 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3822 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3826 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3829 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3833 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3836 if (!z_older_than(10,0,8))
3839 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3844 rd_s16b(&p_ptr->pet_extra_flags);
3847 if (!z_older_than(11, 0, 9))
3849 char buf[SCREEN_BUF_SIZE];
3850 rd_string(buf, sizeof(buf));
3851 if (buf[0]) screen_dump = string_make(buf);
3856 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3858 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3863 /* I'm not dead yet... */
3864 if (!p_ptr->is_dead)
3866 /* Dead players have no dungeon */
3867 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3871 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3875 /* Read the ghost info */
3882 strip_bytes(tmp32s);
3886 /* Quest 18 was removed */
3887 if (h_older_than(1, 7, 0, 6))
3889 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3891 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3893 p_ptr->inside_quest = 0;
3898 #ifdef VERIFY_CHECKSUMS
3900 /* Save the checksum */
3901 n_v_check = v_check;
3903 /* Read the old checksum */
3904 rd_u32b(&o_v_check);
3907 if (o_v_check != n_v_check)
3909 note(_("チェックサムがおかしい", "Invalid checksum"));
3914 /* Save the encoded checksum */
3915 n_x_check = x_check;
3917 /* Read the checksum */
3918 rd_u32b(&o_x_check);
3922 if (o_x_check != n_x_check)
3924 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3935 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3938 errr rd_savefile_new(void)
3942 /* Grab permissions */
3945 /* The savefile is a binary file */
3946 fff = my_fopen(savefile, "rb");
3948 /* Drop permissions */
3952 if (!fff) return (-1);
3954 /* Call the sub-function */
3955 err = rd_savefile_new_aux();
3957 /* Check for errors */
3958 if (ferror(fff)) err = -1;
3960 /* Close the file */
3969 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3970 * @param sf_ptr 保存フロア読み込み先
3973 static bool load_floor_aux(saved_floor_type *sf_ptr)
3978 #ifdef VERIFY_CHECKSUMS
3979 u32b n_x_check, n_v_check;
3980 u32b o_x_check, o_v_check;
3983 /* Hack -- decrypt (read xor_byte) */
3987 /* Clear the checksums */
3991 /* Set the version number to current version */
3992 /* Never load old temporal files */
3993 h_ver_extra = H_VER_EXTRA;
3994 h_ver_patch = H_VER_PATCH;
3995 h_ver_minor = H_VER_MINOR;
3996 h_ver_major = H_VER_MAJOR;
3998 /* Verify the sign */
4000 if (saved_floor_file_sign != tmp32u) return FALSE;
4002 /* Read -- have error? */
4003 if (rd_saved_floor(sf_ptr)) return FALSE;
4006 #ifdef VERIFY_CHECKSUMS
4007 /* Save the checksum */
4008 n_v_check = v_check;
4010 /* Read the old checksum */
4011 rd_u32b(&o_v_check);
4014 if (o_v_check != n_v_check) return FALSE;
4016 /* Save the encoded checksum */
4017 n_x_check = x_check;
4019 /* Read the checksum */
4020 rd_u32b(&o_x_check);
4023 if (o_x_check != n_x_check) return FALSE;
4032 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4033 * @param sf_ptr 保存フロア読み込み先
4037 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
4039 FILE *old_fff = NULL;
4040 byte old_xor_byte = 0;
4041 u32b old_v_check = 0;
4042 u32b old_x_check = 0;
4043 byte old_h_ver_major = 0;
4044 byte old_h_ver_minor = 0;
4045 byte old_h_ver_patch = 0;
4046 byte old_h_ver_extra = 0;
4049 char floor_savefile[1024];
4051 byte old_kanji_code = kanji_code;
4054 * Temporal files are always written in system depended kanji
4059 /* EUC kanji code */
4063 /* SJIS kanji code */
4072 /* We have one file already opened */
4073 if (mode & SLF_SECOND)
4075 /* Backup original values */
4077 old_xor_byte = xor_byte;
4078 old_v_check = v_check;
4079 old_x_check = x_check;
4080 old_h_ver_major = h_ver_major;
4081 old_h_ver_minor = h_ver_minor;
4082 old_h_ver_patch = h_ver_patch;
4083 old_h_ver_extra = h_ver_extra;
4086 /* floor savefile */
4087 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4089 /* Grab permissions */
4092 /* The savefile is a binary file */
4093 fff = my_fopen(floor_savefile, "rb");
4095 /* Drop permissions */
4099 if (!fff) ok = FALSE;
4101 /* Attempt to load */
4104 /* Load saved floor data from file */
4105 ok = load_floor_aux(sf_ptr);
4107 /* Check for errors */
4108 if (ferror(fff)) ok = FALSE;
4110 /* Close the file */
4113 /* Grab permissions */
4116 /* Delete the file */
4117 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4119 /* Drop permissions */
4123 /* We have one file already opened */
4124 if (mode & SLF_SECOND)
4126 /* Restore original values */
4128 xor_byte = old_xor_byte;
4129 v_check = old_v_check;
4130 x_check = old_x_check;
4131 h_ver_major = old_h_ver_major;
4132 h_ver_minor = old_h_ver_minor;
4133 h_ver_patch = old_h_ver_patch;
4134 h_ver_extra = old_h_ver_extra;
4137 /* Restore old knowledge */
4138 kanji_code = old_kanji_code;