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.
49 #include "floor-generate.h"
57 #include "spells-status.h"
58 #include "object-hook.h"
62 #include "floor-save.h"
67 #include "dungeon-file.h"
69 #include "player-skill.h"
70 #include "player-class.h"
72 #include "objectkind.h"
76 * Maximum number of tries for selection of a proper quest monster
82 * Local "savefile" pointer
87 * Hack -- old "encryption" byte
92 * Hack -- simple "checksum" on the actual values
94 static u32b v_check = 0L;
97 * Hack -- simple "checksum" on the encoded bytes
99 static u32b x_check = 0L;
102 * Hack -- Japanese Kanji code
108 static byte kanji_code = 0;
111 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
112 * @param major メジャーバージョン値
113 * @param minor マイナーバージョン値
114 * @param patch パッチバージョン値
115 * @param extra エクストラパージョン値
116 * @return 現在のバージョンより値が古いならtrue
118 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
120 /* Much older, or much more recent */
121 if (h_ver_major < major) return (TRUE);
122 if (h_ver_major > major) return (FALSE);
124 /* Distinctly older, or distinctly more recent */
125 if (h_ver_minor < minor) return (TRUE);
126 if (h_ver_minor > minor) return (FALSE);
128 /* Barely older, or barely more recent */
129 if (h_ver_patch < patch) return (TRUE);
130 if (h_ver_patch > patch) return (FALSE);
132 /* Barely older, or barely more recent */
133 if (h_ver_extra < extra) return (TRUE);
134 if (h_ver_extra > extra) return (FALSE);
136 /* Identical versions */
142 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
143 * @param x メジャーバージョン値
144 * @param y マイナーバージョン値
146 * @return 現在のバージョンより値が古いならtrue
148 static bool z_older_than(byte x, byte y, byte z)
150 /* Much older, or much more recent */
151 if (z_major < x) return (TRUE);
152 if (z_major > x) return (FALSE);
154 /* Distinctly older, or distinctly more recent */
155 if (z_minor < y) return (TRUE);
156 if (z_minor > y) return (FALSE);
158 /* Barely older, or barely more recent */
159 if (z_patch < z) return (TRUE);
160 if (z_patch > z) return (FALSE);
162 /* Identical versions */
168 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
172 * Avoid the top two lines, to avoid interference with "msg_print()".
174 static void note(concptr msg)
176 static TERM_LEN y = 2;
178 /* Draw the message */
181 /* Advance one line (wrap if needed) */
182 if (++y >= 24) y = 2;
190 * @brief ロードファイルポインタから1バイトを読み込む
193 * The following functions are used to load the basic building blocks
194 * of savefiles. They also maintain the "checksum" info for 2.7.0+
196 static byte sf_get(void)
200 /* Get a character, decode the value */
201 c = getc(fff) & 0xFF;
205 /* Maintain the checksum info */
209 /* Return the value */
214 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
218 static void rd_byte(byte *ip)
224 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
228 static void rd_u16b(u16b *ip)
231 (*ip) |= ((u16b)(sf_get()) << 8);
235 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
239 static void rd_s16b(s16b *ip)
245 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
249 static void rd_u32b(u32b *ip)
252 (*ip) |= ((u32b)(sf_get()) << 8);
253 (*ip) |= ((u32b)(sf_get()) << 16);
254 (*ip) |= ((u32b)(sf_get()) << 24);
258 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
262 static void rd_s32b(s32b *ip)
269 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
270 * @param str 読み込みポインタ
271 * @param max 最大読み取りバイト数
274 static void rd_string(char *str, int max)
278 /* Read the string */
279 for (i = 0; TRUE; i++)
286 /* Collect string while legal */
287 if (i < max) str[i] = tmp8u;
298 /* Convert Kanji code */
317 /* 不明の漢字コードからシステムの漢字コードに変換 */
318 byte code = codeconv(str);
320 /* 漢字コードが判明したら、それを記録 */
321 if (code) kanji_code = code;
326 /* No conversion needed */
334 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
338 static void strip_bytes(int n)
342 /* Strip the bytes */
343 while (n--) rd_byte(&tmp8u);
346 #define OLD_MAX_MANE 22
349 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
350 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
353 * This function attempts to "repair" old savefiles, and to extract
354 * the most up to date values for various object fields.
356 * Note that Angband 2.7.9 introduced a new method for object "flags"
357 * in which the "flags" on an object are actually extracted when they
358 * are needed from the object kind, artifact index, ego-item index,
359 * and two special "xtra" fields which are used to encode any "extra"
360 * power of certain ego-items. This had the side effect that items
361 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
362 * may have had, and also, all "uncursed" items will become "cursed"
363 * again, including Calris, even if it is being worn at the time. As
364 * a complete hack, items which are inscribed with "uncursed" will be
365 * "uncursed" when imported from pre-2.7.9 savefiles.
367 static void rd_item_old(object_type *o_ptr)
375 rd_s16b(&o_ptr->k_idx);
378 o_ptr->iy = (POSITION)tmp8u;
380 o_ptr->ix = (POSITION)tmp8u;
388 if (z_older_than(10, 4, 4))
390 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
391 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
392 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
396 rd_s16b(&o_ptr->pval);
398 rd_byte(&o_ptr->discount);
400 o_ptr->number = (ITEM_NUMBER)tmp8u;
403 o_ptr->weight = tmp16s;
406 o_ptr->name1 = tmp8u;
409 o_ptr->name2 = tmp8u;
411 rd_s16b(&o_ptr->timeout);
413 rd_s16b(&o_ptr->to_h);
416 o_ptr->to_d = tmp16s;
417 rd_s16b(&o_ptr->to_a);
426 rd_byte(&o_ptr->ident);
428 rd_byte(&o_ptr->marked);
431 rd_u32b(&o_ptr->art_flags[0]);
432 rd_u32b(&o_ptr->art_flags[1]);
433 rd_u32b(&o_ptr->art_flags[2]);
434 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
435 else rd_u32b(&o_ptr->art_flags[3]);
437 if (h_older_than(1, 3, 0, 0))
439 if (o_ptr->name2 == EGO_TELEPATHY)
440 add_flag(o_ptr->art_flags, TR_TELEPATHY);
443 if (z_older_than(11, 0, 11))
445 o_ptr->curse_flags = 0L;
446 if (o_ptr->ident & 0x40)
448 o_ptr->curse_flags |= TRC_CURSED;
449 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
450 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
451 if (object_is_fixed_artifact(o_ptr))
453 artifact_type *a_ptr = &a_info[o_ptr->name1];
454 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
455 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
457 else if (object_is_ego(o_ptr))
459 ego_item_type *e_ptr = &e_info[o_ptr->name2];
460 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
461 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
464 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
468 rd_u32b(&o_ptr->curse_flags);
471 /* Monster holding object */
472 rd_s16b(&o_ptr->held_m_idx);
475 rd_byte(&o_ptr->xtra1);
476 rd_byte(&o_ptr->xtra2);
478 if (z_older_than(11, 0, 10))
480 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
482 switch (o_ptr->xtra2 % 6)
484 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
485 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
486 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
487 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
488 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
489 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
493 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
495 switch (o_ptr->xtra2 % 11)
497 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
498 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
499 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
500 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
501 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
502 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
503 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
504 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
505 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
506 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
507 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
511 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
513 switch (o_ptr->xtra2 % 8)
515 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
516 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
517 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
518 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
519 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
520 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
521 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
522 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
529 if (z_older_than(10, 2, 3))
534 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
536 o_ptr->xtra3 = o_ptr->xtra1;
539 if (o_ptr->tval == TV_CAPTURE)
541 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
542 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
544 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
545 if (ironman_nightmare)
547 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
549 o_ptr->xtra4 = o_ptr->xtra5;
554 rd_byte(&o_ptr->xtra3);
555 if (h_older_than(1, 3, 0, 1))
557 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
558 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
561 rd_s16b(&o_ptr->xtra4);
562 rd_s16b(&o_ptr->xtra5);
565 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)))
567 o_ptr->xtra4 = o_ptr->pval;
571 rd_byte(&o_ptr->feeling);
574 rd_string(buf, sizeof(buf));
576 /* Save the inscription */
577 if (buf[0]) o_ptr->inscription = quark_add(buf);
579 rd_string(buf, sizeof(buf));
580 if (buf[0]) o_ptr->art_name = quark_add(buf);
582 /* The Python object */
590 /* Mega-Hack -- handle "dungeon objects" later */
591 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
593 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
595 if (z_older_than(10, 4, 9))
597 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
599 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
600 add_flag(o_ptr->art_flags, TR_DEC_MANA);
603 if (object_is_fixed_artifact(o_ptr))
605 artifact_type *a_ptr;
607 /* Obtain the artifact info */
608 a_ptr = &a_info[o_ptr->name1];
610 /* Verify that artifact */
611 if (!a_ptr->name) o_ptr->name1 = 0;
613 if (object_is_ego(o_ptr))
615 ego_item_type *e_ptr;
617 /* Obtain the ego-item info */
618 e_ptr = &e_info[o_ptr->name2];
620 /* Verify that ego-item */
621 if (!e_ptr->name) o_ptr->name2 = 0;
628 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
629 * @param o_ptr アイテムオブジェクト保存先ポインタ
632 static void rd_item(object_type *o_ptr)
640 if (h_older_than(1, 5, 0, 0))
646 /*** Item save flags ***/
649 /*** Read un-obvious elements ***/
651 rd_s16b(&o_ptr->k_idx);
654 o_ptr->iy = (POSITION)tmp8u;
656 o_ptr->ix = (POSITION)tmp8u;
659 k_ptr = &k_info[o_ptr->k_idx];
660 o_ptr->tval = k_ptr->tval;
661 o_ptr->sval = k_ptr->sval;
664 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
665 else o_ptr->pval = 0;
667 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
668 else o_ptr->discount = 0;
669 if (flags & SAVE_ITEM_NUMBER) {
671 o_ptr->number = tmp8u;
673 else o_ptr->number = 1;
676 o_ptr->weight = tmp16s;
678 if (flags & SAVE_ITEM_NAME1)
681 o_ptr->name1 = tmp8u;
683 else o_ptr->name1 = 0;
684 if (flags & SAVE_ITEM_NAME2)
687 o_ptr->name2 = tmp8u;
689 else o_ptr->name2 = 0;
690 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
691 else o_ptr->timeout = 0;
693 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
694 else o_ptr->to_h = 0;
695 if (flags & SAVE_ITEM_TO_D)
698 o_ptr->to_d = tmp16s;
700 else o_ptr->to_d = 0;
701 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
702 else o_ptr->to_a = 0;
704 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
707 if (flags & SAVE_ITEM_DD)
713 if (flags & SAVE_ITEM_DS)
720 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
721 else o_ptr->ident = 0;
723 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
724 else o_ptr->marked = 0;
727 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
728 else o_ptr->art_flags[0] = 0;
729 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
730 else o_ptr->art_flags[1] = 0;
731 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
732 else o_ptr->art_flags[2] = 0;
733 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
734 else o_ptr->art_flags[3] = 0;
735 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
736 else o_ptr->art_flags[4] = 0;
738 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
739 else o_ptr->curse_flags = 0;
741 /* Monster holding object */
742 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
743 else o_ptr->held_m_idx = 0;
746 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
747 else o_ptr->xtra1 = 0;
748 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
749 else o_ptr->xtra2 = 0;
751 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
752 else o_ptr->xtra3 = 0;
754 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
755 else o_ptr->xtra4 = 0;
756 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
757 else o_ptr->xtra5 = 0;
759 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
760 else o_ptr->feeling = 0;
762 if (flags & SAVE_ITEM_INSCRIPTION)
764 rd_string(buf, sizeof(buf));
765 o_ptr->inscription = quark_add(buf);
767 else o_ptr->inscription = 0;
769 if (flags & SAVE_ITEM_ART_NAME)
771 rd_string(buf, sizeof(buf));
772 o_ptr->art_name = quark_add(buf);
774 else o_ptr->art_name = 0;
776 if(h_older_than(2,1,2,4))
778 BIT_FLAGS flgs[TR_FLAG_SIZE];
779 object_flags(o_ptr, flgs);
781 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
783 add_flag(o_ptr->art_flags, TR_LITE_M1);
784 remove_flag(o_ptr->art_flags, TR_LITE_1);
785 remove_flag(o_ptr->art_flags, TR_LITE_2);
786 remove_flag(o_ptr->art_flags, TR_LITE_3);
788 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
790 if (o_ptr->tval == TV_LITE)
792 if (o_ptr->sval == SV_LITE_TORCH)
794 add_flag(o_ptr->art_flags, TR_LITE_M1);
796 else if (o_ptr->sval == SV_LITE_LANTERN)
798 add_flag(o_ptr->art_flags, TR_LITE_M2);
800 else if (o_ptr->sval == SV_LITE_FEANOR)
802 add_flag(o_ptr->art_flags, TR_LITE_M3);
807 add_flag(o_ptr->art_flags, TR_LITE_M1);
810 else if (o_ptr->tval == TV_LITE)
812 if (object_is_fixed_artifact(o_ptr))
814 add_flag(o_ptr->art_flags, TR_LITE_3);
816 else if (o_ptr->sval == SV_LITE_TORCH)
818 add_flag(o_ptr->art_flags, TR_LITE_1);
819 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
821 else if (o_ptr->sval == SV_LITE_LANTERN)
823 add_flag(o_ptr->art_flags, TR_LITE_2);
824 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
826 else if (o_ptr->sval == SV_LITE_FEANOR)
828 add_flag(o_ptr->art_flags, TR_LITE_2);
836 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
837 * @param m_ptr モンスター保存先ポインタ
840 static void rd_monster_old(monster_type *m_ptr)
847 /* Read the monster race */
848 rd_s16b(&m_ptr->r_idx);
850 if (z_older_than(11, 0, 12))
851 m_ptr->ap_r_idx = m_ptr->r_idx;
853 rd_s16b(&m_ptr->ap_r_idx);
855 if (z_older_than(11, 0, 14))
857 monster_race *r_ptr = &r_info[m_ptr->r_idx];
859 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
860 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
861 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
864 rd_byte(&m_ptr->sub_align);
866 /* Read the other information */
868 m_ptr->fy = (POSITION)tmp8u;
870 m_ptr->fx = (POSITION)tmp8u;
875 m_ptr->maxhp = tmp16s;
877 if (z_older_than(11, 0, 5))
879 m_ptr->max_maxhp = m_ptr->maxhp;
884 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
886 if(h_older_than(2, 1, 2, 1))
888 m_ptr->dealt_damage = 0;
892 rd_s32b(&m_ptr->dealt_damage);
895 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
898 m_ptr->mspeed = tmp8u;
900 if (z_older_than(10, 4, 2))
903 m_ptr->energy_need = (s16b)tmp8u;
905 else rd_s16b(&m_ptr->energy_need);
907 if (z_older_than(11, 0, 13))
908 m_ptr->energy_need = 100 - m_ptr->energy_need;
910 if (z_older_than(10,0,7))
912 m_ptr->mtimed[MTIMED_FAST] = 0;
913 m_ptr->mtimed[MTIMED_SLOW] = 0;
918 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
920 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
923 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
925 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
927 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
929 if (z_older_than(10,0,10))
933 else if (z_older_than(10,0,11))
941 m_ptr->target_y = (POSITION)tmp16s;
943 m_ptr->target_x = (POSITION)tmp16s;
947 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
949 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
950 rd_u32b(&m_ptr->smart);
954 if (z_older_than(10, 4, 5)) {
961 if (z_older_than(10, 2, 2))
963 if (m_ptr->r_idx < 0)
965 m_ptr->r_idx = (0-m_ptr->r_idx);
966 m_ptr->mflag2 |= MFLAG2_KAGE;
971 rd_byte(&m_ptr->mflag2);
974 if (z_older_than(11, 0, 12))
976 if (m_ptr->mflag2 & MFLAG2_KAGE)
977 m_ptr->ap_r_idx = MON_KAGE;
980 if (z_older_than(10, 1, 3))
986 rd_string(buf, sizeof(buf));
987 if (buf[0]) m_ptr->nickname = quark_add(buf);
995 * @brief モンスターを読み込む(現版) / Read a monster (New method)
996 * @param m_ptr モンスター保存先ポインタ
999 static void rd_monster(monster_type *m_ptr)
1007 if (h_older_than(1, 5, 0, 0))
1009 rd_monster_old(m_ptr);
1013 /*** Monster save flags ***/
1016 /*** Read un-obvious elements ***/
1018 /* Read the monster race */
1019 rd_s16b(&m_ptr->r_idx);
1021 /* Read the other information */
1023 m_ptr->fy = (POSITION)tmp8u;
1025 m_ptr->fx = (POSITION)tmp8u;
1028 m_ptr->hp = (HIT_POINT)tmp16s;
1030 m_ptr->maxhp = (HIT_POINT)tmp16s;
1032 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1034 if(h_older_than(2, 1, 2, 1))
1036 m_ptr->dealt_damage = 0;
1040 rd_s32b(&m_ptr->dealt_damage);
1043 /* Monster race index of its appearance */
1044 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1045 else m_ptr->ap_r_idx = m_ptr->r_idx;
1047 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1048 else m_ptr->sub_align = 0;
1050 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1051 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1054 m_ptr->mspeed = tmp8u;
1056 rd_s16b(&m_ptr->energy_need);
1058 if (flags & SAVE_MON_FAST)
1061 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1063 else m_ptr->mtimed[MTIMED_FAST] = 0;
1064 if (flags & SAVE_MON_SLOW)
1067 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1069 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1070 if (flags & SAVE_MON_STUNNED)
1073 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1075 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1076 if (flags & SAVE_MON_CONFUSED)
1079 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1081 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1082 if (flags & SAVE_MON_MONFEAR)
1085 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1087 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1089 if (flags & SAVE_MON_TARGET_Y)
1092 m_ptr->target_y = (POSITION)tmp16s;
1094 else m_ptr->target_y = 0;
1095 if (flags & SAVE_MON_TARGET_X)
1098 m_ptr->target_x = (POSITION)tmp16s;
1100 else m_ptr->target_x = 0;
1102 if (flags & SAVE_MON_INVULNER)
1105 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1107 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1109 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1110 else m_ptr->smart = 0;
1112 if (flags & SAVE_MON_EXP)
1115 m_ptr->exp = (EXP)tmp32u;
1117 else m_ptr->exp = 0;
1119 m_ptr->mflag = 0; /* Not saved */
1121 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1122 else m_ptr->mflag2 = 0;
1124 if (flags & SAVE_MON_NICKNAME)
1126 rd_string(buf, sizeof(buf));
1127 m_ptr->nickname = quark_add(buf);
1129 else m_ptr->nickname = 0;
1131 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1132 else m_ptr->parent_m_idx = 0;
1137 * Old monster bit flags of racial resistances
1139 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1140 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1141 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1142 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1143 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1144 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1145 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1146 #define RF3_RES_WATE 0x00800000 /* Resist water */
1147 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1148 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1149 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1150 #define RF3_RES_ALL 0x08000000 /* Resist all */
1152 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1154 if ((R_PTR)->r_flags3 & (RF3)) \
1156 (R_PTR)->r_flags3 &= ~(RF3); \
1157 (R_PTR)->r_flagsr |= (RFR); \
1161 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1163 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1165 (R_PTR)->r_flagsr |= (RFR); \
1169 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1170 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1171 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1172 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1173 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1174 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1175 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1176 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1177 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1178 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1181 * @brief モンスターの思い出を読み込む / Read the monster lore
1182 * @param r_idx 読み込み先モンスターID
1185 static void rd_lore(MONRACE_IDX r_idx)
1190 monster_race *r_ptr = &r_info[r_idx];
1192 /* Count sights/deaths/kills */
1194 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1196 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1198 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1199 if (h_older_than(1, 7, 0, 5))
1201 r_ptr->r_akills = r_ptr->r_pkills;
1206 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1209 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1211 /* Count wakes and ignores */
1212 rd_byte(&r_ptr->r_wake);
1213 rd_byte(&r_ptr->r_ignore);
1216 rd_byte(&r_ptr->r_xtra1);
1217 rd_byte(&r_ptr->r_xtra2);
1221 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1223 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1227 rd_byte(&r_ptr->r_cast_spell);
1229 /* Count blows of each type */
1230 rd_byte(&r_ptr->r_blows[0]);
1231 rd_byte(&r_ptr->r_blows[1]);
1232 rd_byte(&r_ptr->r_blows[2]);
1233 rd_byte(&r_ptr->r_blows[3]);
1235 /* Memorize flags */
1236 rd_u32b(&r_ptr->r_flags1);
1237 rd_u32b(&r_ptr->r_flags2);
1238 rd_u32b(&r_ptr->r_flags3);
1239 rd_u32b(&r_ptr->r_flags4);
1240 rd_u32b(&r_ptr->r_flags5);
1241 rd_u32b(&r_ptr->r_flags6);
1242 if (h_older_than(1, 5, 0, 3))
1244 r_ptr->r_flagsr = 0L;
1246 /* Move RF3 resistance flags to RFR */
1247 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1248 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1249 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1250 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1251 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1252 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1253 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1254 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1255 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1256 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1257 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1258 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1260 /* Separate breathers resistance from RF4 to RFR */
1261 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1262 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1263 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1264 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1265 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1266 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1267 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1268 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1269 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1271 /* Resist confusion is merged to RF3_NO_CONF */
1272 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1274 /* Misc resistance hack to RFR */
1275 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1276 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1280 rd_u32b(&r_ptr->r_flagsr);
1283 /* Read the "Racial" monster limit per level */
1285 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1287 /* Location in saved floor */
1288 rd_s16b(&r_ptr->floor_id);
1293 /* Repair the lore flags */
1294 r_ptr->r_flags1 &= r_ptr->flags1;
1295 r_ptr->r_flags2 &= r_ptr->flags2;
1296 r_ptr->r_flags3 &= r_ptr->flags3;
1297 r_ptr->r_flags4 &= r_ptr->flags4;
1298 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1299 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1300 r_ptr->r_flagsr &= r_ptr->flagsr;
1304 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the p_ptr->inventory_list of the "Home"
1305 * @param st_ptr 店舗の参照ポインタ
1306 * @param o_ptr アイテムオブジェクト参照ポインタ
1309 * In all cases, return the slot (or -1) where the object was placed
1311 * Note that this is a hacked up version of "inven_carry()".
1313 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1314 * known, the player may have to pick stuff up and drop it again.
1316 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1324 /* Check each existing item (try to combine) */
1325 for (slot = 0; slot < st_ptr->stock_num; slot++)
1327 /* Get the existing item */
1328 j_ptr = &st_ptr->stock[slot];
1330 /* The home acts just like the player */
1331 if (object_similar(j_ptr, o_ptr))
1333 /* Save the new number of items */
1334 object_absorb(j_ptr, o_ptr);
1342 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1346 /* Determine the "value" of the item */
1347 value = object_value(o_ptr);
1349 /* Check existing slots to see if we must "slide" */
1350 for (slot = 0; slot < st_ptr->stock_num; slot++)
1352 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1355 /* Slide the others up */
1356 for (i = st_ptr->stock_num; i > slot; i--)
1358 st_ptr->stock[i] = st_ptr->stock[i-1];
1361 /* More stuff now */
1362 st_ptr->stock_num++;
1364 /* Insert the new item */
1365 st_ptr->stock[slot] = *o_ptr;
1367 chg_virtue(V_SACRIFICE, -1);
1369 /* Return the location */
1374 * @brief 店舗情報を読み込む / Read a store
1375 * @param town_number 街ID
1376 * @param store_number 店舗ID
1379 static errr rd_store(int town_number, int store_number)
1391 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1393 st_ptr = &town_info[1].store[store_number];
1394 if (st_ptr->stock_num) sort = TRUE;
1398 st_ptr = &town_info[town_number].store[store_number];
1401 /* Read the basic info */
1402 rd_s32b(&st_ptr->store_open);
1403 rd_s16b(&st_ptr->insult_cur);
1405 if (z_older_than(11, 0, 4))
1414 rd_s16b(&st_ptr->good_buy);
1415 rd_s16b(&st_ptr->bad_buy);
1417 /* Read last visit */
1418 rd_s32b(&st_ptr->last_visit);
1420 /* Extract the owner (see above) */
1421 st_ptr->owner = own;
1423 /* Read the items */
1424 for (j = 0; j < num; j++)
1434 /* Acquire valid items */
1435 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1440 home_carry(st_ptr, q_ptr);
1444 k = st_ptr->stock_num++;
1446 /* Acquire the item */
1447 object_copy(&st_ptr->stock[k], q_ptr);
1458 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1461 static void rd_randomizer(void)
1471 rd_u16b(&Rand_place);
1474 for (i = 0; i < RAND_DEG; i++)
1476 rd_u32b(&Rand_state[i]);
1483 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1486 * Note that the normal options are now stored as a set of 256 bit flags,
1487 * plus a set of 256 bit masks to indicate which bit flags were defined
1488 * at the time the savefile was created. This will allow new options
1489 * to be added, and old options to be removed, at any time, without
1490 * hurting old savefiles.
1492 * The window options are stored in the same way, but note that each
1493 * window gets 32 options, and their order is fixed by certain defines.
1495 static void rd_options(void)
1504 /* Ignore old options */
1507 /*** Special info */
1509 /* Read "delay_factor" */
1513 /* Read "hitpoint_warn" */
1517 /* Read "mana_warn" */
1518 if(h_older_than(1, 7, 0, 0))
1528 /*** Cheating options ***/
1532 if (c & 0x0002) p_ptr->wizard = TRUE;
1534 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1535 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1536 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1537 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1538 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1539 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1540 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1541 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1542 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1543 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1545 rd_byte((byte *)&autosave_l);
1546 rd_byte((byte *)&autosave_t);
1547 rd_s16b(&autosave_freq);
1550 /*** Normal Options ***/
1552 /* Read the option flags */
1553 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1555 /* Read the option 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 (option_mask[n] & (1L << i))
1571 if (flag[n] & (1L << i))
1574 option_flag[n] |= (1L << i);
1581 option_flag[n] &= ~(1L << i);
1588 if (z_older_than(10, 4, 5))
1590 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1591 else option_flag[5] |= (0x00000001 << 4);
1592 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1593 else option_flag[2] |= (0x00000001 << 5);
1594 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1595 else option_flag[4] |= (0x00000001 << 5);
1596 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1597 else option_flag[5] |= (0x00000001 << 0);
1598 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1599 else option_flag[5] |= (0x00000001 << 12);
1600 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1601 else option_flag[1] |= (0x00000001 << 0);
1602 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1603 else option_flag[1] |= (0x00000001 << 18);
1604 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1605 else option_flag[1] |= (0x00000001 << 19);
1606 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1607 else option_flag[5] |= (0x00000001 << 3);
1610 /* Extract the options */
1611 extract_option_vars();
1614 /*** Window Options ***/
1616 /* Read the window flags */
1617 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1619 /* Read the window masks */
1620 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1622 /* Analyze the options */
1623 for (n = 0; n < 8; n++)
1625 /* Analyze the options */
1626 for (i = 0; i < 32; i++)
1628 /* Process valid flags */
1629 if (mask[n] & (1L << i))
1631 /* Process valid flags */
1632 if (window_mask[n] & (1L << i))
1635 if (flag[n] & (1L << i))
1638 window_flag[n] |= (1L << i);
1645 window_flag[n] &= ~(1L << i);
1656 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1659 * This is such a nasty hack it hurts.
1661 static void rd_ghost(void)
1666 rd_string(buf, sizeof(buf));
1668 /* Strip old data */
1674 * @brief クイックスタート情報を読み込む / Load quick start data
1677 static void load_quick_start(void)
1683 if (z_older_than(11, 0, 13))
1685 previous_char.quick_ok = FALSE;
1689 rd_byte(&previous_char.psex);
1691 previous_char.prace = (RACE_IDX)tmp8u;
1693 previous_char.pclass = (CLASS_IDX)tmp8u;
1695 previous_char.pseikaku = (CHARACTER_IDX)tmp8u;
1697 previous_char.realm1 = (REALM_IDX)tmp8u;
1699 previous_char.realm2 = (REALM_IDX)tmp8u;
1701 rd_s16b(&previous_char.age);
1702 rd_s16b(&previous_char.ht);
1703 rd_s16b(&previous_char.wt);
1704 rd_s16b(&previous_char.sc);
1705 rd_s32b(&previous_char.au);
1707 for (i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1708 for (i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1710 for (i = 0; i < PY_MAX_LEVEL; i++)
1713 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1716 rd_s16b(&previous_char.chaos_patron);
1718 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1720 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1722 /* UNUSED : Was number of random quests */
1726 previous_char.quick_ok = (bool)tmp8u;
1730 * @brief その他の情報を読み込む / Read the "extra" information
1733 static void rd_extra(void)
1742 rd_string(p_ptr->name, sizeof(p_ptr->name));
1744 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1746 if (!h_older_than(1, 7, 0, 1))
1750 /* Read the message */
1751 rd_string(buf, sizeof buf);
1752 if (buf[0]) p_ptr->last_message = string_make(buf);
1757 for (i = 0; i < 4; i++)
1759 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1762 /* Class/Race/Seikaku/Gender/Spells */
1764 p_ptr->prace = (RACE_IDX)tmp8u;
1766 p_ptr->pclass = (CLASS_IDX)tmp8u;
1768 p_ptr->pseikaku = (CHARACTER_IDX)tmp8u;
1769 rd_byte(&p_ptr->psex);
1771 p_ptr->realm1 = (REALM_IDX)tmp8u;
1773 p_ptr->realm2 = (REALM_IDX)tmp8u;
1776 if (z_older_than(10, 4, 4))
1778 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1779 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1780 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1781 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1784 /* Special Race/Class info */
1786 p_ptr->hitdie = tmp8u;
1787 rd_u16b(&p_ptr->expfact);
1789 /* Age/Height/Weight */
1790 rd_s16b(&p_ptr->age);
1791 rd_s16b(&p_ptr->ht);
1792 rd_s16b(&p_ptr->wt);
1794 /* Read the stat info */
1795 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_max[i]);
1796 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1797 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_cur[i]);
1800 rd_s32b(&p_ptr->au);
1802 rd_s32b(&p_ptr->max_exp);
1803 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1804 else rd_s32b(&p_ptr->max_max_exp);
1805 rd_s32b(&p_ptr->exp);
1807 if (h_older_than(1, 7, 0, 3))
1810 p_ptr->exp_frac = (u32b)tmp16u;
1814 rd_u32b(&p_ptr->exp_frac);
1817 rd_s16b(&p_ptr->lev);
1819 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1820 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1822 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1824 if (z_older_than(10, 3, 6))
1825 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1827 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1828 for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1829 if (z_older_than(10, 4, 1))
1831 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1832 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1834 if (z_older_than(10, 3, 14))
1836 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1837 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1841 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1842 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1843 if (h_older_than(1, 3, 0, 1))
1845 if (p_ptr->pclass == CLASS_SMITH)
1847 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1848 p_ptr->magic_num1[96] = 0;
1849 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1850 p_ptr->magic_num1[97] = 0;
1854 if (music_singing_any()) p_ptr->action = ACTION_SING;
1856 if (z_older_than(11, 0, 7))
1858 p_ptr->start_race = p_ptr->prace;
1859 p_ptr->old_race1 = 0L;
1860 p_ptr->old_race2 = 0L;
1861 p_ptr->old_realm = 0;
1866 p_ptr->start_race = (RACE_IDX)tmp8u;
1868 p_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1870 p_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1871 rd_s16b(&p_ptr->old_realm);
1874 if (z_older_than(10, 0, 1))
1876 for (i = 0; i < MAX_MANE; i++)
1878 p_ptr->mane_spell[i] = -1;
1879 p_ptr->mane_dam[i] = 0;
1881 p_ptr->mane_num = 0;
1883 else if (z_older_than(10, 2, 3))
1885 for (i = 0; i < OLD_MAX_MANE; i++)
1890 for (i = 0; i < MAX_MANE; i++)
1892 p_ptr->mane_spell[i] = -1;
1893 p_ptr->mane_dam[i] = 0;
1896 p_ptr->mane_num = 0;
1900 for (i = 0; i < MAX_MANE; i++)
1903 p_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1905 p_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1907 rd_s16b(&p_ptr->mane_num);
1910 if (z_older_than(10, 0, 3))
1912 determine_bounty_uniques();
1914 for (i = 0; i < MAX_KUBI; i++)
1916 /* Is this bounty unique already dead? */
1917 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1922 for (i = 0; i < MAX_KUBI; i++)
1924 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1928 if (z_older_than(10, 0, 3))
1930 update_gambling_monsters();
1934 for (i = 0; i < 4; i++)
1936 rd_s16b(&battle_mon[i]);
1937 if (z_older_than(10, 3, 4))
1940 mon_odds[i] = tmp16s;
1942 else rd_u32b(&mon_odds[i]);
1946 rd_s16b(&p_ptr->town_num);
1948 /* Read arena and rewards information */
1949 rd_s16b(&p_ptr->arena_number);
1950 if (h_older_than(1, 5, 0, 1))
1952 /* Arena loser of previous version was marked number 99 */
1953 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1956 p_ptr->inside_arena = (bool)tmp16s;
1957 rd_s16b(&p_ptr->inside_quest);
1958 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1962 p_ptr->inside_battle = (bool)tmp16s;
1964 rd_byte(&p_ptr->exit_bldg);
1968 p_ptr->oldpx = (POSITION)tmp16s;
1970 p_ptr->oldpy = (POSITION)tmp16s;
1972 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1974 /* Was p_ptr->rewards[MAX_BACT] */
1976 for (i = 0; i < tmp16s; i++)
1982 if (h_older_than(1, 7, 0, 3))
1985 p_ptr->mhp = tmp16s;
1988 p_ptr->chp = tmp16s;
1991 p_ptr->chp_frac = (u32b)tmp16u;
1995 rd_s32b(&p_ptr->mhp);
1996 rd_s32b(&p_ptr->chp);
1997 rd_u32b(&p_ptr->chp_frac);
2000 if (h_older_than(1, 7, 0, 3))
2003 p_ptr->msp = tmp16s;
2006 p_ptr->csp = tmp16s;
2009 p_ptr->csp_frac = (u32b)tmp16u;
2013 rd_s32b(&p_ptr->msp);
2014 rd_s32b(&p_ptr->csp);
2015 rd_u32b(&p_ptr->csp_frac);
2018 rd_s16b(&p_ptr->max_plv);
2019 if (z_older_than(10, 3, 8))
2022 max_dlv[DUNGEON_ANGBAND] = tmp16s;
2026 byte max = (byte)max_d_idx;
2030 for(i = 0; i < max; i++)
2033 max_dlv[i] = tmp16s;
2034 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
2038 /* Repair maximum player level */
2039 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
2043 rd_s16b(&p_ptr->sc);
2044 rd_s16b(&p_ptr->concent);
2046 /* Read the flags */
2047 strip_bytes(2); /* Old "rest" */
2048 rd_s16b(&p_ptr->blind);
2049 rd_s16b(&p_ptr->paralyzed);
2050 rd_s16b(&p_ptr->confused);
2051 rd_s16b(&p_ptr->food);
2052 strip_bytes(4); /* Old "food_digested" / "protection" */
2054 rd_s16b(&p_ptr->energy_need);
2055 if (z_older_than(11, 0, 13))
2056 p_ptr->energy_need = 100 - p_ptr->energy_need;
2057 if (h_older_than(2, 1, 2, 0))
2058 p_ptr->enchant_energy_need = 0;
2060 rd_s16b(&p_ptr->enchant_energy_need);
2062 rd_s16b(&p_ptr->fast);
2063 rd_s16b(&p_ptr->slow);
2064 rd_s16b(&p_ptr->afraid);
2065 rd_s16b(&p_ptr->cut);
2066 rd_s16b(&p_ptr->stun);
2067 rd_s16b(&p_ptr->poisoned);
2068 rd_s16b(&p_ptr->image);
2069 rd_s16b(&p_ptr->protevil);
2070 rd_s16b(&p_ptr->invuln);
2071 if(z_older_than(10, 0, 0))
2074 rd_s16b(&p_ptr->ult_res);
2075 rd_s16b(&p_ptr->hero);
2076 rd_s16b(&p_ptr->shero);
2077 rd_s16b(&p_ptr->shield);
2078 rd_s16b(&p_ptr->blessed);
2079 rd_s16b(&p_ptr->tim_invis);
2080 rd_s16b(&p_ptr->word_recall);
2081 if (z_older_than(10, 3, 8))
2082 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2086 p_ptr->recall_dungeon = (byte)tmp16s;
2089 if (h_older_than(1, 5, 0, 0))
2090 p_ptr->alter_reality = 0;
2092 rd_s16b(&p_ptr->alter_reality);
2094 rd_s16b(&p_ptr->see_infra);
2095 rd_s16b(&p_ptr->tim_infra);
2096 rd_s16b(&p_ptr->oppose_fire);
2097 rd_s16b(&p_ptr->oppose_cold);
2098 rd_s16b(&p_ptr->oppose_acid);
2099 rd_s16b(&p_ptr->oppose_elec);
2100 rd_s16b(&p_ptr->oppose_pois);
2101 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2102 else rd_s16b(&p_ptr->tsuyoshi);
2104 /* Old savefiles do not have the following fields... */
2105 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2108 p_ptr->wraith_form = 0;
2109 p_ptr->resist_magic = 0;
2110 p_ptr->tim_regen = 0;
2111 p_ptr->kabenuke = 0;
2112 p_ptr->tim_stealth = 0;
2113 p_ptr->tim_levitation = 0;
2114 p_ptr->tim_sh_touki = 0;
2115 p_ptr->lightspeed = 0;
2116 p_ptr->tsubureru = 0;
2117 p_ptr->tim_res_nether = 0;
2118 p_ptr->tim_res_time = 0;
2119 p_ptr->mimic_form = 0;
2120 p_ptr->tim_mimic = 0;
2121 p_ptr->tim_sh_fire = 0;
2124 p_ptr->tim_reflect = 0;
2125 p_ptr->multishadow = 0;
2126 p_ptr->dustrobe = 0;
2128 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2136 rd_s16b(&p_ptr->tim_esp);
2137 rd_s16b(&p_ptr->wraith_form);
2138 rd_s16b(&p_ptr->resist_magic);
2139 rd_s16b(&p_ptr->tim_regen);
2140 rd_s16b(&p_ptr->kabenuke);
2141 rd_s16b(&p_ptr->tim_stealth);
2142 rd_s16b(&p_ptr->tim_levitation);
2143 rd_s16b(&p_ptr->tim_sh_touki);
2144 rd_s16b(&p_ptr->lightspeed);
2145 rd_s16b(&p_ptr->tsubureru);
2146 if (z_older_than(10, 4, 7))
2147 p_ptr->magicdef = 0;
2149 rd_s16b(&p_ptr->magicdef);
2150 rd_s16b(&p_ptr->tim_res_nether);
2151 if (z_older_than(10, 4, 11))
2153 p_ptr->tim_res_time = 0;
2154 p_ptr->mimic_form = 0;
2155 p_ptr->tim_mimic = 0;
2156 p_ptr->tim_sh_fire = 0;
2160 rd_s16b(&p_ptr->tim_res_time);
2162 p_ptr->mimic_form = (IDX)tmp8u;
2163 rd_s16b(&p_ptr->tim_mimic);
2164 rd_s16b(&p_ptr->tim_sh_fire);
2167 if (z_older_than(11, 0, 99))
2169 p_ptr->tim_sh_holy = 0;
2170 p_ptr->tim_eyeeye = 0;
2174 rd_s16b(&p_ptr->tim_sh_holy);
2175 rd_s16b(&p_ptr->tim_eyeeye);
2179 if ( z_older_than(11,0,3) ){
2180 p_ptr->tim_reflect=0;
2181 p_ptr->multishadow=0;
2185 rd_s16b(&p_ptr->tim_reflect);
2186 rd_s16b(&p_ptr->multishadow);
2187 rd_s16b(&p_ptr->dustrobe);
2190 rd_s16b(&p_ptr->chaos_patron);
2191 rd_u32b(&p_ptr->muta1);
2192 rd_u32b(&p_ptr->muta2);
2193 rd_u32b(&p_ptr->muta3);
2195 for (i = 0; i < 8; i++)
2196 rd_s16b(&p_ptr->virtues[i]);
2197 for (i = 0; i < 8; i++)
2198 rd_s16b(&p_ptr->vir_types[i]);
2201 /* Calc the regeneration modifier for mutations */
2202 p_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod();
2204 if (z_older_than(10,0,9))
2207 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2208 p_ptr->ele_attack = 0;
2212 rd_s16b(&p_ptr->ele_attack);
2213 rd_u32b(&p_ptr->special_attack);
2215 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2216 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2217 if (z_older_than(10,0,12))
2219 p_ptr->ele_immune = 0;
2220 p_ptr->special_defense = 0;
2224 rd_s16b(&p_ptr->ele_immune);
2225 rd_u32b(&p_ptr->special_defense);
2227 rd_byte(&p_ptr->knowledge);
2230 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2234 p_ptr->action = (ACTION_IDX)tmp8u;
2235 if (!z_older_than(10, 4, 3))
2238 if (tmp8u) p_ptr->action = ACTION_LEARN;
2240 rd_byte((byte *)&preserve_mode);
2241 rd_byte((byte *)&p_ptr->wait_report_score);
2244 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2246 /* Skip the flags */
2250 /* Hack -- the two "special seeds" */
2251 rd_u32b(¤t_world_ptr->seed_flavor);
2252 rd_u32b(¤t_world_ptr->seed_town);
2256 rd_u16b(&p_ptr->panic_save);
2257 rd_u16b(&p_ptr->total_winner);
2258 rd_u16b(&p_ptr->noscore);
2263 p_ptr->is_dead = tmp8u;
2265 /* Read "feeling" */
2266 rd_byte(&p_ptr->feeling);
2268 switch (p_ptr->start_race)
2274 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2277 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2280 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2282 /* Turn when level began */
2283 rd_s32b(¤t_floor_ptr->generated_turn);
2285 if (h_older_than(1, 7, 0, 4))
2287 p_ptr->feeling_turn = current_floor_ptr->generated_turn;
2291 /* Turn of last "feeling" */
2292 rd_s32b(&p_ptr->feeling_turn);
2295 /* Current current_world_ptr->game_turn */
2296 rd_s32b(¤t_world_ptr->game_turn);
2298 if (z_older_than(10, 3, 12))
2300 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2302 else rd_s32b(¤t_world_ptr->dungeon_turn);
2304 if (z_older_than(11, 0, 13))
2306 current_floor_ptr->generated_turn /= 2;
2307 p_ptr->feeling_turn /= 2;
2308 current_world_ptr->game_turn /= 2;
2309 current_world_ptr->dungeon_turn /= 2;
2312 if (z_older_than(10, 3, 13))
2314 old_battle = current_world_ptr->game_turn;
2316 else rd_s32b(&old_battle);
2318 if (z_older_than(10,0,3))
2320 determine_today_mon(TRUE);
2324 rd_s16b(&today_mon);
2325 rd_s16b(&p_ptr->today_mon);
2328 if (z_older_than(10,0,7))
2334 rd_s16b(&p_ptr->riding);
2337 /* Current floor_id */
2338 if (h_older_than(1, 5, 0, 0))
2340 p_ptr->floor_id = 0;
2344 rd_s16b(&p_ptr->floor_id);
2347 if (h_older_than(1, 5, 0, 2))
2353 /* Get number of party_mon array */
2356 /* Strip old temporary preserved pets */
2357 for (i = 0; i < tmp16s; i++)
2359 monster_type dummy_mon;
2361 rd_monster(&dummy_mon);
2365 if (z_older_than(10,1,2))
2367 current_world_ptr->play_time = 0;
2371 rd_u32b(¤t_world_ptr->play_time);
2374 if (z_older_than(10,3,9))
2378 else if (z_older_than(10, 3, 10))
2386 p_ptr->visit = (BIT_FLAGS)tmp32s;
2388 if (!z_older_than(11, 0, 5))
2390 rd_u32b(&p_ptr->count);
2396 * @brief プレイヤーの所持品情報を読み込む / Read the player p_ptr->inventory_list
2399 * Note that the p_ptr->inventory_list changed in Angband 2.7.4. Two extra
2400 * pack slots were added and the equipment was rearranged. Note
2401 * that these two features combine when parsing old save-files, in
2402 * which items from the old "aux" slot are "carried", perhaps into
2403 * one of the two new "p_ptr->inventory_list" slots.
2405 * Note that the p_ptr->inventory_list is "re-sorted" later by "dungeon()".
2407 static errr rd_inventory(void)
2415 p_ptr->total_weight = 0;
2418 p_ptr->inven_cnt = 0;
2419 p_ptr->equip_cnt = 0;
2421 /* Read until done */
2426 /* Get the next item index */
2429 /* Nope, we reached the end */
2430 if (n == 0xFFFF) break;
2437 /* Hack -- verify item */
2438 if (!q_ptr->k_idx) return (53);
2440 /* Wield equipment */
2441 if (n >= INVEN_RARM)
2443 q_ptr->marked |= OM_TOUCHED;
2444 object_copy(&p_ptr->inventory_list[n], q_ptr);
2446 /* Add the weight */
2447 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2453 /* Warning -- backpack is full */
2454 else if (p_ptr->inven_cnt == INVEN_PACK)
2456 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the p_ptr->inventory_list!"));
2462 /* Carry p_ptr->inventory_list */
2468 q_ptr->marked |= OM_TOUCHED;
2469 object_copy(&p_ptr->inventory_list[n], q_ptr);
2471 /* Add the weight */
2472 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2485 * @brief メッセージログを読み込む / Read the saved messages
2488 static void rd_messages(void)
2495 if (h_older_than(2, 2, 0, 75))
2500 message_max = (int)num;
2502 /* Read the messages */
2503 for (i = 0; i < message_max; i++)
2505 /* Read the message */
2506 rd_string(buf, sizeof(buf));
2508 /* Save the message */
2517 message_max = (int)num;
2519 /* Read the messages */
2520 for (i = 0; i < message_max; i++)
2522 /* Read the message */
2523 rd_string(buf, sizeof(buf));
2525 /* Save the message */
2534 /* Old hidden trap flag */
2535 #define CAVE_TRAP 0x8000
2537 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2538 #define OLD_FEAT_INVIS 0x02
2539 #define OLD_FEAT_GLYPH 0x03
2540 #define OLD_FEAT_QUEST_ENTER 0x08
2541 #define OLD_FEAT_QUEST_EXIT 0x09
2542 #define OLD_FEAT_MINOR_GLYPH 0x40
2543 #define OLD_FEAT_BLDG_1 0x81
2544 #define OLD_FEAT_MIRROR 0xc3
2547 #define OLD_QUEST_WATER_CAVE 18
2549 /* Quest constants */
2550 #define QUEST_OLD_CASTLE 27
2551 #define QUEST_ROYAL_CRYPT 28
2554 * @brief メッセージログを読み込む / Read the dungeon (old method)
2557 * The monsters/objects must be loaded in the same order
2558 * that they were stored, since the actual indexes matter.
2560 static errr rd_dungeon_old(void)
2571 /*** Basic info ***/
2575 current_floor_ptr->dun_level = (DEPTH)tmp16s;
2576 if (z_older_than(10, 3, 8)) p_ptr->dungeon_idx = DUNGEON_ANGBAND;
2580 p_ptr->dungeon_idx = (IDX)tmp8u;
2583 /* Set the base level for old versions */
2584 current_floor_ptr->base_level = current_floor_ptr->dun_level;
2587 current_floor_ptr->base_level = (DEPTH)tmp16s;
2590 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2592 p_ptr->y = (POSITION)tmp16s;
2594 p_ptr->x = (POSITION)tmp16s;
2595 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2597 current_floor_ptr->height = (POSITION)tmp16s;
2599 current_floor_ptr->width = (POSITION)tmp16s;
2600 rd_s16b(&tmp16s); /* max_panel_rows */
2601 rd_s16b(&tmp16s); /* max_panel_cols */
2604 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2608 ymax = current_floor_ptr->height;
2609 xmax = current_floor_ptr->width;
2612 /*** Run length decoding ***/
2614 /* Load the dungeon data */
2615 for (x = y = 0; y < ymax; )
2621 if (z_older_than(10,3,6))
2630 /* Decline invalid flags */
2631 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2634 /* Apply the RLE info */
2635 for (i = count; i > 0; i--)
2637 /* Access the current_floor_ptr->grid_array */
2638 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2640 /* Extract "info" */
2650 if (++y >= ymax) break;
2656 /*** Run length decoding ***/
2658 /* Load the dungeon data */
2659 for (x = y = 0; y < ymax; )
2665 /* Apply the RLE info */
2666 for (i = count; i > 0; i--)
2668 /* Access the current_floor_ptr->grid_array */
2669 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2671 /* Extract "feat" */
2672 g_ptr->feat = (s16b)tmp8u;
2681 if (++y >= ymax) break;
2686 /*** Run length decoding ***/
2688 /* Load the dungeon data */
2689 for (x = y = 0; y < ymax; )
2695 /* Apply the RLE info */
2696 for (i = count; i > 0; i--)
2698 /* Access the current_floor_ptr->grid_array */
2699 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2701 /* Extract "mimic" */
2702 g_ptr->mimic = (s16b)tmp8u;
2711 if (++y >= ymax) break;
2716 /*** Run length decoding ***/
2718 /* Load the dungeon data */
2719 for (x = y = 0; y < ymax; )
2725 /* Apply the RLE info */
2726 for (i = count; i > 0; i--)
2728 /* Access the current_floor_ptr->grid_array */
2729 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2731 /* Extract "feat" */
2732 g_ptr->special = tmp16s;
2741 if (++y >= ymax) break;
2746 /* Convert current_floor_ptr->grid_array data */
2747 if (z_older_than(11, 0, 99))
2749 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2751 /* Wipe old unused flags */
2752 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2756 if (h_older_than(1, 1, 1, 0))
2758 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2760 /* Access the current_floor_ptr->grid_array */
2761 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2764 if (g_ptr->feat == OLD_FEAT_INVIS)
2766 g_ptr->feat = feat_floor;
2767 g_ptr->info |= CAVE_TRAP;
2770 /* Older than 1.1.1 */
2771 if (g_ptr->feat == OLD_FEAT_MIRROR)
2773 g_ptr->feat = feat_floor;
2774 g_ptr->info |= CAVE_OBJECT;
2779 if (h_older_than(1, 3, 1, 0))
2781 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2783 /* Access the current_floor_ptr->grid_array */
2784 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2786 /* Old CAVE_IN_MIRROR flag */
2787 if (g_ptr->info & CAVE_OBJECT)
2789 g_ptr->mimic = feat_mirror;
2792 /* Runes will be mimics and flags */
2793 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2794 (g_ptr->feat == OLD_FEAT_GLYPH))
2796 g_ptr->info |= CAVE_OBJECT;
2797 g_ptr->mimic = g_ptr->feat;
2798 g_ptr->feat = feat_floor;
2801 /* Hidden traps will be trap terrains mimicing floor */
2802 else if (g_ptr->info & CAVE_TRAP)
2804 g_ptr->info &= ~CAVE_TRAP;
2805 g_ptr->mimic = g_ptr->feat;
2806 g_ptr->feat = choose_random_trap();
2809 /* Another hidden trap */
2810 else if (g_ptr->feat == OLD_FEAT_INVIS)
2812 g_ptr->mimic = feat_floor;
2813 g_ptr->feat = feat_trap_open;
2818 /* Quest 18 was removed */
2819 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2821 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2823 /* Access the current_floor_ptr->grid_array */
2824 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2826 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
2828 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2830 g_ptr->feat = feat_tree;
2833 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2835 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2838 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2839 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2841 g_ptr->feat = feat_up_stair;
2849 /* Read the item count */
2852 /* Verify maximum */
2853 if (limit > current_floor_ptr->max_o_idx)
2855 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2859 /* Read the dungeon items */
2860 for (i = 1; i < limit; i++)
2867 /* Get a new record */
2872 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2878 o_ptr = ¤t_floor_ptr->o_list[o_idx];
2886 if (o_ptr->held_m_idx)
2888 monster_type *m_ptr;
2889 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
2892 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2894 m_ptr->hold_o_idx = o_idx;
2900 /* Access the item location */
2901 g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2904 o_ptr->next_o_idx = g_ptr->o_idx;
2906 g_ptr->o_idx = o_idx;
2913 /* Read the monster count */
2916 /* Hack -- verify */
2917 if (limit > current_floor_ptr->max_m_idx)
2919 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2923 /* Read the monsters */
2924 for (i = 1; i < limit; i++)
2927 monster_type *m_ptr;
2929 /* Get a new record */
2934 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2939 /* Acquire monster */
2940 m_ptr = ¤t_floor_ptr->m_list[m_idx];
2942 /* Read the monster */
2947 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2949 /* Mark the location */
2950 g_ptr->m_idx = m_idx;
2953 real_r_ptr(m_ptr)->cur_num++;
2958 /* The dungeon is ready */
2959 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena)
2960 character_dungeon = FALSE;
2962 character_dungeon = TRUE;
2970 * @brief 保存されたフロアを読み込む / Read the saved floor
2971 * @return info読み込みエラーコード
2973 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2976 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2977 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2979 * The monsters/objects must be loaded in the same order
2980 * that they were stored, since the actual indexes matter.
2982 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2984 POSITION ymax, xmax;
2995 cave_template_type *templates;
2998 /*** Wipe all current_floor_ptr->grid_array ***/
3002 /*** Basic info ***/
3004 /* Dungeon floor specific info follows */
3008 /*** Not a saved floor ***/
3011 current_floor_ptr->dun_level = (DEPTH)tmp16s;
3012 current_floor_ptr->base_level = current_floor_ptr->dun_level;
3016 /*** The saved floor ***/
3019 if (tmp16s != sf_ptr->floor_id) return 171;
3022 if (tmp8u != sf_ptr->savefile_id) return 171;
3025 if (tmp16s != sf_ptr->dun_level) return 171;
3026 current_floor_ptr->dun_level = sf_ptr->dun_level;
3029 if (tmp32s != sf_ptr->last_visit) return 171;
3032 if (tmp32u != sf_ptr->visit_mark) return 171;
3035 if (tmp16s != sf_ptr->upper_floor_id) return 171;
3038 if (tmp16s != sf_ptr->lower_floor_id) return 171;
3042 current_floor_ptr->base_level = (DEPTH)tmp16s;
3044 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
3047 p_ptr->y = (POSITION)tmp16u;
3050 p_ptr->x = (POSITION)tmp16u;
3053 current_floor_ptr->height = (POSITION)tmp16s;
3055 current_floor_ptr->width = (POSITION)tmp16s;
3057 rd_byte(&p_ptr->feeling);
3061 /*** Read template for grid_type ***/
3063 /* Read the template count */
3066 /* Allocate the "template" array */
3067 C_MAKE(templates, limit, cave_template_type);
3069 /* Read the templates */
3070 for (i = 0; i < limit; i++)
3072 cave_template_type *ct_ptr = &templates[i];
3076 ct_ptr->info = (BIT_FLAGS)tmp16u;
3077 if (h_older_than(1, 7, 0, 2))
3080 ct_ptr->feat = (s16b)tmp8u;
3082 ct_ptr->mimic = (s16b)tmp8u;
3086 rd_s16b(&ct_ptr->feat);
3087 rd_s16b(&ct_ptr->mimic);
3089 rd_s16b(&ct_ptr->special);
3093 ymax = current_floor_ptr->height;
3094 xmax = current_floor_ptr->width;
3097 /*** Run length decoding ***/
3099 /* Load the dungeon data */
3100 for (x = y = 0; y < ymax; )
3112 } while (tmp8u == MAX_UCHAR);
3114 /* Apply the RLE info */
3115 for (i = count; i > 0; i--)
3117 /* Access the current_floor_ptr->grid_array */
3118 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3120 /* Extract current_floor_ptr->grid_array data */
3121 g_ptr->info = templates[id].info;
3122 g_ptr->feat = templates[id].feat;
3123 g_ptr->mimic = templates[id].mimic;
3124 g_ptr->special = templates[id].special;
3133 if (++y >= ymax) break;
3138 /* Quest 18 was removed */
3139 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3141 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3143 /* Access the current_floor_ptr->grid_array */
3144 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3146 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
3148 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
3150 g_ptr->feat = feat_tree;
3153 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
3155 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3158 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3159 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3161 g_ptr->feat = feat_up_stair;
3167 /* Free the "template" array */
3168 C_KILL(templates, limit, cave_template_type);
3173 /* Read the item count */
3176 /* Verify maximum */
3177 if (limit > current_floor_ptr->max_o_idx) return 151;
3180 /* Read the dungeon items */
3181 for (i = 1; i < limit; i++)
3187 /* Get a new record */
3190 if (i != o_idx) return 152;
3193 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3198 if (o_ptr->held_m_idx)
3200 monster_type *m_ptr;
3201 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
3204 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3206 m_ptr->hold_o_idx = o_idx;
3212 /* Access the item location */
3213 grid_type *g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
3216 o_ptr->next_o_idx = g_ptr->o_idx;
3218 g_ptr->o_idx = o_idx;
3225 /* Read the monster count */
3228 /* Hack -- verify */
3229 if (limit > current_floor_ptr->max_m_idx) return 161;
3231 /* Read the monsters */
3232 for (i = 1; i < limit; i++)
3236 monster_type *m_ptr;
3238 /* Get a new record */
3241 if (i != m_idx) return 162;
3244 /* Acquire monster */
3245 m_ptr = ¤t_floor_ptr->m_list[m_idx];
3247 /* Read the monster */
3252 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
3254 /* Mark the location */
3255 g_ptr->m_idx = m_idx;
3258 real_r_ptr(m_ptr)->cur_num++;
3267 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3270 * The monsters/objects must be loaded in the same order
3271 * that they were stored, since the actual indexes matter.
3273 static errr rd_dungeon(void)
3281 /* Initialize saved_floors array and temporal files */
3282 init_saved_floors(FALSE);
3285 if (h_older_than(1, 5, 0, 0))
3287 err = rd_dungeon_old();
3289 /* Prepare floor_id of current floor */
3290 if (p_ptr->dungeon_idx)
3292 p_ptr->floor_id = get_new_floor_id();
3293 get_sf_ptr(p_ptr->floor_id)->dun_level = current_floor_ptr->dun_level;
3302 /* Number of floor_id used from birth */
3303 rd_s16b(&max_floor_id);
3305 /* Current dungeon type */
3307 p_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
3309 /* Number of the saved_floors array elements */
3312 /*** No saved floor (On the surface etc.) ***/
3315 /* Read the current floor data */
3316 err = rd_saved_floor(NULL);
3319 /*** In the dungeon ***/
3323 /* Read the saved_floors array */
3324 for (i = 0; i < num; i++)
3326 saved_floor_type *sf_ptr = &saved_floors[i];
3328 rd_s16b(&sf_ptr->floor_id);
3330 sf_ptr->savefile_id = (s16b)tmp8u;
3333 sf_ptr->dun_level = (DEPTH)tmp16s;
3335 rd_s32b(&sf_ptr->last_visit);
3336 rd_u32b(&sf_ptr->visit_mark);
3337 rd_s16b(&sf_ptr->upper_floor_id);
3338 rd_s16b(&sf_ptr->lower_floor_id);
3342 /* Move saved floors data to temporal files */
3343 for (i = 0; i < num; i++)
3345 saved_floor_type *sf_ptr = &saved_floors[i];
3347 /* Unused element */
3348 if (!sf_ptr->floor_id) continue;
3350 /* Read the failure mark */
3352 if (tmp8u) continue;
3354 /* Read from the save file */
3355 err = rd_saved_floor(sf_ptr);
3360 /* Re-save as temporal saved floor file */
3361 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3367 /* Finally load current floor data from temporal file */
3370 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3375 /*** Error messages ***/
3379 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3383 note(_("アイテム配置エラー", "Object allocation error"));
3387 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3391 note(_("モンスター配置エラー", "Monster allocation error"));
3395 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3399 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3403 note(_("Error 183", "Error 183"));
3407 /* The dungeon is ready */
3408 character_dungeon = TRUE;
3410 /* Success or Error */
3416 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3419 static errr rd_savefile_new_aux(void)
3432 #ifdef VERIFY_CHECKSUMS
3433 u32b n_x_check, n_v_check;
3434 u32b o_x_check, o_v_check;
3438 /* Strip the version bytes */
3441 /* Hack -- decrypt */
3442 xor_byte = sf_extra;
3445 /* Clear the checksums */
3449 /* Read the version number of the savefile */
3450 /* Old savefile will be version 0.0.0.3 */
3451 rd_byte(&h_ver_extra);
3452 rd_byte(&h_ver_patch);
3453 rd_byte(&h_ver_minor);
3454 rd_byte(&h_ver_major);
3456 /* Mention the savefile version */
3458 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3459 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3462 /* Operating system info */
3463 rd_u32b(&sf_system);
3465 /* Time of savefile creation */
3468 /* Number of resurrections */
3471 /* Number of times played */
3475 /* Later use (always zero) */
3478 /* Later use (always zero) */
3481 /* Later use (always zero) */
3485 rd_byte(&kanji_code);
3487 /* Read RNG state */
3489 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3491 /* Then the options */
3493 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3495 /* Then the "messages" */
3497 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3499 for (i = 0; i < max_r_idx; i++)
3501 /* Access that monster */
3502 monster_race *r_ptr = &r_info[i];
3504 /* Hack -- Reset the death counter */
3505 r_ptr->max_num = 100;
3507 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3509 /* Hack -- Non-unique Nazguls are semi-unique */
3510 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3513 /* Monster Memory */
3516 /* Incompatible save files */
3517 if (tmp16u > max_r_idx)
3519 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3523 /* Read the available records */
3524 for (i = 0; i < tmp16u; i++)
3527 rd_lore((MONRACE_IDX)i);
3530 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3535 /* Incompatible save files */
3536 if (tmp16u > max_k_idx)
3538 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3542 /* Read the object memory */
3543 for (i = 0; i < tmp16u; i++)
3545 object_kind *k_ptr = &k_info[i];
3549 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3550 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3552 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3554 /* 2.1.3 or newer version */
3556 u16b max_towns_load;
3557 u16b max_quests_load;
3558 byte max_rquests_load;
3559 s16b old_inside_quest = p_ptr->inside_quest;
3561 /* Number of towns */
3562 rd_u16b(&max_towns_load);
3564 /* Incompatible save files */
3565 if (max_towns_load > max_towns)
3567 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3571 /* Number of quests */
3572 rd_u16b(&max_quests_load);
3574 if (z_older_than(11, 0, 7))
3576 max_rquests_load = 10;
3580 rd_byte(&max_rquests_load);
3583 /* Incompatible save files */
3584 if (max_quests_load > max_q_idx)
3586 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3590 for (i = 0; i < max_quests_load; i++)
3594 quest_type* const q_ptr = &quest[i];
3596 rd_s16b(&q_ptr->status);
3598 q_ptr->level = tmp16s;
3600 if (z_older_than(11, 0, 6))
3607 q_ptr->complev = tmp8u;
3609 if(h_older_than(2, 1, 2, 2))
3611 q_ptr->comptime = 0;
3615 rd_u32b(&q_ptr->comptime);
3618 /* Load quest status if quest is running */
3619 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3620 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3621 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3624 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3626 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3627 rd_s16b(&q_ptr->type);
3629 /* Load quest monster index */
3630 rd_s16b(&q_ptr->r_idx);
3632 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3634 determine_random_questor(&quest[i]);
3637 /* Load quest item index */
3638 rd_s16b(&q_ptr->k_idx);
3641 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3644 q_ptr->flags = tmp8u;
3646 if (z_older_than(10, 3, 11))
3648 if (q_ptr->flags & QUEST_FLAG_PRESET)
3654 init_flags = INIT_ASSIGN;
3655 p_ptr->inside_quest = (QUEST_IDX)i;
3657 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3658 p_ptr->inside_quest = old_inside_quest;
3664 q_ptr->dungeon = tmp8u;
3667 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3668 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3669 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3672 /* Ignore the empty quests from old versions */
3675 /* Ignore quest status */
3678 /* Ignore quest level */
3682 * We don't have to care about the other info,
3683 * since status should be 0 for these quests anyway
3688 /* Quest 18 was removed */
3689 if (h_older_than(1, 7, 0, 6))
3691 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3692 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3695 /* Position in the wilderness */
3696 rd_s32b(&p_ptr->wilderness_x);
3697 rd_s32b(&p_ptr->wilderness_y);
3698 if (z_older_than(10, 3, 13))
3700 p_ptr->wilderness_x = 5;
3701 p_ptr->wilderness_y = 48;
3704 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3705 else rd_byte((byte *)&p_ptr->wild_mode);
3706 if (z_older_than(10, 3, 7)) p_ptr->ambush_flag = FALSE;
3707 else rd_byte((byte *)&p_ptr->ambush_flag);
3709 /* Size of the wilderness */
3710 rd_s32b(&wild_x_size);
3711 rd_s32b(&wild_y_size);
3713 /* Incompatible save files */
3714 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3716 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3720 /* Load the wilderness seeds */
3721 for (i = 0; i < wild_x_size; i++)
3723 for (j = 0; j < wild_y_size; j++)
3725 rd_u32b(&wilderness[j][i].seed);
3730 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3732 /* Load the Artifacts */
3735 /* Incompatible save files */
3736 if (tmp16u > max_a_idx)
3738 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3742 /* Read the artifact flags */
3743 for (i = 0; i < tmp16u; i++)
3745 artifact_type *a_ptr = &a_info[i];
3748 a_ptr->cur_num = tmp8u;
3750 if (h_older_than(1, 5, 0, 0))
3752 a_ptr->floor_id = 0;
3760 rd_s16b(&a_ptr->floor_id);
3763 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3765 /* Read the extra stuff */
3767 if (p_ptr->energy_need < -999) p_ptr->timewalk = TRUE;
3769 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3772 /* Read the player_hp array */
3775 /* Incompatible save files */
3776 if (tmp16u > PY_MAX_LEVEL)
3778 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3782 /* Read the player_hp array */
3783 for (i = 0; i < tmp16u; i++)
3786 p_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3789 /* Important -- Initialize the sex */
3790 sp_ptr = &sex_info[p_ptr->psex];
3792 /* Important -- Initialize the race/class */
3793 rp_ptr = &race_info[p_ptr->prace];
3794 cp_ptr = &class_info[p_ptr->pclass];
3795 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3797 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3799 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3800 roll_hitdice(p_ptr, 0L);
3802 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3804 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3805 roll_hitdice(p_ptr, 0L);
3807 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3809 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3810 roll_hitdice(p_ptr, 0L);
3812 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3814 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3815 roll_hitdice(p_ptr, 0L);
3818 /* Important -- Initialize the magic */
3819 mp_ptr = &m_info[p_ptr->pclass];
3822 /* Read spell info */
3823 rd_u32b(&p_ptr->spell_learned1);
3824 rd_u32b(&p_ptr->spell_learned2);
3825 rd_u32b(&p_ptr->spell_worked1);
3826 rd_u32b(&p_ptr->spell_worked2);
3827 rd_u32b(&p_ptr->spell_forgotten1);
3828 rd_u32b(&p_ptr->spell_forgotten2);
3830 if (z_older_than(10,0,5))
3832 p_ptr->learned_spells = 0;
3833 for (i = 0; i < 64; i++)
3835 /* Count known spells */
3837 (p_ptr->spell_learned1 & (1L << i)) :
3838 (p_ptr->spell_learned2 & (1L << (i - 32))))
3840 p_ptr->learned_spells++;
3844 else rd_s16b(&p_ptr->learned_spells);
3846 if (z_older_than(10,0,6))
3848 p_ptr->add_spells = 0;
3850 else rd_s16b(&p_ptr->add_spells);
3851 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3853 for (i = 0; i < 64; i++)
3856 p_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3860 /* Read the p_ptr->inventory_list */
3863 note(_("持ち物情報を読み込むことができません", "Unable to read p_ptr->inventory_list"));
3867 /* Read number of towns */
3869 town_count = tmp16u;
3871 /* Read the stores */
3873 for (i = 1; i < town_count; i++)
3875 for (j = 0; j < tmp16u; j++)
3877 if (rd_store(i, j)) return (22);
3881 rd_s16b(&p_ptr->pet_follow_distance);
3882 if (z_older_than(10, 4, 10))
3884 p_ptr->pet_extra_flags = 0;
3886 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3888 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3890 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3894 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3897 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3901 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3904 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3908 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3911 if (!z_older_than(10,0,8))
3914 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3919 rd_s16b(&p_ptr->pet_extra_flags);
3922 if (!z_older_than(11, 0, 9))
3924 char buf[SCREEN_BUF_MAX_SIZE];
3925 rd_string(buf, sizeof(buf));
3926 if (buf[0]) screen_dump = string_make(buf);
3931 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3933 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3938 /* I'm not dead yet... */
3939 if (!p_ptr->is_dead)
3941 /* Dead players have no dungeon */
3942 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3946 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3950 /* Read the ghost info */
3957 strip_bytes(tmp32s);
3961 /* Quest 18 was removed */
3962 if (h_older_than(1, 7, 0, 6))
3964 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3966 p_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3967 current_floor_ptr->dun_level = 1;
3968 p_ptr->inside_quest = 0;
3973 #ifdef VERIFY_CHECKSUMS
3975 /* Save the checksum */
3976 n_v_check = v_check;
3978 /* Read the old checksum */
3979 rd_u32b(&o_v_check);
3982 if (o_v_check != n_v_check)
3984 note(_("チェックサムがおかしい", "Invalid checksum"));
3989 /* Save the encoded checksum */
3990 n_x_check = x_check;
3992 /* Read the checksum */
3993 rd_u32b(&o_x_check);
3997 if (o_x_check != n_x_check)
3999 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
4010 * @brief ロード処理全体のメイン関数 / Actually read the savefile
4013 errr rd_savefile_new(void)
4017 /* Grab permissions */
4020 /* The savefile is a binary file */
4021 fff = my_fopen(savefile, "rb");
4023 /* Drop permissions */
4025 if (!fff) return (-1);
4027 /* Call the sub-function */
4028 err = rd_savefile_new_aux();
4030 /* Check for errors */
4031 if (ferror(fff)) err = -1;
4038 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
4039 * @param sf_ptr 保存フロア読み込み先
4042 static bool load_floor_aux(saved_floor_type *sf_ptr)
4047 #ifdef VERIFY_CHECKSUMS
4048 u32b n_x_check, n_v_check;
4049 u32b o_x_check, o_v_check;
4052 /* Hack -- decrypt (read xor_byte) */
4056 /* Clear the checksums */
4060 /* Set the version number to current version */
4061 /* Never load old temporal files */
4062 h_ver_extra = H_VER_EXTRA;
4063 h_ver_patch = H_VER_PATCH;
4064 h_ver_minor = H_VER_MINOR;
4065 h_ver_major = H_VER_MAJOR;
4067 /* Verify the sign */
4069 if (saved_floor_file_sign != tmp32u) return FALSE;
4071 /* Read -- have error? */
4072 if (rd_saved_floor(sf_ptr)) return FALSE;
4075 #ifdef VERIFY_CHECKSUMS
4076 /* Save the checksum */
4077 n_v_check = v_check;
4079 /* Read the old checksum */
4080 rd_u32b(&o_v_check);
4083 if (o_v_check != n_v_check) return FALSE;
4085 /* Save the encoded checksum */
4086 n_x_check = x_check;
4088 /* Read the checksum */
4089 rd_u32b(&o_x_check);
4092 if (o_x_check != n_x_check) return FALSE;
4101 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4102 * @param sf_ptr 保存フロア読み込み先
4106 bool load_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
4108 FILE *old_fff = NULL;
4109 byte old_xor_byte = 0;
4110 u32b old_v_check = 0;
4111 u32b old_x_check = 0;
4112 byte old_h_ver_major = 0;
4113 byte old_h_ver_minor = 0;
4114 byte old_h_ver_patch = 0;
4115 byte old_h_ver_extra = 0;
4118 char floor_savefile[1024];
4120 byte old_kanji_code = kanji_code;
4123 * Temporal files are always written in system depended kanji
4128 /* EUC kanji code */
4132 /* SJIS kanji code */
4141 /* We have one file already opened */
4142 if (mode & SLF_SECOND)
4144 /* Backup original values */
4146 old_xor_byte = xor_byte;
4147 old_v_check = v_check;
4148 old_x_check = x_check;
4149 old_h_ver_major = h_ver_major;
4150 old_h_ver_minor = h_ver_minor;
4151 old_h_ver_patch = h_ver_patch;
4152 old_h_ver_extra = h_ver_extra;
4155 /* floor savefile */
4156 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4158 /* Grab permissions */
4161 /* The savefile is a binary file */
4162 fff = my_fopen(floor_savefile, "rb");
4164 /* Drop permissions */
4168 if (!fff) ok = FALSE;
4170 /* Attempt to load */
4173 /* Load saved floor data from file */
4174 ok = load_floor_aux(sf_ptr);
4176 /* Check for errors */
4177 if (ferror(fff)) ok = FALSE;
4180 /* Grab permissions */
4183 /* Delete the file */
4184 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4186 /* Drop permissions */
4190 /* We have one file already opened */
4191 if (mode & SLF_SECOND)
4193 /* Restore original values */
4195 xor_byte = old_xor_byte;
4196 v_check = old_v_check;
4197 x_check = old_x_check;
4198 h_ver_major = old_h_ver_major;
4199 h_ver_minor = old_h_ver_minor;
4200 h_ver_patch = old_h_ver_patch;
4201 h_ver_extra = old_h_ver_extra;
4204 /* Restore old knowledge */
4205 kanji_code = old_kanji_code;