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.
49 #include "floor-generate.h"
57 #include "spells-status.h"
58 #include "object-hook.h"
63 #include "floor-save.h"
64 #include "floor-town.h"
68 #include "dungeon-file.h"
70 #include "player-skill.h"
71 #include "player-class.h"
73 #include "objectkind.h"
74 #include "object-ego.h"
78 * Maximum number of tries for selection of a proper quest monster
84 * Local "savefile" pointer
89 * Hack -- old "encryption" byte
94 * Hack -- simple "checksum" on the actual values
96 static u32b v_check = 0L;
99 * Hack -- simple "checksum" on the encoded bytes
101 static u32b x_check = 0L;
104 * Hack -- Japanese Kanji code
110 static byte kanji_code = 0;
113 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
114 * @param major メジャーバージョン値
115 * @param minor マイナーバージョン値
116 * @param patch パッチバージョン値
117 * @param extra エクストラパージョン値
118 * @return 現在のバージョンより値が古いならtrue
120 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
122 /* Much older, or much more recent */
123 if (h_ver_major < major) return (TRUE);
124 if (h_ver_major > major) return (FALSE);
126 /* Distinctly older, or distinctly more recent */
127 if (h_ver_minor < minor) return (TRUE);
128 if (h_ver_minor > minor) return (FALSE);
130 /* Barely older, or barely more recent */
131 if (h_ver_patch < patch) return (TRUE);
132 if (h_ver_patch > patch) return (FALSE);
134 /* Barely older, or barely more recent */
135 if (h_ver_extra < extra) return (TRUE);
136 if (h_ver_extra > extra) return (FALSE);
138 /* Identical versions */
144 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
145 * @param x メジャーバージョン値
146 * @param y マイナーバージョン値
148 * @return 現在のバージョンより値が古いならtrue
150 static bool z_older_than(byte x, byte y, byte z)
152 /* Much older, or much more recent */
153 if (z_major < x) return (TRUE);
154 if (z_major > x) return (FALSE);
156 /* Distinctly older, or distinctly more recent */
157 if (z_minor < y) return (TRUE);
158 if (z_minor > y) return (FALSE);
160 /* Barely older, or barely more recent */
161 if (z_patch < z) return (TRUE);
162 if (z_patch > z) return (FALSE);
164 /* Identical versions */
170 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
174 * Avoid the top two lines, to avoid interference with "msg_print()".
176 static void note(concptr msg)
178 static TERM_LEN y = 2;
180 /* Draw the message */
183 /* Advance one line (wrap if needed) */
184 if (++y >= 24) y = 2;
192 * @brief ロードファイルポインタから1バイトを読み込む
195 * The following functions are used to load the basic building blocks
196 * of savefiles. They also maintain the "checksum" info for 2.7.0+
198 static byte sf_get(void)
202 /* Get a character, decode the value */
203 c = getc(fff) & 0xFF;
207 /* Maintain the checksum info */
211 /* Return the value */
216 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
220 static void rd_byte(byte *ip)
226 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
230 static void rd_u16b(u16b *ip)
233 (*ip) |= ((u16b)(sf_get()) << 8);
237 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
241 static void rd_s16b(s16b *ip)
247 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
251 static void rd_u32b(u32b *ip)
254 (*ip) |= ((u32b)(sf_get()) << 8);
255 (*ip) |= ((u32b)(sf_get()) << 16);
256 (*ip) |= ((u32b)(sf_get()) << 24);
260 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
264 static void rd_s32b(s32b *ip)
271 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
272 * @param str 読み込みポインタ
273 * @param max 最大読み取りバイト数
276 static void rd_string(char *str, int max)
280 /* Read the string */
281 for (i = 0; TRUE; i++)
288 /* Collect string while legal */
289 if (i < max) str[i] = tmp8u;
300 /* Convert Kanji code */
319 /* 不明の漢字コードからシステムの漢字コードに変換 */
320 byte code = codeconv(str);
322 /* 漢字コードが判明したら、それを記録 */
323 if (code) kanji_code = code;
328 /* No conversion needed */
336 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
340 static void strip_bytes(int n)
344 /* Strip the bytes */
345 while (n--) rd_byte(&tmp8u);
348 #define OLD_MAX_MANE 22
351 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
352 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
355 * This function attempts to "repair" old savefiles, and to extract
356 * the most up to date values for various object fields.
358 * Note that Angband 2.7.9 introduced a new method for object "flags"
359 * in which the "flags" on an object are actually extracted when they
360 * are needed from the object kind, artifact index, ego-item index,
361 * and two special "xtra" fields which are used to encode any "extra"
362 * power of certain ego-items. This had the side effect that items
363 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
364 * may have had, and also, all "uncursed" items will become "cursed"
365 * again, including Calris, even if it is being worn at the time. As
366 * a complete hack, items which are inscribed with "uncursed" will be
367 * "uncursed" when imported from pre-2.7.9 savefiles.
369 static void rd_item_old(object_type *o_ptr)
377 rd_s16b(&o_ptr->k_idx);
380 o_ptr->iy = (POSITION)tmp8u;
382 o_ptr->ix = (POSITION)tmp8u;
390 if (z_older_than(10, 4, 4))
392 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
393 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
394 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
398 rd_s16b(&o_ptr->pval);
400 rd_byte(&o_ptr->discount);
402 o_ptr->number = (ITEM_NUMBER)tmp8u;
405 o_ptr->weight = tmp16s;
408 o_ptr->name1 = tmp8u;
411 o_ptr->name2 = tmp8u;
413 rd_s16b(&o_ptr->timeout);
415 rd_s16b(&o_ptr->to_h);
418 o_ptr->to_d = tmp16s;
419 rd_s16b(&o_ptr->to_a);
428 rd_byte(&o_ptr->ident);
430 rd_byte(&o_ptr->marked);
433 rd_u32b(&o_ptr->art_flags[0]);
434 rd_u32b(&o_ptr->art_flags[1]);
435 rd_u32b(&o_ptr->art_flags[2]);
436 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
437 else rd_u32b(&o_ptr->art_flags[3]);
439 if (h_older_than(1, 3, 0, 0))
441 if (o_ptr->name2 == EGO_TELEPATHY)
442 add_flag(o_ptr->art_flags, TR_TELEPATHY);
445 if (z_older_than(11, 0, 11))
447 o_ptr->curse_flags = 0L;
448 if (o_ptr->ident & 0x40)
450 o_ptr->curse_flags |= TRC_CURSED;
451 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
452 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
453 if (object_is_fixed_artifact(o_ptr))
455 artifact_type *a_ptr = &a_info[o_ptr->name1];
456 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
457 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
459 else if (object_is_ego(o_ptr))
461 ego_item_type *e_ptr = &e_info[o_ptr->name2];
462 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
463 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
466 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
470 rd_u32b(&o_ptr->curse_flags);
473 /* Monster holding object */
474 rd_s16b(&o_ptr->held_m_idx);
477 rd_byte(&o_ptr->xtra1);
478 rd_byte(&o_ptr->xtra2);
480 if (z_older_than(11, 0, 10))
482 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
484 switch (o_ptr->xtra2 % 6)
486 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
487 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
488 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
489 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
490 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
491 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
495 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
497 switch (o_ptr->xtra2 % 11)
499 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
500 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
501 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
502 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
503 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
504 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
505 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
506 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
507 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
508 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
509 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
513 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
515 switch (o_ptr->xtra2 % 8)
517 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
518 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
519 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
520 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
521 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
522 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
523 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
524 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
531 if (z_older_than(10, 2, 3))
536 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
538 o_ptr->xtra3 = o_ptr->xtra1;
541 if (o_ptr->tval == TV_CAPTURE)
543 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
544 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
546 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
547 if (ironman_nightmare)
549 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
551 o_ptr->xtra4 = o_ptr->xtra5;
556 rd_byte(&o_ptr->xtra3);
557 if (h_older_than(1, 3, 0, 1))
559 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
560 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
563 rd_s16b(&o_ptr->xtra4);
564 rd_s16b(&o_ptr->xtra5);
567 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)))
569 o_ptr->xtra4 = o_ptr->pval;
573 rd_byte(&o_ptr->feeling);
576 rd_string(buf, sizeof(buf));
578 /* Save the inscription */
579 if (buf[0]) o_ptr->inscription = quark_add(buf);
581 rd_string(buf, sizeof(buf));
582 if (buf[0]) o_ptr->art_name = quark_add(buf);
584 /* The Python object */
592 /* Mega-Hack -- handle "dungeon objects" later */
593 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
595 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
597 if (z_older_than(10, 4, 9))
599 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
601 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
602 add_flag(o_ptr->art_flags, TR_DEC_MANA);
605 if (object_is_fixed_artifact(o_ptr))
607 artifact_type *a_ptr;
609 /* Obtain the artifact info */
610 a_ptr = &a_info[o_ptr->name1];
612 /* Verify that artifact */
613 if (!a_ptr->name) o_ptr->name1 = 0;
615 if (object_is_ego(o_ptr))
617 ego_item_type *e_ptr;
619 /* Obtain the ego-item info */
620 e_ptr = &e_info[o_ptr->name2];
622 /* Verify that ego-item */
623 if (!e_ptr->name) o_ptr->name2 = 0;
630 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
631 * @param o_ptr アイテムオブジェクト保存先ポインタ
634 static void rd_item(object_type *o_ptr)
642 if (h_older_than(1, 5, 0, 0))
648 /*** Item save flags ***/
651 /*** Read un-obvious elements ***/
653 rd_s16b(&o_ptr->k_idx);
656 o_ptr->iy = (POSITION)tmp8u;
658 o_ptr->ix = (POSITION)tmp8u;
661 k_ptr = &k_info[o_ptr->k_idx];
662 o_ptr->tval = k_ptr->tval;
663 o_ptr->sval = k_ptr->sval;
666 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
667 else o_ptr->pval = 0;
669 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
670 else o_ptr->discount = 0;
671 if (flags & SAVE_ITEM_NUMBER) {
673 o_ptr->number = tmp8u;
675 else o_ptr->number = 1;
678 o_ptr->weight = tmp16s;
680 if (flags & SAVE_ITEM_NAME1)
683 o_ptr->name1 = tmp8u;
685 else o_ptr->name1 = 0;
686 if (flags & SAVE_ITEM_NAME2)
689 o_ptr->name2 = tmp8u;
691 else o_ptr->name2 = 0;
692 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
693 else o_ptr->timeout = 0;
695 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
696 else o_ptr->to_h = 0;
697 if (flags & SAVE_ITEM_TO_D)
700 o_ptr->to_d = tmp16s;
702 else o_ptr->to_d = 0;
703 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
704 else o_ptr->to_a = 0;
706 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
709 if (flags & SAVE_ITEM_DD)
715 if (flags & SAVE_ITEM_DS)
722 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
723 else o_ptr->ident = 0;
725 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
726 else o_ptr->marked = 0;
729 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
730 else o_ptr->art_flags[0] = 0;
731 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
732 else o_ptr->art_flags[1] = 0;
733 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
734 else o_ptr->art_flags[2] = 0;
735 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
736 else o_ptr->art_flags[3] = 0;
737 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
738 else o_ptr->art_flags[4] = 0;
740 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
741 else o_ptr->curse_flags = 0;
743 /* Monster holding object */
744 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
745 else o_ptr->held_m_idx = 0;
748 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
749 else o_ptr->xtra1 = 0;
750 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
751 else o_ptr->xtra2 = 0;
753 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
754 else o_ptr->xtra3 = 0;
756 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
757 else o_ptr->xtra4 = 0;
758 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
759 else o_ptr->xtra5 = 0;
761 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
762 else o_ptr->feeling = 0;
764 if (flags & SAVE_ITEM_INSCRIPTION)
766 rd_string(buf, sizeof(buf));
767 o_ptr->inscription = quark_add(buf);
769 else o_ptr->inscription = 0;
771 if (flags & SAVE_ITEM_ART_NAME)
773 rd_string(buf, sizeof(buf));
774 o_ptr->art_name = quark_add(buf);
776 else o_ptr->art_name = 0;
778 if(h_older_than(2,1,2,4))
780 BIT_FLAGS flgs[TR_FLAG_SIZE];
781 object_flags(o_ptr, flgs);
783 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
785 add_flag(o_ptr->art_flags, TR_LITE_M1);
786 remove_flag(o_ptr->art_flags, TR_LITE_1);
787 remove_flag(o_ptr->art_flags, TR_LITE_2);
788 remove_flag(o_ptr->art_flags, TR_LITE_3);
790 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
792 if (o_ptr->tval == TV_LITE)
794 if (o_ptr->sval == SV_LITE_TORCH)
796 add_flag(o_ptr->art_flags, TR_LITE_M1);
798 else if (o_ptr->sval == SV_LITE_LANTERN)
800 add_flag(o_ptr->art_flags, TR_LITE_M2);
802 else if (o_ptr->sval == SV_LITE_FEANOR)
804 add_flag(o_ptr->art_flags, TR_LITE_M3);
809 add_flag(o_ptr->art_flags, TR_LITE_M1);
812 else if (o_ptr->tval == TV_LITE)
814 if (object_is_fixed_artifact(o_ptr))
816 add_flag(o_ptr->art_flags, TR_LITE_3);
818 else if (o_ptr->sval == SV_LITE_TORCH)
820 add_flag(o_ptr->art_flags, TR_LITE_1);
821 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
823 else if (o_ptr->sval == SV_LITE_LANTERN)
825 add_flag(o_ptr->art_flags, TR_LITE_2);
826 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
828 else if (o_ptr->sval == SV_LITE_FEANOR)
830 add_flag(o_ptr->art_flags, TR_LITE_2);
838 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
839 * @param m_ptr モンスター保存先ポインタ
842 static void rd_monster_old(monster_type *m_ptr)
849 /* Read the monster race */
850 rd_s16b(&m_ptr->r_idx);
852 if (z_older_than(11, 0, 12))
853 m_ptr->ap_r_idx = m_ptr->r_idx;
855 rd_s16b(&m_ptr->ap_r_idx);
857 if (z_older_than(11, 0, 14))
859 monster_race *r_ptr = &r_info[m_ptr->r_idx];
861 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
862 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
863 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
866 rd_byte(&m_ptr->sub_align);
868 /* Read the other information */
870 m_ptr->fy = (POSITION)tmp8u;
872 m_ptr->fx = (POSITION)tmp8u;
877 m_ptr->maxhp = tmp16s;
879 if (z_older_than(11, 0, 5))
881 m_ptr->max_maxhp = m_ptr->maxhp;
886 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
888 if(h_older_than(2, 1, 2, 1))
890 m_ptr->dealt_damage = 0;
894 rd_s32b(&m_ptr->dealt_damage);
897 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
900 m_ptr->mspeed = tmp8u;
902 if (z_older_than(10, 4, 2))
905 m_ptr->energy_need = (s16b)tmp8u;
907 else rd_s16b(&m_ptr->energy_need);
909 if (z_older_than(11, 0, 13))
910 m_ptr->energy_need = 100 - m_ptr->energy_need;
912 if (z_older_than(10,0,7))
914 m_ptr->mtimed[MTIMED_FAST] = 0;
915 m_ptr->mtimed[MTIMED_SLOW] = 0;
920 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
922 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
925 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
927 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
929 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
931 if (z_older_than(10,0,10))
935 else if (z_older_than(10,0,11))
943 m_ptr->target_y = (POSITION)tmp16s;
945 m_ptr->target_x = (POSITION)tmp16s;
949 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
951 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
952 rd_u32b(&m_ptr->smart);
956 if (z_older_than(10, 4, 5)) {
963 if (z_older_than(10, 2, 2))
965 if (m_ptr->r_idx < 0)
967 m_ptr->r_idx = (0-m_ptr->r_idx);
968 m_ptr->mflag2 |= MFLAG2_KAGE;
973 rd_byte(&m_ptr->mflag2);
976 if (z_older_than(11, 0, 12))
978 if (m_ptr->mflag2 & MFLAG2_KAGE)
979 m_ptr->ap_r_idx = MON_KAGE;
982 if (z_older_than(10, 1, 3))
988 rd_string(buf, sizeof(buf));
989 if (buf[0]) m_ptr->nickname = quark_add(buf);
997 * @brief モンスターを読み込む(現版) / Read a monster (New method)
998 * @param m_ptr モンスター保存先ポインタ
1001 static void rd_monster(monster_type *m_ptr)
1009 if (h_older_than(1, 5, 0, 0))
1011 rd_monster_old(m_ptr);
1015 /*** Monster save flags ***/
1018 /*** Read un-obvious elements ***/
1020 /* Read the monster race */
1021 rd_s16b(&m_ptr->r_idx);
1023 /* Read the other information */
1025 m_ptr->fy = (POSITION)tmp8u;
1027 m_ptr->fx = (POSITION)tmp8u;
1030 m_ptr->hp = (HIT_POINT)tmp16s;
1032 m_ptr->maxhp = (HIT_POINT)tmp16s;
1034 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1036 if(h_older_than(2, 1, 2, 1))
1038 m_ptr->dealt_damage = 0;
1042 rd_s32b(&m_ptr->dealt_damage);
1045 /* Monster race index of its appearance */
1046 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1047 else m_ptr->ap_r_idx = m_ptr->r_idx;
1049 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1050 else m_ptr->sub_align = 0;
1052 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1053 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1056 m_ptr->mspeed = tmp8u;
1058 rd_s16b(&m_ptr->energy_need);
1060 if (flags & SAVE_MON_FAST)
1063 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1065 else m_ptr->mtimed[MTIMED_FAST] = 0;
1066 if (flags & SAVE_MON_SLOW)
1069 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1071 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1072 if (flags & SAVE_MON_STUNNED)
1075 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1077 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1078 if (flags & SAVE_MON_CONFUSED)
1081 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1083 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1084 if (flags & SAVE_MON_MONFEAR)
1087 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1089 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1091 if (flags & SAVE_MON_TARGET_Y)
1094 m_ptr->target_y = (POSITION)tmp16s;
1096 else m_ptr->target_y = 0;
1097 if (flags & SAVE_MON_TARGET_X)
1100 m_ptr->target_x = (POSITION)tmp16s;
1102 else m_ptr->target_x = 0;
1104 if (flags & SAVE_MON_INVULNER)
1107 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1109 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1111 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1112 else m_ptr->smart = 0;
1114 if (flags & SAVE_MON_EXP)
1117 m_ptr->exp = (EXP)tmp32u;
1119 else m_ptr->exp = 0;
1121 m_ptr->mflag = 0; /* Not saved */
1123 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1124 else m_ptr->mflag2 = 0;
1126 if (flags & SAVE_MON_NICKNAME)
1128 rd_string(buf, sizeof(buf));
1129 m_ptr->nickname = quark_add(buf);
1131 else m_ptr->nickname = 0;
1133 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1134 else m_ptr->parent_m_idx = 0;
1139 * Old monster bit flags of racial resistances
1141 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1142 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1143 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1144 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1145 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1146 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1147 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1148 #define RF3_RES_WATE 0x00800000 /* Resist water */
1149 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1150 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1151 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1152 #define RF3_RES_ALL 0x08000000 /* Resist all */
1154 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1156 if ((R_PTR)->r_flags3 & (RF3)) \
1158 (R_PTR)->r_flags3 &= ~(RF3); \
1159 (R_PTR)->r_flagsr |= (RFR); \
1163 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1165 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1167 (R_PTR)->r_flagsr |= (RFR); \
1171 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1172 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1173 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1174 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1175 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1176 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1177 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1178 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1179 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1180 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1183 * @brief モンスターの思い出を読み込む / Read the monster lore
1184 * @param r_idx 読み込み先モンスターID
1187 static void rd_lore(MONRACE_IDX r_idx)
1192 monster_race *r_ptr = &r_info[r_idx];
1194 /* Count sights/deaths/kills */
1196 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1198 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1200 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1201 if (h_older_than(1, 7, 0, 5))
1203 r_ptr->r_akills = r_ptr->r_pkills;
1208 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1211 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1213 /* Count wakes and ignores */
1214 rd_byte(&r_ptr->r_wake);
1215 rd_byte(&r_ptr->r_ignore);
1218 rd_byte(&r_ptr->r_xtra1);
1219 rd_byte(&r_ptr->r_xtra2);
1223 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1225 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1229 rd_byte(&r_ptr->r_cast_spell);
1231 /* Count blows of each type */
1232 rd_byte(&r_ptr->r_blows[0]);
1233 rd_byte(&r_ptr->r_blows[1]);
1234 rd_byte(&r_ptr->r_blows[2]);
1235 rd_byte(&r_ptr->r_blows[3]);
1237 /* Memorize flags */
1238 rd_u32b(&r_ptr->r_flags1);
1239 rd_u32b(&r_ptr->r_flags2);
1240 rd_u32b(&r_ptr->r_flags3);
1241 rd_u32b(&r_ptr->r_flags4);
1242 rd_u32b(&r_ptr->r_flags5);
1243 rd_u32b(&r_ptr->r_flags6);
1244 if (h_older_than(1, 5, 0, 3))
1246 r_ptr->r_flagsr = 0L;
1248 /* Move RF3 resistance flags to RFR */
1249 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1250 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1251 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1252 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1253 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1254 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1255 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1256 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1257 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1258 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1259 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1260 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1262 /* Separate breathers resistance from RF4 to RFR */
1263 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1264 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1265 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1266 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1267 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1268 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1269 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1270 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1271 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1273 /* Resist confusion is merged to RF3_NO_CONF */
1274 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1276 /* Misc resistance hack to RFR */
1277 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1278 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1282 rd_u32b(&r_ptr->r_flagsr);
1285 /* Read the "Racial" monster limit per level */
1287 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1289 /* Location in saved floor */
1290 rd_s16b(&r_ptr->floor_id);
1295 /* Repair the lore flags */
1296 r_ptr->r_flags1 &= r_ptr->flags1;
1297 r_ptr->r_flags2 &= r_ptr->flags2;
1298 r_ptr->r_flags3 &= r_ptr->flags3;
1299 r_ptr->r_flags4 &= r_ptr->flags4;
1300 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1301 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1302 r_ptr->r_flagsr &= r_ptr->flagsr;
1306 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the p_ptr->inventory_list of the "Home"
1307 * @param st_ptr 店舗の参照ポインタ
1308 * @param o_ptr アイテムオブジェクト参照ポインタ
1311 * In all cases, return the slot (or -1) where the object was placed
1313 * Note that this is a hacked up version of "inven_carry()".
1315 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1316 * known, the player may have to pick stuff up and drop it again.
1318 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1326 /* Check each existing item (try to combine) */
1327 for (slot = 0; slot < st_ptr->stock_num; slot++)
1329 /* Get the existing item */
1330 j_ptr = &st_ptr->stock[slot];
1332 /* The home acts just like the player */
1333 if (object_similar(j_ptr, o_ptr))
1335 /* Save the new number of items */
1336 object_absorb(j_ptr, o_ptr);
1344 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1348 /* Determine the "value" of the item */
1349 value = object_value(o_ptr);
1351 /* Check existing slots to see if we must "slide" */
1352 for (slot = 0; slot < st_ptr->stock_num; slot++)
1354 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1357 /* Slide the others up */
1358 for (i = st_ptr->stock_num; i > slot; i--)
1360 st_ptr->stock[i] = st_ptr->stock[i-1];
1363 /* More stuff now */
1364 st_ptr->stock_num++;
1366 /* Insert the new item */
1367 st_ptr->stock[slot] = *o_ptr;
1369 chg_virtue(V_SACRIFICE, -1);
1371 /* Return the location */
1376 * @brief 店舗情報を読み込む / Read a store
1377 * @param town_number 街ID
1378 * @param store_number 店舗ID
1381 static errr rd_store(int town_number, int store_number)
1393 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1395 st_ptr = &town_info[1].store[store_number];
1396 if (st_ptr->stock_num) sort = TRUE;
1400 st_ptr = &town_info[town_number].store[store_number];
1403 /* Read the basic info */
1404 rd_s32b(&st_ptr->store_open);
1405 rd_s16b(&st_ptr->insult_cur);
1407 if (z_older_than(11, 0, 4))
1416 rd_s16b(&st_ptr->good_buy);
1417 rd_s16b(&st_ptr->bad_buy);
1419 /* Read last visit */
1420 rd_s32b(&st_ptr->last_visit);
1422 /* Extract the owner (see above) */
1423 st_ptr->owner = own;
1425 /* Read the items */
1426 for (j = 0; j < num; j++)
1436 /* Acquire valid items */
1437 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1442 home_carry(st_ptr, q_ptr);
1446 k = st_ptr->stock_num++;
1448 /* Acquire the item */
1449 object_copy(&st_ptr->stock[k], q_ptr);
1460 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1463 static void rd_randomizer(void)
1473 rd_u16b(&Rand_place);
1476 for (i = 0; i < RAND_DEG; i++)
1478 rd_u32b(&Rand_state[i]);
1485 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1488 * Note that the normal options are now stored as a set of 256 bit flags,
1489 * plus a set of 256 bit masks to indicate which bit flags were defined
1490 * at the time the savefile was created. This will allow new options
1491 * to be added, and old options to be removed, at any time, without
1492 * hurting old savefiles.
1494 * The window options are stored in the same way, but note that each
1495 * window gets 32 options, and their order is fixed by certain defines.
1497 static void rd_options(void)
1506 /* Ignore old options */
1509 /*** Special info */
1511 /* Read "delay_factor" */
1515 /* Read "hitpoint_warn" */
1519 /* Read "mana_warn" */
1520 if(h_older_than(1, 7, 0, 0))
1530 /*** Cheating options ***/
1534 if (c & 0x0002) p_ptr->wizard = TRUE;
1536 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1537 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1538 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1539 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1540 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1541 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1542 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1543 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1544 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1545 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1547 rd_byte((byte *)&autosave_l);
1548 rd_byte((byte *)&autosave_t);
1549 rd_s16b(&autosave_freq);
1552 /*** Normal Options ***/
1554 /* Read the option flags */
1555 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1557 /* Read the option masks */
1558 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1560 /* Analyze the options */
1561 for (n = 0; n < 8; n++)
1563 /* Analyze the options */
1564 for (i = 0; i < 32; i++)
1566 /* Process valid flags */
1567 if (mask[n] & (1L << i))
1569 /* Process valid flags */
1570 if (option_mask[n] & (1L << i))
1573 if (flag[n] & (1L << i))
1576 option_flag[n] |= (1L << i);
1583 option_flag[n] &= ~(1L << i);
1590 if (z_older_than(10, 4, 5))
1592 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1593 else option_flag[5] |= (0x00000001 << 4);
1594 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1595 else option_flag[2] |= (0x00000001 << 5);
1596 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1597 else option_flag[4] |= (0x00000001 << 5);
1598 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1599 else option_flag[5] |= (0x00000001 << 0);
1600 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1601 else option_flag[5] |= (0x00000001 << 12);
1602 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1603 else option_flag[1] |= (0x00000001 << 0);
1604 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1605 else option_flag[1] |= (0x00000001 << 18);
1606 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1607 else option_flag[1] |= (0x00000001 << 19);
1608 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1609 else option_flag[5] |= (0x00000001 << 3);
1612 /* Extract the options */
1613 extract_option_vars();
1616 /*** Window Options ***/
1618 /* Read the window flags */
1619 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1621 /* Read the window masks */
1622 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1624 /* Analyze the options */
1625 for (n = 0; n < 8; n++)
1627 /* Analyze the options */
1628 for (i = 0; i < 32; i++)
1630 /* Process valid flags */
1631 if (mask[n] & (1L << i))
1633 /* Process valid flags */
1634 if (window_mask[n] & (1L << i))
1637 if (flag[n] & (1L << i))
1640 window_flag[n] |= (1L << i);
1647 window_flag[n] &= ~(1L << i);
1658 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1661 * This is such a nasty hack it hurts.
1663 static void rd_ghost(void)
1668 rd_string(buf, sizeof(buf));
1670 /* Strip old data */
1676 * @brief クイックスタート情報を読み込む / Load quick start data
1679 static void load_quick_start(void)
1685 if (z_older_than(11, 0, 13))
1687 previous_char.quick_ok = FALSE;
1691 rd_byte(&previous_char.psex);
1693 previous_char.prace = (RACE_IDX)tmp8u;
1695 previous_char.pclass = (CLASS_IDX)tmp8u;
1697 previous_char.pseikaku = (CHARACTER_IDX)tmp8u;
1699 previous_char.realm1 = (REALM_IDX)tmp8u;
1701 previous_char.realm2 = (REALM_IDX)tmp8u;
1703 rd_s16b(&previous_char.age);
1704 rd_s16b(&previous_char.ht);
1705 rd_s16b(&previous_char.wt);
1706 rd_s16b(&previous_char.sc);
1707 rd_s32b(&previous_char.au);
1709 for (i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1710 for (i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1712 for (i = 0; i < PY_MAX_LEVEL; i++)
1715 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1718 rd_s16b(&previous_char.chaos_patron);
1720 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1722 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1724 /* UNUSED : Was number of random quests */
1728 previous_char.quick_ok = (bool)tmp8u;
1732 * @brief その他の情報を読み込む / Read the "extra" information
1735 static void rd_extra(void)
1744 rd_string(p_ptr->name, sizeof(p_ptr->name));
1746 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1748 if (!h_older_than(1, 7, 0, 1))
1752 /* Read the message */
1753 rd_string(buf, sizeof buf);
1754 if (buf[0]) p_ptr->last_message = string_make(buf);
1759 for (i = 0; i < 4; i++)
1761 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1764 /* Class/Race/Seikaku/Gender/Spells */
1766 p_ptr->prace = (RACE_IDX)tmp8u;
1768 p_ptr->pclass = (CLASS_IDX)tmp8u;
1770 p_ptr->pseikaku = (CHARACTER_IDX)tmp8u;
1771 rd_byte(&p_ptr->psex);
1773 p_ptr->realm1 = (REALM_IDX)tmp8u;
1775 p_ptr->realm2 = (REALM_IDX)tmp8u;
1778 if (z_older_than(10, 4, 4))
1780 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1781 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1782 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1783 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1786 /* Special Race/Class info */
1788 p_ptr->hitdie = tmp8u;
1789 rd_u16b(&p_ptr->expfact);
1791 /* Age/Height/Weight */
1792 rd_s16b(&p_ptr->age);
1793 rd_s16b(&p_ptr->ht);
1794 rd_s16b(&p_ptr->wt);
1796 /* Read the stat info */
1797 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_max[i]);
1798 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1799 for (i = 0; i < A_MAX; i++) rd_s16b(&p_ptr->stat_cur[i]);
1802 rd_s32b(&p_ptr->au);
1804 rd_s32b(&p_ptr->max_exp);
1805 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1806 else rd_s32b(&p_ptr->max_max_exp);
1807 rd_s32b(&p_ptr->exp);
1809 if (h_older_than(1, 7, 0, 3))
1812 p_ptr->exp_frac = (u32b)tmp16u;
1816 rd_u32b(&p_ptr->exp_frac);
1819 rd_s16b(&p_ptr->lev);
1821 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1822 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1824 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1826 if (z_older_than(10, 3, 6))
1827 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1829 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1830 for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1831 if (z_older_than(10, 4, 1))
1833 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1834 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1836 if (z_older_than(10, 3, 14))
1838 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1839 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1843 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1844 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1845 if (h_older_than(1, 3, 0, 1))
1847 if (p_ptr->pclass == CLASS_SMITH)
1849 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1850 p_ptr->magic_num1[96] = 0;
1851 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1852 p_ptr->magic_num1[97] = 0;
1856 if (music_singing_any()) p_ptr->action = ACTION_SING;
1858 if (z_older_than(11, 0, 7))
1860 p_ptr->start_race = p_ptr->prace;
1861 p_ptr->old_race1 = 0L;
1862 p_ptr->old_race2 = 0L;
1863 p_ptr->old_realm = 0;
1868 p_ptr->start_race = (RACE_IDX)tmp8u;
1870 p_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1872 p_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1873 rd_s16b(&p_ptr->old_realm);
1876 if (z_older_than(10, 0, 1))
1878 for (i = 0; i < MAX_MANE; i++)
1880 p_ptr->mane_spell[i] = -1;
1881 p_ptr->mane_dam[i] = 0;
1883 p_ptr->mane_num = 0;
1885 else if (z_older_than(10, 2, 3))
1887 for (i = 0; i < OLD_MAX_MANE; i++)
1892 for (i = 0; i < MAX_MANE; i++)
1894 p_ptr->mane_spell[i] = -1;
1895 p_ptr->mane_dam[i] = 0;
1898 p_ptr->mane_num = 0;
1902 for (i = 0; i < MAX_MANE; i++)
1905 p_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1907 p_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1909 rd_s16b(&p_ptr->mane_num);
1912 if (z_older_than(10, 0, 3))
1914 determine_bounty_uniques();
1916 for (i = 0; i < MAX_KUBI; i++)
1918 /* Is this bounty unique already dead? */
1919 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1924 for (i = 0; i < MAX_KUBI; i++)
1926 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1930 if (z_older_than(10, 0, 3))
1932 update_gambling_monsters();
1936 for (i = 0; i < 4; i++)
1938 rd_s16b(&battle_mon[i]);
1939 if (z_older_than(10, 3, 4))
1942 mon_odds[i] = tmp16s;
1944 else rd_u32b(&mon_odds[i]);
1948 rd_s16b(&p_ptr->town_num);
1950 /* Read arena and rewards information */
1951 rd_s16b(&p_ptr->arena_number);
1952 if (h_older_than(1, 5, 0, 1))
1954 /* Arena loser of previous version was marked number 99 */
1955 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1958 p_ptr->inside_arena = (bool)tmp16s;
1959 rd_s16b(&p_ptr->inside_quest);
1960 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1964 p_ptr->inside_battle = (bool)tmp16s;
1966 rd_byte(&p_ptr->exit_bldg);
1970 p_ptr->oldpx = (POSITION)tmp16s;
1972 p_ptr->oldpy = (POSITION)tmp16s;
1974 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1976 /* Was p_ptr->rewards[MAX_BACT] */
1978 for (i = 0; i < tmp16s; i++)
1984 if (h_older_than(1, 7, 0, 3))
1987 p_ptr->mhp = tmp16s;
1990 p_ptr->chp = tmp16s;
1993 p_ptr->chp_frac = (u32b)tmp16u;
1997 rd_s32b(&p_ptr->mhp);
1998 rd_s32b(&p_ptr->chp);
1999 rd_u32b(&p_ptr->chp_frac);
2002 if (h_older_than(1, 7, 0, 3))
2005 p_ptr->msp = tmp16s;
2008 p_ptr->csp = tmp16s;
2011 p_ptr->csp_frac = (u32b)tmp16u;
2015 rd_s32b(&p_ptr->msp);
2016 rd_s32b(&p_ptr->csp);
2017 rd_u32b(&p_ptr->csp_frac);
2020 rd_s16b(&p_ptr->max_plv);
2021 if (z_older_than(10, 3, 8))
2024 max_dlv[DUNGEON_ANGBAND] = tmp16s;
2028 byte max = (byte)max_d_idx;
2032 for(i = 0; i < max; i++)
2035 max_dlv[i] = tmp16s;
2036 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
2040 /* Repair maximum player level */
2041 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
2045 rd_s16b(&p_ptr->sc);
2046 rd_s16b(&p_ptr->concent);
2048 /* Read the flags */
2049 strip_bytes(2); /* Old "rest" */
2050 rd_s16b(&p_ptr->blind);
2051 rd_s16b(&p_ptr->paralyzed);
2052 rd_s16b(&p_ptr->confused);
2053 rd_s16b(&p_ptr->food);
2054 strip_bytes(4); /* Old "food_digested" / "protection" */
2056 rd_s16b(&p_ptr->energy_need);
2057 if (z_older_than(11, 0, 13))
2058 p_ptr->energy_need = 100 - p_ptr->energy_need;
2059 if (h_older_than(2, 1, 2, 0))
2060 p_ptr->enchant_energy_need = 0;
2062 rd_s16b(&p_ptr->enchant_energy_need);
2064 rd_s16b(&p_ptr->fast);
2065 rd_s16b(&p_ptr->slow);
2066 rd_s16b(&p_ptr->afraid);
2067 rd_s16b(&p_ptr->cut);
2068 rd_s16b(&p_ptr->stun);
2069 rd_s16b(&p_ptr->poisoned);
2070 rd_s16b(&p_ptr->image);
2071 rd_s16b(&p_ptr->protevil);
2072 rd_s16b(&p_ptr->invuln);
2073 if(z_older_than(10, 0, 0))
2076 rd_s16b(&p_ptr->ult_res);
2077 rd_s16b(&p_ptr->hero);
2078 rd_s16b(&p_ptr->shero);
2079 rd_s16b(&p_ptr->shield);
2080 rd_s16b(&p_ptr->blessed);
2081 rd_s16b(&p_ptr->tim_invis);
2082 rd_s16b(&p_ptr->word_recall);
2083 if (z_older_than(10, 3, 8))
2084 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2088 p_ptr->recall_dungeon = (byte)tmp16s;
2091 if (h_older_than(1, 5, 0, 0))
2092 p_ptr->alter_reality = 0;
2094 rd_s16b(&p_ptr->alter_reality);
2096 rd_s16b(&p_ptr->see_infra);
2097 rd_s16b(&p_ptr->tim_infra);
2098 rd_s16b(&p_ptr->oppose_fire);
2099 rd_s16b(&p_ptr->oppose_cold);
2100 rd_s16b(&p_ptr->oppose_acid);
2101 rd_s16b(&p_ptr->oppose_elec);
2102 rd_s16b(&p_ptr->oppose_pois);
2103 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2104 else rd_s16b(&p_ptr->tsuyoshi);
2106 /* Old savefiles do not have the following fields... */
2107 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2110 p_ptr->wraith_form = 0;
2111 p_ptr->resist_magic = 0;
2112 p_ptr->tim_regen = 0;
2113 p_ptr->kabenuke = 0;
2114 p_ptr->tim_stealth = 0;
2115 p_ptr->tim_levitation = 0;
2116 p_ptr->tim_sh_touki = 0;
2117 p_ptr->lightspeed = 0;
2118 p_ptr->tsubureru = 0;
2119 p_ptr->tim_res_nether = 0;
2120 p_ptr->tim_res_time = 0;
2121 p_ptr->mimic_form = 0;
2122 p_ptr->tim_mimic = 0;
2123 p_ptr->tim_sh_fire = 0;
2126 p_ptr->tim_reflect = 0;
2127 p_ptr->multishadow = 0;
2128 p_ptr->dustrobe = 0;
2130 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2138 rd_s16b(&p_ptr->tim_esp);
2139 rd_s16b(&p_ptr->wraith_form);
2140 rd_s16b(&p_ptr->resist_magic);
2141 rd_s16b(&p_ptr->tim_regen);
2142 rd_s16b(&p_ptr->kabenuke);
2143 rd_s16b(&p_ptr->tim_stealth);
2144 rd_s16b(&p_ptr->tim_levitation);
2145 rd_s16b(&p_ptr->tim_sh_touki);
2146 rd_s16b(&p_ptr->lightspeed);
2147 rd_s16b(&p_ptr->tsubureru);
2148 if (z_older_than(10, 4, 7))
2149 p_ptr->magicdef = 0;
2151 rd_s16b(&p_ptr->magicdef);
2152 rd_s16b(&p_ptr->tim_res_nether);
2153 if (z_older_than(10, 4, 11))
2155 p_ptr->tim_res_time = 0;
2156 p_ptr->mimic_form = 0;
2157 p_ptr->tim_mimic = 0;
2158 p_ptr->tim_sh_fire = 0;
2162 rd_s16b(&p_ptr->tim_res_time);
2164 p_ptr->mimic_form = (IDX)tmp8u;
2165 rd_s16b(&p_ptr->tim_mimic);
2166 rd_s16b(&p_ptr->tim_sh_fire);
2169 if (z_older_than(11, 0, 99))
2171 p_ptr->tim_sh_holy = 0;
2172 p_ptr->tim_eyeeye = 0;
2176 rd_s16b(&p_ptr->tim_sh_holy);
2177 rd_s16b(&p_ptr->tim_eyeeye);
2181 if ( z_older_than(11,0,3) ){
2182 p_ptr->tim_reflect=0;
2183 p_ptr->multishadow=0;
2187 rd_s16b(&p_ptr->tim_reflect);
2188 rd_s16b(&p_ptr->multishadow);
2189 rd_s16b(&p_ptr->dustrobe);
2192 rd_s16b(&p_ptr->chaos_patron);
2193 rd_u32b(&p_ptr->muta1);
2194 rd_u32b(&p_ptr->muta2);
2195 rd_u32b(&p_ptr->muta3);
2197 for (i = 0; i < 8; i++)
2198 rd_s16b(&p_ptr->virtues[i]);
2199 for (i = 0; i < 8; i++)
2200 rd_s16b(&p_ptr->vir_types[i]);
2203 /* Calc the regeneration modifier for mutations */
2204 p_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod();
2206 if (z_older_than(10,0,9))
2209 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2210 p_ptr->ele_attack = 0;
2214 rd_s16b(&p_ptr->ele_attack);
2215 rd_u32b(&p_ptr->special_attack);
2217 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2218 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2219 if (z_older_than(10,0,12))
2221 p_ptr->ele_immune = 0;
2222 p_ptr->special_defense = 0;
2226 rd_s16b(&p_ptr->ele_immune);
2227 rd_u32b(&p_ptr->special_defense);
2229 rd_byte(&p_ptr->knowledge);
2232 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2236 p_ptr->action = (ACTION_IDX)tmp8u;
2237 if (!z_older_than(10, 4, 3))
2240 if (tmp8u) p_ptr->action = ACTION_LEARN;
2242 rd_byte((byte *)&preserve_mode);
2243 rd_byte((byte *)&p_ptr->wait_report_score);
2246 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2248 /* Skip the flags */
2252 /* Hack -- the two "special seeds" */
2253 rd_u32b(¤t_world_ptr->seed_flavor);
2254 rd_u32b(¤t_world_ptr->seed_town);
2258 rd_u16b(&p_ptr->panic_save);
2259 rd_u16b(&p_ptr->total_winner);
2260 rd_u16b(&p_ptr->noscore);
2265 p_ptr->is_dead = tmp8u;
2267 /* Read "feeling" */
2268 rd_byte(&p_ptr->feeling);
2270 switch (p_ptr->start_race)
2276 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2279 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2282 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2284 /* Turn when level began */
2285 rd_s32b(¤t_floor_ptr->generated_turn);
2287 if (h_older_than(1, 7, 0, 4))
2289 p_ptr->feeling_turn = current_floor_ptr->generated_turn;
2293 /* Turn of last "feeling" */
2294 rd_s32b(&p_ptr->feeling_turn);
2297 /* Current current_world_ptr->game_turn */
2298 rd_s32b(¤t_world_ptr->game_turn);
2300 if (z_older_than(10, 3, 12))
2302 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2304 else rd_s32b(¤t_world_ptr->dungeon_turn);
2306 if (z_older_than(11, 0, 13))
2308 current_floor_ptr->generated_turn /= 2;
2309 p_ptr->feeling_turn /= 2;
2310 current_world_ptr->game_turn /= 2;
2311 current_world_ptr->dungeon_turn /= 2;
2314 if (z_older_than(10, 3, 13))
2316 old_battle = current_world_ptr->game_turn;
2318 else rd_s32b(&old_battle);
2320 if (z_older_than(10,0,3))
2322 determine_today_mon(TRUE);
2326 rd_s16b(&today_mon);
2327 rd_s16b(&p_ptr->today_mon);
2330 if (z_older_than(10,0,7))
2336 rd_s16b(&p_ptr->riding);
2339 /* Current floor_id */
2340 if (h_older_than(1, 5, 0, 0))
2342 p_ptr->floor_id = 0;
2346 rd_s16b(&p_ptr->floor_id);
2349 if (h_older_than(1, 5, 0, 2))
2355 /* Get number of party_mon array */
2358 /* Strip old temporary preserved pets */
2359 for (i = 0; i < tmp16s; i++)
2361 monster_type dummy_mon;
2363 rd_monster(&dummy_mon);
2367 if (z_older_than(10,1,2))
2369 current_world_ptr->play_time = 0;
2373 rd_u32b(¤t_world_ptr->play_time);
2376 if (z_older_than(10,3,9))
2380 else if (z_older_than(10, 3, 10))
2388 p_ptr->visit = (BIT_FLAGS)tmp32s;
2390 if (!z_older_than(11, 0, 5))
2392 rd_u32b(&p_ptr->count);
2398 * @brief プレイヤーの所持品情報を読み込む / Read the player p_ptr->inventory_list
2401 * Note that the p_ptr->inventory_list changed in Angband 2.7.4. Two extra
2402 * pack slots were added and the equipment was rearranged. Note
2403 * that these two features combine when parsing old save-files, in
2404 * which items from the old "aux" slot are "carried", perhaps into
2405 * one of the two new "p_ptr->inventory_list" slots.
2407 * Note that the p_ptr->inventory_list is "re-sorted" later by "dungeon()".
2409 static errr rd_inventory(void)
2417 p_ptr->total_weight = 0;
2420 p_ptr->inven_cnt = 0;
2421 p_ptr->equip_cnt = 0;
2423 /* Read until done */
2428 /* Get the next item index */
2431 /* Nope, we reached the end */
2432 if (n == 0xFFFF) break;
2439 /* Hack -- verify item */
2440 if (!q_ptr->k_idx) return (53);
2442 /* Wield equipment */
2443 if (n >= INVEN_RARM)
2445 q_ptr->marked |= OM_TOUCHED;
2446 object_copy(&p_ptr->inventory_list[n], q_ptr);
2448 /* Add the weight */
2449 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2455 /* Warning -- backpack is full */
2456 else if (p_ptr->inven_cnt == INVEN_PACK)
2458 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the p_ptr->inventory_list!"));
2464 /* Carry p_ptr->inventory_list */
2470 q_ptr->marked |= OM_TOUCHED;
2471 object_copy(&p_ptr->inventory_list[n], q_ptr);
2473 /* Add the weight */
2474 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2487 * @brief メッセージログを読み込む / Read the saved messages
2490 static void rd_messages(void)
2497 if (h_older_than(2, 2, 0, 75))
2502 message_max = (int)num;
2504 /* Read the messages */
2505 for (i = 0; i < message_max; i++)
2507 /* Read the message */
2508 rd_string(buf, sizeof(buf));
2510 /* Save the message */
2519 message_max = (int)num;
2521 /* Read the messages */
2522 for (i = 0; i < message_max; i++)
2524 /* Read the message */
2525 rd_string(buf, sizeof(buf));
2527 /* Save the message */
2536 /* Old hidden trap flag */
2537 #define CAVE_TRAP 0x8000
2539 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2540 #define OLD_FEAT_INVIS 0x02
2541 #define OLD_FEAT_GLYPH 0x03
2542 #define OLD_FEAT_QUEST_ENTER 0x08
2543 #define OLD_FEAT_QUEST_EXIT 0x09
2544 #define OLD_FEAT_MINOR_GLYPH 0x40
2545 #define OLD_FEAT_BLDG_1 0x81
2546 #define OLD_FEAT_MIRROR 0xc3
2549 #define OLD_QUEST_WATER_CAVE 18
2551 /* Quest constants */
2552 #define QUEST_OLD_CASTLE 27
2553 #define QUEST_ROYAL_CRYPT 28
2556 * @brief メッセージログを読み込む / Read the dungeon (old method)
2559 * The monsters/objects must be loaded in the same order
2560 * that they were stored, since the actual indexes matter.
2562 static errr rd_dungeon_old(void)
2573 /*** Basic info ***/
2577 current_floor_ptr->dun_level = (DEPTH)tmp16s;
2578 if (z_older_than(10, 3, 8)) p_ptr->dungeon_idx = DUNGEON_ANGBAND;
2582 p_ptr->dungeon_idx = (IDX)tmp8u;
2585 /* Set the base level for old versions */
2586 current_floor_ptr->base_level = current_floor_ptr->dun_level;
2589 current_floor_ptr->base_level = (DEPTH)tmp16s;
2592 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2594 p_ptr->y = (POSITION)tmp16s;
2596 p_ptr->x = (POSITION)tmp16s;
2597 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2599 current_floor_ptr->height = (POSITION)tmp16s;
2601 current_floor_ptr->width = (POSITION)tmp16s;
2602 rd_s16b(&tmp16s); /* max_panel_rows */
2603 rd_s16b(&tmp16s); /* max_panel_cols */
2606 if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2610 ymax = current_floor_ptr->height;
2611 xmax = current_floor_ptr->width;
2614 /*** Run length decoding ***/
2616 /* Load the dungeon data */
2617 for (x = y = 0; y < ymax; )
2623 if (z_older_than(10,3,6))
2632 /* Decline invalid flags */
2633 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2636 /* Apply the RLE info */
2637 for (i = count; i > 0; i--)
2639 /* Access the current_floor_ptr->grid_array */
2640 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2642 /* Extract "info" */
2652 if (++y >= ymax) break;
2658 /*** Run length decoding ***/
2660 /* Load the dungeon data */
2661 for (x = y = 0; y < ymax; )
2667 /* Apply the RLE info */
2668 for (i = count; i > 0; i--)
2670 /* Access the current_floor_ptr->grid_array */
2671 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2673 /* Extract "feat" */
2674 g_ptr->feat = (s16b)tmp8u;
2683 if (++y >= ymax) break;
2688 /*** Run length decoding ***/
2690 /* Load the dungeon data */
2691 for (x = y = 0; y < ymax; )
2697 /* Apply the RLE info */
2698 for (i = count; i > 0; i--)
2700 /* Access the current_floor_ptr->grid_array */
2701 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2703 /* Extract "mimic" */
2704 g_ptr->mimic = (s16b)tmp8u;
2713 if (++y >= ymax) break;
2718 /*** Run length decoding ***/
2720 /* Load the dungeon data */
2721 for (x = y = 0; y < ymax; )
2727 /* Apply the RLE info */
2728 for (i = count; i > 0; i--)
2730 /* Access the current_floor_ptr->grid_array */
2731 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2733 /* Extract "feat" */
2734 g_ptr->special = tmp16s;
2743 if (++y >= ymax) break;
2748 /* Convert current_floor_ptr->grid_array data */
2749 if (z_older_than(11, 0, 99))
2751 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2753 /* Wipe old unused flags */
2754 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2758 if (h_older_than(1, 1, 1, 0))
2760 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2762 /* Access the current_floor_ptr->grid_array */
2763 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2766 if (g_ptr->feat == OLD_FEAT_INVIS)
2768 g_ptr->feat = feat_floor;
2769 g_ptr->info |= CAVE_TRAP;
2772 /* Older than 1.1.1 */
2773 if (g_ptr->feat == OLD_FEAT_MIRROR)
2775 g_ptr->feat = feat_floor;
2776 g_ptr->info |= CAVE_OBJECT;
2781 if (h_older_than(1, 3, 1, 0))
2783 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2785 /* Access the current_floor_ptr->grid_array */
2786 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2788 /* Old CAVE_IN_MIRROR flag */
2789 if (g_ptr->info & CAVE_OBJECT)
2791 g_ptr->mimic = feat_mirror;
2794 /* Runes will be mimics and flags */
2795 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2796 (g_ptr->feat == OLD_FEAT_GLYPH))
2798 g_ptr->info |= CAVE_OBJECT;
2799 g_ptr->mimic = g_ptr->feat;
2800 g_ptr->feat = feat_floor;
2803 /* Hidden traps will be trap terrains mimicing floor */
2804 else if (g_ptr->info & CAVE_TRAP)
2806 g_ptr->info &= ~CAVE_TRAP;
2807 g_ptr->mimic = g_ptr->feat;
2808 g_ptr->feat = choose_random_trap();
2811 /* Another hidden trap */
2812 else if (g_ptr->feat == OLD_FEAT_INVIS)
2814 g_ptr->mimic = feat_floor;
2815 g_ptr->feat = feat_trap_open;
2820 /* Quest 18 was removed */
2821 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2823 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2825 /* Access the current_floor_ptr->grid_array */
2826 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2828 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
2830 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2832 g_ptr->feat = feat_tree;
2835 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2837 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2840 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2841 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2843 g_ptr->feat = feat_up_stair;
2851 /* Read the item count */
2854 /* Verify maximum */
2855 if (limit > current_floor_ptr->max_o_idx)
2857 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2861 /* Read the dungeon items */
2862 for (i = 1; i < limit; i++)
2869 /* Get a new record */
2874 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2880 o_ptr = ¤t_floor_ptr->o_list[o_idx];
2888 if (o_ptr->held_m_idx)
2890 monster_type *m_ptr;
2891 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
2894 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2896 m_ptr->hold_o_idx = o_idx;
2902 /* Access the item location */
2903 g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2906 o_ptr->next_o_idx = g_ptr->o_idx;
2908 g_ptr->o_idx = o_idx;
2915 /* Read the monster count */
2918 /* Hack -- verify */
2919 if (limit > current_floor_ptr->max_m_idx)
2921 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2925 /* Read the monsters */
2926 for (i = 1; i < limit; i++)
2929 monster_type *m_ptr;
2931 /* Get a new record */
2936 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2941 /* Acquire monster */
2942 m_ptr = ¤t_floor_ptr->m_list[m_idx];
2944 /* Read the monster */
2949 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2951 /* Mark the location */
2952 g_ptr->m_idx = m_idx;
2955 real_r_ptr(m_ptr)->cur_num++;
2960 /* The dungeon is ready */
2961 if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena)
2962 character_dungeon = FALSE;
2964 character_dungeon = TRUE;
2972 * @brief 保存されたフロアを読み込む / Read the saved floor
2973 * @return info読み込みエラーコード
2975 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2978 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2979 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2981 * The monsters/objects must be loaded in the same order
2982 * that they were stored, since the actual indexes matter.
2984 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2986 POSITION ymax, xmax;
2997 grid_template_type *templates;
3000 /*** Wipe all current_floor_ptr->grid_array ***/
3004 /*** Basic info ***/
3006 /* Dungeon floor specific info follows */
3010 /*** Not a saved floor ***/
3013 current_floor_ptr->dun_level = (DEPTH)tmp16s;
3014 current_floor_ptr->base_level = current_floor_ptr->dun_level;
3018 /*** The saved floor ***/
3021 if (tmp16s != sf_ptr->floor_id) return 171;
3024 if (tmp8u != sf_ptr->savefile_id) return 171;
3027 if (tmp16s != sf_ptr->dun_level) return 171;
3028 current_floor_ptr->dun_level = sf_ptr->dun_level;
3031 if (tmp32s != sf_ptr->last_visit) return 171;
3034 if (tmp32u != sf_ptr->visit_mark) return 171;
3037 if (tmp16s != sf_ptr->upper_floor_id) return 171;
3040 if (tmp16s != sf_ptr->lower_floor_id) return 171;
3044 current_floor_ptr->base_level = (DEPTH)tmp16s;
3046 current_floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
3049 p_ptr->y = (POSITION)tmp16u;
3052 p_ptr->x = (POSITION)tmp16u;
3055 current_floor_ptr->height = (POSITION)tmp16s;
3057 current_floor_ptr->width = (POSITION)tmp16s;
3059 rd_byte(&p_ptr->feeling);
3063 /*** Read template for grid_type ***/
3065 /* Read the template count */
3068 /* Allocate the "template" array */
3069 C_MAKE(templates, limit, grid_template_type);
3071 /* Read the templates */
3072 for (i = 0; i < limit; i++)
3074 grid_template_type *ct_ptr = &templates[i];
3078 ct_ptr->info = (BIT_FLAGS)tmp16u;
3079 if (h_older_than(1, 7, 0, 2))
3082 ct_ptr->feat = (s16b)tmp8u;
3084 ct_ptr->mimic = (s16b)tmp8u;
3088 rd_s16b(&ct_ptr->feat);
3089 rd_s16b(&ct_ptr->mimic);
3091 rd_s16b(&ct_ptr->special);
3095 ymax = current_floor_ptr->height;
3096 xmax = current_floor_ptr->width;
3099 /*** Run length decoding ***/
3101 /* Load the dungeon data */
3102 for (x = y = 0; y < ymax; )
3114 } while (tmp8u == MAX_UCHAR);
3116 /* Apply the RLE info */
3117 for (i = count; i > 0; i--)
3119 /* Access the current_floor_ptr->grid_array */
3120 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3122 /* Extract current_floor_ptr->grid_array data */
3123 g_ptr->info = templates[id].info;
3124 g_ptr->feat = templates[id].feat;
3125 g_ptr->mimic = templates[id].mimic;
3126 g_ptr->special = templates[id].special;
3135 if (++y >= ymax) break;
3140 /* Quest 18 was removed */
3141 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3143 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3145 /* Access the current_floor_ptr->grid_array */
3146 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3148 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !current_floor_ptr->dun_level)
3150 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
3152 g_ptr->feat = feat_tree;
3155 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
3157 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3160 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3161 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3163 g_ptr->feat = feat_up_stair;
3169 /* Free the "template" array */
3170 C_KILL(templates, limit, grid_template_type);
3175 /* Read the item count */
3178 /* Verify maximum */
3179 if (limit > current_floor_ptr->max_o_idx) return 151;
3182 /* Read the dungeon items */
3183 for (i = 1; i < limit; i++)
3189 /* Get a new record */
3192 if (i != o_idx) return 152;
3195 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3200 if (o_ptr->held_m_idx)
3202 monster_type *m_ptr;
3203 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
3206 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3208 m_ptr->hold_o_idx = o_idx;
3214 /* Access the item location */
3215 grid_type *g_ptr = ¤t_floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
3218 o_ptr->next_o_idx = g_ptr->o_idx;
3220 g_ptr->o_idx = o_idx;
3227 /* Read the monster count */
3230 /* Hack -- verify */
3231 if (limit > current_floor_ptr->max_m_idx) return 161;
3233 /* Read the monsters */
3234 for (i = 1; i < limit; i++)
3238 monster_type *m_ptr;
3240 /* Get a new record */
3243 if (i != m_idx) return 162;
3246 /* Acquire monster */
3247 m_ptr = ¤t_floor_ptr->m_list[m_idx];
3249 /* Read the monster */
3254 g_ptr = ¤t_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
3256 /* Mark the location */
3257 g_ptr->m_idx = m_idx;
3260 real_r_ptr(m_ptr)->cur_num++;
3269 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3272 * The monsters/objects must be loaded in the same order
3273 * that they were stored, since the actual indexes matter.
3275 static errr rd_dungeon(void)
3283 /* Initialize saved_floors array and temporal files */
3284 init_saved_floors(FALSE);
3287 if (h_older_than(1, 5, 0, 0))
3289 err = rd_dungeon_old();
3291 /* Prepare floor_id of current floor */
3292 if (p_ptr->dungeon_idx)
3294 p_ptr->floor_id = get_new_floor_id();
3295 get_sf_ptr(p_ptr->floor_id)->dun_level = current_floor_ptr->dun_level;
3304 /* Number of floor_id used from birth */
3305 rd_s16b(&max_floor_id);
3307 /* Current dungeon type */
3309 p_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
3311 /* Number of the saved_floors array elements */
3314 /*** No saved floor (On the surface etc.) ***/
3317 /* Read the current floor data */
3318 err = rd_saved_floor(NULL);
3321 /*** In the dungeon ***/
3325 /* Read the saved_floors array */
3326 for (i = 0; i < num; i++)
3328 saved_floor_type *sf_ptr = &saved_floors[i];
3330 rd_s16b(&sf_ptr->floor_id);
3332 sf_ptr->savefile_id = (s16b)tmp8u;
3335 sf_ptr->dun_level = (DEPTH)tmp16s;
3337 rd_s32b(&sf_ptr->last_visit);
3338 rd_u32b(&sf_ptr->visit_mark);
3339 rd_s16b(&sf_ptr->upper_floor_id);
3340 rd_s16b(&sf_ptr->lower_floor_id);
3344 /* Move saved floors data to temporal files */
3345 for (i = 0; i < num; i++)
3347 saved_floor_type *sf_ptr = &saved_floors[i];
3349 /* Unused element */
3350 if (!sf_ptr->floor_id) continue;
3352 /* Read the failure mark */
3354 if (tmp8u) continue;
3356 /* Read from the save file */
3357 err = rd_saved_floor(sf_ptr);
3362 /* Re-save as temporal saved floor file */
3363 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3369 /* Finally load current floor data from temporal file */
3372 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3377 /*** Error messages ***/
3381 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3385 note(_("アイテム配置エラー", "Object allocation error"));
3389 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3393 note(_("モンスター配置エラー", "Monster allocation error"));
3397 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3401 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3405 note(_("Error 183", "Error 183"));
3409 /* The dungeon is ready */
3410 character_dungeon = TRUE;
3412 /* Success or Error */
3418 * @brief ロード処理全体のサブ関数 / Actually read the savefile
3421 static errr rd_savefile_new_aux(void)
3434 #ifdef VERIFY_CHECKSUMS
3435 u32b n_x_check, n_v_check;
3436 u32b o_x_check, o_v_check;
3440 /* Strip the version bytes */
3443 /* Hack -- decrypt */
3444 xor_byte = sf_extra;
3447 /* Clear the checksums */
3451 /* Read the version number of the savefile */
3452 /* Old savefile will be version 0.0.0.3 */
3453 rd_byte(&h_ver_extra);
3454 rd_byte(&h_ver_patch);
3455 rd_byte(&h_ver_minor);
3456 rd_byte(&h_ver_major);
3458 /* Mention the savefile version */
3460 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3461 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3464 /* Operating system info */
3465 rd_u32b(&sf_system);
3467 /* Time of savefile creation */
3470 /* Number of resurrections */
3473 /* Number of times played */
3477 /* Later use (always zero) */
3480 /* Later use (always zero) */
3483 /* Later use (always zero) */
3487 rd_byte(&kanji_code);
3489 /* Read RNG state */
3491 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3493 /* Then the options */
3495 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3497 /* Then the "messages" */
3499 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3501 for (i = 0; i < max_r_idx; i++)
3503 /* Access that monster */
3504 monster_race *r_ptr = &r_info[i];
3506 /* Hack -- Reset the death counter */
3507 r_ptr->max_num = 100;
3509 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3511 /* Hack -- Non-unique Nazguls are semi-unique */
3512 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3515 /* Monster Memory */
3518 /* Incompatible save files */
3519 if (tmp16u > max_r_idx)
3521 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3525 /* Read the available records */
3526 for (i = 0; i < tmp16u; i++)
3529 rd_lore((MONRACE_IDX)i);
3532 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3537 /* Incompatible save files */
3538 if (tmp16u > max_k_idx)
3540 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3544 /* Read the object memory */
3545 for (i = 0; i < tmp16u; i++)
3547 object_kind *k_ptr = &k_info[i];
3551 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3552 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3554 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3556 /* 2.1.3 or newer version */
3558 u16b max_towns_load;
3559 u16b max_quests_load;
3560 byte max_rquests_load;
3561 s16b old_inside_quest = p_ptr->inside_quest;
3563 /* Number of towns */
3564 rd_u16b(&max_towns_load);
3566 /* Incompatible save files */
3567 if (max_towns_load > max_towns)
3569 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3573 /* Number of quests */
3574 rd_u16b(&max_quests_load);
3576 if (z_older_than(11, 0, 7))
3578 max_rquests_load = 10;
3582 rd_byte(&max_rquests_load);
3585 /* Incompatible save files */
3586 if (max_quests_load > max_q_idx)
3588 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3592 for (i = 0; i < max_quests_load; i++)
3596 quest_type* const q_ptr = &quest[i];
3598 rd_s16b(&q_ptr->status);
3600 q_ptr->level = tmp16s;
3602 if (z_older_than(11, 0, 6))
3609 q_ptr->complev = tmp8u;
3611 if(h_older_than(2, 1, 2, 2))
3613 q_ptr->comptime = 0;
3617 rd_u32b(&q_ptr->comptime);
3620 /* Load quest status if quest is running */
3621 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3622 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3623 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3626 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3628 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3629 rd_s16b(&q_ptr->type);
3631 /* Load quest monster index */
3632 rd_s16b(&q_ptr->r_idx);
3634 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3636 determine_random_questor(&quest[i]);
3639 /* Load quest item index */
3640 rd_s16b(&q_ptr->k_idx);
3643 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3646 q_ptr->flags = tmp8u;
3648 if (z_older_than(10, 3, 11))
3650 if (q_ptr->flags & QUEST_FLAG_PRESET)
3656 init_flags = INIT_ASSIGN;
3657 p_ptr->inside_quest = (QUEST_IDX)i;
3659 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3660 p_ptr->inside_quest = old_inside_quest;
3666 q_ptr->dungeon = tmp8u;
3669 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3670 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3671 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3674 /* Ignore the empty quests from old versions */
3677 /* Ignore quest status */
3680 /* Ignore quest level */
3684 * We don't have to care about the other info,
3685 * since status should be 0 for these quests anyway
3690 /* Quest 18 was removed */
3691 if (h_older_than(1, 7, 0, 6))
3693 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3694 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3697 /* Position in the wilderness */
3698 rd_s32b(&p_ptr->wilderness_x);
3699 rd_s32b(&p_ptr->wilderness_y);
3700 if (z_older_than(10, 3, 13))
3702 p_ptr->wilderness_x = 5;
3703 p_ptr->wilderness_y = 48;
3706 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3707 else rd_byte((byte *)&p_ptr->wild_mode);
3708 if (z_older_than(10, 3, 7)) p_ptr->ambush_flag = FALSE;
3709 else rd_byte((byte *)&p_ptr->ambush_flag);
3711 /* Size of the wilderness */
3712 rd_s32b(&wild_x_size);
3713 rd_s32b(&wild_y_size);
3715 /* Incompatible save files */
3716 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3718 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3722 /* Load the wilderness seeds */
3723 for (i = 0; i < wild_x_size; i++)
3725 for (j = 0; j < wild_y_size; j++)
3727 rd_u32b(&wilderness[j][i].seed);
3732 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3734 /* Load the Artifacts */
3737 /* Incompatible save files */
3738 if (tmp16u > max_a_idx)
3740 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3744 /* Read the artifact flags */
3745 for (i = 0; i < tmp16u; i++)
3747 artifact_type *a_ptr = &a_info[i];
3750 a_ptr->cur_num = tmp8u;
3752 if (h_older_than(1, 5, 0, 0))
3754 a_ptr->floor_id = 0;
3762 rd_s16b(&a_ptr->floor_id);
3765 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3767 /* Read the extra stuff */
3769 if (p_ptr->energy_need < -999) p_ptr->timewalk = TRUE;
3771 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3774 /* Read the player_hp array */
3777 /* Incompatible save files */
3778 if (tmp16u > PY_MAX_LEVEL)
3780 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3784 /* Read the player_hp array */
3785 for (i = 0; i < tmp16u; i++)
3788 p_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3791 /* Important -- Initialize the sex */
3792 sp_ptr = &sex_info[p_ptr->psex];
3794 /* Important -- Initialize the race/class */
3795 rp_ptr = &race_info[p_ptr->prace];
3796 cp_ptr = &class_info[p_ptr->pclass];
3797 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3799 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3801 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3802 roll_hitdice(p_ptr, 0L);
3804 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3806 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3807 roll_hitdice(p_ptr, 0L);
3809 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3811 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3812 roll_hitdice(p_ptr, 0L);
3814 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3816 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3817 roll_hitdice(p_ptr, 0L);
3820 /* Important -- Initialize the magic */
3821 mp_ptr = &m_info[p_ptr->pclass];
3824 /* Read spell info */
3825 rd_u32b(&p_ptr->spell_learned1);
3826 rd_u32b(&p_ptr->spell_learned2);
3827 rd_u32b(&p_ptr->spell_worked1);
3828 rd_u32b(&p_ptr->spell_worked2);
3829 rd_u32b(&p_ptr->spell_forgotten1);
3830 rd_u32b(&p_ptr->spell_forgotten2);
3832 if (z_older_than(10,0,5))
3834 p_ptr->learned_spells = 0;
3835 for (i = 0; i < 64; i++)
3837 /* Count known spells */
3839 (p_ptr->spell_learned1 & (1L << i)) :
3840 (p_ptr->spell_learned2 & (1L << (i - 32))))
3842 p_ptr->learned_spells++;
3846 else rd_s16b(&p_ptr->learned_spells);
3848 if (z_older_than(10,0,6))
3850 p_ptr->add_spells = 0;
3852 else rd_s16b(&p_ptr->add_spells);
3853 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3855 for (i = 0; i < 64; i++)
3858 p_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3862 /* Read the p_ptr->inventory_list */
3865 note(_("持ち物情報を読み込むことができません", "Unable to read p_ptr->inventory_list"));
3869 /* Read number of towns */
3871 town_count = tmp16u;
3873 /* Read the stores */
3875 for (i = 1; i < town_count; i++)
3877 for (j = 0; j < tmp16u; j++)
3879 if (rd_store(i, j)) return (22);
3883 rd_s16b(&p_ptr->pet_follow_distance);
3884 if (z_older_than(10, 4, 10))
3886 p_ptr->pet_extra_flags = 0;
3888 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3890 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3892 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3896 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3899 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3903 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3906 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3910 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3913 if (!z_older_than(10,0,8))
3916 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3921 rd_s16b(&p_ptr->pet_extra_flags);
3924 if (!z_older_than(11, 0, 9))
3926 char buf[SCREEN_BUF_MAX_SIZE];
3927 rd_string(buf, sizeof(buf));
3928 if (buf[0]) screen_dump = string_make(buf);
3933 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3935 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3940 /* I'm not dead yet... */
3941 if (!p_ptr->is_dead)
3943 /* Dead players have no dungeon */
3944 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3948 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3952 /* Read the ghost info */
3959 strip_bytes(tmp32s);
3963 /* Quest 18 was removed */
3964 if (h_older_than(1, 7, 0, 6))
3966 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3968 p_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3969 current_floor_ptr->dun_level = 1;
3970 p_ptr->inside_quest = 0;
3975 #ifdef VERIFY_CHECKSUMS
3977 /* Save the checksum */
3978 n_v_check = v_check;
3980 /* Read the old checksum */
3981 rd_u32b(&o_v_check);
3984 if (o_v_check != n_v_check)
3986 note(_("チェックサムがおかしい", "Invalid checksum"));
3991 /* Save the encoded checksum */
3992 n_x_check = x_check;
3994 /* Read the checksum */
3995 rd_u32b(&o_x_check);
3999 if (o_x_check != n_x_check)
4001 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
4012 * @brief ロード処理全体のメイン関数 / Actually read the savefile
4015 errr rd_savefile_new(void)
4019 /* Grab permissions */
4022 /* The savefile is a binary file */
4023 fff = my_fopen(savefile, "rb");
4025 /* Drop permissions */
4027 if (!fff) return (-1);
4029 /* Call the sub-function */
4030 err = rd_savefile_new_aux();
4032 /* Check for errors */
4033 if (ferror(fff)) err = -1;
4040 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
4041 * @param sf_ptr 保存フロア読み込み先
4044 static bool load_floor_aux(saved_floor_type *sf_ptr)
4049 #ifdef VERIFY_CHECKSUMS
4050 u32b n_x_check, n_v_check;
4051 u32b o_x_check, o_v_check;
4054 /* Hack -- decrypt (read xor_byte) */
4058 /* Clear the checksums */
4062 /* Set the version number to current version */
4063 /* Never load old temporal files */
4064 h_ver_extra = H_VER_EXTRA;
4065 h_ver_patch = H_VER_PATCH;
4066 h_ver_minor = H_VER_MINOR;
4067 h_ver_major = H_VER_MAJOR;
4069 /* Verify the sign */
4071 if (saved_floor_file_sign != tmp32u) return FALSE;
4073 /* Read -- have error? */
4074 if (rd_saved_floor(sf_ptr)) return FALSE;
4077 #ifdef VERIFY_CHECKSUMS
4078 /* Save the checksum */
4079 n_v_check = v_check;
4081 /* Read the old checksum */
4082 rd_u32b(&o_v_check);
4085 if (o_v_check != n_v_check) return FALSE;
4087 /* Save the encoded checksum */
4088 n_x_check = x_check;
4090 /* Read the checksum */
4091 rd_u32b(&o_x_check);
4094 if (o_x_check != n_x_check) return FALSE;
4103 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4104 * @param sf_ptr 保存フロア読み込み先
4108 bool load_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
4110 FILE *old_fff = NULL;
4111 byte old_xor_byte = 0;
4112 u32b old_v_check = 0;
4113 u32b old_x_check = 0;
4114 byte old_h_ver_major = 0;
4115 byte old_h_ver_minor = 0;
4116 byte old_h_ver_patch = 0;
4117 byte old_h_ver_extra = 0;
4120 char floor_savefile[1024];
4122 byte old_kanji_code = kanji_code;
4125 * Temporal files are always written in system depended kanji
4130 /* EUC kanji code */
4134 /* SJIS kanji code */
4143 /* We have one file already opened */
4144 if (mode & SLF_SECOND)
4146 /* Backup original values */
4148 old_xor_byte = xor_byte;
4149 old_v_check = v_check;
4150 old_x_check = x_check;
4151 old_h_ver_major = h_ver_major;
4152 old_h_ver_minor = h_ver_minor;
4153 old_h_ver_patch = h_ver_patch;
4154 old_h_ver_extra = h_ver_extra;
4157 /* floor savefile */
4158 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4160 /* Grab permissions */
4163 /* The savefile is a binary file */
4164 fff = my_fopen(floor_savefile, "rb");
4166 /* Drop permissions */
4170 if (!fff) ok = FALSE;
4172 /* Attempt to load */
4175 /* Load saved floor data from file */
4176 ok = load_floor_aux(sf_ptr);
4178 /* Check for errors */
4179 if (ferror(fff)) ok = FALSE;
4182 /* Grab permissions */
4185 /* Delete the file */
4186 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4188 /* Drop permissions */
4192 /* We have one file already opened */
4193 if (mode & SLF_SECOND)
4195 /* Restore original values */
4197 xor_byte = old_xor_byte;
4198 v_check = old_v_check;
4199 x_check = old_x_check;
4200 h_ver_major = old_h_ver_major;
4201 h_ver_minor = old_h_ver_minor;
4202 h_ver_patch = old_h_ver_patch;
4203 h_ver_extra = old_h_ver_extra;
4206 /* Restore old knowledge */
4207 kanji_code = old_kanji_code;