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.
53 #include "floor-generate.h"
57 #include "market/store-util.h"
62 #include "spells-status.h"
63 #include "object-hook.h"
68 #include "floor-save.h"
69 #include "floor-town.h"
73 #include "dungeon-file.h"
74 #include "uid-checker.h"
76 #include "player-skill.h"
77 #include "player-class.h"
78 #include "player-race.h"
79 #include "player-personality.h"
80 #include "player-sex.h"
83 #include "objectkind.h"
84 #include "object-ego.h"
87 #include "cmd-smith.h"
90 * Maximum number of tries for selection of a proper quest monster
94 #define OLD_MAX_MANE 22
96 /* Old hidden trap flag */
97 #define CAVE_TRAP 0x8000
99 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
100 #define OLD_FEAT_INVIS 0x02
101 #define OLD_FEAT_GLYPH 0x03
102 #define OLD_FEAT_QUEST_ENTER 0x08
103 #define OLD_FEAT_QUEST_EXIT 0x09
104 #define OLD_FEAT_MINOR_GLYPH 0x40
105 #define OLD_FEAT_BLDG_1 0x81
106 #define OLD_FEAT_MIRROR 0xc3
109 #define OLD_QUEST_WATER_CAVE 18
111 /* Quest constants */
112 #define QUEST_OLD_CASTLE 27
113 #define QUEST_ROYAL_CRYPT 28
116 * Local "savefile" pointer
121 * Hack -- old "encryption" byte
123 static byte xor_byte;
126 * Hack -- simple "checksum" on the actual values
128 static u32b v_check = 0L;
131 * Hack -- simple "checksum" on the encoded bytes
133 static u32b x_check = 0L;
136 * Hack -- Japanese Kanji code
142 static byte kanji_code = 0;
145 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
146 * @param major メジャーバージョン値
147 * @param minor マイナーバージョン値
148 * @param patch パッチバージョン値
149 * @param extra エクストラパージョン値
150 * @return 現在のバージョンより値が古いならtrue
152 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
154 if (current_world_ptr->h_ver_major < major) return TRUE;
155 if (current_world_ptr->h_ver_major > major) return FALSE;
157 if (current_world_ptr->h_ver_minor < minor) return TRUE;
158 if (current_world_ptr->h_ver_minor > minor) return FALSE;
160 if (current_world_ptr->h_ver_patch < patch) return TRUE;
161 if (current_world_ptr->h_ver_patch > patch) return FALSE;
163 if (current_world_ptr->h_ver_extra < extra) return TRUE;
164 if (current_world_ptr->h_ver_extra > extra) return FALSE;
171 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
172 * @param x メジャーバージョン値
173 * @param y マイナーバージョン値
175 * @return 現在のバージョンより値が古いならtrue
177 static bool z_older_than(byte x, byte y, byte z)
179 if (current_world_ptr->z_major < x) return TRUE;
180 if (current_world_ptr->z_major > x) return FALSE;
182 if (current_world_ptr->z_minor < y) return TRUE;
183 if (current_world_ptr->z_minor > y) return FALSE;
185 if (current_world_ptr->z_patch < z) return TRUE;
186 if (current_world_ptr->z_patch > z) return FALSE;
193 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
197 * Avoid the top two lines, to avoid interference with "msg_print()".
199 static void note(concptr msg)
201 static TERM_LEN y = 2;
203 if (++y >= 24) y = 2;
210 * @brief ロードファイルポインタから1バイトを読み込む
213 * The following functions are used to load the basic building blocks
214 * of savefiles. They also maintain the "checksum" info for 2.7.0+
216 static byte sf_get(void)
218 byte c = getc(fff) & 0xFF;
219 byte v = c ^ xor_byte;
229 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
233 static void rd_byte(byte *ip)
240 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
244 static void rd_u16b(u16b *ip)
247 (*ip) |= ((u16b)(sf_get()) << 8);
252 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
256 static void rd_s16b(s16b *ip)
263 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
267 static void rd_u32b(u32b *ip)
270 (*ip) |= ((u32b)(sf_get()) << 8);
271 (*ip) |= ((u32b)(sf_get()) << 16);
272 (*ip) |= ((u32b)(sf_get()) << 24);
277 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
281 static void rd_s32b(s32b *ip)
288 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
289 * @param str 読み込みポインタ
290 * @param max 最大読み取りバイト数
293 static void rd_string(char *str, int max)
295 for (int i = 0; TRUE; i++)
299 if (i < max) str[i] = tmp8u;
322 byte code = codeconv(str);
324 /* 漢字コードが判明したら、それを記録 */
325 if (code) kanji_code = code;
337 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
341 static void strip_bytes(int n)
344 while (n--) rd_byte(&tmp8u);
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)
369 rd_s16b(&o_ptr->k_idx);
373 o_ptr->iy = (POSITION)tmp8u;
375 o_ptr->ix = (POSITION)tmp8u;
383 if (z_older_than(10, 4, 4))
385 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
386 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
387 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
390 rd_s16b(&o_ptr->pval);
391 rd_byte(&o_ptr->discount);
393 o_ptr->number = (ITEM_NUMBER)tmp8u;
397 o_ptr->weight = tmp16s;
400 o_ptr->name1 = tmp8u;
403 o_ptr->name2 = tmp8u;
405 rd_s16b(&o_ptr->timeout);
406 rd_s16b(&o_ptr->to_h);
408 o_ptr->to_d = tmp16s;
410 rd_s16b(&o_ptr->to_a);
418 rd_byte(&o_ptr->ident);
419 rd_byte(&o_ptr->marked);
420 rd_u32b(&o_ptr->art_flags[0]);
421 rd_u32b(&o_ptr->art_flags[1]);
422 rd_u32b(&o_ptr->art_flags[2]);
423 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
424 else rd_u32b(&o_ptr->art_flags[3]);
426 if (h_older_than(1, 3, 0, 0))
428 if (o_ptr->name2 == EGO_TELEPATHY)
429 add_flag(o_ptr->art_flags, TR_TELEPATHY);
432 if (z_older_than(11, 0, 11))
434 o_ptr->curse_flags = 0L;
435 if (o_ptr->ident & 0x40)
437 o_ptr->curse_flags |= TRC_CURSED;
438 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
439 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
440 if (object_is_fixed_artifact(o_ptr))
442 artifact_type *a_ptr = &a_info[o_ptr->name1];
443 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
444 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
446 else if (object_is_ego(o_ptr))
448 ego_item_type *e_ptr = &e_info[o_ptr->name2];
449 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
450 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
453 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
457 rd_u32b(&o_ptr->curse_flags);
460 rd_s16b(&o_ptr->held_m_idx);
461 rd_byte(&o_ptr->xtra1);
462 rd_byte(&o_ptr->xtra2);
464 if (z_older_than(11, 0, 10))
466 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
468 switch (o_ptr->xtra2 % 6)
470 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
471 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
472 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
473 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
474 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
475 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
479 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
481 switch (o_ptr->xtra2 % 11)
483 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
484 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
485 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
486 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
487 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
488 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
489 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
490 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
491 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
492 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
493 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
497 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
499 switch (o_ptr->xtra2 % 8)
501 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
502 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
503 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
504 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
505 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
506 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
507 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
508 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
515 if (z_older_than(10, 2, 3))
520 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
522 o_ptr->xtra3 = o_ptr->xtra1;
525 if (o_ptr->tval == TV_CAPTURE)
527 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
528 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
530 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
531 if (ironman_nightmare)
533 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5 * 2L);
535 o_ptr->xtra4 = o_ptr->xtra5;
540 rd_byte(&o_ptr->xtra3);
541 if (h_older_than(1, 3, 0, 1))
543 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1 + 96)
544 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
547 rd_s16b(&o_ptr->xtra4);
548 rd_s16b(&o_ptr->xtra5);
551 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)))
553 o_ptr->xtra4 = o_ptr->pval;
557 rd_byte(&o_ptr->feeling);
560 rd_string(buf, sizeof(buf));
561 if (buf[0]) o_ptr->inscription = quark_add(buf);
563 rd_string(buf, sizeof(buf));
565 /* todo 元々このif文には末尾に";"が付いていた、バグかもしれない */
566 if (buf[0]) o_ptr->art_name = quark_add(buf);
574 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
576 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
578 if (z_older_than(10, 4, 9))
580 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
582 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
583 add_flag(o_ptr->art_flags, TR_DEC_MANA);
587 if (object_is_fixed_artifact(o_ptr))
589 artifact_type *a_ptr;
590 a_ptr = &a_info[o_ptr->name1];
591 if (!a_ptr->name) o_ptr->name1 = 0;
594 if (object_is_ego(o_ptr))
596 ego_item_type *e_ptr;
597 e_ptr = &e_info[o_ptr->name2];
598 if (!e_ptr->name) o_ptr->name2 = 0;
604 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
605 * @param o_ptr アイテムオブジェクト保存先ポインタ
608 static void rd_item(object_type *o_ptr)
610 if (h_older_than(1, 5, 0, 0))
618 rd_s16b(&o_ptr->k_idx);
622 o_ptr->iy = (POSITION)tmp8u;
624 o_ptr->ix = (POSITION)tmp8u;
627 k_ptr = &k_info[o_ptr->k_idx];
628 o_ptr->tval = k_ptr->tval;
629 o_ptr->sval = k_ptr->sval;
631 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
632 else o_ptr->pval = 0;
634 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
635 else o_ptr->discount = 0;
636 if (flags & SAVE_ITEM_NUMBER) {
638 o_ptr->number = tmp8u;
640 else o_ptr->number = 1;
644 o_ptr->weight = tmp16s;
646 if (flags & SAVE_ITEM_NAME1)
649 o_ptr->name1 = tmp8u;
651 else o_ptr->name1 = 0;
653 if (flags & SAVE_ITEM_NAME2)
656 o_ptr->name2 = tmp8u;
658 else o_ptr->name2 = 0;
660 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
661 else o_ptr->timeout = 0;
663 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
664 else o_ptr->to_h = 0;
666 if (flags & SAVE_ITEM_TO_D)
669 o_ptr->to_d = tmp16s;
671 else o_ptr->to_d = 0;
673 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
674 else o_ptr->to_a = 0;
676 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
679 if (flags & SAVE_ITEM_DD)
686 if (flags & SAVE_ITEM_DS)
693 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
694 else o_ptr->ident = 0;
696 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
697 else o_ptr->marked = 0;
700 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
701 else o_ptr->art_flags[0] = 0;
703 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
704 else o_ptr->art_flags[1] = 0;
706 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
707 else o_ptr->art_flags[2] = 0;
709 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
710 else o_ptr->art_flags[3] = 0;
712 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
713 else o_ptr->art_flags[4] = 0;
715 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
716 else o_ptr->curse_flags = 0;
718 /* Monster holding object */
719 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
720 else o_ptr->held_m_idx = 0;
723 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
724 else o_ptr->xtra1 = 0;
726 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
727 else o_ptr->xtra2 = 0;
729 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
730 else o_ptr->xtra3 = 0;
732 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
733 else o_ptr->xtra4 = 0;
735 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
736 else o_ptr->xtra5 = 0;
738 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
739 else o_ptr->feeling = 0;
741 if (flags & SAVE_ITEM_INSCRIPTION)
744 rd_string(buf, sizeof(buf));
745 o_ptr->inscription = quark_add(buf);
747 else o_ptr->inscription = 0;
749 if (flags & SAVE_ITEM_ART_NAME)
752 rd_string(buf, sizeof(buf));
753 o_ptr->art_name = quark_add(buf);
760 if (!h_older_than(2, 1, 2, 4)) return;
762 BIT_FLAGS flgs[TR_FLAG_SIZE];
763 object_flags(o_ptr, flgs);
765 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
767 add_flag(o_ptr->art_flags, TR_LITE_M1);
768 remove_flag(o_ptr->art_flags, TR_LITE_1);
769 remove_flag(o_ptr->art_flags, TR_LITE_2);
770 remove_flag(o_ptr->art_flags, TR_LITE_3);
774 if (o_ptr->name2 == EGO_LITE_DARKNESS)
776 if (o_ptr->tval != TV_LITE)
778 add_flag(o_ptr->art_flags, TR_LITE_M1);
782 if (o_ptr->sval == SV_LITE_TORCH)
784 add_flag(o_ptr->art_flags, TR_LITE_M1);
786 else if (o_ptr->sval == SV_LITE_LANTERN)
788 add_flag(o_ptr->art_flags, TR_LITE_M2);
790 else if (o_ptr->sval == SV_LITE_FEANOR)
792 add_flag(o_ptr->art_flags, TR_LITE_M3);
798 if (o_ptr->tval == TV_LITE)
800 if (object_is_fixed_artifact(o_ptr))
802 add_flag(o_ptr->art_flags, TR_LITE_3);
806 if (o_ptr->sval == SV_LITE_TORCH)
808 add_flag(o_ptr->art_flags, TR_LITE_1);
809 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
813 if (o_ptr->sval == SV_LITE_LANTERN)
815 add_flag(o_ptr->art_flags, TR_LITE_2);
816 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
820 if (o_ptr->sval == SV_LITE_FEANOR)
822 add_flag(o_ptr->art_flags, TR_LITE_2);
830 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
831 * @param player_ptr プレーヤーへの参照ポインタ
832 * @param m_ptr モンスター保存先ポインタ
835 static void rd_monster_old(player_type *player_ptr, monster_type *m_ptr)
837 rd_s16b(&m_ptr->r_idx);
839 if (z_older_than(11, 0, 12))
840 m_ptr->ap_r_idx = m_ptr->r_idx;
842 rd_s16b(&m_ptr->ap_r_idx);
844 if (z_older_than(11, 0, 14))
846 monster_race *r_ptr = &r_info[m_ptr->r_idx];
848 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
849 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
850 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
853 rd_byte(&m_ptr->sub_align);
857 m_ptr->fy = (POSITION)tmp8u;
859 m_ptr->fx = (POSITION)tmp8u;
860 m_ptr->current_floor_ptr = player_ptr->current_floor_ptr;
866 m_ptr->maxhp = tmp16s;
868 if (z_older_than(11, 0, 5))
870 m_ptr->max_maxhp = m_ptr->maxhp;
875 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
877 if (h_older_than(2, 1, 2, 1))
879 m_ptr->dealt_damage = 0;
883 rd_s32b(&m_ptr->dealt_damage);
886 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
888 m_ptr->mspeed = tmp8u;
890 if (z_older_than(10, 4, 2))
893 m_ptr->energy_need = (s16b)tmp8u;
895 else rd_s16b(&m_ptr->energy_need);
897 if (z_older_than(11, 0, 13))
898 m_ptr->energy_need = 100 - m_ptr->energy_need;
900 if (z_older_than(10, 0, 7))
902 m_ptr->mtimed[MTIMED_FAST] = 0;
903 m_ptr->mtimed[MTIMED_SLOW] = 0;
908 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
910 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
914 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
916 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
918 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
920 if (z_older_than(10, 0, 10))
924 else if (z_older_than(10, 0, 11))
932 m_ptr->target_y = (POSITION)tmp16s;
934 m_ptr->target_x = (POSITION)tmp16s;
938 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
940 if (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6))
941 rd_u32b(&m_ptr->smart);
946 if (z_older_than(10, 4, 5))
956 if (z_older_than(10, 2, 2))
958 if (m_ptr->r_idx < 0)
960 m_ptr->r_idx = (0 - m_ptr->r_idx);
961 m_ptr->mflag2 |= MFLAG2_KAGE;
966 rd_byte(&m_ptr->mflag2);
969 if (z_older_than(11, 0, 12))
971 if (m_ptr->mflag2 & MFLAG2_KAGE)
972 m_ptr->ap_r_idx = MON_KAGE;
975 if (z_older_than(10, 1, 3))
982 rd_string(buf, sizeof(buf));
983 if (buf[0]) m_ptr->nickname = quark_add(buf);
991 * @brief モンスターを読み込む(現版) / Read a monster (New method)
992 * @param player_ptr プレーヤーへの参照ポインタ
993 * @param m_ptr モンスター保存先ポインタ
996 static void rd_monster(player_type *player_ptr, monster_type *m_ptr)
998 if (h_older_than(1, 5, 0, 0))
1000 rd_monster_old(player_ptr, m_ptr);
1006 rd_s16b(&m_ptr->r_idx);
1009 m_ptr->fy = (POSITION)tmp8u;
1011 m_ptr->fx = (POSITION)tmp8u;
1015 m_ptr->hp = (HIT_POINT)tmp16s;
1017 m_ptr->maxhp = (HIT_POINT)tmp16s;
1019 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1021 if (h_older_than(2, 1, 2, 1))
1023 m_ptr->dealt_damage = 0;
1027 rd_s32b(&m_ptr->dealt_damage);
1030 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1031 else m_ptr->ap_r_idx = m_ptr->r_idx;
1033 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1034 else m_ptr->sub_align = 0;
1036 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1037 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1040 m_ptr->mspeed = tmp8u;
1042 rd_s16b(&m_ptr->energy_need);
1044 if (flags & SAVE_MON_FAST)
1047 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1049 else m_ptr->mtimed[MTIMED_FAST] = 0;
1051 if (flags & SAVE_MON_SLOW)
1054 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1056 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1058 if (flags & SAVE_MON_STUNNED)
1061 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1063 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1065 if (flags & SAVE_MON_CONFUSED)
1068 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1070 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1072 if (flags & SAVE_MON_MONFEAR)
1075 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1077 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1079 if (flags & SAVE_MON_TARGET_Y)
1082 m_ptr->target_y = (POSITION)tmp16s;
1084 else m_ptr->target_y = 0;
1086 if (flags & SAVE_MON_TARGET_X)
1089 m_ptr->target_x = (POSITION)tmp16s;
1091 else m_ptr->target_x = 0;
1093 if (flags & SAVE_MON_INVULNER)
1096 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1098 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1100 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1101 else m_ptr->smart = 0;
1103 if (flags & SAVE_MON_EXP)
1107 m_ptr->exp = (EXP)tmp32u;
1109 else m_ptr->exp = 0;
1111 m_ptr->mflag = 0; /* Not saved */
1113 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1114 else m_ptr->mflag2 = 0;
1116 if (flags & SAVE_MON_NICKNAME)
1119 rd_string(buf, sizeof(buf));
1120 m_ptr->nickname = quark_add(buf);
1122 else m_ptr->nickname = 0;
1124 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1125 else m_ptr->parent_m_idx = 0;
1130 * Old monster bit flags of racial resistances
1132 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1133 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1134 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1135 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1136 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1137 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1138 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1139 #define RF3_RES_WATE 0x00800000 /* Resist water */
1140 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1141 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1142 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1143 #define RF3_RES_ALL 0x08000000 /* Resist all */
1145 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1147 if ((R_PTR)->r_flags3 & (RF3)) \
1149 (R_PTR)->r_flags3 &= ~(RF3); \
1150 (R_PTR)->r_flagsr |= (RFR); \
1154 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1156 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1158 (R_PTR)->r_flagsr |= (RFR); \
1162 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1163 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1164 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1165 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1166 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1167 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1168 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1169 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1170 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1171 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1174 * @brief モンスターの思い出を読み込む / Read the monster lore
1175 * @param r_idx 読み込み先モンスターID
1178 static void rd_lore(MONRACE_IDX r_idx)
1180 monster_race *r_ptr = &r_info[r_idx];
1184 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1187 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1190 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1192 if (h_older_than(1, 7, 0, 5))
1194 r_ptr->r_akills = r_ptr->r_pkills;
1199 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1203 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1205 rd_byte(&r_ptr->r_wake);
1206 rd_byte(&r_ptr->r_ignore);
1207 rd_byte(&r_ptr->r_xtra1);
1208 rd_byte(&r_ptr->r_xtra2);
1212 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1214 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1217 rd_byte(&r_ptr->r_cast_spell);
1219 rd_byte(&r_ptr->r_blows[0]);
1220 rd_byte(&r_ptr->r_blows[1]);
1221 rd_byte(&r_ptr->r_blows[2]);
1222 rd_byte(&r_ptr->r_blows[3]);
1224 rd_u32b(&r_ptr->r_flags1);
1225 rd_u32b(&r_ptr->r_flags2);
1226 rd_u32b(&r_ptr->r_flags3);
1227 rd_u32b(&r_ptr->r_flags4);
1228 rd_u32b(&r_ptr->r_flags5);
1229 rd_u32b(&r_ptr->r_flags6);
1230 if (h_older_than(1, 5, 0, 3))
1232 r_ptr->r_flagsr = 0L;
1233 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1234 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1235 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1236 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1237 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1238 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1239 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1240 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1241 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1242 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1243 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1244 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1246 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1247 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1248 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1249 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1250 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1251 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1252 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1253 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1254 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1256 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1257 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1258 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1262 rd_u32b(&r_ptr->r_flagsr);
1266 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1268 rd_s16b(&r_ptr->floor_id);
1271 r_ptr->r_flags1 &= r_ptr->flags1;
1272 r_ptr->r_flags2 &= r_ptr->flags2;
1273 r_ptr->r_flags3 &= r_ptr->flags3;
1274 r_ptr->r_flags4 &= r_ptr->flags4;
1275 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1276 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1277 r_ptr->r_flagsr &= r_ptr->flagsr;
1282 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1283 * @param player_ptr プレーヤーへの参照ポインタ
1284 * @param store_ptr 店舗の参照ポインタ
1285 * @param o_ptr アイテムオブジェクト参照ポインタ
1288 * In all cases, return the slot (or -1) where the object was placed
1290 * Note that this is a hacked up version of "inven_carry()".
1292 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1293 * known, the player may have to pick stuff up and drop it again.
1295 static void home_carry(player_type *player_ptr, store_type *store_ptr, object_type *o_ptr)
1297 for (int i = 0; i < store_ptr->stock_num; i++)
1300 j_ptr = &store_ptr->stock[i];
1301 if (!object_similar(j_ptr, o_ptr)) continue;
1303 object_absorb(j_ptr, o_ptr);
1307 if (store_ptr->stock_num >= STORE_INVEN_MAX * 10) return;
1309 s32b value = object_value(o_ptr);
1311 for (slot = 0; slot < store_ptr->stock_num; slot++)
1313 if (object_sort_comp(o_ptr, value, &store_ptr->stock[slot])) break;
1316 for (int i = store_ptr->stock_num; i > slot; i--)
1318 store_ptr->stock[i] = store_ptr->stock[i - 1];
1321 store_ptr->stock_num++;
1322 store_ptr->stock[slot] = *o_ptr;
1323 chg_virtue(player_ptr, V_SACRIFICE, -1);
1328 * @brief 店舗情報を読み込む / Read a store
1329 * @param player_ptr プレーヤーへの参照ポインタ
1330 * @param town_number 街ID
1331 * @param store_number 店舗ID
1334 static errr rd_store(player_type *player_ptr, int town_number, int store_number)
1336 store_type *store_ptr;
1338 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1340 store_ptr = &town_info[1].store[store_number];
1341 if (store_ptr->stock_num) sort = TRUE;
1345 store_ptr = &town_info[town_number].store[store_number];
1351 rd_s32b(&store_ptr->store_open);
1352 rd_s16b(&store_ptr->insult_cur);
1354 if (z_older_than(11, 0, 4))
1364 rd_s16b(&store_ptr->good_buy);
1365 rd_s16b(&store_ptr->bad_buy);
1367 rd_s32b(&store_ptr->last_visit);
1368 store_ptr->owner = own;
1370 for (int j = 0; j < num; j++)
1379 bool is_valid_item = store_ptr->stock_num < (store_number == STORE_HOME ? STORE_INVEN_MAX * 10 : store_number == STORE_MUSEUM ? STORE_INVEN_MAX * 50 : STORE_INVEN_MAX);
1380 if (!is_valid_item) continue;
1384 home_carry(player_ptr, store_ptr, q_ptr);
1388 int k = store_ptr->stock_num++;
1389 object_copy(&store_ptr->stock[k], q_ptr);
1398 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1401 static void rd_randomizer(void)
1405 rd_u16b(&Rand_place);
1406 for (int i = 0; i < RAND_DEG; i++)
1408 rd_u32b(&Rand_state[i]);
1414 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1417 * Note that the normal options are now stored as a set of 256 bit flags,
1418 * plus a set of 256 bit masks to indicate which bit flags were defined
1419 * at the time the savefile was created. This will allow new options
1420 * to be added, and old options to be removed, at any time, without
1421 * hurting old savefiles.
1423 * The window options are stored in the same way, but note that each
1424 * window gets 32 options, and their order is fixed by certain defines.
1426 static void rd_options(void)
1437 if (h_older_than(1, 7, 0, 0))
1450 if (c & 0x0002) current_world_ptr->wizard = TRUE;
1452 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1453 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1454 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1455 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1456 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1457 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1458 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1459 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1460 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1461 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1463 rd_byte((byte *)&autosave_l);
1464 rd_byte((byte *)&autosave_t);
1465 rd_s16b(&autosave_freq);
1468 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1471 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1473 for (int n = 0; n < 8; n++)
1475 for (int i = 0; i < 32; i++)
1477 if (!(mask[n] & (1L << i))) continue;
1478 if (!(option_mask[n] & (1L << i))) continue;
1480 if (flag[n] & (1L << i))
1482 option_flag[n] |= (1L << i);
1486 option_flag[n] &= ~(1L << i);
1491 if (z_older_than(10, 4, 5))
1493 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1494 else option_flag[5] |= (0x00000001 << 4);
1495 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1496 else option_flag[2] |= (0x00000001 << 5);
1497 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1498 else option_flag[4] |= (0x00000001 << 5);
1499 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1500 else option_flag[5] |= (0x00000001 << 0);
1501 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1502 else option_flag[5] |= (0x00000001 << 12);
1503 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1504 else option_flag[1] |= (0x00000001 << 0);
1505 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1506 else option_flag[1] |= (0x00000001 << 18);
1507 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1508 else option_flag[1] |= (0x00000001 << 19);
1509 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1510 else option_flag[5] |= (0x00000001 << 3);
1513 extract_option_vars();
1514 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1516 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1518 for (int n = 0; n < 8; n++)
1520 for (int i = 0; i < 32; i++)
1522 if (!(mask[n] & (1L << i))) continue;
1523 if (!(window_mask[n] & (1L << i))) continue;
1525 if (flag[n] & (1L << i))
1527 window_flag[n] |= (1L << i);
1531 window_flag[n] &= ~(1L << i);
1539 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1542 * This is such a nasty hack it hurts.
1544 static void rd_ghost(void)
1547 rd_string(buf, sizeof(buf));
1553 * @brief クイックスタート情報を読み込む / Load quick start data
1556 static void load_quick_start(void)
1558 if (z_older_than(11, 0, 13))
1560 previous_char.quick_ok = FALSE;
1564 rd_byte(&previous_char.psex);
1567 previous_char.prace = (RACE_IDX)tmp8u;
1569 previous_char.pclass = (CLASS_IDX)tmp8u;
1571 previous_char.pseikaku = (CHARACTER_IDX)tmp8u;
1573 previous_char.realm1 = (REALM_IDX)tmp8u;
1575 previous_char.realm2 = (REALM_IDX)tmp8u;
1577 rd_s16b(&previous_char.age);
1578 rd_s16b(&previous_char.ht);
1579 rd_s16b(&previous_char.wt);
1580 rd_s16b(&previous_char.sc);
1581 rd_s32b(&previous_char.au);
1583 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1584 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1586 for (int i = 0; i < PY_MAX_LEVEL; i++)
1590 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1593 rd_s16b(&previous_char.chaos_patron);
1595 for (int i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1597 for (int i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1601 previous_char.quick_ok = (bool)tmp8u;
1606 * @brief その他の情報を読み込む / Read the "extra" information
1609 static void rd_extra(player_type *creature_ptr)
1611 rd_string(creature_ptr->name, sizeof(creature_ptr->name));
1612 rd_string(creature_ptr->died_from, sizeof(creature_ptr->died_from));
1613 if (!h_older_than(1, 7, 0, 1))
1616 rd_string(buf, sizeof buf);
1617 if (buf[0]) creature_ptr->last_message = string_make(buf);
1621 for (int i = 0; i < 4; i++)
1623 rd_string(creature_ptr->history[i], sizeof(creature_ptr->history[i]));
1628 creature_ptr->prace = (RACE_IDX)tmp8u;
1631 creature_ptr->pclass = (CLASS_IDX)tmp8u;
1634 creature_ptr->pseikaku = (CHARACTER_IDX)tmp8u;
1636 rd_byte(&creature_ptr->psex);
1638 creature_ptr->realm1 = (REALM_IDX)tmp8u;
1641 creature_ptr->realm2 = (REALM_IDX)tmp8u;
1644 if (z_older_than(10, 4, 4))
1646 if (creature_ptr->realm1 == 9) creature_ptr->realm1 = REALM_MUSIC;
1647 if (creature_ptr->realm2 == 9) creature_ptr->realm2 = REALM_MUSIC;
1648 if (creature_ptr->realm1 == 10) creature_ptr->realm1 = REALM_HISSATSU;
1649 if (creature_ptr->realm2 == 10) creature_ptr->realm2 = REALM_HISSATSU;
1653 creature_ptr->hitdie = tmp8u;
1654 rd_u16b(&creature_ptr->expfact);
1656 rd_s16b(&creature_ptr->age);
1657 rd_s16b(&creature_ptr->ht);
1658 rd_s16b(&creature_ptr->wt);
1660 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max[i]);
1661 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max_max[i]);
1662 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_cur[i]);
1665 rd_s32b(&creature_ptr->au);
1667 rd_s32b(&creature_ptr->max_exp);
1668 if (h_older_than(1, 5, 4, 1)) creature_ptr->max_max_exp = creature_ptr->max_exp;
1669 else rd_s32b(&creature_ptr->max_max_exp);
1670 rd_s32b(&creature_ptr->exp);
1672 if (h_older_than(1, 7, 0, 3))
1676 creature_ptr->exp_frac = (u32b)tmp16u;
1680 rd_u32b(&creature_ptr->exp_frac);
1683 rd_s16b(&creature_ptr->lev);
1685 for (int i = 0; i < 64; i++) rd_s16b(&creature_ptr->spell_exp[i]);
1686 if ((creature_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1688 for (int i = 0; i < 64; i++) creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1691 if (z_older_than(10, 3, 6))
1692 for (int i = 0; i < 5; i++) for (int j = 0; j < 60; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1694 for (int i = 0; i < 5; i++) for (int j = 0; j < 64; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1695 for (int i = 0; i < GINOU_MAX; i++) rd_s16b(&creature_ptr->skill_exp[i]);
1696 if (z_older_than(10, 4, 1))
1698 if (creature_ptr->pclass != CLASS_BEASTMASTER) creature_ptr->skill_exp[GINOU_RIDING] /= 2;
1699 creature_ptr->skill_exp[GINOU_RIDING] = MIN(creature_ptr->skill_exp[GINOU_RIDING], s_info[creature_ptr->pclass].s_max[GINOU_RIDING]);
1702 if (z_older_than(10, 3, 14))
1704 for (int i = 0; i < 108; i++) creature_ptr->magic_num1[i] = 0;
1705 for (int i = 0; i < 108; i++) creature_ptr->magic_num2[i] = 0;
1709 for (int i = 0; i < 108; i++) rd_s32b(&creature_ptr->magic_num1[i]);
1710 for (int i = 0; i < 108; i++) rd_byte(&creature_ptr->magic_num2[i]);
1711 if (h_older_than(1, 3, 0, 1))
1713 if (creature_ptr->pclass == CLASS_SMITH)
1715 creature_ptr->magic_num1[TR_ES_ATTACK] = creature_ptr->magic_num1[96];
1716 creature_ptr->magic_num1[96] = 0;
1717 creature_ptr->magic_num1[TR_ES_AC] = creature_ptr->magic_num1[97];
1718 creature_ptr->magic_num1[97] = 0;
1723 if (music_singing_any(creature_ptr)) creature_ptr->action = ACTION_SING;
1725 if (z_older_than(11, 0, 7))
1727 creature_ptr->start_race = creature_ptr->prace;
1728 creature_ptr->old_race1 = 0L;
1729 creature_ptr->old_race2 = 0L;
1730 creature_ptr->old_realm = 0;
1735 creature_ptr->start_race = (RACE_IDX)tmp8u;
1738 creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1740 creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1741 rd_s16b(&creature_ptr->old_realm);
1744 if (z_older_than(10, 0, 1))
1746 for (int i = 0; i < MAX_MANE; i++)
1748 creature_ptr->mane_spell[i] = -1;
1749 creature_ptr->mane_dam[i] = 0;
1751 creature_ptr->mane_num = 0;
1753 else if (z_older_than(10, 2, 3))
1756 for (int i = 0; i < OLD_MAX_MANE; i++)
1762 for (int i = 0; i < MAX_MANE; i++)
1764 creature_ptr->mane_spell[i] = -1;
1765 creature_ptr->mane_dam[i] = 0;
1769 creature_ptr->mane_num = 0;
1773 for (int i = 0; i < MAX_MANE; i++)
1777 creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1779 creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1782 rd_s16b(&creature_ptr->mane_num);
1785 if (z_older_than(10, 0, 3))
1787 determine_bounty_uniques(creature_ptr);
1789 for (int i = 0; i < MAX_BOUNTY; i++)
1791 /* Is this bounty unique already dead? */
1792 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1797 for (int i = 0; i < MAX_BOUNTY; i++)
1799 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1803 if (z_older_than(10, 0, 3))
1805 update_gambling_monsters(creature_ptr);
1809 for (int i = 0; i < 4; i++)
1811 rd_s16b(&battle_mon[i]);
1812 if (z_older_than(10, 3, 4))
1816 mon_odds[i] = tmp16s;
1818 else rd_u32b(&mon_odds[i]);
1822 rd_s16b(&creature_ptr->town_num);
1823 rd_s16b(&creature_ptr->arena_number);
1824 if (h_older_than(1, 5, 0, 1))
1826 if (creature_ptr->arena_number >= 99) creature_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1831 creature_ptr->current_floor_ptr->inside_arena = (bool)tmp16s;
1832 rd_s16b(&creature_ptr->current_floor_ptr->inside_quest);
1833 if (z_older_than(10, 3, 5)) creature_ptr->phase_out = FALSE;
1837 creature_ptr->phase_out = (bool)tmp16s;
1840 rd_byte(&creature_ptr->exit_bldg);
1844 creature_ptr->oldpx = (POSITION)tmp16s;
1847 creature_ptr->oldpy = (POSITION)tmp16s;
1848 if (z_older_than(10, 3, 13) && !creature_ptr->current_floor_ptr->dun_level && !creature_ptr->current_floor_ptr->inside_arena) { creature_ptr->oldpy = 33; creature_ptr->oldpx = 131; }
1851 for (int i = 0; i < tmp16s; i++)
1857 if (h_older_than(1, 7, 0, 3))
1860 creature_ptr->mhp = tmp16s;
1863 creature_ptr->chp = tmp16s;
1867 creature_ptr->chp_frac = (u32b)tmp16u;
1871 rd_s32b(&creature_ptr->mhp);
1872 rd_s32b(&creature_ptr->chp);
1873 rd_u32b(&creature_ptr->chp_frac);
1876 if (h_older_than(1, 7, 0, 3))
1879 creature_ptr->msp = tmp16s;
1882 creature_ptr->csp = tmp16s;
1886 creature_ptr->csp_frac = (u32b)tmp16u;
1890 rd_s32b(&creature_ptr->msp);
1891 rd_s32b(&creature_ptr->csp);
1892 rd_u32b(&creature_ptr->csp_frac);
1895 rd_s16b(&creature_ptr->max_plv);
1896 if (z_older_than(10, 3, 8))
1899 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1903 byte max = (byte)current_world_ptr->max_d_idx;
1907 for (int i = 0; i < max; i++)
1910 max_dlv[i] = tmp16s;
1911 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1915 if (creature_ptr->max_plv < creature_ptr->lev) creature_ptr->max_plv = creature_ptr->lev;
1918 rd_s16b(&creature_ptr->sc);
1919 rd_s16b(&creature_ptr->concent);
1921 strip_bytes(2); /* Old "rest" */
1922 rd_s16b(&creature_ptr->blind);
1923 rd_s16b(&creature_ptr->paralyzed);
1924 rd_s16b(&creature_ptr->confused);
1925 rd_s16b(&creature_ptr->food);
1926 strip_bytes(4); /* Old "food_digested" / "protection" */
1928 rd_s16b(&creature_ptr->energy_need);
1929 if (z_older_than(11, 0, 13))
1930 creature_ptr->energy_need = 100 - creature_ptr->energy_need;
1931 if (h_older_than(2, 1, 2, 0))
1932 creature_ptr->enchant_energy_need = 0;
1934 rd_s16b(&creature_ptr->enchant_energy_need);
1936 rd_s16b(&creature_ptr->fast);
1937 rd_s16b(&creature_ptr->slow);
1938 rd_s16b(&creature_ptr->afraid);
1939 rd_s16b(&creature_ptr->cut);
1940 rd_s16b(&creature_ptr->stun);
1941 rd_s16b(&creature_ptr->poisoned);
1942 rd_s16b(&creature_ptr->image);
1943 rd_s16b(&creature_ptr->protevil);
1944 rd_s16b(&creature_ptr->invuln);
1945 if (z_older_than(10, 0, 0))
1946 creature_ptr->ult_res = 0;
1948 rd_s16b(&creature_ptr->ult_res);
1949 rd_s16b(&creature_ptr->hero);
1950 rd_s16b(&creature_ptr->shero);
1951 rd_s16b(&creature_ptr->shield);
1952 rd_s16b(&creature_ptr->blessed);
1953 rd_s16b(&creature_ptr->tim_invis);
1954 rd_s16b(&creature_ptr->word_recall);
1955 if (z_older_than(10, 3, 8))
1956 creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
1960 creature_ptr->recall_dungeon = (byte)tmp16s;
1963 if (h_older_than(1, 5, 0, 0))
1964 creature_ptr->alter_reality = 0;
1966 rd_s16b(&creature_ptr->alter_reality);
1968 rd_s16b(&creature_ptr->see_infra);
1969 rd_s16b(&creature_ptr->tim_infra);
1970 rd_s16b(&creature_ptr->oppose_fire);
1971 rd_s16b(&creature_ptr->oppose_cold);
1972 rd_s16b(&creature_ptr->oppose_acid);
1973 rd_s16b(&creature_ptr->oppose_elec);
1974 rd_s16b(&creature_ptr->oppose_pois);
1975 if (z_older_than(10, 0, 2)) creature_ptr->tsuyoshi = 0;
1976 else rd_s16b(&creature_ptr->tsuyoshi);
1978 /* Old savefiles do not have the following fields... */
1979 if ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->z_patch == 6))
1981 creature_ptr->tim_esp = 0;
1982 creature_ptr->wraith_form = 0;
1983 creature_ptr->resist_magic = 0;
1984 creature_ptr->tim_regen = 0;
1985 creature_ptr->kabenuke = 0;
1986 creature_ptr->tim_stealth = 0;
1987 creature_ptr->tim_levitation = 0;
1988 creature_ptr->tim_sh_touki = 0;
1989 creature_ptr->lightspeed = 0;
1990 creature_ptr->tsubureru = 0;
1991 creature_ptr->tim_res_nether = 0;
1992 creature_ptr->tim_res_time = 0;
1993 creature_ptr->mimic_form = 0;
1994 creature_ptr->tim_mimic = 0;
1995 creature_ptr->tim_sh_fire = 0;
1996 creature_ptr->tim_reflect = 0;
1997 creature_ptr->multishadow = 0;
1998 creature_ptr->dustrobe = 0;
1999 creature_ptr->chaos_patron = ((creature_ptr->age + creature_ptr->sc) % MAX_PATRON);
2000 creature_ptr->muta1 = 0;
2001 creature_ptr->muta2 = 0;
2002 creature_ptr->muta3 = 0;
2003 get_virtues(creature_ptr);
2007 rd_s16b(&creature_ptr->tim_esp);
2008 rd_s16b(&creature_ptr->wraith_form);
2009 rd_s16b(&creature_ptr->resist_magic);
2010 rd_s16b(&creature_ptr->tim_regen);
2011 rd_s16b(&creature_ptr->kabenuke);
2012 rd_s16b(&creature_ptr->tim_stealth);
2013 rd_s16b(&creature_ptr->tim_levitation);
2014 rd_s16b(&creature_ptr->tim_sh_touki);
2015 rd_s16b(&creature_ptr->lightspeed);
2016 rd_s16b(&creature_ptr->tsubureru);
2017 if (z_older_than(10, 4, 7))
2018 creature_ptr->magicdef = 0;
2020 rd_s16b(&creature_ptr->magicdef);
2021 rd_s16b(&creature_ptr->tim_res_nether);
2022 if (z_older_than(10, 4, 11))
2024 creature_ptr->tim_res_time = 0;
2025 creature_ptr->mimic_form = 0;
2026 creature_ptr->tim_mimic = 0;
2027 creature_ptr->tim_sh_fire = 0;
2031 rd_s16b(&creature_ptr->tim_res_time);
2033 creature_ptr->mimic_form = (IDX)tmp8u;
2034 rd_s16b(&creature_ptr->tim_mimic);
2035 rd_s16b(&creature_ptr->tim_sh_fire);
2038 if (z_older_than(11, 0, 99))
2040 creature_ptr->tim_sh_holy = 0;
2041 creature_ptr->tim_eyeeye = 0;
2045 rd_s16b(&creature_ptr->tim_sh_holy);
2046 rd_s16b(&creature_ptr->tim_eyeeye);
2049 if (z_older_than(11, 0, 3)) {
2050 creature_ptr->tim_reflect = 0;
2051 creature_ptr->multishadow = 0;
2052 creature_ptr->dustrobe = 0;
2056 rd_s16b(&creature_ptr->tim_reflect);
2057 rd_s16b(&creature_ptr->multishadow);
2058 rd_s16b(&creature_ptr->dustrobe);
2061 rd_s16b(&creature_ptr->chaos_patron);
2062 rd_u32b(&creature_ptr->muta1);
2063 rd_u32b(&creature_ptr->muta2);
2064 rd_u32b(&creature_ptr->muta3);
2066 for (int i = 0; i < 8; i++)
2067 rd_s16b(&creature_ptr->virtues[i]);
2068 for (int i = 0; i < 8; i++)
2069 rd_s16b(&creature_ptr->vir_types[i]);
2072 creature_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod(creature_ptr);
2073 if (z_older_than(10, 0, 9))
2076 if (tmp8u) creature_ptr->special_attack = ATTACK_CONFUSE;
2077 creature_ptr->ele_attack = 0;
2081 rd_s16b(&creature_ptr->ele_attack);
2082 rd_u32b(&creature_ptr->special_attack);
2085 if (creature_ptr->special_attack & KAMAE_MASK) creature_ptr->action = ACTION_KAMAE;
2086 else if (creature_ptr->special_attack & KATA_MASK) creature_ptr->action = ACTION_KATA;
2087 if (z_older_than(10, 0, 12))
2089 creature_ptr->ele_immune = 0;
2090 creature_ptr->special_defense = 0;
2094 rd_s16b(&creature_ptr->ele_immune);
2095 rd_u32b(&creature_ptr->special_defense);
2098 rd_byte(&creature_ptr->knowledge);
2100 creature_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2104 creature_ptr->action = (ACTION_IDX)tmp8u;
2105 if (!z_older_than(10, 4, 3))
2108 if (tmp8u) creature_ptr->action = ACTION_LEARN;
2111 rd_byte((byte *)&preserve_mode);
2112 rd_byte((byte *)&creature_ptr->wait_report_score);
2114 for (int i = 0; i < 48; i++) rd_byte(&tmp8u);
2117 rd_u32b(¤t_world_ptr->seed_flavor);
2118 rd_u32b(¤t_world_ptr->seed_town);
2120 rd_u16b(&creature_ptr->panic_save);
2121 rd_u16b(¤t_world_ptr->total_winner);
2122 rd_u16b(¤t_world_ptr->noscore);
2125 creature_ptr->is_dead = tmp8u;
2127 rd_byte(&creature_ptr->feeling);
2129 switch (creature_ptr->start_race)
2135 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2138 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2142 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2143 rd_s32b(&creature_ptr->current_floor_ptr->generated_turn);
2144 if (h_older_than(1, 7, 0, 4))
2146 creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
2150 rd_s32b(&creature_ptr->feeling_turn);
2153 rd_s32b(¤t_world_ptr->game_turn);
2154 if (z_older_than(10, 3, 12))
2156 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2158 else rd_s32b(¤t_world_ptr->dungeon_turn);
2160 if (z_older_than(11, 0, 13))
2162 creature_ptr->current_floor_ptr->generated_turn /= 2;
2163 creature_ptr->feeling_turn /= 2;
2164 current_world_ptr->game_turn /= 2;
2165 current_world_ptr->dungeon_turn /= 2;
2168 if (z_older_than(10, 3, 13))
2170 current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
2172 else rd_s32b(¤t_world_ptr->arena_start_turn);
2174 if (z_older_than(10, 0, 3))
2176 determine_daily_bounty(creature_ptr, TRUE);
2180 rd_s16b(&today_mon);
2181 rd_s16b(&creature_ptr->today_mon);
2184 if (z_older_than(10, 0, 7))
2186 creature_ptr->riding = 0;
2190 rd_s16b(&creature_ptr->riding);
2193 if (h_older_than(1, 5, 0, 0))
2195 creature_ptr->floor_id = 0;
2199 rd_s16b(&creature_ptr->floor_id);
2202 if (h_older_than(1, 5, 0, 2))
2209 for (int i = 0; i < tmp16s; i++)
2211 monster_type dummy_mon;
2212 rd_monster(creature_ptr, &dummy_mon);
2216 if (z_older_than(10, 1, 2))
2218 current_world_ptr->play_time = 0;
2222 rd_u32b(¤t_world_ptr->play_time);
2225 if (z_older_than(10, 3, 9))
2227 creature_ptr->visit = 1L;
2229 else if (z_older_than(10, 3, 10))
2233 creature_ptr->visit = 1L;
2239 creature_ptr->visit = (BIT_FLAGS)tmp32s;
2242 if (!z_older_than(11, 0, 5))
2244 rd_u32b(&creature_ptr->count);
2250 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2251 * @param player_ptr プレーヤーへの参照ポインタ
2254 * Note that the inventory changed in Angband 2.7.4. Two extra
2255 * pack slots were added and the equipment was rearranged. Note
2256 * that these two features combine when parsing old save-files, in
2257 * which items from the old "aux" slot are "carried", perhaps into
2258 * one of the two new "inventory" slots.
2260 * Note that the inventory is "re-sorted" later by "dungeon()".
2262 static errr rd_inventory(player_type *player_ptr)
2264 player_ptr->total_weight = 0;
2265 player_ptr->inven_cnt = 0;
2266 player_ptr->equip_cnt = 0;
2268 if (player_ptr->inventory_list != NULL) C_WIPE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2269 C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2277 if (n == 0xFFFF) break;
2284 if (!q_ptr->k_idx) return (53);
2286 if (n >= INVEN_RARM)
2288 q_ptr->marked |= OM_TOUCHED;
2289 object_copy(&player_ptr->inventory_list[n], q_ptr);
2290 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2291 player_ptr->equip_cnt++;
2295 if (player_ptr->inven_cnt == INVEN_PACK)
2297 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
2302 q_ptr->marked |= OM_TOUCHED;
2303 object_copy(&player_ptr->inventory_list[n], q_ptr);
2304 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2305 player_ptr->inven_cnt++;
2313 * @brief メッセージログを読み込む / Read the saved messages
2316 static void rd_messages(void)
2318 if (h_older_than(2, 2, 0, 75))
2323 message_max = (int)num;
2325 for (int i = 0; i < message_max; i++)
2328 rd_string(buf, sizeof(buf));
2336 message_max = (int)num;
2338 for (int i = 0; i < message_max; i++)
2341 rd_string(buf, sizeof(buf));
2348 * @brief メッセージログを読み込む / Read the dungeon (old method)
2349 * @param creature_ptr プレーヤーへの参照ポインタ
2352 * The monsters/objects must be loaded in the same order
2353 * that they were stored, since the actual indexes matter.
2355 static errr rd_dungeon_old(player_type *creature_ptr)
2359 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2360 floor_ptr->dun_level = (DEPTH)tmp16s;
2361 if (z_older_than(10, 3, 8)) creature_ptr->dungeon_idx = DUNGEON_ANGBAND;
2366 creature_ptr->dungeon_idx = (IDX)tmp8u;
2369 floor_ptr->base_level = floor_ptr->dun_level;
2371 floor_ptr->base_level = (DEPTH)tmp16s;
2374 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2376 creature_ptr->y = (POSITION)tmp16s;
2378 creature_ptr->x = (POSITION)tmp16s;
2379 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) { creature_ptr->y = 33; creature_ptr->x = 131; }
2381 floor_ptr->height = (POSITION)tmp16s;
2383 floor_ptr->width = (POSITION)tmp16s;
2384 rd_s16b(&tmp16s); /* max_panel_rows */
2385 rd_s16b(&tmp16s); /* max_panel_cols */
2387 int ymax = floor_ptr->height;
2388 int xmax = floor_ptr->width;
2390 for (int x = 0, y = 0; y < ymax; )
2395 if (z_older_than(10, 3, 6))
2404 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2407 for (int i = count; i > 0; i--)
2410 g_ptr = &floor_ptr->grid_array[y][x];
2415 if (++y >= ymax) break;
2420 for (int x = 0, y = 0; y < ymax; )
2426 for (int i = count; i > 0; i--)
2429 g_ptr = &floor_ptr->grid_array[y][x];
2430 g_ptr->feat = (s16b)tmp8u;
2434 if (++y >= ymax) break;
2439 for (int x = 0, y = 0; y < ymax; )
2445 for (int i = count; i > 0; i--)
2448 g_ptr = &floor_ptr->grid_array[y][x];
2449 g_ptr->mimic = (s16b)tmp8u;
2453 if (++y >= ymax) break;
2458 for (int x = 0, y = 0; y < ymax; )
2463 for (int i = count; i > 0; i--)
2466 g_ptr = &floor_ptr->grid_array[y][x];
2467 g_ptr->special = tmp16s;
2471 if (++y >= ymax) break;
2476 if (z_older_than(11, 0, 99))
2478 for (int y = 0; y < ymax; y++)
2480 for (int x = 0; x < xmax; x++)
2482 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2487 if (h_older_than(1, 1, 1, 0))
2489 for (int y = 0; y < ymax; y++)
2491 for (int x = 0; x < xmax; x++)
2494 g_ptr = &floor_ptr->grid_array[y][x];
2497 if (g_ptr->feat == OLD_FEAT_INVIS)
2499 g_ptr->feat = feat_floor;
2500 g_ptr->info |= CAVE_TRAP;
2503 /* Older than 1.1.1 */
2504 if (g_ptr->feat == OLD_FEAT_MIRROR)
2506 g_ptr->feat = feat_floor;
2507 g_ptr->info |= CAVE_OBJECT;
2513 if (h_older_than(1, 3, 1, 0))
2515 for (int y = 0; y < ymax; y++)
2517 for (int x = 0; x < xmax; x++)
2520 g_ptr = &floor_ptr->grid_array[y][x];
2522 /* Old CAVE_IN_MIRROR flag */
2523 if (g_ptr->info & CAVE_OBJECT)
2525 g_ptr->mimic = feat_mirror;
2527 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2528 (g_ptr->feat == OLD_FEAT_GLYPH))
2530 g_ptr->info |= CAVE_OBJECT;
2531 g_ptr->mimic = g_ptr->feat;
2532 g_ptr->feat = feat_floor;
2534 else if (g_ptr->info & CAVE_TRAP)
2536 g_ptr->info &= ~CAVE_TRAP;
2537 g_ptr->mimic = g_ptr->feat;
2538 g_ptr->feat = choose_random_trap(creature_ptr);
2540 else if (g_ptr->feat == OLD_FEAT_INVIS)
2542 g_ptr->mimic = feat_floor;
2543 g_ptr->feat = feat_trap_open;
2549 /* Quest 18 was removed */
2550 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2552 for (int y = 0; y < ymax; y++)
2554 for (int x = 0; x < xmax; x++)
2557 g_ptr = &floor_ptr->grid_array[y][x];
2559 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2561 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2563 g_ptr->feat = feat_tree;
2566 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2568 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2571 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2572 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2574 g_ptr->feat = feat_up_stair;
2583 if (limit > current_world_ptr->max_o_idx)
2585 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2589 for (int i = 1; i < limit; i++)
2591 OBJECT_IDX o_idx = o_pop(floor_ptr);
2594 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2599 o_ptr = &floor_ptr->o_list[o_idx];
2601 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2603 monster_type *m_ptr;
2604 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2605 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2606 m_ptr->hold_o_idx = o_idx;
2611 g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2612 o_ptr->next_o_idx = g_ptr->o_idx;
2613 g_ptr->o_idx = o_idx;
2617 if (limit > current_world_ptr->max_m_idx)
2619 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2623 for (int i = 1; i < limit; i++)
2626 monster_type *m_ptr;
2627 m_idx = m_pop(creature_ptr);
2630 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2634 m_ptr = &floor_ptr->m_list[m_idx];
2635 rd_monster(creature_ptr, m_ptr);
2637 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2638 g_ptr->m_idx = m_idx;
2639 real_r_ptr(m_ptr)->cur_num++;
2642 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena)
2643 current_world_ptr->character_dungeon = FALSE;
2645 current_world_ptr->character_dungeon = TRUE;
2652 * @brief 保存されたフロアを読み込む / Read the saved floor
2653 * @param player_ptr プレーヤーへの参照ポインタ
2654 * @param sf_ptr 最後に保存されたフロアへの参照ポインタ
2655 * @return info読み込みエラーコード
2657 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2660 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2661 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2663 * The monsters/objects must be loaded in the same order
2664 * that they were stored, since the actual indexes matter.
2666 static errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
2668 grid_template_type *templates;
2669 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2670 clear_cave(player_ptr);
2671 player_ptr->x = player_ptr->y = 0;
2677 floor_ptr->dun_level = (DEPTH)tmp16s;
2678 floor_ptr->base_level = floor_ptr->dun_level;
2684 if (tmp16s != sf_ptr->floor_id) return 171;
2688 if (tmp8u != sf_ptr->savefile_id) return 171;
2691 if (tmp16s != sf_ptr->dun_level) return 171;
2692 floor_ptr->dun_level = sf_ptr->dun_level;
2696 if (tmp32s != sf_ptr->last_visit) return 171;
2700 if (tmp32u != sf_ptr->visit_mark) return 171;
2703 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2706 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2711 floor_ptr->base_level = (DEPTH)tmp16s;
2713 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2717 player_ptr->y = (POSITION)tmp16u;
2720 player_ptr->x = (POSITION)tmp16u;
2723 floor_ptr->height = (POSITION)tmp16s;
2725 floor_ptr->width = (POSITION)tmp16s;
2727 rd_byte(&player_ptr->feeling);
2731 C_MAKE(templates, limit, grid_template_type);
2733 for (int i = 0; i < limit; i++)
2735 grid_template_type *ct_ptr = &templates[i];
2737 ct_ptr->info = (BIT_FLAGS)tmp16u;
2738 if (h_older_than(1, 7, 0, 2))
2742 ct_ptr->feat = (s16b)tmp8u;
2744 ct_ptr->mimic = (s16b)tmp8u;
2748 rd_s16b(&ct_ptr->feat);
2749 rd_s16b(&ct_ptr->mimic);
2752 rd_s16b(&ct_ptr->special);
2755 POSITION ymax = floor_ptr->height;
2756 POSITION xmax = floor_ptr->width;
2757 for (POSITION x = 0, y = 0; y < ymax; )
2768 } while (tmp8u == MAX_UCHAR);
2770 for (int i = count; i > 0; i--)
2772 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2773 g_ptr->info = templates[id].info;
2774 g_ptr->feat = templates[id].feat;
2775 g_ptr->mimic = templates[id].mimic;
2776 g_ptr->special = templates[id].special;
2781 if (++y >= ymax) break;
2786 /* Quest 18 was removed */
2787 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2789 for (POSITION y = 0; y < ymax; y++)
2791 for (POSITION x = 0; x < xmax; x++)
2793 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2795 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2797 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2799 g_ptr->feat = feat_tree;
2802 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2804 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2807 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2808 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2810 g_ptr->feat = feat_up_stair;
2817 C_KILL(templates, limit, grid_template_type);
2819 if (limit > current_world_ptr->max_o_idx) return 151;
2820 for (int i = 1; i < limit; i++)
2824 o_idx = o_pop(floor_ptr);
2825 if (i != o_idx) return 152;
2827 o_ptr = &floor_ptr->o_list[o_idx];
2830 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2832 monster_type *m_ptr;
2833 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2834 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2835 m_ptr->hold_o_idx = o_idx;
2839 grid_type *g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2840 o_ptr->next_o_idx = g_ptr->o_idx;
2841 g_ptr->o_idx = o_idx;
2846 if (limit > current_world_ptr->max_m_idx) return 161;
2848 for (int i = 1; i < limit; i++)
2852 monster_type *m_ptr;
2853 m_idx = m_pop(player_ptr);
2854 if (i != m_idx) return 162;
2856 m_ptr = &floor_ptr->m_list[m_idx];
2857 rd_monster(player_ptr, m_ptr);
2858 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2859 g_ptr->m_idx = m_idx;
2860 real_r_ptr(m_ptr)->cur_num++;
2868 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
2869 * @param player_ptr プレーヤーへの参照ポインタ
2872 * The monsters/objects must be loaded in the same order
2873 * that they were stored, since the actual indexes matter.
2875 static errr rd_dungeon(player_type *player_ptr)
2877 init_saved_floors(player_ptr, FALSE);
2879 if (h_older_than(1, 5, 0, 0))
2881 err = rd_dungeon_old(player_ptr);
2882 if (player_ptr->dungeon_idx)
2884 player_ptr->floor_id = get_new_floor_id(player_ptr);
2885 get_sf_ptr(player_ptr->floor_id)->dun_level = player_ptr->current_floor_ptr->dun_level;
2891 rd_s16b(&max_floor_id);
2894 player_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
2899 err = rd_saved_floor(player_ptr, NULL);
2903 for (int i = 0; i < num; i++)
2905 saved_floor_type *sf_ptr = &saved_floors[i];
2907 rd_s16b(&sf_ptr->floor_id);
2909 sf_ptr->savefile_id = (s16b)tmp8u;
2913 sf_ptr->dun_level = (DEPTH)tmp16s;
2915 rd_s32b(&sf_ptr->last_visit);
2916 rd_u32b(&sf_ptr->visit_mark);
2917 rd_s16b(&sf_ptr->upper_floor_id);
2918 rd_s16b(&sf_ptr->lower_floor_id);
2921 for (int i = 0; i < num; i++)
2923 saved_floor_type *sf_ptr = &saved_floors[i];
2924 if (!sf_ptr->floor_id) continue;
2926 if (tmp8u) continue;
2928 err = rd_saved_floor(player_ptr, sf_ptr);
2931 if (!save_floor(player_ptr, sf_ptr, SLF_SECOND)) err = 182;
2938 if (!load_floor(player_ptr, get_sf_ptr(player_ptr->floor_id), SLF_SECOND)) err = 183;
2945 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
2949 note(_("アイテム配置エラー", "Object allocation error"));
2953 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
2957 note(_("モンスター配置エラー", "Monster allocation error"));
2961 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
2965 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporary files!"));
2969 note(_("Error 183", "Error 183"));
2973 current_world_ptr->character_dungeon = TRUE;
2979 * @brief ロード処理全体のサブ関数 / Actually read the savefile
2982 static errr rd_savefile_new_aux(player_type *creature_ptr)
2984 u32b n_x_check, n_v_check;
2985 u32b o_x_check, o_v_check;
2988 xor_byte = current_world_ptr->sf_extra;
2992 /* Old savefile will be version 0.0.0.3 */
2993 rd_byte(¤t_world_ptr->h_ver_extra);
2994 rd_byte(¤t_world_ptr->h_ver_patch);
2995 rd_byte(¤t_world_ptr->h_ver_minor);
2996 rd_byte(¤t_world_ptr->h_ver_major);
2999 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3000 (current_world_ptr->h_ver_major > 9) ? current_world_ptr->h_ver_major - 10 : current_world_ptr->h_ver_major, current_world_ptr->h_ver_minor, current_world_ptr->h_ver_patch, current_world_ptr->h_ver_extra));
3002 rd_u32b(¤t_world_ptr->sf_system);
3003 rd_u32b(¤t_world_ptr->sf_when);
3004 rd_u16b(¤t_world_ptr->sf_lives);
3005 rd_u16b(¤t_world_ptr->sf_saves);
3015 rd_byte(&kanji_code);
3018 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3021 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3024 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3026 for (int i = 0; i < max_r_idx; i++)
3028 monster_race *r_ptr = &r_info[i];
3029 r_ptr->max_num = 100;
3031 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3032 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3036 if (tmp16u > max_r_idx)
3038 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3042 for (int i = 0; i < tmp16u; i++)
3044 rd_lore((MONRACE_IDX)i);
3047 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3050 if (tmp16u > max_k_idx)
3052 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3056 for (int i = 0; i < tmp16u; i++)
3058 object_kind *k_ptr = &k_info[i];
3060 k_ptr->aware = (tmp8u & 0x01) ? TRUE : FALSE;
3061 k_ptr->tried = (tmp8u & 0x02) ? TRUE : FALSE;
3063 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3065 /* 2.1.3 or newer version */
3067 u16b max_towns_load;
3068 u16b max_quests_load;
3069 byte max_rquests_load;
3070 s16b old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
3072 rd_u16b(&max_towns_load);
3073 if (max_towns_load > max_towns)
3075 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3079 rd_u16b(&max_quests_load);
3080 if (z_older_than(11, 0, 7))
3082 max_rquests_load = 10;
3086 rd_byte(&max_rquests_load);
3089 if (max_quests_load > max_q_idx)
3091 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3095 for (int i = 0; i < max_quests_load; i++)
3104 quest_type* const q_ptr = &quest[i];
3106 rd_s16b(&q_ptr->status);
3109 q_ptr->level = tmp16s;
3111 if (z_older_than(11, 0, 6))
3118 q_ptr->complev = tmp8u;
3120 if (h_older_than(2, 1, 2, 2))
3122 q_ptr->comptime = 0;
3126 rd_u32b(&q_ptr->comptime);
3129 bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
3130 is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
3131 is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
3132 if (!is_quest_running) continue;
3135 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3137 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3138 rd_s16b(&q_ptr->type);
3140 rd_s16b(&q_ptr->r_idx);
3141 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3143 determine_random_questor(creature_ptr, &quest[i]);
3146 rd_s16b(&q_ptr->k_idx);
3148 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3151 q_ptr->flags = tmp8u;
3153 if (z_older_than(10, 3, 11))
3155 if (q_ptr->flags & QUEST_FLAG_PRESET)
3161 init_flags = INIT_ASSIGN;
3162 creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)i;
3164 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
3165 creature_ptr->current_floor_ptr->inside_quest = old_inside_quest;
3171 q_ptr->dungeon = tmp8u;
3174 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3175 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3176 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3179 /* Quest 18 was removed */
3180 if (h_older_than(1, 7, 0, 6))
3182 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3183 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3186 rd_s32b(&creature_ptr->wilderness_x);
3187 rd_s32b(&creature_ptr->wilderness_y);
3188 if (z_older_than(10, 3, 13))
3190 creature_ptr->wilderness_x = 5;
3191 creature_ptr->wilderness_y = 48;
3194 if (z_older_than(10, 3, 7)) creature_ptr->wild_mode = FALSE;
3195 else rd_byte((byte *)&creature_ptr->wild_mode);
3196 if (z_older_than(10, 3, 7)) creature_ptr->ambush_flag = FALSE;
3197 else rd_byte((byte *)&creature_ptr->ambush_flag);
3201 rd_s32b(&wild_x_size);
3202 rd_s32b(&wild_y_size);
3204 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3206 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3210 for (int i = 0; i < wild_x_size; i++)
3212 for (int j = 0; j < wild_y_size; j++)
3214 rd_u32b(&wilderness[j][i].seed);
3219 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3222 if (tmp16u > max_a_idx)
3224 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3228 for (int i = 0; i < tmp16u; i++)
3230 artifact_type *a_ptr = &a_info[i];
3233 a_ptr->cur_num = tmp8u;
3235 if (h_older_than(1, 5, 0, 0))
3237 a_ptr->floor_id = 0;
3245 rd_s16b(&a_ptr->floor_id);
3249 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3251 rd_extra(creature_ptr);
3252 if (creature_ptr->energy_need < -999) creature_ptr->timewalk = TRUE;
3254 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3257 if (tmp16u > PY_MAX_LEVEL)
3259 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3263 for (int i = 0; i < tmp16u; i++)
3267 creature_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3270 sp_ptr = &sex_info[creature_ptr->psex];
3271 rp_ptr = &race_info[creature_ptr->prace];
3272 cp_ptr = &class_info[creature_ptr->pclass];
3273 ap_ptr = &seikaku_info[creature_ptr->pseikaku];
3275 if (z_older_than(10, 2, 2) && (creature_ptr->pclass == CLASS_BEASTMASTER) && !creature_ptr->is_dead)
3277 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3278 roll_hitdice(creature_ptr, 0L);
3281 if (z_older_than(10, 3, 2) && (creature_ptr->pclass == CLASS_ARCHER) && !creature_ptr->is_dead)
3283 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3284 roll_hitdice(creature_ptr, 0L);
3287 if (z_older_than(10, 2, 6) && (creature_ptr->pclass == CLASS_SORCERER) && !creature_ptr->is_dead)
3289 creature_ptr->hitdie = rp_ptr->r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3290 roll_hitdice(creature_ptr, 0L);
3293 if (z_older_than(10, 4, 7) && (creature_ptr->pclass == CLASS_BLUE_MAGE) && !creature_ptr->is_dead)
3295 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3296 roll_hitdice(creature_ptr, 0L);
3299 mp_ptr = &m_info[creature_ptr->pclass];
3301 rd_u32b(&creature_ptr->spell_learned1);
3302 rd_u32b(&creature_ptr->spell_learned2);
3303 rd_u32b(&creature_ptr->spell_worked1);
3304 rd_u32b(&creature_ptr->spell_worked2);
3305 rd_u32b(&creature_ptr->spell_forgotten1);
3306 rd_u32b(&creature_ptr->spell_forgotten2);
3308 if (z_older_than(10, 0, 5))
3310 creature_ptr->learned_spells = 0;
3311 for (int i = 0; i < 64; i++)
3314 (creature_ptr->spell_learned1 & (1L << i)) :
3315 (creature_ptr->spell_learned2 & (1L << (i - 32))))
3317 creature_ptr->learned_spells++;
3321 else rd_s16b(&creature_ptr->learned_spells);
3323 if (z_older_than(10, 0, 6))
3325 creature_ptr->add_spells = 0;
3327 else rd_s16b(&creature_ptr->add_spells);
3329 if (creature_ptr->pclass == CLASS_MINDCRAFTER) creature_ptr->add_spells = 0;
3331 for (int i = 0; i < 64; i++)
3334 creature_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3337 if (rd_inventory(creature_ptr))
3339 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3344 int town_count = tmp16u;
3347 for (int i = 1; i < town_count; i++)
3349 for (int j = 0; j < tmp16u; j++)
3351 if (rd_store(creature_ptr, i, j)) return (22);
3355 rd_s16b(&creature_ptr->pet_follow_distance);
3356 if (z_older_than(10, 4, 10))
3358 creature_ptr->pet_extra_flags = 0;
3360 if (tmp8u) creature_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3362 if (tmp8u) creature_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3364 if (z_older_than(10, 0, 4)) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3368 if (tmp8u) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3371 if (z_older_than(10, 0, 7)) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3375 if (tmp8u) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3378 if (z_older_than(10, 0, 8)) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3382 if (tmp8u) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3385 if (!z_older_than(10, 0, 8))
3388 if (tmp8u) creature_ptr->pet_extra_flags |= PF_BALL_SPELL;
3393 rd_s16b(&creature_ptr->pet_extra_flags);
3396 if (!z_older_than(11, 0, 9))
3398 char buf[SCREEN_BUF_MAX_SIZE];
3399 rd_string(buf, sizeof(buf));
3400 if (buf[0]) screen_dump = string_make(buf);
3403 if (creature_ptr->is_dead)
3405 for (int i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3407 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3411 if (!creature_ptr->is_dead)
3413 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3414 if (rd_dungeon(creature_ptr))
3416 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3425 strip_bytes(tmp32s);
3429 /* Quest 18 was removed */
3430 if (h_older_than(1, 7, 0, 6))
3432 if (creature_ptr->current_floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3434 creature_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3435 creature_ptr->current_floor_ptr->dun_level = 1;
3436 creature_ptr->current_floor_ptr->inside_quest = 0;
3440 n_v_check = v_check;
3441 rd_u32b(&o_v_check);
3442 if (o_v_check != n_v_check)
3444 note(_("チェックサムがおかしい", "Invalid checksum"));
3448 n_x_check = x_check;
3449 rd_u32b(&o_x_check);
3450 if (o_x_check != n_x_check)
3452 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3461 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3462 * @param player_ptr プレーヤーへの参照ポインタ
3465 errr rd_savefile_new(player_type *player_ptr)
3468 fff = my_fopen(savefile, "rb");
3470 if (!fff) return -1;
3471 errr err = rd_savefile_new_aux(player_ptr);
3473 if (ferror(fff)) err = -1;
3480 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3481 * @param player_ptr プレーヤーへの参照ポインタ
3482 * @param sf_ptr 保存フロア読み込み先
3485 static bool load_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
3487 u32b n_x_check, n_v_check;
3488 u32b o_x_check, o_v_check;
3497 current_world_ptr->h_ver_extra = H_VER_EXTRA;
3498 current_world_ptr->h_ver_patch = H_VER_PATCH;
3499 current_world_ptr->h_ver_minor = H_VER_MINOR;
3500 current_world_ptr->h_ver_major = H_VER_MAJOR;
3504 if (saved_floor_file_sign != tmp32u) return FALSE;
3506 if (rd_saved_floor(player_ptr, sf_ptr)) return FALSE;
3508 n_v_check = v_check;
3509 rd_u32b(&o_v_check);
3511 if (o_v_check != n_v_check) return FALSE;
3513 n_x_check = x_check;
3514 rd_u32b(&o_x_check);
3516 if (o_x_check != n_x_check) return FALSE;
3522 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporarily saved-floor data
3523 * @param player_ptr プレーヤーへの参照ポインタ
3524 * @param sf_ptr 保存フロア読み込み先
3528 bool load_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
3531 * Temporary files are always written in system depended kanji
3545 FILE *old_fff = NULL;
3546 byte old_xor_byte = 0;
3547 u32b old_v_check = 0;
3548 u32b old_x_check = 0;
3549 byte old_h_ver_major = 0;
3550 byte old_h_ver_minor = 0;
3551 byte old_h_ver_patch = 0;
3552 byte old_h_ver_extra = 0;
3553 if (mode & SLF_SECOND)
3556 old_xor_byte = xor_byte;
3557 old_v_check = v_check;
3558 old_x_check = x_check;
3559 old_h_ver_major = current_world_ptr->h_ver_major;
3560 old_h_ver_minor = current_world_ptr->h_ver_minor;
3561 old_h_ver_patch = current_world_ptr->h_ver_patch;
3562 old_h_ver_extra = current_world_ptr->h_ver_extra;
3565 char floor_savefile[1024];
3566 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3569 fff = my_fopen(floor_savefile, "rb");
3572 bool is_save_successful = TRUE;
3573 if (!fff) is_save_successful = FALSE;
3575 if (is_save_successful)
3577 is_save_successful = load_floor_aux(player_ptr, sf_ptr);
3578 if (ferror(fff)) is_save_successful = FALSE;
3582 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3587 if (mode & SLF_SECOND)
3590 xor_byte = old_xor_byte;
3591 v_check = old_v_check;
3592 x_check = old_x_check;
3593 current_world_ptr->h_ver_major = old_h_ver_major;
3594 current_world_ptr->h_ver_minor = old_h_ver_minor;
3595 current_world_ptr->h_ver_patch = old_h_ver_patch;
3596 current_world_ptr->h_ver_extra = old_h_ver_extra;
3599 byte old_kanji_code = kanji_code;
3600 kanji_code = old_kanji_code;
3601 return is_save_successful;