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.
47 * Maximum number of tries for selection of a proper quest monster
53 * Local "savefile" pointer
58 * Hack -- old "encryption" byte
63 * Hack -- simple "checksum" on the actual values
65 static u32b v_check = 0L;
68 * Hack -- simple "checksum" on the encoded bytes
70 static u32b x_check = 0L;
73 * Hack -- Japanese Kanji code
79 static byte kanji_code = 0;
82 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
83 * @param major メジャーバージョン値
84 * @param minor マイナーバージョン値
85 * @param patch パッチバージョン値
86 * @param extra エクストラパージョン値
87 * @return 現在のバージョンより値が古いならtrue
89 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
91 /* Much older, or much more recent */
92 if (h_ver_major < major) return (TRUE);
93 if (h_ver_major > major) return (FALSE);
95 /* Distinctly older, or distinctly more recent */
96 if (h_ver_minor < minor) return (TRUE);
97 if (h_ver_minor > minor) return (FALSE);
99 /* Barely older, or barely more recent */
100 if (h_ver_patch < patch) return (TRUE);
101 if (h_ver_patch > patch) return (FALSE);
103 /* Barely older, or barely more recent */
104 if (h_ver_extra < extra) return (TRUE);
105 if (h_ver_extra > extra) return (FALSE);
107 /* Identical versions */
113 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
114 * @param x メジャーバージョン値
115 * @param y マイナーバージョン値
117 * @return 現在のバージョンより値が古いならtrue
119 static bool z_older_than(byte x, byte y, byte z)
121 /* Much older, or much more recent */
122 if (z_major < x) return (TRUE);
123 if (z_major > x) return (FALSE);
125 /* Distinctly older, or distinctly more recent */
126 if (z_minor < y) return (TRUE);
127 if (z_minor > y) return (FALSE);
129 /* Barely older, or barely more recent */
130 if (z_patch < z) return (TRUE);
131 if (z_patch > z) return (FALSE);
133 /* Identical versions */
139 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
143 * Avoid the top two lines, to avoid interference with "msg_print()".
145 static void note(cptr msg)
149 /* Draw the message */
152 /* Advance one line (wrap if needed) */
153 if (++y >= 24) y = 2;
161 * @brief ロードファイルポインタから1バイトを読み込む
164 * The following functions are used to load the basic building blocks
165 * of savefiles. They also maintain the "checksum" info for 2.7.0+
167 static byte sf_get(void)
171 /* Get a character, decode the value */
172 c = getc(fff) & 0xFF;
176 /* Maintain the checksum info */
180 /* Return the value */
185 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
189 static void rd_byte(byte *ip)
195 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
199 static void rd_u16b(u16b *ip)
202 (*ip) |= ((u16b)(sf_get()) << 8);
206 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
210 static void rd_s16b(s16b *ip)
216 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
220 static void rd_u32b(u32b *ip)
223 (*ip) |= ((u32b)(sf_get()) << 8);
224 (*ip) |= ((u32b)(sf_get()) << 16);
225 (*ip) |= ((u32b)(sf_get()) << 24);
229 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
233 static void rd_s32b(s32b *ip)
240 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
242 * @param max 最大読み取りバイト数
245 static void rd_string(char *str, int max)
249 /* Read the string */
250 for (i = 0; TRUE; i++)
257 /* Collect string while legal */
258 if (i < max) str[i] = tmp8u;
269 /* Convert Kanji code */
288 /* 不明の漢字コードからシステムの漢字コードに変換 */
289 byte code = codeconv(str);
291 /* 漢字コードが判明したら、それを記録 */
292 if (code) kanji_code = code;
297 /* No conversion needed */
305 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
309 static void strip_bytes(int n)
313 /* Strip the bytes */
314 while (n--) rd_byte(&tmp8u);
317 #define OLD_MAX_MANE 22
320 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
321 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
324 * This function attempts to "repair" old savefiles, and to extract
325 * the most up to date values for various object fields.
327 * Note that Angband 2.7.9 introduced a new method for object "flags"
328 * in which the "flags" on an object are actually extracted when they
329 * are needed from the object kind, artifact index, ego-item index,
330 * and two special "xtra" fields which are used to encode any "extra"
331 * power of certain ego-items. This had the side effect that items
332 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
333 * may have had, and also, all "uncursed" items will become "cursed"
334 * again, including Calris, even if it is being worn at the time. As
335 * a complete hack, items which are inscribed with "uncursed" will be
336 * "uncursed" when imported from pre-2.7.9 savefiles.
338 static void rd_item_old(object_type *o_ptr)
344 rd_s16b(&o_ptr->k_idx);
351 rd_byte(&o_ptr->tval);
352 rd_byte(&o_ptr->sval);
354 if (z_older_than(10, 4, 4))
356 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
357 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
358 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
362 rd_s16b(&o_ptr->pval);
364 rd_byte(&o_ptr->discount);
365 rd_byte(&o_ptr->number);
366 rd_s16b(&o_ptr->weight);
368 rd_byte(&o_ptr->name1);
369 rd_byte(&o_ptr->name2);
370 rd_s16b(&o_ptr->timeout);
372 rd_s16b(&o_ptr->to_h);
373 rd_s16b(&o_ptr->to_d);
374 rd_s16b(&o_ptr->to_a);
381 rd_byte(&o_ptr->ident);
383 rd_byte(&o_ptr->marked);
386 rd_u32b(&o_ptr->art_flags[0]);
387 rd_u32b(&o_ptr->art_flags[1]);
388 rd_u32b(&o_ptr->art_flags[2]);
389 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
390 else rd_u32b(&o_ptr->art_flags[3]);
392 if (h_older_than(1, 3, 0, 0))
394 if (o_ptr->name2 == EGO_TELEPATHY)
395 add_flag(o_ptr->art_flags, TR_TELEPATHY);
398 if (z_older_than(11, 0, 11))
400 o_ptr->curse_flags = 0L;
401 if (o_ptr->ident & 0x40)
403 o_ptr->curse_flags |= TRC_CURSED;
404 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
405 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
406 if (object_is_fixed_artifact(o_ptr))
408 artifact_type *a_ptr = &a_info[o_ptr->name1];
409 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
410 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
412 else if (object_is_ego(o_ptr))
414 ego_item_type *e_ptr = &e_info[o_ptr->name2];
415 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
416 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
419 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
423 rd_u32b(&o_ptr->curse_flags);
426 /* Monster holding object */
427 rd_s16b(&o_ptr->held_m_idx);
430 rd_byte(&o_ptr->xtra1);
431 rd_byte(&o_ptr->xtra2);
433 if (z_older_than(11, 0, 10))
435 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
437 switch (o_ptr->xtra2 % 6)
439 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
440 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
441 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
442 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
443 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
444 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
448 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
450 switch (o_ptr->xtra2 % 11)
452 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
453 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
454 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
455 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
456 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
457 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
458 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
459 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
460 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
461 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
462 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
466 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
468 switch (o_ptr->xtra2 % 8)
470 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
471 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
472 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
473 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
474 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
475 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
476 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
477 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
484 if (z_older_than(10, 2, 3))
489 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
491 o_ptr->xtra3 = o_ptr->xtra1;
494 if (o_ptr->tval == TV_CAPTURE)
496 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
497 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
499 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
500 if (ironman_nightmare)
502 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
504 o_ptr->xtra4 = o_ptr->xtra5;
509 rd_byte(&o_ptr->xtra3);
510 if (h_older_than(1, 3, 0, 1))
512 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
513 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
516 rd_s16b(&o_ptr->xtra4);
517 rd_s16b(&o_ptr->xtra5);
520 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)))
522 o_ptr->xtra4 = o_ptr->pval;
526 rd_byte(&o_ptr->feeling);
529 rd_string(buf, sizeof(buf));
531 /* Save the inscription */
532 if (buf[0]) o_ptr->inscription = quark_add(buf);
534 rd_string(buf, sizeof(buf));
535 if (buf[0]) o_ptr->art_name = quark_add(buf);
537 /* The Python object */
545 /* Mega-Hack -- handle "dungeon objects" later */
546 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
548 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
550 if (z_older_than(10, 4, 9))
552 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
554 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
555 add_flag(o_ptr->art_flags, TR_DEC_MANA);
560 if (object_is_fixed_artifact(o_ptr))
562 artifact_type *a_ptr;
564 /* Obtain the artifact info */
565 a_ptr = &a_info[o_ptr->name1];
567 /* Verify that artifact */
568 if (!a_ptr->name) o_ptr->name1 = 0;
572 if (object_is_ego(o_ptr))
574 ego_item_type *e_ptr;
576 /* Obtain the ego-item info */
577 e_ptr = &e_info[o_ptr->name2];
579 /* Verify that ego-item */
580 if (!e_ptr->name) o_ptr->name2 = 0;
587 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
588 * @param o_ptr アイテムオブジェクト保存先ポインタ
591 static void rd_item(object_type *o_ptr)
597 if (h_older_than(1, 5, 0, 0))
603 /*** Item save flags ***/
606 /*** Read un-obvious elements ***/
608 rd_s16b(&o_ptr->k_idx);
615 k_ptr = &k_info[o_ptr->k_idx];
616 o_ptr->tval = k_ptr->tval;
617 o_ptr->sval = k_ptr->sval;
620 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
621 else o_ptr->pval = 0;
623 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
624 else o_ptr->discount = 0;
625 if (flags & SAVE_ITEM_NUMBER) rd_byte(&o_ptr->number);
626 else o_ptr->number = 1;
628 rd_s16b(&o_ptr->weight);
630 if (flags & SAVE_ITEM_NAME1) rd_byte(&o_ptr->name1);
631 else o_ptr->name1 = 0;
632 if (flags & SAVE_ITEM_NAME2) rd_byte(&o_ptr->name2);
633 else o_ptr->name2 = 0;
634 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
635 else o_ptr->timeout = 0;
637 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
638 else o_ptr->to_h = 0;
639 if (flags & SAVE_ITEM_TO_D) rd_s16b(&o_ptr->to_d);
640 else o_ptr->to_d = 0;
641 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
642 else o_ptr->to_a = 0;
644 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
647 if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
649 if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
652 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
653 else o_ptr->ident = 0;
655 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
656 else o_ptr->marked = 0;
659 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
660 else o_ptr->art_flags[0] = 0;
661 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
662 else o_ptr->art_flags[1] = 0;
663 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
664 else o_ptr->art_flags[2] = 0;
665 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
666 else o_ptr->art_flags[3] = 0;
667 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
668 else o_ptr->art_flags[4] = 0;
670 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
671 else o_ptr->curse_flags = 0;
673 /* Monster holding object */
674 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
675 else o_ptr->held_m_idx = 0;
678 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
679 else o_ptr->xtra1 = 0;
680 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
681 else o_ptr->xtra2 = 0;
683 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
684 else o_ptr->xtra3 = 0;
686 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
687 else o_ptr->xtra4 = 0;
688 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
689 else o_ptr->xtra5 = 0;
691 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
692 else o_ptr->feeling = 0;
694 if (flags & SAVE_ITEM_INSCRIPTION)
696 rd_string(buf, sizeof(buf));
697 o_ptr->inscription = quark_add(buf);
699 else o_ptr->inscription = 0;
701 if (flags & SAVE_ITEM_ART_NAME)
703 rd_string(buf, sizeof(buf));
704 o_ptr->art_name = quark_add(buf);
706 else o_ptr->art_name = 0;
708 if(h_older_than(2,1,2,4))
710 u32b flgs[TR_FLAG_SIZE];
711 object_flags(o_ptr, flgs);
713 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
715 add_flag(o_ptr->art_flags, TR_LITE_M1);
716 remove_flag(o_ptr->art_flags, TR_LITE_1);
717 remove_flag(o_ptr->art_flags, TR_LITE_2);
718 remove_flag(o_ptr->art_flags, TR_LITE_3);
720 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
722 if (o_ptr->tval == TV_LITE)
724 if (o_ptr->sval == SV_LITE_TORCH)
726 add_flag(o_ptr->art_flags, TR_LITE_M1);
728 else if (o_ptr->sval == SV_LITE_LANTERN)
730 add_flag(o_ptr->art_flags, TR_LITE_M2);
732 else if (o_ptr->sval == SV_LITE_FEANOR)
734 add_flag(o_ptr->art_flags, TR_LITE_M3);
740 add_flag(o_ptr->art_flags, TR_LITE_M1);
743 else if (o_ptr->tval == TV_LITE)
745 if (object_is_fixed_artifact(o_ptr))
747 add_flag(o_ptr->art_flags, TR_LITE_3);
749 else if (o_ptr->sval == SV_LITE_TORCH)
751 add_flag(o_ptr->art_flags, TR_LITE_1);
752 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
754 else if (o_ptr->sval == SV_LITE_LANTERN)
756 add_flag(o_ptr->art_flags, TR_LITE_2);
757 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
759 else if (o_ptr->sval == SV_LITE_FEANOR)
761 add_flag(o_ptr->art_flags, TR_LITE_2);
769 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
770 * @param m_ptr モンスター保存先ポインタ
773 static void rd_monster_old(monster_type *m_ptr)
778 /* Read the monster race */
779 rd_s16b(&m_ptr->r_idx);
781 if (z_older_than(11, 0, 12))
782 m_ptr->ap_r_idx = m_ptr->r_idx;
784 rd_s16b(&m_ptr->ap_r_idx);
786 if (z_older_than(11, 0, 14))
788 monster_race *r_ptr = &r_info[m_ptr->r_idx];
790 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
791 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
792 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
795 rd_byte(&m_ptr->sub_align);
797 /* Read the other information */
801 rd_s16b(&m_ptr->maxhp);
802 if (z_older_than(11, 0, 5))
804 m_ptr->max_maxhp = m_ptr->maxhp;
808 rd_s16b(&m_ptr->max_maxhp);
810 if(h_older_than(2, 1, 2, 1))
812 m_ptr->dealt_damage = 0;
816 rd_u32b(&m_ptr->dealt_damage);
819 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
820 rd_byte(&m_ptr->mspeed);
821 if (z_older_than(10, 4, 2))
824 m_ptr->energy_need = (s16b)tmp8u;
826 else rd_s16b(&m_ptr->energy_need);
828 if (z_older_than(11, 0, 13))
829 m_ptr->energy_need = 100 - m_ptr->energy_need;
831 if (z_older_than(10,0,7))
833 m_ptr->mtimed[MTIMED_FAST] = 0;
834 m_ptr->mtimed[MTIMED_SLOW] = 0;
839 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
841 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
844 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
846 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
848 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
850 if (z_older_than(10,0,10))
854 else if (z_older_than(10,0,11))
862 rd_s16b(&m_ptr->target_y);
863 rd_s16b(&m_ptr->target_x);
867 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
869 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
870 rd_u32b(&m_ptr->smart);
874 if (z_older_than(10, 4, 5))
877 rd_u32b(&m_ptr->exp);
879 if (z_older_than(10, 2, 2))
881 if (m_ptr->r_idx < 0)
883 m_ptr->r_idx = (0-m_ptr->r_idx);
884 m_ptr->mflag2 |= MFLAG2_KAGE;
889 rd_byte(&m_ptr->mflag2);
892 if (z_older_than(11, 0, 12))
894 if (m_ptr->mflag2 & MFLAG2_KAGE)
895 m_ptr->ap_r_idx = MON_KAGE;
898 if (z_older_than(10, 1, 3))
904 rd_string(buf, sizeof(buf));
905 if (buf[0]) m_ptr->nickname = quark_add(buf);
913 * @brief モンスターを読み込む(現版) / Read a monster (New method)
914 * @param m_ptr モンスター保存先ポインタ
917 static void rd_monster(monster_type *m_ptr)
923 if (h_older_than(1, 5, 0, 0))
925 rd_monster_old(m_ptr);
929 /*** Monster save flags ***/
932 /*** Read un-obvious elements ***/
934 /* Read the monster race */
935 rd_s16b(&m_ptr->r_idx);
937 /* Read the other information */
941 rd_s16b(&m_ptr->maxhp);
942 rd_s16b(&m_ptr->max_maxhp);
943 if(h_older_than(2, 1, 2, 1))
945 m_ptr->dealt_damage = 0;
949 rd_u32b(&m_ptr->dealt_damage);
952 /* Monster race index of its appearance */
953 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
954 else m_ptr->ap_r_idx = m_ptr->r_idx;
956 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
957 else m_ptr->sub_align = 0;
959 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
960 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
962 rd_byte(&m_ptr->mspeed);
964 rd_s16b(&m_ptr->energy_need);
966 if (flags & SAVE_MON_FAST)
969 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
971 else m_ptr->mtimed[MTIMED_FAST] = 0;
972 if (flags & SAVE_MON_SLOW)
975 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
977 else m_ptr->mtimed[MTIMED_SLOW] = 0;
978 if (flags & SAVE_MON_STUNNED)
981 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
983 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
984 if (flags & SAVE_MON_CONFUSED)
987 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
989 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
990 if (flags & SAVE_MON_MONFEAR)
993 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
995 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
997 if (flags & SAVE_MON_TARGET_Y) rd_s16b(&m_ptr->target_y);
998 else m_ptr->target_y = 0;
999 if (flags & SAVE_MON_TARGET_X) rd_s16b(&m_ptr->target_x);
1000 else m_ptr->target_x = 0;
1002 if (flags & SAVE_MON_INVULNER)
1005 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1007 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1009 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1010 else m_ptr->smart = 0;
1012 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
1013 else m_ptr->exp = 0;
1015 m_ptr->mflag = 0; /* Not saved */
1017 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1018 else m_ptr->mflag2 = 0;
1020 if (flags & SAVE_MON_NICKNAME)
1022 rd_string(buf, sizeof(buf));
1023 m_ptr->nickname = quark_add(buf);
1025 else m_ptr->nickname = 0;
1027 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1028 else m_ptr->parent_m_idx = 0;
1033 * Old monster bit flags of racial resistances
1035 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1036 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1037 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1038 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1039 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1040 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1041 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1042 #define RF3_RES_WATE 0x00800000 /* Resist water */
1043 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1044 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1045 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1046 #define RF3_RES_ALL 0x08000000 /* Resist all */
1048 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1050 if ((R_PTR)->r_flags3 & (RF3)) \
1052 (R_PTR)->r_flags3 &= ~(RF3); \
1053 (R_PTR)->r_flagsr |= (RFR); \
1057 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1059 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1061 (R_PTR)->r_flagsr |= (RFR); \
1065 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1066 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1067 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1068 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1069 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1070 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1071 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1072 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1073 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1074 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1077 * @brief モンスターの思い出を読み込む / Read the monster lore
1078 * @param r_idx 読み込み先モンスターID
1081 static void rd_lore(int r_idx)
1085 monster_race *r_ptr = &r_info[r_idx];
1087 /* Count sights/deaths/kills */
1088 rd_s16b(&r_ptr->r_sights);
1089 rd_s16b(&r_ptr->r_deaths);
1090 rd_s16b(&r_ptr->r_pkills);
1091 if (h_older_than(1, 7, 0, 5))
1093 r_ptr->r_akills = r_ptr->r_pkills;
1097 rd_s16b(&r_ptr->r_akills);
1099 rd_s16b(&r_ptr->r_tkills);
1101 /* Count wakes and ignores */
1102 rd_byte(&r_ptr->r_wake);
1103 rd_byte(&r_ptr->r_ignore);
1106 rd_byte(&r_ptr->r_xtra1);
1107 rd_byte(&r_ptr->r_xtra2);
1110 rd_byte(&r_ptr->r_drop_gold);
1111 rd_byte(&r_ptr->r_drop_item);
1115 rd_byte(&r_ptr->r_cast_spell);
1117 /* Count blows of each type */
1118 rd_byte(&r_ptr->r_blows[0]);
1119 rd_byte(&r_ptr->r_blows[1]);
1120 rd_byte(&r_ptr->r_blows[2]);
1121 rd_byte(&r_ptr->r_blows[3]);
1123 /* Memorize flags */
1124 rd_u32b(&r_ptr->r_flags1);
1125 rd_u32b(&r_ptr->r_flags2);
1126 rd_u32b(&r_ptr->r_flags3);
1127 rd_u32b(&r_ptr->r_flags4);
1128 rd_u32b(&r_ptr->r_flags5);
1129 rd_u32b(&r_ptr->r_flags6);
1130 if (h_older_than(1, 5, 0, 3))
1132 r_ptr->r_flagsr = 0L;
1134 /* Move RF3 resistance flags to RFR */
1135 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1136 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1137 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1138 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1139 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1140 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1141 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1142 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1143 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1144 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1145 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1146 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1148 /* Separate breathers resistance from RF4 to RFR */
1149 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1150 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1151 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1152 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1153 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1154 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1155 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1156 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1157 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1159 /* Resist confusion is merged to RF3_NO_CONF */
1160 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1162 /* Misc resistance hack to RFR */
1163 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1164 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1168 rd_u32b(&r_ptr->r_flagsr);
1171 /* Read the "Racial" monster limit per level */
1172 rd_byte(&r_ptr->max_num);
1174 /* Location in saved floor */
1175 rd_s16b(&r_ptr->floor_id);
1180 /* Repair the lore flags */
1181 r_ptr->r_flags1 &= r_ptr->flags1;
1182 r_ptr->r_flags2 &= r_ptr->flags2;
1183 r_ptr->r_flags3 &= r_ptr->flags3;
1184 r_ptr->r_flags4 &= r_ptr->flags4;
1185 r_ptr->r_flags5 &= r_ptr->flags5;
1186 r_ptr->r_flags6 &= r_ptr->flags6;
1187 r_ptr->r_flagsr &= r_ptr->flagsr;
1191 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1192 * @param st_ptr 店舗の参照ポインタ
1193 * @param o_ptr アイテムオブジェクト参照ポインタ
1196 * In all cases, return the slot (or -1) where the object was placed
1198 * Note that this is a hacked up version of "inven_carry()".
1200 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1201 * known, the player may have to pick stuff up and drop it again.
1203 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1211 /* Check each existing item (try to combine) */
1212 for (slot = 0; slot < st_ptr->stock_num; slot++)
1214 /* Get the existing item */
1215 j_ptr = &st_ptr->stock[slot];
1217 /* The home acts just like the player */
1218 if (object_similar(j_ptr, o_ptr))
1220 /* Save the new number of items */
1221 object_absorb(j_ptr, o_ptr);
1229 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1233 /* Determine the "value" of the item */
1234 value = object_value(o_ptr);
1236 /* Check existing slots to see if we must "slide" */
1237 for (slot = 0; slot < st_ptr->stock_num; slot++)
1239 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1242 /* Slide the others up */
1243 for (i = st_ptr->stock_num; i > slot; i--)
1245 st_ptr->stock[i] = st_ptr->stock[i-1];
1248 /* More stuff now */
1249 st_ptr->stock_num++;
1251 /* Insert the new item */
1252 st_ptr->stock[slot] = *o_ptr;
1254 chg_virtue(V_SACRIFICE, -1);
1256 /* Return the location */
1261 * @brief 店舗情報を読み込む / Read a store
1262 * @param town_number 街ID
1263 * @param store_number 店舗ID
1266 static errr rd_store(int town_number, int store_number)
1278 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1280 st_ptr = &town[1].store[store_number];
1281 if (st_ptr->stock_num) sort = TRUE;
1285 st_ptr = &town[town_number].store[store_number];
1288 /* Read the basic info */
1289 rd_s32b(&st_ptr->store_open);
1290 rd_s16b(&st_ptr->insult_cur);
1292 if (z_older_than(11, 0, 4))
1301 rd_s16b(&st_ptr->good_buy);
1302 rd_s16b(&st_ptr->bad_buy);
1304 /* Read last visit */
1305 rd_s32b(&st_ptr->last_visit);
1307 /* Extract the owner (see above) */
1308 st_ptr->owner = own;
1310 /* Read the items */
1311 for (j = 0; j < num; j++)
1316 /* Get local object */
1319 /* Wipe the object */
1325 /* Acquire valid items */
1326 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1331 home_carry(st_ptr, q_ptr);
1335 k = st_ptr->stock_num++;
1337 /* Acquire the item */
1338 object_copy(&st_ptr->stock[k], q_ptr);
1349 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1352 static void rd_randomizer(void)
1362 rd_u16b(&Rand_place);
1365 for (i = 0; i < RAND_DEG; i++)
1367 rd_u32b(&Rand_state[i]);
1374 * Read options (ignore most pre-2.8.0 options)
1376 * Note that the normal options are now stored as a set of 256 bit flags,
1377 * plus a set of 256 bit masks to indicate which bit flags were defined
1378 * at the time the savefile was created. This will allow new options
1379 * to be added, and old options to be removed, at any time, without
1380 * hurting old savefiles.
1382 * The window options are stored in the same way, but note that each
1383 * window gets 32 options, and their order is fixed by certain defines.
1385 static void rd_options(void)
1399 /* Ignore old options */
1403 /*** Special info */
1405 /* Read "delay_factor" */
1409 /* Read "hitpoint_warn" */
1413 /* Read "mana_warn" */
1414 if(h_older_than(1, 7, 0, 0))
1425 /*** Cheating options ***/
1429 if (c & 0x0002) p_ptr->wizard = TRUE;
1431 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1432 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1433 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1434 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1435 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1436 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1437 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1439 rd_byte((byte *)&autosave_l);
1440 rd_byte((byte *)&autosave_t);
1441 rd_s16b(&autosave_freq);
1444 /*** Normal Options ***/
1446 /* Read the option flags */
1447 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1449 /* Read the option masks */
1450 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1452 /* Analyze the options */
1453 for (n = 0; n < 8; n++)
1455 /* Analyze the options */
1456 for (i = 0; i < 32; i++)
1458 /* Process valid flags */
1459 if (mask[n] & (1L << i))
1461 /* Process valid flags */
1462 if (option_mask[n] & (1L << i))
1465 if (flag[n] & (1L << i))
1468 option_flag[n] |= (1L << i);
1475 option_flag[n] &= ~(1L << i);
1482 if (z_older_than(10, 4, 5))
1484 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1485 else option_flag[5] |= (0x00000001 << 4);
1486 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1487 else option_flag[2] |= (0x00000001 << 5);
1488 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1489 else option_flag[4] |= (0x00000001 << 5);
1490 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1491 else option_flag[5] |= (0x00000001 << 0);
1492 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1493 else option_flag[5] |= (0x00000001 << 12);
1494 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1495 else option_flag[1] |= (0x00000001 << 0);
1496 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1497 else option_flag[1] |= (0x00000001 << 18);
1498 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1499 else option_flag[1] |= (0x00000001 << 19);
1500 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1501 else option_flag[5] |= (0x00000001 << 3);
1504 /* Extract the options */
1505 extract_option_vars();
1508 /*** Window Options ***/
1510 /* Read the window flags */
1511 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1513 /* Read the window masks */
1514 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1516 /* Analyze the options */
1517 for (n = 0; n < 8; n++)
1519 /* Analyze the options */
1520 for (i = 0; i < 32; i++)
1522 /* Process valid flags */
1523 if (mask[n] & (1L << i))
1525 /* Process valid flags */
1526 if (window_mask[n] & (1L << i))
1529 if (flag[n] & (1L << i))
1532 window_flag[n] |= (1L << i);
1539 window_flag[n] &= ~(1L << i);
1552 * Hack -- strip the "ghost" info
1554 * XXX XXX XXX This is such a nasty hack it hurts.
1556 static void rd_ghost(void)
1561 rd_string(buf, sizeof(buf));
1563 /* Strip old data */
1569 * Save quick start data
1571 static void load_quick_start(void)
1576 if (z_older_than(11, 0, 13))
1578 previous_char.quick_ok = FALSE;
1582 rd_byte(&previous_char.psex);
1583 rd_byte(&previous_char.prace);
1584 rd_byte(&previous_char.pclass);
1585 rd_byte(&previous_char.pseikaku);
1586 rd_byte(&previous_char.realm1);
1587 rd_byte(&previous_char.realm2);
1589 rd_s16b(&previous_char.age);
1590 rd_s16b(&previous_char.ht);
1591 rd_s16b(&previous_char.wt);
1592 rd_s16b(&previous_char.sc);
1593 rd_s32b(&previous_char.au);
1595 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1596 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1598 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1600 rd_s16b(&previous_char.chaos_patron);
1602 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1604 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1606 /* UNUSED : Was number of random quests */
1610 previous_char.quick_ok = (bool)tmp8u;
1614 * Read the "extra" information
1616 static void rd_extra(void)
1624 rd_string(player_name, sizeof(player_name));
1626 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1628 if (!h_older_than(1, 7, 0, 1))
1632 /* Read the message */
1633 rd_string(buf, sizeof buf);
1634 if (buf[0]) p_ptr->last_message = string_make(buf);
1639 for (i = 0; i < 4; i++)
1641 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1644 /* Class/Race/Seikaku/Gender/Spells */
1645 rd_byte(&p_ptr->prace);
1646 rd_byte(&p_ptr->pclass);
1647 rd_byte(&p_ptr->pseikaku);
1648 rd_byte(&p_ptr->psex);
1649 rd_byte(&p_ptr->realm1);
1650 rd_byte(&p_ptr->realm2);
1651 rd_byte(&tmp8u); /* oops */
1653 if (z_older_than(10, 4, 4))
1655 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1656 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1657 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1658 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1661 /* Special Race/Class info */
1662 rd_byte(&p_ptr->hitdie);
1663 rd_u16b(&p_ptr->expfact);
1665 /* Age/Height/Weight */
1666 rd_s16b(&p_ptr->age);
1667 rd_s16b(&p_ptr->ht);
1668 rd_s16b(&p_ptr->wt);
1670 /* Read the stat info */
1671 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1672 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1673 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1675 strip_bytes(24); /* oops */
1677 rd_s32b(&p_ptr->au);
1679 rd_s32b(&p_ptr->max_exp);
1680 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1681 else rd_s32b(&p_ptr->max_max_exp);
1682 rd_s32b(&p_ptr->exp);
1684 if (h_older_than(1, 7, 0, 3))
1687 p_ptr->exp_frac = (u32b)tmp16u;
1691 rd_u32b(&p_ptr->exp_frac);
1694 rd_s16b(&p_ptr->lev);
1696 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1697 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1699 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1701 if (z_older_than(10, 3, 6))
1702 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1704 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1705 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1706 if (z_older_than(10, 4, 1))
1708 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1709 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1711 if (z_older_than(10, 3, 14))
1713 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1714 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1718 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1719 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1720 if (h_older_than(1, 3, 0, 1))
1722 if (p_ptr->pclass == CLASS_SMITH)
1724 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1725 p_ptr->magic_num1[96] = 0;
1726 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1727 p_ptr->magic_num1[97] = 0;
1731 if (music_singing_any()) p_ptr->action = ACTION_SING;
1733 if (z_older_than(11, 0, 7))
1735 p_ptr->start_race = p_ptr->prace;
1736 p_ptr->old_race1 = 0L;
1737 p_ptr->old_race2 = 0L;
1738 p_ptr->old_realm = 0;
1742 rd_byte(&p_ptr->start_race);
1743 rd_s32b(&p_ptr->old_race1);
1744 rd_s32b(&p_ptr->old_race2);
1745 rd_s16b(&p_ptr->old_realm);
1748 if (z_older_than(10, 0, 1))
1750 for (i = 0; i < OLD_MAX_MANE; i++)
1752 p_ptr->mane_spell[i] = -1;
1753 p_ptr->mane_dam[i] = 0;
1755 p_ptr->mane_num = 0;
1757 else if (z_older_than(10, 2, 3))
1759 for (i = 0; i < OLD_MAX_MANE; i++)
1764 for (i = 0; i < MAX_MANE; i++)
1766 p_ptr->mane_spell[i] = -1;
1767 p_ptr->mane_dam[i] = 0;
1770 p_ptr->mane_num = 0;
1774 for (i = 0; i < MAX_MANE; i++)
1776 rd_s16b(&p_ptr->mane_spell[i]);
1777 rd_s16b(&p_ptr->mane_dam[i]);
1779 rd_s16b(&p_ptr->mane_num);
1782 if (z_older_than(10, 0, 3))
1784 determine_bounty_uniques();
1786 for (i = 0; i < MAX_KUBI; i++)
1788 /* Is this bounty unique already dead? */
1789 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1794 for (i = 0; i < MAX_KUBI; i++)
1796 rd_s16b(&kubi_r_idx[i]);
1800 if (z_older_than(10, 0, 3))
1806 for (i = 0; i < 4; i++)
1808 rd_s16b(&battle_mon[i]);
1809 if (z_older_than(10, 3, 4))
1812 mon_odds[i] = tmp16s;
1814 else rd_u32b(&mon_odds[i]);
1818 rd_s16b(&p_ptr->town_num);
1820 /* Read arena and rewards information */
1821 rd_s16b(&p_ptr->arena_number);
1822 if (h_older_than(1, 5, 0, 1))
1824 /* Arena loser of previous version was marked number 99 */
1825 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1828 p_ptr->inside_arena = (bool)tmp16s;
1829 rd_s16b(&p_ptr->inside_quest);
1830 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1834 p_ptr->inside_battle = (bool)tmp16s;
1836 rd_byte(&p_ptr->exit_bldg);
1839 rd_s16b(&p_ptr->oldpx);
1840 rd_s16b(&p_ptr->oldpy);
1841 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1843 /* Was p_ptr->rewards[MAX_BACT] */
1845 for (i = 0; i < tmp16s; i++)
1851 if (h_older_than(1, 7, 0, 3))
1854 p_ptr->mhp = tmp16s;
1857 p_ptr->chp = tmp16s;
1860 p_ptr->chp_frac = (u32b)tmp16u;
1864 rd_s32b(&p_ptr->mhp);
1865 rd_s32b(&p_ptr->chp);
1866 rd_u32b(&p_ptr->chp_frac);
1869 if (h_older_than(1, 7, 0, 3))
1872 p_ptr->msp = tmp16s;
1875 p_ptr->csp = tmp16s;
1878 p_ptr->csp_frac = (u32b)tmp16u;
1882 rd_s32b(&p_ptr->msp);
1883 rd_s32b(&p_ptr->csp);
1884 rd_u32b(&p_ptr->csp_frac);
1887 rd_s16b(&p_ptr->max_plv);
1888 if (z_older_than(10, 3, 8))
1890 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1894 byte max = (byte)max_d_idx;
1898 for(i = 0; i < max; i++)
1900 rd_s16b(&max_dlv[i]);
1901 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1905 /* Repair maximum player level XXX XXX XXX */
1906 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1910 rd_s16b(&p_ptr->sc);
1911 rd_s16b(&p_ptr->concent);
1913 /* Read the flags */
1914 strip_bytes(2); /* Old "rest" */
1915 rd_s16b(&p_ptr->blind);
1916 rd_s16b(&p_ptr->paralyzed);
1917 rd_s16b(&p_ptr->confused);
1918 rd_s16b(&p_ptr->food);
1919 strip_bytes(4); /* Old "food_digested" / "protection" */
1921 rd_s16b(&p_ptr->energy_need);
1922 if (z_older_than(11, 0, 13))
1923 p_ptr->energy_need = 100 - p_ptr->energy_need;
1924 if (h_older_than(2, 1, 2, 0))
1925 p_ptr->enchant_energy_need = 0;
1927 rd_s16b(&p_ptr->enchant_energy_need);
1929 rd_s16b(&p_ptr->fast);
1930 rd_s16b(&p_ptr->slow);
1931 rd_s16b(&p_ptr->afraid);
1932 rd_s16b(&p_ptr->cut);
1933 rd_s16b(&p_ptr->stun);
1934 rd_s16b(&p_ptr->poisoned);
1935 rd_s16b(&p_ptr->image);
1936 rd_s16b(&p_ptr->protevil);
1937 rd_s16b(&p_ptr->invuln);
1938 if(z_older_than(10, 0, 0))
1941 rd_s16b(&p_ptr->ult_res);
1942 rd_s16b(&p_ptr->hero);
1943 rd_s16b(&p_ptr->shero);
1944 rd_s16b(&p_ptr->shield);
1945 rd_s16b(&p_ptr->blessed);
1946 rd_s16b(&p_ptr->tim_invis);
1947 rd_s16b(&p_ptr->word_recall);
1948 if (z_older_than(10, 3, 8))
1949 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1953 p_ptr->recall_dungeon = (byte)tmp16s;
1956 if (h_older_than(1, 5, 0, 0))
1957 p_ptr->alter_reality = 0;
1959 rd_s16b(&p_ptr->alter_reality);
1961 rd_s16b(&p_ptr->see_infra);
1962 rd_s16b(&p_ptr->tim_infra);
1963 rd_s16b(&p_ptr->oppose_fire);
1964 rd_s16b(&p_ptr->oppose_cold);
1965 rd_s16b(&p_ptr->oppose_acid);
1966 rd_s16b(&p_ptr->oppose_elec);
1967 rd_s16b(&p_ptr->oppose_pois);
1968 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1969 else rd_s16b(&p_ptr->tsuyoshi);
1971 /* Old savefiles do not have the following fields... */
1972 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1975 p_ptr->wraith_form = 0;
1976 p_ptr->resist_magic = 0;
1977 p_ptr->tim_regen = 0;
1978 p_ptr->kabenuke = 0;
1979 p_ptr->tim_stealth = 0;
1980 p_ptr->tim_levitation = 0;
1981 p_ptr->tim_sh_touki = 0;
1982 p_ptr->lightspeed = 0;
1983 p_ptr->tsubureru = 0;
1984 p_ptr->tim_res_nether = 0;
1985 p_ptr->tim_res_time = 0;
1986 p_ptr->mimic_form = 0;
1987 p_ptr->tim_mimic = 0;
1988 p_ptr->tim_sh_fire = 0;
1991 p_ptr->tim_reflect = 0;
1992 p_ptr->multishadow = 0;
1993 p_ptr->dustrobe = 0;
1995 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2003 rd_s16b(&p_ptr->tim_esp);
2004 rd_s16b(&p_ptr->wraith_form);
2005 rd_s16b(&p_ptr->resist_magic);
2006 rd_s16b(&p_ptr->tim_regen);
2007 rd_s16b(&p_ptr->kabenuke);
2008 rd_s16b(&p_ptr->tim_stealth);
2009 rd_s16b(&p_ptr->tim_levitation);
2010 rd_s16b(&p_ptr->tim_sh_touki);
2011 rd_s16b(&p_ptr->lightspeed);
2012 rd_s16b(&p_ptr->tsubureru);
2013 if (z_older_than(10, 4, 7))
2014 p_ptr->magicdef = 0;
2016 rd_s16b(&p_ptr->magicdef);
2017 rd_s16b(&p_ptr->tim_res_nether);
2018 if (z_older_than(10, 4, 11))
2020 p_ptr->tim_res_time = 0;
2021 p_ptr->mimic_form = 0;
2022 p_ptr->tim_mimic = 0;
2023 p_ptr->tim_sh_fire = 0;
2027 rd_s16b(&p_ptr->tim_res_time);
2028 rd_byte(&p_ptr->mimic_form);
2029 rd_s16b(&p_ptr->tim_mimic);
2030 rd_s16b(&p_ptr->tim_sh_fire);
2033 if (z_older_than(11, 0, 99))
2035 p_ptr->tim_sh_holy = 0;
2036 p_ptr->tim_eyeeye = 0;
2040 rd_s16b(&p_ptr->tim_sh_holy);
2041 rd_s16b(&p_ptr->tim_eyeeye);
2045 if ( z_older_than(11,0,3) ){
2046 p_ptr->tim_reflect=0;
2047 p_ptr->multishadow=0;
2051 rd_s16b(&p_ptr->tim_reflect);
2052 rd_s16b(&p_ptr->multishadow);
2053 rd_s16b(&p_ptr->dustrobe);
2056 rd_s16b(&p_ptr->chaos_patron);
2057 rd_u32b(&p_ptr->muta1);
2058 rd_u32b(&p_ptr->muta2);
2059 rd_u32b(&p_ptr->muta3);
2061 for (i = 0; i < 8; i++)
2062 rd_s16b(&p_ptr->virtues[i]);
2063 for (i = 0; i < 8; i++)
2064 rd_s16b(&p_ptr->vir_types[i]);
2067 /* Calc the regeneration modifier for mutations */
2068 mutant_regenerate_mod = calc_mutant_regenerate_mod();
2070 if (z_older_than(10,0,9))
2073 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2074 p_ptr->ele_attack = 0;
2078 rd_s16b(&p_ptr->ele_attack);
2079 rd_u32b(&p_ptr->special_attack);
2081 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2082 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2083 if (z_older_than(10,0,12))
2085 p_ptr->ele_immune = 0;
2086 p_ptr->special_defense = 0;
2090 rd_s16b(&p_ptr->ele_immune);
2091 rd_u32b(&p_ptr->special_defense);
2093 rd_byte(&p_ptr->knowledge);
2096 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2098 rd_byte(&tmp8u); /* oops */
2099 rd_byte(&p_ptr->action);
2100 if (!z_older_than(10, 4, 3))
2103 if (tmp8u) p_ptr->action = ACTION_LEARN;
2105 rd_byte((byte *)&preserve_mode);
2106 rd_byte((byte *)&p_ptr->wait_report_score);
2109 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2111 /* Skip the flags */
2115 /* Hack -- the two "special seeds" */
2116 rd_u32b(&seed_flavor);
2117 rd_u32b(&seed_town);
2121 rd_u16b(&p_ptr->panic_save);
2122 rd_u16b(&p_ptr->total_winner);
2123 rd_u16b(&p_ptr->noscore);
2128 p_ptr->is_dead = tmp8u;
2130 /* Read "feeling" */
2131 rd_byte(&p_ptr->feeling);
2133 switch (p_ptr->start_race)
2139 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2142 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2145 dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2147 /* Turn when level began */
2150 if (h_older_than(1, 7, 0, 4))
2152 p_ptr->feeling_turn = old_turn;
2156 /* Turn of last "feeling" */
2157 rd_s32b(&p_ptr->feeling_turn);
2163 if (z_older_than(10, 3, 12))
2165 dungeon_turn = turn;
2167 else rd_s32b(&dungeon_turn);
2169 if (z_older_than(11, 0, 13))
2172 p_ptr->feeling_turn /= 2;
2177 if (z_older_than(10, 3, 13))
2181 else rd_s32b(&old_battle);
2183 if (z_older_than(10,0,3))
2185 determine_today_mon(TRUE);
2189 rd_s16b(&today_mon);
2190 rd_s16b(&p_ptr->today_mon);
2193 if (z_older_than(10,0,7))
2199 rd_s16b(&p_ptr->riding);
2202 /* Current floor_id */
2203 if (h_older_than(1, 5, 0, 0))
2205 p_ptr->floor_id = 0;
2209 rd_s16b(&p_ptr->floor_id);
2212 if (h_older_than(1, 5, 0, 2))
2218 /* Get number of party_mon array */
2221 /* Strip old temporary preserved pets */
2222 for (i = 0; i < tmp16s; i++)
2224 monster_type dummy_mon;
2226 rd_monster(&dummy_mon);
2230 if (z_older_than(10,1,2))
2239 if (z_older_than(10,3,9))
2243 else if (z_older_than(10, 3, 10))
2251 rd_s32b(&p_ptr->visit);
2253 if (!z_older_than(11, 0, 5))
2255 rd_u32b(&p_ptr->count);
2263 * Read the player inventory
2265 * Note that the inventory changed in Angband 2.7.4. Two extra
2266 * pack slots were added and the equipment was rearranged. Note
2267 * that these two features combine when parsing old save-files, in
2268 * which items from the old "aux" slot are "carried", perhaps into
2269 * one of the two new "inventory" slots.
2271 * Note that the inventory is "re-sorted" later by "dungeon()".
2273 static errr rd_inventory(void)
2281 p_ptr->total_weight = 0;
2287 /* Read until done */
2292 /* Get the next item index */
2295 /* Nope, we reached the end */
2296 if (n == 0xFFFF) break;
2298 /* Get local object */
2301 /* Wipe the object */
2307 /* Hack -- verify item */
2308 if (!q_ptr->k_idx) return (53);
2310 /* Wield equipment */
2311 if (n >= INVEN_RARM)
2313 /* Player touches it */
2314 q_ptr->marked |= OM_TOUCHED;
2317 object_copy(&inventory[n], q_ptr);
2319 /* Add the weight */
2320 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2326 /* Warning -- backpack is full */
2327 else if (inven_cnt == INVEN_PACK)
2330 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
2336 /* Carry inventory */
2342 /* Player touches it */
2343 q_ptr->marked |= OM_TOUCHED;
2346 object_copy(&inventory[n], q_ptr);
2348 /* Add the weight */
2349 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2363 * Read the saved messages
2365 static void rd_messages(void)
2375 /* Read the messages */
2376 for (i = 0; i < num; i++)
2378 /* Read the message */
2379 rd_string(buf, sizeof(buf));
2381 /* Save the message */
2388 /* Old hidden trap flag */
2389 #define CAVE_TRAP 0x8000
2391 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2392 #define OLD_FEAT_INVIS 0x02
2393 #define OLD_FEAT_GLYPH 0x03
2394 #define OLD_FEAT_QUEST_ENTER 0x08
2395 #define OLD_FEAT_QUEST_EXIT 0x09
2396 #define OLD_FEAT_MINOR_GLYPH 0x40
2397 #define OLD_FEAT_BLDG_1 0x81
2398 #define OLD_FEAT_MIRROR 0xc3
2401 #define OLD_QUEST_WATER_CAVE 18
2403 /* Quest constants */
2404 #define QUEST_OLD_CASTLE 27
2405 #define QUEST_ROYAL_CRYPT 28
2408 * Read the dungeon (old method)
2410 * The monsters/objects must be loaded in the same order
2411 * that they were stored, since the actual indexes matter.
2413 static errr rd_dungeon_old(void)
2424 /*** Basic info ***/
2427 rd_s16b(&dun_level);
2428 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2429 else rd_byte(&dungeon_type);
2431 /* Set the base level for old versions */
2432 base_level = dun_level;
2434 rd_s16b(&base_level);
2436 rd_s16b(&num_repro);
2441 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2444 rd_s16b(&tmp16s); /* max_panel_rows */
2445 rd_s16b(&tmp16s); /* max_panel_cols */
2448 if (!py || !px) {py = 10;px = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2456 /*** Run length decoding ***/
2458 /* Load the dungeon data */
2459 for (x = y = 0; y < ymax; )
2465 if (z_older_than(10,3,6))
2474 /* Decline invalid flags */
2475 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2478 /* Apply the RLE info */
2479 for (i = count; i > 0; i--)
2481 /* Access the cave */
2482 c_ptr = &cave[y][x];
2484 /* Extract "info" */
2494 if (++y >= ymax) break;
2500 /*** Run length decoding ***/
2502 /* Load the dungeon data */
2503 for (x = y = 0; y < ymax; )
2509 /* Apply the RLE info */
2510 for (i = count; i > 0; i--)
2512 /* Access the cave */
2513 c_ptr = &cave[y][x];
2515 /* Extract "feat" */
2516 c_ptr->feat = (s16b)tmp8u;
2525 if (++y >= ymax) break;
2530 /*** Run length decoding ***/
2532 /* Load the dungeon data */
2533 for (x = y = 0; y < ymax; )
2539 /* Apply the RLE info */
2540 for (i = count; i > 0; i--)
2542 /* Access the cave */
2543 c_ptr = &cave[y][x];
2545 /* Extract "mimic" */
2546 c_ptr->mimic = (s16b)tmp8u;
2555 if (++y >= ymax) break;
2560 /*** Run length decoding ***/
2562 /* Load the dungeon data */
2563 for (x = y = 0; y < ymax; )
2569 /* Apply the RLE info */
2570 for (i = count; i > 0; i--)
2572 /* Access the cave */
2573 c_ptr = &cave[y][x];
2575 /* Extract "feat" */
2576 c_ptr->special = tmp16s;
2585 if (++y >= ymax) break;
2590 /* Convert cave data */
2591 if (z_older_than(11, 0, 99))
2593 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2595 /* Wipe old unused flags */
2596 cave[y][x].info &= ~(CAVE_MASK);
2600 if (h_older_than(1, 1, 1, 0))
2602 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2604 /* Access the cave */
2605 c_ptr = &cave[y][x];
2608 if (c_ptr->feat == OLD_FEAT_INVIS)
2610 c_ptr->feat = feat_floor;
2611 c_ptr->info |= CAVE_TRAP;
2614 /* Older than 1.1.1 */
2615 if (c_ptr->feat == OLD_FEAT_MIRROR)
2617 c_ptr->feat = feat_floor;
2618 c_ptr->info |= CAVE_OBJECT;
2623 if (h_older_than(1, 3, 1, 0))
2625 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2627 /* Access the cave */
2628 c_ptr = &cave[y][x];
2630 /* Old CAVE_IN_MIRROR flag */
2631 if (c_ptr->info & CAVE_OBJECT)
2633 c_ptr->mimic = feat_mirror;
2636 /* Runes will be mimics and flags */
2637 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2638 (c_ptr->feat == OLD_FEAT_GLYPH))
2640 c_ptr->info |= CAVE_OBJECT;
2641 c_ptr->mimic = c_ptr->feat;
2642 c_ptr->feat = feat_floor;
2645 /* Hidden traps will be trap terrains mimicing floor */
2646 else if (c_ptr->info & CAVE_TRAP)
2648 c_ptr->info &= ~CAVE_TRAP;
2649 c_ptr->mimic = c_ptr->feat;
2650 c_ptr->feat = choose_random_trap();
2653 /* Another hidden trap */
2654 else if (c_ptr->feat == OLD_FEAT_INVIS)
2656 c_ptr->mimic = feat_floor;
2657 c_ptr->feat = feat_trap_open;
2662 /* Quest 18 was removed */
2663 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2665 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2667 /* Access the cave */
2668 c_ptr = &cave[y][x];
2670 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2672 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2674 c_ptr->feat = feat_tree;
2677 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2679 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2682 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2683 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2685 c_ptr->feat = feat_up_stair;
2693 /* Read the item count */
2696 /* Verify maximum */
2697 if (limit > max_o_idx)
2699 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2703 /* Read the dungeon items */
2704 for (i = 1; i < limit; i++)
2711 /* Get a new record */
2717 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2723 o_ptr = &o_list[o_idx];
2729 /* XXX XXX XXX XXX XXX */
2732 if (o_ptr->held_m_idx)
2734 monster_type *m_ptr;
2737 m_ptr = &m_list[o_ptr->held_m_idx];
2740 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2742 /* Place the object */
2743 m_ptr->hold_o_idx = o_idx;
2749 /* Access the item location */
2750 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2753 o_ptr->next_o_idx = c_ptr->o_idx;
2755 /* Place the object */
2756 c_ptr->o_idx = o_idx;
2763 /* Read the monster count */
2766 /* Hack -- verify */
2767 if (limit > max_m_idx)
2769 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2773 /* Read the monsters */
2774 for (i = 1; i < limit; i++)
2777 monster_type *m_ptr;
2779 /* Get a new record */
2785 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2790 /* Acquire monster */
2791 m_ptr = &m_list[m_idx];
2793 /* Read the monster */
2798 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2800 /* Mark the location */
2801 c_ptr->m_idx = m_idx;
2804 real_r_ptr(m_ptr)->cur_num++;
2809 /* The dungeon is ready */
2810 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2811 character_dungeon = FALSE;
2813 character_dungeon = TRUE;
2822 * Read the saved floor
2824 * The monsters/objects must be loaded in the same order
2825 * that they were stored, since the actual indexes matter.
2827 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2839 cave_template_type *templates;
2842 /*** Wipe all cave ***/
2846 /*** Basic info ***/
2848 /* Dungeon floor specific info follows */
2852 /*** Not a saved floor ***/
2854 rd_s16b(&dun_level);
2855 base_level = dun_level;
2859 /*** The saved floor ***/
2862 if (tmp16s != sf_ptr->floor_id) return 171;
2865 if (tmp8u != sf_ptr->savefile_id) return 171;
2868 if (tmp16s != sf_ptr->dun_level) return 171;
2869 dun_level = sf_ptr->dun_level;
2872 if (tmp32s != sf_ptr->last_visit) return 171;
2875 if (tmp32u != sf_ptr->visit_mark) return 171;
2878 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2881 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2884 rd_s16b(&base_level);
2885 rd_s16b(&num_repro);
2896 rd_byte(&p_ptr->feeling);
2900 /*** Read template for cave_type ***/
2902 /* Read the template count */
2905 /* Allocate the "template" array */
2906 C_MAKE(templates, limit, cave_template_type);
2908 /* Read the templates */
2909 for (i = 0; i < limit; i++)
2911 cave_template_type *ct_ptr = &templates[i];
2914 rd_u16b(&ct_ptr->info);
2915 if (h_older_than(1, 7, 0, 2))
2918 ct_ptr->feat = (s16b)tmp8u;
2920 ct_ptr->mimic = (s16b)tmp8u;
2924 rd_s16b(&ct_ptr->feat);
2925 rd_s16b(&ct_ptr->mimic);
2927 rd_s16b(&ct_ptr->special);
2935 /*** Run length decoding ***/
2937 /* Load the dungeon data */
2938 for (x = y = 0; y < ymax; )
2950 } while (tmp8u == MAX_UCHAR);
2952 /* Apply the RLE info */
2953 for (i = count; i > 0; i--)
2955 /* Access the cave */
2956 cave_type *c_ptr = &cave[y][x];
2958 /* Extract cave data */
2959 c_ptr->info = templates[id].info;
2960 c_ptr->feat = templates[id].feat;
2961 c_ptr->mimic = templates[id].mimic;
2962 c_ptr->special = templates[id].special;
2971 if (++y >= ymax) break;
2976 /* Quest 18 was removed */
2977 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2979 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2981 /* Access the cave */
2982 cave_type *c_ptr = &cave[y][x];
2984 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2986 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2988 c_ptr->feat = feat_tree;
2991 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2993 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2996 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2997 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2999 c_ptr->feat = feat_up_stair;
3005 /* Free the "template" array */
3006 C_KILL(templates, limit, cave_template_type);
3011 /* Read the item count */
3014 /* Verify maximum */
3015 if (limit > max_o_idx) return 151;
3018 /* Read the dungeon items */
3019 for (i = 1; i < limit; i++)
3025 /* Get a new record */
3029 if (i != o_idx) return 152;
3032 o_ptr = &o_list[o_idx];
3039 if (o_ptr->held_m_idx)
3041 monster_type *m_ptr;
3044 m_ptr = &m_list[o_ptr->held_m_idx];
3047 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3049 /* Place the object */
3050 m_ptr->hold_o_idx = o_idx;
3056 /* Access the item location */
3057 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3060 o_ptr->next_o_idx = c_ptr->o_idx;
3062 /* Place the object */
3063 c_ptr->o_idx = o_idx;
3070 /* Read the monster count */
3073 /* Hack -- verify */
3074 if (limit > max_m_idx) return 161;
3076 /* Read the monsters */
3077 for (i = 1; i < limit; i++)
3081 monster_type *m_ptr;
3083 /* Get a new record */
3087 if (i != m_idx) return 162;
3090 /* Acquire monster */
3091 m_ptr = &m_list[m_idx];
3093 /* Read the monster */
3098 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3100 /* Mark the location */
3101 c_ptr->m_idx = m_idx;
3104 real_r_ptr(m_ptr)->cur_num++;
3113 * Read the dungeon (new method)
3115 * The monsters/objects must be loaded in the same order
3116 * that they were stored, since the actual indexes matter.
3118 static errr rd_dungeon(void)
3124 /* Initialize saved_floors array and temporal files */
3125 init_saved_floors(FALSE);
3128 if (h_older_than(1, 5, 0, 0))
3130 err = rd_dungeon_old();
3132 /* Prepare floor_id of current floor */
3135 p_ptr->floor_id = get_new_floor_id();
3136 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3145 /* Number of floor_id used from birth */
3146 rd_s16b(&max_floor_id);
3148 /* Current dungeon type */
3149 rd_byte(&dungeon_type);
3152 /* Number of the saved_floors array elements */
3155 /*** No saved floor (On the surface etc.) ***/
3158 /* Read the current floor data */
3159 err = rd_saved_floor(NULL);
3162 /*** In the dungeon ***/
3166 /* Read the saved_floors array */
3167 for (i = 0; i < num; i++)
3169 saved_floor_type *sf_ptr = &saved_floors[i];
3171 rd_s16b(&sf_ptr->floor_id);
3172 rd_byte(&sf_ptr->savefile_id);
3173 rd_s16b(&sf_ptr->dun_level);
3174 rd_s32b(&sf_ptr->last_visit);
3175 rd_u32b(&sf_ptr->visit_mark);
3176 rd_s16b(&sf_ptr->upper_floor_id);
3177 rd_s16b(&sf_ptr->lower_floor_id);
3181 /* Move saved floors data to temporal files */
3182 for (i = 0; i < num; i++)
3184 saved_floor_type *sf_ptr = &saved_floors[i];
3187 /* Unused element */
3188 if (!sf_ptr->floor_id) continue;
3190 /* Read the failure mark */
3192 if (tmp8u) continue;
3194 /* Read from the save file */
3195 err = rd_saved_floor(sf_ptr);
3200 /* Re-save as temporal saved floor file */
3201 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3207 /* Finally load current floor data from temporal file */
3210 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3215 /*** Error messages ***/
3219 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3223 note(_("アイテム配置エラー", "Object allocation error"));
3227 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3231 note(_("モンスター配置エラー", "Monster allocation error"));
3235 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3239 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3243 note(_("Error 183", "Error 183"));
3247 /* The dungeon is ready */
3248 character_dungeon = TRUE;
3250 /* Success or Error */
3256 * Actually read the savefile
3258 static errr rd_savefile_new_aux(void)
3270 #ifdef VERIFY_CHECKSUMS
3271 u32b n_x_check, n_v_check;
3272 u32b o_x_check, o_v_check;
3276 /* Mention the savefile version */
3278 _("バージョン %d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d savefile..."),
3279 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
3282 /* Strip the version bytes */
3285 /* Hack -- decrypt */
3286 xor_byte = sf_extra;
3289 /* Clear the checksums */
3293 /* Read the version number of the savefile */
3294 /* Old savefile will be version 0.0.0.3 */
3295 rd_byte(&h_ver_extra);
3296 rd_byte(&h_ver_patch);
3297 rd_byte(&h_ver_minor);
3298 rd_byte(&h_ver_major);
3300 /* Operating system info */
3301 rd_u32b(&sf_system);
3303 /* Time of savefile creation */
3306 /* Number of resurrections */
3309 /* Number of times played */
3313 /* Later use (always zero) */
3316 /* Later use (always zero) */
3319 /* Later use (always zero) */
3323 rd_byte(&kanji_code);
3325 /* Read RNG state */
3327 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3329 /* Then the options */
3331 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3333 /* Then the "messages" */
3335 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3337 for (i = 0; i < max_r_idx; i++)
3339 /* Access that monster */
3340 monster_race *r_ptr = &r_info[i];
3342 /* Hack -- Reset the death counter */
3343 r_ptr->max_num = 100;
3345 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3347 /* Hack -- Non-unique Nazguls are semi-unique */
3348 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3351 /* Monster Memory */
3354 /* Incompatible save files */
3355 if (tmp16u > max_r_idx)
3357 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3361 /* Read the available records */
3362 for (i = 0; i < tmp16u; i++)
3368 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3373 /* Incompatible save files */
3374 if (tmp16u > max_k_idx)
3376 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3380 /* Read the object memory */
3381 for (i = 0; i < tmp16u; i++)
3384 object_kind *k_ptr = &k_info[i];
3388 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3389 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3391 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3393 /* 2.1.3 or newer version */
3395 u16b max_towns_load;
3396 u16b max_quests_load;
3397 byte max_rquests_load;
3398 s16b old_inside_quest = p_ptr->inside_quest;
3400 /* Number of towns */
3401 rd_u16b(&max_towns_load);
3403 /* Incompatible save files */
3404 if (max_towns_load > max_towns)
3406 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3410 /* Number of quests */
3411 rd_u16b(&max_quests_load);
3413 if (z_older_than(11, 0, 7))
3415 max_rquests_load = 10;
3419 rd_byte(&max_rquests_load);
3422 /* Incompatible save files */
3423 if (max_quests_load > max_quests)
3425 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3429 for (i = 0; i < max_quests_load; i++)
3433 quest_type* const q_ptr = &quest[i];
3435 rd_s16b(&q_ptr->status);
3436 rd_s16b(&q_ptr->level);
3438 if (z_older_than(11, 0, 6))
3444 rd_byte(&q_ptr->complev);
3446 if(h_older_than(2, 1, 2, 2))
3448 q_ptr->comptime = 0;
3452 rd_u32b(&q_ptr->comptime);
3455 /* Load quest status if quest is running */
3456 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3457 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3458 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3460 rd_s16b(&q_ptr->cur_num);
3461 rd_s16b(&q_ptr->max_num);
3462 rd_s16b(&q_ptr->type);
3464 /* Load quest monster index */
3465 rd_s16b(&q_ptr->r_idx);
3467 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3469 determine_random_questor(&quest[i]);
3472 /* Load quest item index */
3473 rd_s16b(&q_ptr->k_idx);
3476 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3478 rd_byte(&q_ptr->flags);
3480 if (z_older_than(10, 3, 11))
3482 if (q_ptr->flags & QUEST_FLAG_PRESET)
3488 init_flags = INIT_ASSIGN;
3489 p_ptr->inside_quest = i;
3491 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3492 p_ptr->inside_quest = old_inside_quest;
3497 rd_byte(&q_ptr->dungeon);
3500 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3501 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3502 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3505 /* Ignore the empty quests from old versions */
3508 /* Ignore quest status */
3511 /* Ignore quest level */
3515 * We don't have to care about the other info,
3516 * since status should be 0 for these quests anyway
3521 /* Quest 18 was removed */
3522 if (h_older_than(1, 7, 0, 6))
3524 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3525 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3528 /* Position in the wilderness */
3529 rd_s32b(&p_ptr->wilderness_x);
3530 rd_s32b(&p_ptr->wilderness_y);
3531 if (z_older_than(10, 3, 13))
3533 p_ptr->wilderness_x = 5;
3534 p_ptr->wilderness_y = 48;
3537 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3538 else rd_byte((byte *)&p_ptr->wild_mode);
3539 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3540 else rd_byte((byte *)&ambush_flag);
3542 /* Size of the wilderness */
3543 rd_s32b(&wild_x_size);
3544 rd_s32b(&wild_y_size);
3546 /* Incompatible save files */
3547 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3549 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3553 /* Load the wilderness seeds */
3554 for (i = 0; i < wild_x_size; i++)
3556 for (j = 0; j < wild_y_size; j++)
3558 rd_u32b(&wilderness[j][i].seed);
3563 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3565 /* Load the Artifacts */
3568 /* Incompatible save files */
3569 if (tmp16u > max_a_idx)
3571 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3575 /* Read the artifact flags */
3576 for (i = 0; i < tmp16u; i++)
3578 artifact_type *a_ptr = &a_info[i];
3581 a_ptr->cur_num = tmp8u;
3583 if (h_older_than(1, 5, 0, 0))
3585 a_ptr->floor_id = 0;
3593 rd_s16b(&a_ptr->floor_id);
3596 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3598 /* Read the extra stuff */
3600 if (p_ptr->energy_need < -999) world_player = TRUE;
3602 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3605 /* Read the player_hp array */
3608 /* Incompatible save files */
3609 if (tmp16u > PY_MAX_LEVEL)
3611 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3615 /* Read the player_hp array */
3616 for (i = 0; i < tmp16u; i++)
3618 rd_s16b(&p_ptr->player_hp[i]);
3621 /* Important -- Initialize the sex */
3622 sp_ptr = &sex_info[p_ptr->psex];
3624 /* Important -- Initialize the race/class */
3625 rp_ptr = &race_info[p_ptr->prace];
3626 cp_ptr = &class_info[p_ptr->pclass];
3627 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3629 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3631 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3632 do_cmd_rerate(FALSE);
3634 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3636 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3637 do_cmd_rerate(FALSE);
3639 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3641 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3642 do_cmd_rerate(FALSE);
3644 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3646 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3647 do_cmd_rerate(FALSE);
3650 /* Important -- Initialize the magic */
3651 mp_ptr = &m_info[p_ptr->pclass];
3654 /* Read spell info */
3655 rd_u32b(&p_ptr->spell_learned1);
3656 rd_u32b(&p_ptr->spell_learned2);
3657 rd_u32b(&p_ptr->spell_worked1);
3658 rd_u32b(&p_ptr->spell_worked2);
3659 rd_u32b(&p_ptr->spell_forgotten1);
3660 rd_u32b(&p_ptr->spell_forgotten2);
3662 if (z_older_than(10,0,5))
3664 p_ptr->learned_spells = 0;
3665 for (i = 0; i < 64; i++)
3667 /* Count known spells */
3669 (p_ptr->spell_learned1 & (1L << i)) :
3670 (p_ptr->spell_learned2 & (1L << (i - 32))))
3672 p_ptr->learned_spells++;
3676 else rd_s16b(&p_ptr->learned_spells);
3678 if (z_older_than(10,0,6))
3680 p_ptr->add_spells = 0;
3682 else rd_s16b(&p_ptr->add_spells);
3683 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3685 for (i = 0; i < 64; i++)
3687 rd_byte(&p_ptr->spell_order[i]);
3691 /* Read the inventory */
3694 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3698 /* Read number of towns */
3700 town_count = tmp16u;
3702 /* Read the stores */
3704 for (i = 1; i < town_count; i++)
3706 for (j = 0; j < tmp16u; j++)
3708 if (rd_store(i, j)) return (22);
3712 rd_s16b(&p_ptr->pet_follow_distance);
3713 if (z_older_than(10, 4, 10))
3715 p_ptr->pet_extra_flags = 0;
3717 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3719 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3721 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3725 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3728 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3732 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3735 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3739 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3742 if (!z_older_than(10,0,8))
3745 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3750 rd_s16b(&p_ptr->pet_extra_flags);
3753 if (!z_older_than(11, 0, 9))
3755 char buf[SCREEN_BUF_SIZE];
3756 rd_string(buf, sizeof(buf));
3757 if (buf[0]) screen_dump = string_make(buf);
3762 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3764 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3769 /* I'm not dead yet... */
3770 if (!p_ptr->is_dead)
3772 /* Dead players have no dungeon */
3773 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3777 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3781 /* Read the ghost info */
3788 strip_bytes(tmp32s);
3792 /* Quest 18 was removed */
3793 if (h_older_than(1, 7, 0, 6))
3795 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3797 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3799 p_ptr->inside_quest = 0;
3804 #ifdef VERIFY_CHECKSUMS
3806 /* Save the checksum */
3807 n_v_check = v_check;
3809 /* Read the old checksum */
3810 rd_u32b(&o_v_check);
3813 if (o_v_check != n_v_check)
3815 note(_("チェックサムがおかしい", "Invalid checksum"));
3820 /* Save the encoded checksum */
3821 n_x_check = x_check;
3823 /* Read the checksum */
3824 rd_u32b(&o_x_check);
3828 if (o_x_check != n_x_check)
3830 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3842 * Actually read the savefile
3844 errr rd_savefile_new(void)
3848 /* Grab permissions */
3851 /* The savefile is a binary file */
3852 fff = my_fopen(savefile, "rb");
3854 /* Drop permissions */
3858 if (!fff) return (-1);
3860 /* Call the sub-function */
3861 err = rd_savefile_new_aux();
3863 /* Check for errors */
3864 if (ferror(fff)) err = -1;
3866 /* Close the file */
3875 * Actually load and verify a floor save data
3877 static bool load_floor_aux(saved_floor_type *sf_ptr)
3882 #ifdef VERIFY_CHECKSUMS
3883 u32b n_x_check, n_v_check;
3884 u32b o_x_check, o_v_check;
3887 /* Hack -- decrypt (read xor_byte) */
3891 /* Clear the checksums */
3895 /* Set the version number to current version */
3896 /* Never load old temporal files */
3897 h_ver_extra = H_VER_EXTRA;
3898 h_ver_patch = H_VER_PATCH;
3899 h_ver_minor = H_VER_MINOR;
3900 h_ver_major = H_VER_MAJOR;
3902 /* Verify the sign */
3904 if (saved_floor_file_sign != tmp32u) return FALSE;
3906 /* Read -- have error? */
3907 if (rd_saved_floor(sf_ptr)) return FALSE;
3910 #ifdef VERIFY_CHECKSUMS
3911 /* Save the checksum */
3912 n_v_check = v_check;
3914 /* Read the old checksum */
3915 rd_u32b(&o_v_check);
3918 if (o_v_check != n_v_check) return FALSE;
3920 /* Save the encoded checksum */
3921 n_x_check = x_check;
3923 /* Read the checksum */
3924 rd_u32b(&o_x_check);
3927 if (o_x_check != n_x_check) return FALSE;
3936 * Attempt to load the temporally saved-floor data
3938 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
3940 FILE *old_fff = NULL;
3941 byte old_xor_byte = 0;
3942 u32b old_v_check = 0;
3943 u32b old_x_check = 0;
3944 byte old_h_ver_major = 0;
3945 byte old_h_ver_minor = 0;
3946 byte old_h_ver_patch = 0;
3947 byte old_h_ver_extra = 0;
3950 char floor_savefile[1024];
3952 byte old_kanji_code = kanji_code;
3955 * Temporal files are always written in system depended kanji
3960 /* EUC kanji code */
3964 /* SJIS kanji code */
3973 /* We have one file already opened */
3974 if (mode & SLF_SECOND)
3976 /* Backup original values */
3978 old_xor_byte = xor_byte;
3979 old_v_check = v_check;
3980 old_x_check = x_check;
3981 old_h_ver_major = h_ver_major;
3982 old_h_ver_minor = h_ver_minor;
3983 old_h_ver_patch = h_ver_patch;
3984 old_h_ver_extra = h_ver_extra;
3987 /* floor savefile */
3988 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3990 /* Grab permissions */
3993 /* The savefile is a binary file */
3994 fff = my_fopen(floor_savefile, "rb");
3996 /* Drop permissions */
4000 if (!fff) ok = FALSE;
4002 /* Attempt to load */
4005 /* Load saved floor data from file */
4006 ok = load_floor_aux(sf_ptr);
4008 /* Check for errors */
4009 if (ferror(fff)) ok = FALSE;
4011 /* Close the file */
4014 /* Grab permissions */
4017 /* Delete the file */
4018 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4020 /* Drop permissions */
4024 /* We have one file already opened */
4025 if (mode & SLF_SECOND)
4027 /* Restore original values */
4029 xor_byte = old_xor_byte;
4030 v_check = old_v_check;
4031 x_check = old_x_check;
4032 h_ver_major = old_h_ver_major;
4033 h_ver_minor = old_h_ver_minor;
4034 h_ver_patch = old_h_ver_patch;
4035 h_ver_extra = old_h_ver_extra;
4038 /* Restore old knowledge */
4039 kanji_code = old_kanji_code;