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.
52 #include "spells-status.h"
53 #include "object-hook.h"
57 #include "floor-save.h"
62 #include "dungeon-file.h"
67 * Maximum number of tries for selection of a proper quest monster
73 * Local "savefile" pointer
78 * Hack -- old "encryption" byte
83 * Hack -- simple "checksum" on the actual values
85 static u32b v_check = 0L;
88 * Hack -- simple "checksum" on the encoded bytes
90 static u32b x_check = 0L;
93 * Hack -- Japanese Kanji code
99 static byte kanji_code = 0;
102 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
103 * @param major メジャーバージョン値
104 * @param minor マイナーバージョン値
105 * @param patch パッチバージョン値
106 * @param extra エクストラパージョン値
107 * @return 現在のバージョンより値が古いならtrue
109 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
111 /* Much older, or much more recent */
112 if (h_ver_major < major) return (TRUE);
113 if (h_ver_major > major) return (FALSE);
115 /* Distinctly older, or distinctly more recent */
116 if (h_ver_minor < minor) return (TRUE);
117 if (h_ver_minor > minor) return (FALSE);
119 /* Barely older, or barely more recent */
120 if (h_ver_patch < patch) return (TRUE);
121 if (h_ver_patch > patch) return (FALSE);
123 /* Barely older, or barely more recent */
124 if (h_ver_extra < extra) return (TRUE);
125 if (h_ver_extra > extra) return (FALSE);
127 /* Identical versions */
133 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
134 * @param x メジャーバージョン値
135 * @param y マイナーバージョン値
137 * @return 現在のバージョンより値が古いならtrue
139 static bool z_older_than(byte x, byte y, byte z)
141 /* Much older, or much more recent */
142 if (z_major < x) return (TRUE);
143 if (z_major > x) return (FALSE);
145 /* Distinctly older, or distinctly more recent */
146 if (z_minor < y) return (TRUE);
147 if (z_minor > y) return (FALSE);
149 /* Barely older, or barely more recent */
150 if (z_patch < z) return (TRUE);
151 if (z_patch > z) return (FALSE);
153 /* Identical versions */
159 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
163 * Avoid the top two lines, to avoid interference with "msg_print()".
165 static void note(concptr msg)
167 static TERM_LEN y = 2;
169 /* Draw the message */
172 /* Advance one line (wrap if needed) */
173 if (++y >= 24) y = 2;
181 * @brief ロードファイルポインタから1バイトを読み込む
184 * The following functions are used to load the basic building blocks
185 * of savefiles. They also maintain the "checksum" info for 2.7.0+
187 static byte sf_get(void)
191 /* Get a character, decode the value */
192 c = getc(fff) & 0xFF;
196 /* Maintain the checksum info */
200 /* Return the value */
205 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
209 static void rd_byte(byte *ip)
215 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
219 static void rd_u16b(u16b *ip)
222 (*ip) |= ((u16b)(sf_get()) << 8);
226 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
230 static void rd_s16b(s16b *ip)
236 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
240 static void rd_u32b(u32b *ip)
243 (*ip) |= ((u32b)(sf_get()) << 8);
244 (*ip) |= ((u32b)(sf_get()) << 16);
245 (*ip) |= ((u32b)(sf_get()) << 24);
249 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
253 static void rd_s32b(s32b *ip)
260 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
261 * @param str 読み込みポインタ
262 * @param max 最大読み取りバイト数
265 static void rd_string(char *str, int max)
269 /* Read the string */
270 for (i = 0; TRUE; i++)
277 /* Collect string while legal */
278 if (i < max) str[i] = tmp8u;
289 /* Convert Kanji code */
308 /* 不明の漢字コードからシステムの漢字コードに変換 */
309 byte code = codeconv(str);
311 /* 漢字コードが判明したら、それを記録 */
312 if (code) kanji_code = code;
317 /* No conversion needed */
325 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
329 static void strip_bytes(int n)
333 /* Strip the bytes */
334 while (n--) rd_byte(&tmp8u);
337 #define OLD_MAX_MANE 22
340 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
341 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
344 * This function attempts to "repair" old savefiles, and to extract
345 * the most up to date values for various object fields.
347 * Note that Angband 2.7.9 introduced a new method for object "flags"
348 * in which the "flags" on an object are actually extracted when they
349 * are needed from the object kind, artifact index, ego-item index,
350 * and two special "xtra" fields which are used to encode any "extra"
351 * power of certain ego-items. This had the side effect that items
352 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
353 * may have had, and also, all "uncursed" items will become "cursed"
354 * again, including Calris, even if it is being worn at the time. As
355 * a complete hack, items which are inscribed with "uncursed" will be
356 * "uncursed" when imported from pre-2.7.9 savefiles.
358 static void rd_item_old(object_type *o_ptr)
366 rd_s16b(&o_ptr->k_idx);
369 o_ptr->iy = (POSITION)tmp8u;
371 o_ptr->ix = (POSITION)tmp8u;
379 if (z_older_than(10, 4, 4))
381 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
382 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
383 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
387 rd_s16b(&o_ptr->pval);
389 rd_byte(&o_ptr->discount);
391 o_ptr->number = (ITEM_NUMBER)tmp8u;
394 o_ptr->weight = tmp16s;
397 o_ptr->name1 = tmp8u;
400 o_ptr->name2 = tmp8u;
402 rd_s16b(&o_ptr->timeout);
404 rd_s16b(&o_ptr->to_h);
407 o_ptr->to_d = tmp16s;
408 rd_s16b(&o_ptr->to_a);
417 rd_byte(&o_ptr->ident);
419 rd_byte(&o_ptr->marked);
422 rd_u32b(&o_ptr->art_flags[0]);
423 rd_u32b(&o_ptr->art_flags[1]);
424 rd_u32b(&o_ptr->art_flags[2]);
425 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
426 else rd_u32b(&o_ptr->art_flags[3]);
428 if (h_older_than(1, 3, 0, 0))
430 if (o_ptr->name2 == EGO_TELEPATHY)
431 add_flag(o_ptr->art_flags, TR_TELEPATHY);
434 if (z_older_than(11, 0, 11))
436 o_ptr->curse_flags = 0L;
437 if (o_ptr->ident & 0x40)
439 o_ptr->curse_flags |= TRC_CURSED;
440 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
441 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
442 if (object_is_fixed_artifact(o_ptr))
444 artifact_type *a_ptr = &a_info[o_ptr->name1];
445 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
446 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
448 else if (object_is_ego(o_ptr))
450 ego_item_type *e_ptr = &e_info[o_ptr->name2];
451 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
452 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
455 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
459 rd_u32b(&o_ptr->curse_flags);
462 /* Monster holding object */
463 rd_s16b(&o_ptr->held_m_idx);
466 rd_byte(&o_ptr->xtra1);
467 rd_byte(&o_ptr->xtra2);
469 if (z_older_than(11, 0, 10))
471 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
473 switch (o_ptr->xtra2 % 6)
475 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
476 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
477 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
478 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
479 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
480 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
484 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
486 switch (o_ptr->xtra2 % 11)
488 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
489 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
490 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
491 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
492 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
493 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
494 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
495 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
496 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
497 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
498 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
502 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
504 switch (o_ptr->xtra2 % 8)
506 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
507 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
508 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
509 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
510 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
511 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
512 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
513 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
520 if (z_older_than(10, 2, 3))
525 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
527 o_ptr->xtra3 = o_ptr->xtra1;
530 if (o_ptr->tval == TV_CAPTURE)
532 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
533 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
535 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
536 if (ironman_nightmare)
538 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
540 o_ptr->xtra4 = o_ptr->xtra5;
545 rd_byte(&o_ptr->xtra3);
546 if (h_older_than(1, 3, 0, 1))
548 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
549 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
552 rd_s16b(&o_ptr->xtra4);
553 rd_s16b(&o_ptr->xtra5);
556 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)))
558 o_ptr->xtra4 = o_ptr->pval;
562 rd_byte(&o_ptr->feeling);
565 rd_string(buf, sizeof(buf));
567 /* Save the inscription */
568 if (buf[0]) o_ptr->inscription = quark_add(buf);
570 rd_string(buf, sizeof(buf));
571 if (buf[0]) o_ptr->art_name = quark_add(buf);
573 /* The Python object */
581 /* Mega-Hack -- handle "dungeon objects" later */
582 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
584 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
586 if (z_older_than(10, 4, 9))
588 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
590 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
591 add_flag(o_ptr->art_flags, TR_DEC_MANA);
594 if (object_is_fixed_artifact(o_ptr))
596 artifact_type *a_ptr;
598 /* Obtain the artifact info */
599 a_ptr = &a_info[o_ptr->name1];
601 /* Verify that artifact */
602 if (!a_ptr->name) o_ptr->name1 = 0;
604 if (object_is_ego(o_ptr))
606 ego_item_type *e_ptr;
608 /* Obtain the ego-item info */
609 e_ptr = &e_info[o_ptr->name2];
611 /* Verify that ego-item */
612 if (!e_ptr->name) o_ptr->name2 = 0;
619 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
620 * @param o_ptr アイテムオブジェクト保存先ポインタ
623 static void rd_item(object_type *o_ptr)
631 if (h_older_than(1, 5, 0, 0))
637 /*** Item save flags ***/
640 /*** Read un-obvious elements ***/
642 rd_s16b(&o_ptr->k_idx);
645 o_ptr->iy = (POSITION)tmp8u;
647 o_ptr->ix = (POSITION)tmp8u;
650 k_ptr = &k_info[o_ptr->k_idx];
651 o_ptr->tval = k_ptr->tval;
652 o_ptr->sval = k_ptr->sval;
655 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
656 else o_ptr->pval = 0;
658 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
659 else o_ptr->discount = 0;
660 if (flags & SAVE_ITEM_NUMBER) {
662 o_ptr->number = tmp8u;
664 else o_ptr->number = 1;
667 o_ptr->weight = tmp16s;
669 if (flags & SAVE_ITEM_NAME1)
672 o_ptr->name1 = tmp8u;
674 else o_ptr->name1 = 0;
675 if (flags & SAVE_ITEM_NAME2)
678 o_ptr->name2 = tmp8u;
680 else o_ptr->name2 = 0;
681 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
682 else o_ptr->timeout = 0;
684 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
685 else o_ptr->to_h = 0;
686 if (flags & SAVE_ITEM_TO_D)
689 o_ptr->to_d = tmp16s;
691 else o_ptr->to_d = 0;
692 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
693 else o_ptr->to_a = 0;
695 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
698 if (flags & SAVE_ITEM_DD)
704 if (flags & SAVE_ITEM_DS)
711 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
712 else o_ptr->ident = 0;
714 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
715 else o_ptr->marked = 0;
718 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
719 else o_ptr->art_flags[0] = 0;
720 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
721 else o_ptr->art_flags[1] = 0;
722 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
723 else o_ptr->art_flags[2] = 0;
724 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
725 else o_ptr->art_flags[3] = 0;
726 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
727 else o_ptr->art_flags[4] = 0;
729 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
730 else o_ptr->curse_flags = 0;
732 /* Monster holding object */
733 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
734 else o_ptr->held_m_idx = 0;
737 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
738 else o_ptr->xtra1 = 0;
739 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
740 else o_ptr->xtra2 = 0;
742 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
743 else o_ptr->xtra3 = 0;
745 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
746 else o_ptr->xtra4 = 0;
747 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
748 else o_ptr->xtra5 = 0;
750 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
751 else o_ptr->feeling = 0;
753 if (flags & SAVE_ITEM_INSCRIPTION)
755 rd_string(buf, sizeof(buf));
756 o_ptr->inscription = quark_add(buf);
758 else o_ptr->inscription = 0;
760 if (flags & SAVE_ITEM_ART_NAME)
762 rd_string(buf, sizeof(buf));
763 o_ptr->art_name = quark_add(buf);
765 else o_ptr->art_name = 0;
767 if(h_older_than(2,1,2,4))
769 BIT_FLAGS flgs[TR_FLAG_SIZE];
770 object_flags(o_ptr, flgs);
772 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
774 add_flag(o_ptr->art_flags, TR_LITE_M1);
775 remove_flag(o_ptr->art_flags, TR_LITE_1);
776 remove_flag(o_ptr->art_flags, TR_LITE_2);
777 remove_flag(o_ptr->art_flags, TR_LITE_3);
779 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
781 if (o_ptr->tval == TV_LITE)
783 if (o_ptr->sval == SV_LITE_TORCH)
785 add_flag(o_ptr->art_flags, TR_LITE_M1);
787 else if (o_ptr->sval == SV_LITE_LANTERN)
789 add_flag(o_ptr->art_flags, TR_LITE_M2);
791 else if (o_ptr->sval == SV_LITE_FEANOR)
793 add_flag(o_ptr->art_flags, TR_LITE_M3);
798 add_flag(o_ptr->art_flags, TR_LITE_M1);
801 else if (o_ptr->tval == TV_LITE)
803 if (object_is_fixed_artifact(o_ptr))
805 add_flag(o_ptr->art_flags, TR_LITE_3);
807 else if (o_ptr->sval == SV_LITE_TORCH)
809 add_flag(o_ptr->art_flags, TR_LITE_1);
810 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
812 else if (o_ptr->sval == SV_LITE_LANTERN)
814 add_flag(o_ptr->art_flags, TR_LITE_2);
815 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
817 else if (o_ptr->sval == SV_LITE_FEANOR)
819 add_flag(o_ptr->art_flags, TR_LITE_2);
827 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
828 * @param m_ptr モンスター保存先ポインタ
831 static void rd_monster_old(monster_type *m_ptr)
838 /* Read the monster race */
839 rd_s16b(&m_ptr->r_idx);
841 if (z_older_than(11, 0, 12))
842 m_ptr->ap_r_idx = m_ptr->r_idx;
844 rd_s16b(&m_ptr->ap_r_idx);
846 if (z_older_than(11, 0, 14))
848 monster_race *r_ptr = &r_info[m_ptr->r_idx];
850 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
851 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
852 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
855 rd_byte(&m_ptr->sub_align);
857 /* Read the other information */
859 m_ptr->fy = (POSITION)tmp8u;
861 m_ptr->fx = (POSITION)tmp8u;
866 m_ptr->maxhp = tmp16s;
868 if (z_older_than(11, 0, 5))
870 m_ptr->max_maxhp = m_ptr->maxhp;
875 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
877 if(h_older_than(2, 1, 2, 1))
879 m_ptr->dealt_damage = 0;
883 rd_s32b(&m_ptr->dealt_damage);
886 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
889 m_ptr->mspeed = tmp8u;
891 if (z_older_than(10, 4, 2))
894 m_ptr->energy_need = (s16b)tmp8u;
896 else rd_s16b(&m_ptr->energy_need);
898 if (z_older_than(11, 0, 13))
899 m_ptr->energy_need = 100 - m_ptr->energy_need;
901 if (z_older_than(10,0,7))
903 m_ptr->mtimed[MTIMED_FAST] = 0;
904 m_ptr->mtimed[MTIMED_SLOW] = 0;
909 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
911 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
914 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
916 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
918 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
920 if (z_older_than(10,0,10))
924 else if (z_older_than(10,0,11))
932 m_ptr->target_y = (POSITION)tmp16s;
934 m_ptr->target_x = (POSITION)tmp16s;
938 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
940 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
941 rd_u32b(&m_ptr->smart);
945 if (z_older_than(10, 4, 5)) {
952 if (z_older_than(10, 2, 2))
954 if (m_ptr->r_idx < 0)
956 m_ptr->r_idx = (0-m_ptr->r_idx);
957 m_ptr->mflag2 |= MFLAG2_KAGE;
962 rd_byte(&m_ptr->mflag2);
965 if (z_older_than(11, 0, 12))
967 if (m_ptr->mflag2 & MFLAG2_KAGE)
968 m_ptr->ap_r_idx = MON_KAGE;
971 if (z_older_than(10, 1, 3))
977 rd_string(buf, sizeof(buf));
978 if (buf[0]) m_ptr->nickname = quark_add(buf);
986 * @brief モンスターを読み込む(現版) / Read a monster (New method)
987 * @param m_ptr モンスター保存先ポインタ
990 static void rd_monster(monster_type *m_ptr)
998 if (h_older_than(1, 5, 0, 0))
1000 rd_monster_old(m_ptr);
1004 /*** Monster save flags ***/
1007 /*** Read un-obvious elements ***/
1009 /* Read the monster race */
1010 rd_s16b(&m_ptr->r_idx);
1012 /* Read the other information */
1014 m_ptr->fy = (POSITION)tmp8u;
1016 m_ptr->fx = (POSITION)tmp8u;
1019 m_ptr->hp = (HIT_POINT)tmp16s;
1021 m_ptr->maxhp = (HIT_POINT)tmp16s;
1023 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1025 if(h_older_than(2, 1, 2, 1))
1027 m_ptr->dealt_damage = 0;
1031 rd_s32b(&m_ptr->dealt_damage);
1034 /* Monster race index of its appearance */
1035 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1036 else m_ptr->ap_r_idx = m_ptr->r_idx;
1038 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1039 else m_ptr->sub_align = 0;
1041 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1042 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1045 m_ptr->mspeed = tmp8u;
1047 rd_s16b(&m_ptr->energy_need);
1049 if (flags & SAVE_MON_FAST)
1052 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1054 else m_ptr->mtimed[MTIMED_FAST] = 0;
1055 if (flags & SAVE_MON_SLOW)
1058 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1060 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1061 if (flags & SAVE_MON_STUNNED)
1064 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1066 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1067 if (flags & SAVE_MON_CONFUSED)
1070 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1072 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1073 if (flags & SAVE_MON_MONFEAR)
1076 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1078 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1080 if (flags & SAVE_MON_TARGET_Y)
1083 m_ptr->target_y = (POSITION)tmp16s;
1085 else m_ptr->target_y = 0;
1086 if (flags & SAVE_MON_TARGET_X)
1089 m_ptr->target_x = (POSITION)tmp16s;
1091 else m_ptr->target_x = 0;
1093 if (flags & SAVE_MON_INVULNER)
1096 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1098 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1100 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1101 else m_ptr->smart = 0;
1103 if (flags & SAVE_MON_EXP)
1106 m_ptr->exp = (EXP)tmp32u;
1108 else m_ptr->exp = 0;
1110 m_ptr->mflag = 0; /* Not saved */
1112 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1113 else m_ptr->mflag2 = 0;
1115 if (flags & SAVE_MON_NICKNAME)
1117 rd_string(buf, sizeof(buf));
1118 m_ptr->nickname = quark_add(buf);
1120 else m_ptr->nickname = 0;
1122 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1123 else m_ptr->parent_m_idx = 0;
1128 * Old monster bit flags of racial resistances
1130 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1131 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1132 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1133 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1134 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1135 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1136 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1137 #define RF3_RES_WATE 0x00800000 /* Resist water */
1138 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1139 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1140 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1141 #define RF3_RES_ALL 0x08000000 /* Resist all */
1143 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1145 if ((R_PTR)->r_flags3 & (RF3)) \
1147 (R_PTR)->r_flags3 &= ~(RF3); \
1148 (R_PTR)->r_flagsr |= (RFR); \
1152 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1154 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1156 (R_PTR)->r_flagsr |= (RFR); \
1160 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1161 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1162 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1163 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1164 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1165 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1166 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1167 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1168 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1169 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1172 * @brief モンスターの思い出を読み込む / Read the monster lore
1173 * @param r_idx 読み込み先モンスターID
1176 static void rd_lore(MONRACE_IDX r_idx)
1181 monster_race *r_ptr = &r_info[r_idx];
1183 /* Count sights/deaths/kills */
1185 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1187 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1189 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1190 if (h_older_than(1, 7, 0, 5))
1192 r_ptr->r_akills = r_ptr->r_pkills;
1197 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1200 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1202 /* Count wakes and ignores */
1203 rd_byte(&r_ptr->r_wake);
1204 rd_byte(&r_ptr->r_ignore);
1207 rd_byte(&r_ptr->r_xtra1);
1208 rd_byte(&r_ptr->r_xtra2);
1212 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1214 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1218 rd_byte(&r_ptr->r_cast_spell);
1220 /* Count blows of each type */
1221 rd_byte(&r_ptr->r_blows[0]);
1222 rd_byte(&r_ptr->r_blows[1]);
1223 rd_byte(&r_ptr->r_blows[2]);
1224 rd_byte(&r_ptr->r_blows[3]);
1226 /* Memorize flags */
1227 rd_u32b(&r_ptr->r_flags1);
1228 rd_u32b(&r_ptr->r_flags2);
1229 rd_u32b(&r_ptr->r_flags3);
1230 rd_u32b(&r_ptr->r_flags4);
1231 rd_u32b(&r_ptr->r_flags5);
1232 rd_u32b(&r_ptr->r_flags6);
1233 if (h_older_than(1, 5, 0, 3))
1235 r_ptr->r_flagsr = 0L;
1237 /* Move RF3 resistance flags to RFR */
1238 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1239 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1240 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1241 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1242 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1243 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1244 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1245 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1246 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1247 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1248 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1249 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1251 /* Separate breathers resistance from RF4 to RFR */
1252 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1253 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1254 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1255 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1256 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1257 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1258 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1259 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1260 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1262 /* Resist confusion is merged to RF3_NO_CONF */
1263 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1265 /* Misc resistance hack to RFR */
1266 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1267 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1271 rd_u32b(&r_ptr->r_flagsr);
1274 /* Read the "Racial" monster limit per level */
1276 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1278 /* Location in saved floor */
1279 rd_s16b(&r_ptr->floor_id);
1284 /* Repair the lore flags */
1285 r_ptr->r_flags1 &= r_ptr->flags1;
1286 r_ptr->r_flags2 &= r_ptr->flags2;
1287 r_ptr->r_flags3 &= r_ptr->flags3;
1288 r_ptr->r_flags4 &= r_ptr->flags4;
1289 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1290 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1291 r_ptr->r_flagsr &= r_ptr->flagsr;
1295 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1296 * @param st_ptr 店舗の参照ポインタ
1297 * @param o_ptr アイテムオブジェクト参照ポインタ
1300 * In all cases, return the slot (or -1) where the object was placed
1302 * Note that this is a hacked up version of "inven_carry()".
1304 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1305 * known, the player may have to pick stuff up and drop it again.
1307 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1315 /* Check each existing item (try to combine) */
1316 for (slot = 0; slot < st_ptr->stock_num; slot++)
1318 /* Get the existing item */
1319 j_ptr = &st_ptr->stock[slot];
1321 /* The home acts just like the player */
1322 if (object_similar(j_ptr, o_ptr))
1324 /* Save the new number of items */
1325 object_absorb(j_ptr, o_ptr);
1333 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1337 /* Determine the "value" of the item */
1338 value = object_value(o_ptr);
1340 /* Check existing slots to see if we must "slide" */
1341 for (slot = 0; slot < st_ptr->stock_num; slot++)
1343 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1346 /* Slide the others up */
1347 for (i = st_ptr->stock_num; i > slot; i--)
1349 st_ptr->stock[i] = st_ptr->stock[i-1];
1352 /* More stuff now */
1353 st_ptr->stock_num++;
1355 /* Insert the new item */
1356 st_ptr->stock[slot] = *o_ptr;
1358 chg_virtue(V_SACRIFICE, -1);
1360 /* Return the location */
1365 * @brief 店舗情報を読み込む / Read a store
1366 * @param town_number 街ID
1367 * @param store_number 店舗ID
1370 static errr rd_store(int town_number, int store_number)
1382 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1384 st_ptr = &town_info[1].store[store_number];
1385 if (st_ptr->stock_num) sort = TRUE;
1389 st_ptr = &town_info[town_number].store[store_number];
1392 /* Read the basic info */
1393 rd_s32b(&st_ptr->store_open);
1394 rd_s16b(&st_ptr->insult_cur);
1396 if (z_older_than(11, 0, 4))
1405 rd_s16b(&st_ptr->good_buy);
1406 rd_s16b(&st_ptr->bad_buy);
1408 /* Read last visit */
1409 rd_s32b(&st_ptr->last_visit);
1411 /* Extract the owner (see above) */
1412 st_ptr->owner = own;
1414 /* Read the items */
1415 for (j = 0; j < num; j++)
1425 /* Acquire valid items */
1426 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1431 home_carry(st_ptr, q_ptr);
1435 k = st_ptr->stock_num++;
1437 /* Acquire the item */
1438 object_copy(&st_ptr->stock[k], q_ptr);
1449 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1452 static void rd_randomizer(void)
1462 rd_u16b(&Rand_place);
1465 for (i = 0; i < RAND_DEG; i++)
1467 rd_u32b(&Rand_state[i]);
1474 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1477 * Note that the normal options are now stored as a set of 256 bit flags,
1478 * plus a set of 256 bit masks to indicate which bit flags were defined
1479 * at the time the savefile was created. This will allow new options
1480 * to be added, and old options to be removed, at any time, without
1481 * hurting old savefiles.
1483 * The window options are stored in the same way, but note that each
1484 * window gets 32 options, and their order is fixed by certain defines.
1486 static void rd_options(void)
1495 /* Ignore old options */
1498 /*** Special info */
1500 /* Read "delay_factor" */
1504 /* Read "hitpoint_warn" */
1508 /* Read "mana_warn" */
1509 if(h_older_than(1, 7, 0, 0))
1519 /*** Cheating options ***/
1523 if (c & 0x0002) p_ptr->wizard = TRUE;
1525 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1526 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1527 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1528 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1529 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1530 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1531 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1532 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1533 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1534 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1536 rd_byte((byte *)&autosave_l);
1537 rd_byte((byte *)&autosave_t);
1538 rd_s16b(&autosave_freq);
1541 /*** Normal Options ***/
1543 /* Read the option flags */
1544 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1546 /* Read the option masks */
1547 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1549 /* Analyze the options */
1550 for (n = 0; n < 8; n++)
1552 /* Analyze the options */
1553 for (i = 0; i < 32; i++)
1555 /* Process valid flags */
1556 if (mask[n] & (1L << i))
1558 /* Process valid flags */
1559 if (option_mask[n] & (1L << i))
1562 if (flag[n] & (1L << i))
1565 option_flag[n] |= (1L << i);
1572 option_flag[n] &= ~(1L << i);
1579 if (z_older_than(10, 4, 5))
1581 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1582 else option_flag[5] |= (0x00000001 << 4);
1583 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1584 else option_flag[2] |= (0x00000001 << 5);
1585 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1586 else option_flag[4] |= (0x00000001 << 5);
1587 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1588 else option_flag[5] |= (0x00000001 << 0);
1589 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1590 else option_flag[5] |= (0x00000001 << 12);
1591 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1592 else option_flag[1] |= (0x00000001 << 0);
1593 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1594 else option_flag[1] |= (0x00000001 << 18);
1595 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1596 else option_flag[1] |= (0x00000001 << 19);
1597 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1598 else option_flag[5] |= (0x00000001 << 3);
1601 /* Extract the options */
1602 extract_option_vars();
1605 /*** Window Options ***/
1607 /* Read the window flags */
1608 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1610 /* Read the window masks */
1611 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1613 /* Analyze the options */
1614 for (n = 0; n < 8; n++)
1616 /* Analyze the options */
1617 for (i = 0; i < 32; i++)
1619 /* Process valid flags */
1620 if (mask[n] & (1L << i))
1622 /* Process valid flags */
1623 if (window_mask[n] & (1L << i))
1626 if (flag[n] & (1L << i))
1629 window_flag[n] |= (1L << i);
1636 window_flag[n] &= ~(1L << i);
1647 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1650 * This is such a nasty hack it hurts.
1652 static void rd_ghost(void)
1657 rd_string(buf, sizeof(buf));
1659 /* Strip old data */
1665 * @brief クイックスタート情報を読み込む / Load quick start data
1668 static void load_quick_start(void)
1674 if (z_older_than(11, 0, 13))
1676 previous_char.quick_ok = FALSE;
1680 rd_byte(&previous_char.psex);
1682 previous_char.prace = (RACE_IDX)tmp8u;
1684 previous_char.pclass = (CLASS_IDX)tmp8u;
1686 previous_char.pseikaku = (CHARACTER_IDX)tmp8u;
1688 previous_char.realm1 = (REALM_IDX)tmp8u;
1690 previous_char.realm2 = (REALM_IDX)tmp8u;
1692 rd_s16b(&previous_char.age);
1693 rd_s16b(&previous_char.ht);
1694 rd_s16b(&previous_char.wt);
1695 rd_s16b(&previous_char.sc);
1696 rd_s32b(&previous_char.au);
1698 for (i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1699 for (i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1701 for (i = 0; i < PY_MAX_LEVEL; i++)
1704 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1707 rd_s16b(&previous_char.chaos_patron);
1709 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1711 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1713 /* UNUSED : Was number of random quests */
1717 previous_char.quick_ok = (bool)tmp8u;
1721 * @brief その他の情報を読み込む / Read the "extra" information
1724 static void rd_extra(void)
1733 rd_string(p_ptr->name, sizeof(p_ptr->name));
1735 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1737 if (!h_older_than(1, 7, 0, 1))
1741 /* Read the message */
1742 rd_string(buf, sizeof buf);
1743 if (buf[0]) p_ptr->last_message = string_make(buf);
1748 for (i = 0; i < 4; i++)
1750 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1753 /* Class/Race/Seikaku/Gender/Spells */
1755 p_ptr->prace = (RACE_IDX)tmp8u;
1757 p_ptr->pclass = (CLASS_IDX)tmp8u;
1759 p_ptr->pseikaku = (CHARACTER_IDX)tmp8u;
1760 rd_byte(&p_ptr->psex);
1762 p_ptr->realm1 = (REALM_IDX)tmp8u;
1764 p_ptr->realm2 = (REALM_IDX)tmp8u;
1767 if (z_older_than(10, 4, 4))
1769 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1770 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1771 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1772 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1775 /* Special Race/Class info */
1777 p_ptr->hitdie = tmp8u;
1778 rd_u16b(&p_ptr->expfact);
1780 /* Age/Height/Weight */
1781 rd_s16b(&p_ptr->age);
1782 rd_s16b(&p_ptr->ht);
1783 rd_s16b(&p_ptr->wt);
1785 /* Read the stat info */
1786 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_max[i]);
1787 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1788 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_cur[i]);
1791 rd_s32b(&p_ptr->au);
1793 rd_s32b(&p_ptr->max_exp);
1794 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1795 else rd_s32b(&p_ptr->max_max_exp);
1796 rd_s32b(&p_ptr->exp);
1798 if (h_older_than(1, 7, 0, 3))
1801 p_ptr->exp_frac = (u32b)tmp16u;
1805 rd_u32b(&p_ptr->exp_frac);
1808 rd_s16b(&p_ptr->lev);
1810 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1811 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1813 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1815 if (z_older_than(10, 3, 6))
1816 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1818 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1819 for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1820 if (z_older_than(10, 4, 1))
1822 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1823 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1825 if (z_older_than(10, 3, 14))
1827 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1828 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1832 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1833 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1834 if (h_older_than(1, 3, 0, 1))
1836 if (p_ptr->pclass == CLASS_SMITH)
1838 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1839 p_ptr->magic_num1[96] = 0;
1840 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1841 p_ptr->magic_num1[97] = 0;
1845 if (music_singing_any()) p_ptr->action = ACTION_SING;
1847 if (z_older_than(11, 0, 7))
1849 p_ptr->start_race = p_ptr->prace;
1850 p_ptr->old_race1 = 0L;
1851 p_ptr->old_race2 = 0L;
1852 p_ptr->old_realm = 0;
1857 p_ptr->start_race = (RACE_IDX)tmp8u;
1859 p_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1861 p_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1862 rd_s16b(&p_ptr->old_realm);
1865 if (z_older_than(10, 0, 1))
1867 for (i = 0; i < MAX_MANE; i++)
1869 p_ptr->mane_spell[i] = -1;
1870 p_ptr->mane_dam[i] = 0;
1872 p_ptr->mane_num = 0;
1874 else if (z_older_than(10, 2, 3))
1876 for (i = 0; i < OLD_MAX_MANE; i++)
1881 for (i = 0; i < MAX_MANE; i++)
1883 p_ptr->mane_spell[i] = -1;
1884 p_ptr->mane_dam[i] = 0;
1887 p_ptr->mane_num = 0;
1891 for (i = 0; i < MAX_MANE; i++)
1894 p_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1896 p_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1898 rd_s16b(&p_ptr->mane_num);
1901 if (z_older_than(10, 0, 3))
1903 determine_bounty_uniques();
1905 for (i = 0; i < MAX_KUBI; i++)
1907 /* Is this bounty unique already dead? */
1908 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1913 for (i = 0; i < MAX_KUBI; i++)
1915 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1919 if (z_older_than(10, 0, 3))
1921 update_gambling_monsters();
1925 for (i = 0; i < 4; i++)
1927 rd_s16b(&battle_mon[i]);
1928 if (z_older_than(10, 3, 4))
1931 mon_odds[i] = tmp16s;
1933 else rd_u32b(&mon_odds[i]);
1937 rd_s16b(&p_ptr->town_num);
1939 /* Read arena and rewards information */
1940 rd_s16b(&p_ptr->arena_number);
1941 if (h_older_than(1, 5, 0, 1))
1943 /* Arena loser of previous version was marked number 99 */
1944 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1947 p_ptr->inside_arena = (bool)tmp16s;
1948 rd_s16b(&p_ptr->inside_quest);
1949 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1953 p_ptr->inside_battle = (bool)tmp16s;
1955 rd_byte(&p_ptr->exit_bldg);
1959 p_ptr->oldpx = (POSITION)tmp16s;
1961 p_ptr->oldpy = (POSITION)tmp16s;
1963 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1965 /* Was p_ptr->rewards[MAX_BACT] */
1967 for (i = 0; i < tmp16s; i++)
1973 if (h_older_than(1, 7, 0, 3))
1976 p_ptr->mhp = tmp16s;
1979 p_ptr->chp = tmp16s;
1982 p_ptr->chp_frac = (u32b)tmp16u;
1986 rd_s32b(&p_ptr->mhp);
1987 rd_s32b(&p_ptr->chp);
1988 rd_u32b(&p_ptr->chp_frac);
1991 if (h_older_than(1, 7, 0, 3))
1994 p_ptr->msp = tmp16s;
1997 p_ptr->csp = tmp16s;
2000 p_ptr->csp_frac = (u32b)tmp16u;
2004 rd_s32b(&p_ptr->msp);
2005 rd_s32b(&p_ptr->csp);
2006 rd_u32b(&p_ptr->csp_frac);
2009 rd_s16b(&p_ptr->max_plv);
2010 if (z_older_than(10, 3, 8))
2013 max_dlv[DUNGEON_ANGBAND] = tmp16s;
2017 byte max = (byte)max_d_idx;
2021 for(i = 0; i < max; i++)
2024 max_dlv[i] = tmp16s;
2025 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
2029 /* Repair maximum player level */
2030 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
2034 rd_s16b(&p_ptr->sc);
2035 rd_s16b(&p_ptr->concent);
2037 /* Read the flags */
2038 strip_bytes(2); /* Old "rest" */
2039 rd_s16b(&p_ptr->blind);
2040 rd_s16b(&p_ptr->paralyzed);
2041 rd_s16b(&p_ptr->confused);
2042 rd_s16b(&p_ptr->food);
2043 strip_bytes(4); /* Old "food_digested" / "protection" */
2045 rd_s16b(&p_ptr->energy_need);
2046 if (z_older_than(11, 0, 13))
2047 p_ptr->energy_need = 100 - p_ptr->energy_need;
2048 if (h_older_than(2, 1, 2, 0))
2049 p_ptr->enchant_energy_need = 0;
2051 rd_s16b(&p_ptr->enchant_energy_need);
2053 rd_s16b(&p_ptr->fast);
2054 rd_s16b(&p_ptr->slow);
2055 rd_s16b(&p_ptr->afraid);
2056 rd_s16b(&p_ptr->cut);
2057 rd_s16b(&p_ptr->stun);
2058 rd_s16b(&p_ptr->poisoned);
2059 rd_s16b(&p_ptr->image);
2060 rd_s16b(&p_ptr->protevil);
2061 rd_s16b(&p_ptr->invuln);
2062 if(z_older_than(10, 0, 0))
2065 rd_s16b(&p_ptr->ult_res);
2066 rd_s16b(&p_ptr->hero);
2067 rd_s16b(&p_ptr->shero);
2068 rd_s16b(&p_ptr->shield);
2069 rd_s16b(&p_ptr->blessed);
2070 rd_s16b(&p_ptr->tim_invis);
2071 rd_s16b(&p_ptr->word_recall);
2072 if (z_older_than(10, 3, 8))
2073 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2077 p_ptr->recall_dungeon = (byte)tmp16s;
2080 if (h_older_than(1, 5, 0, 0))
2081 p_ptr->alter_reality = 0;
2083 rd_s16b(&p_ptr->alter_reality);
2085 rd_s16b(&p_ptr->see_infra);
2086 rd_s16b(&p_ptr->tim_infra);
2087 rd_s16b(&p_ptr->oppose_fire);
2088 rd_s16b(&p_ptr->oppose_cold);
2089 rd_s16b(&p_ptr->oppose_acid);
2090 rd_s16b(&p_ptr->oppose_elec);
2091 rd_s16b(&p_ptr->oppose_pois);
2092 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2093 else rd_s16b(&p_ptr->tsuyoshi);
2095 /* Old savefiles do not have the following fields... */
2096 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2099 p_ptr->wraith_form = 0;
2100 p_ptr->resist_magic = 0;
2101 p_ptr->tim_regen = 0;
2102 p_ptr->kabenuke = 0;
2103 p_ptr->tim_stealth = 0;
2104 p_ptr->tim_levitation = 0;
2105 p_ptr->tim_sh_touki = 0;
2106 p_ptr->lightspeed = 0;
2107 p_ptr->tsubureru = 0;
2108 p_ptr->tim_res_nether = 0;
2109 p_ptr->tim_res_time = 0;
2110 p_ptr->mimic_form = 0;
2111 p_ptr->tim_mimic = 0;
2112 p_ptr->tim_sh_fire = 0;
2115 p_ptr->tim_reflect = 0;
2116 p_ptr->multishadow = 0;
2117 p_ptr->dustrobe = 0;
2119 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2127 rd_s16b(&p_ptr->tim_esp);
2128 rd_s16b(&p_ptr->wraith_form);
2129 rd_s16b(&p_ptr->resist_magic);
2130 rd_s16b(&p_ptr->tim_regen);
2131 rd_s16b(&p_ptr->kabenuke);
2132 rd_s16b(&p_ptr->tim_stealth);
2133 rd_s16b(&p_ptr->tim_levitation);
2134 rd_s16b(&p_ptr->tim_sh_touki);
2135 rd_s16b(&p_ptr->lightspeed);
2136 rd_s16b(&p_ptr->tsubureru);
2137 if (z_older_than(10, 4, 7))
2138 p_ptr->magicdef = 0;
2140 rd_s16b(&p_ptr->magicdef);
2141 rd_s16b(&p_ptr->tim_res_nether);
2142 if (z_older_than(10, 4, 11))
2144 p_ptr->tim_res_time = 0;
2145 p_ptr->mimic_form = 0;
2146 p_ptr->tim_mimic = 0;
2147 p_ptr->tim_sh_fire = 0;
2151 rd_s16b(&p_ptr->tim_res_time);
2153 p_ptr->mimic_form = (IDX)tmp8u;
2154 rd_s16b(&p_ptr->tim_mimic);
2155 rd_s16b(&p_ptr->tim_sh_fire);
2158 if (z_older_than(11, 0, 99))
2160 p_ptr->tim_sh_holy = 0;
2161 p_ptr->tim_eyeeye = 0;
2165 rd_s16b(&p_ptr->tim_sh_holy);
2166 rd_s16b(&p_ptr->tim_eyeeye);
2170 if ( z_older_than(11,0,3) ){
2171 p_ptr->tim_reflect=0;
2172 p_ptr->multishadow=0;
2176 rd_s16b(&p_ptr->tim_reflect);
2177 rd_s16b(&p_ptr->multishadow);
2178 rd_s16b(&p_ptr->dustrobe);
2181 rd_s16b(&p_ptr->chaos_patron);
2182 rd_u32b(&p_ptr->muta1);
2183 rd_u32b(&p_ptr->muta2);
2184 rd_u32b(&p_ptr->muta3);
2186 for (i = 0; i < 8; i++)
2187 rd_s16b(&p_ptr->virtues[i]);
2188 for (i = 0; i < 8; i++)
2189 rd_s16b(&p_ptr->vir_types[i]);
2192 /* Calc the regeneration modifier for mutations */
2193 p_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod();
2195 if (z_older_than(10,0,9))
2198 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2199 p_ptr->ele_attack = 0;
2203 rd_s16b(&p_ptr->ele_attack);
2204 rd_u32b(&p_ptr->special_attack);
2206 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2207 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2208 if (z_older_than(10,0,12))
2210 p_ptr->ele_immune = 0;
2211 p_ptr->special_defense = 0;
2215 rd_s16b(&p_ptr->ele_immune);
2216 rd_u32b(&p_ptr->special_defense);
2218 rd_byte(&p_ptr->knowledge);
2221 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2225 p_ptr->action = (ACTION_IDX)tmp8u;
2226 if (!z_older_than(10, 4, 3))
2229 if (tmp8u) p_ptr->action = ACTION_LEARN;
2231 rd_byte((byte *)&preserve_mode);
2232 rd_byte((byte *)&p_ptr->wait_report_score);
2235 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2237 /* Skip the flags */
2241 /* Hack -- the two "special seeds" */
2242 rd_u32b(&seed_flavor);
2243 rd_u32b(&seed_town);
2247 rd_u16b(&p_ptr->panic_save);
2248 rd_u16b(&p_ptr->total_winner);
2249 rd_u16b(&p_ptr->noscore);
2254 p_ptr->is_dead = tmp8u;
2256 /* Read "feeling" */
2257 rd_byte(&p_ptr->feeling);
2259 switch (p_ptr->start_race)
2265 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2268 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2271 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2273 /* Turn when level began */
2274 rd_s32b(¤t_floor_ptr->generated_turn);
2276 if (h_older_than(1, 7, 0, 4))
2278 p_ptr->feeling_turn = current_floor_ptr->generated_turn;
2282 /* Turn of last "feeling" */
2283 rd_s32b(&p_ptr->feeling_turn);
2286 /* Current current_world_ptr->game_turn */
2287 rd_s32b(¤t_world_ptr->game_turn);
2289 if (z_older_than(10, 3, 12))
2291 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2293 else rd_s32b(¤t_world_ptr->dungeon_turn);
2295 if (z_older_than(11, 0, 13))
2297 current_floor_ptr->generated_turn /= 2;
2298 p_ptr->feeling_turn /= 2;
2299 current_world_ptr->game_turn /= 2;
2300 current_world_ptr->dungeon_turn /= 2;
2303 if (z_older_than(10, 3, 13))
2305 old_battle = current_world_ptr->game_turn;
2307 else rd_s32b(&old_battle);
2309 if (z_older_than(10,0,3))
2311 determine_today_mon(TRUE);
2315 rd_s16b(&today_mon);
2316 rd_s16b(&p_ptr->today_mon);
2319 if (z_older_than(10,0,7))
2325 rd_s16b(&p_ptr->riding);
2328 /* Current floor_id */
2329 if (h_older_than(1, 5, 0, 0))
2331 p_ptr->floor_id = 0;
2335 rd_s16b(&p_ptr->floor_id);
2338 if (h_older_than(1, 5, 0, 2))
2344 /* Get number of party_mon array */
2347 /* Strip old temporary preserved pets */
2348 for (i = 0; i < tmp16s; i++)
2350 monster_type dummy_mon;
2352 rd_monster(&dummy_mon);
2356 if (z_older_than(10,1,2))
2358 current_world_ptr->play_time = 0;
2362 rd_u32b(¤t_world_ptr->play_time);
2365 if (z_older_than(10,3,9))
2369 else if (z_older_than(10, 3, 10))
2377 p_ptr->visit = (BIT_FLAGS)tmp32s;
2379 if (!z_older_than(11, 0, 5))
2381 rd_u32b(&p_ptr->count);
2387 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2390 * Note that the inventory changed in Angband 2.7.4. Two extra
2391 * pack slots were added and the equipment was rearranged. Note
2392 * that these two features combine when parsing old save-files, in
2393 * which items from the old "aux" slot are "carried", perhaps into
2394 * one of the two new "inventory" slots.
2396 * Note that the inventory is "re-sorted" later by "dungeon()".
2398 static errr rd_inventory(void)
2406 p_ptr->total_weight = 0;
2412 /* Read until done */
2417 /* Get the next item index */
2420 /* Nope, we reached the end */
2421 if (n == 0xFFFF) break;
2428 /* Hack -- verify item */
2429 if (!q_ptr->k_idx) return (53);
2431 /* Wield equipment */
2432 if (n >= INVEN_RARM)
2434 q_ptr->marked |= OM_TOUCHED;
2435 object_copy(&inventory[n], q_ptr);
2437 /* Add the weight */
2438 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2444 /* Warning -- backpack is full */
2445 else if (inven_cnt == INVEN_PACK)
2447 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
2453 /* Carry inventory */
2459 q_ptr->marked |= OM_TOUCHED;
2460 object_copy(&inventory[n], q_ptr);
2462 /* Add the weight */
2463 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2476 * @brief メッセージログを読み込む / Read the saved messages
2479 static void rd_messages(void)
2486 if (h_older_than(2, 2, 0, 75))
2491 message_max = (int)num;
2493 /* Read the messages */
2494 for (i = 0; i < message_max; i++)
2496 /* Read the message */
2497 rd_string(buf, sizeof(buf));
2499 /* Save the message */
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 /* Old hidden trap flag */
2526 #define CAVE_TRAP 0x8000
2528 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2529 #define OLD_FEAT_INVIS 0x02
2530 #define OLD_FEAT_GLYPH 0x03
2531 #define OLD_FEAT_QUEST_ENTER 0x08
2532 #define OLD_FEAT_QUEST_EXIT 0x09
2533 #define OLD_FEAT_MINOR_GLYPH 0x40
2534 #define OLD_FEAT_BLDG_1 0x81
2535 #define OLD_FEAT_MIRROR 0xc3
2538 #define OLD_QUEST_WATER_CAVE 18
2540 /* Quest constants */
2541 #define QUEST_OLD_CASTLE 27
2542 #define QUEST_ROYAL_CRYPT 28
2545 * @brief メッセージログを読み込む / Read the dungeon (old method)
2548 * The monsters/objects must be loaded in the same order
2549 * that they were stored, since the actual indexes matter.
2551 static errr rd_dungeon_old(void)
2562 /*** Basic info ***/
2566 current_floor_ptr->dun_level = (DEPTH)tmp16s;
2567 if (z_older_than(10, 3, 8)) p_ptr->dungeon_idx = DUNGEON_ANGBAND;
2571 p_ptr->dungeon_idx = (IDX)tmp8u;
2574 /* Set the base level for old versions */
2575 current_floor_ptr->base_level = current_floor_ptr->dun_level;
2578 current_floor_ptr->base_level = (DEPTH)tmp16s;
2581 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2583 p_ptr->y = (POSITION)tmp16s;
2585 p_ptr->x = (POSITION)tmp16s;
2586 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2588 current_floor_ptr->height = (POSITION)tmp16s;
2590 current_floor_ptr->width = (POSITION)tmp16s;
2591 rd_s16b(&tmp16s); /* max_panel_rows */
2592 rd_s16b(&tmp16s); /* max_panel_cols */
2595 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2599 ymax = current_floor_ptr->height;
2600 xmax = current_floor_ptr->width;
2603 /*** Run length decoding ***/
2605 /* Load the dungeon data */
2606 for (x = y = 0; y < ymax; )
2612 if (z_older_than(10,3,6))
2621 /* Decline invalid flags */
2622 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2625 /* Apply the RLE info */
2626 for (i = count; i > 0; i--)
2628 /* Access the current_floor_ptr->grid_array */
2629 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2631 /* Extract "info" */
2641 if (++y >= ymax) break;
2647 /*** Run length decoding ***/
2649 /* Load the dungeon data */
2650 for (x = y = 0; y < ymax; )
2656 /* Apply the RLE info */
2657 for (i = count; i > 0; i--)
2659 /* Access the current_floor_ptr->grid_array */
2660 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2662 /* Extract "feat" */
2663 g_ptr->feat = (s16b)tmp8u;
2672 if (++y >= ymax) break;
2677 /*** Run length decoding ***/
2679 /* Load the dungeon data */
2680 for (x = y = 0; y < ymax; )
2686 /* Apply the RLE info */
2687 for (i = count; i > 0; i--)
2689 /* Access the current_floor_ptr->grid_array */
2690 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2692 /* Extract "mimic" */
2693 g_ptr->mimic = (s16b)tmp8u;
2702 if (++y >= ymax) break;
2707 /*** Run length decoding ***/
2709 /* Load the dungeon data */
2710 for (x = y = 0; y < ymax; )
2716 /* Apply the RLE info */
2717 for (i = count; i > 0; i--)
2719 /* Access the current_floor_ptr->grid_array */
2720 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2722 /* Extract "feat" */
2723 g_ptr->special = tmp16s;
2732 if (++y >= ymax) break;
2737 /* Convert current_floor_ptr->grid_array data */
2738 if (z_older_than(11, 0, 99))
2740 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2742 /* Wipe old unused flags */
2743 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2747 if (h_older_than(1, 1, 1, 0))
2749 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2751 /* Access the current_floor_ptr->grid_array */
2752 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2755 if (g_ptr->feat == OLD_FEAT_INVIS)
2757 g_ptr->feat = feat_floor;
2758 g_ptr->info |= CAVE_TRAP;
2761 /* Older than 1.1.1 */
2762 if (g_ptr->feat == OLD_FEAT_MIRROR)
2764 g_ptr->feat = feat_floor;
2765 g_ptr->info |= CAVE_OBJECT;
2770 if (h_older_than(1, 3, 1, 0))
2772 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2774 /* Access the current_floor_ptr->grid_array */
2775 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2777 /* Old CAVE_IN_MIRROR flag */
2778 if (g_ptr->info & CAVE_OBJECT)
2780 g_ptr->mimic = feat_mirror;
2783 /* Runes will be mimics and flags */
2784 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2785 (g_ptr->feat == OLD_FEAT_GLYPH))
2787 g_ptr->info |= CAVE_OBJECT;
2788 g_ptr->mimic = g_ptr->feat;
2789 g_ptr->feat = feat_floor;
2792 /* Hidden traps will be trap terrains mimicing floor */
2793 else if (g_ptr->info & CAVE_TRAP)
2795 g_ptr->info &= ~CAVE_TRAP;
2796 g_ptr->mimic = g_ptr->feat;
2797 g_ptr->feat = choose_random_trap();
2800 /* Another hidden trap */
2801 else if (g_ptr->feat == OLD_FEAT_INVIS)
2803 g_ptr->mimic = feat_floor;
2804 g_ptr->feat = feat_trap_open;
2809 /* Quest 18 was removed */
2810 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2812 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2814 /* Access the current_floor_ptr->grid_array */
2815 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2817 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
2819 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2821 g_ptr->feat = feat_tree;
2824 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2826 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2829 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2830 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2832 g_ptr->feat = feat_up_stair;
2840 /* Read the item count */
2843 /* Verify maximum */
2844 if (limit > current_floor_ptr->max_o_idx)
2846 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2850 /* Read the dungeon items */
2851 for (i = 1; i < limit; i++)
2858 /* Get a new record */
2863 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2869 o_ptr = ¤t_floor_ptr->o_list[o_idx];
2877 if (o_ptr->held_m_idx)
2879 monster_type *m_ptr;
2880 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
2883 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2885 m_ptr->hold_o_idx = o_idx;
2891 /* Access the item location */
2892 g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2895 o_ptr->next_o_idx = g_ptr->o_idx;
2897 g_ptr->o_idx = o_idx;
2904 /* Read the monster count */
2907 /* Hack -- verify */
2908 if (limit > current_floor_ptr->max_m_idx)
2910 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2914 /* Read the monsters */
2915 for (i = 1; i < limit; i++)
2918 monster_type *m_ptr;
2920 /* Get a new record */
2925 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2930 /* Acquire monster */
2931 m_ptr = ¤t_floor_ptr->m_list[m_idx];
2933 /* Read the monster */
2938 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2940 /* Mark the location */
2941 g_ptr->m_idx = m_idx;
2944 real_r_ptr(m_ptr)->cur_num++;
2949 /* The dungeon is ready */
2950 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena)
2951 character_dungeon = FALSE;
2953 character_dungeon = TRUE;
2961 * @brief 保存されたフロアを読み込む / Read the saved floor
2962 * @return info読み込みエラーコード
2964 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2967 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2968 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2970 * The monsters/objects must be loaded in the same order
2971 * that they were stored, since the actual indexes matter.
2973 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2975 POSITION ymax, xmax;
2986 cave_template_type *templates;
2989 /*** Wipe all current_floor_ptr->grid_array ***/
2993 /*** Basic info ***/
2995 /* Dungeon floor specific info follows */
2999 /*** Not a saved floor ***/
3002 current_floor_ptr->dun_level = (DEPTH)tmp16s;
3003 current_floor_ptr->base_level = current_floor_ptr->dun_level;
3007 /*** The saved floor ***/
3010 if (tmp16s != sf_ptr->floor_id) return 171;
3013 if (tmp8u != sf_ptr->savefile_id) return 171;
3016 if (tmp16s != sf_ptr->dun_level) return 171;
3017 current_floor_ptr->dun_level = sf_ptr->dun_level;
3020 if (tmp32s != sf_ptr->last_visit) return 171;
3023 if (tmp32u != sf_ptr->visit_mark) return 171;
3026 if (tmp16s != sf_ptr->upper_floor_id) return 171;
3029 if (tmp16s != sf_ptr->lower_floor_id) return 171;
3033 current_floor_ptr->base_level = (DEPTH)tmp16s;
3035 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
3038 p_ptr->y = (POSITION)tmp16u;
3041 p_ptr->x = (POSITION)tmp16u;
3044 current_floor_ptr->height = (POSITION)tmp16s;
3046 current_floor_ptr->width = (POSITION)tmp16s;
3048 rd_byte(&p_ptr->feeling);
3052 /*** Read template for grid_type ***/
3054 /* Read the template count */
3057 /* Allocate the "template" array */
3058 C_MAKE(templates, limit, cave_template_type);
3060 /* Read the templates */
3061 for (i = 0; i < limit; i++)
3063 cave_template_type *ct_ptr = &templates[i];
3067 ct_ptr->info = (BIT_FLAGS)tmp16u;
3068 if (h_older_than(1, 7, 0, 2))
3071 ct_ptr->feat = (s16b)tmp8u;
3073 ct_ptr->mimic = (s16b)tmp8u;
3077 rd_s16b(&ct_ptr->feat);
3078 rd_s16b(&ct_ptr->mimic);
3080 rd_s16b(&ct_ptr->special);
3084 ymax = current_floor_ptr->height;
3085 xmax = current_floor_ptr->width;
3088 /*** Run length decoding ***/
3090 /* Load the dungeon data */
3091 for (x = y = 0; y < ymax; )
3103 } while (tmp8u == MAX_UCHAR);
3105 /* Apply the RLE info */
3106 for (i = count; i > 0; i--)
3108 /* Access the current_floor_ptr->grid_array */
3109 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3111 /* Extract current_floor_ptr->grid_array data */
3112 g_ptr->info = templates[id].info;
3113 g_ptr->feat = templates[id].feat;
3114 g_ptr->mimic = templates[id].mimic;
3115 g_ptr->special = templates[id].special;
3124 if (++y >= ymax) break;
3129 /* Quest 18 was removed */
3130 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3132 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3134 /* Access the current_floor_ptr->grid_array */
3135 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3137 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
3139 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
3141 g_ptr->feat = feat_tree;
3144 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
3146 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3149 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3150 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3152 g_ptr->feat = feat_up_stair;
3158 /* Free the "template" array */
3159 C_KILL(templates, limit, cave_template_type);
3164 /* Read the item count */
3167 /* Verify maximum */
3168 if (limit > current_floor_ptr->max_o_idx) return 151;
3171 /* Read the dungeon items */
3172 for (i = 1; i < limit; i++)
3178 /* Get a new record */
3181 if (i != o_idx) return 152;
3184 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3189 if (o_ptr->held_m_idx)
3191 monster_type *m_ptr;
3192 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
3195 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3197 m_ptr->hold_o_idx = o_idx;
3203 /* Access the item location */
3204 grid_type *g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
3207 o_ptr->next_o_idx = g_ptr->o_idx;
3209 g_ptr->o_idx = o_idx;
3216 /* Read the monster count */
3219 /* Hack -- verify */
3220 if (limit > current_floor_ptr->max_m_idx) return 161;
3222 /* Read the monsters */
3223 for (i = 1; i < limit; i++)
3227 monster_type *m_ptr;
3229 /* Get a new record */
3232 if (i != m_idx) return 162;
3235 /* Acquire monster */
3236 m_ptr = ¤t_floor_ptr->m_list[m_idx];
3238 /* Read the monster */
3243 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
3245 /* Mark the location */
3246 g_ptr->m_idx = m_idx;
3249 real_r_ptr(m_ptr)->cur_num++;
3258 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3261 * The monsters/objects must be loaded in the same order
3262 * that they were stored, since the actual indexes matter.
3264 static errr rd_dungeon(void)
3272 /* Initialize saved_floors array and temporal files */
3273 init_saved_floors(FALSE);
3276 if (h_older_than(1, 5, 0, 0))
3278 err = rd_dungeon_old();
3280 /* Prepare floor_id of current floor */
3281 if (p_ptr->dungeon_idx)
3283 p_ptr->floor_id = get_new_floor_id();
3284 get_sf_ptr(p_ptr->floor_id)->dun_level = current_floor_ptr->dun_level;
3293 /* Number of floor_id used from birth */
3294 rd_s16b(&max_floor_id);
3296 /* Current dungeon type */
3298 p_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
3300 /* Number of the saved_floors array elements */
3303 /*** No saved floor (On the surface etc.) ***/
3306 /* Read the current floor data */
3307 err = rd_saved_floor(NULL);
3310 /*** In the dungeon ***/
3314 /* Read the saved_floors array */
3315 for (i = 0; i < num; i++)
3317 saved_floor_type *sf_ptr = &saved_floors[i];
3319 rd_s16b(&sf_ptr->floor_id);
3321 sf_ptr->savefile_id = (s16b)tmp8u;
3324 sf_ptr->dun_level = (DEPTH)tmp16s;
3326 rd_s32b(&sf_ptr->last_visit);
3327 rd_u32b(&sf_ptr->visit_mark);
3328 rd_s16b(&sf_ptr->upper_floor_id);
3329 rd_s16b(&sf_ptr->lower_floor_id);
3333 /* Move saved floors data to temporal files */
3334 for (i = 0; i < num; i++)
3336 saved_floor_type *sf_ptr = &saved_floors[i];
3338 /* Unused element */
3339 if (!sf_ptr->floor_id) continue;
3341 /* Read the failure mark */
3343 if (tmp8u) continue;
3345 /* Read from the save file */
3346 err = rd_saved_floor(sf_ptr);
3351 /* Re-save as temporal saved floor file */
3352 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3358 /* Finally load current floor data from temporal file */
3361 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3366 /*** Error messages ***/
3370 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3374 note(_("アイテム配置エラー", "Object allocation error"));
3378 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3382 note(_("モンスター配置エラー", "Monster allocation error"));
3386 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3390 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3394 note(_("Error 183", "Error 183"));
3398 /* The dungeon is ready */
3399 character_dungeon = TRUE;
3401 /* Success or Error */
3407 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3410 static errr rd_savefile_new_aux(void)
3423 #ifdef VERIFY_CHECKSUMS
3424 u32b n_x_check, n_v_check;
3425 u32b o_x_check, o_v_check;
3429 /* Strip the version bytes */
3432 /* Hack -- decrypt */
3433 xor_byte = sf_extra;
3436 /* Clear the checksums */
3440 /* Read the version number of the savefile */
3441 /* Old savefile will be version 0.0.0.3 */
3442 rd_byte(&h_ver_extra);
3443 rd_byte(&h_ver_patch);
3444 rd_byte(&h_ver_minor);
3445 rd_byte(&h_ver_major);
3447 /* Mention the savefile version */
3449 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3450 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3453 /* Operating system info */
3454 rd_u32b(&sf_system);
3456 /* Time of savefile creation */
3459 /* Number of resurrections */
3462 /* Number of times played */
3466 /* Later use (always zero) */
3469 /* Later use (always zero) */
3472 /* Later use (always zero) */
3476 rd_byte(&kanji_code);
3478 /* Read RNG state */
3480 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3482 /* Then the options */
3484 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3486 /* Then the "messages" */
3488 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3490 for (i = 0; i < max_r_idx; i++)
3492 /* Access that monster */
3493 monster_race *r_ptr = &r_info[i];
3495 /* Hack -- Reset the death counter */
3496 r_ptr->max_num = 100;
3498 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3500 /* Hack -- Non-unique Nazguls are semi-unique */
3501 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3504 /* Monster Memory */
3507 /* Incompatible save files */
3508 if (tmp16u > max_r_idx)
3510 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3514 /* Read the available records */
3515 for (i = 0; i < tmp16u; i++)
3518 rd_lore((MONRACE_IDX)i);
3521 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3526 /* Incompatible save files */
3527 if (tmp16u > max_k_idx)
3529 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3533 /* Read the object memory */
3534 for (i = 0; i < tmp16u; i++)
3536 object_kind *k_ptr = &k_info[i];
3540 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3541 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3543 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3545 /* 2.1.3 or newer version */
3547 u16b max_towns_load;
3548 u16b max_quests_load;
3549 byte max_rquests_load;
3550 s16b old_inside_quest = p_ptr->inside_quest;
3552 /* Number of towns */
3553 rd_u16b(&max_towns_load);
3555 /* Incompatible save files */
3556 if (max_towns_load > max_towns)
3558 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3562 /* Number of quests */
3563 rd_u16b(&max_quests_load);
3565 if (z_older_than(11, 0, 7))
3567 max_rquests_load = 10;
3571 rd_byte(&max_rquests_load);
3574 /* Incompatible save files */
3575 if (max_quests_load > max_q_idx)
3577 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3581 for (i = 0; i < max_quests_load; i++)
3585 quest_type* const q_ptr = &quest[i];
3587 rd_s16b(&q_ptr->status);
3589 q_ptr->level = tmp16s;
3591 if (z_older_than(11, 0, 6))
3598 q_ptr->complev = tmp8u;
3600 if(h_older_than(2, 1, 2, 2))
3602 q_ptr->comptime = 0;
3606 rd_u32b(&q_ptr->comptime);
3609 /* Load quest status if quest is running */
3610 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3611 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3612 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3615 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3617 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3618 rd_s16b(&q_ptr->type);
3620 /* Load quest monster index */
3621 rd_s16b(&q_ptr->r_idx);
3623 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3625 determine_random_questor(&quest[i]);
3628 /* Load quest item index */
3629 rd_s16b(&q_ptr->k_idx);
3632 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3635 q_ptr->flags = tmp8u;
3637 if (z_older_than(10, 3, 11))
3639 if (q_ptr->flags & QUEST_FLAG_PRESET)
3645 init_flags = INIT_ASSIGN;
3646 p_ptr->inside_quest = (QUEST_IDX)i;
3648 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3649 p_ptr->inside_quest = old_inside_quest;
3655 q_ptr->dungeon = tmp8u;
3658 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3659 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3660 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3663 /* Ignore the empty quests from old versions */
3666 /* Ignore quest status */
3669 /* Ignore quest level */
3673 * We don't have to care about the other info,
3674 * since status should be 0 for these quests anyway
3679 /* Quest 18 was removed */
3680 if (h_older_than(1, 7, 0, 6))
3682 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3683 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3686 /* Position in the wilderness */
3687 rd_s32b(&p_ptr->wilderness_x);
3688 rd_s32b(&p_ptr->wilderness_y);
3689 if (z_older_than(10, 3, 13))
3691 p_ptr->wilderness_x = 5;
3692 p_ptr->wilderness_y = 48;
3695 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3696 else rd_byte((byte *)&p_ptr->wild_mode);
3697 if (z_older_than(10, 3, 7)) p_ptr->ambush_flag = FALSE;
3698 else rd_byte((byte *)&p_ptr->ambush_flag);
3700 /* Size of the wilderness */
3701 rd_s32b(&wild_x_size);
3702 rd_s32b(&wild_y_size);
3704 /* Incompatible save files */
3705 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3707 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3711 /* Load the wilderness seeds */
3712 for (i = 0; i < wild_x_size; i++)
3714 for (j = 0; j < wild_y_size; j++)
3716 rd_u32b(&wilderness[j][i].seed);
3721 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3723 /* Load the Artifacts */
3726 /* Incompatible save files */
3727 if (tmp16u > max_a_idx)
3729 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3733 /* Read the artifact flags */
3734 for (i = 0; i < tmp16u; i++)
3736 artifact_type *a_ptr = &a_info[i];
3739 a_ptr->cur_num = tmp8u;
3741 if (h_older_than(1, 5, 0, 0))
3743 a_ptr->floor_id = 0;
3751 rd_s16b(&a_ptr->floor_id);
3754 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3756 /* Read the extra stuff */
3758 if (p_ptr->energy_need < -999) p_ptr->timewalk = TRUE;
3760 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3763 /* Read the player_hp array */
3766 /* Incompatible save files */
3767 if (tmp16u > PY_MAX_LEVEL)
3769 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3773 /* Read the player_hp array */
3774 for (i = 0; i < tmp16u; i++)
3777 p_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3780 /* Important -- Initialize the sex */
3781 sp_ptr = &sex_info[p_ptr->psex];
3783 /* Important -- Initialize the race/class */
3784 rp_ptr = &race_info[p_ptr->prace];
3785 cp_ptr = &class_info[p_ptr->pclass];
3786 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3788 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3790 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3791 roll_hitdice(p_ptr, 0L);
3793 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3795 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3796 roll_hitdice(p_ptr, 0L);
3798 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3800 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3801 roll_hitdice(p_ptr, 0L);
3803 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3805 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3806 roll_hitdice(p_ptr, 0L);
3809 /* Important -- Initialize the magic */
3810 mp_ptr = &m_info[p_ptr->pclass];
3813 /* Read spell info */
3814 rd_u32b(&p_ptr->spell_learned1);
3815 rd_u32b(&p_ptr->spell_learned2);
3816 rd_u32b(&p_ptr->spell_worked1);
3817 rd_u32b(&p_ptr->spell_worked2);
3818 rd_u32b(&p_ptr->spell_forgotten1);
3819 rd_u32b(&p_ptr->spell_forgotten2);
3821 if (z_older_than(10,0,5))
3823 p_ptr->learned_spells = 0;
3824 for (i = 0; i < 64; i++)
3826 /* Count known spells */
3828 (p_ptr->spell_learned1 & (1L << i)) :
3829 (p_ptr->spell_learned2 & (1L << (i - 32))))
3831 p_ptr->learned_spells++;
3835 else rd_s16b(&p_ptr->learned_spells);
3837 if (z_older_than(10,0,6))
3839 p_ptr->add_spells = 0;
3841 else rd_s16b(&p_ptr->add_spells);
3842 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3844 for (i = 0; i < 64; i++)
3847 p_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3851 /* Read the inventory */
3854 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3858 /* Read number of towns */
3860 town_count = tmp16u;
3862 /* Read the stores */
3864 for (i = 1; i < town_count; i++)
3866 for (j = 0; j < tmp16u; j++)
3868 if (rd_store(i, j)) return (22);
3872 rd_s16b(&p_ptr->pet_follow_distance);
3873 if (z_older_than(10, 4, 10))
3875 p_ptr->pet_extra_flags = 0;
3877 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3879 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3881 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3885 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3888 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3892 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3895 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3899 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3902 if (!z_older_than(10,0,8))
3905 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3910 rd_s16b(&p_ptr->pet_extra_flags);
3913 if (!z_older_than(11, 0, 9))
3915 char buf[SCREEN_BUF_MAX_SIZE];
3916 rd_string(buf, sizeof(buf));
3917 if (buf[0]) screen_dump = string_make(buf);
3922 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3924 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3929 /* I'm not dead yet... */
3930 if (!p_ptr->is_dead)
3932 /* Dead players have no dungeon */
3933 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3937 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3941 /* Read the ghost info */
3948 strip_bytes(tmp32s);
3952 /* Quest 18 was removed */
3953 if (h_older_than(1, 7, 0, 6))
3955 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3957 p_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3958 current_floor_ptr->dun_level = 1;
3959 p_ptr->inside_quest = 0;
3964 #ifdef VERIFY_CHECKSUMS
3966 /* Save the checksum */
3967 n_v_check = v_check;
3969 /* Read the old checksum */
3970 rd_u32b(&o_v_check);
3973 if (o_v_check != n_v_check)
3975 note(_("チェックサムがおかしい", "Invalid checksum"));
3980 /* Save the encoded checksum */
3981 n_x_check = x_check;
3983 /* Read the checksum */
3984 rd_u32b(&o_x_check);
3988 if (o_x_check != n_x_check)
3990 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
4001 * @brief ロード処理全体のメイン関数 / Actually read the savefile
4004 errr rd_savefile_new(void)
4008 /* Grab permissions */
4011 /* The savefile is a binary file */
4012 fff = my_fopen(savefile, "rb");
4014 /* Drop permissions */
4016 if (!fff) return (-1);
4018 /* Call the sub-function */
4019 err = rd_savefile_new_aux();
4021 /* Check for errors */
4022 if (ferror(fff)) err = -1;
4029 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
4030 * @param sf_ptr 保存フロア読み込み先
4033 static bool load_floor_aux(saved_floor_type *sf_ptr)
4038 #ifdef VERIFY_CHECKSUMS
4039 u32b n_x_check, n_v_check;
4040 u32b o_x_check, o_v_check;
4043 /* Hack -- decrypt (read xor_byte) */
4047 /* Clear the checksums */
4051 /* Set the version number to current version */
4052 /* Never load old temporal files */
4053 h_ver_extra = H_VER_EXTRA;
4054 h_ver_patch = H_VER_PATCH;
4055 h_ver_minor = H_VER_MINOR;
4056 h_ver_major = H_VER_MAJOR;
4058 /* Verify the sign */
4060 if (saved_floor_file_sign != tmp32u) return FALSE;
4062 /* Read -- have error? */
4063 if (rd_saved_floor(sf_ptr)) return FALSE;
4066 #ifdef VERIFY_CHECKSUMS
4067 /* Save the checksum */
4068 n_v_check = v_check;
4070 /* Read the old checksum */
4071 rd_u32b(&o_v_check);
4074 if (o_v_check != n_v_check) return FALSE;
4076 /* Save the encoded checksum */
4077 n_x_check = x_check;
4079 /* Read the checksum */
4080 rd_u32b(&o_x_check);
4083 if (o_x_check != n_x_check) return FALSE;
4092 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4093 * @param sf_ptr 保存フロア読み込み先
4097 bool load_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
4099 FILE *old_fff = NULL;
4100 byte old_xor_byte = 0;
4101 u32b old_v_check = 0;
4102 u32b old_x_check = 0;
4103 byte old_h_ver_major = 0;
4104 byte old_h_ver_minor = 0;
4105 byte old_h_ver_patch = 0;
4106 byte old_h_ver_extra = 0;
4109 char floor_savefile[1024];
4111 byte old_kanji_code = kanji_code;
4114 * Temporal files are always written in system depended kanji
4119 /* EUC kanji code */
4123 /* SJIS kanji code */
4132 /* We have one file already opened */
4133 if (mode & SLF_SECOND)
4135 /* Backup original values */
4137 old_xor_byte = xor_byte;
4138 old_v_check = v_check;
4139 old_x_check = x_check;
4140 old_h_ver_major = h_ver_major;
4141 old_h_ver_minor = h_ver_minor;
4142 old_h_ver_patch = h_ver_patch;
4143 old_h_ver_extra = h_ver_extra;
4146 /* floor savefile */
4147 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4149 /* Grab permissions */
4152 /* The savefile is a binary file */
4153 fff = my_fopen(floor_savefile, "rb");
4155 /* Drop permissions */
4159 if (!fff) ok = FALSE;
4161 /* Attempt to load */
4164 /* Load saved floor data from file */
4165 ok = load_floor_aux(sf_ptr);
4167 /* Check for errors */
4168 if (ferror(fff)) ok = FALSE;
4171 /* Grab permissions */
4174 /* Delete the file */
4175 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4177 /* Drop permissions */
4181 /* We have one file already opened */
4182 if (mode & SLF_SECOND)
4184 /* Restore original values */
4186 xor_byte = old_xor_byte;
4187 v_check = old_v_check;
4188 x_check = old_x_check;
4189 h_ver_major = old_h_ver_major;
4190 h_ver_minor = old_h_ver_minor;
4191 h_ver_patch = old_h_ver_patch;
4192 h_ver_extra = old_h_ver_extra;
4195 /* Restore old knowledge */
4196 kanji_code = old_kanji_code;