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.
43 #include "system/angband.h"
44 #include "util/util.h"
45 #include "system/system-variables.h" // 暫定、init_flags の扱いを決めた上で消す.
46 #include "system/angband-version.h"
49 #include "market/building.h"
50 #include "io/report.h"
52 #include "dungeon/dungeon.h"
53 #include "grid/feature.h"
54 #include "floor/floor-generate.h"
55 #include "grid/trap.h"
56 #include "mutation/mutation.h"
57 #include "monster/monster.h"
58 #include "market/store-util.h"
59 #include "dungeon/quest.h"
60 #include "market/store.h"
61 #include "object/artifact.h"
62 #include "player/avatar.h"
63 #include "spell/spells-status.h"
64 #include "object/object-hook.h"
65 #include "floor/wild.h"
66 #include "player/patron.h"
68 #include "floor/floor.h"
69 #include "floor/floor-save.h"
70 #include "floor/floor-town.h"
71 #include "grid/grid.h"
74 #include "dungeon/dungeon-file.h"
75 #include "io/uid-checker.h"
77 #include "player/player-skill.h"
78 #include "player/player-class.h"
79 #include "player/race-info-table.h"
80 #include "player/player-personality.h"
81 #include "player/player-sex.h"
82 #include "world/world.h"
83 #include "object/object-kind.h"
84 #include "object/object-ego.h"
86 #include "locale/japanese.h"
87 #include "cmd-smith.h"
88 #include "birth/quick-start.h"
89 #include "player/player-races-table.h"
92 * Maximum number of tries for selection of a proper quest monster
96 #define OLD_MAX_MANE 22
98 /* Old hidden trap flag */
99 #define CAVE_TRAP 0x8000
101 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
102 #define OLD_FEAT_INVIS 0x02
103 #define OLD_FEAT_GLYPH 0x03
104 #define OLD_FEAT_QUEST_ENTER 0x08
105 #define OLD_FEAT_QUEST_EXIT 0x09
106 #define OLD_FEAT_MINOR_GLYPH 0x40
107 #define OLD_FEAT_BLDG_1 0x81
108 #define OLD_FEAT_MIRROR 0xc3
111 #define OLD_QUEST_WATER_CAVE 18
113 /* Quest constants */
114 #define QUEST_OLD_CASTLE 27
115 #define QUEST_ROYAL_CRYPT 28
118 * Local "savefile" pointer
123 * Hack -- old "encryption" byte
125 static byte xor_byte;
128 * Hack -- simple "checksum" on the actual values
130 static u32b v_check = 0L;
133 * Hack -- simple "checksum" on the encoded bytes
135 static u32b x_check = 0L;
138 * Hack -- Japanese Kanji code
144 static byte kanji_code = 0;
147 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
148 * @param major メジャーバージョン値
149 * @param minor マイナーバージョン値
150 * @param patch パッチバージョン値
151 * @param extra エクストラパージョン値
152 * @return 現在のバージョンより値が古いならtrue
154 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
156 if (current_world_ptr->h_ver_major < major) return TRUE;
157 if (current_world_ptr->h_ver_major > major) return FALSE;
159 if (current_world_ptr->h_ver_minor < minor) return TRUE;
160 if (current_world_ptr->h_ver_minor > minor) return FALSE;
162 if (current_world_ptr->h_ver_patch < patch) return TRUE;
163 if (current_world_ptr->h_ver_patch > patch) return FALSE;
165 if (current_world_ptr->h_ver_extra < extra) return TRUE;
166 if (current_world_ptr->h_ver_extra > extra) return FALSE;
173 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
174 * @param x メジャーバージョン値
175 * @param y マイナーバージョン値
177 * @return 現在のバージョンより値が古いならtrue
179 static bool z_older_than(byte x, byte y, byte z)
181 if (current_world_ptr->z_major < x) return TRUE;
182 if (current_world_ptr->z_major > x) return FALSE;
184 if (current_world_ptr->z_minor < y) return TRUE;
185 if (current_world_ptr->z_minor > y) return FALSE;
187 if (current_world_ptr->z_patch < z) return TRUE;
188 if (current_world_ptr->z_patch > z) return FALSE;
195 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
199 * Avoid the top two lines, to avoid interference with "msg_print()".
201 static void note(concptr msg)
203 static TERM_LEN y = 2;
205 if (++y >= 24) y = 2;
212 * @brief ロードファイルポインタから1バイトを読み込む
215 * The following functions are used to load the basic building blocks
216 * of savefiles. They also maintain the "checksum" info for 2.7.0+
218 static byte sf_get(void)
220 byte c = getc(fff) & 0xFF;
221 byte v = c ^ xor_byte;
231 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
235 static void rd_byte(byte *ip)
242 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
246 static void rd_u16b(u16b *ip)
249 (*ip) |= ((u16b)(sf_get()) << 8);
254 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
258 static void rd_s16b(s16b *ip)
265 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
269 static void rd_u32b(u32b *ip)
272 (*ip) |= ((u32b)(sf_get()) << 8);
273 (*ip) |= ((u32b)(sf_get()) << 16);
274 (*ip) |= ((u32b)(sf_get()) << 24);
279 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
283 static void rd_s32b(s32b *ip)
290 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
291 * @param str 読み込みポインタ
292 * @param max 最大読み取りバイト数
295 static void rd_string(char *str, int max)
297 for (int i = 0; TRUE; i++)
301 if (i < max) str[i] = tmp8u;
324 byte code = codeconv(str);
326 /* 漢字コードが判明したら、それを記録 */
327 if (code) kanji_code = code;
339 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
343 static void strip_bytes(int n)
346 while (n--) rd_byte(&tmp8u);
351 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
352 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
355 * This function attempts to "repair" old savefiles, and to extract
356 * the most up to date values for various object fields.
358 * Note that Angband 2.7.9 introduced a new method for object "flags"
359 * in which the "flags" on an object are actually extracted when they
360 * are needed from the object kind, artifact index, ego-item index,
361 * and two special "xtra" fields which are used to encode any "extra"
362 * power of certain ego-items. This had the side effect that items
363 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
364 * may have had, and also, all "uncursed" items will become "cursed"
365 * again, including Calris, even if it is being worn at the time. As
366 * a complete hack, items which are inscribed with "uncursed" will be
367 * "uncursed" when imported from pre-2.7.9 savefiles.
369 static void rd_item_old(object_type *o_ptr)
371 rd_s16b(&o_ptr->k_idx);
375 o_ptr->iy = (POSITION)tmp8u;
377 o_ptr->ix = (POSITION)tmp8u;
385 if (z_older_than(10, 4, 4))
387 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
388 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
389 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
392 rd_s16b(&o_ptr->pval);
393 rd_byte(&o_ptr->discount);
395 o_ptr->number = (ITEM_NUMBER)tmp8u;
399 o_ptr->weight = tmp16s;
402 o_ptr->name1 = tmp8u;
405 o_ptr->name2 = tmp8u;
407 rd_s16b(&o_ptr->timeout);
408 rd_s16b(&o_ptr->to_h);
410 o_ptr->to_d = tmp16s;
412 rd_s16b(&o_ptr->to_a);
420 rd_byte(&o_ptr->ident);
421 rd_byte(&o_ptr->marked);
422 rd_u32b(&o_ptr->art_flags[0]);
423 rd_u32b(&o_ptr->art_flags[1]);
424 rd_u32b(&o_ptr->art_flags[2]);
425 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
426 else rd_u32b(&o_ptr->art_flags[3]);
428 if (h_older_than(1, 3, 0, 0))
430 if (o_ptr->name2 == EGO_TELEPATHY)
431 add_flag(o_ptr->art_flags, TR_TELEPATHY);
434 if (z_older_than(11, 0, 11))
436 o_ptr->curse_flags = 0L;
437 if (o_ptr->ident & 0x40)
439 o_ptr->curse_flags |= TRC_CURSED;
440 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
441 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
442 if (object_is_fixed_artifact(o_ptr))
444 artifact_type *a_ptr = &a_info[o_ptr->name1];
445 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
446 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
448 else if (object_is_ego(o_ptr))
450 ego_item_type *e_ptr = &e_info[o_ptr->name2];
451 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
452 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
455 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
459 rd_u32b(&o_ptr->curse_flags);
462 rd_s16b(&o_ptr->held_m_idx);
463 rd_byte(&o_ptr->xtra1);
464 rd_byte(&o_ptr->xtra2);
466 if (z_older_than(11, 0, 10))
468 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
470 switch (o_ptr->xtra2 % 6)
472 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
473 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
474 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
475 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
476 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
477 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
481 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
483 switch (o_ptr->xtra2 % 11)
485 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
486 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
487 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
488 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
489 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
490 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
491 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
492 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
493 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
494 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
495 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
499 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
501 switch (o_ptr->xtra2 % 8)
503 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
504 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
505 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
506 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
507 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
508 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
509 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
510 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
517 if (z_older_than(10, 2, 3))
522 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
524 o_ptr->xtra3 = o_ptr->xtra1;
527 if (o_ptr->tval == TV_CAPTURE)
529 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
530 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
532 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
533 if (ironman_nightmare)
535 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5 * 2L);
537 o_ptr->xtra4 = o_ptr->xtra5;
542 rd_byte(&o_ptr->xtra3);
543 if (h_older_than(1, 3, 0, 1))
545 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1 + 96)
546 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
549 rd_s16b(&o_ptr->xtra4);
550 rd_s16b(&o_ptr->xtra5);
553 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)))
555 o_ptr->xtra4 = o_ptr->pval;
559 rd_byte(&o_ptr->feeling);
562 rd_string(buf, sizeof(buf));
563 if (buf[0]) o_ptr->inscription = quark_add(buf);
565 rd_string(buf, sizeof(buf));
567 /* todo 元々このif文には末尾に";"が付いていた、バグかもしれない */
568 if (buf[0]) o_ptr->art_name = quark_add(buf);
576 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
578 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
580 if (z_older_than(10, 4, 9))
582 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
584 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
585 add_flag(o_ptr->art_flags, TR_DEC_MANA);
589 if (object_is_fixed_artifact(o_ptr))
591 artifact_type *a_ptr;
592 a_ptr = &a_info[o_ptr->name1];
593 if (!a_ptr->name) o_ptr->name1 = 0;
596 if (object_is_ego(o_ptr))
598 ego_item_type *e_ptr;
599 e_ptr = &e_info[o_ptr->name2];
600 if (!e_ptr->name) o_ptr->name2 = 0;
606 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
607 * @param o_ptr アイテムオブジェクト保存先ポインタ
610 static void rd_item(object_type *o_ptr)
612 if (h_older_than(1, 5, 0, 0))
620 rd_s16b(&o_ptr->k_idx);
624 o_ptr->iy = (POSITION)tmp8u;
626 o_ptr->ix = (POSITION)tmp8u;
629 k_ptr = &k_info[o_ptr->k_idx];
630 o_ptr->tval = k_ptr->tval;
631 o_ptr->sval = k_ptr->sval;
633 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
634 else o_ptr->pval = 0;
636 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
637 else o_ptr->discount = 0;
638 if (flags & SAVE_ITEM_NUMBER) {
640 o_ptr->number = tmp8u;
642 else o_ptr->number = 1;
646 o_ptr->weight = tmp16s;
648 if (flags & SAVE_ITEM_NAME1)
651 o_ptr->name1 = tmp8u;
653 else o_ptr->name1 = 0;
655 if (flags & SAVE_ITEM_NAME2)
658 o_ptr->name2 = tmp8u;
660 else o_ptr->name2 = 0;
662 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
663 else o_ptr->timeout = 0;
665 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
666 else o_ptr->to_h = 0;
668 if (flags & SAVE_ITEM_TO_D)
671 o_ptr->to_d = tmp16s;
673 else o_ptr->to_d = 0;
675 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
676 else o_ptr->to_a = 0;
678 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
681 if (flags & SAVE_ITEM_DD)
688 if (flags & SAVE_ITEM_DS)
695 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
696 else o_ptr->ident = 0;
698 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
699 else o_ptr->marked = 0;
702 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
703 else o_ptr->art_flags[0] = 0;
705 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
706 else o_ptr->art_flags[1] = 0;
708 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
709 else o_ptr->art_flags[2] = 0;
711 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
712 else o_ptr->art_flags[3] = 0;
714 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
715 else o_ptr->art_flags[4] = 0;
717 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
718 else o_ptr->curse_flags = 0;
720 /* Monster holding object */
721 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
722 else o_ptr->held_m_idx = 0;
725 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
726 else o_ptr->xtra1 = 0;
728 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
729 else o_ptr->xtra2 = 0;
731 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
732 else o_ptr->xtra3 = 0;
734 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
735 else o_ptr->xtra4 = 0;
737 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
738 else o_ptr->xtra5 = 0;
740 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
741 else o_ptr->feeling = 0;
743 if (flags & SAVE_ITEM_INSCRIPTION)
746 rd_string(buf, sizeof(buf));
747 o_ptr->inscription = quark_add(buf);
749 else o_ptr->inscription = 0;
751 if (flags & SAVE_ITEM_ART_NAME)
754 rd_string(buf, sizeof(buf));
755 o_ptr->art_name = quark_add(buf);
762 if (!h_older_than(2, 1, 2, 4)) return;
764 BIT_FLAGS flgs[TR_FLAG_SIZE];
765 object_flags(o_ptr, flgs);
767 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
769 add_flag(o_ptr->art_flags, TR_LITE_M1);
770 remove_flag(o_ptr->art_flags, TR_LITE_1);
771 remove_flag(o_ptr->art_flags, TR_LITE_2);
772 remove_flag(o_ptr->art_flags, TR_LITE_3);
776 if (o_ptr->name2 == EGO_LITE_DARKNESS)
778 if (o_ptr->tval != TV_LITE)
780 add_flag(o_ptr->art_flags, TR_LITE_M1);
784 if (o_ptr->sval == SV_LITE_TORCH)
786 add_flag(o_ptr->art_flags, TR_LITE_M1);
788 else if (o_ptr->sval == SV_LITE_LANTERN)
790 add_flag(o_ptr->art_flags, TR_LITE_M2);
792 else if (o_ptr->sval == SV_LITE_FEANOR)
794 add_flag(o_ptr->art_flags, TR_LITE_M3);
800 if (o_ptr->tval == TV_LITE)
802 if (object_is_fixed_artifact(o_ptr))
804 add_flag(o_ptr->art_flags, TR_LITE_3);
808 if (o_ptr->sval == SV_LITE_TORCH)
810 add_flag(o_ptr->art_flags, TR_LITE_1);
811 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
815 if (o_ptr->sval == SV_LITE_LANTERN)
817 add_flag(o_ptr->art_flags, TR_LITE_2);
818 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
822 if (o_ptr->sval == SV_LITE_FEANOR)
824 add_flag(o_ptr->art_flags, TR_LITE_2);
832 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
833 * @param player_ptr プレーヤーへの参照ポインタ
834 * @param m_ptr モンスター保存先ポインタ
837 static void rd_monster_old(player_type *player_ptr, monster_type *m_ptr)
839 rd_s16b(&m_ptr->r_idx);
841 if (z_older_than(11, 0, 12))
842 m_ptr->ap_r_idx = m_ptr->r_idx;
844 rd_s16b(&m_ptr->ap_r_idx);
846 if (z_older_than(11, 0, 14))
848 monster_race *r_ptr = &r_info[m_ptr->r_idx];
850 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
851 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
852 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
855 rd_byte(&m_ptr->sub_align);
859 m_ptr->fy = (POSITION)tmp8u;
861 m_ptr->fx = (POSITION)tmp8u;
862 m_ptr->current_floor_ptr = player_ptr->current_floor_ptr;
868 m_ptr->maxhp = tmp16s;
870 if (z_older_than(11, 0, 5))
872 m_ptr->max_maxhp = m_ptr->maxhp;
877 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
879 if (h_older_than(2, 1, 2, 1))
881 m_ptr->dealt_damage = 0;
885 rd_s32b(&m_ptr->dealt_damage);
888 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
890 m_ptr->mspeed = tmp8u;
892 if (z_older_than(10, 4, 2))
895 m_ptr->energy_need = (s16b)tmp8u;
897 else rd_s16b(&m_ptr->energy_need);
899 if (z_older_than(11, 0, 13))
900 m_ptr->energy_need = 100 - m_ptr->energy_need;
902 if (z_older_than(10, 0, 7))
904 m_ptr->mtimed[MTIMED_FAST] = 0;
905 m_ptr->mtimed[MTIMED_SLOW] = 0;
910 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
912 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
916 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
918 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
920 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
922 if (z_older_than(10, 0, 10))
926 else if (z_older_than(10, 0, 11))
934 m_ptr->target_y = (POSITION)tmp16s;
936 m_ptr->target_x = (POSITION)tmp16s;
940 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
942 if (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6))
943 rd_u32b(&m_ptr->smart);
948 if (z_older_than(10, 4, 5))
958 if (z_older_than(10, 2, 2))
960 if (m_ptr->r_idx < 0)
962 m_ptr->r_idx = (0 - m_ptr->r_idx);
963 m_ptr->mflag2 |= MFLAG2_KAGE;
968 rd_byte(&m_ptr->mflag2);
971 if (z_older_than(11, 0, 12))
973 if (m_ptr->mflag2 & MFLAG2_KAGE)
974 m_ptr->ap_r_idx = MON_KAGE;
977 if (z_older_than(10, 1, 3))
984 rd_string(buf, sizeof(buf));
985 if (buf[0]) m_ptr->nickname = quark_add(buf);
993 * @brief モンスターを読み込む(現版) / Read a monster (New method)
994 * @param player_ptr プレーヤーへの参照ポインタ
995 * @param m_ptr モンスター保存先ポインタ
998 static void rd_monster(player_type *player_ptr, monster_type *m_ptr)
1000 if (h_older_than(1, 5, 0, 0))
1002 rd_monster_old(player_ptr, m_ptr);
1008 rd_s16b(&m_ptr->r_idx);
1011 m_ptr->fy = (POSITION)tmp8u;
1013 m_ptr->fx = (POSITION)tmp8u;
1017 m_ptr->hp = (HIT_POINT)tmp16s;
1019 m_ptr->maxhp = (HIT_POINT)tmp16s;
1021 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1023 if (h_older_than(2, 1, 2, 1))
1025 m_ptr->dealt_damage = 0;
1029 rd_s32b(&m_ptr->dealt_damage);
1032 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1033 else m_ptr->ap_r_idx = m_ptr->r_idx;
1035 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1036 else m_ptr->sub_align = 0;
1038 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1039 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1042 m_ptr->mspeed = tmp8u;
1044 rd_s16b(&m_ptr->energy_need);
1046 if (flags & SAVE_MON_FAST)
1049 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1051 else m_ptr->mtimed[MTIMED_FAST] = 0;
1053 if (flags & SAVE_MON_SLOW)
1056 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1058 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1060 if (flags & SAVE_MON_STUNNED)
1063 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1065 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1067 if (flags & SAVE_MON_CONFUSED)
1070 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1072 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1074 if (flags & SAVE_MON_MONFEAR)
1077 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1079 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1081 if (flags & SAVE_MON_TARGET_Y)
1084 m_ptr->target_y = (POSITION)tmp16s;
1086 else m_ptr->target_y = 0;
1088 if (flags & SAVE_MON_TARGET_X)
1091 m_ptr->target_x = (POSITION)tmp16s;
1093 else m_ptr->target_x = 0;
1095 if (flags & SAVE_MON_INVULNER)
1098 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1100 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1102 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1103 else m_ptr->smart = 0;
1105 if (flags & SAVE_MON_EXP)
1109 m_ptr->exp = (EXP)tmp32u;
1111 else m_ptr->exp = 0;
1113 m_ptr->mflag = 0; /* Not saved */
1115 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1116 else m_ptr->mflag2 = 0;
1118 if (flags & SAVE_MON_NICKNAME)
1121 rd_string(buf, sizeof(buf));
1122 m_ptr->nickname = quark_add(buf);
1124 else m_ptr->nickname = 0;
1126 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1127 else m_ptr->parent_m_idx = 0;
1132 * Old monster bit flags of racial resistances
1134 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1135 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1136 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1137 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1138 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1139 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1140 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1141 #define RF3_RES_WATE 0x00800000 /* Resist water */
1142 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1143 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1144 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1145 #define RF3_RES_ALL 0x08000000 /* Resist all */
1147 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1149 if ((R_PTR)->r_flags3 & (RF3)) \
1151 (R_PTR)->r_flags3 &= ~(RF3); \
1152 (R_PTR)->r_flagsr |= (RFR); \
1156 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1158 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1160 (R_PTR)->r_flagsr |= (RFR); \
1164 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1165 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1166 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1167 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1168 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1169 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1170 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1171 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1172 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1173 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1176 * @brief モンスターの思い出を読み込む / Read the monster lore
1177 * @param r_idx 読み込み先モンスターID
1180 static void rd_lore(MONRACE_IDX r_idx)
1182 monster_race *r_ptr = &r_info[r_idx];
1186 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1189 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1192 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1194 if (h_older_than(1, 7, 0, 5))
1196 r_ptr->r_akills = r_ptr->r_pkills;
1201 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1205 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1207 rd_byte(&r_ptr->r_wake);
1208 rd_byte(&r_ptr->r_ignore);
1209 rd_byte(&r_ptr->r_xtra1);
1210 rd_byte(&r_ptr->r_xtra2);
1214 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1216 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1219 rd_byte(&r_ptr->r_cast_spell);
1221 rd_byte(&r_ptr->r_blows[0]);
1222 rd_byte(&r_ptr->r_blows[1]);
1223 rd_byte(&r_ptr->r_blows[2]);
1224 rd_byte(&r_ptr->r_blows[3]);
1226 rd_u32b(&r_ptr->r_flags1);
1227 rd_u32b(&r_ptr->r_flags2);
1228 rd_u32b(&r_ptr->r_flags3);
1229 rd_u32b(&r_ptr->r_flags4);
1230 rd_u32b(&r_ptr->r_flags5);
1231 rd_u32b(&r_ptr->r_flags6);
1232 if (h_older_than(1, 5, 0, 3))
1234 r_ptr->r_flagsr = 0L;
1235 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1236 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1237 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1238 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1239 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1240 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1241 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1242 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1243 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1244 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1245 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1246 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1248 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1249 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1250 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1251 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1252 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1253 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1254 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1255 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1256 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1258 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1259 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1260 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1264 rd_u32b(&r_ptr->r_flagsr);
1268 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1270 rd_s16b(&r_ptr->floor_id);
1273 r_ptr->r_flags1 &= r_ptr->flags1;
1274 r_ptr->r_flags2 &= r_ptr->flags2;
1275 r_ptr->r_flags3 &= r_ptr->flags3;
1276 r_ptr->r_flags4 &= r_ptr->flags4;
1277 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1278 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1279 r_ptr->r_flagsr &= r_ptr->flagsr;
1284 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1285 * @param player_ptr プレーヤーへの参照ポインタ
1286 * @param store_ptr 店舗の参照ポインタ
1287 * @param o_ptr アイテムオブジェクト参照ポインタ
1290 * In all cases, return the slot (or -1) where the object was placed
1292 * Note that this is a hacked up version of "inven_carry()".
1294 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1295 * known, the player may have to pick stuff up and drop it again.
1297 static void home_carry(player_type *player_ptr, store_type *store_ptr, object_type *o_ptr)
1299 for (int i = 0; i < store_ptr->stock_num; i++)
1302 j_ptr = &store_ptr->stock[i];
1303 if (!object_similar(j_ptr, o_ptr)) continue;
1305 object_absorb(j_ptr, o_ptr);
1309 if (store_ptr->stock_num >= STORE_INVEN_MAX * 10) return;
1311 s32b value = object_value(o_ptr);
1313 for (slot = 0; slot < store_ptr->stock_num; slot++)
1315 if (object_sort_comp(o_ptr, value, &store_ptr->stock[slot])) break;
1318 for (int i = store_ptr->stock_num; i > slot; i--)
1320 store_ptr->stock[i] = store_ptr->stock[i - 1];
1323 store_ptr->stock_num++;
1324 store_ptr->stock[slot] = *o_ptr;
1325 chg_virtue(player_ptr, V_SACRIFICE, -1);
1330 * @brief 店舗情報を読み込む / Read a store
1331 * @param player_ptr プレーヤーへの参照ポインタ
1332 * @param town_number 街ID
1333 * @param store_number 店舗ID
1336 static errr rd_store(player_type *player_ptr, int town_number, int store_number)
1338 store_type *store_ptr;
1340 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1342 store_ptr = &town_info[1].store[store_number];
1343 if (store_ptr->stock_num) sort = TRUE;
1347 store_ptr = &town_info[town_number].store[store_number];
1353 rd_s32b(&store_ptr->store_open);
1354 rd_s16b(&store_ptr->insult_cur);
1356 if (z_older_than(11, 0, 4))
1366 rd_s16b(&store_ptr->good_buy);
1367 rd_s16b(&store_ptr->bad_buy);
1369 rd_s32b(&store_ptr->last_visit);
1370 store_ptr->owner = own;
1372 for (int j = 0; j < num; j++)
1381 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);
1382 if (!is_valid_item) continue;
1386 home_carry(player_ptr, store_ptr, q_ptr);
1390 int k = store_ptr->stock_num++;
1391 object_copy(&store_ptr->stock[k], q_ptr);
1400 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1403 static void rd_randomizer(void)
1407 rd_u16b(&Rand_place);
1408 for (int i = 0; i < RAND_DEG; i++)
1410 rd_u32b(&Rand_state[i]);
1416 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1419 * Note that the normal options are now stored as a set of 256 bit flags,
1420 * plus a set of 256 bit masks to indicate which bit flags were defined
1421 * at the time the savefile was created. This will allow new options
1422 * to be added, and old options to be removed, at any time, without
1423 * hurting old savefiles.
1425 * The window options are stored in the same way, but note that each
1426 * window gets 32 options, and their order is fixed by certain defines.
1428 static void rd_options(void)
1439 if (h_older_than(1, 7, 0, 0))
1452 if (c & 0x0002) current_world_ptr->wizard = TRUE;
1454 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1455 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1456 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1457 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1458 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1459 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1460 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1461 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1462 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1463 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1465 rd_byte((byte *)&autosave_l);
1466 rd_byte((byte *)&autosave_t);
1467 rd_s16b(&autosave_freq);
1470 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1473 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1475 for (int n = 0; n < 8; n++)
1477 for (int i = 0; i < 32; i++)
1479 if (!(mask[n] & (1L << i))) continue;
1480 if (!(option_mask[n] & (1L << i))) continue;
1482 if (flag[n] & (1L << i))
1484 option_flag[n] |= (1L << i);
1488 option_flag[n] &= ~(1L << i);
1493 if (z_older_than(10, 4, 5))
1495 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1496 else option_flag[5] |= (0x00000001 << 4);
1497 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1498 else option_flag[2] |= (0x00000001 << 5);
1499 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1500 else option_flag[4] |= (0x00000001 << 5);
1501 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1502 else option_flag[5] |= (0x00000001 << 0);
1503 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1504 else option_flag[5] |= (0x00000001 << 12);
1505 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1506 else option_flag[1] |= (0x00000001 << 0);
1507 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1508 else option_flag[1] |= (0x00000001 << 18);
1509 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1510 else option_flag[1] |= (0x00000001 << 19);
1511 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1512 else option_flag[5] |= (0x00000001 << 3);
1515 extract_option_vars();
1516 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1518 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1520 for (int n = 0; n < 8; n++)
1522 for (int i = 0; i < 32; i++)
1524 if (!(mask[n] & (1L << i))) continue;
1525 if (!(window_mask[n] & (1L << i))) continue;
1527 if (flag[n] & (1L << i))
1529 window_flag[n] |= (1L << i);
1533 window_flag[n] &= ~(1L << i);
1541 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1544 * This is such a nasty hack it hurts.
1546 static void rd_ghost(void)
1549 rd_string(buf, sizeof(buf));
1555 * @brief クイックスタート情報を読み込む / Load quick start data
1558 static void load_quick_start(void)
1560 if (z_older_than(11, 0, 13))
1562 previous_char.quick_ok = FALSE;
1566 rd_byte(&previous_char.psex);
1569 previous_char.prace = (player_race_table)tmp8u;
1571 previous_char.pclass = (CLASS_IDX)tmp8u;
1573 previous_char.pseikaku = (CHARACTER_IDX)tmp8u;
1575 previous_char.realm1 = (REALM_IDX)tmp8u;
1577 previous_char.realm2 = (REALM_IDX)tmp8u;
1579 rd_s16b(&previous_char.age);
1580 rd_s16b(&previous_char.ht);
1581 rd_s16b(&previous_char.wt);
1582 rd_s16b(&previous_char.sc);
1583 rd_s32b(&previous_char.au);
1585 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1586 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1588 for (int i = 0; i < PY_MAX_LEVEL; i++)
1592 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1595 rd_s16b(&previous_char.chaos_patron);
1597 for (int i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1599 for (int i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1603 previous_char.quick_ok = (bool)tmp8u;
1608 * @brief その他の情報を読み込む / Read the "extra" information
1611 static void rd_extra(player_type *creature_ptr)
1613 rd_string(creature_ptr->name, sizeof(creature_ptr->name));
1614 rd_string(creature_ptr->died_from, sizeof(creature_ptr->died_from));
1615 if (!h_older_than(1, 7, 0, 1))
1618 rd_string(buf, sizeof buf);
1619 if (buf[0]) creature_ptr->last_message = string_make(buf);
1623 for (int i = 0; i < 4; i++)
1625 rd_string(creature_ptr->history[i], sizeof(creature_ptr->history[i]));
1630 creature_ptr->prace = (player_race_table)tmp8u;
1633 creature_ptr->pclass = (CLASS_IDX)tmp8u;
1636 creature_ptr->pseikaku = (CHARACTER_IDX)tmp8u;
1638 rd_byte(&creature_ptr->psex);
1640 creature_ptr->realm1 = (REALM_IDX)tmp8u;
1643 creature_ptr->realm2 = (REALM_IDX)tmp8u;
1646 if (z_older_than(10, 4, 4))
1648 if (creature_ptr->realm1 == 9) creature_ptr->realm1 = REALM_MUSIC;
1649 if (creature_ptr->realm2 == 9) creature_ptr->realm2 = REALM_MUSIC;
1650 if (creature_ptr->realm1 == 10) creature_ptr->realm1 = REALM_HISSATSU;
1651 if (creature_ptr->realm2 == 10) creature_ptr->realm2 = REALM_HISSATSU;
1655 creature_ptr->hitdie = tmp8u;
1656 rd_u16b(&creature_ptr->expfact);
1658 rd_s16b(&creature_ptr->age);
1659 rd_s16b(&creature_ptr->ht);
1660 rd_s16b(&creature_ptr->wt);
1662 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max[i]);
1663 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max_max[i]);
1664 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_cur[i]);
1667 rd_s32b(&creature_ptr->au);
1669 rd_s32b(&creature_ptr->max_exp);
1670 if (h_older_than(1, 5, 4, 1)) creature_ptr->max_max_exp = creature_ptr->max_exp;
1671 else rd_s32b(&creature_ptr->max_max_exp);
1672 rd_s32b(&creature_ptr->exp);
1674 if (h_older_than(1, 7, 0, 3))
1678 creature_ptr->exp_frac = (u32b)tmp16u;
1682 rd_u32b(&creature_ptr->exp_frac);
1685 rd_s16b(&creature_ptr->lev);
1687 for (int i = 0; i < 64; i++) rd_s16b(&creature_ptr->spell_exp[i]);
1688 if ((creature_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1690 for (int i = 0; i < 64; i++) creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1693 if (z_older_than(10, 3, 6))
1694 for (int i = 0; i < 5; i++) for (int j = 0; j < 60; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1696 for (int i = 0; i < 5; i++) for (int j = 0; j < 64; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1697 for (int i = 0; i < GINOU_MAX; i++) rd_s16b(&creature_ptr->skill_exp[i]);
1698 if (z_older_than(10, 4, 1))
1700 if (creature_ptr->pclass != CLASS_BEASTMASTER) creature_ptr->skill_exp[GINOU_RIDING] /= 2;
1701 creature_ptr->skill_exp[GINOU_RIDING] = MIN(creature_ptr->skill_exp[GINOU_RIDING], s_info[creature_ptr->pclass].s_max[GINOU_RIDING]);
1704 if (z_older_than(10, 3, 14))
1706 for (int i = 0; i < 108; i++) creature_ptr->magic_num1[i] = 0;
1707 for (int i = 0; i < 108; i++) creature_ptr->magic_num2[i] = 0;
1711 for (int i = 0; i < 108; i++) rd_s32b(&creature_ptr->magic_num1[i]);
1712 for (int i = 0; i < 108; i++) rd_byte(&creature_ptr->magic_num2[i]);
1713 if (h_older_than(1, 3, 0, 1))
1715 if (creature_ptr->pclass == CLASS_SMITH)
1717 creature_ptr->magic_num1[TR_ES_ATTACK] = creature_ptr->magic_num1[96];
1718 creature_ptr->magic_num1[96] = 0;
1719 creature_ptr->magic_num1[TR_ES_AC] = creature_ptr->magic_num1[97];
1720 creature_ptr->magic_num1[97] = 0;
1725 if (music_singing_any(creature_ptr)) creature_ptr->action = ACTION_SING;
1727 if (z_older_than(11, 0, 7))
1729 creature_ptr->start_race = creature_ptr->prace;
1730 creature_ptr->old_race1 = 0L;
1731 creature_ptr->old_race2 = 0L;
1732 creature_ptr->old_realm = 0;
1737 creature_ptr->start_race = (player_race_table)tmp8u;
1740 creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1742 creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1743 rd_s16b(&creature_ptr->old_realm);
1746 if (z_older_than(10, 0, 1))
1748 for (int i = 0; i < MAX_MANE; i++)
1750 creature_ptr->mane_spell[i] = -1;
1751 creature_ptr->mane_dam[i] = 0;
1753 creature_ptr->mane_num = 0;
1755 else if (z_older_than(10, 2, 3))
1758 for (int i = 0; i < OLD_MAX_MANE; i++)
1764 for (int i = 0; i < MAX_MANE; i++)
1766 creature_ptr->mane_spell[i] = -1;
1767 creature_ptr->mane_dam[i] = 0;
1771 creature_ptr->mane_num = 0;
1775 for (int i = 0; i < MAX_MANE; i++)
1779 creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1781 creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1784 rd_s16b(&creature_ptr->mane_num);
1787 if (z_older_than(10, 0, 3))
1789 determine_bounty_uniques(creature_ptr);
1791 for (int i = 0; i < MAX_BOUNTY; i++)
1793 /* Is this bounty unique already dead? */
1794 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1799 for (int i = 0; i < MAX_BOUNTY; i++)
1801 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1805 if (z_older_than(10, 0, 3))
1807 update_gambling_monsters(creature_ptr);
1811 for (int i = 0; i < 4; i++)
1813 rd_s16b(&battle_mon[i]);
1814 if (z_older_than(10, 3, 4))
1818 mon_odds[i] = tmp16s;
1820 else rd_u32b(&mon_odds[i]);
1824 rd_s16b(&creature_ptr->town_num);
1825 rd_s16b(&creature_ptr->arena_number);
1826 if (h_older_than(1, 5, 0, 1))
1828 if (creature_ptr->arena_number >= 99) creature_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1833 creature_ptr->current_floor_ptr->inside_arena = (bool)tmp16s;
1834 rd_s16b(&creature_ptr->current_floor_ptr->inside_quest);
1835 if (z_older_than(10, 3, 5)) creature_ptr->phase_out = FALSE;
1839 creature_ptr->phase_out = (bool)tmp16s;
1842 rd_byte(&creature_ptr->exit_bldg);
1846 creature_ptr->oldpx = (POSITION)tmp16s;
1849 creature_ptr->oldpy = (POSITION)tmp16s;
1850 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; }
1853 for (int i = 0; i < tmp16s; i++)
1859 if (h_older_than(1, 7, 0, 3))
1862 creature_ptr->mhp = tmp16s;
1865 creature_ptr->chp = tmp16s;
1869 creature_ptr->chp_frac = (u32b)tmp16u;
1873 rd_s32b(&creature_ptr->mhp);
1874 rd_s32b(&creature_ptr->chp);
1875 rd_u32b(&creature_ptr->chp_frac);
1878 if (h_older_than(1, 7, 0, 3))
1881 creature_ptr->msp = tmp16s;
1884 creature_ptr->csp = tmp16s;
1888 creature_ptr->csp_frac = (u32b)tmp16u;
1892 rd_s32b(&creature_ptr->msp);
1893 rd_s32b(&creature_ptr->csp);
1894 rd_u32b(&creature_ptr->csp_frac);
1897 rd_s16b(&creature_ptr->max_plv);
1898 if (z_older_than(10, 3, 8))
1901 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1905 byte max = (byte)current_world_ptr->max_d_idx;
1909 for (int i = 0; i < max; i++)
1912 max_dlv[i] = tmp16s;
1913 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1917 if (creature_ptr->max_plv < creature_ptr->lev) creature_ptr->max_plv = creature_ptr->lev;
1920 rd_s16b(&creature_ptr->sc);
1921 rd_s16b(&creature_ptr->concent);
1923 strip_bytes(2); /* Old "rest" */
1924 rd_s16b(&creature_ptr->blind);
1925 rd_s16b(&creature_ptr->paralyzed);
1926 rd_s16b(&creature_ptr->confused);
1927 rd_s16b(&creature_ptr->food);
1928 strip_bytes(4); /* Old "food_digested" / "protection" */
1930 rd_s16b(&creature_ptr->energy_need);
1931 if (z_older_than(11, 0, 13))
1932 creature_ptr->energy_need = 100 - creature_ptr->energy_need;
1933 if (h_older_than(2, 1, 2, 0))
1934 creature_ptr->enchant_energy_need = 0;
1936 rd_s16b(&creature_ptr->enchant_energy_need);
1938 rd_s16b(&creature_ptr->fast);
1939 rd_s16b(&creature_ptr->slow);
1940 rd_s16b(&creature_ptr->afraid);
1941 rd_s16b(&creature_ptr->cut);
1942 rd_s16b(&creature_ptr->stun);
1943 rd_s16b(&creature_ptr->poisoned);
1944 rd_s16b(&creature_ptr->image);
1945 rd_s16b(&creature_ptr->protevil);
1946 rd_s16b(&creature_ptr->invuln);
1947 if (z_older_than(10, 0, 0))
1948 creature_ptr->ult_res = 0;
1950 rd_s16b(&creature_ptr->ult_res);
1951 rd_s16b(&creature_ptr->hero);
1952 rd_s16b(&creature_ptr->shero);
1953 rd_s16b(&creature_ptr->shield);
1954 rd_s16b(&creature_ptr->blessed);
1955 rd_s16b(&creature_ptr->tim_invis);
1956 rd_s16b(&creature_ptr->word_recall);
1957 if (z_older_than(10, 3, 8))
1958 creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
1962 creature_ptr->recall_dungeon = (byte)tmp16s;
1965 if (h_older_than(1, 5, 0, 0))
1966 creature_ptr->alter_reality = 0;
1968 rd_s16b(&creature_ptr->alter_reality);
1970 rd_s16b(&creature_ptr->see_infra);
1971 rd_s16b(&creature_ptr->tim_infra);
1972 rd_s16b(&creature_ptr->oppose_fire);
1973 rd_s16b(&creature_ptr->oppose_cold);
1974 rd_s16b(&creature_ptr->oppose_acid);
1975 rd_s16b(&creature_ptr->oppose_elec);
1976 rd_s16b(&creature_ptr->oppose_pois);
1977 if (z_older_than(10, 0, 2)) creature_ptr->tsuyoshi = 0;
1978 else rd_s16b(&creature_ptr->tsuyoshi);
1980 /* Old savefiles do not have the following fields... */
1981 if ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->z_patch == 6))
1983 creature_ptr->tim_esp = 0;
1984 creature_ptr->wraith_form = 0;
1985 creature_ptr->resist_magic = 0;
1986 creature_ptr->tim_regen = 0;
1987 creature_ptr->kabenuke = 0;
1988 creature_ptr->tim_stealth = 0;
1989 creature_ptr->tim_levitation = 0;
1990 creature_ptr->tim_sh_touki = 0;
1991 creature_ptr->lightspeed = 0;
1992 creature_ptr->tsubureru = 0;
1993 creature_ptr->tim_res_nether = 0;
1994 creature_ptr->tim_res_time = 0;
1995 creature_ptr->mimic_form = 0;
1996 creature_ptr->tim_mimic = 0;
1997 creature_ptr->tim_sh_fire = 0;
1998 creature_ptr->tim_reflect = 0;
1999 creature_ptr->multishadow = 0;
2000 creature_ptr->dustrobe = 0;
2001 creature_ptr->chaos_patron = ((creature_ptr->age + creature_ptr->sc) % MAX_PATRON);
2002 creature_ptr->muta1 = 0;
2003 creature_ptr->muta2 = 0;
2004 creature_ptr->muta3 = 0;
2005 get_virtues(creature_ptr);
2009 rd_s16b(&creature_ptr->tim_esp);
2010 rd_s16b(&creature_ptr->wraith_form);
2011 rd_s16b(&creature_ptr->resist_magic);
2012 rd_s16b(&creature_ptr->tim_regen);
2013 rd_s16b(&creature_ptr->kabenuke);
2014 rd_s16b(&creature_ptr->tim_stealth);
2015 rd_s16b(&creature_ptr->tim_levitation);
2016 rd_s16b(&creature_ptr->tim_sh_touki);
2017 rd_s16b(&creature_ptr->lightspeed);
2018 rd_s16b(&creature_ptr->tsubureru);
2019 if (z_older_than(10, 4, 7))
2020 creature_ptr->magicdef = 0;
2022 rd_s16b(&creature_ptr->magicdef);
2023 rd_s16b(&creature_ptr->tim_res_nether);
2024 if (z_older_than(10, 4, 11))
2026 creature_ptr->tim_res_time = 0;
2027 creature_ptr->mimic_form = 0;
2028 creature_ptr->tim_mimic = 0;
2029 creature_ptr->tim_sh_fire = 0;
2033 rd_s16b(&creature_ptr->tim_res_time);
2035 creature_ptr->mimic_form = (IDX)tmp8u;
2036 rd_s16b(&creature_ptr->tim_mimic);
2037 rd_s16b(&creature_ptr->tim_sh_fire);
2040 if (z_older_than(11, 0, 99))
2042 creature_ptr->tim_sh_holy = 0;
2043 creature_ptr->tim_eyeeye = 0;
2047 rd_s16b(&creature_ptr->tim_sh_holy);
2048 rd_s16b(&creature_ptr->tim_eyeeye);
2051 if (z_older_than(11, 0, 3)) {
2052 creature_ptr->tim_reflect = 0;
2053 creature_ptr->multishadow = 0;
2054 creature_ptr->dustrobe = 0;
2058 rd_s16b(&creature_ptr->tim_reflect);
2059 rd_s16b(&creature_ptr->multishadow);
2060 rd_s16b(&creature_ptr->dustrobe);
2063 rd_s16b(&creature_ptr->chaos_patron);
2064 rd_u32b(&creature_ptr->muta1);
2065 rd_u32b(&creature_ptr->muta2);
2066 rd_u32b(&creature_ptr->muta3);
2068 for (int i = 0; i < 8; i++)
2069 rd_s16b(&creature_ptr->virtues[i]);
2070 for (int i = 0; i < 8; i++)
2071 rd_s16b(&creature_ptr->vir_types[i]);
2074 creature_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod(creature_ptr);
2075 if (z_older_than(10, 0, 9))
2078 if (tmp8u) creature_ptr->special_attack = ATTACK_CONFUSE;
2079 creature_ptr->ele_attack = 0;
2083 rd_s16b(&creature_ptr->ele_attack);
2084 rd_u32b(&creature_ptr->special_attack);
2087 if (creature_ptr->special_attack & KAMAE_MASK) creature_ptr->action = ACTION_KAMAE;
2088 else if (creature_ptr->special_attack & KATA_MASK) creature_ptr->action = ACTION_KATA;
2089 if (z_older_than(10, 0, 12))
2091 creature_ptr->ele_immune = 0;
2092 creature_ptr->special_defense = 0;
2096 rd_s16b(&creature_ptr->ele_immune);
2097 rd_u32b(&creature_ptr->special_defense);
2100 rd_byte(&creature_ptr->knowledge);
2102 creature_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2106 creature_ptr->action = (ACTION_IDX)tmp8u;
2107 if (!z_older_than(10, 4, 3))
2110 if (tmp8u) creature_ptr->action = ACTION_LEARN;
2113 rd_byte((byte *)&preserve_mode);
2114 rd_byte((byte *)&creature_ptr->wait_report_score);
2116 for (int i = 0; i < 48; i++) rd_byte(&tmp8u);
2119 rd_u32b(¤t_world_ptr->seed_flavor);
2120 rd_u32b(¤t_world_ptr->seed_town);
2122 rd_u16b(&creature_ptr->panic_save);
2123 rd_u16b(¤t_world_ptr->total_winner);
2124 rd_u16b(¤t_world_ptr->noscore);
2127 creature_ptr->is_dead = tmp8u;
2129 rd_byte(&creature_ptr->feeling);
2131 switch (creature_ptr->start_race)
2137 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2140 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2144 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2145 rd_s32b(&creature_ptr->current_floor_ptr->generated_turn);
2146 if (h_older_than(1, 7, 0, 4))
2148 creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
2152 rd_s32b(&creature_ptr->feeling_turn);
2155 rd_s32b(¤t_world_ptr->game_turn);
2156 if (z_older_than(10, 3, 12))
2158 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2160 else rd_s32b(¤t_world_ptr->dungeon_turn);
2162 if (z_older_than(11, 0, 13))
2164 creature_ptr->current_floor_ptr->generated_turn /= 2;
2165 creature_ptr->feeling_turn /= 2;
2166 current_world_ptr->game_turn /= 2;
2167 current_world_ptr->dungeon_turn /= 2;
2170 if (z_older_than(10, 3, 13))
2172 current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
2174 else rd_s32b(¤t_world_ptr->arena_start_turn);
2176 if (z_older_than(10, 0, 3))
2178 determine_daily_bounty(creature_ptr, TRUE);
2182 rd_s16b(&today_mon);
2183 rd_s16b(&creature_ptr->today_mon);
2186 if (z_older_than(10, 0, 7))
2188 creature_ptr->riding = 0;
2192 rd_s16b(&creature_ptr->riding);
2195 if (h_older_than(1, 5, 0, 0))
2197 creature_ptr->floor_id = 0;
2201 rd_s16b(&creature_ptr->floor_id);
2204 if (h_older_than(1, 5, 0, 2))
2211 for (int i = 0; i < tmp16s; i++)
2213 monster_type dummy_mon;
2214 rd_monster(creature_ptr, &dummy_mon);
2218 if (z_older_than(10, 1, 2))
2220 current_world_ptr->play_time = 0;
2224 rd_u32b(¤t_world_ptr->play_time);
2227 if (z_older_than(10, 3, 9))
2229 creature_ptr->visit = 1L;
2231 else if (z_older_than(10, 3, 10))
2235 creature_ptr->visit = 1L;
2241 creature_ptr->visit = (BIT_FLAGS)tmp32s;
2244 if (!z_older_than(11, 0, 5))
2246 rd_u32b(&creature_ptr->count);
2252 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2253 * @param player_ptr プレーヤーへの参照ポインタ
2256 * Note that the inventory changed in Angband 2.7.4. Two extra
2257 * pack slots were added and the equipment was rearranged. Note
2258 * that these two features combine when parsing old save-files, in
2259 * which items from the old "aux" slot are "carried", perhaps into
2260 * one of the two new "inventory" slots.
2262 * Note that the inventory is "re-sorted" later by "dungeon()".
2264 static errr rd_inventory(player_type *player_ptr)
2266 player_ptr->total_weight = 0;
2267 player_ptr->inven_cnt = 0;
2268 player_ptr->equip_cnt = 0;
2270 if (player_ptr->inventory_list != NULL) C_WIPE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2271 C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2279 if (n == 0xFFFF) break;
2286 if (!q_ptr->k_idx) return (53);
2288 if (n >= INVEN_RARM)
2290 q_ptr->marked |= OM_TOUCHED;
2291 object_copy(&player_ptr->inventory_list[n], q_ptr);
2292 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2293 player_ptr->equip_cnt++;
2297 if (player_ptr->inven_cnt == INVEN_PACK)
2299 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
2304 q_ptr->marked |= OM_TOUCHED;
2305 object_copy(&player_ptr->inventory_list[n], q_ptr);
2306 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2307 player_ptr->inven_cnt++;
2315 * @brief メッセージログを読み込む / Read the saved messages
2318 static void rd_messages(void)
2320 if (h_older_than(2, 2, 0, 75))
2325 message_max = (int)num;
2327 for (int i = 0; i < message_max; i++)
2330 rd_string(buf, sizeof(buf));
2338 message_max = (int)num;
2340 for (int i = 0; i < message_max; i++)
2343 rd_string(buf, sizeof(buf));
2350 * @brief メッセージログを読み込む / Read the dungeon (old method)
2351 * @param creature_ptr プレーヤーへの参照ポインタ
2354 * The monsters/objects must be loaded in the same order
2355 * that they were stored, since the actual indexes matter.
2357 static errr rd_dungeon_old(player_type *creature_ptr)
2361 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2362 floor_ptr->dun_level = (DEPTH)tmp16s;
2363 if (z_older_than(10, 3, 8)) creature_ptr->dungeon_idx = DUNGEON_ANGBAND;
2368 creature_ptr->dungeon_idx = (IDX)tmp8u;
2371 floor_ptr->base_level = floor_ptr->dun_level;
2373 floor_ptr->base_level = (DEPTH)tmp16s;
2376 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2378 creature_ptr->y = (POSITION)tmp16s;
2380 creature_ptr->x = (POSITION)tmp16s;
2381 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) { creature_ptr->y = 33; creature_ptr->x = 131; }
2383 floor_ptr->height = (POSITION)tmp16s;
2385 floor_ptr->width = (POSITION)tmp16s;
2386 rd_s16b(&tmp16s); /* max_panel_rows */
2387 rd_s16b(&tmp16s); /* max_panel_cols */
2389 int ymax = floor_ptr->height;
2390 int xmax = floor_ptr->width;
2392 for (int x = 0, y = 0; y < ymax; )
2397 if (z_older_than(10, 3, 6))
2406 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2409 for (int i = count; i > 0; i--)
2412 g_ptr = &floor_ptr->grid_array[y][x];
2417 if (++y >= ymax) break;
2422 for (int x = 0, y = 0; y < ymax; )
2428 for (int i = count; i > 0; i--)
2431 g_ptr = &floor_ptr->grid_array[y][x];
2432 g_ptr->feat = (s16b)tmp8u;
2436 if (++y >= ymax) break;
2441 for (int x = 0, y = 0; y < ymax; )
2447 for (int i = count; i > 0; i--)
2450 g_ptr = &floor_ptr->grid_array[y][x];
2451 g_ptr->mimic = (s16b)tmp8u;
2455 if (++y >= ymax) break;
2460 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->special = tmp16s;
2473 if (++y >= ymax) break;
2478 if (z_older_than(11, 0, 99))
2480 for (int y = 0; y < ymax; y++)
2482 for (int x = 0; x < xmax; x++)
2484 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2489 if (h_older_than(1, 1, 1, 0))
2491 for (int y = 0; y < ymax; y++)
2493 for (int x = 0; x < xmax; x++)
2496 g_ptr = &floor_ptr->grid_array[y][x];
2499 if (g_ptr->feat == OLD_FEAT_INVIS)
2501 g_ptr->feat = feat_floor;
2502 g_ptr->info |= CAVE_TRAP;
2505 /* Older than 1.1.1 */
2506 if (g_ptr->feat == OLD_FEAT_MIRROR)
2508 g_ptr->feat = feat_floor;
2509 g_ptr->info |= CAVE_OBJECT;
2515 if (h_older_than(1, 3, 1, 0))
2517 for (int y = 0; y < ymax; y++)
2519 for (int x = 0; x < xmax; x++)
2522 g_ptr = &floor_ptr->grid_array[y][x];
2524 /* Old CAVE_IN_MIRROR flag */
2525 if (g_ptr->info & CAVE_OBJECT)
2527 g_ptr->mimic = feat_mirror;
2529 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2530 (g_ptr->feat == OLD_FEAT_GLYPH))
2532 g_ptr->info |= CAVE_OBJECT;
2533 g_ptr->mimic = g_ptr->feat;
2534 g_ptr->feat = feat_floor;
2536 else if (g_ptr->info & CAVE_TRAP)
2538 g_ptr->info &= ~CAVE_TRAP;
2539 g_ptr->mimic = g_ptr->feat;
2540 g_ptr->feat = choose_random_trap(creature_ptr);
2542 else if (g_ptr->feat == OLD_FEAT_INVIS)
2544 g_ptr->mimic = feat_floor;
2545 g_ptr->feat = feat_trap_open;
2551 /* Quest 18 was removed */
2552 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2554 for (int y = 0; y < ymax; y++)
2556 for (int x = 0; x < xmax; x++)
2559 g_ptr = &floor_ptr->grid_array[y][x];
2561 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2563 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2565 g_ptr->feat = feat_tree;
2568 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2570 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2573 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2574 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2576 g_ptr->feat = feat_up_stair;
2585 if (limit > current_world_ptr->max_o_idx)
2587 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2591 for (int i = 1; i < limit; i++)
2593 OBJECT_IDX o_idx = o_pop(floor_ptr);
2596 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2601 o_ptr = &floor_ptr->o_list[o_idx];
2603 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2605 monster_type *m_ptr;
2606 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2607 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2608 m_ptr->hold_o_idx = o_idx;
2613 g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2614 o_ptr->next_o_idx = g_ptr->o_idx;
2615 g_ptr->o_idx = o_idx;
2619 if (limit > current_world_ptr->max_m_idx)
2621 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2625 for (int i = 1; i < limit; i++)
2628 monster_type *m_ptr;
2629 m_idx = m_pop(creature_ptr);
2632 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2636 m_ptr = &floor_ptr->m_list[m_idx];
2637 rd_monster(creature_ptr, m_ptr);
2639 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2640 g_ptr->m_idx = m_idx;
2641 real_r_ptr(m_ptr)->cur_num++;
2644 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena)
2645 current_world_ptr->character_dungeon = FALSE;
2647 current_world_ptr->character_dungeon = TRUE;
2654 * @brief 保存されたフロアを読み込む / Read the saved floor
2655 * @param player_ptr プレーヤーへの参照ポインタ
2656 * @param sf_ptr 最後に保存されたフロアへの参照ポインタ
2657 * @return info読み込みエラーコード
2659 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2662 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2663 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2665 * The monsters/objects must be loaded in the same order
2666 * that they were stored, since the actual indexes matter.
2668 static errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
2670 grid_template_type *templates;
2671 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2672 clear_cave(player_ptr);
2673 player_ptr->x = player_ptr->y = 0;
2679 floor_ptr->dun_level = (DEPTH)tmp16s;
2680 floor_ptr->base_level = floor_ptr->dun_level;
2686 if (tmp16s != sf_ptr->floor_id) return 171;
2690 if (tmp8u != sf_ptr->savefile_id) return 171;
2693 if (tmp16s != sf_ptr->dun_level) return 171;
2694 floor_ptr->dun_level = sf_ptr->dun_level;
2698 if (tmp32s != sf_ptr->last_visit) return 171;
2702 if (tmp32u != sf_ptr->visit_mark) return 171;
2705 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2708 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2713 floor_ptr->base_level = (DEPTH)tmp16s;
2715 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2719 player_ptr->y = (POSITION)tmp16u;
2722 player_ptr->x = (POSITION)tmp16u;
2725 floor_ptr->height = (POSITION)tmp16s;
2727 floor_ptr->width = (POSITION)tmp16s;
2729 rd_byte(&player_ptr->feeling);
2733 C_MAKE(templates, limit, grid_template_type);
2735 for (int i = 0; i < limit; i++)
2737 grid_template_type *ct_ptr = &templates[i];
2739 ct_ptr->info = (BIT_FLAGS)tmp16u;
2740 if (h_older_than(1, 7, 0, 2))
2744 ct_ptr->feat = (s16b)tmp8u;
2746 ct_ptr->mimic = (s16b)tmp8u;
2750 rd_s16b(&ct_ptr->feat);
2751 rd_s16b(&ct_ptr->mimic);
2754 rd_s16b(&ct_ptr->special);
2757 POSITION ymax = floor_ptr->height;
2758 POSITION xmax = floor_ptr->width;
2759 for (POSITION x = 0, y = 0; y < ymax; )
2770 } while (tmp8u == MAX_UCHAR);
2772 for (int i = count; i > 0; i--)
2774 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2775 g_ptr->info = templates[id].info;
2776 g_ptr->feat = templates[id].feat;
2777 g_ptr->mimic = templates[id].mimic;
2778 g_ptr->special = templates[id].special;
2783 if (++y >= ymax) break;
2788 /* Quest 18 was removed */
2789 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2791 for (POSITION y = 0; y < ymax; y++)
2793 for (POSITION x = 0; x < xmax; x++)
2795 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2797 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2799 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2801 g_ptr->feat = feat_tree;
2804 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2806 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2809 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2810 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2812 g_ptr->feat = feat_up_stair;
2819 C_KILL(templates, limit, grid_template_type);
2821 if (limit > current_world_ptr->max_o_idx) return 151;
2822 for (int i = 1; i < limit; i++)
2826 o_idx = o_pop(floor_ptr);
2827 if (i != o_idx) return 152;
2829 o_ptr = &floor_ptr->o_list[o_idx];
2832 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2834 monster_type *m_ptr;
2835 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2836 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2837 m_ptr->hold_o_idx = o_idx;
2841 grid_type *g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2842 o_ptr->next_o_idx = g_ptr->o_idx;
2843 g_ptr->o_idx = o_idx;
2848 if (limit > current_world_ptr->max_m_idx) return 161;
2850 for (int i = 1; i < limit; i++)
2854 monster_type *m_ptr;
2855 m_idx = m_pop(player_ptr);
2856 if (i != m_idx) return 162;
2858 m_ptr = &floor_ptr->m_list[m_idx];
2859 rd_monster(player_ptr, m_ptr);
2860 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2861 g_ptr->m_idx = m_idx;
2862 real_r_ptr(m_ptr)->cur_num++;
2870 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
2871 * @param player_ptr プレーヤーへの参照ポインタ
2874 * The monsters/objects must be loaded in the same order
2875 * that they were stored, since the actual indexes matter.
2877 static errr rd_dungeon(player_type *player_ptr)
2879 init_saved_floors(player_ptr, FALSE);
2881 if (h_older_than(1, 5, 0, 0))
2883 err = rd_dungeon_old(player_ptr);
2884 if (player_ptr->dungeon_idx)
2886 player_ptr->floor_id = get_new_floor_id(player_ptr);
2887 get_sf_ptr(player_ptr->floor_id)->dun_level = player_ptr->current_floor_ptr->dun_level;
2893 rd_s16b(&max_floor_id);
2896 player_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
2901 err = rd_saved_floor(player_ptr, NULL);
2905 for (int i = 0; i < num; i++)
2907 saved_floor_type *sf_ptr = &saved_floors[i];
2909 rd_s16b(&sf_ptr->floor_id);
2911 sf_ptr->savefile_id = (s16b)tmp8u;
2915 sf_ptr->dun_level = (DEPTH)tmp16s;
2917 rd_s32b(&sf_ptr->last_visit);
2918 rd_u32b(&sf_ptr->visit_mark);
2919 rd_s16b(&sf_ptr->upper_floor_id);
2920 rd_s16b(&sf_ptr->lower_floor_id);
2923 for (int i = 0; i < num; i++)
2925 saved_floor_type *sf_ptr = &saved_floors[i];
2926 if (!sf_ptr->floor_id) continue;
2928 if (tmp8u) continue;
2930 err = rd_saved_floor(player_ptr, sf_ptr);
2933 if (!save_floor(player_ptr, sf_ptr, SLF_SECOND)) err = 182;
2940 if (!load_floor(player_ptr, get_sf_ptr(player_ptr->floor_id), SLF_SECOND)) err = 183;
2947 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
2951 note(_("アイテム配置エラー", "Object allocation error"));
2955 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
2959 note(_("モンスター配置エラー", "Monster allocation error"));
2963 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
2967 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporary files!"));
2971 note(_("Error 183", "Error 183"));
2975 current_world_ptr->character_dungeon = TRUE;
2981 * @brief ロード処理全体のサブ関数 / Actually read the savefile
2984 static errr rd_savefile_new_aux(player_type *creature_ptr)
2986 u32b n_x_check, n_v_check;
2987 u32b o_x_check, o_v_check;
2990 xor_byte = current_world_ptr->sf_extra;
2994 /* Old savefile will be version 0.0.0.3 */
2995 rd_byte(¤t_world_ptr->h_ver_extra);
2996 rd_byte(¤t_world_ptr->h_ver_patch);
2997 rd_byte(¤t_world_ptr->h_ver_minor);
2998 rd_byte(¤t_world_ptr->h_ver_major);
3001 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3002 (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));
3004 rd_u32b(¤t_world_ptr->sf_system);
3005 rd_u32b(¤t_world_ptr->sf_when);
3006 rd_u16b(¤t_world_ptr->sf_lives);
3007 rd_u16b(¤t_world_ptr->sf_saves);
3017 rd_byte(&kanji_code);
3020 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3023 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3026 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3028 for (int i = 0; i < max_r_idx; i++)
3030 monster_race *r_ptr = &r_info[i];
3031 r_ptr->max_num = 100;
3033 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3034 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3038 if (tmp16u > max_r_idx)
3040 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3044 for (int i = 0; i < tmp16u; i++)
3046 rd_lore((MONRACE_IDX)i);
3049 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3052 if (tmp16u > max_k_idx)
3054 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3058 for (int i = 0; i < tmp16u; i++)
3060 object_kind *k_ptr = &k_info[i];
3062 k_ptr->aware = (tmp8u & 0x01) ? TRUE : FALSE;
3063 k_ptr->tried = (tmp8u & 0x02) ? TRUE : FALSE;
3065 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3067 /* 2.1.3 or newer version */
3069 u16b max_towns_load;
3070 u16b max_quests_load;
3071 byte max_rquests_load;
3072 s16b old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
3074 rd_u16b(&max_towns_load);
3075 if (max_towns_load > max_towns)
3077 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3081 rd_u16b(&max_quests_load);
3082 if (z_older_than(11, 0, 7))
3084 max_rquests_load = 10;
3088 rd_byte(&max_rquests_load);
3091 if (max_quests_load > max_q_idx)
3093 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3097 for (int i = 0; i < max_quests_load; i++)
3106 quest_type* const q_ptr = &quest[i];
3108 rd_s16b(&q_ptr->status);
3111 q_ptr->level = tmp16s;
3113 if (z_older_than(11, 0, 6))
3120 q_ptr->complev = tmp8u;
3122 if (h_older_than(2, 1, 2, 2))
3124 q_ptr->comptime = 0;
3128 rd_u32b(&q_ptr->comptime);
3131 bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
3132 is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
3133 is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
3134 if (!is_quest_running) continue;
3137 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3139 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3140 rd_s16b(&q_ptr->type);
3142 rd_s16b(&q_ptr->r_idx);
3143 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3145 determine_random_questor(creature_ptr, &quest[i]);
3148 rd_s16b(&q_ptr->k_idx);
3150 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3153 q_ptr->flags = tmp8u;
3155 if (z_older_than(10, 3, 11))
3157 if (q_ptr->flags & QUEST_FLAG_PRESET)
3163 init_flags = INIT_ASSIGN;
3164 creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)i;
3166 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
3167 creature_ptr->current_floor_ptr->inside_quest = old_inside_quest;
3173 q_ptr->dungeon = tmp8u;
3176 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3177 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3178 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3181 /* Quest 18 was removed */
3182 if (h_older_than(1, 7, 0, 6))
3184 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3185 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3188 rd_s32b(&creature_ptr->wilderness_x);
3189 rd_s32b(&creature_ptr->wilderness_y);
3190 if (z_older_than(10, 3, 13))
3192 creature_ptr->wilderness_x = 5;
3193 creature_ptr->wilderness_y = 48;
3196 if (z_older_than(10, 3, 7)) creature_ptr->wild_mode = FALSE;
3197 else rd_byte((byte *)&creature_ptr->wild_mode);
3198 if (z_older_than(10, 3, 7)) creature_ptr->ambush_flag = FALSE;
3199 else rd_byte((byte *)&creature_ptr->ambush_flag);
3203 rd_s32b(&wild_x_size);
3204 rd_s32b(&wild_y_size);
3206 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3208 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3212 for (int i = 0; i < wild_x_size; i++)
3214 for (int j = 0; j < wild_y_size; j++)
3216 rd_u32b(&wilderness[j][i].seed);
3221 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3224 if (tmp16u > max_a_idx)
3226 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3230 for (int i = 0; i < tmp16u; i++)
3232 artifact_type *a_ptr = &a_info[i];
3235 a_ptr->cur_num = tmp8u;
3237 if (h_older_than(1, 5, 0, 0))
3239 a_ptr->floor_id = 0;
3247 rd_s16b(&a_ptr->floor_id);
3251 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3253 rd_extra(creature_ptr);
3254 if (creature_ptr->energy_need < -999) creature_ptr->timewalk = TRUE;
3256 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3259 if (tmp16u > PY_MAX_LEVEL)
3261 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3265 for (int i = 0; i < tmp16u; i++)
3269 creature_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3272 sp_ptr = &sex_info[creature_ptr->psex];
3273 rp_ptr = &race_info[creature_ptr->prace];
3274 cp_ptr = &class_info[creature_ptr->pclass];
3275 ap_ptr = &seikaku_info[creature_ptr->pseikaku];
3277 if (z_older_than(10, 2, 2) && (creature_ptr->pclass == CLASS_BEASTMASTER) && !creature_ptr->is_dead)
3279 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3280 roll_hitdice(creature_ptr, 0L);
3283 if (z_older_than(10, 3, 2) && (creature_ptr->pclass == CLASS_ARCHER) && !creature_ptr->is_dead)
3285 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3286 roll_hitdice(creature_ptr, 0L);
3289 if (z_older_than(10, 2, 6) && (creature_ptr->pclass == CLASS_SORCERER) && !creature_ptr->is_dead)
3291 creature_ptr->hitdie = rp_ptr->r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3292 roll_hitdice(creature_ptr, 0L);
3295 if (z_older_than(10, 4, 7) && (creature_ptr->pclass == CLASS_BLUE_MAGE) && !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 mp_ptr = &m_info[creature_ptr->pclass];
3303 rd_u32b(&creature_ptr->spell_learned1);
3304 rd_u32b(&creature_ptr->spell_learned2);
3305 rd_u32b(&creature_ptr->spell_worked1);
3306 rd_u32b(&creature_ptr->spell_worked2);
3307 rd_u32b(&creature_ptr->spell_forgotten1);
3308 rd_u32b(&creature_ptr->spell_forgotten2);
3310 if (z_older_than(10, 0, 5))
3312 creature_ptr->learned_spells = 0;
3313 for (int i = 0; i < 64; i++)
3316 (creature_ptr->spell_learned1 & (1L << i)) :
3317 (creature_ptr->spell_learned2 & (1L << (i - 32))))
3319 creature_ptr->learned_spells++;
3323 else rd_s16b(&creature_ptr->learned_spells);
3325 if (z_older_than(10, 0, 6))
3327 creature_ptr->add_spells = 0;
3329 else rd_s16b(&creature_ptr->add_spells);
3331 if (creature_ptr->pclass == CLASS_MINDCRAFTER) creature_ptr->add_spells = 0;
3333 for (int i = 0; i < 64; i++)
3336 creature_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3339 if (rd_inventory(creature_ptr))
3341 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3346 int town_count = tmp16u;
3349 for (int i = 1; i < town_count; i++)
3351 for (int j = 0; j < tmp16u; j++)
3353 if (rd_store(creature_ptr, i, j)) return (22);
3357 rd_s16b(&creature_ptr->pet_follow_distance);
3358 if (z_older_than(10, 4, 10))
3360 creature_ptr->pet_extra_flags = 0;
3362 if (tmp8u) creature_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3364 if (tmp8u) creature_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3366 if (z_older_than(10, 0, 4)) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3370 if (tmp8u) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3373 if (z_older_than(10, 0, 7)) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3377 if (tmp8u) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3380 if (z_older_than(10, 0, 8)) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3384 if (tmp8u) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3387 if (!z_older_than(10, 0, 8))
3390 if (tmp8u) creature_ptr->pet_extra_flags |= PF_BALL_SPELL;
3395 rd_s16b(&creature_ptr->pet_extra_flags);
3398 if (!z_older_than(11, 0, 9))
3400 char buf[SCREEN_BUF_MAX_SIZE];
3401 rd_string(buf, sizeof(buf));
3402 if (buf[0]) screen_dump = string_make(buf);
3405 if (creature_ptr->is_dead)
3407 for (int i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3409 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3413 if (!creature_ptr->is_dead)
3415 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3416 if (rd_dungeon(creature_ptr))
3418 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3427 strip_bytes(tmp32s);
3431 /* Quest 18 was removed */
3432 if (h_older_than(1, 7, 0, 6))
3434 if (creature_ptr->current_floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3436 creature_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3437 creature_ptr->current_floor_ptr->dun_level = 1;
3438 creature_ptr->current_floor_ptr->inside_quest = 0;
3442 n_v_check = v_check;
3443 rd_u32b(&o_v_check);
3444 if (o_v_check != n_v_check)
3446 note(_("チェックサムがおかしい", "Invalid checksum"));
3450 n_x_check = x_check;
3451 rd_u32b(&o_x_check);
3452 if (o_x_check != n_x_check)
3454 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3463 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3464 * @param player_ptr プレーヤーへの参照ポインタ
3467 errr rd_savefile_new(player_type *player_ptr)
3470 fff = my_fopen(savefile, "rb");
3472 if (!fff) return -1;
3473 errr err = rd_savefile_new_aux(player_ptr);
3475 if (ferror(fff)) err = -1;
3482 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3483 * @param player_ptr プレーヤーへの参照ポインタ
3484 * @param sf_ptr 保存フロア読み込み先
3487 static bool load_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
3489 u32b n_x_check, n_v_check;
3490 u32b o_x_check, o_v_check;
3499 current_world_ptr->h_ver_extra = H_VER_EXTRA;
3500 current_world_ptr->h_ver_patch = H_VER_PATCH;
3501 current_world_ptr->h_ver_minor = H_VER_MINOR;
3502 current_world_ptr->h_ver_major = H_VER_MAJOR;
3506 if (saved_floor_file_sign != tmp32u) return FALSE;
3508 if (rd_saved_floor(player_ptr, sf_ptr)) return FALSE;
3510 n_v_check = v_check;
3511 rd_u32b(&o_v_check);
3513 if (o_v_check != n_v_check) return FALSE;
3515 n_x_check = x_check;
3516 rd_u32b(&o_x_check);
3518 if (o_x_check != n_x_check) return FALSE;
3524 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporarily saved-floor data
3525 * @param player_ptr プレーヤーへの参照ポインタ
3526 * @param sf_ptr 保存フロア読み込み先
3530 bool load_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
3533 * Temporary files are always written in system depended kanji
3547 FILE *old_fff = NULL;
3548 byte old_xor_byte = 0;
3549 u32b old_v_check = 0;
3550 u32b old_x_check = 0;
3551 byte old_h_ver_major = 0;
3552 byte old_h_ver_minor = 0;
3553 byte old_h_ver_patch = 0;
3554 byte old_h_ver_extra = 0;
3555 if (mode & SLF_SECOND)
3558 old_xor_byte = xor_byte;
3559 old_v_check = v_check;
3560 old_x_check = x_check;
3561 old_h_ver_major = current_world_ptr->h_ver_major;
3562 old_h_ver_minor = current_world_ptr->h_ver_minor;
3563 old_h_ver_patch = current_world_ptr->h_ver_patch;
3564 old_h_ver_extra = current_world_ptr->h_ver_extra;
3567 char floor_savefile[1024];
3568 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3571 fff = my_fopen(floor_savefile, "rb");
3574 bool is_save_successful = TRUE;
3575 if (!fff) is_save_successful = FALSE;
3577 if (is_save_successful)
3579 is_save_successful = load_floor_aux(player_ptr, sf_ptr);
3580 if (ferror(fff)) is_save_successful = FALSE;
3584 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3589 if (mode & SLF_SECOND)
3592 xor_byte = old_xor_byte;
3593 v_check = old_v_check;
3594 x_check = old_x_check;
3595 current_world_ptr->h_ver_major = old_h_ver_major;
3596 current_world_ptr->h_ver_minor = old_h_ver_minor;
3597 current_world_ptr->h_ver_patch = old_h_ver_patch;
3598 current_world_ptr->h_ver_extra = old_h_ver_extra;
3601 byte old_kanji_code = kanji_code;
3602 kanji_code = old_kanji_code;
3603 return is_save_successful;