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.
51 #include "floor-generate.h"
59 #include "spells-status.h"
60 #include "object-hook.h"
65 #include "floor-save.h"
66 #include "floor-town.h"
70 #include "dungeon-file.h"
72 #include "player-skill.h"
73 #include "player-class.h"
74 #include "player-race.h"
75 #include "player-personality.h"
76 #include "player-sex.h"
79 #include "objectkind.h"
80 #include "object-ego.h"
84 * Maximum number of tries for selection of a proper quest monster
90 * Local "savefile" pointer
95 * Hack -- old "encryption" byte
100 * Hack -- simple "checksum" on the actual values
102 static u32b v_check = 0L;
105 * Hack -- simple "checksum" on the encoded bytes
107 static u32b x_check = 0L;
110 * Hack -- Japanese Kanji code
116 static byte kanji_code = 0;
119 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
120 * @param major メジャーバージョン値
121 * @param minor マイナーバージョン値
122 * @param patch パッチバージョン値
123 * @param extra エクストラパージョン値
124 * @return 現在のバージョンより値が古いならtrue
126 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
128 /* Much older, or much more recent */
129 if (h_ver_major < major) return (TRUE);
130 if (h_ver_major > major) return (FALSE);
132 /* Distinctly older, or distinctly more recent */
133 if (h_ver_minor < minor) return (TRUE);
134 if (h_ver_minor > minor) return (FALSE);
136 /* Barely older, or barely more recent */
137 if (h_ver_patch < patch) return (TRUE);
138 if (h_ver_patch > patch) return (FALSE);
140 /* Barely older, or barely more recent */
141 if (h_ver_extra < extra) return (TRUE);
142 if (h_ver_extra > extra) return (FALSE);
144 /* Identical versions */
150 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
151 * @param x メジャーバージョン値
152 * @param y マイナーバージョン値
154 * @return 現在のバージョンより値が古いならtrue
156 static bool z_older_than(byte x, byte y, byte z)
158 /* Much older, or much more recent */
159 if (z_major < x) return (TRUE);
160 if (z_major > x) return (FALSE);
162 /* Distinctly older, or distinctly more recent */
163 if (z_minor < y) return (TRUE);
164 if (z_minor > y) return (FALSE);
166 /* Barely older, or barely more recent */
167 if (z_patch < z) return (TRUE);
168 if (z_patch > z) return (FALSE);
170 /* Identical versions */
176 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
180 * Avoid the top two lines, to avoid interference with "msg_print()".
182 static void note(concptr msg)
184 static TERM_LEN y = 2;
186 /* Draw the message */
189 /* Advance one line (wrap if needed) */
190 if (++y >= 24) y = 2;
198 * @brief ロードファイルポインタから1バイトを読み込む
201 * The following functions are used to load the basic building blocks
202 * of savefiles. They also maintain the "checksum" info for 2.7.0+
204 static byte sf_get(void)
208 /* Get a character, decode the value */
209 c = getc(fff) & 0xFF;
213 /* Maintain the checksum info */
217 /* Return the value */
222 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
226 static void rd_byte(byte *ip)
232 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
236 static void rd_u16b(u16b *ip)
239 (*ip) |= ((u16b)(sf_get()) << 8);
243 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
247 static void rd_s16b(s16b *ip)
253 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
257 static void rd_u32b(u32b *ip)
260 (*ip) |= ((u32b)(sf_get()) << 8);
261 (*ip) |= ((u32b)(sf_get()) << 16);
262 (*ip) |= ((u32b)(sf_get()) << 24);
266 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
270 static void rd_s32b(s32b *ip)
277 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
278 * @param str 読み込みポインタ
279 * @param max 最大読み取りバイト数
282 static void rd_string(char *str, int max)
286 /* Read the string */
287 for (i = 0; TRUE; i++)
294 /* Collect string while legal */
295 if (i < max) str[i] = tmp8u;
306 /* Convert Kanji code */
325 /* 不明の漢字コードからシステムの漢字コードに変換 */
326 byte code = codeconv(str);
328 /* 漢字コードが判明したら、それを記録 */
329 if (code) kanji_code = code;
334 /* No conversion needed */
342 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
346 static void strip_bytes(int n)
350 /* Strip the bytes */
351 while (n--) rd_byte(&tmp8u);
354 #define OLD_MAX_MANE 22
357 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
358 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
361 * This function attempts to "repair" old savefiles, and to extract
362 * the most up to date values for various object fields.
364 * Note that Angband 2.7.9 introduced a new method for object "flags"
365 * in which the "flags" on an object are actually extracted when they
366 * are needed from the object kind, artifact index, ego-item index,
367 * and two special "xtra" fields which are used to encode any "extra"
368 * power of certain ego-items. This had the side effect that items
369 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
370 * may have had, and also, all "uncursed" items will become "cursed"
371 * again, including Calris, even if it is being worn at the time. As
372 * a complete hack, items which are inscribed with "uncursed" will be
373 * "uncursed" when imported from pre-2.7.9 savefiles.
375 static void rd_item_old(object_type *o_ptr)
383 rd_s16b(&o_ptr->k_idx);
386 o_ptr->iy = (POSITION)tmp8u;
388 o_ptr->ix = (POSITION)tmp8u;
396 if (z_older_than(10, 4, 4))
398 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
399 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
400 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
404 rd_s16b(&o_ptr->pval);
406 rd_byte(&o_ptr->discount);
408 o_ptr->number = (ITEM_NUMBER)tmp8u;
411 o_ptr->weight = tmp16s;
414 o_ptr->name1 = tmp8u;
417 o_ptr->name2 = tmp8u;
419 rd_s16b(&o_ptr->timeout);
421 rd_s16b(&o_ptr->to_h);
424 o_ptr->to_d = tmp16s;
425 rd_s16b(&o_ptr->to_a);
434 rd_byte(&o_ptr->ident);
436 rd_byte(&o_ptr->marked);
439 rd_u32b(&o_ptr->art_flags[0]);
440 rd_u32b(&o_ptr->art_flags[1]);
441 rd_u32b(&o_ptr->art_flags[2]);
442 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
443 else rd_u32b(&o_ptr->art_flags[3]);
445 if (h_older_than(1, 3, 0, 0))
447 if (o_ptr->name2 == EGO_TELEPATHY)
448 add_flag(o_ptr->art_flags, TR_TELEPATHY);
451 if (z_older_than(11, 0, 11))
453 o_ptr->curse_flags = 0L;
454 if (o_ptr->ident & 0x40)
456 o_ptr->curse_flags |= TRC_CURSED;
457 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
458 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
459 if (object_is_fixed_artifact(o_ptr))
461 artifact_type *a_ptr = &a_info[o_ptr->name1];
462 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
463 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
465 else if (object_is_ego(o_ptr))
467 ego_item_type *e_ptr = &e_info[o_ptr->name2];
468 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
469 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
472 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
476 rd_u32b(&o_ptr->curse_flags);
479 /* Monster holding object */
480 rd_s16b(&o_ptr->held_m_idx);
483 rd_byte(&o_ptr->xtra1);
484 rd_byte(&o_ptr->xtra2);
486 if (z_older_than(11, 0, 10))
488 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
490 switch (o_ptr->xtra2 % 6)
492 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
493 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
494 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
495 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
496 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
497 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
501 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
503 switch (o_ptr->xtra2 % 11)
505 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
506 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
507 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
508 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
509 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
510 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
511 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
512 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
513 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
514 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
515 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
519 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
521 switch (o_ptr->xtra2 % 8)
523 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
524 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
525 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
526 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
527 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
528 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
529 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
530 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
537 if (z_older_than(10, 2, 3))
542 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
544 o_ptr->xtra3 = o_ptr->xtra1;
547 if (o_ptr->tval == TV_CAPTURE)
549 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
550 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
552 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
553 if (ironman_nightmare)
555 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
557 o_ptr->xtra4 = o_ptr->xtra5;
562 rd_byte(&o_ptr->xtra3);
563 if (h_older_than(1, 3, 0, 1))
565 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
566 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
569 rd_s16b(&o_ptr->xtra4);
570 rd_s16b(&o_ptr->xtra5);
573 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)))
575 o_ptr->xtra4 = o_ptr->pval;
579 rd_byte(&o_ptr->feeling);
582 rd_string(buf, sizeof(buf));
584 /* Save the inscription */
585 if (buf[0]) o_ptr->inscription = quark_add(buf);
587 rd_string(buf, sizeof(buf));
588 if (buf[0]) o_ptr->art_name = quark_add(buf);
590 /* The Python object */
598 /* Mega-Hack -- handle "dungeon objects" later */
599 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
601 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
603 if (z_older_than(10, 4, 9))
605 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
607 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
608 add_flag(o_ptr->art_flags, TR_DEC_MANA);
611 if (object_is_fixed_artifact(o_ptr))
613 artifact_type *a_ptr;
615 /* Obtain the artifact info */
616 a_ptr = &a_info[o_ptr->name1];
618 /* Verify that artifact */
619 if (!a_ptr->name) o_ptr->name1 = 0;
621 if (object_is_ego(o_ptr))
623 ego_item_type *e_ptr;
625 /* Obtain the ego-item info */
626 e_ptr = &e_info[o_ptr->name2];
628 /* Verify that ego-item */
629 if (!e_ptr->name) o_ptr->name2 = 0;
636 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
637 * @param o_ptr アイテムオブジェクト保存先ポインタ
640 static void rd_item(object_type *o_ptr)
648 if (h_older_than(1, 5, 0, 0))
654 /*** Item save flags ***/
657 /*** Read un-obvious elements ***/
659 rd_s16b(&o_ptr->k_idx);
662 o_ptr->iy = (POSITION)tmp8u;
664 o_ptr->ix = (POSITION)tmp8u;
667 k_ptr = &k_info[o_ptr->k_idx];
668 o_ptr->tval = k_ptr->tval;
669 o_ptr->sval = k_ptr->sval;
672 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
673 else o_ptr->pval = 0;
675 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
676 else o_ptr->discount = 0;
677 if (flags & SAVE_ITEM_NUMBER) {
679 o_ptr->number = tmp8u;
681 else o_ptr->number = 1;
684 o_ptr->weight = tmp16s;
686 if (flags & SAVE_ITEM_NAME1)
689 o_ptr->name1 = tmp8u;
691 else o_ptr->name1 = 0;
692 if (flags & SAVE_ITEM_NAME2)
695 o_ptr->name2 = tmp8u;
697 else o_ptr->name2 = 0;
698 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
699 else o_ptr->timeout = 0;
701 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
702 else o_ptr->to_h = 0;
703 if (flags & SAVE_ITEM_TO_D)
706 o_ptr->to_d = tmp16s;
708 else o_ptr->to_d = 0;
709 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
710 else o_ptr->to_a = 0;
712 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
715 if (flags & SAVE_ITEM_DD)
721 if (flags & SAVE_ITEM_DS)
728 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
729 else o_ptr->ident = 0;
731 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
732 else o_ptr->marked = 0;
735 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
736 else o_ptr->art_flags[0] = 0;
737 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
738 else o_ptr->art_flags[1] = 0;
739 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
740 else o_ptr->art_flags[2] = 0;
741 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
742 else o_ptr->art_flags[3] = 0;
743 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
744 else o_ptr->art_flags[4] = 0;
746 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
747 else o_ptr->curse_flags = 0;
749 /* Monster holding object */
750 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
751 else o_ptr->held_m_idx = 0;
754 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
755 else o_ptr->xtra1 = 0;
756 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
757 else o_ptr->xtra2 = 0;
759 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
760 else o_ptr->xtra3 = 0;
762 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
763 else o_ptr->xtra4 = 0;
764 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
765 else o_ptr->xtra5 = 0;
767 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
768 else o_ptr->feeling = 0;
770 if (flags & SAVE_ITEM_INSCRIPTION)
772 rd_string(buf, sizeof(buf));
773 o_ptr->inscription = quark_add(buf);
775 else o_ptr->inscription = 0;
777 if (flags & SAVE_ITEM_ART_NAME)
779 rd_string(buf, sizeof(buf));
780 o_ptr->art_name = quark_add(buf);
782 else o_ptr->art_name = 0;
784 if(h_older_than(2,1,2,4))
786 BIT_FLAGS flgs[TR_FLAG_SIZE];
787 object_flags(o_ptr, flgs);
789 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
791 add_flag(o_ptr->art_flags, TR_LITE_M1);
792 remove_flag(o_ptr->art_flags, TR_LITE_1);
793 remove_flag(o_ptr->art_flags, TR_LITE_2);
794 remove_flag(o_ptr->art_flags, TR_LITE_3);
796 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
798 if (o_ptr->tval == TV_LITE)
800 if (o_ptr->sval == SV_LITE_TORCH)
802 add_flag(o_ptr->art_flags, TR_LITE_M1);
804 else if (o_ptr->sval == SV_LITE_LANTERN)
806 add_flag(o_ptr->art_flags, TR_LITE_M2);
808 else if (o_ptr->sval == SV_LITE_FEANOR)
810 add_flag(o_ptr->art_flags, TR_LITE_M3);
815 add_flag(o_ptr->art_flags, TR_LITE_M1);
818 else if (o_ptr->tval == TV_LITE)
820 if (object_is_fixed_artifact(o_ptr))
822 add_flag(o_ptr->art_flags, TR_LITE_3);
824 else if (o_ptr->sval == SV_LITE_TORCH)
826 add_flag(o_ptr->art_flags, TR_LITE_1);
827 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
829 else if (o_ptr->sval == SV_LITE_LANTERN)
831 add_flag(o_ptr->art_flags, TR_LITE_2);
832 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
834 else if (o_ptr->sval == SV_LITE_FEANOR)
836 add_flag(o_ptr->art_flags, TR_LITE_2);
844 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
845 * @param m_ptr モンスター保存先ポインタ
848 static void rd_monster_old(monster_type *m_ptr)
855 /* Read the monster race */
856 rd_s16b(&m_ptr->r_idx);
858 if (z_older_than(11, 0, 12))
859 m_ptr->ap_r_idx = m_ptr->r_idx;
861 rd_s16b(&m_ptr->ap_r_idx);
863 if (z_older_than(11, 0, 14))
865 monster_race *r_ptr = &r_info[m_ptr->r_idx];
867 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
868 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
869 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
872 rd_byte(&m_ptr->sub_align);
874 /* Read the other information */
876 m_ptr->fy = (POSITION)tmp8u;
878 m_ptr->fx = (POSITION)tmp8u;
883 m_ptr->maxhp = tmp16s;
885 if (z_older_than(11, 0, 5))
887 m_ptr->max_maxhp = m_ptr->maxhp;
892 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
894 if(h_older_than(2, 1, 2, 1))
896 m_ptr->dealt_damage = 0;
900 rd_s32b(&m_ptr->dealt_damage);
903 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
906 m_ptr->mspeed = tmp8u;
908 if (z_older_than(10, 4, 2))
911 m_ptr->energy_need = (s16b)tmp8u;
913 else rd_s16b(&m_ptr->energy_need);
915 if (z_older_than(11, 0, 13))
916 m_ptr->energy_need = 100 - m_ptr->energy_need;
918 if (z_older_than(10,0,7))
920 m_ptr->mtimed[MTIMED_FAST] = 0;
921 m_ptr->mtimed[MTIMED_SLOW] = 0;
926 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
928 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
931 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
933 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
935 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
937 if (z_older_than(10,0,10))
941 else if (z_older_than(10,0,11))
949 m_ptr->target_y = (POSITION)tmp16s;
951 m_ptr->target_x = (POSITION)tmp16s;
955 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
957 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
958 rd_u32b(&m_ptr->smart);
962 if (z_older_than(10, 4, 5)) {
969 if (z_older_than(10, 2, 2))
971 if (m_ptr->r_idx < 0)
973 m_ptr->r_idx = (0-m_ptr->r_idx);
974 m_ptr->mflag2 |= MFLAG2_KAGE;
979 rd_byte(&m_ptr->mflag2);
982 if (z_older_than(11, 0, 12))
984 if (m_ptr->mflag2 & MFLAG2_KAGE)
985 m_ptr->ap_r_idx = MON_KAGE;
988 if (z_older_than(10, 1, 3))
994 rd_string(buf, sizeof(buf));
995 if (buf[0]) m_ptr->nickname = quark_add(buf);
1003 * @brief モンスターを読み込む(現版) / Read a monster (New method)
1004 * @param m_ptr モンスター保存先ポインタ
1007 static void rd_monster(monster_type *m_ptr)
1015 if (h_older_than(1, 5, 0, 0))
1017 rd_monster_old(m_ptr);
1021 /*** Monster save flags ***/
1024 /*** Read un-obvious elements ***/
1026 /* Read the monster race */
1027 rd_s16b(&m_ptr->r_idx);
1029 /* Read the other information */
1031 m_ptr->fy = (POSITION)tmp8u;
1033 m_ptr->fx = (POSITION)tmp8u;
1036 m_ptr->hp = (HIT_POINT)tmp16s;
1038 m_ptr->maxhp = (HIT_POINT)tmp16s;
1040 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1042 if(h_older_than(2, 1, 2, 1))
1044 m_ptr->dealt_damage = 0;
1048 rd_s32b(&m_ptr->dealt_damage);
1051 /* Monster race index of its appearance */
1052 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1053 else m_ptr->ap_r_idx = m_ptr->r_idx;
1055 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1056 else m_ptr->sub_align = 0;
1058 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1059 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1062 m_ptr->mspeed = tmp8u;
1064 rd_s16b(&m_ptr->energy_need);
1066 if (flags & SAVE_MON_FAST)
1069 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1071 else m_ptr->mtimed[MTIMED_FAST] = 0;
1072 if (flags & SAVE_MON_SLOW)
1075 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1077 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1078 if (flags & SAVE_MON_STUNNED)
1081 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1083 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1084 if (flags & SAVE_MON_CONFUSED)
1087 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1089 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1090 if (flags & SAVE_MON_MONFEAR)
1093 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1095 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1097 if (flags & SAVE_MON_TARGET_Y)
1100 m_ptr->target_y = (POSITION)tmp16s;
1102 else m_ptr->target_y = 0;
1103 if (flags & SAVE_MON_TARGET_X)
1106 m_ptr->target_x = (POSITION)tmp16s;
1108 else m_ptr->target_x = 0;
1110 if (flags & SAVE_MON_INVULNER)
1113 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1115 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1117 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1118 else m_ptr->smart = 0;
1120 if (flags & SAVE_MON_EXP)
1123 m_ptr->exp = (EXP)tmp32u;
1125 else m_ptr->exp = 0;
1127 m_ptr->mflag = 0; /* Not saved */
1129 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1130 else m_ptr->mflag2 = 0;
1132 if (flags & SAVE_MON_NICKNAME)
1134 rd_string(buf, sizeof(buf));
1135 m_ptr->nickname = quark_add(buf);
1137 else m_ptr->nickname = 0;
1139 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1140 else m_ptr->parent_m_idx = 0;
1145 * Old monster bit flags of racial resistances
1147 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1148 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1149 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1150 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1151 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1152 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1153 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1154 #define RF3_RES_WATE 0x00800000 /* Resist water */
1155 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1156 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1157 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1158 #define RF3_RES_ALL 0x08000000 /* Resist all */
1160 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1162 if ((R_PTR)->r_flags3 & (RF3)) \
1164 (R_PTR)->r_flags3 &= ~(RF3); \
1165 (R_PTR)->r_flagsr |= (RFR); \
1169 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1171 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1173 (R_PTR)->r_flagsr |= (RFR); \
1177 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1178 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1179 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1180 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1181 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1182 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1183 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1184 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1185 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1186 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1189 * @brief モンスターの思い出を読み込む / Read the monster lore
1190 * @param r_idx 読み込み先モンスターID
1193 static void rd_lore(MONRACE_IDX r_idx)
1198 monster_race *r_ptr = &r_info[r_idx];
1200 /* Count sights/deaths/kills */
1202 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1204 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1206 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1207 if (h_older_than(1, 7, 0, 5))
1209 r_ptr->r_akills = r_ptr->r_pkills;
1214 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1217 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1219 /* Count wakes and ignores */
1220 rd_byte(&r_ptr->r_wake);
1221 rd_byte(&r_ptr->r_ignore);
1224 rd_byte(&r_ptr->r_xtra1);
1225 rd_byte(&r_ptr->r_xtra2);
1229 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1231 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1235 rd_byte(&r_ptr->r_cast_spell);
1237 /* Count blows of each type */
1238 rd_byte(&r_ptr->r_blows[0]);
1239 rd_byte(&r_ptr->r_blows[1]);
1240 rd_byte(&r_ptr->r_blows[2]);
1241 rd_byte(&r_ptr->r_blows[3]);
1243 /* Memorize flags */
1244 rd_u32b(&r_ptr->r_flags1);
1245 rd_u32b(&r_ptr->r_flags2);
1246 rd_u32b(&r_ptr->r_flags3);
1247 rd_u32b(&r_ptr->r_flags4);
1248 rd_u32b(&r_ptr->r_flags5);
1249 rd_u32b(&r_ptr->r_flags6);
1250 if (h_older_than(1, 5, 0, 3))
1252 r_ptr->r_flagsr = 0L;
1254 /* Move RF3 resistance flags to RFR */
1255 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1256 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1257 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1258 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1259 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1260 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1261 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1262 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1263 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1264 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1265 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1266 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1268 /* Separate breathers resistance from RF4 to RFR */
1269 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1270 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1271 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1272 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1273 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1274 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1275 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1276 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1277 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1279 /* Resist confusion is merged to RF3_NO_CONF */
1280 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1282 /* Misc resistance hack to RFR */
1283 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1284 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1288 rd_u32b(&r_ptr->r_flagsr);
1291 /* Read the "Racial" monster limit per level */
1293 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1295 /* Location in saved floor */
1296 rd_s16b(&r_ptr->floor_id);
1301 /* Repair the lore flags */
1302 r_ptr->r_flags1 &= r_ptr->flags1;
1303 r_ptr->r_flags2 &= r_ptr->flags2;
1304 r_ptr->r_flags3 &= r_ptr->flags3;
1305 r_ptr->r_flags4 &= r_ptr->flags4;
1306 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1307 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1308 r_ptr->r_flagsr &= r_ptr->flagsr;
1312 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the p_ptr->inventory_list of the "Home"
1313 * @param st_ptr 店舗の参照ポインタ
1314 * @param o_ptr アイテムオブジェクト参照ポインタ
1317 * In all cases, return the slot (or -1) where the object was placed
1319 * Note that this is a hacked up version of "inven_carry()".
1321 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1322 * known, the player may have to pick stuff up and drop it again.
1324 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1332 /* Check each existing item (try to combine) */
1333 for (slot = 0; slot < st_ptr->stock_num; slot++)
1335 /* Get the existing item */
1336 j_ptr = &st_ptr->stock[slot];
1338 /* The home acts just like the player */
1339 if (object_similar(j_ptr, o_ptr))
1341 /* Save the new number of items */
1342 object_absorb(j_ptr, o_ptr);
1350 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1354 /* Determine the "value" of the item */
1355 value = object_value(o_ptr);
1357 /* Check existing slots to see if we must "slide" */
1358 for (slot = 0; slot < st_ptr->stock_num; slot++)
1360 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1363 /* Slide the others up */
1364 for (i = st_ptr->stock_num; i > slot; i--)
1366 st_ptr->stock[i] = st_ptr->stock[i-1];
1369 /* More stuff now */
1370 st_ptr->stock_num++;
1372 /* Insert the new item */
1373 st_ptr->stock[slot] = *o_ptr;
1375 chg_virtue(V_SACRIFICE, -1);
1377 /* Return the location */
1382 * @brief 店舗情報を読み込む / Read a store
1383 * @param town_number 街ID
1384 * @param store_number 店舗ID
1387 static errr rd_store(int town_number, int store_number)
1399 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1401 st_ptr = &town_info[1].store[store_number];
1402 if (st_ptr->stock_num) sort = TRUE;
1406 st_ptr = &town_info[town_number].store[store_number];
1409 /* Read the basic info */
1410 rd_s32b(&st_ptr->store_open);
1411 rd_s16b(&st_ptr->insult_cur);
1413 if (z_older_than(11, 0, 4))
1422 rd_s16b(&st_ptr->good_buy);
1423 rd_s16b(&st_ptr->bad_buy);
1425 /* Read last visit */
1426 rd_s32b(&st_ptr->last_visit);
1428 /* Extract the owner (see above) */
1429 st_ptr->owner = own;
1431 /* Read the items */
1432 for (j = 0; j < num; j++)
1442 /* Acquire valid items */
1443 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1448 home_carry(st_ptr, q_ptr);
1452 k = st_ptr->stock_num++;
1454 /* Acquire the item */
1455 object_copy(&st_ptr->stock[k], q_ptr);
1466 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1469 static void rd_randomizer(void)
1479 rd_u16b(&Rand_place);
1482 for (i = 0; i < RAND_DEG; i++)
1484 rd_u32b(&Rand_state[i]);
1491 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1494 * Note that the normal options are now stored as a set of 256 bit flags,
1495 * plus a set of 256 bit masks to indicate which bit flags were defined
1496 * at the time the savefile was created. This will allow new options
1497 * to be added, and old options to be removed, at any time, without
1498 * hurting old savefiles.
1500 * The window options are stored in the same way, but note that each
1501 * window gets 32 options, and their order is fixed by certain defines.
1503 static void rd_options(void)
1512 /* Ignore old options */
1515 /*** Special info */
1517 /* Read "delay_factor" */
1521 /* Read "hitpoint_warn" */
1525 /* Read "mana_warn" */
1526 if(h_older_than(1, 7, 0, 0))
1536 /*** Cheating options ***/
1540 if (c & 0x0002) p_ptr->wizard = TRUE;
1542 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1543 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1544 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1545 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1546 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1547 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1548 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1549 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1550 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1551 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1553 rd_byte((byte *)&autosave_l);
1554 rd_byte((byte *)&autosave_t);
1555 rd_s16b(&autosave_freq);
1558 /*** Normal Options ***/
1560 /* Read the option flags */
1561 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1563 /* Read the option masks */
1564 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1566 /* Analyze the options */
1567 for (n = 0; n < 8; n++)
1569 /* Analyze the options */
1570 for (i = 0; i < 32; i++)
1572 /* Process valid flags */
1573 if (mask[n] & (1L << i))
1575 /* Process valid flags */
1576 if (option_mask[n] & (1L << i))
1579 if (flag[n] & (1L << i))
1582 option_flag[n] |= (1L << i);
1589 option_flag[n] &= ~(1L << i);
1596 if (z_older_than(10, 4, 5))
1598 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1599 else option_flag[5] |= (0x00000001 << 4);
1600 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1601 else option_flag[2] |= (0x00000001 << 5);
1602 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1603 else option_flag[4] |= (0x00000001 << 5);
1604 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1605 else option_flag[5] |= (0x00000001 << 0);
1606 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1607 else option_flag[5] |= (0x00000001 << 12);
1608 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1609 else option_flag[1] |= (0x00000001 << 0);
1610 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1611 else option_flag[1] |= (0x00000001 << 18);
1612 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1613 else option_flag[1] |= (0x00000001 << 19);
1614 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1615 else option_flag[5] |= (0x00000001 << 3);
1618 /* Extract the options */
1619 extract_option_vars();
1622 /*** Window Options ***/
1624 /* Read the window flags */
1625 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1627 /* Read the window masks */
1628 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1630 /* Analyze the options */
1631 for (n = 0; n < 8; n++)
1633 /* Analyze the options */
1634 for (i = 0; i < 32; i++)
1636 /* Process valid flags */
1637 if (mask[n] & (1L << i))
1639 /* Process valid flags */
1640 if (window_mask[n] & (1L << i))
1643 if (flag[n] & (1L << i))
1646 window_flag[n] |= (1L << i);
1653 window_flag[n] &= ~(1L << i);
1664 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1667 * This is such a nasty hack it hurts.
1669 static void rd_ghost(void)
1674 rd_string(buf, sizeof(buf));
1676 /* Strip old data */
1682 * @brief クイックスタート情報を読み込む / Load quick start data
1685 static void load_quick_start(void)
1691 if (z_older_than(11, 0, 13))
1693 previous_char.quick_ok = FALSE;
1697 rd_byte(&previous_char.psex);
1699 previous_char.prace = (RACE_IDX)tmp8u;
1701 previous_char.pclass = (CLASS_IDX)tmp8u;
1703 previous_char.pseikaku = (CHARACTER_IDX)tmp8u;
1705 previous_char.realm1 = (REALM_IDX)tmp8u;
1707 previous_char.realm2 = (REALM_IDX)tmp8u;
1709 rd_s16b(&previous_char.age);
1710 rd_s16b(&previous_char.ht);
1711 rd_s16b(&previous_char.wt);
1712 rd_s16b(&previous_char.sc);
1713 rd_s32b(&previous_char.au);
1715 for (i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1716 for (i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1718 for (i = 0; i < PY_MAX_LEVEL; i++)
1721 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1724 rd_s16b(&previous_char.chaos_patron);
1726 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1728 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1730 /* UNUSED : Was number of random quests */
1734 previous_char.quick_ok = (bool)tmp8u;
1738 * @brief その他の情報を読み込む / Read the "extra" information
1741 static void rd_extra(void)
1750 rd_string(p_ptr->name, sizeof(p_ptr->name));
1752 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1754 if (!h_older_than(1, 7, 0, 1))
1758 /* Read the message */
1759 rd_string(buf, sizeof buf);
1760 if (buf[0]) p_ptr->last_message = string_make(buf);
1765 for (i = 0; i < 4; i++)
1767 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1770 /* Class/Race/Seikaku/Gender/Spells */
1772 p_ptr->prace = (RACE_IDX)tmp8u;
1774 p_ptr->pclass = (CLASS_IDX)tmp8u;
1776 p_ptr->pseikaku = (CHARACTER_IDX)tmp8u;
1777 rd_byte(&p_ptr->psex);
1779 p_ptr->realm1 = (REALM_IDX)tmp8u;
1781 p_ptr->realm2 = (REALM_IDX)tmp8u;
1784 if (z_older_than(10, 4, 4))
1786 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1787 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1788 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1789 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1792 /* Special Race/Class info */
1794 p_ptr->hitdie = tmp8u;
1795 rd_u16b(&p_ptr->expfact);
1797 /* Age/Height/Weight */
1798 rd_s16b(&p_ptr->age);
1799 rd_s16b(&p_ptr->ht);
1800 rd_s16b(&p_ptr->wt);
1802 /* Read the stat info */
1803 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_max[i]);
1804 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1805 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_cur[i]);
1808 rd_s32b(&p_ptr->au);
1810 rd_s32b(&p_ptr->max_exp);
1811 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1812 else rd_s32b(&p_ptr->max_max_exp);
1813 rd_s32b(&p_ptr->exp);
1815 if (h_older_than(1, 7, 0, 3))
1818 p_ptr->exp_frac = (u32b)tmp16u;
1822 rd_u32b(&p_ptr->exp_frac);
1825 rd_s16b(&p_ptr->lev);
1827 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1828 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1830 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1832 if (z_older_than(10, 3, 6))
1833 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1835 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1836 for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1837 if (z_older_than(10, 4, 1))
1839 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1840 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1842 if (z_older_than(10, 3, 14))
1844 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1845 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1849 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1850 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1851 if (h_older_than(1, 3, 0, 1))
1853 if (p_ptr->pclass == CLASS_SMITH)
1855 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1856 p_ptr->magic_num1[96] = 0;
1857 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1858 p_ptr->magic_num1[97] = 0;
1862 if (music_singing_any()) p_ptr->action = ACTION_SING;
1864 if (z_older_than(11, 0, 7))
1866 p_ptr->start_race = p_ptr->prace;
1867 p_ptr->old_race1 = 0L;
1868 p_ptr->old_race2 = 0L;
1869 p_ptr->old_realm = 0;
1874 p_ptr->start_race = (RACE_IDX)tmp8u;
1876 p_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1878 p_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1879 rd_s16b(&p_ptr->old_realm);
1882 if (z_older_than(10, 0, 1))
1884 for (i = 0; i < MAX_MANE; i++)
1886 p_ptr->mane_spell[i] = -1;
1887 p_ptr->mane_dam[i] = 0;
1889 p_ptr->mane_num = 0;
1891 else if (z_older_than(10, 2, 3))
1893 for (i = 0; i < OLD_MAX_MANE; i++)
1898 for (i = 0; i < MAX_MANE; i++)
1900 p_ptr->mane_spell[i] = -1;
1901 p_ptr->mane_dam[i] = 0;
1904 p_ptr->mane_num = 0;
1908 for (i = 0; i < MAX_MANE; i++)
1911 p_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1913 p_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1915 rd_s16b(&p_ptr->mane_num);
1918 if (z_older_than(10, 0, 3))
1920 determine_bounty_uniques();
1922 for (i = 0; i < MAX_KUBI; i++)
1924 /* Is this bounty unique already dead? */
1925 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1930 for (i = 0; i < MAX_KUBI; i++)
1932 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1936 if (z_older_than(10, 0, 3))
1938 update_gambling_monsters();
1942 for (i = 0; i < 4; i++)
1944 rd_s16b(&battle_mon[i]);
1945 if (z_older_than(10, 3, 4))
1948 mon_odds[i] = tmp16s;
1950 else rd_u32b(&mon_odds[i]);
1954 rd_s16b(&p_ptr->town_num);
1956 /* Read arena and rewards information */
1957 rd_s16b(&p_ptr->arena_number);
1958 if (h_older_than(1, 5, 0, 1))
1960 /* Arena loser of previous version was marked number 99 */
1961 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1964 p_ptr->inside_arena = (bool)tmp16s;
1965 rd_s16b(&p_ptr->inside_quest);
1966 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1970 p_ptr->inside_battle = (bool)tmp16s;
1972 rd_byte(&p_ptr->exit_bldg);
1976 p_ptr->oldpx = (POSITION)tmp16s;
1978 p_ptr->oldpy = (POSITION)tmp16s;
1980 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1982 /* Was p_ptr->rewards[MAX_BACT] */
1984 for (i = 0; i < tmp16s; i++)
1990 if (h_older_than(1, 7, 0, 3))
1993 p_ptr->mhp = tmp16s;
1996 p_ptr->chp = tmp16s;
1999 p_ptr->chp_frac = (u32b)tmp16u;
2003 rd_s32b(&p_ptr->mhp);
2004 rd_s32b(&p_ptr->chp);
2005 rd_u32b(&p_ptr->chp_frac);
2008 if (h_older_than(1, 7, 0, 3))
2011 p_ptr->msp = tmp16s;
2014 p_ptr->csp = tmp16s;
2017 p_ptr->csp_frac = (u32b)tmp16u;
2021 rd_s32b(&p_ptr->msp);
2022 rd_s32b(&p_ptr->csp);
2023 rd_u32b(&p_ptr->csp_frac);
2026 rd_s16b(&p_ptr->max_plv);
2027 if (z_older_than(10, 3, 8))
2030 max_dlv[DUNGEON_ANGBAND] = tmp16s;
2034 byte max = (byte)max_d_idx;
2038 for(i = 0; i < max; i++)
2041 max_dlv[i] = tmp16s;
2042 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
2046 /* Repair maximum player level */
2047 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
2051 rd_s16b(&p_ptr->sc);
2052 rd_s16b(&p_ptr->concent);
2054 /* Read the flags */
2055 strip_bytes(2); /* Old "rest" */
2056 rd_s16b(&p_ptr->blind);
2057 rd_s16b(&p_ptr->paralyzed);
2058 rd_s16b(&p_ptr->confused);
2059 rd_s16b(&p_ptr->food);
2060 strip_bytes(4); /* Old "food_digested" / "protection" */
2062 rd_s16b(&p_ptr->energy_need);
2063 if (z_older_than(11, 0, 13))
2064 p_ptr->energy_need = 100 - p_ptr->energy_need;
2065 if (h_older_than(2, 1, 2, 0))
2066 p_ptr->enchant_energy_need = 0;
2068 rd_s16b(&p_ptr->enchant_energy_need);
2070 rd_s16b(&p_ptr->fast);
2071 rd_s16b(&p_ptr->slow);
2072 rd_s16b(&p_ptr->afraid);
2073 rd_s16b(&p_ptr->cut);
2074 rd_s16b(&p_ptr->stun);
2075 rd_s16b(&p_ptr->poisoned);
2076 rd_s16b(&p_ptr->image);
2077 rd_s16b(&p_ptr->protevil);
2078 rd_s16b(&p_ptr->invuln);
2079 if(z_older_than(10, 0, 0))
2082 rd_s16b(&p_ptr->ult_res);
2083 rd_s16b(&p_ptr->hero);
2084 rd_s16b(&p_ptr->shero);
2085 rd_s16b(&p_ptr->shield);
2086 rd_s16b(&p_ptr->blessed);
2087 rd_s16b(&p_ptr->tim_invis);
2088 rd_s16b(&p_ptr->word_recall);
2089 if (z_older_than(10, 3, 8))
2090 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2094 p_ptr->recall_dungeon = (byte)tmp16s;
2097 if (h_older_than(1, 5, 0, 0))
2098 p_ptr->alter_reality = 0;
2100 rd_s16b(&p_ptr->alter_reality);
2102 rd_s16b(&p_ptr->see_infra);
2103 rd_s16b(&p_ptr->tim_infra);
2104 rd_s16b(&p_ptr->oppose_fire);
2105 rd_s16b(&p_ptr->oppose_cold);
2106 rd_s16b(&p_ptr->oppose_acid);
2107 rd_s16b(&p_ptr->oppose_elec);
2108 rd_s16b(&p_ptr->oppose_pois);
2109 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2110 else rd_s16b(&p_ptr->tsuyoshi);
2112 /* Old savefiles do not have the following fields... */
2113 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2116 p_ptr->wraith_form = 0;
2117 p_ptr->resist_magic = 0;
2118 p_ptr->tim_regen = 0;
2119 p_ptr->kabenuke = 0;
2120 p_ptr->tim_stealth = 0;
2121 p_ptr->tim_levitation = 0;
2122 p_ptr->tim_sh_touki = 0;
2123 p_ptr->lightspeed = 0;
2124 p_ptr->tsubureru = 0;
2125 p_ptr->tim_res_nether = 0;
2126 p_ptr->tim_res_time = 0;
2127 p_ptr->mimic_form = 0;
2128 p_ptr->tim_mimic = 0;
2129 p_ptr->tim_sh_fire = 0;
2132 p_ptr->tim_reflect = 0;
2133 p_ptr->multishadow = 0;
2134 p_ptr->dustrobe = 0;
2136 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2144 rd_s16b(&p_ptr->tim_esp);
2145 rd_s16b(&p_ptr->wraith_form);
2146 rd_s16b(&p_ptr->resist_magic);
2147 rd_s16b(&p_ptr->tim_regen);
2148 rd_s16b(&p_ptr->kabenuke);
2149 rd_s16b(&p_ptr->tim_stealth);
2150 rd_s16b(&p_ptr->tim_levitation);
2151 rd_s16b(&p_ptr->tim_sh_touki);
2152 rd_s16b(&p_ptr->lightspeed);
2153 rd_s16b(&p_ptr->tsubureru);
2154 if (z_older_than(10, 4, 7))
2155 p_ptr->magicdef = 0;
2157 rd_s16b(&p_ptr->magicdef);
2158 rd_s16b(&p_ptr->tim_res_nether);
2159 if (z_older_than(10, 4, 11))
2161 p_ptr->tim_res_time = 0;
2162 p_ptr->mimic_form = 0;
2163 p_ptr->tim_mimic = 0;
2164 p_ptr->tim_sh_fire = 0;
2168 rd_s16b(&p_ptr->tim_res_time);
2170 p_ptr->mimic_form = (IDX)tmp8u;
2171 rd_s16b(&p_ptr->tim_mimic);
2172 rd_s16b(&p_ptr->tim_sh_fire);
2175 if (z_older_than(11, 0, 99))
2177 p_ptr->tim_sh_holy = 0;
2178 p_ptr->tim_eyeeye = 0;
2182 rd_s16b(&p_ptr->tim_sh_holy);
2183 rd_s16b(&p_ptr->tim_eyeeye);
2187 if ( z_older_than(11,0,3) ){
2188 p_ptr->tim_reflect=0;
2189 p_ptr->multishadow=0;
2193 rd_s16b(&p_ptr->tim_reflect);
2194 rd_s16b(&p_ptr->multishadow);
2195 rd_s16b(&p_ptr->dustrobe);
2198 rd_s16b(&p_ptr->chaos_patron);
2199 rd_u32b(&p_ptr->muta1);
2200 rd_u32b(&p_ptr->muta2);
2201 rd_u32b(&p_ptr->muta3);
2203 for (i = 0; i < 8; i++)
2204 rd_s16b(&p_ptr->virtues[i]);
2205 for (i = 0; i < 8; i++)
2206 rd_s16b(&p_ptr->vir_types[i]);
2209 /* Calc the regeneration modifier for mutations */
2210 p_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod();
2212 if (z_older_than(10,0,9))
2215 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2216 p_ptr->ele_attack = 0;
2220 rd_s16b(&p_ptr->ele_attack);
2221 rd_u32b(&p_ptr->special_attack);
2223 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2224 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2225 if (z_older_than(10,0,12))
2227 p_ptr->ele_immune = 0;
2228 p_ptr->special_defense = 0;
2232 rd_s16b(&p_ptr->ele_immune);
2233 rd_u32b(&p_ptr->special_defense);
2235 rd_byte(&p_ptr->knowledge);
2238 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2242 p_ptr->action = (ACTION_IDX)tmp8u;
2243 if (!z_older_than(10, 4, 3))
2246 if (tmp8u) p_ptr->action = ACTION_LEARN;
2248 rd_byte((byte *)&preserve_mode);
2249 rd_byte((byte *)&p_ptr->wait_report_score);
2252 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2254 /* Skip the flags */
2258 /* Hack -- the two "special seeds" */
2259 rd_u32b(¤t_world_ptr->seed_flavor);
2260 rd_u32b(¤t_world_ptr->seed_town);
2264 rd_u16b(&p_ptr->panic_save);
2265 rd_u16b(&p_ptr->total_winner);
2266 rd_u16b(&p_ptr->noscore);
2271 p_ptr->is_dead = tmp8u;
2273 /* Read "feeling" */
2274 rd_byte(&p_ptr->feeling);
2276 switch (p_ptr->start_race)
2282 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2285 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2288 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2290 /* Turn when level began */
2291 rd_s32b(¤t_floor_ptr->generated_turn);
2293 if (h_older_than(1, 7, 0, 4))
2295 p_ptr->feeling_turn = current_floor_ptr->generated_turn;
2299 /* Turn of last "feeling" */
2300 rd_s32b(&p_ptr->feeling_turn);
2303 /* Current current_world_ptr->game_turn */
2304 rd_s32b(¤t_world_ptr->game_turn);
2306 if (z_older_than(10, 3, 12))
2308 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2310 else rd_s32b(¤t_world_ptr->dungeon_turn);
2312 if (z_older_than(11, 0, 13))
2314 current_floor_ptr->generated_turn /= 2;
2315 p_ptr->feeling_turn /= 2;
2316 current_world_ptr->game_turn /= 2;
2317 current_world_ptr->dungeon_turn /= 2;
2320 if (z_older_than(10, 3, 13))
2322 old_battle = current_world_ptr->game_turn;
2324 else rd_s32b(&old_battle);
2326 if (z_older_than(10,0,3))
2328 determine_today_mon(TRUE);
2332 rd_s16b(&today_mon);
2333 rd_s16b(&p_ptr->today_mon);
2336 if (z_older_than(10,0,7))
2342 rd_s16b(&p_ptr->riding);
2345 /* Current floor_id */
2346 if (h_older_than(1, 5, 0, 0))
2348 p_ptr->floor_id = 0;
2352 rd_s16b(&p_ptr->floor_id);
2355 if (h_older_than(1, 5, 0, 2))
2361 /* Get number of party_mon array */
2364 /* Strip old temporary preserved pets */
2365 for (i = 0; i < tmp16s; i++)
2367 monster_type dummy_mon;
2369 rd_monster(&dummy_mon);
2373 if (z_older_than(10,1,2))
2375 current_world_ptr->play_time = 0;
2379 rd_u32b(¤t_world_ptr->play_time);
2382 if (z_older_than(10,3,9))
2386 else if (z_older_than(10, 3, 10))
2394 p_ptr->visit = (BIT_FLAGS)tmp32s;
2396 if (!z_older_than(11, 0, 5))
2398 rd_u32b(&p_ptr->count);
2404 * @brief プレイヤーの所持品情報を読み込む / Read the player p_ptr->inventory_list
2407 * Note that the p_ptr->inventory_list changed in Angband 2.7.4. Two extra
2408 * pack slots were added and the equipment was rearranged. Note
2409 * that these two features combine when parsing old save-files, in
2410 * which items from the old "aux" slot are "carried", perhaps into
2411 * one of the two new "p_ptr->inventory_list" slots.
2413 * Note that the p_ptr->inventory_list is "re-sorted" later by "dungeon()".
2415 static errr rd_inventory(void)
2423 p_ptr->total_weight = 0;
2426 p_ptr->inven_cnt = 0;
2427 p_ptr->equip_cnt = 0;
2429 /* Read until done */
2434 /* Get the next item index */
2437 /* Nope, we reached the end */
2438 if (n == 0xFFFF) break;
2445 /* Hack -- verify item */
2446 if (!q_ptr->k_idx) return (53);
2448 /* Wield equipment */
2449 if (n >= INVEN_RARM)
2451 q_ptr->marked |= OM_TOUCHED;
2452 object_copy(&p_ptr->inventory_list[n], q_ptr);
2454 /* Add the weight */
2455 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2461 /* Warning -- backpack is full */
2462 else if (p_ptr->inven_cnt == INVEN_PACK)
2464 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the p_ptr->inventory_list!"));
2470 /* Carry p_ptr->inventory_list */
2476 q_ptr->marked |= OM_TOUCHED;
2477 object_copy(&p_ptr->inventory_list[n], q_ptr);
2479 /* Add the weight */
2480 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2493 * @brief メッセージログを読み込む / Read the saved messages
2496 static void rd_messages(void)
2503 if (h_older_than(2, 2, 0, 75))
2508 message_max = (int)num;
2510 /* Read the messages */
2511 for (i = 0; i < message_max; i++)
2513 /* Read the message */
2514 rd_string(buf, sizeof(buf));
2516 /* Save the message */
2525 message_max = (int)num;
2527 /* Read the messages */
2528 for (i = 0; i < message_max; i++)
2530 /* Read the message */
2531 rd_string(buf, sizeof(buf));
2533 /* Save the message */
2542 /* Old hidden trap flag */
2543 #define CAVE_TRAP 0x8000
2545 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2546 #define OLD_FEAT_INVIS 0x02
2547 #define OLD_FEAT_GLYPH 0x03
2548 #define OLD_FEAT_QUEST_ENTER 0x08
2549 #define OLD_FEAT_QUEST_EXIT 0x09
2550 #define OLD_FEAT_MINOR_GLYPH 0x40
2551 #define OLD_FEAT_BLDG_1 0x81
2552 #define OLD_FEAT_MIRROR 0xc3
2555 #define OLD_QUEST_WATER_CAVE 18
2557 /* Quest constants */
2558 #define QUEST_OLD_CASTLE 27
2559 #define QUEST_ROYAL_CRYPT 28
2562 * @brief メッセージログを読み込む / Read the dungeon (old method)
2565 * The monsters/objects must be loaded in the same order
2566 * that they were stored, since the actual indexes matter.
2568 static errr rd_dungeon_old(void)
2579 /*** Basic info ***/
2583 current_floor_ptr->dun_level = (DEPTH)tmp16s;
2584 if (z_older_than(10, 3, 8)) p_ptr->dungeon_idx = DUNGEON_ANGBAND;
2588 p_ptr->dungeon_idx = (IDX)tmp8u;
2591 /* Set the base level for old versions */
2592 current_floor_ptr->base_level = current_floor_ptr->dun_level;
2595 current_floor_ptr->base_level = (DEPTH)tmp16s;
2598 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2600 p_ptr->y = (POSITION)tmp16s;
2602 p_ptr->x = (POSITION)tmp16s;
2603 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2605 current_floor_ptr->height = (POSITION)tmp16s;
2607 current_floor_ptr->width = (POSITION)tmp16s;
2608 rd_s16b(&tmp16s); /* max_panel_rows */
2609 rd_s16b(&tmp16s); /* max_panel_cols */
2612 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2616 ymax = current_floor_ptr->height;
2617 xmax = current_floor_ptr->width;
2620 /*** Run length decoding ***/
2622 /* Load the dungeon data */
2623 for (x = y = 0; y < ymax; )
2629 if (z_older_than(10,3,6))
2638 /* Decline invalid flags */
2639 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2642 /* Apply the RLE info */
2643 for (i = count; i > 0; i--)
2645 /* Access the current_floor_ptr->grid_array */
2646 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2648 /* Extract "info" */
2658 if (++y >= ymax) break;
2664 /*** Run length decoding ***/
2666 /* Load the dungeon data */
2667 for (x = y = 0; y < ymax; )
2673 /* Apply the RLE info */
2674 for (i = count; i > 0; i--)
2676 /* Access the current_floor_ptr->grid_array */
2677 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2679 /* Extract "feat" */
2680 g_ptr->feat = (s16b)tmp8u;
2689 if (++y >= ymax) break;
2694 /*** Run length decoding ***/
2696 /* Load the dungeon data */
2697 for (x = y = 0; y < ymax; )
2703 /* Apply the RLE info */
2704 for (i = count; i > 0; i--)
2706 /* Access the current_floor_ptr->grid_array */
2707 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2709 /* Extract "mimic" */
2710 g_ptr->mimic = (s16b)tmp8u;
2719 if (++y >= ymax) break;
2724 /*** Run length decoding ***/
2726 /* Load the dungeon data */
2727 for (x = y = 0; y < ymax; )
2733 /* Apply the RLE info */
2734 for (i = count; i > 0; i--)
2736 /* Access the current_floor_ptr->grid_array */
2737 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2739 /* Extract "feat" */
2740 g_ptr->special = tmp16s;
2749 if (++y >= ymax) break;
2754 /* Convert current_floor_ptr->grid_array data */
2755 if (z_older_than(11, 0, 99))
2757 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2759 /* Wipe old unused flags */
2760 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2764 if (h_older_than(1, 1, 1, 0))
2766 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2768 /* Access the current_floor_ptr->grid_array */
2769 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2772 if (g_ptr->feat == OLD_FEAT_INVIS)
2774 g_ptr->feat = feat_floor;
2775 g_ptr->info |= CAVE_TRAP;
2778 /* Older than 1.1.1 */
2779 if (g_ptr->feat == OLD_FEAT_MIRROR)
2781 g_ptr->feat = feat_floor;
2782 g_ptr->info |= CAVE_OBJECT;
2787 if (h_older_than(1, 3, 1, 0))
2789 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2791 /* Access the current_floor_ptr->grid_array */
2792 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2794 /* Old CAVE_IN_MIRROR flag */
2795 if (g_ptr->info & CAVE_OBJECT)
2797 g_ptr->mimic = feat_mirror;
2800 /* Runes will be mimics and flags */
2801 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2802 (g_ptr->feat == OLD_FEAT_GLYPH))
2804 g_ptr->info |= CAVE_OBJECT;
2805 g_ptr->mimic = g_ptr->feat;
2806 g_ptr->feat = feat_floor;
2809 /* Hidden traps will be trap terrains mimicing floor */
2810 else if (g_ptr->info & CAVE_TRAP)
2812 g_ptr->info &= ~CAVE_TRAP;
2813 g_ptr->mimic = g_ptr->feat;
2814 g_ptr->feat = choose_random_trap();
2817 /* Another hidden trap */
2818 else if (g_ptr->feat == OLD_FEAT_INVIS)
2820 g_ptr->mimic = feat_floor;
2821 g_ptr->feat = feat_trap_open;
2826 /* Quest 18 was removed */
2827 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2829 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2831 /* Access the current_floor_ptr->grid_array */
2832 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2834 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
2836 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2838 g_ptr->feat = feat_tree;
2841 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2843 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2846 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2847 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2849 g_ptr->feat = feat_up_stair;
2857 /* Read the item count */
2860 /* Verify maximum */
2861 if (limit > current_floor_ptr->max_o_idx)
2863 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2867 /* Read the dungeon items */
2868 for (i = 1; i < limit; i++)
2875 /* Get a new record */
2880 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2886 o_ptr = ¤t_floor_ptr->o_list[o_idx];
2894 if (o_ptr->held_m_idx)
2896 monster_type *m_ptr;
2897 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
2900 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2902 m_ptr->hold_o_idx = o_idx;
2908 /* Access the item location */
2909 g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2912 o_ptr->next_o_idx = g_ptr->o_idx;
2914 g_ptr->o_idx = o_idx;
2921 /* Read the monster count */
2924 /* Hack -- verify */
2925 if (limit > current_floor_ptr->max_m_idx)
2927 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2931 /* Read the monsters */
2932 for (i = 1; i < limit; i++)
2935 monster_type *m_ptr;
2937 /* Get a new record */
2942 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2947 /* Acquire monster */
2948 m_ptr = ¤t_floor_ptr->m_list[m_idx];
2950 /* Read the monster */
2955 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2957 /* Mark the location */
2958 g_ptr->m_idx = m_idx;
2961 real_r_ptr(m_ptr)->cur_num++;
2966 /* The dungeon is ready */
2967 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena)
2968 character_dungeon = FALSE;
2970 character_dungeon = TRUE;
2978 * @brief 保存されたフロアを読み込む / Read the saved floor
2979 * @return info読み込みエラーコード
2981 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2984 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2985 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2987 * The monsters/objects must be loaded in the same order
2988 * that they were stored, since the actual indexes matter.
2990 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2992 POSITION ymax, xmax;
3003 grid_template_type *templates;
3006 /*** Wipe all current_floor_ptr->grid_array ***/
3010 /*** Basic info ***/
3012 /* Dungeon floor specific info follows */
3016 /*** Not a saved floor ***/
3019 current_floor_ptr->dun_level = (DEPTH)tmp16s;
3020 current_floor_ptr->base_level = current_floor_ptr->dun_level;
3024 /*** The saved floor ***/
3027 if (tmp16s != sf_ptr->floor_id) return 171;
3030 if (tmp8u != sf_ptr->savefile_id) return 171;
3033 if (tmp16s != sf_ptr->dun_level) return 171;
3034 current_floor_ptr->dun_level = sf_ptr->dun_level;
3037 if (tmp32s != sf_ptr->last_visit) return 171;
3040 if (tmp32u != sf_ptr->visit_mark) return 171;
3043 if (tmp16s != sf_ptr->upper_floor_id) return 171;
3046 if (tmp16s != sf_ptr->lower_floor_id) return 171;
3050 current_floor_ptr->base_level = (DEPTH)tmp16s;
3052 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
3055 p_ptr->y = (POSITION)tmp16u;
3058 p_ptr->x = (POSITION)tmp16u;
3061 current_floor_ptr->height = (POSITION)tmp16s;
3063 current_floor_ptr->width = (POSITION)tmp16s;
3065 rd_byte(&p_ptr->feeling);
3069 /*** Read template for grid_type ***/
3071 /* Read the template count */
3074 /* Allocate the "template" array */
3075 C_MAKE(templates, limit, grid_template_type);
3077 /* Read the templates */
3078 for (i = 0; i < limit; i++)
3080 grid_template_type *ct_ptr = &templates[i];
3084 ct_ptr->info = (BIT_FLAGS)tmp16u;
3085 if (h_older_than(1, 7, 0, 2))
3088 ct_ptr->feat = (s16b)tmp8u;
3090 ct_ptr->mimic = (s16b)tmp8u;
3094 rd_s16b(&ct_ptr->feat);
3095 rd_s16b(&ct_ptr->mimic);
3097 rd_s16b(&ct_ptr->special);
3101 ymax = current_floor_ptr->height;
3102 xmax = current_floor_ptr->width;
3105 /*** Run length decoding ***/
3107 /* Load the dungeon data */
3108 for (x = y = 0; y < ymax; )
3120 } while (tmp8u == MAX_UCHAR);
3122 /* Apply the RLE info */
3123 for (i = count; i > 0; i--)
3125 /* Access the current_floor_ptr->grid_array */
3126 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3128 /* Extract current_floor_ptr->grid_array data */
3129 g_ptr->info = templates[id].info;
3130 g_ptr->feat = templates[id].feat;
3131 g_ptr->mimic = templates[id].mimic;
3132 g_ptr->special = templates[id].special;
3141 if (++y >= ymax) break;
3146 /* Quest 18 was removed */
3147 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3149 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3151 /* Access the current_floor_ptr->grid_array */
3152 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3154 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
3156 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
3158 g_ptr->feat = feat_tree;
3161 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
3163 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3166 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3167 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3169 g_ptr->feat = feat_up_stair;
3175 /* Free the "template" array */
3176 C_KILL(templates, limit, grid_template_type);
3181 /* Read the item count */
3184 /* Verify maximum */
3185 if (limit > current_floor_ptr->max_o_idx) return 151;
3188 /* Read the dungeon items */
3189 for (i = 1; i < limit; i++)
3195 /* Get a new record */
3198 if (i != o_idx) return 152;
3201 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3206 if (o_ptr->held_m_idx)
3208 monster_type *m_ptr;
3209 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
3212 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3214 m_ptr->hold_o_idx = o_idx;
3220 /* Access the item location */
3221 grid_type *g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
3224 o_ptr->next_o_idx = g_ptr->o_idx;
3226 g_ptr->o_idx = o_idx;
3233 /* Read the monster count */
3236 /* Hack -- verify */
3237 if (limit > current_floor_ptr->max_m_idx) return 161;
3239 /* Read the monsters */
3240 for (i = 1; i < limit; i++)
3244 monster_type *m_ptr;
3246 /* Get a new record */
3249 if (i != m_idx) return 162;
3252 /* Acquire monster */
3253 m_ptr = ¤t_floor_ptr->m_list[m_idx];
3255 /* Read the monster */
3260 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
3262 /* Mark the location */
3263 g_ptr->m_idx = m_idx;
3266 real_r_ptr(m_ptr)->cur_num++;
3275 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3278 * The monsters/objects must be loaded in the same order
3279 * that they were stored, since the actual indexes matter.
3281 static errr rd_dungeon(void)
3289 /* Initialize saved_floors array and temporal files */
3290 init_saved_floors(FALSE);
3293 if (h_older_than(1, 5, 0, 0))
3295 err = rd_dungeon_old();
3297 /* Prepare floor_id of current floor */
3298 if (p_ptr->dungeon_idx)
3300 p_ptr->floor_id = get_new_floor_id();
3301 get_sf_ptr(p_ptr->floor_id)->dun_level = current_floor_ptr->dun_level;
3310 /* Number of floor_id used from birth */
3311 rd_s16b(&max_floor_id);
3313 /* Current dungeon type */
3315 p_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
3317 /* Number of the saved_floors array elements */
3320 /*** No saved floor (On the surface etc.) ***/
3323 /* Read the current floor data */
3324 err = rd_saved_floor(NULL);
3327 /*** In the dungeon ***/
3331 /* Read the saved_floors array */
3332 for (i = 0; i < num; i++)
3334 saved_floor_type *sf_ptr = &saved_floors[i];
3336 rd_s16b(&sf_ptr->floor_id);
3338 sf_ptr->savefile_id = (s16b)tmp8u;
3341 sf_ptr->dun_level = (DEPTH)tmp16s;
3343 rd_s32b(&sf_ptr->last_visit);
3344 rd_u32b(&sf_ptr->visit_mark);
3345 rd_s16b(&sf_ptr->upper_floor_id);
3346 rd_s16b(&sf_ptr->lower_floor_id);
3350 /* Move saved floors data to temporal files */
3351 for (i = 0; i < num; i++)
3353 saved_floor_type *sf_ptr = &saved_floors[i];
3355 /* Unused element */
3356 if (!sf_ptr->floor_id) continue;
3358 /* Read the failure mark */
3360 if (tmp8u) continue;
3362 /* Read from the save file */
3363 err = rd_saved_floor(sf_ptr);
3368 /* Re-save as temporal saved floor file */
3369 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3375 /* Finally load current floor data from temporal file */
3378 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3383 /*** Error messages ***/
3387 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3391 note(_("アイテム配置エラー", "Object allocation error"));
3395 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3399 note(_("モンスター配置エラー", "Monster allocation error"));
3403 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3407 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3411 note(_("Error 183", "Error 183"));
3415 /* The dungeon is ready */
3416 character_dungeon = TRUE;
3418 /* Success or Error */
3424 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3427 static errr rd_savefile_new_aux(void)
3440 #ifdef VERIFY_CHECKSUMS
3441 u32b n_x_check, n_v_check;
3442 u32b o_x_check, o_v_check;
3446 /* Strip the version bytes */
3449 /* Hack -- decrypt */
3450 xor_byte = sf_extra;
3453 /* Clear the checksums */
3457 /* Read the version number of the savefile */
3458 /* Old savefile will be version 0.0.0.3 */
3459 rd_byte(&h_ver_extra);
3460 rd_byte(&h_ver_patch);
3461 rd_byte(&h_ver_minor);
3462 rd_byte(&h_ver_major);
3464 /* Mention the savefile version */
3466 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3467 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3470 /* Operating system info */
3471 rd_u32b(&sf_system);
3473 /* Time of savefile creation */
3476 /* Number of resurrections */
3479 /* Number of times played */
3483 /* Later use (always zero) */
3486 /* Later use (always zero) */
3489 /* Later use (always zero) */
3493 rd_byte(&kanji_code);
3495 /* Read RNG state */
3497 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3499 /* Then the options */
3501 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3503 /* Then the "messages" */
3505 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3507 for (i = 0; i < max_r_idx; i++)
3509 /* Access that monster */
3510 monster_race *r_ptr = &r_info[i];
3512 /* Hack -- Reset the death counter */
3513 r_ptr->max_num = 100;
3515 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3517 /* Hack -- Non-unique Nazguls are semi-unique */
3518 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3521 /* Monster Memory */
3524 /* Incompatible save files */
3525 if (tmp16u > max_r_idx)
3527 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3531 /* Read the available records */
3532 for (i = 0; i < tmp16u; i++)
3535 rd_lore((MONRACE_IDX)i);
3538 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3543 /* Incompatible save files */
3544 if (tmp16u > max_k_idx)
3546 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3550 /* Read the object memory */
3551 for (i = 0; i < tmp16u; i++)
3553 object_kind *k_ptr = &k_info[i];
3557 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3558 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3560 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3562 /* 2.1.3 or newer version */
3564 u16b max_towns_load;
3565 u16b max_quests_load;
3566 byte max_rquests_load;
3567 s16b old_inside_quest = p_ptr->inside_quest;
3569 /* Number of towns */
3570 rd_u16b(&max_towns_load);
3572 /* Incompatible save files */
3573 if (max_towns_load > max_towns)
3575 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3579 /* Number of quests */
3580 rd_u16b(&max_quests_load);
3582 if (z_older_than(11, 0, 7))
3584 max_rquests_load = 10;
3588 rd_byte(&max_rquests_load);
3591 /* Incompatible save files */
3592 if (max_quests_load > max_q_idx)
3594 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3598 for (i = 0; i < max_quests_load; i++)
3602 quest_type* const q_ptr = &quest[i];
3604 rd_s16b(&q_ptr->status);
3606 q_ptr->level = tmp16s;
3608 if (z_older_than(11, 0, 6))
3615 q_ptr->complev = tmp8u;
3617 if(h_older_than(2, 1, 2, 2))
3619 q_ptr->comptime = 0;
3623 rd_u32b(&q_ptr->comptime);
3626 /* Load quest status if quest is running */
3627 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3628 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3629 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3632 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3634 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3635 rd_s16b(&q_ptr->type);
3637 /* Load quest monster index */
3638 rd_s16b(&q_ptr->r_idx);
3640 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3642 determine_random_questor(&quest[i]);
3645 /* Load quest item index */
3646 rd_s16b(&q_ptr->k_idx);
3649 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3652 q_ptr->flags = tmp8u;
3654 if (z_older_than(10, 3, 11))
3656 if (q_ptr->flags & QUEST_FLAG_PRESET)
3662 init_flags = INIT_ASSIGN;
3663 p_ptr->inside_quest = (QUEST_IDX)i;
3665 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3666 p_ptr->inside_quest = old_inside_quest;
3672 q_ptr->dungeon = tmp8u;
3675 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3676 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3677 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3680 /* Ignore the empty quests from old versions */
3683 /* Ignore quest status */
3686 /* Ignore quest level */
3690 * We don't have to care about the other info,
3691 * since status should be 0 for these quests anyway
3696 /* Quest 18 was removed */
3697 if (h_older_than(1, 7, 0, 6))
3699 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3700 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3703 /* Position in the wilderness */
3704 rd_s32b(&p_ptr->wilderness_x);
3705 rd_s32b(&p_ptr->wilderness_y);
3706 if (z_older_than(10, 3, 13))
3708 p_ptr->wilderness_x = 5;
3709 p_ptr->wilderness_y = 48;
3712 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3713 else rd_byte((byte *)&p_ptr->wild_mode);
3714 if (z_older_than(10, 3, 7)) p_ptr->ambush_flag = FALSE;
3715 else rd_byte((byte *)&p_ptr->ambush_flag);
3717 /* Size of the wilderness */
3718 rd_s32b(&wild_x_size);
3719 rd_s32b(&wild_y_size);
3721 /* Incompatible save files */
3722 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3724 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3728 /* Load the wilderness seeds */
3729 for (i = 0; i < wild_x_size; i++)
3731 for (j = 0; j < wild_y_size; j++)
3733 rd_u32b(&wilderness[j][i].seed);
3738 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3740 /* Load the Artifacts */
3743 /* Incompatible save files */
3744 if (tmp16u > max_a_idx)
3746 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3750 /* Read the artifact flags */
3751 for (i = 0; i < tmp16u; i++)
3753 artifact_type *a_ptr = &a_info[i];
3756 a_ptr->cur_num = tmp8u;
3758 if (h_older_than(1, 5, 0, 0))
3760 a_ptr->floor_id = 0;
3768 rd_s16b(&a_ptr->floor_id);
3771 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3773 /* Read the extra stuff */
3775 if (p_ptr->energy_need < -999) p_ptr->timewalk = TRUE;
3777 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3780 /* Read the player_hp array */
3783 /* Incompatible save files */
3784 if (tmp16u > PY_MAX_LEVEL)
3786 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3790 /* Read the player_hp array */
3791 for (i = 0; i < tmp16u; i++)
3794 p_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3797 /* Important -- Initialize the sex */
3798 sp_ptr = &sex_info[p_ptr->psex];
3800 /* Important -- Initialize the race/class */
3801 rp_ptr = &race_info[p_ptr->prace];
3802 cp_ptr = &class_info[p_ptr->pclass];
3803 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3805 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3807 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3808 roll_hitdice(p_ptr, 0L);
3810 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3812 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3813 roll_hitdice(p_ptr, 0L);
3815 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3817 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3818 roll_hitdice(p_ptr, 0L);
3820 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3822 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3823 roll_hitdice(p_ptr, 0L);
3826 /* Important -- Initialize the magic */
3827 mp_ptr = &m_info[p_ptr->pclass];
3830 /* Read spell info */
3831 rd_u32b(&p_ptr->spell_learned1);
3832 rd_u32b(&p_ptr->spell_learned2);
3833 rd_u32b(&p_ptr->spell_worked1);
3834 rd_u32b(&p_ptr->spell_worked2);
3835 rd_u32b(&p_ptr->spell_forgotten1);
3836 rd_u32b(&p_ptr->spell_forgotten2);
3838 if (z_older_than(10,0,5))
3840 p_ptr->learned_spells = 0;
3841 for (i = 0; i < 64; i++)
3843 /* Count known spells */
3845 (p_ptr->spell_learned1 & (1L << i)) :
3846 (p_ptr->spell_learned2 & (1L << (i - 32))))
3848 p_ptr->learned_spells++;
3852 else rd_s16b(&p_ptr->learned_spells);
3854 if (z_older_than(10,0,6))
3856 p_ptr->add_spells = 0;
3858 else rd_s16b(&p_ptr->add_spells);
3859 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3861 for (i = 0; i < 64; i++)
3864 p_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3868 /* Read the p_ptr->inventory_list */
3871 note(_("持ち物情報を読み込むことができません", "Unable to read p_ptr->inventory_list"));
3875 /* Read number of towns */
3877 town_count = tmp16u;
3879 /* Read the stores */
3881 for (i = 1; i < town_count; i++)
3883 for (j = 0; j < tmp16u; j++)
3885 if (rd_store(i, j)) return (22);
3889 rd_s16b(&p_ptr->pet_follow_distance);
3890 if (z_older_than(10, 4, 10))
3892 p_ptr->pet_extra_flags = 0;
3894 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3896 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3898 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3902 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3905 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3909 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3912 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3916 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3919 if (!z_older_than(10,0,8))
3922 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3927 rd_s16b(&p_ptr->pet_extra_flags);
3930 if (!z_older_than(11, 0, 9))
3932 char buf[SCREEN_BUF_MAX_SIZE];
3933 rd_string(buf, sizeof(buf));
3934 if (buf[0]) screen_dump = string_make(buf);
3939 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3941 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3946 /* I'm not dead yet... */
3947 if (!p_ptr->is_dead)
3949 /* Dead players have no dungeon */
3950 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3954 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3958 /* Read the ghost info */
3965 strip_bytes(tmp32s);
3969 /* Quest 18 was removed */
3970 if (h_older_than(1, 7, 0, 6))
3972 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3974 p_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3975 current_floor_ptr->dun_level = 1;
3976 p_ptr->inside_quest = 0;
3981 #ifdef VERIFY_CHECKSUMS
3983 /* Save the checksum */
3984 n_v_check = v_check;
3986 /* Read the old checksum */
3987 rd_u32b(&o_v_check);
3990 if (o_v_check != n_v_check)
3992 note(_("チェックサムがおかしい", "Invalid checksum"));
3997 /* Save the encoded checksum */
3998 n_x_check = x_check;
4000 /* Read the checksum */
4001 rd_u32b(&o_x_check);
4005 if (o_x_check != n_x_check)
4007 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
4018 * @brief ロード処理全体のメイン関数 / Actually read the savefile
4021 errr rd_savefile_new(void)
4025 /* Grab permissions */
4028 /* The savefile is a binary file */
4029 fff = my_fopen(savefile, "rb");
4031 /* Drop permissions */
4033 if (!fff) return (-1);
4035 /* Call the sub-function */
4036 err = rd_savefile_new_aux();
4038 /* Check for errors */
4039 if (ferror(fff)) err = -1;
4046 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
4047 * @param sf_ptr 保存フロア読み込み先
4050 static bool load_floor_aux(saved_floor_type *sf_ptr)
4055 #ifdef VERIFY_CHECKSUMS
4056 u32b n_x_check, n_v_check;
4057 u32b o_x_check, o_v_check;
4060 /* Hack -- decrypt (read xor_byte) */
4064 /* Clear the checksums */
4068 /* Set the version number to current version */
4069 /* Never load old temporal files */
4070 h_ver_extra = H_VER_EXTRA;
4071 h_ver_patch = H_VER_PATCH;
4072 h_ver_minor = H_VER_MINOR;
4073 h_ver_major = H_VER_MAJOR;
4075 /* Verify the sign */
4077 if (saved_floor_file_sign != tmp32u) return FALSE;
4079 /* Read -- have error? */
4080 if (rd_saved_floor(sf_ptr)) return FALSE;
4083 #ifdef VERIFY_CHECKSUMS
4084 /* Save the checksum */
4085 n_v_check = v_check;
4087 /* Read the old checksum */
4088 rd_u32b(&o_v_check);
4091 if (o_v_check != n_v_check) return FALSE;
4093 /* Save the encoded checksum */
4094 n_x_check = x_check;
4096 /* Read the checksum */
4097 rd_u32b(&o_x_check);
4100 if (o_x_check != n_x_check) return FALSE;
4109 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4110 * @param sf_ptr 保存フロア読み込み先
4114 bool load_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
4116 FILE *old_fff = NULL;
4117 byte old_xor_byte = 0;
4118 u32b old_v_check = 0;
4119 u32b old_x_check = 0;
4120 byte old_h_ver_major = 0;
4121 byte old_h_ver_minor = 0;
4122 byte old_h_ver_patch = 0;
4123 byte old_h_ver_extra = 0;
4126 char floor_savefile[1024];
4128 byte old_kanji_code = kanji_code;
4131 * Temporal files are always written in system depended kanji
4136 /* EUC kanji code */
4140 /* SJIS kanji code */
4149 /* We have one file already opened */
4150 if (mode & SLF_SECOND)
4152 /* Backup original values */
4154 old_xor_byte = xor_byte;
4155 old_v_check = v_check;
4156 old_x_check = x_check;
4157 old_h_ver_major = h_ver_major;
4158 old_h_ver_minor = h_ver_minor;
4159 old_h_ver_patch = h_ver_patch;
4160 old_h_ver_extra = h_ver_extra;
4163 /* floor savefile */
4164 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4166 /* Grab permissions */
4169 /* The savefile is a binary file */
4170 fff = my_fopen(floor_savefile, "rb");
4172 /* Drop permissions */
4176 if (!fff) ok = FALSE;
4178 /* Attempt to load */
4181 /* Load saved floor data from file */
4182 ok = load_floor_aux(sf_ptr);
4184 /* Check for errors */
4185 if (ferror(fff)) ok = FALSE;
4188 /* Grab permissions */
4191 /* Delete the file */
4192 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4194 /* Drop permissions */
4198 /* We have one file already opened */
4199 if (mode & SLF_SECOND)
4201 /* Restore original values */
4203 xor_byte = old_xor_byte;
4204 v_check = old_v_check;
4205 x_check = old_x_check;
4206 h_ver_major = old_h_ver_major;
4207 h_ver_minor = old_h_ver_minor;
4208 h_ver_patch = old_h_ver_patch;
4209 h_ver_extra = old_h_ver_extra;
4212 /* Restore old knowledge */
4213 kanji_code = old_kanji_code;