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.
44 #include "art-definition/art-accessory-types.h"
45 #include "birth/quick-start.h"
46 #include "cmd-item/cmd-smith.h"
47 #include "dungeon/dungeon.h"
48 #include "dungeon/quest.h"
49 #include "floor/floor-generate.h"
50 #include "floor/floor-save.h"
51 #include "floor/floor-town.h"
52 #include "floor/floor.h"
53 #include "floor/wild.h"
54 #include "grid/feature.h"
55 #include "grid/grid.h"
56 #include "grid/trap.h"
57 #include "info-reader/fixed-map-parser.h"
58 #include "io/files-util.h"
59 #include "io/report.h"
61 #include "io/uid-checker.h"
62 #include "locale/japanese.h"
63 #include "market/arena.h"
64 #include "market/bounty.h"
65 #include "monster-race/race-flags-resistance.h"
66 #include "monster-race/race-flags1.h"
67 #include "monster-race/race-flags3.h"
68 #include "monster-race/race-flags7.h"
69 #include "monster-race/race-indice-types.h"
70 #include "monster/monster-flag-types.h"
71 #include "monster/monster2.h"
72 #include "mutation/mutation.h"
73 #include "object-enchant/artifact.h"
74 #include "object-enchant/object-ego.h"
75 #include "object-enchant/old-ego-extra-values.h" // TODO v1.5.0以前のセーブファイルをロードする処理を分離する.
76 #include "object-enchant/tr-types.h"
77 #include "object-enchant/trc-types.h"
78 #include "object-enchant/trg-types.h"
79 #include "object/object-flags.h"
80 #include "object/object-generator.h"
81 #include "object/object-hook.h"
82 #include "object/object-kind-hook.h"
83 #include "object/object-kind.h"
84 #include "object/object-mark-types.h"
85 #include "object/object-stack.h"
86 #include "object/object-value.h"
87 #include "pet/pet-util.h"
88 #include "player/avatar.h"
89 #include "player/patron.h"
90 #include "player/player-class.h"
91 #include "player/player-personality.h"
92 #include "player/player-races-table.h"
93 #include "player/player-sex.h"
94 #include "player/player-skill.h"
95 #include "player/race-info-table.h"
96 #include "spell/spells-status.h"
97 #include "store/store-util.h"
98 #include "store/store.h"
99 #include "sv-definition/sv-armor-types.h"
100 #include "sv-definition/sv-lite-types.h"
101 #include "system/angband-version.h"
102 #include "system/system-variables.h" // 暫定、init_flags の扱いを決めた上で消す.
103 #include "util/object-sort.h"
104 #include "util/util.h"
105 #include "world/world-object.h"
106 #include "world/world.h"
109 * Maximum number of tries for selection of a proper quest monster
111 #define MAX_TRIES 100
113 #define OLD_MAX_MANE 22
115 /* Old hidden trap flag */
116 #define CAVE_TRAP 0x8000
118 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
119 #define OLD_FEAT_INVIS 0x02
120 #define OLD_FEAT_GLYPH 0x03
121 #define OLD_FEAT_QUEST_ENTER 0x08
122 #define OLD_FEAT_QUEST_EXIT 0x09
123 #define OLD_FEAT_MINOR_GLYPH 0x40
124 #define OLD_FEAT_BLDG_1 0x81
125 #define OLD_FEAT_MIRROR 0xc3
128 #define OLD_QUEST_WATER_CAVE 18
130 /* Quest constants */
131 #define QUEST_OLD_CASTLE 27
132 #define QUEST_ROYAL_CRYPT 28
135 * Local "savefile" pointer
140 * Hack -- old "encryption" byte
142 static byte xor_byte;
145 * Hack -- simple "checksum" on the actual values
147 static u32b v_check = 0L;
150 * Hack -- simple "checksum" on the encoded bytes
152 static u32b x_check = 0L;
155 * Hack -- Japanese Kanji code
161 static byte kanji_code = 0;
164 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
165 * @param major メジャーバージョン値
166 * @param minor マイナーバージョン値
167 * @param patch パッチバージョン値
168 * @param extra エクストラパージョン値
169 * @return 現在のバージョンより値が古いならtrue
171 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
173 if (current_world_ptr->h_ver_major < major) return TRUE;
174 if (current_world_ptr->h_ver_major > major) return FALSE;
176 if (current_world_ptr->h_ver_minor < minor) return TRUE;
177 if (current_world_ptr->h_ver_minor > minor) return FALSE;
179 if (current_world_ptr->h_ver_patch < patch) return TRUE;
180 if (current_world_ptr->h_ver_patch > patch) return FALSE;
182 if (current_world_ptr->h_ver_extra < extra) return TRUE;
183 if (current_world_ptr->h_ver_extra > extra) return FALSE;
190 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
191 * @param x メジャーバージョン値
192 * @param y マイナーバージョン値
194 * @return 現在のバージョンより値が古いならtrue
196 static bool z_older_than(byte x, byte y, byte z)
198 if (current_world_ptr->z_major < x) return TRUE;
199 if (current_world_ptr->z_major > x) return FALSE;
201 if (current_world_ptr->z_minor < y) return TRUE;
202 if (current_world_ptr->z_minor > y) return FALSE;
204 if (current_world_ptr->z_patch < z) return TRUE;
205 if (current_world_ptr->z_patch > z) return FALSE;
212 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
216 * Avoid the top two lines, to avoid interference with "msg_print()".
218 static void note(concptr msg)
220 static TERM_LEN y = 2;
222 if (++y >= 24) y = 2;
229 * @brief ロードファイルポインタから1バイトを読み込む
232 * The following functions are used to load the basic building blocks
233 * of savefiles. They also maintain the "checksum" info for 2.7.0+
235 static byte sf_get(void)
237 byte c = getc(fff) & 0xFF;
238 byte v = c ^ xor_byte;
248 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
252 static void rd_byte(byte *ip)
259 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
263 static void rd_u16b(u16b *ip)
266 (*ip) |= ((u16b)(sf_get()) << 8);
271 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
275 static void rd_s16b(s16b *ip)
282 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
286 static void rd_u32b(u32b *ip)
289 (*ip) |= ((u32b)(sf_get()) << 8);
290 (*ip) |= ((u32b)(sf_get()) << 16);
291 (*ip) |= ((u32b)(sf_get()) << 24);
296 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
300 static void rd_s32b(s32b *ip)
307 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
308 * @param str 読み込みポインタ
309 * @param max 最大読み取りバイト数
312 static void rd_string(char *str, int max)
314 for (int i = 0; TRUE; i++)
318 if (i < max) str[i] = tmp8u;
341 byte code = codeconv(str);
343 /* 漢字コードが判明したら、それを記録 */
344 if (code) kanji_code = code;
356 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
360 static void strip_bytes(int n)
363 while (n--) rd_byte(&tmp8u);
368 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
369 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
372 * This function attempts to "repair" old savefiles, and to extract
373 * the most up to date values for various object fields.
375 * Note that Angband 2.7.9 introduced a new method for object "flags"
376 * in which the "flags" on an object are actually extracted when they
377 * are needed from the object kind, artifact index, ego-item index,
378 * and two special "xtra" fields which are used to encode any "extra"
379 * power of certain ego-items. This had the side effect that items
380 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
381 * may have had, and also, all "uncursed" items will become "cursed"
382 * again, including Calris, even if it is being worn at the time. As
383 * a complete hack, items which are inscribed with "uncursed" will be
384 * "uncursed" when imported from pre-2.7.9 savefiles.
386 static void rd_item_old(object_type *o_ptr)
388 rd_s16b(&o_ptr->k_idx);
392 o_ptr->iy = (POSITION)tmp8u;
394 o_ptr->ix = (POSITION)tmp8u;
402 if (z_older_than(10, 4, 4))
404 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
405 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
406 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
409 rd_s16b(&o_ptr->pval);
410 rd_byte(&o_ptr->discount);
412 o_ptr->number = (ITEM_NUMBER)tmp8u;
416 o_ptr->weight = tmp16s;
419 o_ptr->name1 = tmp8u;
422 o_ptr->name2 = tmp8u;
424 rd_s16b(&o_ptr->timeout);
425 rd_s16b(&o_ptr->to_h);
427 o_ptr->to_d = tmp16s;
429 rd_s16b(&o_ptr->to_a);
437 rd_byte(&o_ptr->ident);
438 rd_byte(&o_ptr->marked);
439 rd_u32b(&o_ptr->art_flags[0]);
440 rd_u32b(&o_ptr->art_flags[1]);
441 rd_u32b(&o_ptr->art_flags[2]);
442 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
443 else rd_u32b(&o_ptr->art_flags[3]);
445 if (h_older_than(1, 3, 0, 0))
447 if (o_ptr->name2 == EGO_TELEPATHY)
448 add_flag(o_ptr->art_flags, TR_TELEPATHY);
451 if (z_older_than(11, 0, 11))
453 o_ptr->curse_flags = 0L;
454 if (o_ptr->ident & 0x40)
456 o_ptr->curse_flags |= TRC_CURSED;
457 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
458 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
459 if (object_is_fixed_artifact(o_ptr))
461 artifact_type *a_ptr = &a_info[o_ptr->name1];
462 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
463 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
465 else if (object_is_ego(o_ptr))
467 ego_item_type *e_ptr = &e_info[o_ptr->name2];
468 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
469 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
472 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
476 rd_u32b(&o_ptr->curse_flags);
479 rd_s16b(&o_ptr->held_m_idx);
480 rd_byte(&o_ptr->xtra1);
481 rd_byte(&o_ptr->xtra2);
483 if (z_older_than(11, 0, 10))
485 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
487 switch (o_ptr->xtra2 % 6)
489 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
490 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
491 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
492 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
493 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
494 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
498 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
500 switch (o_ptr->xtra2 % 11)
502 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
503 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
504 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
505 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
506 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
507 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
508 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
509 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
510 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
511 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
512 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
516 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
518 switch (o_ptr->xtra2 % 8)
520 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
521 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
522 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
523 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
524 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
525 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
526 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
527 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
534 if (z_older_than(10, 2, 3))
539 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
541 o_ptr->xtra3 = o_ptr->xtra1;
544 if (o_ptr->tval == TV_CAPTURE)
546 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
547 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
549 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
550 if (ironman_nightmare)
552 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5 * 2L);
554 o_ptr->xtra4 = o_ptr->xtra5;
559 rd_byte(&o_ptr->xtra3);
560 if (h_older_than(1, 3, 0, 1))
562 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1 + 96)
563 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
566 rd_s16b(&o_ptr->xtra4);
567 rd_s16b(&o_ptr->xtra5);
570 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)))
572 o_ptr->xtra4 = o_ptr->pval;
576 rd_byte(&o_ptr->feeling);
579 rd_string(buf, sizeof(buf));
580 if (buf[0]) o_ptr->inscription = quark_add(buf);
582 rd_string(buf, sizeof(buf));
584 /* todo 元々このif文には末尾に";"が付いていた、バグかもしれない */
585 if (buf[0]) o_ptr->art_name = quark_add(buf);
593 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
595 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
597 if (z_older_than(10, 4, 9))
599 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
601 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
602 add_flag(o_ptr->art_flags, TR_DEC_MANA);
606 if (object_is_fixed_artifact(o_ptr))
608 artifact_type *a_ptr;
609 a_ptr = &a_info[o_ptr->name1];
610 if (!a_ptr->name) o_ptr->name1 = 0;
613 if (object_is_ego(o_ptr))
615 ego_item_type *e_ptr;
616 e_ptr = &e_info[o_ptr->name2];
617 if (!e_ptr->name) o_ptr->name2 = 0;
623 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
624 * @param o_ptr アイテムオブジェクト保存先ポインタ
627 static void rd_item(object_type *o_ptr)
629 if (h_older_than(1, 5, 0, 0))
637 rd_s16b(&o_ptr->k_idx);
641 o_ptr->iy = (POSITION)tmp8u;
643 o_ptr->ix = (POSITION)tmp8u;
646 k_ptr = &k_info[o_ptr->k_idx];
647 o_ptr->tval = k_ptr->tval;
648 o_ptr->sval = k_ptr->sval;
650 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
651 else o_ptr->pval = 0;
653 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
654 else o_ptr->discount = 0;
655 if (flags & SAVE_ITEM_NUMBER) {
657 o_ptr->number = tmp8u;
659 else o_ptr->number = 1;
663 o_ptr->weight = tmp16s;
665 if (flags & SAVE_ITEM_NAME1)
668 o_ptr->name1 = tmp8u;
670 else o_ptr->name1 = 0;
672 if (flags & SAVE_ITEM_NAME2)
675 o_ptr->name2 = tmp8u;
677 else o_ptr->name2 = 0;
679 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
680 else o_ptr->timeout = 0;
682 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
683 else o_ptr->to_h = 0;
685 if (flags & SAVE_ITEM_TO_D)
688 o_ptr->to_d = tmp16s;
690 else o_ptr->to_d = 0;
692 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
693 else o_ptr->to_a = 0;
695 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
698 if (flags & SAVE_ITEM_DD)
705 if (flags & SAVE_ITEM_DS)
712 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
713 else o_ptr->ident = 0;
715 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
716 else o_ptr->marked = 0;
719 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
720 else o_ptr->art_flags[0] = 0;
722 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
723 else o_ptr->art_flags[1] = 0;
725 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
726 else o_ptr->art_flags[2] = 0;
728 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
729 else o_ptr->art_flags[3] = 0;
731 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
732 else o_ptr->art_flags[4] = 0;
734 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
735 else o_ptr->curse_flags = 0;
737 /* Monster holding object */
738 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
739 else o_ptr->held_m_idx = 0;
742 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
743 else o_ptr->xtra1 = 0;
745 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
746 else o_ptr->xtra2 = 0;
748 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
749 else o_ptr->xtra3 = 0;
751 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
752 else o_ptr->xtra4 = 0;
754 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
755 else o_ptr->xtra5 = 0;
757 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
758 else o_ptr->feeling = 0;
760 if (flags & SAVE_ITEM_INSCRIPTION)
763 rd_string(buf, sizeof(buf));
764 o_ptr->inscription = quark_add(buf);
766 else o_ptr->inscription = 0;
768 if (flags & SAVE_ITEM_ART_NAME)
771 rd_string(buf, sizeof(buf));
772 o_ptr->art_name = quark_add(buf);
779 if (!h_older_than(2, 1, 2, 4)) return;
781 BIT_FLAGS flgs[TR_FLAG_SIZE];
782 object_flags(o_ptr, flgs);
784 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
786 add_flag(o_ptr->art_flags, TR_LITE_M1);
787 remove_flag(o_ptr->art_flags, TR_LITE_1);
788 remove_flag(o_ptr->art_flags, TR_LITE_2);
789 remove_flag(o_ptr->art_flags, TR_LITE_3);
793 if (o_ptr->name2 == EGO_LITE_DARKNESS)
795 if (o_ptr->tval != TV_LITE)
797 add_flag(o_ptr->art_flags, TR_LITE_M1);
801 if (o_ptr->sval == SV_LITE_TORCH)
803 add_flag(o_ptr->art_flags, TR_LITE_M1);
805 else if (o_ptr->sval == SV_LITE_LANTERN)
807 add_flag(o_ptr->art_flags, TR_LITE_M2);
809 else if (o_ptr->sval == SV_LITE_FEANOR)
811 add_flag(o_ptr->art_flags, TR_LITE_M3);
817 if (o_ptr->tval == TV_LITE)
819 if (object_is_fixed_artifact(o_ptr))
821 add_flag(o_ptr->art_flags, TR_LITE_3);
825 if (o_ptr->sval == SV_LITE_TORCH)
827 add_flag(o_ptr->art_flags, TR_LITE_1);
828 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
832 if (o_ptr->sval == SV_LITE_LANTERN)
834 add_flag(o_ptr->art_flags, TR_LITE_2);
835 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
839 if (o_ptr->sval == SV_LITE_FEANOR)
841 add_flag(o_ptr->art_flags, TR_LITE_2);
849 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
850 * @param player_ptr プレーヤーへの参照ポインタ
851 * @param m_ptr モンスター保存先ポインタ
854 static void rd_monster_old(player_type *player_ptr, monster_type *m_ptr)
856 rd_s16b(&m_ptr->r_idx);
858 if (z_older_than(11, 0, 12))
859 m_ptr->ap_r_idx = m_ptr->r_idx;
861 rd_s16b(&m_ptr->ap_r_idx);
863 if (z_older_than(11, 0, 14))
865 monster_race *r_ptr = &r_info[m_ptr->r_idx];
867 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
868 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
869 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
872 rd_byte(&m_ptr->sub_align);
876 m_ptr->fy = (POSITION)tmp8u;
878 m_ptr->fx = (POSITION)tmp8u;
879 m_ptr->current_floor_ptr = player_ptr->current_floor_ptr;
885 m_ptr->maxhp = tmp16s;
887 if (z_older_than(11, 0, 5))
889 m_ptr->max_maxhp = m_ptr->maxhp;
894 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
896 if (h_older_than(2, 1, 2, 1))
898 m_ptr->dealt_damage = 0;
902 rd_s32b(&m_ptr->dealt_damage);
905 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
907 m_ptr->mspeed = tmp8u;
909 if (z_older_than(10, 4, 2))
912 m_ptr->energy_need = (s16b)tmp8u;
914 else rd_s16b(&m_ptr->energy_need);
916 if (z_older_than(11, 0, 13))
917 m_ptr->energy_need = 100 - m_ptr->energy_need;
919 if (z_older_than(10, 0, 7))
921 m_ptr->mtimed[MTIMED_FAST] = 0;
922 m_ptr->mtimed[MTIMED_SLOW] = 0;
927 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
929 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
933 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
935 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
937 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
939 if (z_older_than(10, 0, 10))
943 else if (z_older_than(10, 0, 11))
951 m_ptr->target_y = (POSITION)tmp16s;
953 m_ptr->target_x = (POSITION)tmp16s;
957 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
959 if (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6))
960 rd_u32b(&m_ptr->smart);
965 if (z_older_than(10, 4, 5))
975 if (z_older_than(10, 2, 2))
977 if (m_ptr->r_idx < 0)
979 m_ptr->r_idx = (0 - m_ptr->r_idx);
980 m_ptr->mflag2 |= MFLAG2_KAGE;
985 rd_byte(&m_ptr->mflag2);
988 if (z_older_than(11, 0, 12))
990 if (m_ptr->mflag2 & MFLAG2_KAGE)
991 m_ptr->ap_r_idx = MON_KAGE;
994 if (z_older_than(10, 1, 3))
1001 rd_string(buf, sizeof(buf));
1002 if (buf[0]) m_ptr->nickname = quark_add(buf);
1010 * @brief モンスターを読み込む(現版) / Read a monster (New method)
1011 * @param player_ptr プレーヤーへの参照ポインタ
1012 * @param m_ptr モンスター保存先ポインタ
1015 static void rd_monster(player_type *player_ptr, monster_type *m_ptr)
1017 if (h_older_than(1, 5, 0, 0))
1019 rd_monster_old(player_ptr, m_ptr);
1025 rd_s16b(&m_ptr->r_idx);
1028 m_ptr->fy = (POSITION)tmp8u;
1030 m_ptr->fx = (POSITION)tmp8u;
1034 m_ptr->hp = (HIT_POINT)tmp16s;
1036 m_ptr->maxhp = (HIT_POINT)tmp16s;
1038 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1040 if (h_older_than(2, 1, 2, 1))
1042 m_ptr->dealt_damage = 0;
1046 rd_s32b(&m_ptr->dealt_damage);
1049 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1050 else m_ptr->ap_r_idx = m_ptr->r_idx;
1052 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1053 else m_ptr->sub_align = 0;
1055 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1056 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1059 m_ptr->mspeed = tmp8u;
1061 rd_s16b(&m_ptr->energy_need);
1063 if (flags & SAVE_MON_FAST)
1066 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1068 else m_ptr->mtimed[MTIMED_FAST] = 0;
1070 if (flags & SAVE_MON_SLOW)
1073 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1075 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1077 if (flags & SAVE_MON_STUNNED)
1080 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1082 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1084 if (flags & SAVE_MON_CONFUSED)
1087 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1089 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1091 if (flags & SAVE_MON_MONFEAR)
1094 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1096 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1098 if (flags & SAVE_MON_TARGET_Y)
1101 m_ptr->target_y = (POSITION)tmp16s;
1103 else m_ptr->target_y = 0;
1105 if (flags & SAVE_MON_TARGET_X)
1108 m_ptr->target_x = (POSITION)tmp16s;
1110 else m_ptr->target_x = 0;
1112 if (flags & SAVE_MON_INVULNER)
1115 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1117 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1119 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1120 else m_ptr->smart = 0;
1122 if (flags & SAVE_MON_EXP)
1126 m_ptr->exp = (EXP)tmp32u;
1128 else m_ptr->exp = 0;
1130 m_ptr->mflag = 0; /* Not saved */
1132 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1133 else m_ptr->mflag2 = 0;
1135 if (flags & SAVE_MON_NICKNAME)
1138 rd_string(buf, sizeof(buf));
1139 m_ptr->nickname = quark_add(buf);
1141 else m_ptr->nickname = 0;
1143 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1144 else m_ptr->parent_m_idx = 0;
1149 * Old monster bit flags of racial resistances
1151 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1152 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1153 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1154 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1155 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1156 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1157 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1158 #define RF3_RES_WATE 0x00800000 /* Resist water */
1159 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1160 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1161 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1162 #define RF3_RES_ALL 0x08000000 /* Resist all */
1164 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1166 if ((R_PTR)->r_flags3 & (RF3)) \
1168 (R_PTR)->r_flags3 &= ~(RF3); \
1169 (R_PTR)->r_flagsr |= (RFR); \
1173 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1175 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1177 (R_PTR)->r_flagsr |= (RFR); \
1181 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1182 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1183 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1184 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1185 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1186 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1187 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1188 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1189 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1190 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1193 * @brief モンスターの思い出を読み込む / Read the monster lore
1194 * @param r_idx 読み込み先モンスターID
1197 static void rd_lore(MONRACE_IDX r_idx)
1199 monster_race *r_ptr = &r_info[r_idx];
1203 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1206 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1209 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1211 if (h_older_than(1, 7, 0, 5))
1213 r_ptr->r_akills = r_ptr->r_pkills;
1218 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1222 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1224 rd_byte(&r_ptr->r_wake);
1225 rd_byte(&r_ptr->r_ignore);
1226 rd_byte(&r_ptr->r_xtra1);
1227 rd_byte(&r_ptr->r_xtra2);
1231 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1233 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1236 rd_byte(&r_ptr->r_cast_spell);
1238 rd_byte(&r_ptr->r_blows[0]);
1239 rd_byte(&r_ptr->r_blows[1]);
1240 rd_byte(&r_ptr->r_blows[2]);
1241 rd_byte(&r_ptr->r_blows[3]);
1243 rd_u32b(&r_ptr->r_flags1);
1244 rd_u32b(&r_ptr->r_flags2);
1245 rd_u32b(&r_ptr->r_flags3);
1246 rd_u32b(&r_ptr->r_flags4);
1247 rd_u32b(&r_ptr->r_flags5);
1248 rd_u32b(&r_ptr->r_flags6);
1249 if (h_older_than(1, 5, 0, 3))
1251 r_ptr->r_flagsr = 0L;
1252 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1253 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1254 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1255 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1256 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1257 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1258 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1259 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1260 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1261 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1262 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1263 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1265 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1266 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1267 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1268 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1269 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1270 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1271 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1272 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1273 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1275 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1276 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1277 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1281 rd_u32b(&r_ptr->r_flagsr);
1285 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1287 rd_s16b(&r_ptr->floor_id);
1290 r_ptr->r_flags1 &= r_ptr->flags1;
1291 r_ptr->r_flags2 &= r_ptr->flags2;
1292 r_ptr->r_flags3 &= r_ptr->flags3;
1293 r_ptr->r_flags4 &= r_ptr->flags4;
1294 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1295 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1296 r_ptr->r_flagsr &= r_ptr->flagsr;
1301 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1302 * @param player_ptr プレーヤーへの参照ポインタ
1303 * @param store_ptr 店舗の参照ポインタ
1304 * @param o_ptr アイテムオブジェクト参照ポインタ
1307 * In all cases, return the slot (or -1) where the object was placed
1309 * Note that this is a hacked up version of "store_item_to_inventory()".
1311 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1312 * known, the player may have to pick stuff up and drop it again.
1314 static void home_carry(player_type *player_ptr, store_type *store_ptr, object_type *o_ptr)
1316 for (int i = 0; i < store_ptr->stock_num; i++)
1319 j_ptr = &store_ptr->stock[i];
1320 if (!object_similar(j_ptr, o_ptr)) continue;
1322 object_absorb(j_ptr, o_ptr);
1326 if (store_ptr->stock_num >= STORE_INVEN_MAX * 10) return;
1328 s32b value = object_value(o_ptr);
1330 for (slot = 0; slot < store_ptr->stock_num; slot++)
1332 if (object_sort_comp(o_ptr, value, &store_ptr->stock[slot])) break;
1335 for (int i = store_ptr->stock_num; i > slot; i--)
1337 store_ptr->stock[i] = store_ptr->stock[i - 1];
1340 store_ptr->stock_num++;
1341 store_ptr->stock[slot] = *o_ptr;
1342 chg_virtue(player_ptr, V_SACRIFICE, -1);
1347 * @brief 店舗情報を読み込む / Read a store
1348 * @param player_ptr プレーヤーへの参照ポインタ
1349 * @param town_number 街ID
1350 * @param store_number 店舗ID
1353 static errr rd_store(player_type *player_ptr, int town_number, int store_number)
1355 store_type *store_ptr;
1357 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1359 store_ptr = &town_info[1].store[store_number];
1360 if (store_ptr->stock_num) sort = TRUE;
1364 store_ptr = &town_info[town_number].store[store_number];
1370 rd_s32b(&store_ptr->store_open);
1371 rd_s16b(&store_ptr->insult_cur);
1373 if (z_older_than(11, 0, 4))
1383 rd_s16b(&store_ptr->good_buy);
1384 rd_s16b(&store_ptr->bad_buy);
1386 rd_s32b(&store_ptr->last_visit);
1387 store_ptr->owner = own;
1389 for (int j = 0; j < num; j++)
1398 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);
1399 if (!is_valid_item) continue;
1403 home_carry(player_ptr, store_ptr, q_ptr);
1407 int k = store_ptr->stock_num++;
1408 object_copy(&store_ptr->stock[k], q_ptr);
1417 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1420 static void rd_randomizer(void)
1424 rd_u16b(&Rand_place);
1425 for (int i = 0; i < RAND_DEG; i++)
1427 rd_u32b(&Rand_state[i]);
1433 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1436 * Note that the normal options are now stored as a set of 256 bit flags,
1437 * plus a set of 256 bit masks to indicate which bit flags were defined
1438 * at the time the savefile was created. This will allow new options
1439 * to be added, and old options to be removed, at any time, without
1440 * hurting old savefiles.
1442 * The window options are stored in the same way, but note that each
1443 * window gets 32 options, and their order is fixed by certain defines.
1445 static void rd_options(void)
1456 if (h_older_than(1, 7, 0, 0))
1469 if (c & 0x0002) current_world_ptr->wizard = TRUE;
1471 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1472 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1473 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1474 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1475 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1476 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1477 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1478 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1479 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1480 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1482 rd_byte((byte *)&autosave_l);
1483 rd_byte((byte *)&autosave_t);
1484 rd_s16b(&autosave_freq);
1487 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1490 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1492 for (int n = 0; n < 8; n++)
1494 for (int i = 0; i < 32; i++)
1496 if (!(mask[n] & (1L << i))) continue;
1497 if (!(option_mask[n] & (1L << i))) continue;
1499 if (flag[n] & (1L << i))
1501 option_flag[n] |= (1L << i);
1505 option_flag[n] &= ~(1L << i);
1510 if (z_older_than(10, 4, 5))
1512 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1513 else option_flag[5] |= (0x00000001 << 4);
1514 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1515 else option_flag[2] |= (0x00000001 << 5);
1516 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1517 else option_flag[4] |= (0x00000001 << 5);
1518 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1519 else option_flag[5] |= (0x00000001 << 0);
1520 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1521 else option_flag[5] |= (0x00000001 << 12);
1522 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1523 else option_flag[1] |= (0x00000001 << 0);
1524 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1525 else option_flag[1] |= (0x00000001 << 18);
1526 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1527 else option_flag[1] |= (0x00000001 << 19);
1528 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1529 else option_flag[5] |= (0x00000001 << 3);
1532 extract_option_vars();
1533 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1535 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1537 for (int n = 0; n < 8; n++)
1539 for (int i = 0; i < 32; i++)
1541 if (!(mask[n] & (1L << i))) continue;
1542 if (!(window_mask[n] & (1L << i))) continue;
1544 if (flag[n] & (1L << i))
1546 window_flag[n] |= (1L << i);
1550 window_flag[n] &= ~(1L << i);
1558 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1561 * This is such a nasty hack it hurts.
1563 static void rd_ghost(void)
1566 rd_string(buf, sizeof(buf));
1572 * @brief クイックスタート情報を読み込む / Load quick start data
1575 static void load_quick_start(void)
1577 if (z_older_than(11, 0, 13))
1579 previous_char.quick_ok = FALSE;
1583 rd_byte(&previous_char.psex);
1586 previous_char.prace = (player_race_type)tmp8u;
1588 previous_char.pclass = (player_class_type)tmp8u;
1590 previous_char.pseikaku = (player_personality_type)tmp8u;
1592 previous_char.realm1 = (REALM_IDX)tmp8u;
1594 previous_char.realm2 = (REALM_IDX)tmp8u;
1596 rd_s16b(&previous_char.age);
1597 rd_s16b(&previous_char.ht);
1598 rd_s16b(&previous_char.wt);
1599 rd_s16b(&previous_char.sc);
1600 rd_s32b(&previous_char.au);
1602 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1603 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1605 for (int i = 0; i < PY_MAX_LEVEL; i++)
1609 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1612 rd_s16b(&previous_char.chaos_patron);
1614 for (int i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1616 for (int i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1620 previous_char.quick_ok = (bool)tmp8u;
1625 * @brief その他の情報を読み込む / Read the "extra" information
1628 static void rd_extra(player_type *creature_ptr)
1630 rd_string(creature_ptr->name, sizeof(creature_ptr->name));
1631 rd_string(creature_ptr->died_from, sizeof(creature_ptr->died_from));
1632 if (!h_older_than(1, 7, 0, 1))
1635 rd_string(buf, sizeof buf);
1636 if (buf[0]) creature_ptr->last_message = string_make(buf);
1640 for (int i = 0; i < 4; i++)
1642 rd_string(creature_ptr->history[i], sizeof(creature_ptr->history[i]));
1647 creature_ptr->prace = (player_race_type)tmp8u;
1650 creature_ptr->pclass = (player_class_type)tmp8u;
1653 creature_ptr->pseikaku = (player_personality_type)tmp8u;
1655 rd_byte(&creature_ptr->psex);
1657 creature_ptr->realm1 = (REALM_IDX)tmp8u;
1660 creature_ptr->realm2 = (REALM_IDX)tmp8u;
1663 if (z_older_than(10, 4, 4))
1665 if (creature_ptr->realm1 == 9) creature_ptr->realm1 = REALM_MUSIC;
1666 if (creature_ptr->realm2 == 9) creature_ptr->realm2 = REALM_MUSIC;
1667 if (creature_ptr->realm1 == 10) creature_ptr->realm1 = REALM_HISSATSU;
1668 if (creature_ptr->realm2 == 10) creature_ptr->realm2 = REALM_HISSATSU;
1672 creature_ptr->hitdie = tmp8u;
1673 rd_u16b(&creature_ptr->expfact);
1675 rd_s16b(&creature_ptr->age);
1676 rd_s16b(&creature_ptr->ht);
1677 rd_s16b(&creature_ptr->wt);
1679 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max[i]);
1680 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max_max[i]);
1681 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_cur[i]);
1684 rd_s32b(&creature_ptr->au);
1686 rd_s32b(&creature_ptr->max_exp);
1687 if (h_older_than(1, 5, 4, 1)) creature_ptr->max_max_exp = creature_ptr->max_exp;
1688 else rd_s32b(&creature_ptr->max_max_exp);
1689 rd_s32b(&creature_ptr->exp);
1691 if (h_older_than(1, 7, 0, 3))
1695 creature_ptr->exp_frac = (u32b)tmp16u;
1699 rd_u32b(&creature_ptr->exp_frac);
1702 rd_s16b(&creature_ptr->lev);
1704 for (int i = 0; i < 64; i++) rd_s16b(&creature_ptr->spell_exp[i]);
1705 if ((creature_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1707 for (int i = 0; i < 64; i++) creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1710 if (z_older_than(10, 3, 6))
1711 for (int i = 0; i < 5; i++) for (int j = 0; j < 60; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1713 for (int i = 0; i < 5; i++) for (int j = 0; j < 64; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1714 for (int i = 0; i < GINOU_MAX; i++) rd_s16b(&creature_ptr->skill_exp[i]);
1715 if (z_older_than(10, 4, 1))
1717 if (creature_ptr->pclass != CLASS_BEASTMASTER) creature_ptr->skill_exp[GINOU_RIDING] /= 2;
1718 creature_ptr->skill_exp[GINOU_RIDING] = MIN(creature_ptr->skill_exp[GINOU_RIDING], s_info[creature_ptr->pclass].s_max[GINOU_RIDING]);
1721 if (z_older_than(10, 3, 14))
1723 for (int i = 0; i < 108; i++) creature_ptr->magic_num1[i] = 0;
1724 for (int i = 0; i < 108; i++) creature_ptr->magic_num2[i] = 0;
1728 for (int i = 0; i < 108; i++) rd_s32b(&creature_ptr->magic_num1[i]);
1729 for (int i = 0; i < 108; i++) rd_byte(&creature_ptr->magic_num2[i]);
1730 if (h_older_than(1, 3, 0, 1))
1732 if (creature_ptr->pclass == CLASS_SMITH)
1734 creature_ptr->magic_num1[TR_ES_ATTACK] = creature_ptr->magic_num1[96];
1735 creature_ptr->magic_num1[96] = 0;
1736 creature_ptr->magic_num1[TR_ES_AC] = creature_ptr->magic_num1[97];
1737 creature_ptr->magic_num1[97] = 0;
1742 if (music_singing_any(creature_ptr)) creature_ptr->action = ACTION_SING;
1744 if (z_older_than(11, 0, 7))
1746 creature_ptr->start_race = creature_ptr->prace;
1747 creature_ptr->old_race1 = 0L;
1748 creature_ptr->old_race2 = 0L;
1749 creature_ptr->old_realm = 0;
1754 creature_ptr->start_race = (player_race_type)tmp8u;
1757 creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1759 creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1760 rd_s16b(&creature_ptr->old_realm);
1763 if (z_older_than(10, 0, 1))
1765 for (int i = 0; i < MAX_MANE; i++)
1767 creature_ptr->mane_spell[i] = -1;
1768 creature_ptr->mane_dam[i] = 0;
1770 creature_ptr->mane_num = 0;
1772 else if (z_older_than(10, 2, 3))
1775 for (int i = 0; i < OLD_MAX_MANE; i++)
1781 for (int i = 0; i < MAX_MANE; i++)
1783 creature_ptr->mane_spell[i] = -1;
1784 creature_ptr->mane_dam[i] = 0;
1788 creature_ptr->mane_num = 0;
1792 for (int i = 0; i < MAX_MANE; i++)
1796 creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1798 creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1801 rd_s16b(&creature_ptr->mane_num);
1804 if (z_older_than(10, 0, 3))
1806 determine_bounty_uniques(creature_ptr);
1808 for (int i = 0; i < MAX_BOUNTY; i++)
1810 /* Is this bounty unique already dead? */
1811 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1816 for (int i = 0; i < MAX_BOUNTY; i++)
1818 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1822 if (z_older_than(10, 0, 3))
1824 update_gambling_monsters(creature_ptr);
1828 for (int i = 0; i < 4; i++)
1830 rd_s16b(&battle_mon[i]);
1831 if (z_older_than(10, 3, 4))
1835 mon_odds[i] = tmp16s;
1837 else rd_u32b(&mon_odds[i]);
1841 rd_s16b(&creature_ptr->town_num);
1842 rd_s16b(&creature_ptr->arena_number);
1843 if (h_older_than(1, 5, 0, 1))
1845 if (creature_ptr->arena_number >= 99) creature_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1850 creature_ptr->current_floor_ptr->inside_arena = (bool)tmp16s;
1851 rd_s16b(&creature_ptr->current_floor_ptr->inside_quest);
1852 if (z_older_than(10, 3, 5)) creature_ptr->phase_out = FALSE;
1856 creature_ptr->phase_out = (bool)tmp16s;
1859 rd_byte(&creature_ptr->exit_bldg);
1863 creature_ptr->oldpx = (POSITION)tmp16s;
1866 creature_ptr->oldpy = (POSITION)tmp16s;
1867 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; }
1870 for (int i = 0; i < tmp16s; i++)
1876 if (h_older_than(1, 7, 0, 3))
1879 creature_ptr->mhp = tmp16s;
1882 creature_ptr->chp = tmp16s;
1886 creature_ptr->chp_frac = (u32b)tmp16u;
1890 rd_s32b(&creature_ptr->mhp);
1891 rd_s32b(&creature_ptr->chp);
1892 rd_u32b(&creature_ptr->chp_frac);
1895 if (h_older_than(1, 7, 0, 3))
1898 creature_ptr->msp = tmp16s;
1901 creature_ptr->csp = tmp16s;
1905 creature_ptr->csp_frac = (u32b)tmp16u;
1909 rd_s32b(&creature_ptr->msp);
1910 rd_s32b(&creature_ptr->csp);
1911 rd_u32b(&creature_ptr->csp_frac);
1914 rd_s16b(&creature_ptr->max_plv);
1915 if (z_older_than(10, 3, 8))
1918 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1922 byte max = (byte)current_world_ptr->max_d_idx;
1926 for (int i = 0; i < max; i++)
1929 max_dlv[i] = tmp16s;
1930 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1934 if (creature_ptr->max_plv < creature_ptr->lev) creature_ptr->max_plv = creature_ptr->lev;
1937 rd_s16b(&creature_ptr->sc);
1938 rd_s16b(&creature_ptr->concent);
1940 strip_bytes(2); /* Old "rest" */
1941 rd_s16b(&creature_ptr->blind);
1942 rd_s16b(&creature_ptr->paralyzed);
1943 rd_s16b(&creature_ptr->confused);
1944 rd_s16b(&creature_ptr->food);
1945 strip_bytes(4); /* Old "food_digested" / "protection" */
1947 rd_s16b(&creature_ptr->energy_need);
1948 if (z_older_than(11, 0, 13))
1949 creature_ptr->energy_need = 100 - creature_ptr->energy_need;
1950 if (h_older_than(2, 1, 2, 0))
1951 creature_ptr->enchant_energy_need = 0;
1953 rd_s16b(&creature_ptr->enchant_energy_need);
1955 rd_s16b(&creature_ptr->fast);
1956 rd_s16b(&creature_ptr->slow);
1957 rd_s16b(&creature_ptr->afraid);
1958 rd_s16b(&creature_ptr->cut);
1959 rd_s16b(&creature_ptr->stun);
1960 rd_s16b(&creature_ptr->poisoned);
1961 rd_s16b(&creature_ptr->image);
1962 rd_s16b(&creature_ptr->protevil);
1963 rd_s16b(&creature_ptr->invuln);
1964 if (z_older_than(10, 0, 0))
1965 creature_ptr->ult_res = 0;
1967 rd_s16b(&creature_ptr->ult_res);
1968 rd_s16b(&creature_ptr->hero);
1969 rd_s16b(&creature_ptr->shero);
1970 rd_s16b(&creature_ptr->shield);
1971 rd_s16b(&creature_ptr->blessed);
1972 rd_s16b(&creature_ptr->tim_invis);
1973 rd_s16b(&creature_ptr->word_recall);
1974 if (z_older_than(10, 3, 8))
1975 creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
1979 creature_ptr->recall_dungeon = (byte)tmp16s;
1982 if (h_older_than(1, 5, 0, 0))
1983 creature_ptr->alter_reality = 0;
1985 rd_s16b(&creature_ptr->alter_reality);
1987 rd_s16b(&creature_ptr->see_infra);
1988 rd_s16b(&creature_ptr->tim_infra);
1989 rd_s16b(&creature_ptr->oppose_fire);
1990 rd_s16b(&creature_ptr->oppose_cold);
1991 rd_s16b(&creature_ptr->oppose_acid);
1992 rd_s16b(&creature_ptr->oppose_elec);
1993 rd_s16b(&creature_ptr->oppose_pois);
1994 if (z_older_than(10, 0, 2)) creature_ptr->tsuyoshi = 0;
1995 else rd_s16b(&creature_ptr->tsuyoshi);
1997 /* Old savefiles do not have the following fields... */
1998 if ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->z_patch == 6))
2000 creature_ptr->tim_esp = 0;
2001 creature_ptr->wraith_form = 0;
2002 creature_ptr->resist_magic = 0;
2003 creature_ptr->tim_regen = 0;
2004 creature_ptr->kabenuke = 0;
2005 creature_ptr->tim_stealth = 0;
2006 creature_ptr->tim_levitation = 0;
2007 creature_ptr->tim_sh_touki = 0;
2008 creature_ptr->lightspeed = 0;
2009 creature_ptr->tsubureru = 0;
2010 creature_ptr->tim_res_nether = 0;
2011 creature_ptr->tim_res_time = 0;
2012 creature_ptr->mimic_form = 0;
2013 creature_ptr->tim_mimic = 0;
2014 creature_ptr->tim_sh_fire = 0;
2015 creature_ptr->tim_reflect = 0;
2016 creature_ptr->multishadow = 0;
2017 creature_ptr->dustrobe = 0;
2018 creature_ptr->chaos_patron = ((creature_ptr->age + creature_ptr->sc) % MAX_PATRON);
2019 creature_ptr->muta1 = 0;
2020 creature_ptr->muta2 = 0;
2021 creature_ptr->muta3 = 0;
2022 get_virtues(creature_ptr);
2026 rd_s16b(&creature_ptr->tim_esp);
2027 rd_s16b(&creature_ptr->wraith_form);
2028 rd_s16b(&creature_ptr->resist_magic);
2029 rd_s16b(&creature_ptr->tim_regen);
2030 rd_s16b(&creature_ptr->kabenuke);
2031 rd_s16b(&creature_ptr->tim_stealth);
2032 rd_s16b(&creature_ptr->tim_levitation);
2033 rd_s16b(&creature_ptr->tim_sh_touki);
2034 rd_s16b(&creature_ptr->lightspeed);
2035 rd_s16b(&creature_ptr->tsubureru);
2036 if (z_older_than(10, 4, 7))
2037 creature_ptr->magicdef = 0;
2039 rd_s16b(&creature_ptr->magicdef);
2040 rd_s16b(&creature_ptr->tim_res_nether);
2041 if (z_older_than(10, 4, 11))
2043 creature_ptr->tim_res_time = 0;
2044 creature_ptr->mimic_form = 0;
2045 creature_ptr->tim_mimic = 0;
2046 creature_ptr->tim_sh_fire = 0;
2050 rd_s16b(&creature_ptr->tim_res_time);
2052 creature_ptr->mimic_form = (IDX)tmp8u;
2053 rd_s16b(&creature_ptr->tim_mimic);
2054 rd_s16b(&creature_ptr->tim_sh_fire);
2057 if (z_older_than(11, 0, 99))
2059 creature_ptr->tim_sh_holy = 0;
2060 creature_ptr->tim_eyeeye = 0;
2064 rd_s16b(&creature_ptr->tim_sh_holy);
2065 rd_s16b(&creature_ptr->tim_eyeeye);
2068 if (z_older_than(11, 0, 3)) {
2069 creature_ptr->tim_reflect = 0;
2070 creature_ptr->multishadow = 0;
2071 creature_ptr->dustrobe = 0;
2075 rd_s16b(&creature_ptr->tim_reflect);
2076 rd_s16b(&creature_ptr->multishadow);
2077 rd_s16b(&creature_ptr->dustrobe);
2080 rd_s16b(&creature_ptr->chaos_patron);
2081 rd_u32b(&creature_ptr->muta1);
2082 rd_u32b(&creature_ptr->muta2);
2083 rd_u32b(&creature_ptr->muta3);
2085 for (int i = 0; i < 8; i++)
2086 rd_s16b(&creature_ptr->virtues[i]);
2087 for (int i = 0; i < 8; i++)
2088 rd_s16b(&creature_ptr->vir_types[i]);
2091 creature_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod(creature_ptr);
2092 if (z_older_than(10, 0, 9))
2095 if (tmp8u) creature_ptr->special_attack = ATTACK_CONFUSE;
2096 creature_ptr->ele_attack = 0;
2100 rd_s16b(&creature_ptr->ele_attack);
2101 rd_u32b(&creature_ptr->special_attack);
2104 if (creature_ptr->special_attack & KAMAE_MASK) creature_ptr->action = ACTION_KAMAE;
2105 else if (creature_ptr->special_attack & KATA_MASK) creature_ptr->action = ACTION_KATA;
2106 if (z_older_than(10, 0, 12))
2108 creature_ptr->ele_immune = 0;
2109 creature_ptr->special_defense = 0;
2113 rd_s16b(&creature_ptr->ele_immune);
2114 rd_u32b(&creature_ptr->special_defense);
2117 rd_byte(&creature_ptr->knowledge);
2119 creature_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2123 creature_ptr->action = (ACTION_IDX)tmp8u;
2124 if (!z_older_than(10, 4, 3))
2127 if (tmp8u) creature_ptr->action = ACTION_LEARN;
2130 rd_byte((byte *)&preserve_mode);
2131 rd_byte((byte *)&creature_ptr->wait_report_score);
2133 for (int i = 0; i < 48; i++) rd_byte(&tmp8u);
2136 rd_u32b(¤t_world_ptr->seed_flavor);
2137 rd_u32b(¤t_world_ptr->seed_town);
2139 rd_u16b(&creature_ptr->panic_save);
2140 rd_u16b(¤t_world_ptr->total_winner);
2141 rd_u16b(¤t_world_ptr->noscore);
2144 creature_ptr->is_dead = tmp8u;
2146 rd_byte(&creature_ptr->feeling);
2148 switch (creature_ptr->start_race)
2154 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2157 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2161 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2162 rd_s32b(&creature_ptr->current_floor_ptr->generated_turn);
2163 if (h_older_than(1, 7, 0, 4))
2165 creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
2169 rd_s32b(&creature_ptr->feeling_turn);
2172 rd_s32b(¤t_world_ptr->game_turn);
2173 if (z_older_than(10, 3, 12))
2175 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2177 else rd_s32b(¤t_world_ptr->dungeon_turn);
2179 if (z_older_than(11, 0, 13))
2181 creature_ptr->current_floor_ptr->generated_turn /= 2;
2182 creature_ptr->feeling_turn /= 2;
2183 current_world_ptr->game_turn /= 2;
2184 current_world_ptr->dungeon_turn /= 2;
2187 if (z_older_than(10, 3, 13))
2189 current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
2191 else rd_s32b(¤t_world_ptr->arena_start_turn);
2193 if (z_older_than(10, 0, 3))
2195 determine_daily_bounty(creature_ptr, TRUE);
2199 rd_s16b(&today_mon);
2200 rd_s16b(&creature_ptr->today_mon);
2203 if (z_older_than(10, 0, 7))
2205 creature_ptr->riding = 0;
2209 rd_s16b(&creature_ptr->riding);
2212 if (h_older_than(1, 5, 0, 0))
2214 creature_ptr->floor_id = 0;
2218 rd_s16b(&creature_ptr->floor_id);
2221 if (h_older_than(1, 5, 0, 2))
2228 for (int i = 0; i < tmp16s; i++)
2230 monster_type dummy_mon;
2231 rd_monster(creature_ptr, &dummy_mon);
2235 if (z_older_than(10, 1, 2))
2237 current_world_ptr->play_time = 0;
2241 rd_u32b(¤t_world_ptr->play_time);
2244 if (z_older_than(10, 3, 9))
2246 creature_ptr->visit = 1L;
2248 else if (z_older_than(10, 3, 10))
2252 creature_ptr->visit = 1L;
2258 creature_ptr->visit = (BIT_FLAGS)tmp32s;
2261 if (!z_older_than(11, 0, 5))
2263 rd_u32b(&creature_ptr->count);
2269 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2270 * @param player_ptr プレーヤーへの参照ポインタ
2273 * Note that the inventory changed in Angband 2.7.4. Two extra
2274 * pack slots were added and the equipment was rearranged. Note
2275 * that these two features combine when parsing old save-files, in
2276 * which items from the old "aux" slot are "carried", perhaps into
2277 * one of the two new "inventory" slots.
2279 * Note that the inventory is "re-sorted" later by "dungeon()".
2281 static errr rd_inventory(player_type *player_ptr)
2283 player_ptr->total_weight = 0;
2284 player_ptr->inven_cnt = 0;
2285 player_ptr->equip_cnt = 0;
2287 if (player_ptr->inventory_list != NULL) C_WIPE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2288 C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2296 if (n == 0xFFFF) break;
2303 if (!q_ptr->k_idx) return (53);
2305 if (n >= INVEN_RARM)
2307 q_ptr->marked |= OM_TOUCHED;
2308 object_copy(&player_ptr->inventory_list[n], q_ptr);
2309 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2310 player_ptr->equip_cnt++;
2314 if (player_ptr->inven_cnt == INVEN_PACK)
2316 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
2321 q_ptr->marked |= OM_TOUCHED;
2322 object_copy(&player_ptr->inventory_list[n], q_ptr);
2323 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2324 player_ptr->inven_cnt++;
2332 * @brief メッセージログを読み込む / Read the saved messages
2335 static void rd_messages(void)
2337 if (h_older_than(2, 2, 0, 75))
2342 message_max = (int)num;
2344 for (int i = 0; i < message_max; i++)
2347 rd_string(buf, sizeof(buf));
2355 message_max = (int)num;
2357 for (int i = 0; i < message_max; i++)
2360 rd_string(buf, sizeof(buf));
2367 * @brief メッセージログを読み込む / Read the dungeon (old method)
2368 * @param creature_ptr プレーヤーへの参照ポインタ
2371 * The monsters/objects must be loaded in the same order
2372 * that they were stored, since the actual indexes matter.
2374 static errr rd_dungeon_old(player_type *creature_ptr)
2378 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2379 floor_ptr->dun_level = (DEPTH)tmp16s;
2380 if (z_older_than(10, 3, 8)) creature_ptr->dungeon_idx = DUNGEON_ANGBAND;
2385 creature_ptr->dungeon_idx = (IDX)tmp8u;
2388 floor_ptr->base_level = floor_ptr->dun_level;
2390 floor_ptr->base_level = (DEPTH)tmp16s;
2393 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2395 creature_ptr->y = (POSITION)tmp16s;
2397 creature_ptr->x = (POSITION)tmp16s;
2398 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) { creature_ptr->y = 33; creature_ptr->x = 131; }
2400 floor_ptr->height = (POSITION)tmp16s;
2402 floor_ptr->width = (POSITION)tmp16s;
2403 rd_s16b(&tmp16s); /* max_panel_rows */
2404 rd_s16b(&tmp16s); /* max_panel_cols */
2406 int ymax = floor_ptr->height;
2407 int xmax = floor_ptr->width;
2409 for (int x = 0, y = 0; y < ymax; )
2414 if (z_older_than(10, 3, 6))
2423 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2426 for (int i = count; i > 0; i--)
2429 g_ptr = &floor_ptr->grid_array[y][x];
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->feat = (s16b)tmp8u;
2453 if (++y >= ymax) break;
2458 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->mimic = (s16b)tmp8u;
2472 if (++y >= ymax) break;
2477 for (int x = 0, y = 0; y < ymax; )
2482 for (int i = count; i > 0; i--)
2485 g_ptr = &floor_ptr->grid_array[y][x];
2486 g_ptr->special = tmp16s;
2490 if (++y >= ymax) break;
2495 if (z_older_than(11, 0, 99))
2497 for (int y = 0; y < ymax; y++)
2499 for (int x = 0; x < xmax; x++)
2501 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2506 if (h_older_than(1, 1, 1, 0))
2508 for (int y = 0; y < ymax; y++)
2510 for (int x = 0; x < xmax; x++)
2513 g_ptr = &floor_ptr->grid_array[y][x];
2516 if (g_ptr->feat == OLD_FEAT_INVIS)
2518 g_ptr->feat = feat_floor;
2519 g_ptr->info |= CAVE_TRAP;
2522 /* Older than 1.1.1 */
2523 if (g_ptr->feat == OLD_FEAT_MIRROR)
2525 g_ptr->feat = feat_floor;
2526 g_ptr->info |= CAVE_OBJECT;
2532 if (h_older_than(1, 3, 1, 0))
2534 for (int y = 0; y < ymax; y++)
2536 for (int x = 0; x < xmax; x++)
2539 g_ptr = &floor_ptr->grid_array[y][x];
2541 /* Old CAVE_IN_MIRROR flag */
2542 if (g_ptr->info & CAVE_OBJECT)
2544 g_ptr->mimic = feat_mirror;
2546 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2547 (g_ptr->feat == OLD_FEAT_GLYPH))
2549 g_ptr->info |= CAVE_OBJECT;
2550 g_ptr->mimic = g_ptr->feat;
2551 g_ptr->feat = feat_floor;
2553 else if (g_ptr->info & CAVE_TRAP)
2555 g_ptr->info &= ~CAVE_TRAP;
2556 g_ptr->mimic = g_ptr->feat;
2557 g_ptr->feat = choose_random_trap(creature_ptr);
2559 else if (g_ptr->feat == OLD_FEAT_INVIS)
2561 g_ptr->mimic = feat_floor;
2562 g_ptr->feat = feat_trap_open;
2568 /* Quest 18 was removed */
2569 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2571 for (int y = 0; y < ymax; y++)
2573 for (int x = 0; x < xmax; x++)
2576 g_ptr = &floor_ptr->grid_array[y][x];
2578 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2580 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2582 g_ptr->feat = feat_tree;
2585 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2587 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2590 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2591 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2593 g_ptr->feat = feat_up_stair;
2602 if (limit > current_world_ptr->max_o_idx)
2604 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2608 for (int i = 1; i < limit; i++)
2610 OBJECT_IDX o_idx = o_pop(floor_ptr);
2613 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2618 o_ptr = &floor_ptr->o_list[o_idx];
2620 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2622 monster_type *m_ptr;
2623 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2624 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2625 m_ptr->hold_o_idx = o_idx;
2630 g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2631 o_ptr->next_o_idx = g_ptr->o_idx;
2632 g_ptr->o_idx = o_idx;
2636 if (limit > current_world_ptr->max_m_idx)
2638 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2642 for (int i = 1; i < limit; i++)
2645 monster_type *m_ptr;
2646 m_idx = m_pop(creature_ptr);
2649 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2653 m_ptr = &floor_ptr->m_list[m_idx];
2654 rd_monster(creature_ptr, m_ptr);
2656 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2657 g_ptr->m_idx = m_idx;
2658 real_r_ptr(m_ptr)->cur_num++;
2661 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena)
2662 current_world_ptr->character_dungeon = FALSE;
2664 current_world_ptr->character_dungeon = TRUE;
2671 * @brief 保存されたフロアを読み込む / Read the saved floor
2672 * @param player_ptr プレーヤーへの参照ポインタ
2673 * @param sf_ptr 最後に保存されたフロアへの参照ポインタ
2674 * @return info読み込みエラーコード
2676 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2679 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2680 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2682 * The monsters/objects must be loaded in the same order
2683 * that they were stored, since the actual indexes matter.
2685 static errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
2687 grid_template_type *templates;
2688 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2689 clear_cave(player_ptr);
2690 player_ptr->x = player_ptr->y = 0;
2696 floor_ptr->dun_level = (DEPTH)tmp16s;
2697 floor_ptr->base_level = floor_ptr->dun_level;
2703 if (tmp16s != sf_ptr->floor_id) return 171;
2707 if (tmp8u != sf_ptr->savefile_id) return 171;
2710 if (tmp16s != sf_ptr->dun_level) return 171;
2711 floor_ptr->dun_level = sf_ptr->dun_level;
2715 if (tmp32s != sf_ptr->last_visit) return 171;
2719 if (tmp32u != sf_ptr->visit_mark) return 171;
2722 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2725 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2730 floor_ptr->base_level = (DEPTH)tmp16s;
2732 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2736 player_ptr->y = (POSITION)tmp16u;
2739 player_ptr->x = (POSITION)tmp16u;
2742 floor_ptr->height = (POSITION)tmp16s;
2744 floor_ptr->width = (POSITION)tmp16s;
2746 rd_byte(&player_ptr->feeling);
2750 C_MAKE(templates, limit, grid_template_type);
2752 for (int i = 0; i < limit; i++)
2754 grid_template_type *ct_ptr = &templates[i];
2756 ct_ptr->info = (BIT_FLAGS)tmp16u;
2757 if (h_older_than(1, 7, 0, 2))
2761 ct_ptr->feat = (s16b)tmp8u;
2763 ct_ptr->mimic = (s16b)tmp8u;
2767 rd_s16b(&ct_ptr->feat);
2768 rd_s16b(&ct_ptr->mimic);
2771 rd_s16b(&ct_ptr->special);
2774 POSITION ymax = floor_ptr->height;
2775 POSITION xmax = floor_ptr->width;
2776 for (POSITION x = 0, y = 0; y < ymax; )
2787 } while (tmp8u == MAX_UCHAR);
2789 for (int i = count; i > 0; i--)
2791 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2792 g_ptr->info = templates[id].info;
2793 g_ptr->feat = templates[id].feat;
2794 g_ptr->mimic = templates[id].mimic;
2795 g_ptr->special = templates[id].special;
2800 if (++y >= ymax) break;
2805 /* Quest 18 was removed */
2806 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2808 for (POSITION y = 0; y < ymax; y++)
2810 for (POSITION x = 0; x < xmax; x++)
2812 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2814 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2816 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2818 g_ptr->feat = feat_tree;
2821 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2823 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2826 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2827 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2829 g_ptr->feat = feat_up_stair;
2836 C_KILL(templates, limit, grid_template_type);
2838 if (limit > current_world_ptr->max_o_idx) return 151;
2839 for (int i = 1; i < limit; i++)
2843 o_idx = o_pop(floor_ptr);
2844 if (i != o_idx) return 152;
2846 o_ptr = &floor_ptr->o_list[o_idx];
2849 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2851 monster_type *m_ptr;
2852 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2853 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2854 m_ptr->hold_o_idx = o_idx;
2858 grid_type *g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2859 o_ptr->next_o_idx = g_ptr->o_idx;
2860 g_ptr->o_idx = o_idx;
2865 if (limit > current_world_ptr->max_m_idx) return 161;
2867 for (int i = 1; i < limit; i++)
2871 monster_type *m_ptr;
2872 m_idx = m_pop(player_ptr);
2873 if (i != m_idx) return 162;
2875 m_ptr = &floor_ptr->m_list[m_idx];
2876 rd_monster(player_ptr, m_ptr);
2877 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2878 g_ptr->m_idx = m_idx;
2879 real_r_ptr(m_ptr)->cur_num++;
2887 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
2888 * @param player_ptr プレーヤーへの参照ポインタ
2891 * The monsters/objects must be loaded in the same order
2892 * that they were stored, since the actual indexes matter.
2894 static errr rd_dungeon(player_type *player_ptr)
2896 init_saved_floors(player_ptr, FALSE);
2898 if (h_older_than(1, 5, 0, 0))
2900 err = rd_dungeon_old(player_ptr);
2901 if (player_ptr->dungeon_idx)
2903 player_ptr->floor_id = get_new_floor_id(player_ptr);
2904 get_sf_ptr(player_ptr->floor_id)->dun_level = player_ptr->current_floor_ptr->dun_level;
2910 rd_s16b(&max_floor_id);
2913 player_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
2918 err = rd_saved_floor(player_ptr, NULL);
2922 for (int i = 0; i < num; i++)
2924 saved_floor_type *sf_ptr = &saved_floors[i];
2926 rd_s16b(&sf_ptr->floor_id);
2928 sf_ptr->savefile_id = (s16b)tmp8u;
2932 sf_ptr->dun_level = (DEPTH)tmp16s;
2934 rd_s32b(&sf_ptr->last_visit);
2935 rd_u32b(&sf_ptr->visit_mark);
2936 rd_s16b(&sf_ptr->upper_floor_id);
2937 rd_s16b(&sf_ptr->lower_floor_id);
2940 for (int i = 0; i < num; i++)
2942 saved_floor_type *sf_ptr = &saved_floors[i];
2943 if (!sf_ptr->floor_id) continue;
2945 if (tmp8u) continue;
2947 err = rd_saved_floor(player_ptr, sf_ptr);
2950 if (!save_floor(player_ptr, sf_ptr, SLF_SECOND)) err = 182;
2957 if (!load_floor(player_ptr, get_sf_ptr(player_ptr->floor_id), SLF_SECOND)) err = 183;
2964 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
2968 note(_("アイテム配置エラー", "Object allocation error"));
2972 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
2976 note(_("モンスター配置エラー", "Monster allocation error"));
2980 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
2984 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporary files!"));
2988 note(_("Error 183", "Error 183"));
2992 current_world_ptr->character_dungeon = TRUE;
2998 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3001 static errr rd_savefile_new_aux(player_type *creature_ptr)
3003 u32b n_x_check, n_v_check;
3004 u32b o_x_check, o_v_check;
3007 xor_byte = current_world_ptr->sf_extra;
3011 /* Old savefile will be version 0.0.0.3 */
3012 rd_byte(¤t_world_ptr->h_ver_extra);
3013 rd_byte(¤t_world_ptr->h_ver_patch);
3014 rd_byte(¤t_world_ptr->h_ver_minor);
3015 rd_byte(¤t_world_ptr->h_ver_major);
3018 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3019 (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));
3021 rd_u32b(¤t_world_ptr->sf_system);
3022 rd_u32b(¤t_world_ptr->sf_when);
3023 rd_u16b(¤t_world_ptr->sf_lives);
3024 rd_u16b(¤t_world_ptr->sf_saves);
3034 rd_byte(&kanji_code);
3037 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3040 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3043 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3045 for (int i = 0; i < max_r_idx; i++)
3047 monster_race *r_ptr = &r_info[i];
3048 r_ptr->max_num = 100;
3050 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3051 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3055 if (tmp16u > max_r_idx)
3057 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3061 for (int i = 0; i < tmp16u; i++)
3063 rd_lore((MONRACE_IDX)i);
3066 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3069 if (tmp16u > max_k_idx)
3071 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3075 for (int i = 0; i < tmp16u; i++)
3077 object_kind *k_ptr = &k_info[i];
3079 k_ptr->aware = (tmp8u & 0x01) ? TRUE : FALSE;
3080 k_ptr->tried = (tmp8u & 0x02) ? TRUE : FALSE;
3082 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3084 /* 2.1.3 or newer version */
3086 u16b max_towns_load;
3087 u16b max_quests_load;
3088 byte max_rquests_load;
3089 s16b old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
3091 rd_u16b(&max_towns_load);
3092 if (max_towns_load > max_towns)
3094 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3098 rd_u16b(&max_quests_load);
3099 if (z_older_than(11, 0, 7))
3101 max_rquests_load = 10;
3105 rd_byte(&max_rquests_load);
3108 if (max_quests_load > max_q_idx)
3110 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3114 for (int i = 0; i < max_quests_load; i++)
3123 quest_type* const q_ptr = &quest[i];
3125 rd_s16b(&q_ptr->status);
3128 q_ptr->level = tmp16s;
3130 if (z_older_than(11, 0, 6))
3137 q_ptr->complev = tmp8u;
3139 if (h_older_than(2, 1, 2, 2))
3141 q_ptr->comptime = 0;
3145 rd_u32b(&q_ptr->comptime);
3148 bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
3149 is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
3150 is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
3151 if (!is_quest_running) continue;
3154 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3156 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3157 rd_s16b(&q_ptr->type);
3159 rd_s16b(&q_ptr->r_idx);
3160 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3162 determine_random_questor(creature_ptr, &quest[i]);
3165 rd_s16b(&q_ptr->k_idx);
3167 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3170 q_ptr->flags = tmp8u;
3172 if (z_older_than(10, 3, 11))
3174 if (q_ptr->flags & QUEST_FLAG_PRESET)
3180 init_flags = INIT_ASSIGN;
3181 creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)i;
3183 parse_fixed_map(creature_ptr, "q_info.txt", 0, 0, 0, 0);
3184 creature_ptr->current_floor_ptr->inside_quest = old_inside_quest;
3190 q_ptr->dungeon = tmp8u;
3193 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3194 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3195 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3198 /* Quest 18 was removed */
3199 if (h_older_than(1, 7, 0, 6))
3201 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3202 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3205 rd_s32b(&creature_ptr->wilderness_x);
3206 rd_s32b(&creature_ptr->wilderness_y);
3207 if (z_older_than(10, 3, 13))
3209 creature_ptr->wilderness_x = 5;
3210 creature_ptr->wilderness_y = 48;
3213 if (z_older_than(10, 3, 7)) creature_ptr->wild_mode = FALSE;
3214 else rd_byte((byte *)&creature_ptr->wild_mode);
3215 if (z_older_than(10, 3, 7)) creature_ptr->ambush_flag = FALSE;
3216 else rd_byte((byte *)&creature_ptr->ambush_flag);
3220 rd_s32b(&wild_x_size);
3221 rd_s32b(&wild_y_size);
3223 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3225 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3229 for (int i = 0; i < wild_x_size; i++)
3231 for (int j = 0; j < wild_y_size; j++)
3233 rd_u32b(&wilderness[j][i].seed);
3238 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3241 if (tmp16u > max_a_idx)
3243 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3247 for (int i = 0; i < tmp16u; i++)
3249 artifact_type *a_ptr = &a_info[i];
3252 a_ptr->cur_num = tmp8u;
3254 if (h_older_than(1, 5, 0, 0))
3256 a_ptr->floor_id = 0;
3264 rd_s16b(&a_ptr->floor_id);
3268 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3270 rd_extra(creature_ptr);
3271 if (creature_ptr->energy_need < -999) creature_ptr->timewalk = TRUE;
3273 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3276 if (tmp16u > PY_MAX_LEVEL)
3278 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3282 for (int i = 0; i < tmp16u; i++)
3286 creature_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3289 sp_ptr = &sex_info[creature_ptr->psex];
3290 rp_ptr = &race_info[creature_ptr->prace];
3291 cp_ptr = &class_info[creature_ptr->pclass];
3292 ap_ptr = &seikaku_info[creature_ptr->pseikaku];
3294 if (z_older_than(10, 2, 2) && (creature_ptr->pclass == CLASS_BEASTMASTER) && !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 if (z_older_than(10, 3, 2) && (creature_ptr->pclass == CLASS_ARCHER) && !creature_ptr->is_dead)
3302 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3303 roll_hitdice(creature_ptr, 0L);
3306 if (z_older_than(10, 2, 6) && (creature_ptr->pclass == CLASS_SORCERER) && !creature_ptr->is_dead)
3308 creature_ptr->hitdie = rp_ptr->r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3309 roll_hitdice(creature_ptr, 0L);
3312 if (z_older_than(10, 4, 7) && (creature_ptr->pclass == CLASS_BLUE_MAGE) && !creature_ptr->is_dead)
3314 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3315 roll_hitdice(creature_ptr, 0L);
3318 mp_ptr = &m_info[creature_ptr->pclass];
3320 rd_u32b(&creature_ptr->spell_learned1);
3321 rd_u32b(&creature_ptr->spell_learned2);
3322 rd_u32b(&creature_ptr->spell_worked1);
3323 rd_u32b(&creature_ptr->spell_worked2);
3324 rd_u32b(&creature_ptr->spell_forgotten1);
3325 rd_u32b(&creature_ptr->spell_forgotten2);
3327 if (z_older_than(10, 0, 5))
3329 creature_ptr->learned_spells = 0;
3330 for (int i = 0; i < 64; i++)
3333 (creature_ptr->spell_learned1 & (1L << i)) :
3334 (creature_ptr->spell_learned2 & (1L << (i - 32))))
3336 creature_ptr->learned_spells++;
3340 else rd_s16b(&creature_ptr->learned_spells);
3342 if (z_older_than(10, 0, 6))
3344 creature_ptr->add_spells = 0;
3346 else rd_s16b(&creature_ptr->add_spells);
3348 if (creature_ptr->pclass == CLASS_MINDCRAFTER) creature_ptr->add_spells = 0;
3350 for (int i = 0; i < 64; i++)
3353 creature_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3356 if (rd_inventory(creature_ptr))
3358 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3363 int town_count = tmp16u;
3366 for (int i = 1; i < town_count; i++)
3368 for (int j = 0; j < tmp16u; j++)
3370 if (rd_store(creature_ptr, i, j)) return (22);
3374 rd_s16b(&creature_ptr->pet_follow_distance);
3375 if (z_older_than(10, 4, 10))
3377 creature_ptr->pet_extra_flags = 0;
3379 if (tmp8u) creature_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3381 if (tmp8u) creature_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3383 if (z_older_than(10, 0, 4)) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3387 if (tmp8u) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3390 if (z_older_than(10, 0, 7)) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3394 if (tmp8u) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3397 if (z_older_than(10, 0, 8)) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3401 if (tmp8u) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3404 if (!z_older_than(10, 0, 8))
3407 if (tmp8u) creature_ptr->pet_extra_flags |= PF_BALL_SPELL;
3412 rd_s16b(&creature_ptr->pet_extra_flags);
3415 if (!z_older_than(11, 0, 9))
3417 char buf[SCREEN_BUF_MAX_SIZE];
3418 rd_string(buf, sizeof(buf));
3419 if (buf[0]) screen_dump = string_make(buf);
3422 if (creature_ptr->is_dead)
3424 for (int i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3426 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3430 if (!creature_ptr->is_dead)
3432 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3433 if (rd_dungeon(creature_ptr))
3435 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3444 strip_bytes(tmp32s);
3448 /* Quest 18 was removed */
3449 if (h_older_than(1, 7, 0, 6))
3451 if (creature_ptr->current_floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3453 creature_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3454 creature_ptr->current_floor_ptr->dun_level = 1;
3455 creature_ptr->current_floor_ptr->inside_quest = 0;
3459 n_v_check = v_check;
3460 rd_u32b(&o_v_check);
3461 if (o_v_check != n_v_check)
3463 note(_("チェックサムがおかしい", "Invalid checksum"));
3467 n_x_check = x_check;
3468 rd_u32b(&o_x_check);
3469 if (o_x_check != n_x_check)
3471 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3480 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3481 * @param player_ptr プレーヤーへの参照ポインタ
3484 errr rd_savefile_new(player_type *player_ptr)
3487 fff = my_fopen(savefile, "rb");
3489 if (!fff) return -1;
3490 errr err = rd_savefile_new_aux(player_ptr);
3492 if (ferror(fff)) err = -1;
3499 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3500 * @param player_ptr プレーヤーへの参照ポインタ
3501 * @param sf_ptr 保存フロア読み込み先
3504 static bool load_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
3506 u32b n_x_check, n_v_check;
3507 u32b o_x_check, o_v_check;
3516 current_world_ptr->h_ver_extra = H_VER_EXTRA;
3517 current_world_ptr->h_ver_patch = H_VER_PATCH;
3518 current_world_ptr->h_ver_minor = H_VER_MINOR;
3519 current_world_ptr->h_ver_major = H_VER_MAJOR;
3523 if (saved_floor_file_sign != tmp32u) return FALSE;
3525 if (rd_saved_floor(player_ptr, sf_ptr)) return FALSE;
3527 n_v_check = v_check;
3528 rd_u32b(&o_v_check);
3530 if (o_v_check != n_v_check) return FALSE;
3532 n_x_check = x_check;
3533 rd_u32b(&o_x_check);
3535 if (o_x_check != n_x_check) return FALSE;
3541 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporarily saved-floor data
3542 * @param player_ptr プレーヤーへの参照ポインタ
3543 * @param sf_ptr 保存フロア読み込み先
3547 bool load_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
3550 * Temporary files are always written in system depended kanji
3564 FILE *old_fff = NULL;
3565 byte old_xor_byte = 0;
3566 u32b old_v_check = 0;
3567 u32b old_x_check = 0;
3568 byte old_h_ver_major = 0;
3569 byte old_h_ver_minor = 0;
3570 byte old_h_ver_patch = 0;
3571 byte old_h_ver_extra = 0;
3572 if (mode & SLF_SECOND)
3575 old_xor_byte = xor_byte;
3576 old_v_check = v_check;
3577 old_x_check = x_check;
3578 old_h_ver_major = current_world_ptr->h_ver_major;
3579 old_h_ver_minor = current_world_ptr->h_ver_minor;
3580 old_h_ver_patch = current_world_ptr->h_ver_patch;
3581 old_h_ver_extra = current_world_ptr->h_ver_extra;
3584 char floor_savefile[1024];
3585 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3588 fff = my_fopen(floor_savefile, "rb");
3591 bool is_save_successful = TRUE;
3592 if (!fff) is_save_successful = FALSE;
3594 if (is_save_successful)
3596 is_save_successful = load_floor_aux(player_ptr, sf_ptr);
3597 if (ferror(fff)) is_save_successful = FALSE;
3601 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3606 if (mode & SLF_SECOND)
3609 xor_byte = old_xor_byte;
3610 v_check = old_v_check;
3611 x_check = old_x_check;
3612 current_world_ptr->h_ver_major = old_h_ver_major;
3613 current_world_ptr->h_ver_minor = old_h_ver_minor;
3614 current_world_ptr->h_ver_patch = old_h_ver_patch;
3615 current_world_ptr->h_ver_extra = old_h_ver_extra;
3618 byte old_kanji_code = kanji_code;
3619 kanji_code = old_kanji_code;
3620 return is_save_successful;