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/arena.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 "store/store-util.h"
59 #include "dungeon/quest.h"
60 #include "store/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"
76 #include "io/files-util.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"
90 #include "market/bounty.h"
91 #include "object/tr-types.h"
94 * Maximum number of tries for selection of a proper quest monster
98 #define OLD_MAX_MANE 22
100 /* Old hidden trap flag */
101 #define CAVE_TRAP 0x8000
103 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
104 #define OLD_FEAT_INVIS 0x02
105 #define OLD_FEAT_GLYPH 0x03
106 #define OLD_FEAT_QUEST_ENTER 0x08
107 #define OLD_FEAT_QUEST_EXIT 0x09
108 #define OLD_FEAT_MINOR_GLYPH 0x40
109 #define OLD_FEAT_BLDG_1 0x81
110 #define OLD_FEAT_MIRROR 0xc3
113 #define OLD_QUEST_WATER_CAVE 18
115 /* Quest constants */
116 #define QUEST_OLD_CASTLE 27
117 #define QUEST_ROYAL_CRYPT 28
120 * Local "savefile" pointer
125 * Hack -- old "encryption" byte
127 static byte xor_byte;
130 * Hack -- simple "checksum" on the actual values
132 static u32b v_check = 0L;
135 * Hack -- simple "checksum" on the encoded bytes
137 static u32b x_check = 0L;
140 * Hack -- Japanese Kanji code
146 static byte kanji_code = 0;
149 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
150 * @param major メジャーバージョン値
151 * @param minor マイナーバージョン値
152 * @param patch パッチバージョン値
153 * @param extra エクストラパージョン値
154 * @return 現在のバージョンより値が古いならtrue
156 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
158 if (current_world_ptr->h_ver_major < major) return TRUE;
159 if (current_world_ptr->h_ver_major > major) return FALSE;
161 if (current_world_ptr->h_ver_minor < minor) return TRUE;
162 if (current_world_ptr->h_ver_minor > minor) return FALSE;
164 if (current_world_ptr->h_ver_patch < patch) return TRUE;
165 if (current_world_ptr->h_ver_patch > patch) return FALSE;
167 if (current_world_ptr->h_ver_extra < extra) return TRUE;
168 if (current_world_ptr->h_ver_extra > extra) return FALSE;
175 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
176 * @param x メジャーバージョン値
177 * @param y マイナーバージョン値
179 * @return 現在のバージョンより値が古いならtrue
181 static bool z_older_than(byte x, byte y, byte z)
183 if (current_world_ptr->z_major < x) return TRUE;
184 if (current_world_ptr->z_major > x) return FALSE;
186 if (current_world_ptr->z_minor < y) return TRUE;
187 if (current_world_ptr->z_minor > y) return FALSE;
189 if (current_world_ptr->z_patch < z) return TRUE;
190 if (current_world_ptr->z_patch > z) return FALSE;
197 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
201 * Avoid the top two lines, to avoid interference with "msg_print()".
203 static void note(concptr msg)
205 static TERM_LEN y = 2;
207 if (++y >= 24) y = 2;
214 * @brief ロードファイルポインタから1バイトを読み込む
217 * The following functions are used to load the basic building blocks
218 * of savefiles. They also maintain the "checksum" info for 2.7.0+
220 static byte sf_get(void)
222 byte c = getc(fff) & 0xFF;
223 byte v = c ^ xor_byte;
233 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
237 static void rd_byte(byte *ip)
244 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
248 static void rd_u16b(u16b *ip)
251 (*ip) |= ((u16b)(sf_get()) << 8);
256 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
260 static void rd_s16b(s16b *ip)
267 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
271 static void rd_u32b(u32b *ip)
274 (*ip) |= ((u32b)(sf_get()) << 8);
275 (*ip) |= ((u32b)(sf_get()) << 16);
276 (*ip) |= ((u32b)(sf_get()) << 24);
281 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
285 static void rd_s32b(s32b *ip)
292 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
293 * @param str 読み込みポインタ
294 * @param max 最大読み取りバイト数
297 static void rd_string(char *str, int max)
299 for (int i = 0; TRUE; i++)
303 if (i < max) str[i] = tmp8u;
326 byte code = codeconv(str);
328 /* 漢字コードが判明したら、それを記録 */
329 if (code) kanji_code = code;
341 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
345 static void strip_bytes(int n)
348 while (n--) rd_byte(&tmp8u);
353 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
354 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
357 * This function attempts to "repair" old savefiles, and to extract
358 * the most up to date values for various object fields.
360 * Note that Angband 2.7.9 introduced a new method for object "flags"
361 * in which the "flags" on an object are actually extracted when they
362 * are needed from the object kind, artifact index, ego-item index,
363 * and two special "xtra" fields which are used to encode any "extra"
364 * power of certain ego-items. This had the side effect that items
365 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
366 * may have had, and also, all "uncursed" items will become "cursed"
367 * again, including Calris, even if it is being worn at the time. As
368 * a complete hack, items which are inscribed with "uncursed" will be
369 * "uncursed" when imported from pre-2.7.9 savefiles.
371 static void rd_item_old(object_type *o_ptr)
373 rd_s16b(&o_ptr->k_idx);
377 o_ptr->iy = (POSITION)tmp8u;
379 o_ptr->ix = (POSITION)tmp8u;
387 if (z_older_than(10, 4, 4))
389 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
390 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
391 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
394 rd_s16b(&o_ptr->pval);
395 rd_byte(&o_ptr->discount);
397 o_ptr->number = (ITEM_NUMBER)tmp8u;
401 o_ptr->weight = tmp16s;
404 o_ptr->name1 = tmp8u;
407 o_ptr->name2 = tmp8u;
409 rd_s16b(&o_ptr->timeout);
410 rd_s16b(&o_ptr->to_h);
412 o_ptr->to_d = tmp16s;
414 rd_s16b(&o_ptr->to_a);
422 rd_byte(&o_ptr->ident);
423 rd_byte(&o_ptr->marked);
424 rd_u32b(&o_ptr->art_flags[0]);
425 rd_u32b(&o_ptr->art_flags[1]);
426 rd_u32b(&o_ptr->art_flags[2]);
427 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
428 else rd_u32b(&o_ptr->art_flags[3]);
430 if (h_older_than(1, 3, 0, 0))
432 if (o_ptr->name2 == EGO_TELEPATHY)
433 add_flag(o_ptr->art_flags, TR_TELEPATHY);
436 if (z_older_than(11, 0, 11))
438 o_ptr->curse_flags = 0L;
439 if (o_ptr->ident & 0x40)
441 o_ptr->curse_flags |= TRC_CURSED;
442 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
443 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
444 if (object_is_fixed_artifact(o_ptr))
446 artifact_type *a_ptr = &a_info[o_ptr->name1];
447 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
448 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
450 else if (object_is_ego(o_ptr))
452 ego_item_type *e_ptr = &e_info[o_ptr->name2];
453 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
454 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
457 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
461 rd_u32b(&o_ptr->curse_flags);
464 rd_s16b(&o_ptr->held_m_idx);
465 rd_byte(&o_ptr->xtra1);
466 rd_byte(&o_ptr->xtra2);
468 if (z_older_than(11, 0, 10))
470 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
472 switch (o_ptr->xtra2 % 6)
474 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
475 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
476 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
477 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
478 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
479 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
483 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
485 switch (o_ptr->xtra2 % 11)
487 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
488 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
489 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
490 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
491 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
492 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
493 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
494 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
495 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
496 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
497 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
501 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
503 switch (o_ptr->xtra2 % 8)
505 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
506 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
507 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
508 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
509 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
510 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
511 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
512 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
519 if (z_older_than(10, 2, 3))
524 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
526 o_ptr->xtra3 = o_ptr->xtra1;
529 if (o_ptr->tval == TV_CAPTURE)
531 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
532 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
534 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
535 if (ironman_nightmare)
537 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5 * 2L);
539 o_ptr->xtra4 = o_ptr->xtra5;
544 rd_byte(&o_ptr->xtra3);
545 if (h_older_than(1, 3, 0, 1))
547 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1 + 96)
548 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
551 rd_s16b(&o_ptr->xtra4);
552 rd_s16b(&o_ptr->xtra5);
555 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)))
557 o_ptr->xtra4 = o_ptr->pval;
561 rd_byte(&o_ptr->feeling);
564 rd_string(buf, sizeof(buf));
565 if (buf[0]) o_ptr->inscription = quark_add(buf);
567 rd_string(buf, sizeof(buf));
569 /* todo 元々このif文には末尾に";"が付いていた、バグかもしれない */
570 if (buf[0]) o_ptr->art_name = quark_add(buf);
578 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
580 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
582 if (z_older_than(10, 4, 9))
584 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
586 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
587 add_flag(o_ptr->art_flags, TR_DEC_MANA);
591 if (object_is_fixed_artifact(o_ptr))
593 artifact_type *a_ptr;
594 a_ptr = &a_info[o_ptr->name1];
595 if (!a_ptr->name) o_ptr->name1 = 0;
598 if (object_is_ego(o_ptr))
600 ego_item_type *e_ptr;
601 e_ptr = &e_info[o_ptr->name2];
602 if (!e_ptr->name) o_ptr->name2 = 0;
608 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
609 * @param o_ptr アイテムオブジェクト保存先ポインタ
612 static void rd_item(object_type *o_ptr)
614 if (h_older_than(1, 5, 0, 0))
622 rd_s16b(&o_ptr->k_idx);
626 o_ptr->iy = (POSITION)tmp8u;
628 o_ptr->ix = (POSITION)tmp8u;
631 k_ptr = &k_info[o_ptr->k_idx];
632 o_ptr->tval = k_ptr->tval;
633 o_ptr->sval = k_ptr->sval;
635 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
636 else o_ptr->pval = 0;
638 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
639 else o_ptr->discount = 0;
640 if (flags & SAVE_ITEM_NUMBER) {
642 o_ptr->number = tmp8u;
644 else o_ptr->number = 1;
648 o_ptr->weight = tmp16s;
650 if (flags & SAVE_ITEM_NAME1)
653 o_ptr->name1 = tmp8u;
655 else o_ptr->name1 = 0;
657 if (flags & SAVE_ITEM_NAME2)
660 o_ptr->name2 = tmp8u;
662 else o_ptr->name2 = 0;
664 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
665 else o_ptr->timeout = 0;
667 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
668 else o_ptr->to_h = 0;
670 if (flags & SAVE_ITEM_TO_D)
673 o_ptr->to_d = tmp16s;
675 else o_ptr->to_d = 0;
677 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
678 else o_ptr->to_a = 0;
680 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
683 if (flags & SAVE_ITEM_DD)
690 if (flags & SAVE_ITEM_DS)
697 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
698 else o_ptr->ident = 0;
700 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
701 else o_ptr->marked = 0;
704 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
705 else o_ptr->art_flags[0] = 0;
707 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
708 else o_ptr->art_flags[1] = 0;
710 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
711 else o_ptr->art_flags[2] = 0;
713 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
714 else o_ptr->art_flags[3] = 0;
716 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
717 else o_ptr->art_flags[4] = 0;
719 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
720 else o_ptr->curse_flags = 0;
722 /* Monster holding object */
723 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
724 else o_ptr->held_m_idx = 0;
727 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
728 else o_ptr->xtra1 = 0;
730 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
731 else o_ptr->xtra2 = 0;
733 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
734 else o_ptr->xtra3 = 0;
736 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
737 else o_ptr->xtra4 = 0;
739 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
740 else o_ptr->xtra5 = 0;
742 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
743 else o_ptr->feeling = 0;
745 if (flags & SAVE_ITEM_INSCRIPTION)
748 rd_string(buf, sizeof(buf));
749 o_ptr->inscription = quark_add(buf);
751 else o_ptr->inscription = 0;
753 if (flags & SAVE_ITEM_ART_NAME)
756 rd_string(buf, sizeof(buf));
757 o_ptr->art_name = quark_add(buf);
764 if (!h_older_than(2, 1, 2, 4)) return;
766 BIT_FLAGS flgs[TR_FLAG_SIZE];
767 object_flags(o_ptr, flgs);
769 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
771 add_flag(o_ptr->art_flags, TR_LITE_M1);
772 remove_flag(o_ptr->art_flags, TR_LITE_1);
773 remove_flag(o_ptr->art_flags, TR_LITE_2);
774 remove_flag(o_ptr->art_flags, TR_LITE_3);
778 if (o_ptr->name2 == EGO_LITE_DARKNESS)
780 if (o_ptr->tval != TV_LITE)
782 add_flag(o_ptr->art_flags, TR_LITE_M1);
786 if (o_ptr->sval == SV_LITE_TORCH)
788 add_flag(o_ptr->art_flags, TR_LITE_M1);
790 else if (o_ptr->sval == SV_LITE_LANTERN)
792 add_flag(o_ptr->art_flags, TR_LITE_M2);
794 else if (o_ptr->sval == SV_LITE_FEANOR)
796 add_flag(o_ptr->art_flags, TR_LITE_M3);
802 if (o_ptr->tval == TV_LITE)
804 if (object_is_fixed_artifact(o_ptr))
806 add_flag(o_ptr->art_flags, TR_LITE_3);
810 if (o_ptr->sval == SV_LITE_TORCH)
812 add_flag(o_ptr->art_flags, TR_LITE_1);
813 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
817 if (o_ptr->sval == SV_LITE_LANTERN)
819 add_flag(o_ptr->art_flags, TR_LITE_2);
820 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
824 if (o_ptr->sval == SV_LITE_FEANOR)
826 add_flag(o_ptr->art_flags, TR_LITE_2);
834 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
835 * @param player_ptr プレーヤーへの参照ポインタ
836 * @param m_ptr モンスター保存先ポインタ
839 static void rd_monster_old(player_type *player_ptr, monster_type *m_ptr)
841 rd_s16b(&m_ptr->r_idx);
843 if (z_older_than(11, 0, 12))
844 m_ptr->ap_r_idx = m_ptr->r_idx;
846 rd_s16b(&m_ptr->ap_r_idx);
848 if (z_older_than(11, 0, 14))
850 monster_race *r_ptr = &r_info[m_ptr->r_idx];
852 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
853 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
854 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
857 rd_byte(&m_ptr->sub_align);
861 m_ptr->fy = (POSITION)tmp8u;
863 m_ptr->fx = (POSITION)tmp8u;
864 m_ptr->current_floor_ptr = player_ptr->current_floor_ptr;
870 m_ptr->maxhp = tmp16s;
872 if (z_older_than(11, 0, 5))
874 m_ptr->max_maxhp = m_ptr->maxhp;
879 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
881 if (h_older_than(2, 1, 2, 1))
883 m_ptr->dealt_damage = 0;
887 rd_s32b(&m_ptr->dealt_damage);
890 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
892 m_ptr->mspeed = tmp8u;
894 if (z_older_than(10, 4, 2))
897 m_ptr->energy_need = (s16b)tmp8u;
899 else rd_s16b(&m_ptr->energy_need);
901 if (z_older_than(11, 0, 13))
902 m_ptr->energy_need = 100 - m_ptr->energy_need;
904 if (z_older_than(10, 0, 7))
906 m_ptr->mtimed[MTIMED_FAST] = 0;
907 m_ptr->mtimed[MTIMED_SLOW] = 0;
912 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
914 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
918 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
920 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
922 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
924 if (z_older_than(10, 0, 10))
928 else if (z_older_than(10, 0, 11))
936 m_ptr->target_y = (POSITION)tmp16s;
938 m_ptr->target_x = (POSITION)tmp16s;
942 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
944 if (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6))
945 rd_u32b(&m_ptr->smart);
950 if (z_older_than(10, 4, 5))
960 if (z_older_than(10, 2, 2))
962 if (m_ptr->r_idx < 0)
964 m_ptr->r_idx = (0 - m_ptr->r_idx);
965 m_ptr->mflag2 |= MFLAG2_KAGE;
970 rd_byte(&m_ptr->mflag2);
973 if (z_older_than(11, 0, 12))
975 if (m_ptr->mflag2 & MFLAG2_KAGE)
976 m_ptr->ap_r_idx = MON_KAGE;
979 if (z_older_than(10, 1, 3))
986 rd_string(buf, sizeof(buf));
987 if (buf[0]) m_ptr->nickname = quark_add(buf);
995 * @brief モンスターを読み込む(現版) / Read a monster (New method)
996 * @param player_ptr プレーヤーへの参照ポインタ
997 * @param m_ptr モンスター保存先ポインタ
1000 static void rd_monster(player_type *player_ptr, monster_type *m_ptr)
1002 if (h_older_than(1, 5, 0, 0))
1004 rd_monster_old(player_ptr, m_ptr);
1010 rd_s16b(&m_ptr->r_idx);
1013 m_ptr->fy = (POSITION)tmp8u;
1015 m_ptr->fx = (POSITION)tmp8u;
1019 m_ptr->hp = (HIT_POINT)tmp16s;
1021 m_ptr->maxhp = (HIT_POINT)tmp16s;
1023 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1025 if (h_older_than(2, 1, 2, 1))
1027 m_ptr->dealt_damage = 0;
1031 rd_s32b(&m_ptr->dealt_damage);
1034 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1035 else m_ptr->ap_r_idx = m_ptr->r_idx;
1037 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1038 else m_ptr->sub_align = 0;
1040 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1041 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1044 m_ptr->mspeed = tmp8u;
1046 rd_s16b(&m_ptr->energy_need);
1048 if (flags & SAVE_MON_FAST)
1051 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1053 else m_ptr->mtimed[MTIMED_FAST] = 0;
1055 if (flags & SAVE_MON_SLOW)
1058 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1060 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1062 if (flags & SAVE_MON_STUNNED)
1065 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1067 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1069 if (flags & SAVE_MON_CONFUSED)
1072 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1074 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1076 if (flags & SAVE_MON_MONFEAR)
1079 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1081 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1083 if (flags & SAVE_MON_TARGET_Y)
1086 m_ptr->target_y = (POSITION)tmp16s;
1088 else m_ptr->target_y = 0;
1090 if (flags & SAVE_MON_TARGET_X)
1093 m_ptr->target_x = (POSITION)tmp16s;
1095 else m_ptr->target_x = 0;
1097 if (flags & SAVE_MON_INVULNER)
1100 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1102 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1104 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1105 else m_ptr->smart = 0;
1107 if (flags & SAVE_MON_EXP)
1111 m_ptr->exp = (EXP)tmp32u;
1113 else m_ptr->exp = 0;
1115 m_ptr->mflag = 0; /* Not saved */
1117 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1118 else m_ptr->mflag2 = 0;
1120 if (flags & SAVE_MON_NICKNAME)
1123 rd_string(buf, sizeof(buf));
1124 m_ptr->nickname = quark_add(buf);
1126 else m_ptr->nickname = 0;
1128 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1129 else m_ptr->parent_m_idx = 0;
1134 * Old monster bit flags of racial resistances
1136 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1137 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1138 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1139 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1140 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1141 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1142 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1143 #define RF3_RES_WATE 0x00800000 /* Resist water */
1144 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1145 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1146 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1147 #define RF3_RES_ALL 0x08000000 /* Resist all */
1149 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1151 if ((R_PTR)->r_flags3 & (RF3)) \
1153 (R_PTR)->r_flags3 &= ~(RF3); \
1154 (R_PTR)->r_flagsr |= (RFR); \
1158 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1160 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1162 (R_PTR)->r_flagsr |= (RFR); \
1166 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1167 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1168 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1169 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1170 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1171 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1172 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1173 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1174 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1175 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1178 * @brief モンスターの思い出を読み込む / Read the monster lore
1179 * @param r_idx 読み込み先モンスターID
1182 static void rd_lore(MONRACE_IDX r_idx)
1184 monster_race *r_ptr = &r_info[r_idx];
1188 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1191 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1194 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1196 if (h_older_than(1, 7, 0, 5))
1198 r_ptr->r_akills = r_ptr->r_pkills;
1203 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1207 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1209 rd_byte(&r_ptr->r_wake);
1210 rd_byte(&r_ptr->r_ignore);
1211 rd_byte(&r_ptr->r_xtra1);
1212 rd_byte(&r_ptr->r_xtra2);
1216 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1218 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1221 rd_byte(&r_ptr->r_cast_spell);
1223 rd_byte(&r_ptr->r_blows[0]);
1224 rd_byte(&r_ptr->r_blows[1]);
1225 rd_byte(&r_ptr->r_blows[2]);
1226 rd_byte(&r_ptr->r_blows[3]);
1228 rd_u32b(&r_ptr->r_flags1);
1229 rd_u32b(&r_ptr->r_flags2);
1230 rd_u32b(&r_ptr->r_flags3);
1231 rd_u32b(&r_ptr->r_flags4);
1232 rd_u32b(&r_ptr->r_flags5);
1233 rd_u32b(&r_ptr->r_flags6);
1234 if (h_older_than(1, 5, 0, 3))
1236 r_ptr->r_flagsr = 0L;
1237 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1238 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1239 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1240 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1241 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1242 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1243 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1244 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1245 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1246 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1247 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1248 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1250 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1251 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1252 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1253 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1254 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1255 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1256 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1257 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1258 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1260 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1261 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1262 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1266 rd_u32b(&r_ptr->r_flagsr);
1270 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1272 rd_s16b(&r_ptr->floor_id);
1275 r_ptr->r_flags1 &= r_ptr->flags1;
1276 r_ptr->r_flags2 &= r_ptr->flags2;
1277 r_ptr->r_flags3 &= r_ptr->flags3;
1278 r_ptr->r_flags4 &= r_ptr->flags4;
1279 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1280 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1281 r_ptr->r_flagsr &= r_ptr->flagsr;
1286 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1287 * @param player_ptr プレーヤーへの参照ポインタ
1288 * @param store_ptr 店舗の参照ポインタ
1289 * @param o_ptr アイテムオブジェクト参照ポインタ
1292 * In all cases, return the slot (or -1) where the object was placed
1294 * Note that this is a hacked up version of "inven_carry()".
1296 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1297 * known, the player may have to pick stuff up and drop it again.
1299 static void home_carry(player_type *player_ptr, store_type *store_ptr, object_type *o_ptr)
1301 for (int i = 0; i < store_ptr->stock_num; i++)
1304 j_ptr = &store_ptr->stock[i];
1305 if (!object_similar(j_ptr, o_ptr)) continue;
1307 object_absorb(j_ptr, o_ptr);
1311 if (store_ptr->stock_num >= STORE_INVEN_MAX * 10) return;
1313 s32b value = object_value(o_ptr);
1315 for (slot = 0; slot < store_ptr->stock_num; slot++)
1317 if (object_sort_comp(o_ptr, value, &store_ptr->stock[slot])) break;
1320 for (int i = store_ptr->stock_num; i > slot; i--)
1322 store_ptr->stock[i] = store_ptr->stock[i - 1];
1325 store_ptr->stock_num++;
1326 store_ptr->stock[slot] = *o_ptr;
1327 chg_virtue(player_ptr, V_SACRIFICE, -1);
1332 * @brief 店舗情報を読み込む / Read a store
1333 * @param player_ptr プレーヤーへの参照ポインタ
1334 * @param town_number 街ID
1335 * @param store_number 店舗ID
1338 static errr rd_store(player_type *player_ptr, int town_number, int store_number)
1340 store_type *store_ptr;
1342 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1344 store_ptr = &town_info[1].store[store_number];
1345 if (store_ptr->stock_num) sort = TRUE;
1349 store_ptr = &town_info[town_number].store[store_number];
1355 rd_s32b(&store_ptr->store_open);
1356 rd_s16b(&store_ptr->insult_cur);
1358 if (z_older_than(11, 0, 4))
1368 rd_s16b(&store_ptr->good_buy);
1369 rd_s16b(&store_ptr->bad_buy);
1371 rd_s32b(&store_ptr->last_visit);
1372 store_ptr->owner = own;
1374 for (int j = 0; j < num; j++)
1383 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);
1384 if (!is_valid_item) continue;
1388 home_carry(player_ptr, store_ptr, q_ptr);
1392 int k = store_ptr->stock_num++;
1393 object_copy(&store_ptr->stock[k], q_ptr);
1402 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1405 static void rd_randomizer(void)
1409 rd_u16b(&Rand_place);
1410 for (int i = 0; i < RAND_DEG; i++)
1412 rd_u32b(&Rand_state[i]);
1418 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1421 * Note that the normal options are now stored as a set of 256 bit flags,
1422 * plus a set of 256 bit masks to indicate which bit flags were defined
1423 * at the time the savefile was created. This will allow new options
1424 * to be added, and old options to be removed, at any time, without
1425 * hurting old savefiles.
1427 * The window options are stored in the same way, but note that each
1428 * window gets 32 options, and their order is fixed by certain defines.
1430 static void rd_options(void)
1441 if (h_older_than(1, 7, 0, 0))
1454 if (c & 0x0002) current_world_ptr->wizard = TRUE;
1456 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1457 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1458 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1459 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1460 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1461 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1462 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1463 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1464 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1465 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1467 rd_byte((byte *)&autosave_l);
1468 rd_byte((byte *)&autosave_t);
1469 rd_s16b(&autosave_freq);
1472 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1475 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1477 for (int n = 0; n < 8; n++)
1479 for (int i = 0; i < 32; i++)
1481 if (!(mask[n] & (1L << i))) continue;
1482 if (!(option_mask[n] & (1L << i))) continue;
1484 if (flag[n] & (1L << i))
1486 option_flag[n] |= (1L << i);
1490 option_flag[n] &= ~(1L << i);
1495 if (z_older_than(10, 4, 5))
1497 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1498 else option_flag[5] |= (0x00000001 << 4);
1499 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1500 else option_flag[2] |= (0x00000001 << 5);
1501 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1502 else option_flag[4] |= (0x00000001 << 5);
1503 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1504 else option_flag[5] |= (0x00000001 << 0);
1505 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1506 else option_flag[5] |= (0x00000001 << 12);
1507 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1508 else option_flag[1] |= (0x00000001 << 0);
1509 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1510 else option_flag[1] |= (0x00000001 << 18);
1511 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1512 else option_flag[1] |= (0x00000001 << 19);
1513 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1514 else option_flag[5] |= (0x00000001 << 3);
1517 extract_option_vars();
1518 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1520 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1522 for (int n = 0; n < 8; n++)
1524 for (int i = 0; i < 32; i++)
1526 if (!(mask[n] & (1L << i))) continue;
1527 if (!(window_mask[n] & (1L << i))) continue;
1529 if (flag[n] & (1L << i))
1531 window_flag[n] |= (1L << i);
1535 window_flag[n] &= ~(1L << i);
1543 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1546 * This is such a nasty hack it hurts.
1548 static void rd_ghost(void)
1551 rd_string(buf, sizeof(buf));
1557 * @brief クイックスタート情報を読み込む / Load quick start data
1560 static void load_quick_start(void)
1562 if (z_older_than(11, 0, 13))
1564 previous_char.quick_ok = FALSE;
1568 rd_byte(&previous_char.psex);
1571 previous_char.prace = (player_race_type)tmp8u;
1573 previous_char.pclass = (player_class_type)tmp8u;
1575 previous_char.pseikaku = (player_personality_type)tmp8u;
1577 previous_char.realm1 = (REALM_IDX)tmp8u;
1579 previous_char.realm2 = (REALM_IDX)tmp8u;
1581 rd_s16b(&previous_char.age);
1582 rd_s16b(&previous_char.ht);
1583 rd_s16b(&previous_char.wt);
1584 rd_s16b(&previous_char.sc);
1585 rd_s32b(&previous_char.au);
1587 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1588 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1590 for (int i = 0; i < PY_MAX_LEVEL; i++)
1594 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1597 rd_s16b(&previous_char.chaos_patron);
1599 for (int i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1601 for (int i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1605 previous_char.quick_ok = (bool)tmp8u;
1610 * @brief その他の情報を読み込む / Read the "extra" information
1613 static void rd_extra(player_type *creature_ptr)
1615 rd_string(creature_ptr->name, sizeof(creature_ptr->name));
1616 rd_string(creature_ptr->died_from, sizeof(creature_ptr->died_from));
1617 if (!h_older_than(1, 7, 0, 1))
1620 rd_string(buf, sizeof buf);
1621 if (buf[0]) creature_ptr->last_message = string_make(buf);
1625 for (int i = 0; i < 4; i++)
1627 rd_string(creature_ptr->history[i], sizeof(creature_ptr->history[i]));
1632 creature_ptr->prace = (player_race_type)tmp8u;
1635 creature_ptr->pclass = (player_class_type)tmp8u;
1638 creature_ptr->pseikaku = (player_personality_type)tmp8u;
1640 rd_byte(&creature_ptr->psex);
1642 creature_ptr->realm1 = (REALM_IDX)tmp8u;
1645 creature_ptr->realm2 = (REALM_IDX)tmp8u;
1648 if (z_older_than(10, 4, 4))
1650 if (creature_ptr->realm1 == 9) creature_ptr->realm1 = REALM_MUSIC;
1651 if (creature_ptr->realm2 == 9) creature_ptr->realm2 = REALM_MUSIC;
1652 if (creature_ptr->realm1 == 10) creature_ptr->realm1 = REALM_HISSATSU;
1653 if (creature_ptr->realm2 == 10) creature_ptr->realm2 = REALM_HISSATSU;
1657 creature_ptr->hitdie = tmp8u;
1658 rd_u16b(&creature_ptr->expfact);
1660 rd_s16b(&creature_ptr->age);
1661 rd_s16b(&creature_ptr->ht);
1662 rd_s16b(&creature_ptr->wt);
1664 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max[i]);
1665 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max_max[i]);
1666 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_cur[i]);
1669 rd_s32b(&creature_ptr->au);
1671 rd_s32b(&creature_ptr->max_exp);
1672 if (h_older_than(1, 5, 4, 1)) creature_ptr->max_max_exp = creature_ptr->max_exp;
1673 else rd_s32b(&creature_ptr->max_max_exp);
1674 rd_s32b(&creature_ptr->exp);
1676 if (h_older_than(1, 7, 0, 3))
1680 creature_ptr->exp_frac = (u32b)tmp16u;
1684 rd_u32b(&creature_ptr->exp_frac);
1687 rd_s16b(&creature_ptr->lev);
1689 for (int i = 0; i < 64; i++) rd_s16b(&creature_ptr->spell_exp[i]);
1690 if ((creature_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1692 for (int i = 0; i < 64; i++) creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1695 if (z_older_than(10, 3, 6))
1696 for (int i = 0; i < 5; i++) for (int j = 0; j < 60; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1698 for (int i = 0; i < 5; i++) for (int j = 0; j < 64; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1699 for (int i = 0; i < GINOU_MAX; i++) rd_s16b(&creature_ptr->skill_exp[i]);
1700 if (z_older_than(10, 4, 1))
1702 if (creature_ptr->pclass != CLASS_BEASTMASTER) creature_ptr->skill_exp[GINOU_RIDING] /= 2;
1703 creature_ptr->skill_exp[GINOU_RIDING] = MIN(creature_ptr->skill_exp[GINOU_RIDING], s_info[creature_ptr->pclass].s_max[GINOU_RIDING]);
1706 if (z_older_than(10, 3, 14))
1708 for (int i = 0; i < 108; i++) creature_ptr->magic_num1[i] = 0;
1709 for (int i = 0; i < 108; i++) creature_ptr->magic_num2[i] = 0;
1713 for (int i = 0; i < 108; i++) rd_s32b(&creature_ptr->magic_num1[i]);
1714 for (int i = 0; i < 108; i++) rd_byte(&creature_ptr->magic_num2[i]);
1715 if (h_older_than(1, 3, 0, 1))
1717 if (creature_ptr->pclass == CLASS_SMITH)
1719 creature_ptr->magic_num1[TR_ES_ATTACK] = creature_ptr->magic_num1[96];
1720 creature_ptr->magic_num1[96] = 0;
1721 creature_ptr->magic_num1[TR_ES_AC] = creature_ptr->magic_num1[97];
1722 creature_ptr->magic_num1[97] = 0;
1727 if (music_singing_any(creature_ptr)) creature_ptr->action = ACTION_SING;
1729 if (z_older_than(11, 0, 7))
1731 creature_ptr->start_race = creature_ptr->prace;
1732 creature_ptr->old_race1 = 0L;
1733 creature_ptr->old_race2 = 0L;
1734 creature_ptr->old_realm = 0;
1739 creature_ptr->start_race = (player_race_type)tmp8u;
1742 creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1744 creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1745 rd_s16b(&creature_ptr->old_realm);
1748 if (z_older_than(10, 0, 1))
1750 for (int i = 0; i < MAX_MANE; i++)
1752 creature_ptr->mane_spell[i] = -1;
1753 creature_ptr->mane_dam[i] = 0;
1755 creature_ptr->mane_num = 0;
1757 else if (z_older_than(10, 2, 3))
1760 for (int i = 0; i < OLD_MAX_MANE; i++)
1766 for (int i = 0; i < MAX_MANE; i++)
1768 creature_ptr->mane_spell[i] = -1;
1769 creature_ptr->mane_dam[i] = 0;
1773 creature_ptr->mane_num = 0;
1777 for (int i = 0; i < MAX_MANE; i++)
1781 creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1783 creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1786 rd_s16b(&creature_ptr->mane_num);
1789 if (z_older_than(10, 0, 3))
1791 determine_bounty_uniques(creature_ptr);
1793 for (int i = 0; i < MAX_BOUNTY; i++)
1795 /* Is this bounty unique already dead? */
1796 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1801 for (int i = 0; i < MAX_BOUNTY; i++)
1803 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1807 if (z_older_than(10, 0, 3))
1809 update_gambling_monsters(creature_ptr);
1813 for (int i = 0; i < 4; i++)
1815 rd_s16b(&battle_mon[i]);
1816 if (z_older_than(10, 3, 4))
1820 mon_odds[i] = tmp16s;
1822 else rd_u32b(&mon_odds[i]);
1826 rd_s16b(&creature_ptr->town_num);
1827 rd_s16b(&creature_ptr->arena_number);
1828 if (h_older_than(1, 5, 0, 1))
1830 if (creature_ptr->arena_number >= 99) creature_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1835 creature_ptr->current_floor_ptr->inside_arena = (bool)tmp16s;
1836 rd_s16b(&creature_ptr->current_floor_ptr->inside_quest);
1837 if (z_older_than(10, 3, 5)) creature_ptr->phase_out = FALSE;
1841 creature_ptr->phase_out = (bool)tmp16s;
1844 rd_byte(&creature_ptr->exit_bldg);
1848 creature_ptr->oldpx = (POSITION)tmp16s;
1851 creature_ptr->oldpy = (POSITION)tmp16s;
1852 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; }
1855 for (int i = 0; i < tmp16s; i++)
1861 if (h_older_than(1, 7, 0, 3))
1864 creature_ptr->mhp = tmp16s;
1867 creature_ptr->chp = tmp16s;
1871 creature_ptr->chp_frac = (u32b)tmp16u;
1875 rd_s32b(&creature_ptr->mhp);
1876 rd_s32b(&creature_ptr->chp);
1877 rd_u32b(&creature_ptr->chp_frac);
1880 if (h_older_than(1, 7, 0, 3))
1883 creature_ptr->msp = tmp16s;
1886 creature_ptr->csp = tmp16s;
1890 creature_ptr->csp_frac = (u32b)tmp16u;
1894 rd_s32b(&creature_ptr->msp);
1895 rd_s32b(&creature_ptr->csp);
1896 rd_u32b(&creature_ptr->csp_frac);
1899 rd_s16b(&creature_ptr->max_plv);
1900 if (z_older_than(10, 3, 8))
1903 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1907 byte max = (byte)current_world_ptr->max_d_idx;
1911 for (int i = 0; i < max; i++)
1914 max_dlv[i] = tmp16s;
1915 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1919 if (creature_ptr->max_plv < creature_ptr->lev) creature_ptr->max_plv = creature_ptr->lev;
1922 rd_s16b(&creature_ptr->sc);
1923 rd_s16b(&creature_ptr->concent);
1925 strip_bytes(2); /* Old "rest" */
1926 rd_s16b(&creature_ptr->blind);
1927 rd_s16b(&creature_ptr->paralyzed);
1928 rd_s16b(&creature_ptr->confused);
1929 rd_s16b(&creature_ptr->food);
1930 strip_bytes(4); /* Old "food_digested" / "protection" */
1932 rd_s16b(&creature_ptr->energy_need);
1933 if (z_older_than(11, 0, 13))
1934 creature_ptr->energy_need = 100 - creature_ptr->energy_need;
1935 if (h_older_than(2, 1, 2, 0))
1936 creature_ptr->enchant_energy_need = 0;
1938 rd_s16b(&creature_ptr->enchant_energy_need);
1940 rd_s16b(&creature_ptr->fast);
1941 rd_s16b(&creature_ptr->slow);
1942 rd_s16b(&creature_ptr->afraid);
1943 rd_s16b(&creature_ptr->cut);
1944 rd_s16b(&creature_ptr->stun);
1945 rd_s16b(&creature_ptr->poisoned);
1946 rd_s16b(&creature_ptr->image);
1947 rd_s16b(&creature_ptr->protevil);
1948 rd_s16b(&creature_ptr->invuln);
1949 if (z_older_than(10, 0, 0))
1950 creature_ptr->ult_res = 0;
1952 rd_s16b(&creature_ptr->ult_res);
1953 rd_s16b(&creature_ptr->hero);
1954 rd_s16b(&creature_ptr->shero);
1955 rd_s16b(&creature_ptr->shield);
1956 rd_s16b(&creature_ptr->blessed);
1957 rd_s16b(&creature_ptr->tim_invis);
1958 rd_s16b(&creature_ptr->word_recall);
1959 if (z_older_than(10, 3, 8))
1960 creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
1964 creature_ptr->recall_dungeon = (byte)tmp16s;
1967 if (h_older_than(1, 5, 0, 0))
1968 creature_ptr->alter_reality = 0;
1970 rd_s16b(&creature_ptr->alter_reality);
1972 rd_s16b(&creature_ptr->see_infra);
1973 rd_s16b(&creature_ptr->tim_infra);
1974 rd_s16b(&creature_ptr->oppose_fire);
1975 rd_s16b(&creature_ptr->oppose_cold);
1976 rd_s16b(&creature_ptr->oppose_acid);
1977 rd_s16b(&creature_ptr->oppose_elec);
1978 rd_s16b(&creature_ptr->oppose_pois);
1979 if (z_older_than(10, 0, 2)) creature_ptr->tsuyoshi = 0;
1980 else rd_s16b(&creature_ptr->tsuyoshi);
1982 /* Old savefiles do not have the following fields... */
1983 if ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->z_patch == 6))
1985 creature_ptr->tim_esp = 0;
1986 creature_ptr->wraith_form = 0;
1987 creature_ptr->resist_magic = 0;
1988 creature_ptr->tim_regen = 0;
1989 creature_ptr->kabenuke = 0;
1990 creature_ptr->tim_stealth = 0;
1991 creature_ptr->tim_levitation = 0;
1992 creature_ptr->tim_sh_touki = 0;
1993 creature_ptr->lightspeed = 0;
1994 creature_ptr->tsubureru = 0;
1995 creature_ptr->tim_res_nether = 0;
1996 creature_ptr->tim_res_time = 0;
1997 creature_ptr->mimic_form = 0;
1998 creature_ptr->tim_mimic = 0;
1999 creature_ptr->tim_sh_fire = 0;
2000 creature_ptr->tim_reflect = 0;
2001 creature_ptr->multishadow = 0;
2002 creature_ptr->dustrobe = 0;
2003 creature_ptr->chaos_patron = ((creature_ptr->age + creature_ptr->sc) % MAX_PATRON);
2004 creature_ptr->muta1 = 0;
2005 creature_ptr->muta2 = 0;
2006 creature_ptr->muta3 = 0;
2007 get_virtues(creature_ptr);
2011 rd_s16b(&creature_ptr->tim_esp);
2012 rd_s16b(&creature_ptr->wraith_form);
2013 rd_s16b(&creature_ptr->resist_magic);
2014 rd_s16b(&creature_ptr->tim_regen);
2015 rd_s16b(&creature_ptr->kabenuke);
2016 rd_s16b(&creature_ptr->tim_stealth);
2017 rd_s16b(&creature_ptr->tim_levitation);
2018 rd_s16b(&creature_ptr->tim_sh_touki);
2019 rd_s16b(&creature_ptr->lightspeed);
2020 rd_s16b(&creature_ptr->tsubureru);
2021 if (z_older_than(10, 4, 7))
2022 creature_ptr->magicdef = 0;
2024 rd_s16b(&creature_ptr->magicdef);
2025 rd_s16b(&creature_ptr->tim_res_nether);
2026 if (z_older_than(10, 4, 11))
2028 creature_ptr->tim_res_time = 0;
2029 creature_ptr->mimic_form = 0;
2030 creature_ptr->tim_mimic = 0;
2031 creature_ptr->tim_sh_fire = 0;
2035 rd_s16b(&creature_ptr->tim_res_time);
2037 creature_ptr->mimic_form = (IDX)tmp8u;
2038 rd_s16b(&creature_ptr->tim_mimic);
2039 rd_s16b(&creature_ptr->tim_sh_fire);
2042 if (z_older_than(11, 0, 99))
2044 creature_ptr->tim_sh_holy = 0;
2045 creature_ptr->tim_eyeeye = 0;
2049 rd_s16b(&creature_ptr->tim_sh_holy);
2050 rd_s16b(&creature_ptr->tim_eyeeye);
2053 if (z_older_than(11, 0, 3)) {
2054 creature_ptr->tim_reflect = 0;
2055 creature_ptr->multishadow = 0;
2056 creature_ptr->dustrobe = 0;
2060 rd_s16b(&creature_ptr->tim_reflect);
2061 rd_s16b(&creature_ptr->multishadow);
2062 rd_s16b(&creature_ptr->dustrobe);
2065 rd_s16b(&creature_ptr->chaos_patron);
2066 rd_u32b(&creature_ptr->muta1);
2067 rd_u32b(&creature_ptr->muta2);
2068 rd_u32b(&creature_ptr->muta3);
2070 for (int i = 0; i < 8; i++)
2071 rd_s16b(&creature_ptr->virtues[i]);
2072 for (int i = 0; i < 8; i++)
2073 rd_s16b(&creature_ptr->vir_types[i]);
2076 creature_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod(creature_ptr);
2077 if (z_older_than(10, 0, 9))
2080 if (tmp8u) creature_ptr->special_attack = ATTACK_CONFUSE;
2081 creature_ptr->ele_attack = 0;
2085 rd_s16b(&creature_ptr->ele_attack);
2086 rd_u32b(&creature_ptr->special_attack);
2089 if (creature_ptr->special_attack & KAMAE_MASK) creature_ptr->action = ACTION_KAMAE;
2090 else if (creature_ptr->special_attack & KATA_MASK) creature_ptr->action = ACTION_KATA;
2091 if (z_older_than(10, 0, 12))
2093 creature_ptr->ele_immune = 0;
2094 creature_ptr->special_defense = 0;
2098 rd_s16b(&creature_ptr->ele_immune);
2099 rd_u32b(&creature_ptr->special_defense);
2102 rd_byte(&creature_ptr->knowledge);
2104 creature_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2108 creature_ptr->action = (ACTION_IDX)tmp8u;
2109 if (!z_older_than(10, 4, 3))
2112 if (tmp8u) creature_ptr->action = ACTION_LEARN;
2115 rd_byte((byte *)&preserve_mode);
2116 rd_byte((byte *)&creature_ptr->wait_report_score);
2118 for (int i = 0; i < 48; i++) rd_byte(&tmp8u);
2121 rd_u32b(¤t_world_ptr->seed_flavor);
2122 rd_u32b(¤t_world_ptr->seed_town);
2124 rd_u16b(&creature_ptr->panic_save);
2125 rd_u16b(¤t_world_ptr->total_winner);
2126 rd_u16b(¤t_world_ptr->noscore);
2129 creature_ptr->is_dead = tmp8u;
2131 rd_byte(&creature_ptr->feeling);
2133 switch (creature_ptr->start_race)
2139 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2142 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2146 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2147 rd_s32b(&creature_ptr->current_floor_ptr->generated_turn);
2148 if (h_older_than(1, 7, 0, 4))
2150 creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
2154 rd_s32b(&creature_ptr->feeling_turn);
2157 rd_s32b(¤t_world_ptr->game_turn);
2158 if (z_older_than(10, 3, 12))
2160 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2162 else rd_s32b(¤t_world_ptr->dungeon_turn);
2164 if (z_older_than(11, 0, 13))
2166 creature_ptr->current_floor_ptr->generated_turn /= 2;
2167 creature_ptr->feeling_turn /= 2;
2168 current_world_ptr->game_turn /= 2;
2169 current_world_ptr->dungeon_turn /= 2;
2172 if (z_older_than(10, 3, 13))
2174 current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
2176 else rd_s32b(¤t_world_ptr->arena_start_turn);
2178 if (z_older_than(10, 0, 3))
2180 determine_daily_bounty(creature_ptr, TRUE);
2184 rd_s16b(&today_mon);
2185 rd_s16b(&creature_ptr->today_mon);
2188 if (z_older_than(10, 0, 7))
2190 creature_ptr->riding = 0;
2194 rd_s16b(&creature_ptr->riding);
2197 if (h_older_than(1, 5, 0, 0))
2199 creature_ptr->floor_id = 0;
2203 rd_s16b(&creature_ptr->floor_id);
2206 if (h_older_than(1, 5, 0, 2))
2213 for (int i = 0; i < tmp16s; i++)
2215 monster_type dummy_mon;
2216 rd_monster(creature_ptr, &dummy_mon);
2220 if (z_older_than(10, 1, 2))
2222 current_world_ptr->play_time = 0;
2226 rd_u32b(¤t_world_ptr->play_time);
2229 if (z_older_than(10, 3, 9))
2231 creature_ptr->visit = 1L;
2233 else if (z_older_than(10, 3, 10))
2237 creature_ptr->visit = 1L;
2243 creature_ptr->visit = (BIT_FLAGS)tmp32s;
2246 if (!z_older_than(11, 0, 5))
2248 rd_u32b(&creature_ptr->count);
2254 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2255 * @param player_ptr プレーヤーへの参照ポインタ
2258 * Note that the inventory changed in Angband 2.7.4. Two extra
2259 * pack slots were added and the equipment was rearranged. Note
2260 * that these two features combine when parsing old save-files, in
2261 * which items from the old "aux" slot are "carried", perhaps into
2262 * one of the two new "inventory" slots.
2264 * Note that the inventory is "re-sorted" later by "dungeon()".
2266 static errr rd_inventory(player_type *player_ptr)
2268 player_ptr->total_weight = 0;
2269 player_ptr->inven_cnt = 0;
2270 player_ptr->equip_cnt = 0;
2272 if (player_ptr->inventory_list != NULL) C_WIPE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2273 C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2281 if (n == 0xFFFF) break;
2288 if (!q_ptr->k_idx) return (53);
2290 if (n >= INVEN_RARM)
2292 q_ptr->marked |= OM_TOUCHED;
2293 object_copy(&player_ptr->inventory_list[n], q_ptr);
2294 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2295 player_ptr->equip_cnt++;
2299 if (player_ptr->inven_cnt == INVEN_PACK)
2301 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
2306 q_ptr->marked |= OM_TOUCHED;
2307 object_copy(&player_ptr->inventory_list[n], q_ptr);
2308 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2309 player_ptr->inven_cnt++;
2317 * @brief メッセージログを読み込む / Read the saved messages
2320 static void rd_messages(void)
2322 if (h_older_than(2, 2, 0, 75))
2327 message_max = (int)num;
2329 for (int i = 0; i < message_max; i++)
2332 rd_string(buf, sizeof(buf));
2340 message_max = (int)num;
2342 for (int i = 0; i < message_max; i++)
2345 rd_string(buf, sizeof(buf));
2352 * @brief メッセージログを読み込む / Read the dungeon (old method)
2353 * @param creature_ptr プレーヤーへの参照ポインタ
2356 * The monsters/objects must be loaded in the same order
2357 * that they were stored, since the actual indexes matter.
2359 static errr rd_dungeon_old(player_type *creature_ptr)
2363 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2364 floor_ptr->dun_level = (DEPTH)tmp16s;
2365 if (z_older_than(10, 3, 8)) creature_ptr->dungeon_idx = DUNGEON_ANGBAND;
2370 creature_ptr->dungeon_idx = (IDX)tmp8u;
2373 floor_ptr->base_level = floor_ptr->dun_level;
2375 floor_ptr->base_level = (DEPTH)tmp16s;
2378 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2380 creature_ptr->y = (POSITION)tmp16s;
2382 creature_ptr->x = (POSITION)tmp16s;
2383 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) { creature_ptr->y = 33; creature_ptr->x = 131; }
2385 floor_ptr->height = (POSITION)tmp16s;
2387 floor_ptr->width = (POSITION)tmp16s;
2388 rd_s16b(&tmp16s); /* max_panel_rows */
2389 rd_s16b(&tmp16s); /* max_panel_cols */
2391 int ymax = floor_ptr->height;
2392 int xmax = floor_ptr->width;
2394 for (int x = 0, y = 0; y < ymax; )
2399 if (z_older_than(10, 3, 6))
2408 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2411 for (int i = count; i > 0; i--)
2414 g_ptr = &floor_ptr->grid_array[y][x];
2419 if (++y >= ymax) break;
2424 for (int x = 0, y = 0; y < ymax; )
2430 for (int i = count; i > 0; i--)
2433 g_ptr = &floor_ptr->grid_array[y][x];
2434 g_ptr->feat = (s16b)tmp8u;
2438 if (++y >= ymax) break;
2443 for (int x = 0, y = 0; y < ymax; )
2449 for (int i = count; i > 0; i--)
2452 g_ptr = &floor_ptr->grid_array[y][x];
2453 g_ptr->mimic = (s16b)tmp8u;
2457 if (++y >= ymax) break;
2462 for (int x = 0, y = 0; y < ymax; )
2467 for (int i = count; i > 0; i--)
2470 g_ptr = &floor_ptr->grid_array[y][x];
2471 g_ptr->special = tmp16s;
2475 if (++y >= ymax) break;
2480 if (z_older_than(11, 0, 99))
2482 for (int y = 0; y < ymax; y++)
2484 for (int x = 0; x < xmax; x++)
2486 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2491 if (h_older_than(1, 1, 1, 0))
2493 for (int y = 0; y < ymax; y++)
2495 for (int x = 0; x < xmax; x++)
2498 g_ptr = &floor_ptr->grid_array[y][x];
2501 if (g_ptr->feat == OLD_FEAT_INVIS)
2503 g_ptr->feat = feat_floor;
2504 g_ptr->info |= CAVE_TRAP;
2507 /* Older than 1.1.1 */
2508 if (g_ptr->feat == OLD_FEAT_MIRROR)
2510 g_ptr->feat = feat_floor;
2511 g_ptr->info |= CAVE_OBJECT;
2517 if (h_older_than(1, 3, 1, 0))
2519 for (int y = 0; y < ymax; y++)
2521 for (int x = 0; x < xmax; x++)
2524 g_ptr = &floor_ptr->grid_array[y][x];
2526 /* Old CAVE_IN_MIRROR flag */
2527 if (g_ptr->info & CAVE_OBJECT)
2529 g_ptr->mimic = feat_mirror;
2531 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2532 (g_ptr->feat == OLD_FEAT_GLYPH))
2534 g_ptr->info |= CAVE_OBJECT;
2535 g_ptr->mimic = g_ptr->feat;
2536 g_ptr->feat = feat_floor;
2538 else if (g_ptr->info & CAVE_TRAP)
2540 g_ptr->info &= ~CAVE_TRAP;
2541 g_ptr->mimic = g_ptr->feat;
2542 g_ptr->feat = choose_random_trap(creature_ptr);
2544 else if (g_ptr->feat == OLD_FEAT_INVIS)
2546 g_ptr->mimic = feat_floor;
2547 g_ptr->feat = feat_trap_open;
2553 /* Quest 18 was removed */
2554 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2556 for (int y = 0; y < ymax; y++)
2558 for (int x = 0; x < xmax; x++)
2561 g_ptr = &floor_ptr->grid_array[y][x];
2563 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2565 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2567 g_ptr->feat = feat_tree;
2570 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2572 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2575 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2576 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2578 g_ptr->feat = feat_up_stair;
2587 if (limit > current_world_ptr->max_o_idx)
2589 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2593 for (int i = 1; i < limit; i++)
2595 OBJECT_IDX o_idx = o_pop(floor_ptr);
2598 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2603 o_ptr = &floor_ptr->o_list[o_idx];
2605 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2607 monster_type *m_ptr;
2608 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2609 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2610 m_ptr->hold_o_idx = o_idx;
2615 g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2616 o_ptr->next_o_idx = g_ptr->o_idx;
2617 g_ptr->o_idx = o_idx;
2621 if (limit > current_world_ptr->max_m_idx)
2623 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2627 for (int i = 1; i < limit; i++)
2630 monster_type *m_ptr;
2631 m_idx = m_pop(creature_ptr);
2634 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2638 m_ptr = &floor_ptr->m_list[m_idx];
2639 rd_monster(creature_ptr, m_ptr);
2641 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2642 g_ptr->m_idx = m_idx;
2643 real_r_ptr(m_ptr)->cur_num++;
2646 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena)
2647 current_world_ptr->character_dungeon = FALSE;
2649 current_world_ptr->character_dungeon = TRUE;
2656 * @brief 保存されたフロアを読み込む / Read the saved floor
2657 * @param player_ptr プレーヤーへの参照ポインタ
2658 * @param sf_ptr 最後に保存されたフロアへの参照ポインタ
2659 * @return info読み込みエラーコード
2661 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2664 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2665 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2667 * The monsters/objects must be loaded in the same order
2668 * that they were stored, since the actual indexes matter.
2670 static errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
2672 grid_template_type *templates;
2673 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2674 clear_cave(player_ptr);
2675 player_ptr->x = player_ptr->y = 0;
2681 floor_ptr->dun_level = (DEPTH)tmp16s;
2682 floor_ptr->base_level = floor_ptr->dun_level;
2688 if (tmp16s != sf_ptr->floor_id) return 171;
2692 if (tmp8u != sf_ptr->savefile_id) return 171;
2695 if (tmp16s != sf_ptr->dun_level) return 171;
2696 floor_ptr->dun_level = sf_ptr->dun_level;
2700 if (tmp32s != sf_ptr->last_visit) return 171;
2704 if (tmp32u != sf_ptr->visit_mark) return 171;
2707 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2710 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2715 floor_ptr->base_level = (DEPTH)tmp16s;
2717 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2721 player_ptr->y = (POSITION)tmp16u;
2724 player_ptr->x = (POSITION)tmp16u;
2727 floor_ptr->height = (POSITION)tmp16s;
2729 floor_ptr->width = (POSITION)tmp16s;
2731 rd_byte(&player_ptr->feeling);
2735 C_MAKE(templates, limit, grid_template_type);
2737 for (int i = 0; i < limit; i++)
2739 grid_template_type *ct_ptr = &templates[i];
2741 ct_ptr->info = (BIT_FLAGS)tmp16u;
2742 if (h_older_than(1, 7, 0, 2))
2746 ct_ptr->feat = (s16b)tmp8u;
2748 ct_ptr->mimic = (s16b)tmp8u;
2752 rd_s16b(&ct_ptr->feat);
2753 rd_s16b(&ct_ptr->mimic);
2756 rd_s16b(&ct_ptr->special);
2759 POSITION ymax = floor_ptr->height;
2760 POSITION xmax = floor_ptr->width;
2761 for (POSITION x = 0, y = 0; y < ymax; )
2772 } while (tmp8u == MAX_UCHAR);
2774 for (int i = count; i > 0; i--)
2776 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2777 g_ptr->info = templates[id].info;
2778 g_ptr->feat = templates[id].feat;
2779 g_ptr->mimic = templates[id].mimic;
2780 g_ptr->special = templates[id].special;
2785 if (++y >= ymax) break;
2790 /* Quest 18 was removed */
2791 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2793 for (POSITION y = 0; y < ymax; y++)
2795 for (POSITION x = 0; x < xmax; x++)
2797 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2799 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2801 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2803 g_ptr->feat = feat_tree;
2806 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2808 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2811 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2812 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2814 g_ptr->feat = feat_up_stair;
2821 C_KILL(templates, limit, grid_template_type);
2823 if (limit > current_world_ptr->max_o_idx) return 151;
2824 for (int i = 1; i < limit; i++)
2828 o_idx = o_pop(floor_ptr);
2829 if (i != o_idx) return 152;
2831 o_ptr = &floor_ptr->o_list[o_idx];
2834 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2836 monster_type *m_ptr;
2837 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2838 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2839 m_ptr->hold_o_idx = o_idx;
2843 grid_type *g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2844 o_ptr->next_o_idx = g_ptr->o_idx;
2845 g_ptr->o_idx = o_idx;
2850 if (limit > current_world_ptr->max_m_idx) return 161;
2852 for (int i = 1; i < limit; i++)
2856 monster_type *m_ptr;
2857 m_idx = m_pop(player_ptr);
2858 if (i != m_idx) return 162;
2860 m_ptr = &floor_ptr->m_list[m_idx];
2861 rd_monster(player_ptr, m_ptr);
2862 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2863 g_ptr->m_idx = m_idx;
2864 real_r_ptr(m_ptr)->cur_num++;
2872 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
2873 * @param player_ptr プレーヤーへの参照ポインタ
2876 * The monsters/objects must be loaded in the same order
2877 * that they were stored, since the actual indexes matter.
2879 static errr rd_dungeon(player_type *player_ptr)
2881 init_saved_floors(player_ptr, FALSE);
2883 if (h_older_than(1, 5, 0, 0))
2885 err = rd_dungeon_old(player_ptr);
2886 if (player_ptr->dungeon_idx)
2888 player_ptr->floor_id = get_new_floor_id(player_ptr);
2889 get_sf_ptr(player_ptr->floor_id)->dun_level = player_ptr->current_floor_ptr->dun_level;
2895 rd_s16b(&max_floor_id);
2898 player_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
2903 err = rd_saved_floor(player_ptr, NULL);
2907 for (int i = 0; i < num; i++)
2909 saved_floor_type *sf_ptr = &saved_floors[i];
2911 rd_s16b(&sf_ptr->floor_id);
2913 sf_ptr->savefile_id = (s16b)tmp8u;
2917 sf_ptr->dun_level = (DEPTH)tmp16s;
2919 rd_s32b(&sf_ptr->last_visit);
2920 rd_u32b(&sf_ptr->visit_mark);
2921 rd_s16b(&sf_ptr->upper_floor_id);
2922 rd_s16b(&sf_ptr->lower_floor_id);
2925 for (int i = 0; i < num; i++)
2927 saved_floor_type *sf_ptr = &saved_floors[i];
2928 if (!sf_ptr->floor_id) continue;
2930 if (tmp8u) continue;
2932 err = rd_saved_floor(player_ptr, sf_ptr);
2935 if (!save_floor(player_ptr, sf_ptr, SLF_SECOND)) err = 182;
2942 if (!load_floor(player_ptr, get_sf_ptr(player_ptr->floor_id), SLF_SECOND)) err = 183;
2949 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
2953 note(_("アイテム配置エラー", "Object allocation error"));
2957 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
2961 note(_("モンスター配置エラー", "Monster allocation error"));
2965 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
2969 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporary files!"));
2973 note(_("Error 183", "Error 183"));
2977 current_world_ptr->character_dungeon = TRUE;
2983 * @brief ロード処理全体のサブ関数 / Actually read the savefile
2986 static errr rd_savefile_new_aux(player_type *creature_ptr)
2988 u32b n_x_check, n_v_check;
2989 u32b o_x_check, o_v_check;
2992 xor_byte = current_world_ptr->sf_extra;
2996 /* Old savefile will be version 0.0.0.3 */
2997 rd_byte(¤t_world_ptr->h_ver_extra);
2998 rd_byte(¤t_world_ptr->h_ver_patch);
2999 rd_byte(¤t_world_ptr->h_ver_minor);
3000 rd_byte(¤t_world_ptr->h_ver_major);
3003 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3004 (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));
3006 rd_u32b(¤t_world_ptr->sf_system);
3007 rd_u32b(¤t_world_ptr->sf_when);
3008 rd_u16b(¤t_world_ptr->sf_lives);
3009 rd_u16b(¤t_world_ptr->sf_saves);
3019 rd_byte(&kanji_code);
3022 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3025 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3028 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3030 for (int i = 0; i < max_r_idx; i++)
3032 monster_race *r_ptr = &r_info[i];
3033 r_ptr->max_num = 100;
3035 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3036 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3040 if (tmp16u > max_r_idx)
3042 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3046 for (int i = 0; i < tmp16u; i++)
3048 rd_lore((MONRACE_IDX)i);
3051 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3054 if (tmp16u > max_k_idx)
3056 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3060 for (int i = 0; i < tmp16u; i++)
3062 object_kind *k_ptr = &k_info[i];
3064 k_ptr->aware = (tmp8u & 0x01) ? TRUE : FALSE;
3065 k_ptr->tried = (tmp8u & 0x02) ? TRUE : FALSE;
3067 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3069 /* 2.1.3 or newer version */
3071 u16b max_towns_load;
3072 u16b max_quests_load;
3073 byte max_rquests_load;
3074 s16b old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
3076 rd_u16b(&max_towns_load);
3077 if (max_towns_load > max_towns)
3079 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3083 rd_u16b(&max_quests_load);
3084 if (z_older_than(11, 0, 7))
3086 max_rquests_load = 10;
3090 rd_byte(&max_rquests_load);
3093 if (max_quests_load > max_q_idx)
3095 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3099 for (int i = 0; i < max_quests_load; i++)
3108 quest_type* const q_ptr = &quest[i];
3110 rd_s16b(&q_ptr->status);
3113 q_ptr->level = tmp16s;
3115 if (z_older_than(11, 0, 6))
3122 q_ptr->complev = tmp8u;
3124 if (h_older_than(2, 1, 2, 2))
3126 q_ptr->comptime = 0;
3130 rd_u32b(&q_ptr->comptime);
3133 bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
3134 is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
3135 is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
3136 if (!is_quest_running) continue;
3139 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3141 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3142 rd_s16b(&q_ptr->type);
3144 rd_s16b(&q_ptr->r_idx);
3145 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3147 determine_random_questor(creature_ptr, &quest[i]);
3150 rd_s16b(&q_ptr->k_idx);
3152 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3155 q_ptr->flags = tmp8u;
3157 if (z_older_than(10, 3, 11))
3159 if (q_ptr->flags & QUEST_FLAG_PRESET)
3165 init_flags = INIT_ASSIGN;
3166 creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)i;
3168 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
3169 creature_ptr->current_floor_ptr->inside_quest = old_inside_quest;
3175 q_ptr->dungeon = tmp8u;
3178 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3179 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3180 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3183 /* Quest 18 was removed */
3184 if (h_older_than(1, 7, 0, 6))
3186 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3187 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3190 rd_s32b(&creature_ptr->wilderness_x);
3191 rd_s32b(&creature_ptr->wilderness_y);
3192 if (z_older_than(10, 3, 13))
3194 creature_ptr->wilderness_x = 5;
3195 creature_ptr->wilderness_y = 48;
3198 if (z_older_than(10, 3, 7)) creature_ptr->wild_mode = FALSE;
3199 else rd_byte((byte *)&creature_ptr->wild_mode);
3200 if (z_older_than(10, 3, 7)) creature_ptr->ambush_flag = FALSE;
3201 else rd_byte((byte *)&creature_ptr->ambush_flag);
3205 rd_s32b(&wild_x_size);
3206 rd_s32b(&wild_y_size);
3208 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3210 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3214 for (int i = 0; i < wild_x_size; i++)
3216 for (int j = 0; j < wild_y_size; j++)
3218 rd_u32b(&wilderness[j][i].seed);
3223 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3226 if (tmp16u > max_a_idx)
3228 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3232 for (int i = 0; i < tmp16u; i++)
3234 artifact_type *a_ptr = &a_info[i];
3237 a_ptr->cur_num = tmp8u;
3239 if (h_older_than(1, 5, 0, 0))
3241 a_ptr->floor_id = 0;
3249 rd_s16b(&a_ptr->floor_id);
3253 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3255 rd_extra(creature_ptr);
3256 if (creature_ptr->energy_need < -999) creature_ptr->timewalk = TRUE;
3258 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3261 if (tmp16u > PY_MAX_LEVEL)
3263 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3267 for (int i = 0; i < tmp16u; i++)
3271 creature_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3274 sp_ptr = &sex_info[creature_ptr->psex];
3275 rp_ptr = &race_info[creature_ptr->prace];
3276 cp_ptr = &class_info[creature_ptr->pclass];
3277 ap_ptr = &seikaku_info[creature_ptr->pseikaku];
3279 if (z_older_than(10, 2, 2) && (creature_ptr->pclass == CLASS_BEASTMASTER) && !creature_ptr->is_dead)
3281 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3282 roll_hitdice(creature_ptr, 0L);
3285 if (z_older_than(10, 3, 2) && (creature_ptr->pclass == CLASS_ARCHER) && !creature_ptr->is_dead)
3287 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3288 roll_hitdice(creature_ptr, 0L);
3291 if (z_older_than(10, 2, 6) && (creature_ptr->pclass == CLASS_SORCERER) && !creature_ptr->is_dead)
3293 creature_ptr->hitdie = rp_ptr->r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3294 roll_hitdice(creature_ptr, 0L);
3297 if (z_older_than(10, 4, 7) && (creature_ptr->pclass == CLASS_BLUE_MAGE) && !creature_ptr->is_dead)
3299 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3300 roll_hitdice(creature_ptr, 0L);
3303 mp_ptr = &m_info[creature_ptr->pclass];
3305 rd_u32b(&creature_ptr->spell_learned1);
3306 rd_u32b(&creature_ptr->spell_learned2);
3307 rd_u32b(&creature_ptr->spell_worked1);
3308 rd_u32b(&creature_ptr->spell_worked2);
3309 rd_u32b(&creature_ptr->spell_forgotten1);
3310 rd_u32b(&creature_ptr->spell_forgotten2);
3312 if (z_older_than(10, 0, 5))
3314 creature_ptr->learned_spells = 0;
3315 for (int i = 0; i < 64; i++)
3318 (creature_ptr->spell_learned1 & (1L << i)) :
3319 (creature_ptr->spell_learned2 & (1L << (i - 32))))
3321 creature_ptr->learned_spells++;
3325 else rd_s16b(&creature_ptr->learned_spells);
3327 if (z_older_than(10, 0, 6))
3329 creature_ptr->add_spells = 0;
3331 else rd_s16b(&creature_ptr->add_spells);
3333 if (creature_ptr->pclass == CLASS_MINDCRAFTER) creature_ptr->add_spells = 0;
3335 for (int i = 0; i < 64; i++)
3338 creature_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3341 if (rd_inventory(creature_ptr))
3343 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3348 int town_count = tmp16u;
3351 for (int i = 1; i < town_count; i++)
3353 for (int j = 0; j < tmp16u; j++)
3355 if (rd_store(creature_ptr, i, j)) return (22);
3359 rd_s16b(&creature_ptr->pet_follow_distance);
3360 if (z_older_than(10, 4, 10))
3362 creature_ptr->pet_extra_flags = 0;
3364 if (tmp8u) creature_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3366 if (tmp8u) creature_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3368 if (z_older_than(10, 0, 4)) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3372 if (tmp8u) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3375 if (z_older_than(10, 0, 7)) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3379 if (tmp8u) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3382 if (z_older_than(10, 0, 8)) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3386 if (tmp8u) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3389 if (!z_older_than(10, 0, 8))
3392 if (tmp8u) creature_ptr->pet_extra_flags |= PF_BALL_SPELL;
3397 rd_s16b(&creature_ptr->pet_extra_flags);
3400 if (!z_older_than(11, 0, 9))
3402 char buf[SCREEN_BUF_MAX_SIZE];
3403 rd_string(buf, sizeof(buf));
3404 if (buf[0]) screen_dump = string_make(buf);
3407 if (creature_ptr->is_dead)
3409 for (int i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3411 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3415 if (!creature_ptr->is_dead)
3417 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3418 if (rd_dungeon(creature_ptr))
3420 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3429 strip_bytes(tmp32s);
3433 /* Quest 18 was removed */
3434 if (h_older_than(1, 7, 0, 6))
3436 if (creature_ptr->current_floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3438 creature_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3439 creature_ptr->current_floor_ptr->dun_level = 1;
3440 creature_ptr->current_floor_ptr->inside_quest = 0;
3444 n_v_check = v_check;
3445 rd_u32b(&o_v_check);
3446 if (o_v_check != n_v_check)
3448 note(_("チェックサムがおかしい", "Invalid checksum"));
3452 n_x_check = x_check;
3453 rd_u32b(&o_x_check);
3454 if (o_x_check != n_x_check)
3456 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3465 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3466 * @param player_ptr プレーヤーへの参照ポインタ
3469 errr rd_savefile_new(player_type *player_ptr)
3472 fff = my_fopen(savefile, "rb");
3474 if (!fff) return -1;
3475 errr err = rd_savefile_new_aux(player_ptr);
3477 if (ferror(fff)) err = -1;
3484 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3485 * @param player_ptr プレーヤーへの参照ポインタ
3486 * @param sf_ptr 保存フロア読み込み先
3489 static bool load_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
3491 u32b n_x_check, n_v_check;
3492 u32b o_x_check, o_v_check;
3501 current_world_ptr->h_ver_extra = H_VER_EXTRA;
3502 current_world_ptr->h_ver_patch = H_VER_PATCH;
3503 current_world_ptr->h_ver_minor = H_VER_MINOR;
3504 current_world_ptr->h_ver_major = H_VER_MAJOR;
3508 if (saved_floor_file_sign != tmp32u) return FALSE;
3510 if (rd_saved_floor(player_ptr, sf_ptr)) return FALSE;
3512 n_v_check = v_check;
3513 rd_u32b(&o_v_check);
3515 if (o_v_check != n_v_check) return FALSE;
3517 n_x_check = x_check;
3518 rd_u32b(&o_x_check);
3520 if (o_x_check != n_x_check) return FALSE;
3526 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporarily saved-floor data
3527 * @param player_ptr プレーヤーへの参照ポインタ
3528 * @param sf_ptr 保存フロア読み込み先
3532 bool load_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
3535 * Temporary files are always written in system depended kanji
3549 FILE *old_fff = NULL;
3550 byte old_xor_byte = 0;
3551 u32b old_v_check = 0;
3552 u32b old_x_check = 0;
3553 byte old_h_ver_major = 0;
3554 byte old_h_ver_minor = 0;
3555 byte old_h_ver_patch = 0;
3556 byte old_h_ver_extra = 0;
3557 if (mode & SLF_SECOND)
3560 old_xor_byte = xor_byte;
3561 old_v_check = v_check;
3562 old_x_check = x_check;
3563 old_h_ver_major = current_world_ptr->h_ver_major;
3564 old_h_ver_minor = current_world_ptr->h_ver_minor;
3565 old_h_ver_patch = current_world_ptr->h_ver_patch;
3566 old_h_ver_extra = current_world_ptr->h_ver_extra;
3569 char floor_savefile[1024];
3570 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3573 fff = my_fopen(floor_savefile, "rb");
3576 bool is_save_successful = TRUE;
3577 if (!fff) is_save_successful = FALSE;
3579 if (is_save_successful)
3581 is_save_successful = load_floor_aux(player_ptr, sf_ptr);
3582 if (ferror(fff)) is_save_successful = FALSE;
3586 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3591 if (mode & SLF_SECOND)
3594 xor_byte = old_xor_byte;
3595 v_check = old_v_check;
3596 x_check = old_x_check;
3597 current_world_ptr->h_ver_major = old_h_ver_major;
3598 current_world_ptr->h_ver_minor = old_h_ver_minor;
3599 current_world_ptr->h_ver_patch = old_h_ver_patch;
3600 current_world_ptr->h_ver_extra = old_h_ver_extra;
3603 byte old_kanji_code = kanji_code;
3604 kanji_code = old_kanji_code;
3605 return is_save_successful;