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/monster-info.h"
72 #include "monster/monster2.h"
73 #include "mutation/mutation.h"
74 #include "object-enchant/artifact.h"
75 #include "object-enchant/object-ego.h"
76 #include "object-enchant/old-ego-extra-values.h" // TODO v1.5.0以前のセーブファイルをロードする処理を分離する.
77 #include "object-enchant/tr-types.h"
78 #include "object-enchant/trc-types.h"
79 #include "object-enchant/trg-types.h"
80 #include "object/object-flags.h"
81 #include "object/object-generator.h"
82 #include "object/object-hook.h"
83 #include "object/object-kind-hook.h"
84 #include "object/object-kind.h"
85 #include "object/object-mark-types.h"
86 #include "object/object-stack.h"
87 #include "object/object-value.h"
88 #include "pet/pet-util.h"
89 #include "player/avatar.h"
90 #include "player/patron.h"
91 #include "player/player-class.h"
92 #include "player/player-personality.h"
93 #include "player/player-races-table.h"
94 #include "player/player-sex.h"
95 #include "player/player-skill.h"
96 #include "player/race-info-table.h"
97 #include "spell/spells-status.h"
98 #include "store/store-util.h"
99 #include "store/store.h"
100 #include "sv-definition/sv-armor-types.h"
101 #include "sv-definition/sv-lite-types.h"
102 #include "system/angband-version.h"
103 #include "system/system-variables.h" // 暫定、init_flags の扱いを決めた上で消す.
104 #include "util/object-sort.h"
105 #include "util/util.h"
106 #include "world/world-object.h"
107 #include "world/world.h"
110 * Maximum number of tries for selection of a proper quest monster
112 #define MAX_TRIES 100
114 #define OLD_MAX_MANE 22
116 /* Old hidden trap flag */
117 #define CAVE_TRAP 0x8000
119 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
120 #define OLD_FEAT_INVIS 0x02
121 #define OLD_FEAT_GLYPH 0x03
122 #define OLD_FEAT_QUEST_ENTER 0x08
123 #define OLD_FEAT_QUEST_EXIT 0x09
124 #define OLD_FEAT_MINOR_GLYPH 0x40
125 #define OLD_FEAT_BLDG_1 0x81
126 #define OLD_FEAT_MIRROR 0xc3
129 #define OLD_QUEST_WATER_CAVE 18
131 /* Quest constants */
132 #define QUEST_OLD_CASTLE 27
133 #define QUEST_ROYAL_CRYPT 28
136 * Local "savefile" pointer
141 * Hack -- old "encryption" byte
143 static byte xor_byte;
146 * Hack -- simple "checksum" on the actual values
148 static u32b v_check = 0L;
151 * Hack -- simple "checksum" on the encoded bytes
153 static u32b x_check = 0L;
156 * Hack -- Japanese Kanji code
162 static byte kanji_code = 0;
165 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
166 * @param major メジャーバージョン値
167 * @param minor マイナーバージョン値
168 * @param patch パッチバージョン値
169 * @param extra エクストラパージョン値
170 * @return 現在のバージョンより値が古いならtrue
172 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
174 if (current_world_ptr->h_ver_major < major) return TRUE;
175 if (current_world_ptr->h_ver_major > major) return FALSE;
177 if (current_world_ptr->h_ver_minor < minor) return TRUE;
178 if (current_world_ptr->h_ver_minor > minor) return FALSE;
180 if (current_world_ptr->h_ver_patch < patch) return TRUE;
181 if (current_world_ptr->h_ver_patch > patch) return FALSE;
183 if (current_world_ptr->h_ver_extra < extra) return TRUE;
184 if (current_world_ptr->h_ver_extra > extra) return FALSE;
191 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
192 * @param x メジャーバージョン値
193 * @param y マイナーバージョン値
195 * @return 現在のバージョンより値が古いならtrue
197 static bool z_older_than(byte x, byte y, byte z)
199 if (current_world_ptr->z_major < x) return TRUE;
200 if (current_world_ptr->z_major > x) return FALSE;
202 if (current_world_ptr->z_minor < y) return TRUE;
203 if (current_world_ptr->z_minor > y) return FALSE;
205 if (current_world_ptr->z_patch < z) return TRUE;
206 if (current_world_ptr->z_patch > z) return FALSE;
213 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
217 * Avoid the top two lines, to avoid interference with "msg_print()".
219 static void note(concptr msg)
221 static TERM_LEN y = 2;
223 if (++y >= 24) y = 2;
230 * @brief ロードファイルポインタから1バイトを読み込む
233 * The following functions are used to load the basic building blocks
234 * of savefiles. They also maintain the "checksum" info for 2.7.0+
236 static byte sf_get(void)
238 byte c = getc(fff) & 0xFF;
239 byte v = c ^ xor_byte;
249 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
253 static void rd_byte(byte *ip)
260 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
264 static void rd_u16b(u16b *ip)
267 (*ip) |= ((u16b)(sf_get()) << 8);
272 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
276 static void rd_s16b(s16b *ip)
283 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
287 static void rd_u32b(u32b *ip)
290 (*ip) |= ((u32b)(sf_get()) << 8);
291 (*ip) |= ((u32b)(sf_get()) << 16);
292 (*ip) |= ((u32b)(sf_get()) << 24);
297 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
301 static void rd_s32b(s32b *ip)
308 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
309 * @param str 読み込みポインタ
310 * @param max 最大読み取りバイト数
313 static void rd_string(char *str, int max)
315 for (int i = 0; TRUE; i++)
319 if (i < max) str[i] = tmp8u;
342 byte code = codeconv(str);
344 /* 漢字コードが判明したら、それを記録 */
345 if (code) kanji_code = code;
357 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
361 static void strip_bytes(int n)
364 while (n--) rd_byte(&tmp8u);
369 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
370 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
373 * This function attempts to "repair" old savefiles, and to extract
374 * the most up to date values for various object fields.
376 * Note that Angband 2.7.9 introduced a new method for object "flags"
377 * in which the "flags" on an object are actually extracted when they
378 * are needed from the object kind, artifact index, ego-item index,
379 * and two special "xtra" fields which are used to encode any "extra"
380 * power of certain ego-items. This had the side effect that items
381 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
382 * may have had, and also, all "uncursed" items will become "cursed"
383 * again, including Calris, even if it is being worn at the time. As
384 * a complete hack, items which are inscribed with "uncursed" will be
385 * "uncursed" when imported from pre-2.7.9 savefiles.
387 static void rd_item_old(object_type *o_ptr)
389 rd_s16b(&o_ptr->k_idx);
393 o_ptr->iy = (POSITION)tmp8u;
395 o_ptr->ix = (POSITION)tmp8u;
403 if (z_older_than(10, 4, 4))
405 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
406 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
407 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
410 rd_s16b(&o_ptr->pval);
411 rd_byte(&o_ptr->discount);
413 o_ptr->number = (ITEM_NUMBER)tmp8u;
417 o_ptr->weight = tmp16s;
420 o_ptr->name1 = tmp8u;
423 o_ptr->name2 = tmp8u;
425 rd_s16b(&o_ptr->timeout);
426 rd_s16b(&o_ptr->to_h);
428 o_ptr->to_d = tmp16s;
430 rd_s16b(&o_ptr->to_a);
438 rd_byte(&o_ptr->ident);
439 rd_byte(&o_ptr->marked);
440 rd_u32b(&o_ptr->art_flags[0]);
441 rd_u32b(&o_ptr->art_flags[1]);
442 rd_u32b(&o_ptr->art_flags[2]);
443 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
444 else rd_u32b(&o_ptr->art_flags[3]);
446 if (h_older_than(1, 3, 0, 0))
448 if (o_ptr->name2 == EGO_TELEPATHY)
449 add_flag(o_ptr->art_flags, TR_TELEPATHY);
452 if (z_older_than(11, 0, 11))
454 o_ptr->curse_flags = 0L;
455 if (o_ptr->ident & 0x40)
457 o_ptr->curse_flags |= TRC_CURSED;
458 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
459 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
460 if (object_is_fixed_artifact(o_ptr))
462 artifact_type *a_ptr = &a_info[o_ptr->name1];
463 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
464 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
466 else if (object_is_ego(o_ptr))
468 ego_item_type *e_ptr = &e_info[o_ptr->name2];
469 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
470 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
473 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
477 rd_u32b(&o_ptr->curse_flags);
480 rd_s16b(&o_ptr->held_m_idx);
481 rd_byte(&o_ptr->xtra1);
482 rd_byte(&o_ptr->xtra2);
484 if (z_older_than(11, 0, 10))
486 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
488 switch (o_ptr->xtra2 % 6)
490 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
491 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
492 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
493 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
494 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
495 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
499 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
501 switch (o_ptr->xtra2 % 11)
503 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
504 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
505 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
506 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
507 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
508 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
509 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
510 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
511 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
512 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
513 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
517 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
519 switch (o_ptr->xtra2 % 8)
521 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
522 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
523 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
524 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
525 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
526 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
527 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
528 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
535 if (z_older_than(10, 2, 3))
540 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
542 o_ptr->xtra3 = o_ptr->xtra1;
545 if (o_ptr->tval == TV_CAPTURE)
547 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
548 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
550 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
551 if (ironman_nightmare)
553 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5 * 2L);
555 o_ptr->xtra4 = o_ptr->xtra5;
560 rd_byte(&o_ptr->xtra3);
561 if (h_older_than(1, 3, 0, 1))
563 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1 + 96)
564 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
567 rd_s16b(&o_ptr->xtra4);
568 rd_s16b(&o_ptr->xtra5);
571 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)))
573 o_ptr->xtra4 = o_ptr->pval;
577 rd_byte(&o_ptr->feeling);
580 rd_string(buf, sizeof(buf));
581 if (buf[0]) o_ptr->inscription = quark_add(buf);
583 rd_string(buf, sizeof(buf));
585 /* todo 元々このif文には末尾に";"が付いていた、バグかもしれない */
586 if (buf[0]) o_ptr->art_name = quark_add(buf);
594 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
596 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
598 if (z_older_than(10, 4, 9))
600 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
602 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
603 add_flag(o_ptr->art_flags, TR_DEC_MANA);
607 if (object_is_fixed_artifact(o_ptr))
609 artifact_type *a_ptr;
610 a_ptr = &a_info[o_ptr->name1];
611 if (!a_ptr->name) o_ptr->name1 = 0;
614 if (object_is_ego(o_ptr))
616 ego_item_type *e_ptr;
617 e_ptr = &e_info[o_ptr->name2];
618 if (!e_ptr->name) o_ptr->name2 = 0;
624 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
625 * @param o_ptr アイテムオブジェクト保存先ポインタ
628 static void rd_item(object_type *o_ptr)
630 if (h_older_than(1, 5, 0, 0))
638 rd_s16b(&o_ptr->k_idx);
642 o_ptr->iy = (POSITION)tmp8u;
644 o_ptr->ix = (POSITION)tmp8u;
647 k_ptr = &k_info[o_ptr->k_idx];
648 o_ptr->tval = k_ptr->tval;
649 o_ptr->sval = k_ptr->sval;
651 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
652 else o_ptr->pval = 0;
654 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
655 else o_ptr->discount = 0;
656 if (flags & SAVE_ITEM_NUMBER) {
658 o_ptr->number = tmp8u;
660 else o_ptr->number = 1;
664 o_ptr->weight = tmp16s;
666 if (flags & SAVE_ITEM_NAME1)
669 o_ptr->name1 = tmp8u;
671 else o_ptr->name1 = 0;
673 if (flags & SAVE_ITEM_NAME2)
676 o_ptr->name2 = tmp8u;
678 else o_ptr->name2 = 0;
680 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
681 else o_ptr->timeout = 0;
683 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
684 else o_ptr->to_h = 0;
686 if (flags & SAVE_ITEM_TO_D)
689 o_ptr->to_d = tmp16s;
691 else o_ptr->to_d = 0;
693 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
694 else o_ptr->to_a = 0;
696 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
699 if (flags & SAVE_ITEM_DD)
706 if (flags & SAVE_ITEM_DS)
713 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
714 else o_ptr->ident = 0;
716 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
717 else o_ptr->marked = 0;
720 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
721 else o_ptr->art_flags[0] = 0;
723 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
724 else o_ptr->art_flags[1] = 0;
726 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
727 else o_ptr->art_flags[2] = 0;
729 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
730 else o_ptr->art_flags[3] = 0;
732 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
733 else o_ptr->art_flags[4] = 0;
735 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
736 else o_ptr->curse_flags = 0;
738 /* Monster holding object */
739 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
740 else o_ptr->held_m_idx = 0;
743 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
744 else o_ptr->xtra1 = 0;
746 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
747 else o_ptr->xtra2 = 0;
749 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
750 else o_ptr->xtra3 = 0;
752 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
753 else o_ptr->xtra4 = 0;
755 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
756 else o_ptr->xtra5 = 0;
758 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
759 else o_ptr->feeling = 0;
761 if (flags & SAVE_ITEM_INSCRIPTION)
764 rd_string(buf, sizeof(buf));
765 o_ptr->inscription = quark_add(buf);
767 else o_ptr->inscription = 0;
769 if (flags & SAVE_ITEM_ART_NAME)
772 rd_string(buf, sizeof(buf));
773 o_ptr->art_name = quark_add(buf);
780 if (!h_older_than(2, 1, 2, 4)) return;
782 BIT_FLAGS flgs[TR_FLAG_SIZE];
783 object_flags(o_ptr, flgs);
785 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
787 add_flag(o_ptr->art_flags, TR_LITE_M1);
788 remove_flag(o_ptr->art_flags, TR_LITE_1);
789 remove_flag(o_ptr->art_flags, TR_LITE_2);
790 remove_flag(o_ptr->art_flags, TR_LITE_3);
794 if (o_ptr->name2 == EGO_LITE_DARKNESS)
796 if (o_ptr->tval != TV_LITE)
798 add_flag(o_ptr->art_flags, TR_LITE_M1);
802 if (o_ptr->sval == SV_LITE_TORCH)
804 add_flag(o_ptr->art_flags, TR_LITE_M1);
806 else if (o_ptr->sval == SV_LITE_LANTERN)
808 add_flag(o_ptr->art_flags, TR_LITE_M2);
810 else if (o_ptr->sval == SV_LITE_FEANOR)
812 add_flag(o_ptr->art_flags, TR_LITE_M3);
818 if (o_ptr->tval == TV_LITE)
820 if (object_is_fixed_artifact(o_ptr))
822 add_flag(o_ptr->art_flags, TR_LITE_3);
826 if (o_ptr->sval == SV_LITE_TORCH)
828 add_flag(o_ptr->art_flags, TR_LITE_1);
829 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
833 if (o_ptr->sval == SV_LITE_LANTERN)
835 add_flag(o_ptr->art_flags, TR_LITE_2);
836 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
840 if (o_ptr->sval == SV_LITE_FEANOR)
842 add_flag(o_ptr->art_flags, TR_LITE_2);
850 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
851 * @param player_ptr プレーヤーへの参照ポインタ
852 * @param m_ptr モンスター保存先ポインタ
855 static void rd_monster_old(player_type *player_ptr, monster_type *m_ptr)
857 rd_s16b(&m_ptr->r_idx);
859 if (z_older_than(11, 0, 12))
860 m_ptr->ap_r_idx = m_ptr->r_idx;
862 rd_s16b(&m_ptr->ap_r_idx);
864 if (z_older_than(11, 0, 14))
866 monster_race *r_ptr = &r_info[m_ptr->r_idx];
868 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
869 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
870 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
873 rd_byte(&m_ptr->sub_align);
877 m_ptr->fy = (POSITION)tmp8u;
879 m_ptr->fx = (POSITION)tmp8u;
880 m_ptr->current_floor_ptr = player_ptr->current_floor_ptr;
886 m_ptr->maxhp = tmp16s;
888 if (z_older_than(11, 0, 5))
890 m_ptr->max_maxhp = m_ptr->maxhp;
895 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
897 if (h_older_than(2, 1, 2, 1))
899 m_ptr->dealt_damage = 0;
903 rd_s32b(&m_ptr->dealt_damage);
906 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
908 m_ptr->mspeed = tmp8u;
910 if (z_older_than(10, 4, 2))
913 m_ptr->energy_need = (s16b)tmp8u;
915 else rd_s16b(&m_ptr->energy_need);
917 if (z_older_than(11, 0, 13))
918 m_ptr->energy_need = 100 - m_ptr->energy_need;
920 if (z_older_than(10, 0, 7))
922 m_ptr->mtimed[MTIMED_FAST] = 0;
923 m_ptr->mtimed[MTIMED_SLOW] = 0;
928 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
930 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
934 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
936 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
938 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
940 if (z_older_than(10, 0, 10))
944 else if (z_older_than(10, 0, 11))
952 m_ptr->target_y = (POSITION)tmp16s;
954 m_ptr->target_x = (POSITION)tmp16s;
958 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
960 if (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6))
961 rd_u32b(&m_ptr->smart);
966 if (z_older_than(10, 4, 5))
976 if (z_older_than(10, 2, 2))
978 if (m_ptr->r_idx < 0)
980 m_ptr->r_idx = (0 - m_ptr->r_idx);
981 m_ptr->mflag2 |= MFLAG2_KAGE;
986 rd_byte(&m_ptr->mflag2);
989 if (z_older_than(11, 0, 12))
991 if (m_ptr->mflag2 & MFLAG2_KAGE)
992 m_ptr->ap_r_idx = MON_KAGE;
995 if (z_older_than(10, 1, 3))
1002 rd_string(buf, sizeof(buf));
1003 if (buf[0]) m_ptr->nickname = quark_add(buf);
1011 * @brief モンスターを読み込む(現版) / Read a monster (New method)
1012 * @param player_ptr プレーヤーへの参照ポインタ
1013 * @param m_ptr モンスター保存先ポインタ
1016 static void rd_monster(player_type *player_ptr, monster_type *m_ptr)
1018 if (h_older_than(1, 5, 0, 0))
1020 rd_monster_old(player_ptr, m_ptr);
1026 rd_s16b(&m_ptr->r_idx);
1029 m_ptr->fy = (POSITION)tmp8u;
1031 m_ptr->fx = (POSITION)tmp8u;
1035 m_ptr->hp = (HIT_POINT)tmp16s;
1037 m_ptr->maxhp = (HIT_POINT)tmp16s;
1039 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1041 if (h_older_than(2, 1, 2, 1))
1043 m_ptr->dealt_damage = 0;
1047 rd_s32b(&m_ptr->dealt_damage);
1050 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1051 else m_ptr->ap_r_idx = m_ptr->r_idx;
1053 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1054 else m_ptr->sub_align = 0;
1056 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1057 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1060 m_ptr->mspeed = tmp8u;
1062 rd_s16b(&m_ptr->energy_need);
1064 if (flags & SAVE_MON_FAST)
1067 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1069 else m_ptr->mtimed[MTIMED_FAST] = 0;
1071 if (flags & SAVE_MON_SLOW)
1074 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1076 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1078 if (flags & SAVE_MON_STUNNED)
1081 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1083 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1085 if (flags & SAVE_MON_CONFUSED)
1088 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1090 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1092 if (flags & SAVE_MON_MONFEAR)
1095 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1097 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1099 if (flags & SAVE_MON_TARGET_Y)
1102 m_ptr->target_y = (POSITION)tmp16s;
1104 else m_ptr->target_y = 0;
1106 if (flags & SAVE_MON_TARGET_X)
1109 m_ptr->target_x = (POSITION)tmp16s;
1111 else m_ptr->target_x = 0;
1113 if (flags & SAVE_MON_INVULNER)
1116 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1118 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1120 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1121 else m_ptr->smart = 0;
1123 if (flags & SAVE_MON_EXP)
1127 m_ptr->exp = (EXP)tmp32u;
1129 else m_ptr->exp = 0;
1131 m_ptr->mflag = 0; /* Not saved */
1133 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1134 else m_ptr->mflag2 = 0;
1136 if (flags & SAVE_MON_NICKNAME)
1139 rd_string(buf, sizeof(buf));
1140 m_ptr->nickname = quark_add(buf);
1142 else m_ptr->nickname = 0;
1144 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1145 else m_ptr->parent_m_idx = 0;
1150 * Old monster bit flags of racial resistances
1152 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1153 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1154 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1155 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1156 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1157 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1158 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1159 #define RF3_RES_WATE 0x00800000 /* Resist water */
1160 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1161 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1162 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1163 #define RF3_RES_ALL 0x08000000 /* Resist all */
1165 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1167 if ((R_PTR)->r_flags3 & (RF3)) \
1169 (R_PTR)->r_flags3 &= ~(RF3); \
1170 (R_PTR)->r_flagsr |= (RFR); \
1174 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1176 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1178 (R_PTR)->r_flagsr |= (RFR); \
1182 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1183 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1184 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1185 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1186 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1187 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1188 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1189 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1190 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1191 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1194 * @brief モンスターの思い出を読み込む / Read the monster lore
1195 * @param r_idx 読み込み先モンスターID
1198 static void rd_lore(MONRACE_IDX r_idx)
1200 monster_race *r_ptr = &r_info[r_idx];
1204 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1207 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1210 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1212 if (h_older_than(1, 7, 0, 5))
1214 r_ptr->r_akills = r_ptr->r_pkills;
1219 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1223 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1225 rd_byte(&r_ptr->r_wake);
1226 rd_byte(&r_ptr->r_ignore);
1227 rd_byte(&r_ptr->r_xtra1);
1228 rd_byte(&r_ptr->r_xtra2);
1232 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1234 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1237 rd_byte(&r_ptr->r_cast_spell);
1239 rd_byte(&r_ptr->r_blows[0]);
1240 rd_byte(&r_ptr->r_blows[1]);
1241 rd_byte(&r_ptr->r_blows[2]);
1242 rd_byte(&r_ptr->r_blows[3]);
1244 rd_u32b(&r_ptr->r_flags1);
1245 rd_u32b(&r_ptr->r_flags2);
1246 rd_u32b(&r_ptr->r_flags3);
1247 rd_u32b(&r_ptr->r_flags4);
1248 rd_u32b(&r_ptr->r_flags5);
1249 rd_u32b(&r_ptr->r_flags6);
1250 if (h_older_than(1, 5, 0, 3))
1252 r_ptr->r_flagsr = 0L;
1253 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1254 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1255 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1256 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1257 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1258 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1259 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1260 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1261 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1262 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1263 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1264 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1266 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1267 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1268 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1269 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1270 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1271 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1272 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1273 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1274 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1276 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1277 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1278 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1282 rd_u32b(&r_ptr->r_flagsr);
1286 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1288 rd_s16b(&r_ptr->floor_id);
1291 r_ptr->r_flags1 &= r_ptr->flags1;
1292 r_ptr->r_flags2 &= r_ptr->flags2;
1293 r_ptr->r_flags3 &= r_ptr->flags3;
1294 r_ptr->r_flags4 &= r_ptr->flags4;
1295 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1296 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1297 r_ptr->r_flagsr &= r_ptr->flagsr;
1302 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1303 * @param player_ptr プレーヤーへの参照ポインタ
1304 * @param store_ptr 店舗の参照ポインタ
1305 * @param o_ptr アイテムオブジェクト参照ポインタ
1308 * In all cases, return the slot (or -1) where the object was placed
1310 * Note that this is a hacked up version of "store_item_to_inventory()".
1312 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1313 * known, the player may have to pick stuff up and drop it again.
1315 static void home_carry(player_type *player_ptr, store_type *store_ptr, object_type *o_ptr)
1317 for (int i = 0; i < store_ptr->stock_num; i++)
1320 j_ptr = &store_ptr->stock[i];
1321 if (!object_similar(j_ptr, o_ptr)) continue;
1323 object_absorb(j_ptr, o_ptr);
1327 if (store_ptr->stock_num >= STORE_INVEN_MAX * 10) return;
1329 s32b value = object_value(o_ptr);
1331 for (slot = 0; slot < store_ptr->stock_num; slot++)
1333 if (object_sort_comp(o_ptr, value, &store_ptr->stock[slot])) break;
1336 for (int i = store_ptr->stock_num; i > slot; i--)
1338 store_ptr->stock[i] = store_ptr->stock[i - 1];
1341 store_ptr->stock_num++;
1342 store_ptr->stock[slot] = *o_ptr;
1343 chg_virtue(player_ptr, V_SACRIFICE, -1);
1348 * @brief 店舗情報を読み込む / Read a store
1349 * @param player_ptr プレーヤーへの参照ポインタ
1350 * @param town_number 街ID
1351 * @param store_number 店舗ID
1354 static errr rd_store(player_type *player_ptr, int town_number, int store_number)
1356 store_type *store_ptr;
1358 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1360 store_ptr = &town_info[1].store[store_number];
1361 if (store_ptr->stock_num) sort = TRUE;
1365 store_ptr = &town_info[town_number].store[store_number];
1371 rd_s32b(&store_ptr->store_open);
1372 rd_s16b(&store_ptr->insult_cur);
1374 if (z_older_than(11, 0, 4))
1384 rd_s16b(&store_ptr->good_buy);
1385 rd_s16b(&store_ptr->bad_buy);
1387 rd_s32b(&store_ptr->last_visit);
1388 store_ptr->owner = own;
1390 for (int j = 0; j < num; j++)
1399 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);
1400 if (!is_valid_item) continue;
1404 home_carry(player_ptr, store_ptr, q_ptr);
1408 int k = store_ptr->stock_num++;
1409 object_copy(&store_ptr->stock[k], q_ptr);
1418 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1421 static void rd_randomizer(void)
1425 rd_u16b(&Rand_place);
1426 for (int i = 0; i < RAND_DEG; i++)
1428 rd_u32b(&Rand_state[i]);
1434 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1437 * Note that the normal options are now stored as a set of 256 bit flags,
1438 * plus a set of 256 bit masks to indicate which bit flags were defined
1439 * at the time the savefile was created. This will allow new options
1440 * to be added, and old options to be removed, at any time, without
1441 * hurting old savefiles.
1443 * The window options are stored in the same way, but note that each
1444 * window gets 32 options, and their order is fixed by certain defines.
1446 static void rd_options(void)
1457 if (h_older_than(1, 7, 0, 0))
1470 if (c & 0x0002) current_world_ptr->wizard = TRUE;
1472 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1473 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1474 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1475 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1476 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1477 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1478 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1479 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1480 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1481 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1483 rd_byte((byte *)&autosave_l);
1484 rd_byte((byte *)&autosave_t);
1485 rd_s16b(&autosave_freq);
1488 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1491 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1493 for (int n = 0; n < 8; n++)
1495 for (int i = 0; i < 32; i++)
1497 if (!(mask[n] & (1L << i))) continue;
1498 if (!(option_mask[n] & (1L << i))) continue;
1500 if (flag[n] & (1L << i))
1502 option_flag[n] |= (1L << i);
1506 option_flag[n] &= ~(1L << i);
1511 if (z_older_than(10, 4, 5))
1513 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1514 else option_flag[5] |= (0x00000001 << 4);
1515 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1516 else option_flag[2] |= (0x00000001 << 5);
1517 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1518 else option_flag[4] |= (0x00000001 << 5);
1519 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1520 else option_flag[5] |= (0x00000001 << 0);
1521 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1522 else option_flag[5] |= (0x00000001 << 12);
1523 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1524 else option_flag[1] |= (0x00000001 << 0);
1525 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1526 else option_flag[1] |= (0x00000001 << 18);
1527 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1528 else option_flag[1] |= (0x00000001 << 19);
1529 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1530 else option_flag[5] |= (0x00000001 << 3);
1533 extract_option_vars();
1534 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1536 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1538 for (int n = 0; n < 8; n++)
1540 for (int i = 0; i < 32; i++)
1542 if (!(mask[n] & (1L << i))) continue;
1543 if (!(window_mask[n] & (1L << i))) continue;
1545 if (flag[n] & (1L << i))
1547 window_flag[n] |= (1L << i);
1551 window_flag[n] &= ~(1L << i);
1559 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1562 * This is such a nasty hack it hurts.
1564 static void rd_ghost(void)
1567 rd_string(buf, sizeof(buf));
1573 * @brief クイックスタート情報を読み込む / Load quick start data
1576 static void load_quick_start(void)
1578 if (z_older_than(11, 0, 13))
1580 previous_char.quick_ok = FALSE;
1584 rd_byte(&previous_char.psex);
1587 previous_char.prace = (player_race_type)tmp8u;
1589 previous_char.pclass = (player_class_type)tmp8u;
1591 previous_char.pseikaku = (player_personality_type)tmp8u;
1593 previous_char.realm1 = (REALM_IDX)tmp8u;
1595 previous_char.realm2 = (REALM_IDX)tmp8u;
1597 rd_s16b(&previous_char.age);
1598 rd_s16b(&previous_char.ht);
1599 rd_s16b(&previous_char.wt);
1600 rd_s16b(&previous_char.sc);
1601 rd_s32b(&previous_char.au);
1603 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1604 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1606 for (int i = 0; i < PY_MAX_LEVEL; i++)
1610 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1613 rd_s16b(&previous_char.chaos_patron);
1615 for (int i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1617 for (int i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1621 previous_char.quick_ok = (bool)tmp8u;
1626 * @brief その他の情報を読み込む / Read the "extra" information
1629 static void rd_extra(player_type *creature_ptr)
1631 rd_string(creature_ptr->name, sizeof(creature_ptr->name));
1632 rd_string(creature_ptr->died_from, sizeof(creature_ptr->died_from));
1633 if (!h_older_than(1, 7, 0, 1))
1636 rd_string(buf, sizeof buf);
1637 if (buf[0]) creature_ptr->last_message = string_make(buf);
1641 for (int i = 0; i < 4; i++)
1643 rd_string(creature_ptr->history[i], sizeof(creature_ptr->history[i]));
1648 creature_ptr->prace = (player_race_type)tmp8u;
1651 creature_ptr->pclass = (player_class_type)tmp8u;
1654 creature_ptr->pseikaku = (player_personality_type)tmp8u;
1656 rd_byte(&creature_ptr->psex);
1658 creature_ptr->realm1 = (REALM_IDX)tmp8u;
1661 creature_ptr->realm2 = (REALM_IDX)tmp8u;
1664 if (z_older_than(10, 4, 4))
1666 if (creature_ptr->realm1 == 9) creature_ptr->realm1 = REALM_MUSIC;
1667 if (creature_ptr->realm2 == 9) creature_ptr->realm2 = REALM_MUSIC;
1668 if (creature_ptr->realm1 == 10) creature_ptr->realm1 = REALM_HISSATSU;
1669 if (creature_ptr->realm2 == 10) creature_ptr->realm2 = REALM_HISSATSU;
1673 creature_ptr->hitdie = tmp8u;
1674 rd_u16b(&creature_ptr->expfact);
1676 rd_s16b(&creature_ptr->age);
1677 rd_s16b(&creature_ptr->ht);
1678 rd_s16b(&creature_ptr->wt);
1680 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max[i]);
1681 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max_max[i]);
1682 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_cur[i]);
1685 rd_s32b(&creature_ptr->au);
1687 rd_s32b(&creature_ptr->max_exp);
1688 if (h_older_than(1, 5, 4, 1)) creature_ptr->max_max_exp = creature_ptr->max_exp;
1689 else rd_s32b(&creature_ptr->max_max_exp);
1690 rd_s32b(&creature_ptr->exp);
1692 if (h_older_than(1, 7, 0, 3))
1696 creature_ptr->exp_frac = (u32b)tmp16u;
1700 rd_u32b(&creature_ptr->exp_frac);
1703 rd_s16b(&creature_ptr->lev);
1705 for (int i = 0; i < 64; i++) rd_s16b(&creature_ptr->spell_exp[i]);
1706 if ((creature_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1708 for (int i = 0; i < 64; i++) creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1711 if (z_older_than(10, 3, 6))
1712 for (int i = 0; i < 5; i++) for (int j = 0; j < 60; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1714 for (int i = 0; i < 5; i++) for (int j = 0; j < 64; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1715 for (int i = 0; i < GINOU_MAX; i++) rd_s16b(&creature_ptr->skill_exp[i]);
1716 if (z_older_than(10, 4, 1))
1718 if (creature_ptr->pclass != CLASS_BEASTMASTER) creature_ptr->skill_exp[GINOU_RIDING] /= 2;
1719 creature_ptr->skill_exp[GINOU_RIDING] = MIN(creature_ptr->skill_exp[GINOU_RIDING], s_info[creature_ptr->pclass].s_max[GINOU_RIDING]);
1722 if (z_older_than(10, 3, 14))
1724 for (int i = 0; i < 108; i++) creature_ptr->magic_num1[i] = 0;
1725 for (int i = 0; i < 108; i++) creature_ptr->magic_num2[i] = 0;
1729 for (int i = 0; i < 108; i++) rd_s32b(&creature_ptr->magic_num1[i]);
1730 for (int i = 0; i < 108; i++) rd_byte(&creature_ptr->magic_num2[i]);
1731 if (h_older_than(1, 3, 0, 1))
1733 if (creature_ptr->pclass == CLASS_SMITH)
1735 creature_ptr->magic_num1[TR_ES_ATTACK] = creature_ptr->magic_num1[96];
1736 creature_ptr->magic_num1[96] = 0;
1737 creature_ptr->magic_num1[TR_ES_AC] = creature_ptr->magic_num1[97];
1738 creature_ptr->magic_num1[97] = 0;
1743 if (music_singing_any(creature_ptr)) creature_ptr->action = ACTION_SING;
1745 if (z_older_than(11, 0, 7))
1747 creature_ptr->start_race = creature_ptr->prace;
1748 creature_ptr->old_race1 = 0L;
1749 creature_ptr->old_race2 = 0L;
1750 creature_ptr->old_realm = 0;
1755 creature_ptr->start_race = (player_race_type)tmp8u;
1758 creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1760 creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1761 rd_s16b(&creature_ptr->old_realm);
1764 if (z_older_than(10, 0, 1))
1766 for (int i = 0; i < MAX_MANE; i++)
1768 creature_ptr->mane_spell[i] = -1;
1769 creature_ptr->mane_dam[i] = 0;
1771 creature_ptr->mane_num = 0;
1773 else if (z_older_than(10, 2, 3))
1776 for (int i = 0; i < OLD_MAX_MANE; i++)
1782 for (int i = 0; i < MAX_MANE; i++)
1784 creature_ptr->mane_spell[i] = -1;
1785 creature_ptr->mane_dam[i] = 0;
1789 creature_ptr->mane_num = 0;
1793 for (int i = 0; i < MAX_MANE; i++)
1797 creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1799 creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1802 rd_s16b(&creature_ptr->mane_num);
1805 if (z_older_than(10, 0, 3))
1807 determine_bounty_uniques(creature_ptr);
1809 for (int i = 0; i < MAX_BOUNTY; i++)
1811 /* Is this bounty unique already dead? */
1812 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1817 for (int i = 0; i < MAX_BOUNTY; i++)
1819 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1823 if (z_older_than(10, 0, 3))
1825 update_gambling_monsters(creature_ptr);
1829 for (int i = 0; i < 4; i++)
1831 rd_s16b(&battle_mon[i]);
1832 if (z_older_than(10, 3, 4))
1836 mon_odds[i] = tmp16s;
1838 else rd_u32b(&mon_odds[i]);
1842 rd_s16b(&creature_ptr->town_num);
1843 rd_s16b(&creature_ptr->arena_number);
1844 if (h_older_than(1, 5, 0, 1))
1846 if (creature_ptr->arena_number >= 99) creature_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1851 creature_ptr->current_floor_ptr->inside_arena = (bool)tmp16s;
1852 rd_s16b(&creature_ptr->current_floor_ptr->inside_quest);
1853 if (z_older_than(10, 3, 5)) creature_ptr->phase_out = FALSE;
1857 creature_ptr->phase_out = (bool)tmp16s;
1860 rd_byte(&creature_ptr->exit_bldg);
1864 creature_ptr->oldpx = (POSITION)tmp16s;
1867 creature_ptr->oldpy = (POSITION)tmp16s;
1868 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; }
1871 for (int i = 0; i < tmp16s; i++)
1877 if (h_older_than(1, 7, 0, 3))
1880 creature_ptr->mhp = tmp16s;
1883 creature_ptr->chp = tmp16s;
1887 creature_ptr->chp_frac = (u32b)tmp16u;
1891 rd_s32b(&creature_ptr->mhp);
1892 rd_s32b(&creature_ptr->chp);
1893 rd_u32b(&creature_ptr->chp_frac);
1896 if (h_older_than(1, 7, 0, 3))
1899 creature_ptr->msp = tmp16s;
1902 creature_ptr->csp = tmp16s;
1906 creature_ptr->csp_frac = (u32b)tmp16u;
1910 rd_s32b(&creature_ptr->msp);
1911 rd_s32b(&creature_ptr->csp);
1912 rd_u32b(&creature_ptr->csp_frac);
1915 rd_s16b(&creature_ptr->max_plv);
1916 if (z_older_than(10, 3, 8))
1919 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1923 byte max = (byte)current_world_ptr->max_d_idx;
1927 for (int i = 0; i < max; i++)
1930 max_dlv[i] = tmp16s;
1931 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1935 if (creature_ptr->max_plv < creature_ptr->lev) creature_ptr->max_plv = creature_ptr->lev;
1938 rd_s16b(&creature_ptr->sc);
1939 rd_s16b(&creature_ptr->concent);
1941 strip_bytes(2); /* Old "rest" */
1942 rd_s16b(&creature_ptr->blind);
1943 rd_s16b(&creature_ptr->paralyzed);
1944 rd_s16b(&creature_ptr->confused);
1945 rd_s16b(&creature_ptr->food);
1946 strip_bytes(4); /* Old "food_digested" / "protection" */
1948 rd_s16b(&creature_ptr->energy_need);
1949 if (z_older_than(11, 0, 13))
1950 creature_ptr->energy_need = 100 - creature_ptr->energy_need;
1951 if (h_older_than(2, 1, 2, 0))
1952 creature_ptr->enchant_energy_need = 0;
1954 rd_s16b(&creature_ptr->enchant_energy_need);
1956 rd_s16b(&creature_ptr->fast);
1957 rd_s16b(&creature_ptr->slow);
1958 rd_s16b(&creature_ptr->afraid);
1959 rd_s16b(&creature_ptr->cut);
1960 rd_s16b(&creature_ptr->stun);
1961 rd_s16b(&creature_ptr->poisoned);
1962 rd_s16b(&creature_ptr->image);
1963 rd_s16b(&creature_ptr->protevil);
1964 rd_s16b(&creature_ptr->invuln);
1965 if (z_older_than(10, 0, 0))
1966 creature_ptr->ult_res = 0;
1968 rd_s16b(&creature_ptr->ult_res);
1969 rd_s16b(&creature_ptr->hero);
1970 rd_s16b(&creature_ptr->shero);
1971 rd_s16b(&creature_ptr->shield);
1972 rd_s16b(&creature_ptr->blessed);
1973 rd_s16b(&creature_ptr->tim_invis);
1974 rd_s16b(&creature_ptr->word_recall);
1975 if (z_older_than(10, 3, 8))
1976 creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
1980 creature_ptr->recall_dungeon = (byte)tmp16s;
1983 if (h_older_than(1, 5, 0, 0))
1984 creature_ptr->alter_reality = 0;
1986 rd_s16b(&creature_ptr->alter_reality);
1988 rd_s16b(&creature_ptr->see_infra);
1989 rd_s16b(&creature_ptr->tim_infra);
1990 rd_s16b(&creature_ptr->oppose_fire);
1991 rd_s16b(&creature_ptr->oppose_cold);
1992 rd_s16b(&creature_ptr->oppose_acid);
1993 rd_s16b(&creature_ptr->oppose_elec);
1994 rd_s16b(&creature_ptr->oppose_pois);
1995 if (z_older_than(10, 0, 2)) creature_ptr->tsuyoshi = 0;
1996 else rd_s16b(&creature_ptr->tsuyoshi);
1998 /* Old savefiles do not have the following fields... */
1999 if ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->z_patch == 6))
2001 creature_ptr->tim_esp = 0;
2002 creature_ptr->wraith_form = 0;
2003 creature_ptr->resist_magic = 0;
2004 creature_ptr->tim_regen = 0;
2005 creature_ptr->kabenuke = 0;
2006 creature_ptr->tim_stealth = 0;
2007 creature_ptr->tim_levitation = 0;
2008 creature_ptr->tim_sh_touki = 0;
2009 creature_ptr->lightspeed = 0;
2010 creature_ptr->tsubureru = 0;
2011 creature_ptr->tim_res_nether = 0;
2012 creature_ptr->tim_res_time = 0;
2013 creature_ptr->mimic_form = 0;
2014 creature_ptr->tim_mimic = 0;
2015 creature_ptr->tim_sh_fire = 0;
2016 creature_ptr->tim_reflect = 0;
2017 creature_ptr->multishadow = 0;
2018 creature_ptr->dustrobe = 0;
2019 creature_ptr->chaos_patron = ((creature_ptr->age + creature_ptr->sc) % MAX_PATRON);
2020 creature_ptr->muta1 = 0;
2021 creature_ptr->muta2 = 0;
2022 creature_ptr->muta3 = 0;
2023 get_virtues(creature_ptr);
2027 rd_s16b(&creature_ptr->tim_esp);
2028 rd_s16b(&creature_ptr->wraith_form);
2029 rd_s16b(&creature_ptr->resist_magic);
2030 rd_s16b(&creature_ptr->tim_regen);
2031 rd_s16b(&creature_ptr->kabenuke);
2032 rd_s16b(&creature_ptr->tim_stealth);
2033 rd_s16b(&creature_ptr->tim_levitation);
2034 rd_s16b(&creature_ptr->tim_sh_touki);
2035 rd_s16b(&creature_ptr->lightspeed);
2036 rd_s16b(&creature_ptr->tsubureru);
2037 if (z_older_than(10, 4, 7))
2038 creature_ptr->magicdef = 0;
2040 rd_s16b(&creature_ptr->magicdef);
2041 rd_s16b(&creature_ptr->tim_res_nether);
2042 if (z_older_than(10, 4, 11))
2044 creature_ptr->tim_res_time = 0;
2045 creature_ptr->mimic_form = 0;
2046 creature_ptr->tim_mimic = 0;
2047 creature_ptr->tim_sh_fire = 0;
2051 rd_s16b(&creature_ptr->tim_res_time);
2053 creature_ptr->mimic_form = (IDX)tmp8u;
2054 rd_s16b(&creature_ptr->tim_mimic);
2055 rd_s16b(&creature_ptr->tim_sh_fire);
2058 if (z_older_than(11, 0, 99))
2060 creature_ptr->tim_sh_holy = 0;
2061 creature_ptr->tim_eyeeye = 0;
2065 rd_s16b(&creature_ptr->tim_sh_holy);
2066 rd_s16b(&creature_ptr->tim_eyeeye);
2069 if (z_older_than(11, 0, 3)) {
2070 creature_ptr->tim_reflect = 0;
2071 creature_ptr->multishadow = 0;
2072 creature_ptr->dustrobe = 0;
2076 rd_s16b(&creature_ptr->tim_reflect);
2077 rd_s16b(&creature_ptr->multishadow);
2078 rd_s16b(&creature_ptr->dustrobe);
2081 rd_s16b(&creature_ptr->chaos_patron);
2082 rd_u32b(&creature_ptr->muta1);
2083 rd_u32b(&creature_ptr->muta2);
2084 rd_u32b(&creature_ptr->muta3);
2086 for (int i = 0; i < 8; i++)
2087 rd_s16b(&creature_ptr->virtues[i]);
2088 for (int i = 0; i < 8; i++)
2089 rd_s16b(&creature_ptr->vir_types[i]);
2092 creature_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod(creature_ptr);
2093 if (z_older_than(10, 0, 9))
2096 if (tmp8u) creature_ptr->special_attack = ATTACK_CONFUSE;
2097 creature_ptr->ele_attack = 0;
2101 rd_s16b(&creature_ptr->ele_attack);
2102 rd_u32b(&creature_ptr->special_attack);
2105 if (creature_ptr->special_attack & KAMAE_MASK) creature_ptr->action = ACTION_KAMAE;
2106 else if (creature_ptr->special_attack & KATA_MASK) creature_ptr->action = ACTION_KATA;
2107 if (z_older_than(10, 0, 12))
2109 creature_ptr->ele_immune = 0;
2110 creature_ptr->special_defense = 0;
2114 rd_s16b(&creature_ptr->ele_immune);
2115 rd_u32b(&creature_ptr->special_defense);
2118 rd_byte(&creature_ptr->knowledge);
2120 creature_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2124 creature_ptr->action = (ACTION_IDX)tmp8u;
2125 if (!z_older_than(10, 4, 3))
2128 if (tmp8u) creature_ptr->action = ACTION_LEARN;
2131 rd_byte((byte *)&preserve_mode);
2132 rd_byte((byte *)&creature_ptr->wait_report_score);
2134 for (int i = 0; i < 48; i++) rd_byte(&tmp8u);
2137 rd_u32b(¤t_world_ptr->seed_flavor);
2138 rd_u32b(¤t_world_ptr->seed_town);
2140 rd_u16b(&creature_ptr->panic_save);
2141 rd_u16b(¤t_world_ptr->total_winner);
2142 rd_u16b(¤t_world_ptr->noscore);
2145 creature_ptr->is_dead = tmp8u;
2147 rd_byte(&creature_ptr->feeling);
2149 switch (creature_ptr->start_race)
2155 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2158 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2162 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2163 rd_s32b(&creature_ptr->current_floor_ptr->generated_turn);
2164 if (h_older_than(1, 7, 0, 4))
2166 creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
2170 rd_s32b(&creature_ptr->feeling_turn);
2173 rd_s32b(¤t_world_ptr->game_turn);
2174 if (z_older_than(10, 3, 12))
2176 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2178 else rd_s32b(¤t_world_ptr->dungeon_turn);
2180 if (z_older_than(11, 0, 13))
2182 creature_ptr->current_floor_ptr->generated_turn /= 2;
2183 creature_ptr->feeling_turn /= 2;
2184 current_world_ptr->game_turn /= 2;
2185 current_world_ptr->dungeon_turn /= 2;
2188 if (z_older_than(10, 3, 13))
2190 current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
2192 else rd_s32b(¤t_world_ptr->arena_start_turn);
2194 if (z_older_than(10, 0, 3))
2196 determine_daily_bounty(creature_ptr, TRUE);
2200 rd_s16b(&today_mon);
2201 rd_s16b(&creature_ptr->today_mon);
2204 if (z_older_than(10, 0, 7))
2206 creature_ptr->riding = 0;
2210 rd_s16b(&creature_ptr->riding);
2213 if (h_older_than(1, 5, 0, 0))
2215 creature_ptr->floor_id = 0;
2219 rd_s16b(&creature_ptr->floor_id);
2222 if (h_older_than(1, 5, 0, 2))
2229 for (int i = 0; i < tmp16s; i++)
2231 monster_type dummy_mon;
2232 rd_monster(creature_ptr, &dummy_mon);
2236 if (z_older_than(10, 1, 2))
2238 current_world_ptr->play_time = 0;
2242 rd_u32b(¤t_world_ptr->play_time);
2245 if (z_older_than(10, 3, 9))
2247 creature_ptr->visit = 1L;
2249 else if (z_older_than(10, 3, 10))
2253 creature_ptr->visit = 1L;
2259 creature_ptr->visit = (BIT_FLAGS)tmp32s;
2262 if (!z_older_than(11, 0, 5))
2264 rd_u32b(&creature_ptr->count);
2270 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2271 * @param player_ptr プレーヤーへの参照ポインタ
2274 * Note that the inventory changed in Angband 2.7.4. Two extra
2275 * pack slots were added and the equipment was rearranged. Note
2276 * that these two features combine when parsing old save-files, in
2277 * which items from the old "aux" slot are "carried", perhaps into
2278 * one of the two new "inventory" slots.
2280 * Note that the inventory is "re-sorted" later by "dungeon()".
2282 static errr rd_inventory(player_type *player_ptr)
2284 player_ptr->total_weight = 0;
2285 player_ptr->inven_cnt = 0;
2286 player_ptr->equip_cnt = 0;
2288 if (player_ptr->inventory_list != NULL) C_WIPE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2289 C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2297 if (n == 0xFFFF) break;
2304 if (!q_ptr->k_idx) return (53);
2306 if (n >= INVEN_RARM)
2308 q_ptr->marked |= OM_TOUCHED;
2309 object_copy(&player_ptr->inventory_list[n], q_ptr);
2310 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2311 player_ptr->equip_cnt++;
2315 if (player_ptr->inven_cnt == INVEN_PACK)
2317 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
2322 q_ptr->marked |= OM_TOUCHED;
2323 object_copy(&player_ptr->inventory_list[n], q_ptr);
2324 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2325 player_ptr->inven_cnt++;
2333 * @brief メッセージログを読み込む / Read the saved messages
2336 static void rd_messages(void)
2338 if (h_older_than(2, 2, 0, 75))
2343 message_max = (int)num;
2345 for (int i = 0; i < message_max; i++)
2348 rd_string(buf, sizeof(buf));
2356 message_max = (int)num;
2358 for (int i = 0; i < message_max; i++)
2361 rd_string(buf, sizeof(buf));
2368 * @brief メッセージログを読み込む / Read the dungeon (old method)
2369 * @param creature_ptr プレーヤーへの参照ポインタ
2372 * The monsters/objects must be loaded in the same order
2373 * that they were stored, since the actual indexes matter.
2375 static errr rd_dungeon_old(player_type *creature_ptr)
2379 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2380 floor_ptr->dun_level = (DEPTH)tmp16s;
2381 if (z_older_than(10, 3, 8)) creature_ptr->dungeon_idx = DUNGEON_ANGBAND;
2386 creature_ptr->dungeon_idx = (IDX)tmp8u;
2389 floor_ptr->base_level = floor_ptr->dun_level;
2391 floor_ptr->base_level = (DEPTH)tmp16s;
2394 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2396 creature_ptr->y = (POSITION)tmp16s;
2398 creature_ptr->x = (POSITION)tmp16s;
2399 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) { creature_ptr->y = 33; creature_ptr->x = 131; }
2401 floor_ptr->height = (POSITION)tmp16s;
2403 floor_ptr->width = (POSITION)tmp16s;
2404 rd_s16b(&tmp16s); /* max_panel_rows */
2405 rd_s16b(&tmp16s); /* max_panel_cols */
2407 int ymax = floor_ptr->height;
2408 int xmax = floor_ptr->width;
2410 for (int x = 0, y = 0; y < ymax; )
2415 if (z_older_than(10, 3, 6))
2424 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2427 for (int i = count; i > 0; i--)
2430 g_ptr = &floor_ptr->grid_array[y][x];
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->feat = (s16b)tmp8u;
2454 if (++y >= ymax) break;
2459 for (int x = 0, y = 0; y < ymax; )
2465 for (int i = count; i > 0; i--)
2468 g_ptr = &floor_ptr->grid_array[y][x];
2469 g_ptr->mimic = (s16b)tmp8u;
2473 if (++y >= ymax) break;
2478 for (int x = 0, y = 0; y < ymax; )
2483 for (int i = count; i > 0; i--)
2486 g_ptr = &floor_ptr->grid_array[y][x];
2487 g_ptr->special = tmp16s;
2491 if (++y >= ymax) break;
2496 if (z_older_than(11, 0, 99))
2498 for (int y = 0; y < ymax; y++)
2500 for (int x = 0; x < xmax; x++)
2502 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2507 if (h_older_than(1, 1, 1, 0))
2509 for (int y = 0; y < ymax; y++)
2511 for (int x = 0; x < xmax; x++)
2514 g_ptr = &floor_ptr->grid_array[y][x];
2517 if (g_ptr->feat == OLD_FEAT_INVIS)
2519 g_ptr->feat = feat_floor;
2520 g_ptr->info |= CAVE_TRAP;
2523 /* Older than 1.1.1 */
2524 if (g_ptr->feat == OLD_FEAT_MIRROR)
2526 g_ptr->feat = feat_floor;
2527 g_ptr->info |= CAVE_OBJECT;
2533 if (h_older_than(1, 3, 1, 0))
2535 for (int y = 0; y < ymax; y++)
2537 for (int x = 0; x < xmax; x++)
2540 g_ptr = &floor_ptr->grid_array[y][x];
2542 /* Old CAVE_IN_MIRROR flag */
2543 if (g_ptr->info & CAVE_OBJECT)
2545 g_ptr->mimic = feat_mirror;
2547 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2548 (g_ptr->feat == OLD_FEAT_GLYPH))
2550 g_ptr->info |= CAVE_OBJECT;
2551 g_ptr->mimic = g_ptr->feat;
2552 g_ptr->feat = feat_floor;
2554 else if (g_ptr->info & CAVE_TRAP)
2556 g_ptr->info &= ~CAVE_TRAP;
2557 g_ptr->mimic = g_ptr->feat;
2558 g_ptr->feat = choose_random_trap(creature_ptr);
2560 else if (g_ptr->feat == OLD_FEAT_INVIS)
2562 g_ptr->mimic = feat_floor;
2563 g_ptr->feat = feat_trap_open;
2569 /* Quest 18 was removed */
2570 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2572 for (int y = 0; y < ymax; y++)
2574 for (int x = 0; x < xmax; x++)
2577 g_ptr = &floor_ptr->grid_array[y][x];
2579 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2581 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2583 g_ptr->feat = feat_tree;
2586 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2588 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2591 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2592 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2594 g_ptr->feat = feat_up_stair;
2603 if (limit > current_world_ptr->max_o_idx)
2605 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2609 for (int i = 1; i < limit; i++)
2611 OBJECT_IDX o_idx = o_pop(floor_ptr);
2614 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2619 o_ptr = &floor_ptr->o_list[o_idx];
2621 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2623 monster_type *m_ptr;
2624 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2625 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2626 m_ptr->hold_o_idx = o_idx;
2631 g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2632 o_ptr->next_o_idx = g_ptr->o_idx;
2633 g_ptr->o_idx = o_idx;
2637 if (limit > current_world_ptr->max_m_idx)
2639 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2643 for (int i = 1; i < limit; i++)
2646 monster_type *m_ptr;
2647 m_idx = m_pop(creature_ptr);
2650 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2654 m_ptr = &floor_ptr->m_list[m_idx];
2655 rd_monster(creature_ptr, m_ptr);
2657 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2658 g_ptr->m_idx = m_idx;
2659 real_r_ptr(m_ptr)->cur_num++;
2662 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena)
2663 current_world_ptr->character_dungeon = FALSE;
2665 current_world_ptr->character_dungeon = TRUE;
2672 * @brief 保存されたフロアを読み込む / Read the saved floor
2673 * @param player_ptr プレーヤーへの参照ポインタ
2674 * @param sf_ptr 最後に保存されたフロアへの参照ポインタ
2675 * @return info読み込みエラーコード
2677 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2680 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2681 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2683 * The monsters/objects must be loaded in the same order
2684 * that they were stored, since the actual indexes matter.
2686 static errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
2688 grid_template_type *templates;
2689 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2690 clear_cave(player_ptr);
2691 player_ptr->x = player_ptr->y = 0;
2697 floor_ptr->dun_level = (DEPTH)tmp16s;
2698 floor_ptr->base_level = floor_ptr->dun_level;
2704 if (tmp16s != sf_ptr->floor_id) return 171;
2708 if (tmp8u != sf_ptr->savefile_id) return 171;
2711 if (tmp16s != sf_ptr->dun_level) return 171;
2712 floor_ptr->dun_level = sf_ptr->dun_level;
2716 if (tmp32s != sf_ptr->last_visit) return 171;
2720 if (tmp32u != sf_ptr->visit_mark) return 171;
2723 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2726 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2731 floor_ptr->base_level = (DEPTH)tmp16s;
2733 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2737 player_ptr->y = (POSITION)tmp16u;
2740 player_ptr->x = (POSITION)tmp16u;
2743 floor_ptr->height = (POSITION)tmp16s;
2745 floor_ptr->width = (POSITION)tmp16s;
2747 rd_byte(&player_ptr->feeling);
2751 C_MAKE(templates, limit, grid_template_type);
2753 for (int i = 0; i < limit; i++)
2755 grid_template_type *ct_ptr = &templates[i];
2757 ct_ptr->info = (BIT_FLAGS)tmp16u;
2758 if (h_older_than(1, 7, 0, 2))
2762 ct_ptr->feat = (s16b)tmp8u;
2764 ct_ptr->mimic = (s16b)tmp8u;
2768 rd_s16b(&ct_ptr->feat);
2769 rd_s16b(&ct_ptr->mimic);
2772 rd_s16b(&ct_ptr->special);
2775 POSITION ymax = floor_ptr->height;
2776 POSITION xmax = floor_ptr->width;
2777 for (POSITION x = 0, y = 0; y < ymax; )
2788 } while (tmp8u == MAX_UCHAR);
2790 for (int i = count; i > 0; i--)
2792 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2793 g_ptr->info = templates[id].info;
2794 g_ptr->feat = templates[id].feat;
2795 g_ptr->mimic = templates[id].mimic;
2796 g_ptr->special = templates[id].special;
2801 if (++y >= ymax) break;
2806 /* Quest 18 was removed */
2807 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2809 for (POSITION y = 0; y < ymax; y++)
2811 for (POSITION x = 0; x < xmax; x++)
2813 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2815 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2817 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2819 g_ptr->feat = feat_tree;
2822 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2824 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2827 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2828 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2830 g_ptr->feat = feat_up_stair;
2837 C_KILL(templates, limit, grid_template_type);
2839 if (limit > current_world_ptr->max_o_idx) return 151;
2840 for (int i = 1; i < limit; i++)
2844 o_idx = o_pop(floor_ptr);
2845 if (i != o_idx) return 152;
2847 o_ptr = &floor_ptr->o_list[o_idx];
2850 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2852 monster_type *m_ptr;
2853 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2854 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2855 m_ptr->hold_o_idx = o_idx;
2859 grid_type *g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2860 o_ptr->next_o_idx = g_ptr->o_idx;
2861 g_ptr->o_idx = o_idx;
2866 if (limit > current_world_ptr->max_m_idx) return 161;
2868 for (int i = 1; i < limit; i++)
2872 monster_type *m_ptr;
2873 m_idx = m_pop(player_ptr);
2874 if (i != m_idx) return 162;
2876 m_ptr = &floor_ptr->m_list[m_idx];
2877 rd_monster(player_ptr, m_ptr);
2878 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2879 g_ptr->m_idx = m_idx;
2880 real_r_ptr(m_ptr)->cur_num++;
2888 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
2889 * @param player_ptr プレーヤーへの参照ポインタ
2892 * The monsters/objects must be loaded in the same order
2893 * that they were stored, since the actual indexes matter.
2895 static errr rd_dungeon(player_type *player_ptr)
2897 init_saved_floors(player_ptr, FALSE);
2899 if (h_older_than(1, 5, 0, 0))
2901 err = rd_dungeon_old(player_ptr);
2902 if (player_ptr->dungeon_idx)
2904 player_ptr->floor_id = get_new_floor_id(player_ptr);
2905 get_sf_ptr(player_ptr->floor_id)->dun_level = player_ptr->current_floor_ptr->dun_level;
2911 rd_s16b(&max_floor_id);
2914 player_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
2919 err = rd_saved_floor(player_ptr, NULL);
2923 for (int i = 0; i < num; i++)
2925 saved_floor_type *sf_ptr = &saved_floors[i];
2927 rd_s16b(&sf_ptr->floor_id);
2929 sf_ptr->savefile_id = (s16b)tmp8u;
2933 sf_ptr->dun_level = (DEPTH)tmp16s;
2935 rd_s32b(&sf_ptr->last_visit);
2936 rd_u32b(&sf_ptr->visit_mark);
2937 rd_s16b(&sf_ptr->upper_floor_id);
2938 rd_s16b(&sf_ptr->lower_floor_id);
2941 for (int i = 0; i < num; i++)
2943 saved_floor_type *sf_ptr = &saved_floors[i];
2944 if (!sf_ptr->floor_id) continue;
2946 if (tmp8u) continue;
2948 err = rd_saved_floor(player_ptr, sf_ptr);
2951 if (!save_floor(player_ptr, sf_ptr, SLF_SECOND)) err = 182;
2958 if (!load_floor(player_ptr, get_sf_ptr(player_ptr->floor_id), SLF_SECOND)) err = 183;
2965 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
2969 note(_("アイテム配置エラー", "Object allocation error"));
2973 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
2977 note(_("モンスター配置エラー", "Monster allocation error"));
2981 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
2985 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporary files!"));
2989 note(_("Error 183", "Error 183"));
2993 current_world_ptr->character_dungeon = TRUE;
2999 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3002 static errr rd_savefile_new_aux(player_type *creature_ptr)
3004 u32b n_x_check, n_v_check;
3005 u32b o_x_check, o_v_check;
3008 xor_byte = current_world_ptr->sf_extra;
3012 /* Old savefile will be version 0.0.0.3 */
3013 rd_byte(¤t_world_ptr->h_ver_extra);
3014 rd_byte(¤t_world_ptr->h_ver_patch);
3015 rd_byte(¤t_world_ptr->h_ver_minor);
3016 rd_byte(¤t_world_ptr->h_ver_major);
3019 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3020 (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));
3022 rd_u32b(¤t_world_ptr->sf_system);
3023 rd_u32b(¤t_world_ptr->sf_when);
3024 rd_u16b(¤t_world_ptr->sf_lives);
3025 rd_u16b(¤t_world_ptr->sf_saves);
3035 rd_byte(&kanji_code);
3038 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3041 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3044 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3046 for (int i = 0; i < max_r_idx; i++)
3048 monster_race *r_ptr = &r_info[i];
3049 r_ptr->max_num = 100;
3051 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3052 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3056 if (tmp16u > max_r_idx)
3058 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3062 for (int i = 0; i < tmp16u; i++)
3064 rd_lore((MONRACE_IDX)i);
3067 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3070 if (tmp16u > max_k_idx)
3072 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3076 for (int i = 0; i < tmp16u; i++)
3078 object_kind *k_ptr = &k_info[i];
3080 k_ptr->aware = (tmp8u & 0x01) ? TRUE : FALSE;
3081 k_ptr->tried = (tmp8u & 0x02) ? TRUE : FALSE;
3083 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3085 /* 2.1.3 or newer version */
3087 u16b max_towns_load;
3088 u16b max_quests_load;
3089 byte max_rquests_load;
3090 s16b old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
3092 rd_u16b(&max_towns_load);
3093 if (max_towns_load > max_towns)
3095 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3099 rd_u16b(&max_quests_load);
3100 if (z_older_than(11, 0, 7))
3102 max_rquests_load = 10;
3106 rd_byte(&max_rquests_load);
3109 if (max_quests_load > max_q_idx)
3111 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3115 for (int i = 0; i < max_quests_load; i++)
3124 quest_type* const q_ptr = &quest[i];
3126 rd_s16b(&q_ptr->status);
3129 q_ptr->level = tmp16s;
3131 if (z_older_than(11, 0, 6))
3138 q_ptr->complev = tmp8u;
3140 if (h_older_than(2, 1, 2, 2))
3142 q_ptr->comptime = 0;
3146 rd_u32b(&q_ptr->comptime);
3149 bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
3150 is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
3151 is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
3152 if (!is_quest_running) continue;
3155 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3157 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3158 rd_s16b(&q_ptr->type);
3160 rd_s16b(&q_ptr->r_idx);
3161 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3163 determine_random_questor(creature_ptr, &quest[i]);
3166 rd_s16b(&q_ptr->k_idx);
3168 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3171 q_ptr->flags = tmp8u;
3173 if (z_older_than(10, 3, 11))
3175 if (q_ptr->flags & QUEST_FLAG_PRESET)
3181 init_flags = INIT_ASSIGN;
3182 creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)i;
3184 parse_fixed_map(creature_ptr, "q_info.txt", 0, 0, 0, 0);
3185 creature_ptr->current_floor_ptr->inside_quest = old_inside_quest;
3191 q_ptr->dungeon = tmp8u;
3194 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3195 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3196 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3199 /* Quest 18 was removed */
3200 if (h_older_than(1, 7, 0, 6))
3202 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3203 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3206 rd_s32b(&creature_ptr->wilderness_x);
3207 rd_s32b(&creature_ptr->wilderness_y);
3208 if (z_older_than(10, 3, 13))
3210 creature_ptr->wilderness_x = 5;
3211 creature_ptr->wilderness_y = 48;
3214 if (z_older_than(10, 3, 7)) creature_ptr->wild_mode = FALSE;
3215 else rd_byte((byte *)&creature_ptr->wild_mode);
3216 if (z_older_than(10, 3, 7)) creature_ptr->ambush_flag = FALSE;
3217 else rd_byte((byte *)&creature_ptr->ambush_flag);
3221 rd_s32b(&wild_x_size);
3222 rd_s32b(&wild_y_size);
3224 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3226 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3230 for (int i = 0; i < wild_x_size; i++)
3232 for (int j = 0; j < wild_y_size; j++)
3234 rd_u32b(&wilderness[j][i].seed);
3239 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3242 if (tmp16u > max_a_idx)
3244 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3248 for (int i = 0; i < tmp16u; i++)
3250 artifact_type *a_ptr = &a_info[i];
3253 a_ptr->cur_num = tmp8u;
3255 if (h_older_than(1, 5, 0, 0))
3257 a_ptr->floor_id = 0;
3265 rd_s16b(&a_ptr->floor_id);
3269 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3271 rd_extra(creature_ptr);
3272 if (creature_ptr->energy_need < -999) creature_ptr->timewalk = TRUE;
3274 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3277 if (tmp16u > PY_MAX_LEVEL)
3279 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3283 for (int i = 0; i < tmp16u; i++)
3287 creature_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3290 sp_ptr = &sex_info[creature_ptr->psex];
3291 rp_ptr = &race_info[creature_ptr->prace];
3292 cp_ptr = &class_info[creature_ptr->pclass];
3293 ap_ptr = &seikaku_info[creature_ptr->pseikaku];
3295 if (z_older_than(10, 2, 2) && (creature_ptr->pclass == CLASS_BEASTMASTER) && !creature_ptr->is_dead)
3297 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3298 roll_hitdice(creature_ptr, 0L);
3301 if (z_older_than(10, 3, 2) && (creature_ptr->pclass == CLASS_ARCHER) && !creature_ptr->is_dead)
3303 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3304 roll_hitdice(creature_ptr, 0L);
3307 if (z_older_than(10, 2, 6) && (creature_ptr->pclass == CLASS_SORCERER) && !creature_ptr->is_dead)
3309 creature_ptr->hitdie = rp_ptr->r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3310 roll_hitdice(creature_ptr, 0L);
3313 if (z_older_than(10, 4, 7) && (creature_ptr->pclass == CLASS_BLUE_MAGE) && !creature_ptr->is_dead)
3315 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3316 roll_hitdice(creature_ptr, 0L);
3319 mp_ptr = &m_info[creature_ptr->pclass];
3321 rd_u32b(&creature_ptr->spell_learned1);
3322 rd_u32b(&creature_ptr->spell_learned2);
3323 rd_u32b(&creature_ptr->spell_worked1);
3324 rd_u32b(&creature_ptr->spell_worked2);
3325 rd_u32b(&creature_ptr->spell_forgotten1);
3326 rd_u32b(&creature_ptr->spell_forgotten2);
3328 if (z_older_than(10, 0, 5))
3330 creature_ptr->learned_spells = 0;
3331 for (int i = 0; i < 64; i++)
3334 (creature_ptr->spell_learned1 & (1L << i)) :
3335 (creature_ptr->spell_learned2 & (1L << (i - 32))))
3337 creature_ptr->learned_spells++;
3341 else rd_s16b(&creature_ptr->learned_spells);
3343 if (z_older_than(10, 0, 6))
3345 creature_ptr->add_spells = 0;
3347 else rd_s16b(&creature_ptr->add_spells);
3349 if (creature_ptr->pclass == CLASS_MINDCRAFTER) creature_ptr->add_spells = 0;
3351 for (int i = 0; i < 64; i++)
3354 creature_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3357 if (rd_inventory(creature_ptr))
3359 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3364 int town_count = tmp16u;
3367 for (int i = 1; i < town_count; i++)
3369 for (int j = 0; j < tmp16u; j++)
3371 if (rd_store(creature_ptr, i, j)) return (22);
3375 rd_s16b(&creature_ptr->pet_follow_distance);
3376 if (z_older_than(10, 4, 10))
3378 creature_ptr->pet_extra_flags = 0;
3380 if (tmp8u) creature_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3382 if (tmp8u) creature_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3384 if (z_older_than(10, 0, 4)) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3388 if (tmp8u) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3391 if (z_older_than(10, 0, 7)) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3395 if (tmp8u) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3398 if (z_older_than(10, 0, 8)) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3402 if (tmp8u) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3405 if (!z_older_than(10, 0, 8))
3408 if (tmp8u) creature_ptr->pet_extra_flags |= PF_BALL_SPELL;
3413 rd_s16b(&creature_ptr->pet_extra_flags);
3416 if (!z_older_than(11, 0, 9))
3418 char buf[SCREEN_BUF_MAX_SIZE];
3419 rd_string(buf, sizeof(buf));
3420 if (buf[0]) screen_dump = string_make(buf);
3423 if (creature_ptr->is_dead)
3425 for (int i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3427 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3431 if (!creature_ptr->is_dead)
3433 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3434 if (rd_dungeon(creature_ptr))
3436 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3445 strip_bytes(tmp32s);
3449 /* Quest 18 was removed */
3450 if (h_older_than(1, 7, 0, 6))
3452 if (creature_ptr->current_floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3454 creature_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3455 creature_ptr->current_floor_ptr->dun_level = 1;
3456 creature_ptr->current_floor_ptr->inside_quest = 0;
3460 n_v_check = v_check;
3461 rd_u32b(&o_v_check);
3462 if (o_v_check != n_v_check)
3464 note(_("チェックサムがおかしい", "Invalid checksum"));
3468 n_x_check = x_check;
3469 rd_u32b(&o_x_check);
3470 if (o_x_check != n_x_check)
3472 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3481 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3482 * @param player_ptr プレーヤーへの参照ポインタ
3485 errr rd_savefile_new(player_type *player_ptr)
3488 fff = my_fopen(savefile, "rb");
3490 if (!fff) return -1;
3491 errr err = rd_savefile_new_aux(player_ptr);
3493 if (ferror(fff)) err = -1;
3500 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3501 * @param player_ptr プレーヤーへの参照ポインタ
3502 * @param sf_ptr 保存フロア読み込み先
3505 static bool load_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
3507 u32b n_x_check, n_v_check;
3508 u32b o_x_check, o_v_check;
3517 current_world_ptr->h_ver_extra = H_VER_EXTRA;
3518 current_world_ptr->h_ver_patch = H_VER_PATCH;
3519 current_world_ptr->h_ver_minor = H_VER_MINOR;
3520 current_world_ptr->h_ver_major = H_VER_MAJOR;
3524 if (saved_floor_file_sign != tmp32u) return FALSE;
3526 if (rd_saved_floor(player_ptr, sf_ptr)) return FALSE;
3528 n_v_check = v_check;
3529 rd_u32b(&o_v_check);
3531 if (o_v_check != n_v_check) return FALSE;
3533 n_x_check = x_check;
3534 rd_u32b(&o_x_check);
3536 if (o_x_check != n_x_check) return FALSE;
3542 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporarily saved-floor data
3543 * @param player_ptr プレーヤーへの参照ポインタ
3544 * @param sf_ptr 保存フロア読み込み先
3548 bool load_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
3551 * Temporary files are always written in system depended kanji
3565 FILE *old_fff = NULL;
3566 byte old_xor_byte = 0;
3567 u32b old_v_check = 0;
3568 u32b old_x_check = 0;
3569 byte old_h_ver_major = 0;
3570 byte old_h_ver_minor = 0;
3571 byte old_h_ver_patch = 0;
3572 byte old_h_ver_extra = 0;
3573 if (mode & SLF_SECOND)
3576 old_xor_byte = xor_byte;
3577 old_v_check = v_check;
3578 old_x_check = x_check;
3579 old_h_ver_major = current_world_ptr->h_ver_major;
3580 old_h_ver_minor = current_world_ptr->h_ver_minor;
3581 old_h_ver_patch = current_world_ptr->h_ver_patch;
3582 old_h_ver_extra = current_world_ptr->h_ver_extra;
3585 char floor_savefile[1024];
3586 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3589 fff = my_fopen(floor_savefile, "rb");
3592 bool is_save_successful = TRUE;
3593 if (!fff) is_save_successful = FALSE;
3595 if (is_save_successful)
3597 is_save_successful = load_floor_aux(player_ptr, sf_ptr);
3598 if (ferror(fff)) is_save_successful = FALSE;
3602 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3607 if (mode & SLF_SECOND)
3610 xor_byte = old_xor_byte;
3611 v_check = old_v_check;
3612 x_check = old_x_check;
3613 current_world_ptr->h_ver_major = old_h_ver_major;
3614 current_world_ptr->h_ver_minor = old_h_ver_minor;
3615 current_world_ptr->h_ver_patch = old_h_ver_patch;
3616 current_world_ptr->h_ver_extra = old_h_ver_extra;
3619 byte old_kanji_code = kanji_code;
3620 kanji_code = old_kanji_code;
3621 return is_save_successful;