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.
45 #include "core/system-variables.h" // 暫定、init_flags の扱いを決めた上で消す.
46 #include "core/angband-version.h"
49 #include "market/building.h"
52 #include "dungeon/dungeon.h"
54 #include "floor/floor-generate.h"
56 #include "mutation/mutation.h"
58 #include "market/store-util.h"
60 #include "market/store.h"
63 #include "spells-status.h"
64 #include "object/object-hook.h"
68 #include "floor/floor.h"
69 #include "floor/floor-save.h"
70 #include "floor/floor-town.h"
74 #include "dungeon/dungeon-file.h"
75 #include "io/uid-checker.h"
77 #include "player-skill.h"
78 #include "player-class.h"
79 #include "player/race-info-table.h"
80 #include "player-personality.h"
81 #include "player-sex.h"
82 #include "birth/birth.h"
83 #include "world/world.h"
84 #include "object/object-kind.h"
85 #include "object/object-ego.h"
88 #include "cmd-smith.h"
91 * Maximum number of tries for selection of a proper quest monster
95 #define OLD_MAX_MANE 22
97 /* Old hidden trap flag */
98 #define CAVE_TRAP 0x8000
100 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
101 #define OLD_FEAT_INVIS 0x02
102 #define OLD_FEAT_GLYPH 0x03
103 #define OLD_FEAT_QUEST_ENTER 0x08
104 #define OLD_FEAT_QUEST_EXIT 0x09
105 #define OLD_FEAT_MINOR_GLYPH 0x40
106 #define OLD_FEAT_BLDG_1 0x81
107 #define OLD_FEAT_MIRROR 0xc3
110 #define OLD_QUEST_WATER_CAVE 18
112 /* Quest constants */
113 #define QUEST_OLD_CASTLE 27
114 #define QUEST_ROYAL_CRYPT 28
117 * Local "savefile" pointer
122 * Hack -- old "encryption" byte
124 static byte xor_byte;
127 * Hack -- simple "checksum" on the actual values
129 static u32b v_check = 0L;
132 * Hack -- simple "checksum" on the encoded bytes
134 static u32b x_check = 0L;
137 * Hack -- Japanese Kanji code
143 static byte kanji_code = 0;
146 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
147 * @param major メジャーバージョン値
148 * @param minor マイナーバージョン値
149 * @param patch パッチバージョン値
150 * @param extra エクストラパージョン値
151 * @return 現在のバージョンより値が古いならtrue
153 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
155 if (current_world_ptr->h_ver_major < major) return TRUE;
156 if (current_world_ptr->h_ver_major > major) return FALSE;
158 if (current_world_ptr->h_ver_minor < minor) return TRUE;
159 if (current_world_ptr->h_ver_minor > minor) return FALSE;
161 if (current_world_ptr->h_ver_patch < patch) return TRUE;
162 if (current_world_ptr->h_ver_patch > patch) return FALSE;
164 if (current_world_ptr->h_ver_extra < extra) return TRUE;
165 if (current_world_ptr->h_ver_extra > extra) return FALSE;
172 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
173 * @param x メジャーバージョン値
174 * @param y マイナーバージョン値
176 * @return 現在のバージョンより値が古いならtrue
178 static bool z_older_than(byte x, byte y, byte z)
180 if (current_world_ptr->z_major < x) return TRUE;
181 if (current_world_ptr->z_major > x) return FALSE;
183 if (current_world_ptr->z_minor < y) return TRUE;
184 if (current_world_ptr->z_minor > y) return FALSE;
186 if (current_world_ptr->z_patch < z) return TRUE;
187 if (current_world_ptr->z_patch > z) return FALSE;
194 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
198 * Avoid the top two lines, to avoid interference with "msg_print()".
200 static void note(concptr msg)
202 static TERM_LEN y = 2;
204 if (++y >= 24) y = 2;
211 * @brief ロードファイルポインタから1バイトを読み込む
214 * The following functions are used to load the basic building blocks
215 * of savefiles. They also maintain the "checksum" info for 2.7.0+
217 static byte sf_get(void)
219 byte c = getc(fff) & 0xFF;
220 byte v = c ^ xor_byte;
230 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
234 static void rd_byte(byte *ip)
241 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
245 static void rd_u16b(u16b *ip)
248 (*ip) |= ((u16b)(sf_get()) << 8);
253 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
257 static void rd_s16b(s16b *ip)
264 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
268 static void rd_u32b(u32b *ip)
271 (*ip) |= ((u32b)(sf_get()) << 8);
272 (*ip) |= ((u32b)(sf_get()) << 16);
273 (*ip) |= ((u32b)(sf_get()) << 24);
278 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
282 static void rd_s32b(s32b *ip)
289 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
290 * @param str 読み込みポインタ
291 * @param max 最大読み取りバイト数
294 static void rd_string(char *str, int max)
296 for (int i = 0; TRUE; i++)
300 if (i < max) str[i] = tmp8u;
323 byte code = codeconv(str);
325 /* 漢字コードが判明したら、それを記録 */
326 if (code) kanji_code = code;
338 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
342 static void strip_bytes(int n)
345 while (n--) rd_byte(&tmp8u);
350 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
351 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
354 * This function attempts to "repair" old savefiles, and to extract
355 * the most up to date values for various object fields.
357 * Note that Angband 2.7.9 introduced a new method for object "flags"
358 * in which the "flags" on an object are actually extracted when they
359 * are needed from the object kind, artifact index, ego-item index,
360 * and two special "xtra" fields which are used to encode any "extra"
361 * power of certain ego-items. This had the side effect that items
362 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
363 * may have had, and also, all "uncursed" items will become "cursed"
364 * again, including Calris, even if it is being worn at the time. As
365 * a complete hack, items which are inscribed with "uncursed" will be
366 * "uncursed" when imported from pre-2.7.9 savefiles.
368 static void rd_item_old(object_type *o_ptr)
370 rd_s16b(&o_ptr->k_idx);
374 o_ptr->iy = (POSITION)tmp8u;
376 o_ptr->ix = (POSITION)tmp8u;
384 if (z_older_than(10, 4, 4))
386 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
387 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
388 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
391 rd_s16b(&o_ptr->pval);
392 rd_byte(&o_ptr->discount);
394 o_ptr->number = (ITEM_NUMBER)tmp8u;
398 o_ptr->weight = tmp16s;
401 o_ptr->name1 = tmp8u;
404 o_ptr->name2 = tmp8u;
406 rd_s16b(&o_ptr->timeout);
407 rd_s16b(&o_ptr->to_h);
409 o_ptr->to_d = tmp16s;
411 rd_s16b(&o_ptr->to_a);
419 rd_byte(&o_ptr->ident);
420 rd_byte(&o_ptr->marked);
421 rd_u32b(&o_ptr->art_flags[0]);
422 rd_u32b(&o_ptr->art_flags[1]);
423 rd_u32b(&o_ptr->art_flags[2]);
424 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
425 else rd_u32b(&o_ptr->art_flags[3]);
427 if (h_older_than(1, 3, 0, 0))
429 if (o_ptr->name2 == EGO_TELEPATHY)
430 add_flag(o_ptr->art_flags, TR_TELEPATHY);
433 if (z_older_than(11, 0, 11))
435 o_ptr->curse_flags = 0L;
436 if (o_ptr->ident & 0x40)
438 o_ptr->curse_flags |= TRC_CURSED;
439 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
440 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
441 if (object_is_fixed_artifact(o_ptr))
443 artifact_type *a_ptr = &a_info[o_ptr->name1];
444 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
445 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
447 else if (object_is_ego(o_ptr))
449 ego_item_type *e_ptr = &e_info[o_ptr->name2];
450 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
451 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
454 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
458 rd_u32b(&o_ptr->curse_flags);
461 rd_s16b(&o_ptr->held_m_idx);
462 rd_byte(&o_ptr->xtra1);
463 rd_byte(&o_ptr->xtra2);
465 if (z_older_than(11, 0, 10))
467 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
469 switch (o_ptr->xtra2 % 6)
471 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
472 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
473 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
474 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
475 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
476 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
480 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
482 switch (o_ptr->xtra2 % 11)
484 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
485 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
486 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
487 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
488 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
489 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
490 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
491 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
492 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
493 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
494 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
498 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
500 switch (o_ptr->xtra2 % 8)
502 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
503 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
504 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
505 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
506 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
507 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
508 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
509 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
516 if (z_older_than(10, 2, 3))
521 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
523 o_ptr->xtra3 = o_ptr->xtra1;
526 if (o_ptr->tval == TV_CAPTURE)
528 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
529 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
531 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
532 if (ironman_nightmare)
534 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5 * 2L);
536 o_ptr->xtra4 = o_ptr->xtra5;
541 rd_byte(&o_ptr->xtra3);
542 if (h_older_than(1, 3, 0, 1))
544 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1 + 96)
545 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
548 rd_s16b(&o_ptr->xtra4);
549 rd_s16b(&o_ptr->xtra5);
552 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)))
554 o_ptr->xtra4 = o_ptr->pval;
558 rd_byte(&o_ptr->feeling);
561 rd_string(buf, sizeof(buf));
562 if (buf[0]) o_ptr->inscription = quark_add(buf);
564 rd_string(buf, sizeof(buf));
566 /* todo 元々このif文には末尾に";"が付いていた、バグかもしれない */
567 if (buf[0]) o_ptr->art_name = quark_add(buf);
575 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
577 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
579 if (z_older_than(10, 4, 9))
581 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
583 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
584 add_flag(o_ptr->art_flags, TR_DEC_MANA);
588 if (object_is_fixed_artifact(o_ptr))
590 artifact_type *a_ptr;
591 a_ptr = &a_info[o_ptr->name1];
592 if (!a_ptr->name) o_ptr->name1 = 0;
595 if (object_is_ego(o_ptr))
597 ego_item_type *e_ptr;
598 e_ptr = &e_info[o_ptr->name2];
599 if (!e_ptr->name) o_ptr->name2 = 0;
605 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
606 * @param o_ptr アイテムオブジェクト保存先ポインタ
609 static void rd_item(object_type *o_ptr)
611 if (h_older_than(1, 5, 0, 0))
619 rd_s16b(&o_ptr->k_idx);
623 o_ptr->iy = (POSITION)tmp8u;
625 o_ptr->ix = (POSITION)tmp8u;
628 k_ptr = &k_info[o_ptr->k_idx];
629 o_ptr->tval = k_ptr->tval;
630 o_ptr->sval = k_ptr->sval;
632 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
633 else o_ptr->pval = 0;
635 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
636 else o_ptr->discount = 0;
637 if (flags & SAVE_ITEM_NUMBER) {
639 o_ptr->number = tmp8u;
641 else o_ptr->number = 1;
645 o_ptr->weight = tmp16s;
647 if (flags & SAVE_ITEM_NAME1)
650 o_ptr->name1 = tmp8u;
652 else o_ptr->name1 = 0;
654 if (flags & SAVE_ITEM_NAME2)
657 o_ptr->name2 = tmp8u;
659 else o_ptr->name2 = 0;
661 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
662 else o_ptr->timeout = 0;
664 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
665 else o_ptr->to_h = 0;
667 if (flags & SAVE_ITEM_TO_D)
670 o_ptr->to_d = tmp16s;
672 else o_ptr->to_d = 0;
674 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
675 else o_ptr->to_a = 0;
677 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
680 if (flags & SAVE_ITEM_DD)
687 if (flags & SAVE_ITEM_DS)
694 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
695 else o_ptr->ident = 0;
697 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
698 else o_ptr->marked = 0;
701 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
702 else o_ptr->art_flags[0] = 0;
704 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
705 else o_ptr->art_flags[1] = 0;
707 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
708 else o_ptr->art_flags[2] = 0;
710 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
711 else o_ptr->art_flags[3] = 0;
713 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
714 else o_ptr->art_flags[4] = 0;
716 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
717 else o_ptr->curse_flags = 0;
719 /* Monster holding object */
720 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
721 else o_ptr->held_m_idx = 0;
724 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
725 else o_ptr->xtra1 = 0;
727 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
728 else o_ptr->xtra2 = 0;
730 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
731 else o_ptr->xtra3 = 0;
733 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
734 else o_ptr->xtra4 = 0;
736 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
737 else o_ptr->xtra5 = 0;
739 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
740 else o_ptr->feeling = 0;
742 if (flags & SAVE_ITEM_INSCRIPTION)
745 rd_string(buf, sizeof(buf));
746 o_ptr->inscription = quark_add(buf);
748 else o_ptr->inscription = 0;
750 if (flags & SAVE_ITEM_ART_NAME)
753 rd_string(buf, sizeof(buf));
754 o_ptr->art_name = quark_add(buf);
761 if (!h_older_than(2, 1, 2, 4)) return;
763 BIT_FLAGS flgs[TR_FLAG_SIZE];
764 object_flags(o_ptr, flgs);
766 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
768 add_flag(o_ptr->art_flags, TR_LITE_M1);
769 remove_flag(o_ptr->art_flags, TR_LITE_1);
770 remove_flag(o_ptr->art_flags, TR_LITE_2);
771 remove_flag(o_ptr->art_flags, TR_LITE_3);
775 if (o_ptr->name2 == EGO_LITE_DARKNESS)
777 if (o_ptr->tval != TV_LITE)
779 add_flag(o_ptr->art_flags, TR_LITE_M1);
783 if (o_ptr->sval == SV_LITE_TORCH)
785 add_flag(o_ptr->art_flags, TR_LITE_M1);
787 else if (o_ptr->sval == SV_LITE_LANTERN)
789 add_flag(o_ptr->art_flags, TR_LITE_M2);
791 else if (o_ptr->sval == SV_LITE_FEANOR)
793 add_flag(o_ptr->art_flags, TR_LITE_M3);
799 if (o_ptr->tval == TV_LITE)
801 if (object_is_fixed_artifact(o_ptr))
803 add_flag(o_ptr->art_flags, TR_LITE_3);
807 if (o_ptr->sval == SV_LITE_TORCH)
809 add_flag(o_ptr->art_flags, TR_LITE_1);
810 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
814 if (o_ptr->sval == SV_LITE_LANTERN)
816 add_flag(o_ptr->art_flags, TR_LITE_2);
817 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
821 if (o_ptr->sval == SV_LITE_FEANOR)
823 add_flag(o_ptr->art_flags, TR_LITE_2);
831 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
832 * @param player_ptr プレーヤーへの参照ポインタ
833 * @param m_ptr モンスター保存先ポインタ
836 static void rd_monster_old(player_type *player_ptr, monster_type *m_ptr)
838 rd_s16b(&m_ptr->r_idx);
840 if (z_older_than(11, 0, 12))
841 m_ptr->ap_r_idx = m_ptr->r_idx;
843 rd_s16b(&m_ptr->ap_r_idx);
845 if (z_older_than(11, 0, 14))
847 monster_race *r_ptr = &r_info[m_ptr->r_idx];
849 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
850 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
851 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
854 rd_byte(&m_ptr->sub_align);
858 m_ptr->fy = (POSITION)tmp8u;
860 m_ptr->fx = (POSITION)tmp8u;
861 m_ptr->current_floor_ptr = player_ptr->current_floor_ptr;
867 m_ptr->maxhp = tmp16s;
869 if (z_older_than(11, 0, 5))
871 m_ptr->max_maxhp = m_ptr->maxhp;
876 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
878 if (h_older_than(2, 1, 2, 1))
880 m_ptr->dealt_damage = 0;
884 rd_s32b(&m_ptr->dealt_damage);
887 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
889 m_ptr->mspeed = tmp8u;
891 if (z_older_than(10, 4, 2))
894 m_ptr->energy_need = (s16b)tmp8u;
896 else rd_s16b(&m_ptr->energy_need);
898 if (z_older_than(11, 0, 13))
899 m_ptr->energy_need = 100 - m_ptr->energy_need;
901 if (z_older_than(10, 0, 7))
903 m_ptr->mtimed[MTIMED_FAST] = 0;
904 m_ptr->mtimed[MTIMED_SLOW] = 0;
909 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
911 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
915 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
917 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
919 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
921 if (z_older_than(10, 0, 10))
925 else if (z_older_than(10, 0, 11))
933 m_ptr->target_y = (POSITION)tmp16s;
935 m_ptr->target_x = (POSITION)tmp16s;
939 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
941 if (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6))
942 rd_u32b(&m_ptr->smart);
947 if (z_older_than(10, 4, 5))
957 if (z_older_than(10, 2, 2))
959 if (m_ptr->r_idx < 0)
961 m_ptr->r_idx = (0 - m_ptr->r_idx);
962 m_ptr->mflag2 |= MFLAG2_KAGE;
967 rd_byte(&m_ptr->mflag2);
970 if (z_older_than(11, 0, 12))
972 if (m_ptr->mflag2 & MFLAG2_KAGE)
973 m_ptr->ap_r_idx = MON_KAGE;
976 if (z_older_than(10, 1, 3))
983 rd_string(buf, sizeof(buf));
984 if (buf[0]) m_ptr->nickname = quark_add(buf);
992 * @brief モンスターを読み込む(現版) / Read a monster (New method)
993 * @param player_ptr プレーヤーへの参照ポインタ
994 * @param m_ptr モンスター保存先ポインタ
997 static void rd_monster(player_type *player_ptr, monster_type *m_ptr)
999 if (h_older_than(1, 5, 0, 0))
1001 rd_monster_old(player_ptr, m_ptr);
1007 rd_s16b(&m_ptr->r_idx);
1010 m_ptr->fy = (POSITION)tmp8u;
1012 m_ptr->fx = (POSITION)tmp8u;
1016 m_ptr->hp = (HIT_POINT)tmp16s;
1018 m_ptr->maxhp = (HIT_POINT)tmp16s;
1020 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1022 if (h_older_than(2, 1, 2, 1))
1024 m_ptr->dealt_damage = 0;
1028 rd_s32b(&m_ptr->dealt_damage);
1031 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1032 else m_ptr->ap_r_idx = m_ptr->r_idx;
1034 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1035 else m_ptr->sub_align = 0;
1037 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1038 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1041 m_ptr->mspeed = tmp8u;
1043 rd_s16b(&m_ptr->energy_need);
1045 if (flags & SAVE_MON_FAST)
1048 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1050 else m_ptr->mtimed[MTIMED_FAST] = 0;
1052 if (flags & SAVE_MON_SLOW)
1055 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1057 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1059 if (flags & SAVE_MON_STUNNED)
1062 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1064 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1066 if (flags & SAVE_MON_CONFUSED)
1069 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1071 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1073 if (flags & SAVE_MON_MONFEAR)
1076 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1078 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1080 if (flags & SAVE_MON_TARGET_Y)
1083 m_ptr->target_y = (POSITION)tmp16s;
1085 else m_ptr->target_y = 0;
1087 if (flags & SAVE_MON_TARGET_X)
1090 m_ptr->target_x = (POSITION)tmp16s;
1092 else m_ptr->target_x = 0;
1094 if (flags & SAVE_MON_INVULNER)
1097 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1099 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1101 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1102 else m_ptr->smart = 0;
1104 if (flags & SAVE_MON_EXP)
1108 m_ptr->exp = (EXP)tmp32u;
1110 else m_ptr->exp = 0;
1112 m_ptr->mflag = 0; /* Not saved */
1114 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1115 else m_ptr->mflag2 = 0;
1117 if (flags & SAVE_MON_NICKNAME)
1120 rd_string(buf, sizeof(buf));
1121 m_ptr->nickname = quark_add(buf);
1123 else m_ptr->nickname = 0;
1125 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1126 else m_ptr->parent_m_idx = 0;
1131 * Old monster bit flags of racial resistances
1133 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1134 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1135 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1136 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1137 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1138 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1139 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1140 #define RF3_RES_WATE 0x00800000 /* Resist water */
1141 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1142 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1143 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1144 #define RF3_RES_ALL 0x08000000 /* Resist all */
1146 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1148 if ((R_PTR)->r_flags3 & (RF3)) \
1150 (R_PTR)->r_flags3 &= ~(RF3); \
1151 (R_PTR)->r_flagsr |= (RFR); \
1155 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1157 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1159 (R_PTR)->r_flagsr |= (RFR); \
1163 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1164 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1165 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1166 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1167 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1168 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1169 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1170 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1171 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1172 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1175 * @brief モンスターの思い出を読み込む / Read the monster lore
1176 * @param r_idx 読み込み先モンスターID
1179 static void rd_lore(MONRACE_IDX r_idx)
1181 monster_race *r_ptr = &r_info[r_idx];
1185 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1188 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1191 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1193 if (h_older_than(1, 7, 0, 5))
1195 r_ptr->r_akills = r_ptr->r_pkills;
1200 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1204 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1206 rd_byte(&r_ptr->r_wake);
1207 rd_byte(&r_ptr->r_ignore);
1208 rd_byte(&r_ptr->r_xtra1);
1209 rd_byte(&r_ptr->r_xtra2);
1213 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1215 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1218 rd_byte(&r_ptr->r_cast_spell);
1220 rd_byte(&r_ptr->r_blows[0]);
1221 rd_byte(&r_ptr->r_blows[1]);
1222 rd_byte(&r_ptr->r_blows[2]);
1223 rd_byte(&r_ptr->r_blows[3]);
1225 rd_u32b(&r_ptr->r_flags1);
1226 rd_u32b(&r_ptr->r_flags2);
1227 rd_u32b(&r_ptr->r_flags3);
1228 rd_u32b(&r_ptr->r_flags4);
1229 rd_u32b(&r_ptr->r_flags5);
1230 rd_u32b(&r_ptr->r_flags6);
1231 if (h_older_than(1, 5, 0, 3))
1233 r_ptr->r_flagsr = 0L;
1234 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1235 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1236 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1237 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1238 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1239 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1240 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1241 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1242 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1243 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1244 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1245 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1247 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1248 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1249 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1250 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1251 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1252 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1253 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1254 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1255 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1257 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1258 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1259 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1263 rd_u32b(&r_ptr->r_flagsr);
1267 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1269 rd_s16b(&r_ptr->floor_id);
1272 r_ptr->r_flags1 &= r_ptr->flags1;
1273 r_ptr->r_flags2 &= r_ptr->flags2;
1274 r_ptr->r_flags3 &= r_ptr->flags3;
1275 r_ptr->r_flags4 &= r_ptr->flags4;
1276 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1277 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1278 r_ptr->r_flagsr &= r_ptr->flagsr;
1283 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1284 * @param player_ptr プレーヤーへの参照ポインタ
1285 * @param store_ptr 店舗の参照ポインタ
1286 * @param o_ptr アイテムオブジェクト参照ポインタ
1289 * In all cases, return the slot (or -1) where the object was placed
1291 * Note that this is a hacked up version of "inven_carry()".
1293 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1294 * known, the player may have to pick stuff up and drop it again.
1296 static void home_carry(player_type *player_ptr, store_type *store_ptr, object_type *o_ptr)
1298 for (int i = 0; i < store_ptr->stock_num; i++)
1301 j_ptr = &store_ptr->stock[i];
1302 if (!object_similar(j_ptr, o_ptr)) continue;
1304 object_absorb(j_ptr, o_ptr);
1308 if (store_ptr->stock_num >= STORE_INVEN_MAX * 10) return;
1310 s32b value = object_value(o_ptr);
1312 for (slot = 0; slot < store_ptr->stock_num; slot++)
1314 if (object_sort_comp(o_ptr, value, &store_ptr->stock[slot])) break;
1317 for (int i = store_ptr->stock_num; i > slot; i--)
1319 store_ptr->stock[i] = store_ptr->stock[i - 1];
1322 store_ptr->stock_num++;
1323 store_ptr->stock[slot] = *o_ptr;
1324 chg_virtue(player_ptr, V_SACRIFICE, -1);
1329 * @brief 店舗情報を読み込む / Read a store
1330 * @param player_ptr プレーヤーへの参照ポインタ
1331 * @param town_number 街ID
1332 * @param store_number 店舗ID
1335 static errr rd_store(player_type *player_ptr, int town_number, int store_number)
1337 store_type *store_ptr;
1339 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1341 store_ptr = &town_info[1].store[store_number];
1342 if (store_ptr->stock_num) sort = TRUE;
1346 store_ptr = &town_info[town_number].store[store_number];
1352 rd_s32b(&store_ptr->store_open);
1353 rd_s16b(&store_ptr->insult_cur);
1355 if (z_older_than(11, 0, 4))
1365 rd_s16b(&store_ptr->good_buy);
1366 rd_s16b(&store_ptr->bad_buy);
1368 rd_s32b(&store_ptr->last_visit);
1369 store_ptr->owner = own;
1371 for (int j = 0; j < num; j++)
1380 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);
1381 if (!is_valid_item) continue;
1385 home_carry(player_ptr, store_ptr, q_ptr);
1389 int k = store_ptr->stock_num++;
1390 object_copy(&store_ptr->stock[k], q_ptr);
1399 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1402 static void rd_randomizer(void)
1406 rd_u16b(&Rand_place);
1407 for (int i = 0; i < RAND_DEG; i++)
1409 rd_u32b(&Rand_state[i]);
1415 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1418 * Note that the normal options are now stored as a set of 256 bit flags,
1419 * plus a set of 256 bit masks to indicate which bit flags were defined
1420 * at the time the savefile was created. This will allow new options
1421 * to be added, and old options to be removed, at any time, without
1422 * hurting old savefiles.
1424 * The window options are stored in the same way, but note that each
1425 * window gets 32 options, and their order is fixed by certain defines.
1427 static void rd_options(void)
1438 if (h_older_than(1, 7, 0, 0))
1451 if (c & 0x0002) current_world_ptr->wizard = TRUE;
1453 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1454 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1455 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1456 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1457 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1458 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1459 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1460 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1461 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1462 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1464 rd_byte((byte *)&autosave_l);
1465 rd_byte((byte *)&autosave_t);
1466 rd_s16b(&autosave_freq);
1469 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1472 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1474 for (int n = 0; n < 8; n++)
1476 for (int i = 0; i < 32; i++)
1478 if (!(mask[n] & (1L << i))) continue;
1479 if (!(option_mask[n] & (1L << i))) continue;
1481 if (flag[n] & (1L << i))
1483 option_flag[n] |= (1L << i);
1487 option_flag[n] &= ~(1L << i);
1492 if (z_older_than(10, 4, 5))
1494 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1495 else option_flag[5] |= (0x00000001 << 4);
1496 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1497 else option_flag[2] |= (0x00000001 << 5);
1498 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1499 else option_flag[4] |= (0x00000001 << 5);
1500 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1501 else option_flag[5] |= (0x00000001 << 0);
1502 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1503 else option_flag[5] |= (0x00000001 << 12);
1504 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1505 else option_flag[1] |= (0x00000001 << 0);
1506 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1507 else option_flag[1] |= (0x00000001 << 18);
1508 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1509 else option_flag[1] |= (0x00000001 << 19);
1510 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1511 else option_flag[5] |= (0x00000001 << 3);
1514 extract_option_vars();
1515 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1517 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1519 for (int n = 0; n < 8; n++)
1521 for (int i = 0; i < 32; i++)
1523 if (!(mask[n] & (1L << i))) continue;
1524 if (!(window_mask[n] & (1L << i))) continue;
1526 if (flag[n] & (1L << i))
1528 window_flag[n] |= (1L << i);
1532 window_flag[n] &= ~(1L << i);
1540 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1543 * This is such a nasty hack it hurts.
1545 static void rd_ghost(void)
1548 rd_string(buf, sizeof(buf));
1554 * @brief クイックスタート情報を読み込む / Load quick start data
1557 static void load_quick_start(void)
1559 if (z_older_than(11, 0, 13))
1561 previous_char.quick_ok = FALSE;
1565 rd_byte(&previous_char.psex);
1568 previous_char.prace = (RACE_IDX)tmp8u;
1570 previous_char.pclass = (CLASS_IDX)tmp8u;
1572 previous_char.pseikaku = (CHARACTER_IDX)tmp8u;
1574 previous_char.realm1 = (REALM_IDX)tmp8u;
1576 previous_char.realm2 = (REALM_IDX)tmp8u;
1578 rd_s16b(&previous_char.age);
1579 rd_s16b(&previous_char.ht);
1580 rd_s16b(&previous_char.wt);
1581 rd_s16b(&previous_char.sc);
1582 rd_s32b(&previous_char.au);
1584 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1585 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1587 for (int i = 0; i < PY_MAX_LEVEL; i++)
1591 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1594 rd_s16b(&previous_char.chaos_patron);
1596 for (int i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1598 for (int i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1602 previous_char.quick_ok = (bool)tmp8u;
1607 * @brief その他の情報を読み込む / Read the "extra" information
1610 static void rd_extra(player_type *creature_ptr)
1612 rd_string(creature_ptr->name, sizeof(creature_ptr->name));
1613 rd_string(creature_ptr->died_from, sizeof(creature_ptr->died_from));
1614 if (!h_older_than(1, 7, 0, 1))
1617 rd_string(buf, sizeof buf);
1618 if (buf[0]) creature_ptr->last_message = string_make(buf);
1622 for (int i = 0; i < 4; i++)
1624 rd_string(creature_ptr->history[i], sizeof(creature_ptr->history[i]));
1629 creature_ptr->prace = (RACE_IDX)tmp8u;
1632 creature_ptr->pclass = (CLASS_IDX)tmp8u;
1635 creature_ptr->pseikaku = (CHARACTER_IDX)tmp8u;
1637 rd_byte(&creature_ptr->psex);
1639 creature_ptr->realm1 = (REALM_IDX)tmp8u;
1642 creature_ptr->realm2 = (REALM_IDX)tmp8u;
1645 if (z_older_than(10, 4, 4))
1647 if (creature_ptr->realm1 == 9) creature_ptr->realm1 = REALM_MUSIC;
1648 if (creature_ptr->realm2 == 9) creature_ptr->realm2 = REALM_MUSIC;
1649 if (creature_ptr->realm1 == 10) creature_ptr->realm1 = REALM_HISSATSU;
1650 if (creature_ptr->realm2 == 10) creature_ptr->realm2 = REALM_HISSATSU;
1654 creature_ptr->hitdie = tmp8u;
1655 rd_u16b(&creature_ptr->expfact);
1657 rd_s16b(&creature_ptr->age);
1658 rd_s16b(&creature_ptr->ht);
1659 rd_s16b(&creature_ptr->wt);
1661 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max[i]);
1662 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max_max[i]);
1663 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_cur[i]);
1666 rd_s32b(&creature_ptr->au);
1668 rd_s32b(&creature_ptr->max_exp);
1669 if (h_older_than(1, 5, 4, 1)) creature_ptr->max_max_exp = creature_ptr->max_exp;
1670 else rd_s32b(&creature_ptr->max_max_exp);
1671 rd_s32b(&creature_ptr->exp);
1673 if (h_older_than(1, 7, 0, 3))
1677 creature_ptr->exp_frac = (u32b)tmp16u;
1681 rd_u32b(&creature_ptr->exp_frac);
1684 rd_s16b(&creature_ptr->lev);
1686 for (int i = 0; i < 64; i++) rd_s16b(&creature_ptr->spell_exp[i]);
1687 if ((creature_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1689 for (int i = 0; i < 64; i++) creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1692 if (z_older_than(10, 3, 6))
1693 for (int i = 0; i < 5; i++) for (int j = 0; j < 60; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1695 for (int i = 0; i < 5; i++) for (int j = 0; j < 64; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1696 for (int i = 0; i < GINOU_MAX; i++) rd_s16b(&creature_ptr->skill_exp[i]);
1697 if (z_older_than(10, 4, 1))
1699 if (creature_ptr->pclass != CLASS_BEASTMASTER) creature_ptr->skill_exp[GINOU_RIDING] /= 2;
1700 creature_ptr->skill_exp[GINOU_RIDING] = MIN(creature_ptr->skill_exp[GINOU_RIDING], s_info[creature_ptr->pclass].s_max[GINOU_RIDING]);
1703 if (z_older_than(10, 3, 14))
1705 for (int i = 0; i < 108; i++) creature_ptr->magic_num1[i] = 0;
1706 for (int i = 0; i < 108; i++) creature_ptr->magic_num2[i] = 0;
1710 for (int i = 0; i < 108; i++) rd_s32b(&creature_ptr->magic_num1[i]);
1711 for (int i = 0; i < 108; i++) rd_byte(&creature_ptr->magic_num2[i]);
1712 if (h_older_than(1, 3, 0, 1))
1714 if (creature_ptr->pclass == CLASS_SMITH)
1716 creature_ptr->magic_num1[TR_ES_ATTACK] = creature_ptr->magic_num1[96];
1717 creature_ptr->magic_num1[96] = 0;
1718 creature_ptr->magic_num1[TR_ES_AC] = creature_ptr->magic_num1[97];
1719 creature_ptr->magic_num1[97] = 0;
1724 if (music_singing_any(creature_ptr)) creature_ptr->action = ACTION_SING;
1726 if (z_older_than(11, 0, 7))
1728 creature_ptr->start_race = creature_ptr->prace;
1729 creature_ptr->old_race1 = 0L;
1730 creature_ptr->old_race2 = 0L;
1731 creature_ptr->old_realm = 0;
1736 creature_ptr->start_race = (RACE_IDX)tmp8u;
1739 creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1741 creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1742 rd_s16b(&creature_ptr->old_realm);
1745 if (z_older_than(10, 0, 1))
1747 for (int i = 0; i < MAX_MANE; i++)
1749 creature_ptr->mane_spell[i] = -1;
1750 creature_ptr->mane_dam[i] = 0;
1752 creature_ptr->mane_num = 0;
1754 else if (z_older_than(10, 2, 3))
1757 for (int i = 0; i < OLD_MAX_MANE; i++)
1763 for (int i = 0; i < MAX_MANE; i++)
1765 creature_ptr->mane_spell[i] = -1;
1766 creature_ptr->mane_dam[i] = 0;
1770 creature_ptr->mane_num = 0;
1774 for (int i = 0; i < MAX_MANE; i++)
1778 creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1780 creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1783 rd_s16b(&creature_ptr->mane_num);
1786 if (z_older_than(10, 0, 3))
1788 determine_bounty_uniques(creature_ptr);
1790 for (int i = 0; i < MAX_BOUNTY; i++)
1792 /* Is this bounty unique already dead? */
1793 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1798 for (int i = 0; i < MAX_BOUNTY; i++)
1800 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1804 if (z_older_than(10, 0, 3))
1806 update_gambling_monsters(creature_ptr);
1810 for (int i = 0; i < 4; i++)
1812 rd_s16b(&battle_mon[i]);
1813 if (z_older_than(10, 3, 4))
1817 mon_odds[i] = tmp16s;
1819 else rd_u32b(&mon_odds[i]);
1823 rd_s16b(&creature_ptr->town_num);
1824 rd_s16b(&creature_ptr->arena_number);
1825 if (h_older_than(1, 5, 0, 1))
1827 if (creature_ptr->arena_number >= 99) creature_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1832 creature_ptr->current_floor_ptr->inside_arena = (bool)tmp16s;
1833 rd_s16b(&creature_ptr->current_floor_ptr->inside_quest);
1834 if (z_older_than(10, 3, 5)) creature_ptr->phase_out = FALSE;
1838 creature_ptr->phase_out = (bool)tmp16s;
1841 rd_byte(&creature_ptr->exit_bldg);
1845 creature_ptr->oldpx = (POSITION)tmp16s;
1848 creature_ptr->oldpy = (POSITION)tmp16s;
1849 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; }
1852 for (int i = 0; i < tmp16s; i++)
1858 if (h_older_than(1, 7, 0, 3))
1861 creature_ptr->mhp = tmp16s;
1864 creature_ptr->chp = tmp16s;
1868 creature_ptr->chp_frac = (u32b)tmp16u;
1872 rd_s32b(&creature_ptr->mhp);
1873 rd_s32b(&creature_ptr->chp);
1874 rd_u32b(&creature_ptr->chp_frac);
1877 if (h_older_than(1, 7, 0, 3))
1880 creature_ptr->msp = tmp16s;
1883 creature_ptr->csp = tmp16s;
1887 creature_ptr->csp_frac = (u32b)tmp16u;
1891 rd_s32b(&creature_ptr->msp);
1892 rd_s32b(&creature_ptr->csp);
1893 rd_u32b(&creature_ptr->csp_frac);
1896 rd_s16b(&creature_ptr->max_plv);
1897 if (z_older_than(10, 3, 8))
1900 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1904 byte max = (byte)current_world_ptr->max_d_idx;
1908 for (int i = 0; i < max; i++)
1911 max_dlv[i] = tmp16s;
1912 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1916 if (creature_ptr->max_plv < creature_ptr->lev) creature_ptr->max_plv = creature_ptr->lev;
1919 rd_s16b(&creature_ptr->sc);
1920 rd_s16b(&creature_ptr->concent);
1922 strip_bytes(2); /* Old "rest" */
1923 rd_s16b(&creature_ptr->blind);
1924 rd_s16b(&creature_ptr->paralyzed);
1925 rd_s16b(&creature_ptr->confused);
1926 rd_s16b(&creature_ptr->food);
1927 strip_bytes(4); /* Old "food_digested" / "protection" */
1929 rd_s16b(&creature_ptr->energy_need);
1930 if (z_older_than(11, 0, 13))
1931 creature_ptr->energy_need = 100 - creature_ptr->energy_need;
1932 if (h_older_than(2, 1, 2, 0))
1933 creature_ptr->enchant_energy_need = 0;
1935 rd_s16b(&creature_ptr->enchant_energy_need);
1937 rd_s16b(&creature_ptr->fast);
1938 rd_s16b(&creature_ptr->slow);
1939 rd_s16b(&creature_ptr->afraid);
1940 rd_s16b(&creature_ptr->cut);
1941 rd_s16b(&creature_ptr->stun);
1942 rd_s16b(&creature_ptr->poisoned);
1943 rd_s16b(&creature_ptr->image);
1944 rd_s16b(&creature_ptr->protevil);
1945 rd_s16b(&creature_ptr->invuln);
1946 if (z_older_than(10, 0, 0))
1947 creature_ptr->ult_res = 0;
1949 rd_s16b(&creature_ptr->ult_res);
1950 rd_s16b(&creature_ptr->hero);
1951 rd_s16b(&creature_ptr->shero);
1952 rd_s16b(&creature_ptr->shield);
1953 rd_s16b(&creature_ptr->blessed);
1954 rd_s16b(&creature_ptr->tim_invis);
1955 rd_s16b(&creature_ptr->word_recall);
1956 if (z_older_than(10, 3, 8))
1957 creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
1961 creature_ptr->recall_dungeon = (byte)tmp16s;
1964 if (h_older_than(1, 5, 0, 0))
1965 creature_ptr->alter_reality = 0;
1967 rd_s16b(&creature_ptr->alter_reality);
1969 rd_s16b(&creature_ptr->see_infra);
1970 rd_s16b(&creature_ptr->tim_infra);
1971 rd_s16b(&creature_ptr->oppose_fire);
1972 rd_s16b(&creature_ptr->oppose_cold);
1973 rd_s16b(&creature_ptr->oppose_acid);
1974 rd_s16b(&creature_ptr->oppose_elec);
1975 rd_s16b(&creature_ptr->oppose_pois);
1976 if (z_older_than(10, 0, 2)) creature_ptr->tsuyoshi = 0;
1977 else rd_s16b(&creature_ptr->tsuyoshi);
1979 /* Old savefiles do not have the following fields... */
1980 if ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->z_patch == 6))
1982 creature_ptr->tim_esp = 0;
1983 creature_ptr->wraith_form = 0;
1984 creature_ptr->resist_magic = 0;
1985 creature_ptr->tim_regen = 0;
1986 creature_ptr->kabenuke = 0;
1987 creature_ptr->tim_stealth = 0;
1988 creature_ptr->tim_levitation = 0;
1989 creature_ptr->tim_sh_touki = 0;
1990 creature_ptr->lightspeed = 0;
1991 creature_ptr->tsubureru = 0;
1992 creature_ptr->tim_res_nether = 0;
1993 creature_ptr->tim_res_time = 0;
1994 creature_ptr->mimic_form = 0;
1995 creature_ptr->tim_mimic = 0;
1996 creature_ptr->tim_sh_fire = 0;
1997 creature_ptr->tim_reflect = 0;
1998 creature_ptr->multishadow = 0;
1999 creature_ptr->dustrobe = 0;
2000 creature_ptr->chaos_patron = ((creature_ptr->age + creature_ptr->sc) % MAX_PATRON);
2001 creature_ptr->muta1 = 0;
2002 creature_ptr->muta2 = 0;
2003 creature_ptr->muta3 = 0;
2004 get_virtues(creature_ptr);
2008 rd_s16b(&creature_ptr->tim_esp);
2009 rd_s16b(&creature_ptr->wraith_form);
2010 rd_s16b(&creature_ptr->resist_magic);
2011 rd_s16b(&creature_ptr->tim_regen);
2012 rd_s16b(&creature_ptr->kabenuke);
2013 rd_s16b(&creature_ptr->tim_stealth);
2014 rd_s16b(&creature_ptr->tim_levitation);
2015 rd_s16b(&creature_ptr->tim_sh_touki);
2016 rd_s16b(&creature_ptr->lightspeed);
2017 rd_s16b(&creature_ptr->tsubureru);
2018 if (z_older_than(10, 4, 7))
2019 creature_ptr->magicdef = 0;
2021 rd_s16b(&creature_ptr->magicdef);
2022 rd_s16b(&creature_ptr->tim_res_nether);
2023 if (z_older_than(10, 4, 11))
2025 creature_ptr->tim_res_time = 0;
2026 creature_ptr->mimic_form = 0;
2027 creature_ptr->tim_mimic = 0;
2028 creature_ptr->tim_sh_fire = 0;
2032 rd_s16b(&creature_ptr->tim_res_time);
2034 creature_ptr->mimic_form = (IDX)tmp8u;
2035 rd_s16b(&creature_ptr->tim_mimic);
2036 rd_s16b(&creature_ptr->tim_sh_fire);
2039 if (z_older_than(11, 0, 99))
2041 creature_ptr->tim_sh_holy = 0;
2042 creature_ptr->tim_eyeeye = 0;
2046 rd_s16b(&creature_ptr->tim_sh_holy);
2047 rd_s16b(&creature_ptr->tim_eyeeye);
2050 if (z_older_than(11, 0, 3)) {
2051 creature_ptr->tim_reflect = 0;
2052 creature_ptr->multishadow = 0;
2053 creature_ptr->dustrobe = 0;
2057 rd_s16b(&creature_ptr->tim_reflect);
2058 rd_s16b(&creature_ptr->multishadow);
2059 rd_s16b(&creature_ptr->dustrobe);
2062 rd_s16b(&creature_ptr->chaos_patron);
2063 rd_u32b(&creature_ptr->muta1);
2064 rd_u32b(&creature_ptr->muta2);
2065 rd_u32b(&creature_ptr->muta3);
2067 for (int i = 0; i < 8; i++)
2068 rd_s16b(&creature_ptr->virtues[i]);
2069 for (int i = 0; i < 8; i++)
2070 rd_s16b(&creature_ptr->vir_types[i]);
2073 creature_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod(creature_ptr);
2074 if (z_older_than(10, 0, 9))
2077 if (tmp8u) creature_ptr->special_attack = ATTACK_CONFUSE;
2078 creature_ptr->ele_attack = 0;
2082 rd_s16b(&creature_ptr->ele_attack);
2083 rd_u32b(&creature_ptr->special_attack);
2086 if (creature_ptr->special_attack & KAMAE_MASK) creature_ptr->action = ACTION_KAMAE;
2087 else if (creature_ptr->special_attack & KATA_MASK) creature_ptr->action = ACTION_KATA;
2088 if (z_older_than(10, 0, 12))
2090 creature_ptr->ele_immune = 0;
2091 creature_ptr->special_defense = 0;
2095 rd_s16b(&creature_ptr->ele_immune);
2096 rd_u32b(&creature_ptr->special_defense);
2099 rd_byte(&creature_ptr->knowledge);
2101 creature_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2105 creature_ptr->action = (ACTION_IDX)tmp8u;
2106 if (!z_older_than(10, 4, 3))
2109 if (tmp8u) creature_ptr->action = ACTION_LEARN;
2112 rd_byte((byte *)&preserve_mode);
2113 rd_byte((byte *)&creature_ptr->wait_report_score);
2115 for (int i = 0; i < 48; i++) rd_byte(&tmp8u);
2118 rd_u32b(¤t_world_ptr->seed_flavor);
2119 rd_u32b(¤t_world_ptr->seed_town);
2121 rd_u16b(&creature_ptr->panic_save);
2122 rd_u16b(¤t_world_ptr->total_winner);
2123 rd_u16b(¤t_world_ptr->noscore);
2126 creature_ptr->is_dead = tmp8u;
2128 rd_byte(&creature_ptr->feeling);
2130 switch (creature_ptr->start_race)
2136 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2139 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2143 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2144 rd_s32b(&creature_ptr->current_floor_ptr->generated_turn);
2145 if (h_older_than(1, 7, 0, 4))
2147 creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
2151 rd_s32b(&creature_ptr->feeling_turn);
2154 rd_s32b(¤t_world_ptr->game_turn);
2155 if (z_older_than(10, 3, 12))
2157 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2159 else rd_s32b(¤t_world_ptr->dungeon_turn);
2161 if (z_older_than(11, 0, 13))
2163 creature_ptr->current_floor_ptr->generated_turn /= 2;
2164 creature_ptr->feeling_turn /= 2;
2165 current_world_ptr->game_turn /= 2;
2166 current_world_ptr->dungeon_turn /= 2;
2169 if (z_older_than(10, 3, 13))
2171 current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
2173 else rd_s32b(¤t_world_ptr->arena_start_turn);
2175 if (z_older_than(10, 0, 3))
2177 determine_daily_bounty(creature_ptr, TRUE);
2181 rd_s16b(&today_mon);
2182 rd_s16b(&creature_ptr->today_mon);
2185 if (z_older_than(10, 0, 7))
2187 creature_ptr->riding = 0;
2191 rd_s16b(&creature_ptr->riding);
2194 if (h_older_than(1, 5, 0, 0))
2196 creature_ptr->floor_id = 0;
2200 rd_s16b(&creature_ptr->floor_id);
2203 if (h_older_than(1, 5, 0, 2))
2210 for (int i = 0; i < tmp16s; i++)
2212 monster_type dummy_mon;
2213 rd_monster(creature_ptr, &dummy_mon);
2217 if (z_older_than(10, 1, 2))
2219 current_world_ptr->play_time = 0;
2223 rd_u32b(¤t_world_ptr->play_time);
2226 if (z_older_than(10, 3, 9))
2228 creature_ptr->visit = 1L;
2230 else if (z_older_than(10, 3, 10))
2234 creature_ptr->visit = 1L;
2240 creature_ptr->visit = (BIT_FLAGS)tmp32s;
2243 if (!z_older_than(11, 0, 5))
2245 rd_u32b(&creature_ptr->count);
2251 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2252 * @param player_ptr プレーヤーへの参照ポインタ
2255 * Note that the inventory changed in Angband 2.7.4. Two extra
2256 * pack slots were added and the equipment was rearranged. Note
2257 * that these two features combine when parsing old save-files, in
2258 * which items from the old "aux" slot are "carried", perhaps into
2259 * one of the two new "inventory" slots.
2261 * Note that the inventory is "re-sorted" later by "dungeon()".
2263 static errr rd_inventory(player_type *player_ptr)
2265 player_ptr->total_weight = 0;
2266 player_ptr->inven_cnt = 0;
2267 player_ptr->equip_cnt = 0;
2269 if (player_ptr->inventory_list != NULL) C_WIPE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2270 C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2278 if (n == 0xFFFF) break;
2285 if (!q_ptr->k_idx) return (53);
2287 if (n >= INVEN_RARM)
2289 q_ptr->marked |= OM_TOUCHED;
2290 object_copy(&player_ptr->inventory_list[n], q_ptr);
2291 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2292 player_ptr->equip_cnt++;
2296 if (player_ptr->inven_cnt == INVEN_PACK)
2298 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
2303 q_ptr->marked |= OM_TOUCHED;
2304 object_copy(&player_ptr->inventory_list[n], q_ptr);
2305 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2306 player_ptr->inven_cnt++;
2314 * @brief メッセージログを読み込む / Read the saved messages
2317 static void rd_messages(void)
2319 if (h_older_than(2, 2, 0, 75))
2324 message_max = (int)num;
2326 for (int i = 0; i < message_max; i++)
2329 rd_string(buf, sizeof(buf));
2337 message_max = (int)num;
2339 for (int i = 0; i < message_max; i++)
2342 rd_string(buf, sizeof(buf));
2349 * @brief メッセージログを読み込む / Read the dungeon (old method)
2350 * @param creature_ptr プレーヤーへの参照ポインタ
2353 * The monsters/objects must be loaded in the same order
2354 * that they were stored, since the actual indexes matter.
2356 static errr rd_dungeon_old(player_type *creature_ptr)
2360 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2361 floor_ptr->dun_level = (DEPTH)tmp16s;
2362 if (z_older_than(10, 3, 8)) creature_ptr->dungeon_idx = DUNGEON_ANGBAND;
2367 creature_ptr->dungeon_idx = (IDX)tmp8u;
2370 floor_ptr->base_level = floor_ptr->dun_level;
2372 floor_ptr->base_level = (DEPTH)tmp16s;
2375 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2377 creature_ptr->y = (POSITION)tmp16s;
2379 creature_ptr->x = (POSITION)tmp16s;
2380 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) { creature_ptr->y = 33; creature_ptr->x = 131; }
2382 floor_ptr->height = (POSITION)tmp16s;
2384 floor_ptr->width = (POSITION)tmp16s;
2385 rd_s16b(&tmp16s); /* max_panel_rows */
2386 rd_s16b(&tmp16s); /* max_panel_cols */
2388 int ymax = floor_ptr->height;
2389 int xmax = floor_ptr->width;
2391 for (int x = 0, y = 0; y < ymax; )
2396 if (z_older_than(10, 3, 6))
2405 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2408 for (int i = count; i > 0; i--)
2411 g_ptr = &floor_ptr->grid_array[y][x];
2416 if (++y >= ymax) break;
2421 for (int x = 0, y = 0; y < ymax; )
2427 for (int i = count; i > 0; i--)
2430 g_ptr = &floor_ptr->grid_array[y][x];
2431 g_ptr->feat = (s16b)tmp8u;
2435 if (++y >= ymax) break;
2440 for (int x = 0, y = 0; y < ymax; )
2446 for (int i = count; i > 0; i--)
2449 g_ptr = &floor_ptr->grid_array[y][x];
2450 g_ptr->mimic = (s16b)tmp8u;
2454 if (++y >= ymax) break;
2459 for (int x = 0, y = 0; y < ymax; )
2464 for (int i = count; i > 0; i--)
2467 g_ptr = &floor_ptr->grid_array[y][x];
2468 g_ptr->special = tmp16s;
2472 if (++y >= ymax) break;
2477 if (z_older_than(11, 0, 99))
2479 for (int y = 0; y < ymax; y++)
2481 for (int x = 0; x < xmax; x++)
2483 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2488 if (h_older_than(1, 1, 1, 0))
2490 for (int y = 0; y < ymax; y++)
2492 for (int x = 0; x < xmax; x++)
2495 g_ptr = &floor_ptr->grid_array[y][x];
2498 if (g_ptr->feat == OLD_FEAT_INVIS)
2500 g_ptr->feat = feat_floor;
2501 g_ptr->info |= CAVE_TRAP;
2504 /* Older than 1.1.1 */
2505 if (g_ptr->feat == OLD_FEAT_MIRROR)
2507 g_ptr->feat = feat_floor;
2508 g_ptr->info |= CAVE_OBJECT;
2514 if (h_older_than(1, 3, 1, 0))
2516 for (int y = 0; y < ymax; y++)
2518 for (int x = 0; x < xmax; x++)
2521 g_ptr = &floor_ptr->grid_array[y][x];
2523 /* Old CAVE_IN_MIRROR flag */
2524 if (g_ptr->info & CAVE_OBJECT)
2526 g_ptr->mimic = feat_mirror;
2528 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2529 (g_ptr->feat == OLD_FEAT_GLYPH))
2531 g_ptr->info |= CAVE_OBJECT;
2532 g_ptr->mimic = g_ptr->feat;
2533 g_ptr->feat = feat_floor;
2535 else if (g_ptr->info & CAVE_TRAP)
2537 g_ptr->info &= ~CAVE_TRAP;
2538 g_ptr->mimic = g_ptr->feat;
2539 g_ptr->feat = choose_random_trap(creature_ptr);
2541 else if (g_ptr->feat == OLD_FEAT_INVIS)
2543 g_ptr->mimic = feat_floor;
2544 g_ptr->feat = feat_trap_open;
2550 /* Quest 18 was removed */
2551 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2553 for (int y = 0; y < ymax; y++)
2555 for (int x = 0; x < xmax; x++)
2558 g_ptr = &floor_ptr->grid_array[y][x];
2560 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2562 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2564 g_ptr->feat = feat_tree;
2567 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2569 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2572 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2573 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2575 g_ptr->feat = feat_up_stair;
2584 if (limit > current_world_ptr->max_o_idx)
2586 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2590 for (int i = 1; i < limit; i++)
2592 OBJECT_IDX o_idx = o_pop(floor_ptr);
2595 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2600 o_ptr = &floor_ptr->o_list[o_idx];
2602 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2604 monster_type *m_ptr;
2605 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2606 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2607 m_ptr->hold_o_idx = o_idx;
2612 g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2613 o_ptr->next_o_idx = g_ptr->o_idx;
2614 g_ptr->o_idx = o_idx;
2618 if (limit > current_world_ptr->max_m_idx)
2620 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2624 for (int i = 1; i < limit; i++)
2627 monster_type *m_ptr;
2628 m_idx = m_pop(creature_ptr);
2631 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2635 m_ptr = &floor_ptr->m_list[m_idx];
2636 rd_monster(creature_ptr, m_ptr);
2638 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2639 g_ptr->m_idx = m_idx;
2640 real_r_ptr(m_ptr)->cur_num++;
2643 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena)
2644 current_world_ptr->character_dungeon = FALSE;
2646 current_world_ptr->character_dungeon = TRUE;
2653 * @brief 保存されたフロアを読み込む / Read the saved floor
2654 * @param player_ptr プレーヤーへの参照ポインタ
2655 * @param sf_ptr 最後に保存されたフロアへの参照ポインタ
2656 * @return info読み込みエラーコード
2658 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2661 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2662 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2664 * The monsters/objects must be loaded in the same order
2665 * that they were stored, since the actual indexes matter.
2667 static errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
2669 grid_template_type *templates;
2670 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2671 clear_cave(player_ptr);
2672 player_ptr->x = player_ptr->y = 0;
2678 floor_ptr->dun_level = (DEPTH)tmp16s;
2679 floor_ptr->base_level = floor_ptr->dun_level;
2685 if (tmp16s != sf_ptr->floor_id) return 171;
2689 if (tmp8u != sf_ptr->savefile_id) return 171;
2692 if (tmp16s != sf_ptr->dun_level) return 171;
2693 floor_ptr->dun_level = sf_ptr->dun_level;
2697 if (tmp32s != sf_ptr->last_visit) return 171;
2701 if (tmp32u != sf_ptr->visit_mark) return 171;
2704 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2707 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2712 floor_ptr->base_level = (DEPTH)tmp16s;
2714 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2718 player_ptr->y = (POSITION)tmp16u;
2721 player_ptr->x = (POSITION)tmp16u;
2724 floor_ptr->height = (POSITION)tmp16s;
2726 floor_ptr->width = (POSITION)tmp16s;
2728 rd_byte(&player_ptr->feeling);
2732 C_MAKE(templates, limit, grid_template_type);
2734 for (int i = 0; i < limit; i++)
2736 grid_template_type *ct_ptr = &templates[i];
2738 ct_ptr->info = (BIT_FLAGS)tmp16u;
2739 if (h_older_than(1, 7, 0, 2))
2743 ct_ptr->feat = (s16b)tmp8u;
2745 ct_ptr->mimic = (s16b)tmp8u;
2749 rd_s16b(&ct_ptr->feat);
2750 rd_s16b(&ct_ptr->mimic);
2753 rd_s16b(&ct_ptr->special);
2756 POSITION ymax = floor_ptr->height;
2757 POSITION xmax = floor_ptr->width;
2758 for (POSITION x = 0, y = 0; y < ymax; )
2769 } while (tmp8u == MAX_UCHAR);
2771 for (int i = count; i > 0; i--)
2773 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2774 g_ptr->info = templates[id].info;
2775 g_ptr->feat = templates[id].feat;
2776 g_ptr->mimic = templates[id].mimic;
2777 g_ptr->special = templates[id].special;
2782 if (++y >= ymax) break;
2787 /* Quest 18 was removed */
2788 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2790 for (POSITION y = 0; y < ymax; y++)
2792 for (POSITION x = 0; x < xmax; x++)
2794 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2796 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2798 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2800 g_ptr->feat = feat_tree;
2803 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2805 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2808 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2809 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2811 g_ptr->feat = feat_up_stair;
2818 C_KILL(templates, limit, grid_template_type);
2820 if (limit > current_world_ptr->max_o_idx) return 151;
2821 for (int i = 1; i < limit; i++)
2825 o_idx = o_pop(floor_ptr);
2826 if (i != o_idx) return 152;
2828 o_ptr = &floor_ptr->o_list[o_idx];
2831 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2833 monster_type *m_ptr;
2834 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2835 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2836 m_ptr->hold_o_idx = o_idx;
2840 grid_type *g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2841 o_ptr->next_o_idx = g_ptr->o_idx;
2842 g_ptr->o_idx = o_idx;
2847 if (limit > current_world_ptr->max_m_idx) return 161;
2849 for (int i = 1; i < limit; i++)
2853 monster_type *m_ptr;
2854 m_idx = m_pop(player_ptr);
2855 if (i != m_idx) return 162;
2857 m_ptr = &floor_ptr->m_list[m_idx];
2858 rd_monster(player_ptr, m_ptr);
2859 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2860 g_ptr->m_idx = m_idx;
2861 real_r_ptr(m_ptr)->cur_num++;
2869 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
2870 * @param player_ptr プレーヤーへの参照ポインタ
2873 * The monsters/objects must be loaded in the same order
2874 * that they were stored, since the actual indexes matter.
2876 static errr rd_dungeon(player_type *player_ptr)
2878 init_saved_floors(player_ptr, FALSE);
2880 if (h_older_than(1, 5, 0, 0))
2882 err = rd_dungeon_old(player_ptr);
2883 if (player_ptr->dungeon_idx)
2885 player_ptr->floor_id = get_new_floor_id(player_ptr);
2886 get_sf_ptr(player_ptr->floor_id)->dun_level = player_ptr->current_floor_ptr->dun_level;
2892 rd_s16b(&max_floor_id);
2895 player_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
2900 err = rd_saved_floor(player_ptr, NULL);
2904 for (int i = 0; i < num; i++)
2906 saved_floor_type *sf_ptr = &saved_floors[i];
2908 rd_s16b(&sf_ptr->floor_id);
2910 sf_ptr->savefile_id = (s16b)tmp8u;
2914 sf_ptr->dun_level = (DEPTH)tmp16s;
2916 rd_s32b(&sf_ptr->last_visit);
2917 rd_u32b(&sf_ptr->visit_mark);
2918 rd_s16b(&sf_ptr->upper_floor_id);
2919 rd_s16b(&sf_ptr->lower_floor_id);
2922 for (int i = 0; i < num; i++)
2924 saved_floor_type *sf_ptr = &saved_floors[i];
2925 if (!sf_ptr->floor_id) continue;
2927 if (tmp8u) continue;
2929 err = rd_saved_floor(player_ptr, sf_ptr);
2932 if (!save_floor(player_ptr, sf_ptr, SLF_SECOND)) err = 182;
2939 if (!load_floor(player_ptr, get_sf_ptr(player_ptr->floor_id), SLF_SECOND)) err = 183;
2946 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
2950 note(_("アイテム配置エラー", "Object allocation error"));
2954 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
2958 note(_("モンスター配置エラー", "Monster allocation error"));
2962 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
2966 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporary files!"));
2970 note(_("Error 183", "Error 183"));
2974 current_world_ptr->character_dungeon = TRUE;
2980 * @brief ロード処理全体のサブ関数 / Actually read the savefile
2983 static errr rd_savefile_new_aux(player_type *creature_ptr)
2985 u32b n_x_check, n_v_check;
2986 u32b o_x_check, o_v_check;
2989 xor_byte = current_world_ptr->sf_extra;
2993 /* Old savefile will be version 0.0.0.3 */
2994 rd_byte(¤t_world_ptr->h_ver_extra);
2995 rd_byte(¤t_world_ptr->h_ver_patch);
2996 rd_byte(¤t_world_ptr->h_ver_minor);
2997 rd_byte(¤t_world_ptr->h_ver_major);
3000 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3001 (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));
3003 rd_u32b(¤t_world_ptr->sf_system);
3004 rd_u32b(¤t_world_ptr->sf_when);
3005 rd_u16b(¤t_world_ptr->sf_lives);
3006 rd_u16b(¤t_world_ptr->sf_saves);
3016 rd_byte(&kanji_code);
3019 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3022 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3025 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3027 for (int i = 0; i < max_r_idx; i++)
3029 monster_race *r_ptr = &r_info[i];
3030 r_ptr->max_num = 100;
3032 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3033 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3037 if (tmp16u > max_r_idx)
3039 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3043 for (int i = 0; i < tmp16u; i++)
3045 rd_lore((MONRACE_IDX)i);
3048 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3051 if (tmp16u > max_k_idx)
3053 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3057 for (int i = 0; i < tmp16u; i++)
3059 object_kind *k_ptr = &k_info[i];
3061 k_ptr->aware = (tmp8u & 0x01) ? TRUE : FALSE;
3062 k_ptr->tried = (tmp8u & 0x02) ? TRUE : FALSE;
3064 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3066 /* 2.1.3 or newer version */
3068 u16b max_towns_load;
3069 u16b max_quests_load;
3070 byte max_rquests_load;
3071 s16b old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
3073 rd_u16b(&max_towns_load);
3074 if (max_towns_load > max_towns)
3076 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3080 rd_u16b(&max_quests_load);
3081 if (z_older_than(11, 0, 7))
3083 max_rquests_load = 10;
3087 rd_byte(&max_rquests_load);
3090 if (max_quests_load > max_q_idx)
3092 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3096 for (int i = 0; i < max_quests_load; i++)
3105 quest_type* const q_ptr = &quest[i];
3107 rd_s16b(&q_ptr->status);
3110 q_ptr->level = tmp16s;
3112 if (z_older_than(11, 0, 6))
3119 q_ptr->complev = tmp8u;
3121 if (h_older_than(2, 1, 2, 2))
3123 q_ptr->comptime = 0;
3127 rd_u32b(&q_ptr->comptime);
3130 bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
3131 is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
3132 is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
3133 if (!is_quest_running) continue;
3136 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3138 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3139 rd_s16b(&q_ptr->type);
3141 rd_s16b(&q_ptr->r_idx);
3142 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3144 determine_random_questor(creature_ptr, &quest[i]);
3147 rd_s16b(&q_ptr->k_idx);
3149 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3152 q_ptr->flags = tmp8u;
3154 if (z_older_than(10, 3, 11))
3156 if (q_ptr->flags & QUEST_FLAG_PRESET)
3162 init_flags = INIT_ASSIGN;
3163 creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)i;
3165 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
3166 creature_ptr->current_floor_ptr->inside_quest = old_inside_quest;
3172 q_ptr->dungeon = tmp8u;
3175 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3176 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3177 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3180 /* Quest 18 was removed */
3181 if (h_older_than(1, 7, 0, 6))
3183 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3184 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3187 rd_s32b(&creature_ptr->wilderness_x);
3188 rd_s32b(&creature_ptr->wilderness_y);
3189 if (z_older_than(10, 3, 13))
3191 creature_ptr->wilderness_x = 5;
3192 creature_ptr->wilderness_y = 48;
3195 if (z_older_than(10, 3, 7)) creature_ptr->wild_mode = FALSE;
3196 else rd_byte((byte *)&creature_ptr->wild_mode);
3197 if (z_older_than(10, 3, 7)) creature_ptr->ambush_flag = FALSE;
3198 else rd_byte((byte *)&creature_ptr->ambush_flag);
3202 rd_s32b(&wild_x_size);
3203 rd_s32b(&wild_y_size);
3205 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3207 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3211 for (int i = 0; i < wild_x_size; i++)
3213 for (int j = 0; j < wild_y_size; j++)
3215 rd_u32b(&wilderness[j][i].seed);
3220 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3223 if (tmp16u > max_a_idx)
3225 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3229 for (int i = 0; i < tmp16u; i++)
3231 artifact_type *a_ptr = &a_info[i];
3234 a_ptr->cur_num = tmp8u;
3236 if (h_older_than(1, 5, 0, 0))
3238 a_ptr->floor_id = 0;
3246 rd_s16b(&a_ptr->floor_id);
3250 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3252 rd_extra(creature_ptr);
3253 if (creature_ptr->energy_need < -999) creature_ptr->timewalk = TRUE;
3255 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3258 if (tmp16u > PY_MAX_LEVEL)
3260 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3264 for (int i = 0; i < tmp16u; i++)
3268 creature_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3271 sp_ptr = &sex_info[creature_ptr->psex];
3272 rp_ptr = &race_info[creature_ptr->prace];
3273 cp_ptr = &class_info[creature_ptr->pclass];
3274 ap_ptr = &seikaku_info[creature_ptr->pseikaku];
3276 if (z_older_than(10, 2, 2) && (creature_ptr->pclass == CLASS_BEASTMASTER) && !creature_ptr->is_dead)
3278 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3279 roll_hitdice(creature_ptr, 0L);
3282 if (z_older_than(10, 3, 2) && (creature_ptr->pclass == CLASS_ARCHER) && !creature_ptr->is_dead)
3284 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3285 roll_hitdice(creature_ptr, 0L);
3288 if (z_older_than(10, 2, 6) && (creature_ptr->pclass == CLASS_SORCERER) && !creature_ptr->is_dead)
3290 creature_ptr->hitdie = rp_ptr->r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3291 roll_hitdice(creature_ptr, 0L);
3294 if (z_older_than(10, 4, 7) && (creature_ptr->pclass == CLASS_BLUE_MAGE) && !creature_ptr->is_dead)
3296 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3297 roll_hitdice(creature_ptr, 0L);
3300 mp_ptr = &m_info[creature_ptr->pclass];
3302 rd_u32b(&creature_ptr->spell_learned1);
3303 rd_u32b(&creature_ptr->spell_learned2);
3304 rd_u32b(&creature_ptr->spell_worked1);
3305 rd_u32b(&creature_ptr->spell_worked2);
3306 rd_u32b(&creature_ptr->spell_forgotten1);
3307 rd_u32b(&creature_ptr->spell_forgotten2);
3309 if (z_older_than(10, 0, 5))
3311 creature_ptr->learned_spells = 0;
3312 for (int i = 0; i < 64; i++)
3315 (creature_ptr->spell_learned1 & (1L << i)) :
3316 (creature_ptr->spell_learned2 & (1L << (i - 32))))
3318 creature_ptr->learned_spells++;
3322 else rd_s16b(&creature_ptr->learned_spells);
3324 if (z_older_than(10, 0, 6))
3326 creature_ptr->add_spells = 0;
3328 else rd_s16b(&creature_ptr->add_spells);
3330 if (creature_ptr->pclass == CLASS_MINDCRAFTER) creature_ptr->add_spells = 0;
3332 for (int i = 0; i < 64; i++)
3335 creature_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3338 if (rd_inventory(creature_ptr))
3340 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3345 int town_count = tmp16u;
3348 for (int i = 1; i < town_count; i++)
3350 for (int j = 0; j < tmp16u; j++)
3352 if (rd_store(creature_ptr, i, j)) return (22);
3356 rd_s16b(&creature_ptr->pet_follow_distance);
3357 if (z_older_than(10, 4, 10))
3359 creature_ptr->pet_extra_flags = 0;
3361 if (tmp8u) creature_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3363 if (tmp8u) creature_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3365 if (z_older_than(10, 0, 4)) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3369 if (tmp8u) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3372 if (z_older_than(10, 0, 7)) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3376 if (tmp8u) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3379 if (z_older_than(10, 0, 8)) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3383 if (tmp8u) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3386 if (!z_older_than(10, 0, 8))
3389 if (tmp8u) creature_ptr->pet_extra_flags |= PF_BALL_SPELL;
3394 rd_s16b(&creature_ptr->pet_extra_flags);
3397 if (!z_older_than(11, 0, 9))
3399 char buf[SCREEN_BUF_MAX_SIZE];
3400 rd_string(buf, sizeof(buf));
3401 if (buf[0]) screen_dump = string_make(buf);
3404 if (creature_ptr->is_dead)
3406 for (int i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3408 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3412 if (!creature_ptr->is_dead)
3414 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3415 if (rd_dungeon(creature_ptr))
3417 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3426 strip_bytes(tmp32s);
3430 /* Quest 18 was removed */
3431 if (h_older_than(1, 7, 0, 6))
3433 if (creature_ptr->current_floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3435 creature_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3436 creature_ptr->current_floor_ptr->dun_level = 1;
3437 creature_ptr->current_floor_ptr->inside_quest = 0;
3441 n_v_check = v_check;
3442 rd_u32b(&o_v_check);
3443 if (o_v_check != n_v_check)
3445 note(_("チェックサムがおかしい", "Invalid checksum"));
3449 n_x_check = x_check;
3450 rd_u32b(&o_x_check);
3451 if (o_x_check != n_x_check)
3453 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3462 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3463 * @param player_ptr プレーヤーへの参照ポインタ
3466 errr rd_savefile_new(player_type *player_ptr)
3469 fff = my_fopen(savefile, "rb");
3471 if (!fff) return -1;
3472 errr err = rd_savefile_new_aux(player_ptr);
3474 if (ferror(fff)) err = -1;
3481 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3482 * @param player_ptr プレーヤーへの参照ポインタ
3483 * @param sf_ptr 保存フロア読み込み先
3486 static bool load_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
3488 u32b n_x_check, n_v_check;
3489 u32b o_x_check, o_v_check;
3498 current_world_ptr->h_ver_extra = H_VER_EXTRA;
3499 current_world_ptr->h_ver_patch = H_VER_PATCH;
3500 current_world_ptr->h_ver_minor = H_VER_MINOR;
3501 current_world_ptr->h_ver_major = H_VER_MAJOR;
3505 if (saved_floor_file_sign != tmp32u) return FALSE;
3507 if (rd_saved_floor(player_ptr, sf_ptr)) return FALSE;
3509 n_v_check = v_check;
3510 rd_u32b(&o_v_check);
3512 if (o_v_check != n_v_check) return FALSE;
3514 n_x_check = x_check;
3515 rd_u32b(&o_x_check);
3517 if (o_x_check != n_x_check) return FALSE;
3523 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporarily saved-floor data
3524 * @param player_ptr プレーヤーへの参照ポインタ
3525 * @param sf_ptr 保存フロア読み込み先
3529 bool load_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
3532 * Temporary files are always written in system depended kanji
3546 FILE *old_fff = NULL;
3547 byte old_xor_byte = 0;
3548 u32b old_v_check = 0;
3549 u32b old_x_check = 0;
3550 byte old_h_ver_major = 0;
3551 byte old_h_ver_minor = 0;
3552 byte old_h_ver_patch = 0;
3553 byte old_h_ver_extra = 0;
3554 if (mode & SLF_SECOND)
3557 old_xor_byte = xor_byte;
3558 old_v_check = v_check;
3559 old_x_check = x_check;
3560 old_h_ver_major = current_world_ptr->h_ver_major;
3561 old_h_ver_minor = current_world_ptr->h_ver_minor;
3562 old_h_ver_patch = current_world_ptr->h_ver_patch;
3563 old_h_ver_extra = current_world_ptr->h_ver_extra;
3566 char floor_savefile[1024];
3567 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3570 fff = my_fopen(floor_savefile, "rb");
3573 bool is_save_successful = TRUE;
3574 if (!fff) is_save_successful = FALSE;
3576 if (is_save_successful)
3578 is_save_successful = load_floor_aux(player_ptr, sf_ptr);
3579 if (ferror(fff)) is_save_successful = FALSE;
3583 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3588 if (mode & SLF_SECOND)
3591 xor_byte = old_xor_byte;
3592 v_check = old_v_check;
3593 x_check = old_x_check;
3594 current_world_ptr->h_ver_major = old_h_ver_major;
3595 current_world_ptr->h_ver_minor = old_h_ver_minor;
3596 current_world_ptr->h_ver_patch = old_h_ver_patch;
3597 current_world_ptr->h_ver_extra = old_h_ver_extra;
3600 byte old_kanji_code = kanji_code;
3601 kanji_code = old_kanji_code;
3602 return is_save_successful;