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);
372 rd_byte(&o_ptr->name1);
373 rd_byte(&o_ptr->name2);
374 rd_s16b(&o_ptr->timeout);
376 rd_s16b(&o_ptr->to_h);
379 o_ptr->to_d = tmp16s;
380 rd_s16b(&o_ptr->to_a);
387 rd_byte(&o_ptr->ident);
389 rd_byte(&o_ptr->marked);
392 rd_u32b(&o_ptr->art_flags[0]);
393 rd_u32b(&o_ptr->art_flags[1]);
394 rd_u32b(&o_ptr->art_flags[2]);
395 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
396 else rd_u32b(&o_ptr->art_flags[3]);
398 if (h_older_than(1, 3, 0, 0))
400 if (o_ptr->name2 == EGO_TELEPATHY)
401 add_flag(o_ptr->art_flags, TR_TELEPATHY);
404 if (z_older_than(11, 0, 11))
406 o_ptr->curse_flags = 0L;
407 if (o_ptr->ident & 0x40)
409 o_ptr->curse_flags |= TRC_CURSED;
410 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
411 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
412 if (object_is_fixed_artifact(o_ptr))
414 artifact_type *a_ptr = &a_info[o_ptr->name1];
415 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
416 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
418 else if (object_is_ego(o_ptr))
420 ego_item_type *e_ptr = &e_info[o_ptr->name2];
421 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
422 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
425 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
429 rd_u32b(&o_ptr->curse_flags);
432 /* Monster holding object */
433 rd_s16b(&o_ptr->held_m_idx);
436 rd_byte(&o_ptr->xtra1);
437 rd_byte(&o_ptr->xtra2);
439 if (z_older_than(11, 0, 10))
441 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
443 switch (o_ptr->xtra2 % 6)
445 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
446 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
447 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
448 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
449 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
450 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
454 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
456 switch (o_ptr->xtra2 % 11)
458 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
459 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
460 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
461 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
462 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
463 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
464 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
465 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
466 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
467 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
468 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
472 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
474 switch (o_ptr->xtra2 % 8)
476 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
477 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
478 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
479 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
480 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
481 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
482 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
483 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
490 if (z_older_than(10, 2, 3))
495 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
497 o_ptr->xtra3 = o_ptr->xtra1;
500 if (o_ptr->tval == TV_CAPTURE)
502 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
503 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
505 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
506 if (ironman_nightmare)
508 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
510 o_ptr->xtra4 = o_ptr->xtra5;
515 rd_byte(&o_ptr->xtra3);
516 if (h_older_than(1, 3, 0, 1))
518 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
519 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
522 rd_s16b(&o_ptr->xtra4);
523 rd_s16b(&o_ptr->xtra5);
526 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)))
528 o_ptr->xtra4 = o_ptr->pval;
532 rd_byte(&o_ptr->feeling);
535 rd_string(buf, sizeof(buf));
537 /* Save the inscription */
538 if (buf[0]) o_ptr->inscription = quark_add(buf);
540 rd_string(buf, sizeof(buf));
541 if (buf[0]) o_ptr->art_name = quark_add(buf);
543 /* The Python object */
551 /* Mega-Hack -- handle "dungeon objects" later */
552 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
554 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
556 if (z_older_than(10, 4, 9))
558 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
560 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
561 add_flag(o_ptr->art_flags, TR_DEC_MANA);
566 if (object_is_fixed_artifact(o_ptr))
568 artifact_type *a_ptr;
570 /* Obtain the artifact info */
571 a_ptr = &a_info[o_ptr->name1];
573 /* Verify that artifact */
574 if (!a_ptr->name) o_ptr->name1 = 0;
578 if (object_is_ego(o_ptr))
580 ego_item_type *e_ptr;
582 /* Obtain the ego-item info */
583 e_ptr = &e_info[o_ptr->name2];
585 /* Verify that ego-item */
586 if (!e_ptr->name) o_ptr->name2 = 0;
593 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
594 * @param o_ptr アイテムオブジェクト保存先ポインタ
597 static void rd_item(object_type *o_ptr)
605 if (h_older_than(1, 5, 0, 0))
611 /*** Item save flags ***/
614 /*** Read un-obvious elements ***/
616 rd_s16b(&o_ptr->k_idx);
620 o_ptr->iy = (POSITION)tmp8u;
622 o_ptr->ix = (POSITION)tmp8u;
625 k_ptr = &k_info[o_ptr->k_idx];
626 o_ptr->tval = k_ptr->tval;
627 o_ptr->sval = k_ptr->sval;
630 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
631 else o_ptr->pval = 0;
633 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
634 else o_ptr->discount = 0;
635 if (flags & SAVE_ITEM_NUMBER) rd_byte(&o_ptr->number);
636 else o_ptr->number = 1;
638 rd_s16b(&o_ptr->weight);
640 if (flags & SAVE_ITEM_NAME1) rd_byte(&o_ptr->name1);
641 else o_ptr->name1 = 0;
642 if (flags & SAVE_ITEM_NAME2) rd_byte(&o_ptr->name2);
643 else o_ptr->name2 = 0;
644 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
645 else o_ptr->timeout = 0;
647 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
648 else o_ptr->to_h = 0;
649 if (flags & SAVE_ITEM_TO_D)
652 o_ptr->to_d = tmp16s;
654 else o_ptr->to_d = 0;
655 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
656 else o_ptr->to_a = 0;
658 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
661 if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
663 if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
666 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
667 else o_ptr->ident = 0;
669 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
670 else o_ptr->marked = 0;
673 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
674 else o_ptr->art_flags[0] = 0;
675 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
676 else o_ptr->art_flags[1] = 0;
677 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
678 else o_ptr->art_flags[2] = 0;
679 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
680 else o_ptr->art_flags[3] = 0;
681 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
682 else o_ptr->art_flags[4] = 0;
684 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
685 else o_ptr->curse_flags = 0;
687 /* Monster holding object */
688 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
689 else o_ptr->held_m_idx = 0;
692 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
693 else o_ptr->xtra1 = 0;
694 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
695 else o_ptr->xtra2 = 0;
697 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
698 else o_ptr->xtra3 = 0;
700 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
701 else o_ptr->xtra4 = 0;
702 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
703 else o_ptr->xtra5 = 0;
705 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
706 else o_ptr->feeling = 0;
708 if (flags & SAVE_ITEM_INSCRIPTION)
710 rd_string(buf, sizeof(buf));
711 o_ptr->inscription = quark_add(buf);
713 else o_ptr->inscription = 0;
715 if (flags & SAVE_ITEM_ART_NAME)
717 rd_string(buf, sizeof(buf));
718 o_ptr->art_name = quark_add(buf);
720 else o_ptr->art_name = 0;
722 if(h_older_than(2,1,2,4))
724 u32b flgs[TR_FLAG_SIZE];
725 object_flags(o_ptr, flgs);
727 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
729 add_flag(o_ptr->art_flags, TR_LITE_M1);
730 remove_flag(o_ptr->art_flags, TR_LITE_1);
731 remove_flag(o_ptr->art_flags, TR_LITE_2);
732 remove_flag(o_ptr->art_flags, TR_LITE_3);
734 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
736 if (o_ptr->tval == TV_LITE)
738 if (o_ptr->sval == SV_LITE_TORCH)
740 add_flag(o_ptr->art_flags, TR_LITE_M1);
742 else if (o_ptr->sval == SV_LITE_LANTERN)
744 add_flag(o_ptr->art_flags, TR_LITE_M2);
746 else if (o_ptr->sval == SV_LITE_FEANOR)
748 add_flag(o_ptr->art_flags, TR_LITE_M3);
754 add_flag(o_ptr->art_flags, TR_LITE_M1);
757 else if (o_ptr->tval == TV_LITE)
759 if (object_is_fixed_artifact(o_ptr))
761 add_flag(o_ptr->art_flags, TR_LITE_3);
763 else if (o_ptr->sval == SV_LITE_TORCH)
765 add_flag(o_ptr->art_flags, TR_LITE_1);
766 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
768 else if (o_ptr->sval == SV_LITE_LANTERN)
770 add_flag(o_ptr->art_flags, TR_LITE_2);
771 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
773 else if (o_ptr->sval == SV_LITE_FEANOR)
775 add_flag(o_ptr->art_flags, TR_LITE_2);
783 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
784 * @param m_ptr モンスター保存先ポインタ
787 static void rd_monster_old(monster_type *m_ptr)
793 /* Read the monster race */
794 rd_s16b(&m_ptr->r_idx);
796 if (z_older_than(11, 0, 12))
797 m_ptr->ap_r_idx = m_ptr->r_idx;
799 rd_s16b(&m_ptr->ap_r_idx);
801 if (z_older_than(11, 0, 14))
803 monster_race *r_ptr = &r_info[m_ptr->r_idx];
805 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
806 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
807 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
810 rd_byte(&m_ptr->sub_align);
812 /* Read the other information */
814 m_ptr->fy = (POSITION)tmp8u;
816 m_ptr->fx = (POSITION)tmp8u;
821 m_ptr->maxhp = tmp16s;
823 if (z_older_than(11, 0, 5))
825 m_ptr->max_maxhp = m_ptr->maxhp;
830 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
832 if(h_older_than(2, 1, 2, 1))
834 m_ptr->dealt_damage = 0;
838 rd_u32b(&m_ptr->dealt_damage);
841 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
842 rd_byte(&m_ptr->mspeed);
843 if (z_older_than(10, 4, 2))
846 m_ptr->energy_need = (s16b)tmp8u;
848 else rd_s16b(&m_ptr->energy_need);
850 if (z_older_than(11, 0, 13))
851 m_ptr->energy_need = 100 - m_ptr->energy_need;
853 if (z_older_than(10,0,7))
855 m_ptr->mtimed[MTIMED_FAST] = 0;
856 m_ptr->mtimed[MTIMED_SLOW] = 0;
861 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
863 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
866 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
868 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
870 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
872 if (z_older_than(10,0,10))
876 else if (z_older_than(10,0,11))
884 m_ptr->target_y = (POSITION)tmp16s;
886 m_ptr->target_x = (POSITION)tmp16s;
890 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
892 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
893 rd_u32b(&m_ptr->smart);
897 if (z_older_than(10, 4, 5))
900 rd_u32b(&m_ptr->exp);
902 if (z_older_than(10, 2, 2))
904 if (m_ptr->r_idx < 0)
906 m_ptr->r_idx = (0-m_ptr->r_idx);
907 m_ptr->mflag2 |= MFLAG2_KAGE;
912 rd_byte(&m_ptr->mflag2);
915 if (z_older_than(11, 0, 12))
917 if (m_ptr->mflag2 & MFLAG2_KAGE)
918 m_ptr->ap_r_idx = MON_KAGE;
921 if (z_older_than(10, 1, 3))
927 rd_string(buf, sizeof(buf));
928 if (buf[0]) m_ptr->nickname = quark_add(buf);
936 * @brief モンスターを読み込む(現版) / Read a monster (New method)
937 * @param m_ptr モンスター保存先ポインタ
940 static void rd_monster(monster_type *m_ptr)
947 if (h_older_than(1, 5, 0, 0))
949 rd_monster_old(m_ptr);
953 /*** Monster save flags ***/
956 /*** Read un-obvious elements ***/
958 /* Read the monster race */
959 rd_s16b(&m_ptr->r_idx);
961 /* Read the other information */
963 m_ptr->fy = (POSITION)tmp8u;
965 m_ptr->fx = (POSITION)tmp8u;
968 m_ptr->hp = (HIT_POINT)tmp16s;
970 m_ptr->maxhp = (HIT_POINT)tmp16s;
972 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
974 if(h_older_than(2, 1, 2, 1))
976 m_ptr->dealt_damage = 0;
980 rd_u32b(&m_ptr->dealt_damage);
983 /* Monster race index of its appearance */
984 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
985 else m_ptr->ap_r_idx = m_ptr->r_idx;
987 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
988 else m_ptr->sub_align = 0;
990 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
991 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
993 rd_byte(&m_ptr->mspeed);
995 rd_s16b(&m_ptr->energy_need);
997 if (flags & SAVE_MON_FAST)
1000 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1002 else m_ptr->mtimed[MTIMED_FAST] = 0;
1003 if (flags & SAVE_MON_SLOW)
1006 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1008 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1009 if (flags & SAVE_MON_STUNNED)
1012 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1014 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1015 if (flags & SAVE_MON_CONFUSED)
1018 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1020 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1021 if (flags & SAVE_MON_MONFEAR)
1024 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1026 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1028 if (flags & SAVE_MON_TARGET_Y)
1031 m_ptr->target_y = (POSITION)tmp16s;
1033 else m_ptr->target_y = 0;
1034 if (flags & SAVE_MON_TARGET_X)
1037 m_ptr->target_x = (POSITION)tmp16s;
1039 else m_ptr->target_x = 0;
1041 if (flags & SAVE_MON_INVULNER)
1044 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1046 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1048 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1049 else m_ptr->smart = 0;
1051 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
1052 else m_ptr->exp = 0;
1054 m_ptr->mflag = 0; /* Not saved */
1056 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1057 else m_ptr->mflag2 = 0;
1059 if (flags & SAVE_MON_NICKNAME)
1061 rd_string(buf, sizeof(buf));
1062 m_ptr->nickname = quark_add(buf);
1064 else m_ptr->nickname = 0;
1066 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1067 else m_ptr->parent_m_idx = 0;
1072 * Old monster bit flags of racial resistances
1074 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1075 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1076 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1077 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1078 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1079 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1080 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1081 #define RF3_RES_WATE 0x00800000 /* Resist water */
1082 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1083 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1084 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1085 #define RF3_RES_ALL 0x08000000 /* Resist all */
1087 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1089 if ((R_PTR)->r_flags3 & (RF3)) \
1091 (R_PTR)->r_flags3 &= ~(RF3); \
1092 (R_PTR)->r_flagsr |= (RFR); \
1096 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1098 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1100 (R_PTR)->r_flagsr |= (RFR); \
1104 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1105 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1106 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1107 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1108 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1109 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1110 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1111 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1112 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1113 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1116 * @brief モンスターの思い出を読み込む / Read the monster lore
1117 * @param r_idx 読み込み先モンスターID
1120 static void rd_lore(int r_idx)
1124 monster_race *r_ptr = &r_info[r_idx];
1126 /* Count sights/deaths/kills */
1127 rd_s16b(&r_ptr->r_sights);
1128 rd_s16b(&r_ptr->r_deaths);
1129 rd_s16b(&r_ptr->r_pkills);
1130 if (h_older_than(1, 7, 0, 5))
1132 r_ptr->r_akills = r_ptr->r_pkills;
1136 rd_s16b(&r_ptr->r_akills);
1138 rd_s16b(&r_ptr->r_tkills);
1140 /* Count wakes and ignores */
1141 rd_byte(&r_ptr->r_wake);
1142 rd_byte(&r_ptr->r_ignore);
1145 rd_byte(&r_ptr->r_xtra1);
1146 rd_byte(&r_ptr->r_xtra2);
1149 rd_byte(&r_ptr->r_drop_gold);
1150 rd_byte(&r_ptr->r_drop_item);
1154 rd_byte(&r_ptr->r_cast_spell);
1156 /* Count blows of each type */
1157 rd_byte(&r_ptr->r_blows[0]);
1158 rd_byte(&r_ptr->r_blows[1]);
1159 rd_byte(&r_ptr->r_blows[2]);
1160 rd_byte(&r_ptr->r_blows[3]);
1162 /* Memorize flags */
1163 rd_u32b(&r_ptr->r_flags1);
1164 rd_u32b(&r_ptr->r_flags2);
1165 rd_u32b(&r_ptr->r_flags3);
1166 rd_u32b(&r_ptr->r_flags4);
1167 rd_u32b(&r_ptr->r_flags5);
1168 rd_u32b(&r_ptr->r_flags6);
1169 if (h_older_than(1, 5, 0, 3))
1171 r_ptr->r_flagsr = 0L;
1173 /* Move RF3 resistance flags to RFR */
1174 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1175 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1176 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1177 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1178 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1179 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1180 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1181 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1182 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1183 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1184 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1185 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1187 /* Separate breathers resistance from RF4 to RFR */
1188 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1189 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1190 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1191 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1192 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1193 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1194 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1195 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1196 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1198 /* Resist confusion is merged to RF3_NO_CONF */
1199 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1201 /* Misc resistance hack to RFR */
1202 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1203 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1207 rd_u32b(&r_ptr->r_flagsr);
1210 /* Read the "Racial" monster limit per level */
1211 rd_byte(&r_ptr->max_num);
1213 /* Location in saved floor */
1214 rd_s16b(&r_ptr->floor_id);
1219 /* Repair the lore flags */
1220 r_ptr->r_flags1 &= r_ptr->flags1;
1221 r_ptr->r_flags2 &= r_ptr->flags2;
1222 r_ptr->r_flags3 &= r_ptr->flags3;
1223 r_ptr->r_flags4 &= r_ptr->flags4;
1224 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1225 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1226 r_ptr->r_flagsr &= r_ptr->flagsr;
1230 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1231 * @param st_ptr 店舗の参照ポインタ
1232 * @param o_ptr アイテムオブジェクト参照ポインタ
1235 * In all cases, return the slot (or -1) where the object was placed
1237 * Note that this is a hacked up version of "inven_carry()".
1239 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1240 * known, the player may have to pick stuff up and drop it again.
1242 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1250 /* Check each existing item (try to combine) */
1251 for (slot = 0; slot < st_ptr->stock_num; slot++)
1253 /* Get the existing item */
1254 j_ptr = &st_ptr->stock[slot];
1256 /* The home acts just like the player */
1257 if (object_similar(j_ptr, o_ptr))
1259 /* Save the new number of items */
1260 object_absorb(j_ptr, o_ptr);
1268 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1272 /* Determine the "value" of the item */
1273 value = object_value(o_ptr);
1275 /* Check existing slots to see if we must "slide" */
1276 for (slot = 0; slot < st_ptr->stock_num; slot++)
1278 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1281 /* Slide the others up */
1282 for (i = st_ptr->stock_num; i > slot; i--)
1284 st_ptr->stock[i] = st_ptr->stock[i-1];
1287 /* More stuff now */
1288 st_ptr->stock_num++;
1290 /* Insert the new item */
1291 st_ptr->stock[slot] = *o_ptr;
1293 chg_virtue(V_SACRIFICE, -1);
1295 /* Return the location */
1300 * @brief 店舗情報を読み込む / Read a store
1301 * @param town_number 街ID
1302 * @param store_number 店舗ID
1305 static errr rd_store(int town_number, int store_number)
1317 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1319 st_ptr = &town[1].store[store_number];
1320 if (st_ptr->stock_num) sort = TRUE;
1324 st_ptr = &town[town_number].store[store_number];
1327 /* Read the basic info */
1328 rd_s32b(&st_ptr->store_open);
1329 rd_s16b(&st_ptr->insult_cur);
1331 if (z_older_than(11, 0, 4))
1340 rd_s16b(&st_ptr->good_buy);
1341 rd_s16b(&st_ptr->bad_buy);
1343 /* Read last visit */
1344 rd_s32b(&st_ptr->last_visit);
1346 /* Extract the owner (see above) */
1347 st_ptr->owner = own;
1349 /* Read the items */
1350 for (j = 0; j < num; j++)
1355 /* Get local object */
1358 /* Wipe the object */
1364 /* Acquire valid items */
1365 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1370 home_carry(st_ptr, q_ptr);
1374 k = st_ptr->stock_num++;
1376 /* Acquire the item */
1377 object_copy(&st_ptr->stock[k], q_ptr);
1388 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1391 static void rd_randomizer(void)
1401 rd_u16b(&Rand_place);
1404 for (i = 0; i < RAND_DEG; i++)
1406 rd_u32b(&Rand_state[i]);
1413 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1416 * Note that the normal options are now stored as a set of 256 bit flags,
1417 * plus a set of 256 bit masks to indicate which bit flags were defined
1418 * at the time the savefile was created. This will allow new options
1419 * to be added, and old options to be removed, at any time, without
1420 * hurting old savefiles.
1422 * The window options are stored in the same way, but note that each
1423 * window gets 32 options, and their order is fixed by certain defines.
1425 static void rd_options(void)
1439 /* Ignore old options */
1443 /*** Special info */
1445 /* Read "delay_factor" */
1449 /* Read "hitpoint_warn" */
1453 /* Read "mana_warn" */
1454 if(h_older_than(1, 7, 0, 0))
1465 /*** Cheating options ***/
1469 if (c & 0x0002) p_ptr->wizard = TRUE;
1471 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1472 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1473 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1474 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1475 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1476 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1477 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1478 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1479 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1481 rd_byte((byte *)&autosave_l);
1482 rd_byte((byte *)&autosave_t);
1483 rd_s16b(&autosave_freq);
1486 /*** Normal Options ***/
1488 /* Read the option flags */
1489 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1491 /* Read the option masks */
1492 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1494 /* Analyze the options */
1495 for (n = 0; n < 8; n++)
1497 /* Analyze the options */
1498 for (i = 0; i < 32; i++)
1500 /* Process valid flags */
1501 if (mask[n] & (1L << i))
1503 /* Process valid flags */
1504 if (option_mask[n] & (1L << i))
1507 if (flag[n] & (1L << i))
1510 option_flag[n] |= (1L << i);
1517 option_flag[n] &= ~(1L << i);
1524 if (z_older_than(10, 4, 5))
1526 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1527 else option_flag[5] |= (0x00000001 << 4);
1528 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1529 else option_flag[2] |= (0x00000001 << 5);
1530 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1531 else option_flag[4] |= (0x00000001 << 5);
1532 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1533 else option_flag[5] |= (0x00000001 << 0);
1534 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1535 else option_flag[5] |= (0x00000001 << 12);
1536 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1537 else option_flag[1] |= (0x00000001 << 0);
1538 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1539 else option_flag[1] |= (0x00000001 << 18);
1540 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1541 else option_flag[1] |= (0x00000001 << 19);
1542 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1543 else option_flag[5] |= (0x00000001 << 3);
1546 /* Extract the options */
1547 extract_option_vars();
1550 /*** Window Options ***/
1552 /* Read the window flags */
1553 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1555 /* Read the window masks */
1556 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1558 /* Analyze the options */
1559 for (n = 0; n < 8; n++)
1561 /* Analyze the options */
1562 for (i = 0; i < 32; i++)
1564 /* Process valid flags */
1565 if (mask[n] & (1L << i))
1567 /* Process valid flags */
1568 if (window_mask[n] & (1L << i))
1571 if (flag[n] & (1L << i))
1574 window_flag[n] |= (1L << i);
1581 window_flag[n] &= ~(1L << i);
1592 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1595 * XXX XXX XXX This is such a nasty hack it hurts.
1597 static void rd_ghost(void)
1602 rd_string(buf, sizeof(buf));
1604 /* Strip old data */
1610 * @brief クイックスタート情報を読み込む / Load quick start data
1613 static void load_quick_start(void)
1618 if (z_older_than(11, 0, 13))
1620 previous_char.quick_ok = FALSE;
1624 rd_byte(&previous_char.psex);
1625 rd_byte(&previous_char.prace);
1626 rd_byte(&previous_char.pclass);
1627 rd_byte(&previous_char.pseikaku);
1628 rd_byte(&previous_char.realm1);
1629 rd_byte(&previous_char.realm2);
1631 rd_s16b(&previous_char.age);
1632 rd_s16b(&previous_char.ht);
1633 rd_s16b(&previous_char.wt);
1634 rd_s16b(&previous_char.sc);
1635 rd_s32b(&previous_char.au);
1637 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1638 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1640 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1642 rd_s16b(&previous_char.chaos_patron);
1644 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1646 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1648 /* UNUSED : Was number of random quests */
1652 previous_char.quick_ok = (bool)tmp8u;
1656 * @brief その他の情報を読み込む / Read the "extra" information
1659 static void rd_extra(void)
1667 rd_string(p_ptr->name, sizeof(p_ptr->name));
1669 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1671 if (!h_older_than(1, 7, 0, 1))
1675 /* Read the message */
1676 rd_string(buf, sizeof buf);
1677 if (buf[0]) p_ptr->last_message = string_make(buf);
1682 for (i = 0; i < 4; i++)
1684 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1687 /* Class/Race/Seikaku/Gender/Spells */
1688 rd_byte(&p_ptr->prace);
1689 rd_byte(&p_ptr->pclass);
1690 rd_byte(&p_ptr->pseikaku);
1691 rd_byte(&p_ptr->psex);
1692 rd_byte(&p_ptr->realm1);
1693 rd_byte(&p_ptr->realm2);
1694 rd_byte(&tmp8u); /* oops */
1696 if (z_older_than(10, 4, 4))
1698 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1699 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1700 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1701 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1704 /* Special Race/Class info */
1706 p_ptr->hitdie = tmp8u;
1707 rd_u16b(&p_ptr->expfact);
1709 /* Age/Height/Weight */
1710 rd_s16b(&p_ptr->age);
1711 rd_s16b(&p_ptr->ht);
1712 rd_s16b(&p_ptr->wt);
1714 /* Read the stat info */
1715 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1716 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1717 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1719 strip_bytes(24); /* oops */
1721 rd_s32b(&p_ptr->au);
1723 rd_s32b(&p_ptr->max_exp);
1724 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1725 else rd_s32b(&p_ptr->max_max_exp);
1726 rd_s32b(&p_ptr->exp);
1728 if (h_older_than(1, 7, 0, 3))
1731 p_ptr->exp_frac = (u32b)tmp16u;
1735 rd_u32b(&p_ptr->exp_frac);
1738 rd_s16b(&p_ptr->lev);
1740 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1741 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1743 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1745 if (z_older_than(10, 3, 6))
1746 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1748 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1749 for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1750 if (z_older_than(10, 4, 1))
1752 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1753 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1755 if (z_older_than(10, 3, 14))
1757 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1758 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1762 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1763 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1764 if (h_older_than(1, 3, 0, 1))
1766 if (p_ptr->pclass == CLASS_SMITH)
1768 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1769 p_ptr->magic_num1[96] = 0;
1770 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1771 p_ptr->magic_num1[97] = 0;
1775 if (music_singing_any()) p_ptr->action = ACTION_SING;
1777 if (z_older_than(11, 0, 7))
1779 p_ptr->start_race = p_ptr->prace;
1780 p_ptr->old_race1 = 0L;
1781 p_ptr->old_race2 = 0L;
1782 p_ptr->old_realm = 0;
1786 rd_byte(&p_ptr->start_race);
1787 rd_s32b(&p_ptr->old_race1);
1788 rd_s32b(&p_ptr->old_race2);
1789 rd_s16b(&p_ptr->old_realm);
1792 if (z_older_than(10, 0, 1))
1794 for (i = 0; i < MAX_MANE; i++)
1796 p_ptr->mane_spell[i] = -1;
1797 p_ptr->mane_dam[i] = 0;
1799 p_ptr->mane_num = 0;
1801 else if (z_older_than(10, 2, 3))
1803 for (i = 0; i < OLD_MAX_MANE; i++)
1808 for (i = 0; i < MAX_MANE; i++)
1810 p_ptr->mane_spell[i] = -1;
1811 p_ptr->mane_dam[i] = 0;
1814 p_ptr->mane_num = 0;
1818 for (i = 0; i < MAX_MANE; i++)
1820 rd_s16b(&p_ptr->mane_spell[i]);
1821 rd_s16b(&p_ptr->mane_dam[i]);
1823 rd_s16b(&p_ptr->mane_num);
1826 if (z_older_than(10, 0, 3))
1828 determine_bounty_uniques();
1830 for (i = 0; i < MAX_KUBI; i++)
1832 /* Is this bounty unique already dead? */
1833 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1838 for (i = 0; i < MAX_KUBI; i++)
1840 rd_s16b(&kubi_r_idx[i]);
1844 if (z_older_than(10, 0, 3))
1850 for (i = 0; i < 4; i++)
1852 rd_s16b(&battle_mon[i]);
1853 if (z_older_than(10, 3, 4))
1856 mon_odds[i] = tmp16s;
1858 else rd_u32b(&mon_odds[i]);
1862 rd_s16b(&p_ptr->town_num);
1864 /* Read arena and rewards information */
1865 rd_s16b(&p_ptr->arena_number);
1866 if (h_older_than(1, 5, 0, 1))
1868 /* Arena loser of previous version was marked number 99 */
1869 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1872 p_ptr->inside_arena = (bool)tmp16s;
1873 rd_s16b(&p_ptr->inside_quest);
1874 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1878 p_ptr->inside_battle = (bool)tmp16s;
1880 rd_byte(&p_ptr->exit_bldg);
1884 p_ptr->oldpx = (POSITION)tmp16s;
1886 p_ptr->oldpy = (POSITION)tmp16s;
1888 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1890 /* Was p_ptr->rewards[MAX_BACT] */
1892 for (i = 0; i < tmp16s; i++)
1898 if (h_older_than(1, 7, 0, 3))
1901 p_ptr->mhp = tmp16s;
1904 p_ptr->chp = tmp16s;
1907 p_ptr->chp_frac = (u32b)tmp16u;
1911 rd_s32b(&p_ptr->mhp);
1912 rd_s32b(&p_ptr->chp);
1913 rd_u32b(&p_ptr->chp_frac);
1916 if (h_older_than(1, 7, 0, 3))
1919 p_ptr->msp = tmp16s;
1922 p_ptr->csp = tmp16s;
1925 p_ptr->csp_frac = (u32b)tmp16u;
1929 rd_s32b(&p_ptr->msp);
1930 rd_s32b(&p_ptr->csp);
1931 rd_u32b(&p_ptr->csp_frac);
1934 rd_s16b(&p_ptr->max_plv);
1935 if (z_older_than(10, 3, 8))
1937 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1941 byte max = (byte)max_d_idx;
1945 for(i = 0; i < max; i++)
1947 rd_s16b(&max_dlv[i]);
1948 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1952 /* Repair maximum player level XXX XXX XXX */
1953 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1957 rd_s16b(&p_ptr->sc);
1958 rd_s16b(&p_ptr->concent);
1960 /* Read the flags */
1961 strip_bytes(2); /* Old "rest" */
1962 rd_s16b(&p_ptr->blind);
1963 rd_s16b(&p_ptr->paralyzed);
1964 rd_s16b(&p_ptr->confused);
1965 rd_s16b(&p_ptr->food);
1966 strip_bytes(4); /* Old "food_digested" / "protection" */
1968 rd_s16b(&p_ptr->energy_need);
1969 if (z_older_than(11, 0, 13))
1970 p_ptr->energy_need = 100 - p_ptr->energy_need;
1971 if (h_older_than(2, 1, 2, 0))
1972 p_ptr->enchant_energy_need = 0;
1974 rd_s16b(&p_ptr->enchant_energy_need);
1976 rd_s16b(&p_ptr->fast);
1977 rd_s16b(&p_ptr->slow);
1978 rd_s16b(&p_ptr->afraid);
1979 rd_s16b(&p_ptr->cut);
1980 rd_s16b(&p_ptr->stun);
1981 rd_s16b(&p_ptr->poisoned);
1982 rd_s16b(&p_ptr->image);
1983 rd_s16b(&p_ptr->protevil);
1984 rd_s16b(&p_ptr->invuln);
1985 if(z_older_than(10, 0, 0))
1988 rd_s16b(&p_ptr->ult_res);
1989 rd_s16b(&p_ptr->hero);
1990 rd_s16b(&p_ptr->shero);
1991 rd_s16b(&p_ptr->shield);
1992 rd_s16b(&p_ptr->blessed);
1993 rd_s16b(&p_ptr->tim_invis);
1994 rd_s16b(&p_ptr->word_recall);
1995 if (z_older_than(10, 3, 8))
1996 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2000 p_ptr->recall_dungeon = (byte)tmp16s;
2003 if (h_older_than(1, 5, 0, 0))
2004 p_ptr->alter_reality = 0;
2006 rd_s16b(&p_ptr->alter_reality);
2008 rd_s16b(&p_ptr->see_infra);
2009 rd_s16b(&p_ptr->tim_infra);
2010 rd_s16b(&p_ptr->oppose_fire);
2011 rd_s16b(&p_ptr->oppose_cold);
2012 rd_s16b(&p_ptr->oppose_acid);
2013 rd_s16b(&p_ptr->oppose_elec);
2014 rd_s16b(&p_ptr->oppose_pois);
2015 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2016 else rd_s16b(&p_ptr->tsuyoshi);
2018 /* Old savefiles do not have the following fields... */
2019 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2022 p_ptr->wraith_form = 0;
2023 p_ptr->resist_magic = 0;
2024 p_ptr->tim_regen = 0;
2025 p_ptr->kabenuke = 0;
2026 p_ptr->tim_stealth = 0;
2027 p_ptr->tim_levitation = 0;
2028 p_ptr->tim_sh_touki = 0;
2029 p_ptr->lightspeed = 0;
2030 p_ptr->tsubureru = 0;
2031 p_ptr->tim_res_nether = 0;
2032 p_ptr->tim_res_time = 0;
2033 p_ptr->mimic_form = 0;
2034 p_ptr->tim_mimic = 0;
2035 p_ptr->tim_sh_fire = 0;
2038 p_ptr->tim_reflect = 0;
2039 p_ptr->multishadow = 0;
2040 p_ptr->dustrobe = 0;
2042 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2050 rd_s16b(&p_ptr->tim_esp);
2051 rd_s16b(&p_ptr->wraith_form);
2052 rd_s16b(&p_ptr->resist_magic);
2053 rd_s16b(&p_ptr->tim_regen);
2054 rd_s16b(&p_ptr->kabenuke);
2055 rd_s16b(&p_ptr->tim_stealth);
2056 rd_s16b(&p_ptr->tim_levitation);
2057 rd_s16b(&p_ptr->tim_sh_touki);
2058 rd_s16b(&p_ptr->lightspeed);
2059 rd_s16b(&p_ptr->tsubureru);
2060 if (z_older_than(10, 4, 7))
2061 p_ptr->magicdef = 0;
2063 rd_s16b(&p_ptr->magicdef);
2064 rd_s16b(&p_ptr->tim_res_nether);
2065 if (z_older_than(10, 4, 11))
2067 p_ptr->tim_res_time = 0;
2068 p_ptr->mimic_form = 0;
2069 p_ptr->tim_mimic = 0;
2070 p_ptr->tim_sh_fire = 0;
2074 rd_s16b(&p_ptr->tim_res_time);
2075 rd_byte(&p_ptr->mimic_form);
2076 rd_s16b(&p_ptr->tim_mimic);
2077 rd_s16b(&p_ptr->tim_sh_fire);
2080 if (z_older_than(11, 0, 99))
2082 p_ptr->tim_sh_holy = 0;
2083 p_ptr->tim_eyeeye = 0;
2087 rd_s16b(&p_ptr->tim_sh_holy);
2088 rd_s16b(&p_ptr->tim_eyeeye);
2092 if ( z_older_than(11,0,3) ){
2093 p_ptr->tim_reflect=0;
2094 p_ptr->multishadow=0;
2098 rd_s16b(&p_ptr->tim_reflect);
2099 rd_s16b(&p_ptr->multishadow);
2100 rd_s16b(&p_ptr->dustrobe);
2103 rd_s16b(&p_ptr->chaos_patron);
2104 rd_u32b(&p_ptr->muta1);
2105 rd_u32b(&p_ptr->muta2);
2106 rd_u32b(&p_ptr->muta3);
2108 for (i = 0; i < 8; i++)
2109 rd_s16b(&p_ptr->virtues[i]);
2110 for (i = 0; i < 8; i++)
2111 rd_s16b(&p_ptr->vir_types[i]);
2114 /* Calc the regeneration modifier for mutations */
2115 mutant_regenerate_mod = calc_mutant_regenerate_mod();
2117 if (z_older_than(10,0,9))
2120 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2121 p_ptr->ele_attack = 0;
2125 rd_s16b(&p_ptr->ele_attack);
2126 rd_u32b(&p_ptr->special_attack);
2128 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2129 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2130 if (z_older_than(10,0,12))
2132 p_ptr->ele_immune = 0;
2133 p_ptr->special_defense = 0;
2137 rd_s16b(&p_ptr->ele_immune);
2138 rd_u32b(&p_ptr->special_defense);
2140 rd_byte(&p_ptr->knowledge);
2143 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2145 rd_byte(&tmp8u); /* oops */
2146 rd_byte(&p_ptr->action);
2147 if (!z_older_than(10, 4, 3))
2150 if (tmp8u) p_ptr->action = ACTION_LEARN;
2152 rd_byte((byte *)&preserve_mode);
2153 rd_byte((byte *)&p_ptr->wait_report_score);
2156 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2158 /* Skip the flags */
2162 /* Hack -- the two "special seeds" */
2163 rd_u32b(&seed_flavor);
2164 rd_u32b(&seed_town);
2168 rd_u16b(&p_ptr->panic_save);
2169 rd_u16b(&p_ptr->total_winner);
2170 rd_u16b(&p_ptr->noscore);
2175 p_ptr->is_dead = tmp8u;
2177 /* Read "feeling" */
2178 rd_byte(&p_ptr->feeling);
2180 switch (p_ptr->start_race)
2186 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2189 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2192 dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2194 /* Turn when level began */
2197 if (h_older_than(1, 7, 0, 4))
2199 p_ptr->feeling_turn = old_turn;
2203 /* Turn of last "feeling" */
2204 rd_s32b(&p_ptr->feeling_turn);
2210 if (z_older_than(10, 3, 12))
2212 dungeon_turn = turn;
2214 else rd_s32b(&dungeon_turn);
2216 if (z_older_than(11, 0, 13))
2219 p_ptr->feeling_turn /= 2;
2224 if (z_older_than(10, 3, 13))
2228 else rd_s32b(&old_battle);
2230 if (z_older_than(10,0,3))
2232 determine_today_mon(TRUE);
2236 rd_s16b(&today_mon);
2237 rd_s16b(&p_ptr->today_mon);
2240 if (z_older_than(10,0,7))
2246 rd_s16b(&p_ptr->riding);
2249 /* Current floor_id */
2250 if (h_older_than(1, 5, 0, 0))
2252 p_ptr->floor_id = 0;
2256 rd_s16b(&p_ptr->floor_id);
2259 if (h_older_than(1, 5, 0, 2))
2265 /* Get number of party_mon array */
2268 /* Strip old temporary preserved pets */
2269 for (i = 0; i < tmp16s; i++)
2271 monster_type dummy_mon;
2273 rd_monster(&dummy_mon);
2277 if (z_older_than(10,1,2))
2286 if (z_older_than(10,3,9))
2290 else if (z_older_than(10, 3, 10))
2298 rd_s32b(&p_ptr->visit);
2300 if (!z_older_than(11, 0, 5))
2302 rd_u32b(&p_ptr->count);
2308 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2311 * Note that the inventory changed in Angband 2.7.4. Two extra
2312 * pack slots were added and the equipment was rearranged. Note
2313 * that these two features combine when parsing old save-files, in
2314 * which items from the old "aux" slot are "carried", perhaps into
2315 * one of the two new "inventory" slots.
2317 * Note that the inventory is "re-sorted" later by "dungeon()".
2319 static errr rd_inventory(void)
2327 p_ptr->total_weight = 0;
2333 /* Read until done */
2338 /* Get the next item index */
2341 /* Nope, we reached the end */
2342 if (n == 0xFFFF) break;
2344 /* Get local object */
2347 /* Wipe the object */
2353 /* Hack -- verify item */
2354 if (!q_ptr->k_idx) return (53);
2356 /* Wield equipment */
2357 if (n >= INVEN_RARM)
2359 /* Player touches it */
2360 q_ptr->marked |= OM_TOUCHED;
2363 object_copy(&inventory[n], q_ptr);
2365 /* Add the weight */
2366 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2372 /* Warning -- backpack is full */
2373 else if (inven_cnt == INVEN_PACK)
2376 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
2382 /* Carry inventory */
2388 /* Player touches it */
2389 q_ptr->marked |= OM_TOUCHED;
2392 object_copy(&inventory[n], q_ptr);
2394 /* Add the weight */
2395 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2408 * @brief メッセージログを読み込む / Read the saved messages
2411 static void rd_messages(void)
2417 if (h_older_than(2, 2, 0, 75))
2423 /* Read the messages */
2424 for (i = 0; i < num; i++)
2426 /* Read the message */
2427 rd_string(buf, sizeof(buf));
2429 /* Save the message */
2439 /* Read the messages */
2440 for (i = 0; i < num; i++)
2442 /* Read the message */
2443 rd_string(buf, sizeof(buf));
2445 /* Save the message */
2454 /* Old hidden trap flag */
2455 #define CAVE_TRAP 0x8000
2457 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2458 #define OLD_FEAT_INVIS 0x02
2459 #define OLD_FEAT_GLYPH 0x03
2460 #define OLD_FEAT_QUEST_ENTER 0x08
2461 #define OLD_FEAT_QUEST_EXIT 0x09
2462 #define OLD_FEAT_MINOR_GLYPH 0x40
2463 #define OLD_FEAT_BLDG_1 0x81
2464 #define OLD_FEAT_MIRROR 0xc3
2467 #define OLD_QUEST_WATER_CAVE 18
2469 /* Quest constants */
2470 #define QUEST_OLD_CASTLE 27
2471 #define QUEST_ROYAL_CRYPT 28
2474 * @brief メッセージログを読み込む / Read the dungeon (old method)
2477 * The monsters/objects must be loaded in the same order
2478 * that they were stored, since the actual indexes matter.
2480 static errr rd_dungeon_old(void)
2491 /*** Basic info ***/
2495 dun_level = (DEPTH)tmp16s;
2496 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2497 else rd_byte(&dungeon_type);
2499 /* Set the base level for old versions */
2500 base_level = dun_level;
2503 base_level = (DEPTH)tmp16s;
2505 rd_s16b(&num_repro);
2507 p_ptr->y = (int)tmp16s;
2509 p_ptr->x = (int)tmp16s;
2510 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2512 cur_hgt = (POSITION)tmp16s;
2514 cur_wid = (POSITION)tmp16s;
2515 rd_s16b(&tmp16s); /* max_panel_rows */
2516 rd_s16b(&tmp16s); /* max_panel_cols */
2519 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2527 /*** Run length decoding ***/
2529 /* Load the dungeon data */
2530 for (x = y = 0; y < ymax; )
2536 if (z_older_than(10,3,6))
2545 /* Decline invalid flags */
2546 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2549 /* Apply the RLE info */
2550 for (i = count; i > 0; i--)
2552 /* Access the cave */
2553 c_ptr = &cave[y][x];
2555 /* Extract "info" */
2565 if (++y >= ymax) break;
2571 /*** Run length decoding ***/
2573 /* Load the dungeon data */
2574 for (x = y = 0; y < ymax; )
2580 /* Apply the RLE info */
2581 for (i = count; i > 0; i--)
2583 /* Access the cave */
2584 c_ptr = &cave[y][x];
2586 /* Extract "feat" */
2587 c_ptr->feat = (s16b)tmp8u;
2596 if (++y >= ymax) break;
2601 /*** Run length decoding ***/
2603 /* Load the dungeon data */
2604 for (x = y = 0; y < ymax; )
2610 /* Apply the RLE info */
2611 for (i = count; i > 0; i--)
2613 /* Access the cave */
2614 c_ptr = &cave[y][x];
2616 /* Extract "mimic" */
2617 c_ptr->mimic = (s16b)tmp8u;
2626 if (++y >= ymax) break;
2631 /*** Run length decoding ***/
2633 /* Load the dungeon data */
2634 for (x = y = 0; y < ymax; )
2640 /* Apply the RLE info */
2641 for (i = count; i > 0; i--)
2643 /* Access the cave */
2644 c_ptr = &cave[y][x];
2646 /* Extract "feat" */
2647 c_ptr->special = tmp16s;
2656 if (++y >= ymax) break;
2661 /* Convert cave data */
2662 if (z_older_than(11, 0, 99))
2664 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2666 /* Wipe old unused flags */
2667 cave[y][x].info &= ~(CAVE_MASK);
2671 if (h_older_than(1, 1, 1, 0))
2673 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2675 /* Access the cave */
2676 c_ptr = &cave[y][x];
2679 if (c_ptr->feat == OLD_FEAT_INVIS)
2681 c_ptr->feat = feat_floor;
2682 c_ptr->info |= CAVE_TRAP;
2685 /* Older than 1.1.1 */
2686 if (c_ptr->feat == OLD_FEAT_MIRROR)
2688 c_ptr->feat = feat_floor;
2689 c_ptr->info |= CAVE_OBJECT;
2694 if (h_older_than(1, 3, 1, 0))
2696 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2698 /* Access the cave */
2699 c_ptr = &cave[y][x];
2701 /* Old CAVE_IN_MIRROR flag */
2702 if (c_ptr->info & CAVE_OBJECT)
2704 c_ptr->mimic = feat_mirror;
2707 /* Runes will be mimics and flags */
2708 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2709 (c_ptr->feat == OLD_FEAT_GLYPH))
2711 c_ptr->info |= CAVE_OBJECT;
2712 c_ptr->mimic = c_ptr->feat;
2713 c_ptr->feat = feat_floor;
2716 /* Hidden traps will be trap terrains mimicing floor */
2717 else if (c_ptr->info & CAVE_TRAP)
2719 c_ptr->info &= ~CAVE_TRAP;
2720 c_ptr->mimic = c_ptr->feat;
2721 c_ptr->feat = choose_random_trap();
2724 /* Another hidden trap */
2725 else if (c_ptr->feat == OLD_FEAT_INVIS)
2727 c_ptr->mimic = feat_floor;
2728 c_ptr->feat = feat_trap_open;
2733 /* Quest 18 was removed */
2734 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2736 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2738 /* Access the cave */
2739 c_ptr = &cave[y][x];
2741 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2743 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2745 c_ptr->feat = feat_tree;
2748 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2750 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2753 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2754 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2756 c_ptr->feat = feat_up_stair;
2764 /* Read the item count */
2767 /* Verify maximum */
2768 if (limit > max_o_idx)
2770 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2774 /* Read the dungeon items */
2775 for (i = 1; i < limit; i++)
2782 /* Get a new record */
2788 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2794 o_ptr = &o_list[o_idx];
2800 /* XXX XXX XXX XXX XXX */
2803 if (o_ptr->held_m_idx)
2805 monster_type *m_ptr;
2808 m_ptr = &m_list[o_ptr->held_m_idx];
2811 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2813 /* Place the object */
2814 m_ptr->hold_o_idx = o_idx;
2820 /* Access the item location */
2821 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2824 o_ptr->next_o_idx = c_ptr->o_idx;
2826 /* Place the object */
2827 c_ptr->o_idx = o_idx;
2834 /* Read the monster count */
2837 /* Hack -- verify */
2838 if (limit > max_m_idx)
2840 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2844 /* Read the monsters */
2845 for (i = 1; i < limit; i++)
2848 monster_type *m_ptr;
2850 /* Get a new record */
2856 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2861 /* Acquire monster */
2862 m_ptr = &m_list[m_idx];
2864 /* Read the monster */
2869 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2871 /* Mark the location */
2872 c_ptr->m_idx = m_idx;
2875 real_r_ptr(m_ptr)->cur_num++;
2880 /* The dungeon is ready */
2881 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2882 character_dungeon = FALSE;
2884 character_dungeon = TRUE;
2892 * @brief 保存されたフロアを読み込む / Read the saved floor
2895 * The monsters/objects must be loaded in the same order
2896 * that they were stored, since the actual indexes matter.
2898 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2910 cave_template_type *templates;
2913 /*** Wipe all cave ***/
2917 /*** Basic info ***/
2919 /* Dungeon floor specific info follows */
2923 /*** Not a saved floor ***/
2926 dun_level = (DEPTH)tmp16s;
2927 base_level = dun_level;
2931 /*** The saved floor ***/
2934 if (tmp16s != sf_ptr->floor_id) return 171;
2937 if (tmp8u != sf_ptr->savefile_id) return 171;
2940 if (tmp16s != sf_ptr->dun_level) return 171;
2941 dun_level = sf_ptr->dun_level;
2944 if (tmp32s != sf_ptr->last_visit) return 171;
2947 if (tmp32u != sf_ptr->visit_mark) return 171;
2950 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2953 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2957 base_level = (DEPTH)tmp16s;
2958 rd_s16b(&num_repro);
2961 p_ptr->y = (int)tmp16u;
2964 p_ptr->x = (int)tmp16u;
2967 cur_hgt = (POSITION)tmp16s;
2969 cur_wid = (POSITION)tmp16s;
2971 rd_byte(&p_ptr->feeling);
2975 /*** Read template for cave_type ***/
2977 /* Read the template count */
2980 /* Allocate the "template" array */
2981 C_MAKE(templates, limit, cave_template_type);
2983 /* Read the templates */
2984 for (i = 0; i < limit; i++)
2986 cave_template_type *ct_ptr = &templates[i];
2989 rd_u16b(&ct_ptr->info);
2990 if (h_older_than(1, 7, 0, 2))
2993 ct_ptr->feat = (s16b)tmp8u;
2995 ct_ptr->mimic = (s16b)tmp8u;
2999 rd_s16b(&ct_ptr->feat);
3000 rd_s16b(&ct_ptr->mimic);
3002 rd_s16b(&ct_ptr->special);
3010 /*** Run length decoding ***/
3012 /* Load the dungeon data */
3013 for (x = y = 0; y < ymax; )
3025 } while (tmp8u == MAX_UCHAR);
3027 /* Apply the RLE info */
3028 for (i = count; i > 0; i--)
3030 /* Access the cave */
3031 cave_type *c_ptr = &cave[y][x];
3033 /* Extract cave data */
3034 c_ptr->info = templates[id].info;
3035 c_ptr->feat = templates[id].feat;
3036 c_ptr->mimic = templates[id].mimic;
3037 c_ptr->special = templates[id].special;
3046 if (++y >= ymax) break;
3051 /* Quest 18 was removed */
3052 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3054 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3056 /* Access the cave */
3057 cave_type *c_ptr = &cave[y][x];
3059 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
3061 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
3063 c_ptr->feat = feat_tree;
3066 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
3068 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3071 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3072 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3074 c_ptr->feat = feat_up_stair;
3080 /* Free the "template" array */
3081 C_KILL(templates, limit, cave_template_type);
3086 /* Read the item count */
3089 /* Verify maximum */
3090 if (limit > max_o_idx) return 151;
3093 /* Read the dungeon items */
3094 for (i = 1; i < limit; i++)
3100 /* Get a new record */
3104 if (i != o_idx) return 152;
3107 o_ptr = &o_list[o_idx];
3114 if (o_ptr->held_m_idx)
3116 monster_type *m_ptr;
3119 m_ptr = &m_list[o_ptr->held_m_idx];
3122 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3124 /* Place the object */
3125 m_ptr->hold_o_idx = o_idx;
3131 /* Access the item location */
3132 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3135 o_ptr->next_o_idx = c_ptr->o_idx;
3137 /* Place the object */
3138 c_ptr->o_idx = o_idx;
3145 /* Read the monster count */
3148 /* Hack -- verify */
3149 if (limit > max_m_idx) return 161;
3151 /* Read the monsters */
3152 for (i = 1; i < limit; i++)
3156 monster_type *m_ptr;
3158 /* Get a new record */
3162 if (i != m_idx) return 162;
3165 /* Acquire monster */
3166 m_ptr = &m_list[m_idx];
3168 /* Read the monster */
3173 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3175 /* Mark the location */
3176 c_ptr->m_idx = m_idx;
3179 real_r_ptr(m_ptr)->cur_num++;
3188 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3191 * The monsters/objects must be loaded in the same order
3192 * that they were stored, since the actual indexes matter.
3194 static errr rd_dungeon(void)
3200 /* Initialize saved_floors array and temporal files */
3201 init_saved_floors(FALSE);
3204 if (h_older_than(1, 5, 0, 0))
3206 err = rd_dungeon_old();
3208 /* Prepare floor_id of current floor */
3211 p_ptr->floor_id = get_new_floor_id();
3212 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3221 /* Number of floor_id used from birth */
3222 rd_s16b(&max_floor_id);
3224 /* Current dungeon type */
3225 rd_byte(&dungeon_type);
3228 /* Number of the saved_floors array elements */
3231 /*** No saved floor (On the surface etc.) ***/
3234 /* Read the current floor data */
3235 err = rd_saved_floor(NULL);
3238 /*** In the dungeon ***/
3242 /* Read the saved_floors array */
3243 for (i = 0; i < num; i++)
3245 saved_floor_type *sf_ptr = &saved_floors[i];
3247 rd_s16b(&sf_ptr->floor_id);
3248 rd_byte(&sf_ptr->savefile_id);
3249 rd_s16b(&sf_ptr->dun_level);
3250 rd_s32b(&sf_ptr->last_visit);
3251 rd_u32b(&sf_ptr->visit_mark);
3252 rd_s16b(&sf_ptr->upper_floor_id);
3253 rd_s16b(&sf_ptr->lower_floor_id);
3257 /* Move saved floors data to temporal files */
3258 for (i = 0; i < num; i++)
3260 saved_floor_type *sf_ptr = &saved_floors[i];
3263 /* Unused element */
3264 if (!sf_ptr->floor_id) continue;
3266 /* Read the failure mark */
3268 if (tmp8u) continue;
3270 /* Read from the save file */
3271 err = rd_saved_floor(sf_ptr);
3276 /* Re-save as temporal saved floor file */
3277 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3283 /* Finally load current floor data from temporal file */
3286 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3291 /*** Error messages ***/
3295 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3299 note(_("アイテム配置エラー", "Object allocation error"));
3303 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3307 note(_("モンスター配置エラー", "Monster allocation error"));
3311 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3315 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3319 note(_("Error 183", "Error 183"));
3323 /* The dungeon is ready */
3324 character_dungeon = TRUE;
3326 /* Success or Error */
3332 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3335 static errr rd_savefile_new_aux(void)
3347 #ifdef VERIFY_CHECKSUMS
3348 u32b n_x_check, n_v_check;
3349 u32b o_x_check, o_v_check;
3353 /* Strip the version bytes */
3356 /* Hack -- decrypt */
3357 xor_byte = sf_extra;
3360 /* Clear the checksums */
3364 /* Read the version number of the savefile */
3365 /* Old savefile will be version 0.0.0.3 */
3366 rd_byte(&h_ver_extra);
3367 rd_byte(&h_ver_patch);
3368 rd_byte(&h_ver_minor);
3369 rd_byte(&h_ver_major);
3371 /* Mention the savefile version */
3373 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3374 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3377 /* Operating system info */
3378 rd_u32b(&sf_system);
3380 /* Time of savefile creation */
3383 /* Number of resurrections */
3386 /* Number of times played */
3390 /* Later use (always zero) */
3393 /* Later use (always zero) */
3396 /* Later use (always zero) */
3400 rd_byte(&kanji_code);
3402 /* Read RNG state */
3404 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3406 /* Then the options */
3408 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3410 /* Then the "messages" */
3412 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3414 for (i = 0; i < max_r_idx; i++)
3416 /* Access that monster */
3417 monster_race *r_ptr = &r_info[i];
3419 /* Hack -- Reset the death counter */
3420 r_ptr->max_num = 100;
3422 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3424 /* Hack -- Non-unique Nazguls are semi-unique */
3425 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3428 /* Monster Memory */
3431 /* Incompatible save files */
3432 if (tmp16u > max_r_idx)
3434 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3438 /* Read the available records */
3439 for (i = 0; i < tmp16u; i++)
3445 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3450 /* Incompatible save files */
3451 if (tmp16u > max_k_idx)
3453 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3457 /* Read the object memory */
3458 for (i = 0; i < tmp16u; i++)
3460 object_kind *k_ptr = &k_info[i];
3464 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3465 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3467 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3469 /* 2.1.3 or newer version */
3471 u16b max_towns_load;
3472 u16b max_quests_load;
3473 byte max_rquests_load;
3474 s16b old_inside_quest = p_ptr->inside_quest;
3476 /* Number of towns */
3477 rd_u16b(&max_towns_load);
3479 /* Incompatible save files */
3480 if (max_towns_load > max_towns)
3482 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3486 /* Number of quests */
3487 rd_u16b(&max_quests_load);
3489 if (z_older_than(11, 0, 7))
3491 max_rquests_load = 10;
3495 rd_byte(&max_rquests_load);
3498 /* Incompatible save files */
3499 if (max_quests_load > max_quests)
3501 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3505 for (i = 0; i < max_quests_load; i++)
3509 quest_type* const q_ptr = &quest[i];
3511 rd_s16b(&q_ptr->status);
3512 rd_s16b(&q_ptr->level);
3514 if (z_older_than(11, 0, 6))
3520 rd_byte(&q_ptr->complev);
3522 if(h_older_than(2, 1, 2, 2))
3524 q_ptr->comptime = 0;
3528 rd_u32b(&q_ptr->comptime);
3531 /* Load quest status if quest is running */
3532 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3533 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3534 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3536 rd_s16b(&q_ptr->cur_num);
3537 rd_s16b(&q_ptr->max_num);
3538 rd_s16b(&q_ptr->type);
3540 /* Load quest monster index */
3541 rd_s16b(&q_ptr->r_idx);
3543 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3545 determine_random_questor(&quest[i]);
3548 /* Load quest item index */
3549 rd_s16b(&q_ptr->k_idx);
3552 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3554 rd_byte(&q_ptr->flags);
3556 if (z_older_than(10, 3, 11))
3558 if (q_ptr->flags & QUEST_FLAG_PRESET)
3564 init_flags = INIT_ASSIGN;
3565 p_ptr->inside_quest = i;
3567 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3568 p_ptr->inside_quest = old_inside_quest;
3573 rd_byte(&q_ptr->dungeon);
3576 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3577 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3578 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3581 /* Ignore the empty quests from old versions */
3584 /* Ignore quest status */
3587 /* Ignore quest level */
3591 * We don't have to care about the other info,
3592 * since status should be 0 for these quests anyway
3597 /* Quest 18 was removed */
3598 if (h_older_than(1, 7, 0, 6))
3600 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3601 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3604 /* Position in the wilderness */
3605 rd_s32b(&p_ptr->wilderness_x);
3606 rd_s32b(&p_ptr->wilderness_y);
3607 if (z_older_than(10, 3, 13))
3609 p_ptr->wilderness_x = 5;
3610 p_ptr->wilderness_y = 48;
3613 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3614 else rd_byte((byte *)&p_ptr->wild_mode);
3615 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3616 else rd_byte((byte *)&ambush_flag);
3618 /* Size of the wilderness */
3619 rd_s32b(&wild_x_size);
3620 rd_s32b(&wild_y_size);
3622 /* Incompatible save files */
3623 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3625 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3629 /* Load the wilderness seeds */
3630 for (i = 0; i < wild_x_size; i++)
3632 for (j = 0; j < wild_y_size; j++)
3634 rd_u32b(&wilderness[j][i].seed);
3639 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3641 /* Load the Artifacts */
3644 /* Incompatible save files */
3645 if (tmp16u > max_a_idx)
3647 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3651 /* Read the artifact flags */
3652 for (i = 0; i < tmp16u; i++)
3654 artifact_type *a_ptr = &a_info[i];
3657 a_ptr->cur_num = tmp8u;
3659 if (h_older_than(1, 5, 0, 0))
3661 a_ptr->floor_id = 0;
3669 rd_s16b(&a_ptr->floor_id);
3672 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3674 /* Read the extra stuff */
3676 if (p_ptr->energy_need < -999) world_player = TRUE;
3678 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3681 /* Read the player_hp array */
3684 /* Incompatible save files */
3685 if (tmp16u > PY_MAX_LEVEL)
3687 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3691 /* Read the player_hp array */
3692 for (i = 0; i < tmp16u; i++)
3694 rd_s16b(&p_ptr->player_hp[i]);
3697 /* Important -- Initialize the sex */
3698 sp_ptr = &sex_info[p_ptr->psex];
3700 /* Important -- Initialize the race/class */
3701 rp_ptr = &race_info[p_ptr->prace];
3702 cp_ptr = &class_info[p_ptr->pclass];
3703 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3705 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3707 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3708 do_cmd_rerate(FALSE);
3710 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3712 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3713 do_cmd_rerate(FALSE);
3715 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3717 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3718 do_cmd_rerate(FALSE);
3720 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3722 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3723 do_cmd_rerate(FALSE);
3726 /* Important -- Initialize the magic */
3727 mp_ptr = &m_info[p_ptr->pclass];
3730 /* Read spell info */
3731 rd_u32b(&p_ptr->spell_learned1);
3732 rd_u32b(&p_ptr->spell_learned2);
3733 rd_u32b(&p_ptr->spell_worked1);
3734 rd_u32b(&p_ptr->spell_worked2);
3735 rd_u32b(&p_ptr->spell_forgotten1);
3736 rd_u32b(&p_ptr->spell_forgotten2);
3738 if (z_older_than(10,0,5))
3740 p_ptr->learned_spells = 0;
3741 for (i = 0; i < 64; i++)
3743 /* Count known spells */
3745 (p_ptr->spell_learned1 & (1L << i)) :
3746 (p_ptr->spell_learned2 & (1L << (i - 32))))
3748 p_ptr->learned_spells++;
3752 else rd_s16b(&p_ptr->learned_spells);
3754 if (z_older_than(10,0,6))
3756 p_ptr->add_spells = 0;
3758 else rd_s16b(&p_ptr->add_spells);
3759 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3761 for (i = 0; i < 64; i++)
3763 rd_byte(&p_ptr->spell_order[i]);
3767 /* Read the inventory */
3770 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3774 /* Read number of towns */
3776 town_count = tmp16u;
3778 /* Read the stores */
3780 for (i = 1; i < town_count; i++)
3782 for (j = 0; j < tmp16u; j++)
3784 if (rd_store(i, j)) return (22);
3788 rd_s16b(&p_ptr->pet_follow_distance);
3789 if (z_older_than(10, 4, 10))
3791 p_ptr->pet_extra_flags = 0;
3793 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3795 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3797 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3801 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3804 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3808 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3811 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3815 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3818 if (!z_older_than(10,0,8))
3821 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3826 rd_s16b(&p_ptr->pet_extra_flags);
3829 if (!z_older_than(11, 0, 9))
3831 char buf[SCREEN_BUF_SIZE];
3832 rd_string(buf, sizeof(buf));
3833 if (buf[0]) screen_dump = string_make(buf);
3838 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3840 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3845 /* I'm not dead yet... */
3846 if (!p_ptr->is_dead)
3848 /* Dead players have no dungeon */
3849 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3853 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3857 /* Read the ghost info */
3864 strip_bytes(tmp32s);
3868 /* Quest 18 was removed */
3869 if (h_older_than(1, 7, 0, 6))
3871 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3873 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3875 p_ptr->inside_quest = 0;
3880 #ifdef VERIFY_CHECKSUMS
3882 /* Save the checksum */
3883 n_v_check = v_check;
3885 /* Read the old checksum */
3886 rd_u32b(&o_v_check);
3889 if (o_v_check != n_v_check)
3891 note(_("チェックサムがおかしい", "Invalid checksum"));
3896 /* Save the encoded checksum */
3897 n_x_check = x_check;
3899 /* Read the checksum */
3900 rd_u32b(&o_x_check);
3904 if (o_x_check != n_x_check)
3906 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3917 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3920 errr rd_savefile_new(void)
3924 /* Grab permissions */
3927 /* The savefile is a binary file */
3928 fff = my_fopen(savefile, "rb");
3930 /* Drop permissions */
3934 if (!fff) return (-1);
3936 /* Call the sub-function */
3937 err = rd_savefile_new_aux();
3939 /* Check for errors */
3940 if (ferror(fff)) err = -1;
3942 /* Close the file */
3951 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3952 * @param sf_ptr 保存フロア読み込み先
3955 static bool load_floor_aux(saved_floor_type *sf_ptr)
3960 #ifdef VERIFY_CHECKSUMS
3961 u32b n_x_check, n_v_check;
3962 u32b o_x_check, o_v_check;
3965 /* Hack -- decrypt (read xor_byte) */
3969 /* Clear the checksums */
3973 /* Set the version number to current version */
3974 /* Never load old temporal files */
3975 h_ver_extra = H_VER_EXTRA;
3976 h_ver_patch = H_VER_PATCH;
3977 h_ver_minor = H_VER_MINOR;
3978 h_ver_major = H_VER_MAJOR;
3980 /* Verify the sign */
3982 if (saved_floor_file_sign != tmp32u) return FALSE;
3984 /* Read -- have error? */
3985 if (rd_saved_floor(sf_ptr)) return FALSE;
3988 #ifdef VERIFY_CHECKSUMS
3989 /* Save the checksum */
3990 n_v_check = v_check;
3992 /* Read the old checksum */
3993 rd_u32b(&o_v_check);
3996 if (o_v_check != n_v_check) return FALSE;
3998 /* Save the encoded checksum */
3999 n_x_check = x_check;
4001 /* Read the checksum */
4002 rd_u32b(&o_x_check);
4005 if (o_x_check != n_x_check) return FALSE;
4014 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4015 * @param sf_ptr 保存フロア読み込み先
4019 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
4021 FILE *old_fff = NULL;
4022 byte old_xor_byte = 0;
4023 u32b old_v_check = 0;
4024 u32b old_x_check = 0;
4025 byte old_h_ver_major = 0;
4026 byte old_h_ver_minor = 0;
4027 byte old_h_ver_patch = 0;
4028 byte old_h_ver_extra = 0;
4031 char floor_savefile[1024];
4033 byte old_kanji_code = kanji_code;
4036 * Temporal files are always written in system depended kanji
4041 /* EUC kanji code */
4045 /* SJIS kanji code */
4054 /* We have one file already opened */
4055 if (mode & SLF_SECOND)
4057 /* Backup original values */
4059 old_xor_byte = xor_byte;
4060 old_v_check = v_check;
4061 old_x_check = x_check;
4062 old_h_ver_major = h_ver_major;
4063 old_h_ver_minor = h_ver_minor;
4064 old_h_ver_patch = h_ver_patch;
4065 old_h_ver_extra = h_ver_extra;
4068 /* floor savefile */
4069 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4071 /* Grab permissions */
4074 /* The savefile is a binary file */
4075 fff = my_fopen(floor_savefile, "rb");
4077 /* Drop permissions */
4081 if (!fff) ok = FALSE;
4083 /* Attempt to load */
4086 /* Load saved floor data from file */
4087 ok = load_floor_aux(sf_ptr);
4089 /* Check for errors */
4090 if (ferror(fff)) ok = FALSE;
4092 /* Close the file */
4095 /* Grab permissions */
4098 /* Delete the file */
4099 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4101 /* Drop permissions */
4105 /* We have one file already opened */
4106 if (mode & SLF_SECOND)
4108 /* Restore original values */
4110 xor_byte = old_xor_byte;
4111 v_check = old_v_check;
4112 x_check = old_x_check;
4113 h_ver_major = old_h_ver_major;
4114 h_ver_minor = old_h_ver_minor;
4115 h_ver_patch = old_h_ver_patch;
4116 h_ver_extra = old_h_ver_extra;
4119 /* Restore old knowledge */
4120 kanji_code = old_kanji_code;