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 (current_world_ptr->h_ver_major < major) return (TRUE);
130 if (current_world_ptr->h_ver_major > major) return (FALSE);
132 /* Distinctly older, or distinctly more recent */
133 if (current_world_ptr->h_ver_minor < minor) return (TRUE);
134 if (current_world_ptr->h_ver_minor > minor) return (FALSE);
136 /* Barely older, or barely more recent */
137 if (current_world_ptr->h_ver_patch < patch) return (TRUE);
138 if (current_world_ptr->h_ver_patch > patch) return (FALSE);
140 /* Barely older, or barely more recent */
141 if (current_world_ptr->h_ver_extra < extra) return (TRUE);
142 if (current_world_ptr->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 (current_world_ptr->z_major < x) return (TRUE);
160 if (current_world_ptr->z_major > x) return (FALSE);
162 /* Distinctly older, or distinctly more recent */
163 if (current_world_ptr->z_minor < y) return (TRUE);
164 if (current_world_ptr->z_minor > y) return (FALSE);
166 /* Barely older, or barely more recent */
167 if (current_world_ptr->z_patch < z) return (TRUE);
168 if (current_world_ptr->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 (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->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 ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->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 if (p_ptr->inventory_list != NULL) C_WIPE(p_ptr->inventory_list, INVEN_TOTAL, object_type);
2430 C_MAKE(p_ptr->inventory_list, INVEN_TOTAL, object_type);
2432 /* Read until done */
2437 /* Get the next item index */
2440 /* Nope, we reached the end */
2441 if (n == 0xFFFF) break;
2448 /* Hack -- verify item */
2449 if (!q_ptr->k_idx) return (53);
2451 /* Wield equipment */
2452 if (n >= INVEN_RARM)
2454 q_ptr->marked |= OM_TOUCHED;
2455 object_copy(&p_ptr->inventory_list[n], q_ptr);
2457 /* Add the weight */
2458 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2464 /* Warning -- backpack is full */
2465 else if (p_ptr->inven_cnt == INVEN_PACK)
2467 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the p_ptr->inventory_list!"));
2473 /* Carry p_ptr->inventory_list */
2479 q_ptr->marked |= OM_TOUCHED;
2480 object_copy(&p_ptr->inventory_list[n], q_ptr);
2482 /* Add the weight */
2483 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2496 * @brief メッセージログを読み込む / Read the saved messages
2499 static void rd_messages(void)
2506 if (h_older_than(2, 2, 0, 75))
2511 message_max = (int)num;
2513 /* Read the messages */
2514 for (i = 0; i < message_max; i++)
2516 /* Read the message */
2517 rd_string(buf, sizeof(buf));
2519 /* Save the message */
2528 message_max = (int)num;
2530 /* Read the messages */
2531 for (i = 0; i < message_max; i++)
2533 /* Read the message */
2534 rd_string(buf, sizeof(buf));
2536 /* Save the message */
2545 /* Old hidden trap flag */
2546 #define CAVE_TRAP 0x8000
2548 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2549 #define OLD_FEAT_INVIS 0x02
2550 #define OLD_FEAT_GLYPH 0x03
2551 #define OLD_FEAT_QUEST_ENTER 0x08
2552 #define OLD_FEAT_QUEST_EXIT 0x09
2553 #define OLD_FEAT_MINOR_GLYPH 0x40
2554 #define OLD_FEAT_BLDG_1 0x81
2555 #define OLD_FEAT_MIRROR 0xc3
2558 #define OLD_QUEST_WATER_CAVE 18
2560 /* Quest constants */
2561 #define QUEST_OLD_CASTLE 27
2562 #define QUEST_ROYAL_CRYPT 28
2565 * @brief メッセージログを読み込む / Read the dungeon (old method)
2568 * The monsters/objects must be loaded in the same order
2569 * that they were stored, since the actual indexes matter.
2571 static errr rd_dungeon_old(void)
2582 /*** Basic info ***/
2586 current_floor_ptr->dun_level = (DEPTH)tmp16s;
2587 if (z_older_than(10, 3, 8)) p_ptr->dungeon_idx = DUNGEON_ANGBAND;
2591 p_ptr->dungeon_idx = (IDX)tmp8u;
2594 /* Set the base level for old versions */
2595 current_floor_ptr->base_level = current_floor_ptr->dun_level;
2598 current_floor_ptr->base_level = (DEPTH)tmp16s;
2601 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2603 p_ptr->y = (POSITION)tmp16s;
2605 p_ptr->x = (POSITION)tmp16s;
2606 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2608 current_floor_ptr->height = (POSITION)tmp16s;
2610 current_floor_ptr->width = (POSITION)tmp16s;
2611 rd_s16b(&tmp16s); /* max_panel_rows */
2612 rd_s16b(&tmp16s); /* max_panel_cols */
2615 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2619 ymax = current_floor_ptr->height;
2620 xmax = current_floor_ptr->width;
2623 /*** Run length decoding ***/
2625 /* Load the dungeon data */
2626 for (x = y = 0; y < ymax; )
2632 if (z_older_than(10,3,6))
2641 /* Decline invalid flags */
2642 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2645 /* Apply the RLE info */
2646 for (i = count; i > 0; i--)
2648 /* Access the current_floor_ptr->grid_array */
2649 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2651 /* Extract "info" */
2661 if (++y >= ymax) break;
2667 /*** Run length decoding ***/
2669 /* Load the dungeon data */
2670 for (x = y = 0; y < ymax; )
2676 /* Apply the RLE info */
2677 for (i = count; i > 0; i--)
2679 /* Access the current_floor_ptr->grid_array */
2680 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2682 /* Extract "feat" */
2683 g_ptr->feat = (s16b)tmp8u;
2692 if (++y >= ymax) break;
2697 /*** Run length decoding ***/
2699 /* Load the dungeon data */
2700 for (x = y = 0; y < ymax; )
2706 /* Apply the RLE info */
2707 for (i = count; i > 0; i--)
2709 /* Access the current_floor_ptr->grid_array */
2710 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2712 /* Extract "mimic" */
2713 g_ptr->mimic = (s16b)tmp8u;
2722 if (++y >= ymax) break;
2727 /*** Run length decoding ***/
2729 /* Load the dungeon data */
2730 for (x = y = 0; y < ymax; )
2736 /* Apply the RLE info */
2737 for (i = count; i > 0; i--)
2739 /* Access the current_floor_ptr->grid_array */
2740 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2742 /* Extract "feat" */
2743 g_ptr->special = tmp16s;
2752 if (++y >= ymax) break;
2757 /* Convert current_floor_ptr->grid_array data */
2758 if (z_older_than(11, 0, 99))
2760 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2762 /* Wipe old unused flags */
2763 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2767 if (h_older_than(1, 1, 1, 0))
2769 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2771 /* Access the current_floor_ptr->grid_array */
2772 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2775 if (g_ptr->feat == OLD_FEAT_INVIS)
2777 g_ptr->feat = feat_floor;
2778 g_ptr->info |= CAVE_TRAP;
2781 /* Older than 1.1.1 */
2782 if (g_ptr->feat == OLD_FEAT_MIRROR)
2784 g_ptr->feat = feat_floor;
2785 g_ptr->info |= CAVE_OBJECT;
2790 if (h_older_than(1, 3, 1, 0))
2792 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2794 /* Access the current_floor_ptr->grid_array */
2795 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2797 /* Old CAVE_IN_MIRROR flag */
2798 if (g_ptr->info & CAVE_OBJECT)
2800 g_ptr->mimic = feat_mirror;
2803 /* Runes will be mimics and flags */
2804 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2805 (g_ptr->feat == OLD_FEAT_GLYPH))
2807 g_ptr->info |= CAVE_OBJECT;
2808 g_ptr->mimic = g_ptr->feat;
2809 g_ptr->feat = feat_floor;
2812 /* Hidden traps will be trap terrains mimicing floor */
2813 else if (g_ptr->info & CAVE_TRAP)
2815 g_ptr->info &= ~CAVE_TRAP;
2816 g_ptr->mimic = g_ptr->feat;
2817 g_ptr->feat = choose_random_trap();
2820 /* Another hidden trap */
2821 else if (g_ptr->feat == OLD_FEAT_INVIS)
2823 g_ptr->mimic = feat_floor;
2824 g_ptr->feat = feat_trap_open;
2829 /* Quest 18 was removed */
2830 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2832 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2834 /* Access the current_floor_ptr->grid_array */
2835 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2837 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
2839 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2841 g_ptr->feat = feat_tree;
2844 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2846 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2849 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2850 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2852 g_ptr->feat = feat_up_stair;
2860 /* Read the item count */
2863 /* Verify maximum */
2864 if (limit > current_floor_ptr->max_o_idx)
2866 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2870 /* Read the dungeon items */
2871 for (i = 1; i < limit; i++)
2878 /* Get a new record */
2883 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2889 o_ptr = ¤t_floor_ptr->o_list[o_idx];
2897 if (o_ptr->held_m_idx)
2899 monster_type *m_ptr;
2900 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
2903 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2905 m_ptr->hold_o_idx = o_idx;
2911 /* Access the item location */
2912 g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2915 o_ptr->next_o_idx = g_ptr->o_idx;
2917 g_ptr->o_idx = o_idx;
2924 /* Read the monster count */
2927 /* Hack -- verify */
2928 if (limit > current_floor_ptr->max_m_idx)
2930 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2934 /* Read the monsters */
2935 for (i = 1; i < limit; i++)
2938 monster_type *m_ptr;
2940 /* Get a new record */
2945 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2950 /* Acquire monster */
2951 m_ptr = ¤t_floor_ptr->m_list[m_idx];
2953 /* Read the monster */
2958 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2960 /* Mark the location */
2961 g_ptr->m_idx = m_idx;
2964 real_r_ptr(m_ptr)->cur_num++;
2969 /* The dungeon is ready */
2970 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena)
2971 character_dungeon = FALSE;
2973 character_dungeon = TRUE;
2981 * @brief 保存されたフロアを読み込む / Read the saved floor
2982 * @return info読み込みエラーコード
2984 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2987 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2988 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2990 * The monsters/objects must be loaded in the same order
2991 * that they were stored, since the actual indexes matter.
2993 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2995 POSITION ymax, xmax;
3006 grid_template_type *templates;
3009 /*** Wipe all current_floor_ptr->grid_array ***/
3013 /*** Basic info ***/
3015 /* Dungeon floor specific info follows */
3019 /*** Not a saved floor ***/
3022 current_floor_ptr->dun_level = (DEPTH)tmp16s;
3023 current_floor_ptr->base_level = current_floor_ptr->dun_level;
3027 /*** The saved floor ***/
3030 if (tmp16s != sf_ptr->floor_id) return 171;
3033 if (tmp8u != sf_ptr->savefile_id) return 171;
3036 if (tmp16s != sf_ptr->dun_level) return 171;
3037 current_floor_ptr->dun_level = sf_ptr->dun_level;
3040 if (tmp32s != sf_ptr->last_visit) return 171;
3043 if (tmp32u != sf_ptr->visit_mark) return 171;
3046 if (tmp16s != sf_ptr->upper_floor_id) return 171;
3049 if (tmp16s != sf_ptr->lower_floor_id) return 171;
3053 current_floor_ptr->base_level = (DEPTH)tmp16s;
3055 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
3058 p_ptr->y = (POSITION)tmp16u;
3061 p_ptr->x = (POSITION)tmp16u;
3064 current_floor_ptr->height = (POSITION)tmp16s;
3066 current_floor_ptr->width = (POSITION)tmp16s;
3068 rd_byte(&p_ptr->feeling);
3072 /*** Read template for grid_type ***/
3074 /* Read the template count */
3077 /* Allocate the "template" array */
3078 C_MAKE(templates, limit, grid_template_type);
3080 /* Read the templates */
3081 for (i = 0; i < limit; i++)
3083 grid_template_type *ct_ptr = &templates[i];
3087 ct_ptr->info = (BIT_FLAGS)tmp16u;
3088 if (h_older_than(1, 7, 0, 2))
3091 ct_ptr->feat = (s16b)tmp8u;
3093 ct_ptr->mimic = (s16b)tmp8u;
3097 rd_s16b(&ct_ptr->feat);
3098 rd_s16b(&ct_ptr->mimic);
3100 rd_s16b(&ct_ptr->special);
3104 ymax = current_floor_ptr->height;
3105 xmax = current_floor_ptr->width;
3108 /*** Run length decoding ***/
3110 /* Load the dungeon data */
3111 for (x = y = 0; y < ymax; )
3123 } while (tmp8u == MAX_UCHAR);
3125 /* Apply the RLE info */
3126 for (i = count; i > 0; i--)
3128 /* Access the current_floor_ptr->grid_array */
3129 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3131 /* Extract current_floor_ptr->grid_array data */
3132 g_ptr->info = templates[id].info;
3133 g_ptr->feat = templates[id].feat;
3134 g_ptr->mimic = templates[id].mimic;
3135 g_ptr->special = templates[id].special;
3144 if (++y >= ymax) break;
3149 /* Quest 18 was removed */
3150 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3152 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3154 /* Access the current_floor_ptr->grid_array */
3155 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3157 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
3159 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
3161 g_ptr->feat = feat_tree;
3164 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
3166 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3169 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3170 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3172 g_ptr->feat = feat_up_stair;
3178 /* Free the "template" array */
3179 C_KILL(templates, limit, grid_template_type);
3184 /* Read the item count */
3187 /* Verify maximum */
3188 if (limit > current_floor_ptr->max_o_idx) return 151;
3191 /* Read the dungeon items */
3192 for (i = 1; i < limit; i++)
3198 /* Get a new record */
3201 if (i != o_idx) return 152;
3204 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3209 if (o_ptr->held_m_idx)
3211 monster_type *m_ptr;
3212 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
3215 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3217 m_ptr->hold_o_idx = o_idx;
3223 /* Access the item location */
3224 grid_type *g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
3227 o_ptr->next_o_idx = g_ptr->o_idx;
3229 g_ptr->o_idx = o_idx;
3236 /* Read the monster count */
3239 /* Hack -- verify */
3240 if (limit > current_floor_ptr->max_m_idx) return 161;
3242 /* Read the monsters */
3243 for (i = 1; i < limit; i++)
3247 monster_type *m_ptr;
3249 /* Get a new record */
3252 if (i != m_idx) return 162;
3255 /* Acquire monster */
3256 m_ptr = ¤t_floor_ptr->m_list[m_idx];
3258 /* Read the monster */
3263 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
3265 /* Mark the location */
3266 g_ptr->m_idx = m_idx;
3269 real_r_ptr(m_ptr)->cur_num++;
3278 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3281 * The monsters/objects must be loaded in the same order
3282 * that they were stored, since the actual indexes matter.
3284 static errr rd_dungeon(void)
3292 /* Initialize saved_floors array and temporal files */
3293 init_saved_floors(FALSE);
3296 if (h_older_than(1, 5, 0, 0))
3298 err = rd_dungeon_old();
3300 /* Prepare floor_id of current floor */
3301 if (p_ptr->dungeon_idx)
3303 p_ptr->floor_id = get_new_floor_id();
3304 get_sf_ptr(p_ptr->floor_id)->dun_level = current_floor_ptr->dun_level;
3313 /* Number of floor_id used from birth */
3314 rd_s16b(&max_floor_id);
3316 /* Current dungeon type */
3318 p_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
3320 /* Number of the saved_floors array elements */
3323 /*** No saved floor (On the surface etc.) ***/
3326 /* Read the current floor data */
3327 err = rd_saved_floor(NULL);
3330 /*** In the dungeon ***/
3334 /* Read the saved_floors array */
3335 for (i = 0; i < num; i++)
3337 saved_floor_type *sf_ptr = &saved_floors[i];
3339 rd_s16b(&sf_ptr->floor_id);
3341 sf_ptr->savefile_id = (s16b)tmp8u;
3344 sf_ptr->dun_level = (DEPTH)tmp16s;
3346 rd_s32b(&sf_ptr->last_visit);
3347 rd_u32b(&sf_ptr->visit_mark);
3348 rd_s16b(&sf_ptr->upper_floor_id);
3349 rd_s16b(&sf_ptr->lower_floor_id);
3353 /* Move saved floors data to temporal files */
3354 for (i = 0; i < num; i++)
3356 saved_floor_type *sf_ptr = &saved_floors[i];
3358 /* Unused element */
3359 if (!sf_ptr->floor_id) continue;
3361 /* Read the failure mark */
3363 if (tmp8u) continue;
3365 /* Read from the save file */
3366 err = rd_saved_floor(sf_ptr);
3371 /* Re-save as temporal saved floor file */
3372 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3378 /* Finally load current floor data from temporal file */
3381 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3386 /*** Error messages ***/
3390 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3394 note(_("アイテム配置エラー", "Object allocation error"));
3398 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3402 note(_("モンスター配置エラー", "Monster allocation error"));
3406 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3410 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3414 note(_("Error 183", "Error 183"));
3418 /* The dungeon is ready */
3419 character_dungeon = TRUE;
3421 /* Success or Error */
3427 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3430 static errr rd_savefile_new_aux(void)
3443 #ifdef VERIFY_CHECKSUMS
3444 u32b n_x_check, n_v_check;
3445 u32b o_x_check, o_v_check;
3449 /* Strip the version bytes */
3452 /* Hack -- decrypt */
3453 xor_byte = current_world_ptr->sf_extra;
3456 /* Clear the checksums */
3460 /* Read the version number of the savefile */
3461 /* Old savefile will be version 0.0.0.3 */
3462 rd_byte(¤t_world_ptr->h_ver_extra);
3463 rd_byte(¤t_world_ptr->h_ver_patch);
3464 rd_byte(¤t_world_ptr->h_ver_minor);
3465 rd_byte(¤t_world_ptr->h_ver_major);
3467 /* Mention the savefile version */
3469 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3470 (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));
3473 /* Operating system info */
3474 rd_u32b(¤t_world_ptr->sf_system);
3476 /* Time of savefile creation */
3477 rd_u32b(¤t_world_ptr->sf_when);
3479 /* Number of resurrections */
3480 rd_u16b(¤t_world_ptr->sf_lives);
3482 /* Number of times played */
3483 rd_u16b(¤t_world_ptr->sf_saves);
3486 /* Later use (always zero) */
3489 /* Later use (always zero) */
3492 /* Later use (always zero) */
3496 rd_byte(&kanji_code);
3498 /* Read RNG state */
3500 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3502 /* Then the options */
3504 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3506 /* Then the "messages" */
3508 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3510 for (i = 0; i < max_r_idx; i++)
3512 /* Access that monster */
3513 monster_race *r_ptr = &r_info[i];
3515 /* Hack -- Reset the death counter */
3516 r_ptr->max_num = 100;
3518 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3520 /* Hack -- Non-unique Nazguls are semi-unique */
3521 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3524 /* Monster Memory */
3527 /* Incompatible save files */
3528 if (tmp16u > max_r_idx)
3530 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3534 /* Read the available records */
3535 for (i = 0; i < tmp16u; i++)
3538 rd_lore((MONRACE_IDX)i);
3541 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3546 /* Incompatible save files */
3547 if (tmp16u > max_k_idx)
3549 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3553 /* Read the object memory */
3554 for (i = 0; i < tmp16u; i++)
3556 object_kind *k_ptr = &k_info[i];
3560 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3561 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3563 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3565 /* 2.1.3 or newer version */
3567 u16b max_towns_load;
3568 u16b max_quests_load;
3569 byte max_rquests_load;
3570 s16b old_inside_quest = p_ptr->inside_quest;
3572 /* Number of towns */
3573 rd_u16b(&max_towns_load);
3575 /* Incompatible save files */
3576 if (max_towns_load > max_towns)
3578 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3582 /* Number of quests */
3583 rd_u16b(&max_quests_load);
3585 if (z_older_than(11, 0, 7))
3587 max_rquests_load = 10;
3591 rd_byte(&max_rquests_load);
3594 /* Incompatible save files */
3595 if (max_quests_load > max_q_idx)
3597 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3601 for (i = 0; i < max_quests_load; i++)
3605 quest_type* const q_ptr = &quest[i];
3607 rd_s16b(&q_ptr->status);
3609 q_ptr->level = tmp16s;
3611 if (z_older_than(11, 0, 6))
3618 q_ptr->complev = tmp8u;
3620 if(h_older_than(2, 1, 2, 2))
3622 q_ptr->comptime = 0;
3626 rd_u32b(&q_ptr->comptime);
3629 /* Load quest status if quest is running */
3630 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3631 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3632 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3635 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3637 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3638 rd_s16b(&q_ptr->type);
3640 /* Load quest monster index */
3641 rd_s16b(&q_ptr->r_idx);
3643 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3645 determine_random_questor(&quest[i]);
3648 /* Load quest item index */
3649 rd_s16b(&q_ptr->k_idx);
3652 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3655 q_ptr->flags = tmp8u;
3657 if (z_older_than(10, 3, 11))
3659 if (q_ptr->flags & QUEST_FLAG_PRESET)
3665 init_flags = INIT_ASSIGN;
3666 p_ptr->inside_quest = (QUEST_IDX)i;
3668 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3669 p_ptr->inside_quest = old_inside_quest;
3675 q_ptr->dungeon = tmp8u;
3678 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3679 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3680 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3683 /* Ignore the empty quests from old versions */
3686 /* Ignore quest status */
3689 /* Ignore quest level */
3693 * We don't have to care about the other info,
3694 * since status should be 0 for these quests anyway
3699 /* Quest 18 was removed */
3700 if (h_older_than(1, 7, 0, 6))
3702 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3703 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3706 /* Position in the wilderness */
3707 rd_s32b(&p_ptr->wilderness_x);
3708 rd_s32b(&p_ptr->wilderness_y);
3709 if (z_older_than(10, 3, 13))
3711 p_ptr->wilderness_x = 5;
3712 p_ptr->wilderness_y = 48;
3715 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3716 else rd_byte((byte *)&p_ptr->wild_mode);
3717 if (z_older_than(10, 3, 7)) p_ptr->ambush_flag = FALSE;
3718 else rd_byte((byte *)&p_ptr->ambush_flag);
3720 /* Size of the wilderness */
3721 rd_s32b(&wild_x_size);
3722 rd_s32b(&wild_y_size);
3724 /* Incompatible save files */
3725 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3727 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3731 /* Load the wilderness seeds */
3732 for (i = 0; i < wild_x_size; i++)
3734 for (j = 0; j < wild_y_size; j++)
3736 rd_u32b(&wilderness[j][i].seed);
3741 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3743 /* Load the Artifacts */
3746 /* Incompatible save files */
3747 if (tmp16u > max_a_idx)
3749 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3753 /* Read the artifact flags */
3754 for (i = 0; i < tmp16u; i++)
3756 artifact_type *a_ptr = &a_info[i];
3759 a_ptr->cur_num = tmp8u;
3761 if (h_older_than(1, 5, 0, 0))
3763 a_ptr->floor_id = 0;
3771 rd_s16b(&a_ptr->floor_id);
3774 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3776 /* Read the extra stuff */
3778 if (p_ptr->energy_need < -999) p_ptr->timewalk = TRUE;
3780 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3783 /* Read the player_hp array */
3786 /* Incompatible save files */
3787 if (tmp16u > PY_MAX_LEVEL)
3789 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3793 /* Read the player_hp array */
3794 for (i = 0; i < tmp16u; i++)
3797 p_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3800 /* Important -- Initialize the sex */
3801 sp_ptr = &sex_info[p_ptr->psex];
3803 /* Important -- Initialize the race/class */
3804 rp_ptr = &race_info[p_ptr->prace];
3805 cp_ptr = &class_info[p_ptr->pclass];
3806 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3808 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3810 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3811 roll_hitdice(p_ptr, 0L);
3813 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3815 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3816 roll_hitdice(p_ptr, 0L);
3818 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3820 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3821 roll_hitdice(p_ptr, 0L);
3823 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3825 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3826 roll_hitdice(p_ptr, 0L);
3829 /* Important -- Initialize the magic */
3830 mp_ptr = &m_info[p_ptr->pclass];
3833 /* Read spell info */
3834 rd_u32b(&p_ptr->spell_learned1);
3835 rd_u32b(&p_ptr->spell_learned2);
3836 rd_u32b(&p_ptr->spell_worked1);
3837 rd_u32b(&p_ptr->spell_worked2);
3838 rd_u32b(&p_ptr->spell_forgotten1);
3839 rd_u32b(&p_ptr->spell_forgotten2);
3841 if (z_older_than(10,0,5))
3843 p_ptr->learned_spells = 0;
3844 for (i = 0; i < 64; i++)
3846 /* Count known spells */
3848 (p_ptr->spell_learned1 & (1L << i)) :
3849 (p_ptr->spell_learned2 & (1L << (i - 32))))
3851 p_ptr->learned_spells++;
3855 else rd_s16b(&p_ptr->learned_spells);
3857 if (z_older_than(10,0,6))
3859 p_ptr->add_spells = 0;
3861 else rd_s16b(&p_ptr->add_spells);
3862 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3864 for (i = 0; i < 64; i++)
3867 p_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3871 /* Read the p_ptr->inventory_list */
3874 note(_("持ち物情報を読み込むことができません", "Unable to read p_ptr->inventory_list"));
3878 /* Read number of towns */
3880 town_count = tmp16u;
3882 /* Read the stores */
3884 for (i = 1; i < town_count; i++)
3886 for (j = 0; j < tmp16u; j++)
3888 if (rd_store(i, j)) return (22);
3892 rd_s16b(&p_ptr->pet_follow_distance);
3893 if (z_older_than(10, 4, 10))
3895 p_ptr->pet_extra_flags = 0;
3897 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3899 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3901 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3905 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3908 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3912 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3915 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3919 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3922 if (!z_older_than(10,0,8))
3925 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3930 rd_s16b(&p_ptr->pet_extra_flags);
3933 if (!z_older_than(11, 0, 9))
3935 char buf[SCREEN_BUF_MAX_SIZE];
3936 rd_string(buf, sizeof(buf));
3937 if (buf[0]) screen_dump = string_make(buf);
3942 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3944 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3949 /* I'm not dead yet... */
3950 if (!p_ptr->is_dead)
3952 /* Dead players have no dungeon */
3953 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3957 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3961 /* Read the ghost info */
3968 strip_bytes(tmp32s);
3972 /* Quest 18 was removed */
3973 if (h_older_than(1, 7, 0, 6))
3975 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3977 p_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3978 current_floor_ptr->dun_level = 1;
3979 p_ptr->inside_quest = 0;
3984 #ifdef VERIFY_CHECKSUMS
3986 /* Save the checksum */
3987 n_v_check = v_check;
3989 /* Read the old checksum */
3990 rd_u32b(&o_v_check);
3993 if (o_v_check != n_v_check)
3995 note(_("チェックサムがおかしい", "Invalid checksum"));
4000 /* Save the encoded checksum */
4001 n_x_check = x_check;
4003 /* Read the checksum */
4004 rd_u32b(&o_x_check);
4008 if (o_x_check != n_x_check)
4010 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
4021 * @brief ロード処理全体のメイン関数 / Actually read the savefile
4024 errr rd_savefile_new(void)
4028 /* Grab permissions */
4031 /* The savefile is a binary file */
4032 fff = my_fopen(savefile, "rb");
4034 /* Drop permissions */
4036 if (!fff) return (-1);
4038 /* Call the sub-function */
4039 err = rd_savefile_new_aux();
4041 /* Check for errors */
4042 if (ferror(fff)) err = -1;
4049 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
4050 * @param sf_ptr 保存フロア読み込み先
4053 static bool load_floor_aux(saved_floor_type *sf_ptr)
4058 #ifdef VERIFY_CHECKSUMS
4059 u32b n_x_check, n_v_check;
4060 u32b o_x_check, o_v_check;
4063 /* Hack -- decrypt (read xor_byte) */
4067 /* Clear the checksums */
4071 /* Set the version number to current version */
4072 /* Never load old temporal files */
4073 current_world_ptr->h_ver_extra = H_VER_EXTRA;
4074 current_world_ptr->h_ver_patch = H_VER_PATCH;
4075 current_world_ptr->h_ver_minor = H_VER_MINOR;
4076 current_world_ptr->h_ver_major = H_VER_MAJOR;
4078 /* Verify the sign */
4080 if (saved_floor_file_sign != tmp32u) return FALSE;
4082 /* Read -- have error? */
4083 if (rd_saved_floor(sf_ptr)) return FALSE;
4086 #ifdef VERIFY_CHECKSUMS
4087 /* Save the checksum */
4088 n_v_check = v_check;
4090 /* Read the old checksum */
4091 rd_u32b(&o_v_check);
4094 if (o_v_check != n_v_check) return FALSE;
4096 /* Save the encoded checksum */
4097 n_x_check = x_check;
4099 /* Read the checksum */
4100 rd_u32b(&o_x_check);
4103 if (o_x_check != n_x_check) return FALSE;
4112 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4113 * @param sf_ptr 保存フロア読み込み先
4117 bool load_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
4119 FILE *old_fff = NULL;
4120 byte old_xor_byte = 0;
4121 u32b old_v_check = 0;
4122 u32b old_x_check = 0;
4123 byte old_h_ver_major = 0;
4124 byte old_h_ver_minor = 0;
4125 byte old_h_ver_patch = 0;
4126 byte old_h_ver_extra = 0;
4129 char floor_savefile[1024];
4131 byte old_kanji_code = kanji_code;
4134 * Temporal files are always written in system depended kanji
4139 /* EUC kanji code */
4143 /* SJIS kanji code */
4152 /* We have one file already opened */
4153 if (mode & SLF_SECOND)
4155 /* Backup original values */
4157 old_xor_byte = xor_byte;
4158 old_v_check = v_check;
4159 old_x_check = x_check;
4160 old_h_ver_major = current_world_ptr->h_ver_major;
4161 old_h_ver_minor = current_world_ptr->h_ver_minor;
4162 old_h_ver_patch = current_world_ptr->h_ver_patch;
4163 old_h_ver_extra = current_world_ptr->h_ver_extra;
4166 /* floor savefile */
4167 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4169 /* Grab permissions */
4172 /* The savefile is a binary file */
4173 fff = my_fopen(floor_savefile, "rb");
4175 /* Drop permissions */
4179 if (!fff) ok = FALSE;
4181 /* Attempt to load */
4184 /* Load saved floor data from file */
4185 ok = load_floor_aux(sf_ptr);
4187 /* Check for errors */
4188 if (ferror(fff)) ok = FALSE;
4191 /* Grab permissions */
4194 /* Delete the file */
4195 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4197 /* Drop permissions */
4201 /* We have one file already opened */
4202 if (mode & SLF_SECOND)
4204 /* Restore original values */
4206 xor_byte = old_xor_byte;
4207 v_check = old_v_check;
4208 x_check = old_x_check;
4209 current_world_ptr->h_ver_major = old_h_ver_major;
4210 current_world_ptr->h_ver_minor = old_h_ver_minor;
4211 current_world_ptr->h_ver_patch = old_h_ver_patch;
4212 current_world_ptr->h_ver_extra = old_h_ver_extra;
4215 /* Restore old knowledge */
4216 kanji_code = old_kanji_code;