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.
53 #include "floor-generate.h"
61 #include "spells-status.h"
62 #include "object-hook.h"
67 #include "floor-save.h"
68 #include "floor-town.h"
72 #include "dungeon-file.h"
74 #include "player-skill.h"
75 #include "player-class.h"
76 #include "player-race.h"
77 #include "player-personality.h"
78 #include "player-sex.h"
81 #include "objectkind.h"
82 #include "object-ego.h"
85 #include "realm-song.h"
86 #include "cmd-smith.h"
89 * Maximum number of tries for selection of a proper quest monster
93 #define OLD_MAX_MANE 22
95 /* Old hidden trap flag */
96 #define CAVE_TRAP 0x8000
98 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
99 #define OLD_FEAT_INVIS 0x02
100 #define OLD_FEAT_GLYPH 0x03
101 #define OLD_FEAT_QUEST_ENTER 0x08
102 #define OLD_FEAT_QUEST_EXIT 0x09
103 #define OLD_FEAT_MINOR_GLYPH 0x40
104 #define OLD_FEAT_BLDG_1 0x81
105 #define OLD_FEAT_MIRROR 0xc3
108 #define OLD_QUEST_WATER_CAVE 18
110 /* Quest constants */
111 #define QUEST_OLD_CASTLE 27
112 #define QUEST_ROYAL_CRYPT 28
115 * Local "savefile" pointer
120 * Hack -- old "encryption" byte
122 static byte xor_byte;
125 * Hack -- simple "checksum" on the actual values
127 static u32b v_check = 0L;
130 * Hack -- simple "checksum" on the encoded bytes
132 static u32b x_check = 0L;
135 * Hack -- Japanese Kanji code
141 static byte kanji_code = 0;
144 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
145 * @param major メジャーバージョン値
146 * @param minor マイナーバージョン値
147 * @param patch パッチバージョン値
148 * @param extra エクストラパージョン値
149 * @return 現在のバージョンより値が古いならtrue
151 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
153 if (current_world_ptr->h_ver_major < major) return TRUE;
154 if (current_world_ptr->h_ver_major > major) return FALSE;
156 if (current_world_ptr->h_ver_minor < minor) return TRUE;
157 if (current_world_ptr->h_ver_minor > minor) return FALSE;
159 if (current_world_ptr->h_ver_patch < patch) return TRUE;
160 if (current_world_ptr->h_ver_patch > patch) return FALSE;
162 if (current_world_ptr->h_ver_extra < extra) return TRUE;
163 if (current_world_ptr->h_ver_extra > extra) return FALSE;
170 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
171 * @param x メジャーバージョン値
172 * @param y マイナーバージョン値
174 * @return 現在のバージョンより値が古いならtrue
176 static bool z_older_than(byte x, byte y, byte z)
178 if (current_world_ptr->z_major < x) return TRUE;
179 if (current_world_ptr->z_major > x) return FALSE;
181 if (current_world_ptr->z_minor < y) return TRUE;
182 if (current_world_ptr->z_minor > y) return FALSE;
184 if (current_world_ptr->z_patch < z) return TRUE;
185 if (current_world_ptr->z_patch > z) return FALSE;
192 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
196 * Avoid the top two lines, to avoid interference with "msg_print()".
198 static void note(concptr msg)
200 static TERM_LEN y = 2;
202 if (++y >= 24) y = 2;
209 * @brief ロードファイルポインタから1バイトを読み込む
212 * The following functions are used to load the basic building blocks
213 * of savefiles. They also maintain the "checksum" info for 2.7.0+
215 static byte sf_get(void)
217 byte c = getc(fff) & 0xFF;
218 byte v = c ^ xor_byte;
228 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
232 static void rd_byte(byte *ip)
239 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
243 static void rd_u16b(u16b *ip)
246 (*ip) |= ((u16b)(sf_get()) << 8);
251 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
255 static void rd_s16b(s16b *ip)
262 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
266 static void rd_u32b(u32b *ip)
269 (*ip) |= ((u32b)(sf_get()) << 8);
270 (*ip) |= ((u32b)(sf_get()) << 16);
271 (*ip) |= ((u32b)(sf_get()) << 24);
276 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
280 static void rd_s32b(s32b *ip)
287 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
288 * @param str 読み込みポインタ
289 * @param max 最大読み取りバイト数
292 static void rd_string(char *str, int max)
294 for (int i = 0; TRUE; i++)
298 if (i < max) str[i] = tmp8u;
321 byte code = codeconv(str);
323 /* 漢字コードが判明したら、それを記録 */
324 if (code) kanji_code = code;
336 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
340 static void strip_bytes(int n)
343 while (n--) rd_byte(&tmp8u);
348 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
349 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
352 * This function attempts to "repair" old savefiles, and to extract
353 * the most up to date values for various object fields.
355 * Note that Angband 2.7.9 introduced a new method for object "flags"
356 * in which the "flags" on an object are actually extracted when they
357 * are needed from the object kind, artifact index, ego-item index,
358 * and two special "xtra" fields which are used to encode any "extra"
359 * power of certain ego-items. This had the side effect that items
360 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
361 * may have had, and also, all "uncursed" items will become "cursed"
362 * again, including Calris, even if it is being worn at the time. As
363 * a complete hack, items which are inscribed with "uncursed" will be
364 * "uncursed" when imported from pre-2.7.9 savefiles.
366 static void rd_item_old(object_type *o_ptr)
368 rd_s16b(&o_ptr->k_idx);
372 o_ptr->iy = (POSITION)tmp8u;
374 o_ptr->ix = (POSITION)tmp8u;
382 if (z_older_than(10, 4, 4))
384 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
385 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
386 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
389 rd_s16b(&o_ptr->pval);
390 rd_byte(&o_ptr->discount);
392 o_ptr->number = (ITEM_NUMBER)tmp8u;
396 o_ptr->weight = tmp16s;
399 o_ptr->name1 = tmp8u;
402 o_ptr->name2 = tmp8u;
404 rd_s16b(&o_ptr->timeout);
405 rd_s16b(&o_ptr->to_h);
407 o_ptr->to_d = tmp16s;
409 rd_s16b(&o_ptr->to_a);
417 rd_byte(&o_ptr->ident);
418 rd_byte(&o_ptr->marked);
419 rd_u32b(&o_ptr->art_flags[0]);
420 rd_u32b(&o_ptr->art_flags[1]);
421 rd_u32b(&o_ptr->art_flags[2]);
422 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
423 else rd_u32b(&o_ptr->art_flags[3]);
425 if (h_older_than(1, 3, 0, 0))
427 if (o_ptr->name2 == EGO_TELEPATHY)
428 add_flag(o_ptr->art_flags, TR_TELEPATHY);
431 if (z_older_than(11, 0, 11))
433 o_ptr->curse_flags = 0L;
434 if (o_ptr->ident & 0x40)
436 o_ptr->curse_flags |= TRC_CURSED;
437 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
438 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
439 if (object_is_fixed_artifact(o_ptr))
441 artifact_type *a_ptr = &a_info[o_ptr->name1];
442 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
443 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
445 else if (object_is_ego(o_ptr))
447 ego_item_type *e_ptr = &e_info[o_ptr->name2];
448 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
449 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
452 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
456 rd_u32b(&o_ptr->curse_flags);
459 rd_s16b(&o_ptr->held_m_idx);
460 rd_byte(&o_ptr->xtra1);
461 rd_byte(&o_ptr->xtra2);
463 if (z_older_than(11, 0, 10))
465 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
467 switch (o_ptr->xtra2 % 6)
469 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
470 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
471 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
472 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
473 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
474 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
478 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
480 switch (o_ptr->xtra2 % 11)
482 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
483 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
484 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
485 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
486 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
487 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
488 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
489 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
490 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
491 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
492 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
496 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
498 switch (o_ptr->xtra2 % 8)
500 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
501 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
502 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
503 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
504 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
505 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
506 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
507 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
514 if (z_older_than(10, 2, 3))
519 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
521 o_ptr->xtra3 = o_ptr->xtra1;
524 if (o_ptr->tval == TV_CAPTURE)
526 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
527 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
529 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
530 if (ironman_nightmare)
532 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5 * 2L);
534 o_ptr->xtra4 = o_ptr->xtra5;
539 rd_byte(&o_ptr->xtra3);
540 if (h_older_than(1, 3, 0, 1))
542 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1 + 96)
543 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
546 rd_s16b(&o_ptr->xtra4);
547 rd_s16b(&o_ptr->xtra5);
550 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)))
552 o_ptr->xtra4 = o_ptr->pval;
556 rd_byte(&o_ptr->feeling);
559 rd_string(buf, sizeof(buf));
560 if (buf[0]) o_ptr->inscription = quark_add(buf);
562 rd_string(buf, sizeof(buf));
564 /* todo 元々このif文には末尾に";"が付いていた、バグかもしれない */
565 if (buf[0]) o_ptr->art_name = quark_add(buf);
573 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
575 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
577 if (z_older_than(10, 4, 9))
579 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
581 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
582 add_flag(o_ptr->art_flags, TR_DEC_MANA);
586 if (object_is_fixed_artifact(o_ptr))
588 artifact_type *a_ptr;
589 a_ptr = &a_info[o_ptr->name1];
590 if (!a_ptr->name) o_ptr->name1 = 0;
593 if (object_is_ego(o_ptr))
595 ego_item_type *e_ptr;
596 e_ptr = &e_info[o_ptr->name2];
597 if (!e_ptr->name) o_ptr->name2 = 0;
603 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
604 * @param o_ptr アイテムオブジェクト保存先ポインタ
607 static void rd_item(object_type *o_ptr)
609 if (h_older_than(1, 5, 0, 0))
617 rd_s16b(&o_ptr->k_idx);
621 o_ptr->iy = (POSITION)tmp8u;
623 o_ptr->ix = (POSITION)tmp8u;
626 k_ptr = &k_info[o_ptr->k_idx];
627 o_ptr->tval = k_ptr->tval;
628 o_ptr->sval = k_ptr->sval;
630 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
631 else o_ptr->pval = 0;
633 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
634 else o_ptr->discount = 0;
635 if (flags & SAVE_ITEM_NUMBER) {
637 o_ptr->number = tmp8u;
639 else o_ptr->number = 1;
643 o_ptr->weight = tmp16s;
645 if (flags & SAVE_ITEM_NAME1)
648 o_ptr->name1 = tmp8u;
650 else o_ptr->name1 = 0;
652 if (flags & SAVE_ITEM_NAME2)
655 o_ptr->name2 = tmp8u;
657 else o_ptr->name2 = 0;
659 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
660 else o_ptr->timeout = 0;
662 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
663 else o_ptr->to_h = 0;
665 if (flags & SAVE_ITEM_TO_D)
668 o_ptr->to_d = tmp16s;
670 else o_ptr->to_d = 0;
672 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
673 else o_ptr->to_a = 0;
675 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
678 if (flags & SAVE_ITEM_DD)
685 if (flags & SAVE_ITEM_DS)
692 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
693 else o_ptr->ident = 0;
695 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
696 else o_ptr->marked = 0;
699 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
700 else o_ptr->art_flags[0] = 0;
702 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
703 else o_ptr->art_flags[1] = 0;
705 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
706 else o_ptr->art_flags[2] = 0;
708 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
709 else o_ptr->art_flags[3] = 0;
711 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
712 else o_ptr->art_flags[4] = 0;
714 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
715 else o_ptr->curse_flags = 0;
717 /* Monster holding object */
718 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
719 else o_ptr->held_m_idx = 0;
722 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
723 else o_ptr->xtra1 = 0;
725 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
726 else o_ptr->xtra2 = 0;
728 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
729 else o_ptr->xtra3 = 0;
731 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
732 else o_ptr->xtra4 = 0;
734 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
735 else o_ptr->xtra5 = 0;
737 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
738 else o_ptr->feeling = 0;
740 if (flags & SAVE_ITEM_INSCRIPTION)
743 rd_string(buf, sizeof(buf));
744 o_ptr->inscription = quark_add(buf);
746 else o_ptr->inscription = 0;
748 if (flags & SAVE_ITEM_ART_NAME)
751 rd_string(buf, sizeof(buf));
752 o_ptr->art_name = quark_add(buf);
759 if (!h_older_than(2, 1, 2, 4)) return;
761 BIT_FLAGS flgs[TR_FLAG_SIZE];
762 object_flags(o_ptr, flgs);
764 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
766 add_flag(o_ptr->art_flags, TR_LITE_M1);
767 remove_flag(o_ptr->art_flags, TR_LITE_1);
768 remove_flag(o_ptr->art_flags, TR_LITE_2);
769 remove_flag(o_ptr->art_flags, TR_LITE_3);
773 if (o_ptr->name2 == EGO_LITE_DARKNESS)
775 if (o_ptr->tval != TV_LITE)
777 add_flag(o_ptr->art_flags, TR_LITE_M1);
781 if (o_ptr->sval == SV_LITE_TORCH)
783 add_flag(o_ptr->art_flags, TR_LITE_M1);
785 else if (o_ptr->sval == SV_LITE_LANTERN)
787 add_flag(o_ptr->art_flags, TR_LITE_M2);
789 else if (o_ptr->sval == SV_LITE_FEANOR)
791 add_flag(o_ptr->art_flags, TR_LITE_M3);
797 if (o_ptr->tval == TV_LITE)
799 if (object_is_fixed_artifact(o_ptr))
801 add_flag(o_ptr->art_flags, TR_LITE_3);
805 if (o_ptr->sval == SV_LITE_TORCH)
807 add_flag(o_ptr->art_flags, TR_LITE_1);
808 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
812 if (o_ptr->sval == SV_LITE_LANTERN)
814 add_flag(o_ptr->art_flags, TR_LITE_2);
815 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
819 if (o_ptr->sval == SV_LITE_FEANOR)
821 add_flag(o_ptr->art_flags, TR_LITE_2);
829 * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
830 * @param player_ptr プレーヤーへの参照ポインタ
831 * @param m_ptr モンスター保存先ポインタ
834 static void rd_monster_old(player_type *player_ptr, monster_type *m_ptr)
836 rd_s16b(&m_ptr->r_idx);
838 if (z_older_than(11, 0, 12))
839 m_ptr->ap_r_idx = m_ptr->r_idx;
841 rd_s16b(&m_ptr->ap_r_idx);
843 if (z_older_than(11, 0, 14))
845 monster_race *r_ptr = &r_info[m_ptr->r_idx];
847 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
848 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
849 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
852 rd_byte(&m_ptr->sub_align);
856 m_ptr->fy = (POSITION)tmp8u;
858 m_ptr->fx = (POSITION)tmp8u;
859 m_ptr->current_floor_ptr = player_ptr->current_floor_ptr;
865 m_ptr->maxhp = tmp16s;
867 if (z_older_than(11, 0, 5))
869 m_ptr->max_maxhp = m_ptr->maxhp;
874 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
876 if (h_older_than(2, 1, 2, 1))
878 m_ptr->dealt_damage = 0;
882 rd_s32b(&m_ptr->dealt_damage);
885 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
887 m_ptr->mspeed = tmp8u;
889 if (z_older_than(10, 4, 2))
892 m_ptr->energy_need = (s16b)tmp8u;
894 else rd_s16b(&m_ptr->energy_need);
896 if (z_older_than(11, 0, 13))
897 m_ptr->energy_need = 100 - m_ptr->energy_need;
899 if (z_older_than(10, 0, 7))
901 m_ptr->mtimed[MTIMED_FAST] = 0;
902 m_ptr->mtimed[MTIMED_SLOW] = 0;
907 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
909 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
913 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
915 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
917 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
919 if (z_older_than(10, 0, 10))
923 else if (z_older_than(10, 0, 11))
931 m_ptr->target_y = (POSITION)tmp16s;
933 m_ptr->target_x = (POSITION)tmp16s;
937 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
939 if (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6))
940 rd_u32b(&m_ptr->smart);
945 if (z_older_than(10, 4, 5))
955 if (z_older_than(10, 2, 2))
957 if (m_ptr->r_idx < 0)
959 m_ptr->r_idx = (0 - m_ptr->r_idx);
960 m_ptr->mflag2 |= MFLAG2_KAGE;
965 rd_byte(&m_ptr->mflag2);
968 if (z_older_than(11, 0, 12))
970 if (m_ptr->mflag2 & MFLAG2_KAGE)
971 m_ptr->ap_r_idx = MON_KAGE;
974 if (z_older_than(10, 1, 3))
981 rd_string(buf, sizeof(buf));
982 if (buf[0]) m_ptr->nickname = quark_add(buf);
990 * @brief モンスターを読み込む(現版) / Read a monster (New method)
991 * @param player_ptr プレーヤーへの参照ポインタ
992 * @param m_ptr モンスター保存先ポインタ
995 static void rd_monster(player_type *player_ptr, monster_type *m_ptr)
997 if (h_older_than(1, 5, 0, 0))
999 rd_monster_old(player_ptr, m_ptr);
1005 rd_s16b(&m_ptr->r_idx);
1008 m_ptr->fy = (POSITION)tmp8u;
1010 m_ptr->fx = (POSITION)tmp8u;
1014 m_ptr->hp = (HIT_POINT)tmp16s;
1016 m_ptr->maxhp = (HIT_POINT)tmp16s;
1018 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1020 if (h_older_than(2, 1, 2, 1))
1022 m_ptr->dealt_damage = 0;
1026 rd_s32b(&m_ptr->dealt_damage);
1029 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1030 else m_ptr->ap_r_idx = m_ptr->r_idx;
1032 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1033 else m_ptr->sub_align = 0;
1035 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1036 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1039 m_ptr->mspeed = tmp8u;
1041 rd_s16b(&m_ptr->energy_need);
1043 if (flags & SAVE_MON_FAST)
1046 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1048 else m_ptr->mtimed[MTIMED_FAST] = 0;
1050 if (flags & SAVE_MON_SLOW)
1053 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1055 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1057 if (flags & SAVE_MON_STUNNED)
1060 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1062 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1064 if (flags & SAVE_MON_CONFUSED)
1067 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1069 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1071 if (flags & SAVE_MON_MONFEAR)
1074 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1076 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1078 if (flags & SAVE_MON_TARGET_Y)
1081 m_ptr->target_y = (POSITION)tmp16s;
1083 else m_ptr->target_y = 0;
1085 if (flags & SAVE_MON_TARGET_X)
1088 m_ptr->target_x = (POSITION)tmp16s;
1090 else m_ptr->target_x = 0;
1092 if (flags & SAVE_MON_INVULNER)
1095 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1097 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1099 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1100 else m_ptr->smart = 0;
1102 if (flags & SAVE_MON_EXP)
1106 m_ptr->exp = (EXP)tmp32u;
1108 else m_ptr->exp = 0;
1110 m_ptr->mflag = 0; /* Not saved */
1112 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1113 else m_ptr->mflag2 = 0;
1115 if (flags & SAVE_MON_NICKNAME)
1118 rd_string(buf, sizeof(buf));
1119 m_ptr->nickname = quark_add(buf);
1121 else m_ptr->nickname = 0;
1123 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1124 else m_ptr->parent_m_idx = 0;
1129 * Old monster bit flags of racial resistances
1131 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1132 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1133 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1134 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1135 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1136 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1137 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1138 #define RF3_RES_WATE 0x00800000 /* Resist water */
1139 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1140 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1141 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1142 #define RF3_RES_ALL 0x08000000 /* Resist all */
1144 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1146 if ((R_PTR)->r_flags3 & (RF3)) \
1148 (R_PTR)->r_flags3 &= ~(RF3); \
1149 (R_PTR)->r_flagsr |= (RFR); \
1153 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1155 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1157 (R_PTR)->r_flagsr |= (RFR); \
1161 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1162 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1163 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1164 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1165 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1166 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1167 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1168 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1169 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1170 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1173 * @brief モンスターの思い出を読み込む / Read the monster lore
1174 * @param r_idx 読み込み先モンスターID
1177 static void rd_lore(MONRACE_IDX r_idx)
1179 monster_race *r_ptr = &r_info[r_idx];
1183 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1186 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1189 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1191 if (h_older_than(1, 7, 0, 5))
1193 r_ptr->r_akills = r_ptr->r_pkills;
1198 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1202 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1204 rd_byte(&r_ptr->r_wake);
1205 rd_byte(&r_ptr->r_ignore);
1206 rd_byte(&r_ptr->r_xtra1);
1207 rd_byte(&r_ptr->r_xtra2);
1211 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1213 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1216 rd_byte(&r_ptr->r_cast_spell);
1218 rd_byte(&r_ptr->r_blows[0]);
1219 rd_byte(&r_ptr->r_blows[1]);
1220 rd_byte(&r_ptr->r_blows[2]);
1221 rd_byte(&r_ptr->r_blows[3]);
1223 rd_u32b(&r_ptr->r_flags1);
1224 rd_u32b(&r_ptr->r_flags2);
1225 rd_u32b(&r_ptr->r_flags3);
1226 rd_u32b(&r_ptr->r_flags4);
1227 rd_u32b(&r_ptr->r_flags5);
1228 rd_u32b(&r_ptr->r_flags6);
1229 if (h_older_than(1, 5, 0, 3))
1231 r_ptr->r_flagsr = 0L;
1232 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1233 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1234 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1235 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1236 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1237 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1238 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1239 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1240 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1241 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1242 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1243 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1245 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1246 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1247 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1248 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1249 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1250 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1251 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1252 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1253 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1255 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1256 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1257 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1261 rd_u32b(&r_ptr->r_flagsr);
1265 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1267 rd_s16b(&r_ptr->floor_id);
1270 r_ptr->r_flags1 &= r_ptr->flags1;
1271 r_ptr->r_flags2 &= r_ptr->flags2;
1272 r_ptr->r_flags3 &= r_ptr->flags3;
1273 r_ptr->r_flags4 &= r_ptr->flags4;
1274 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1275 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1276 r_ptr->r_flagsr &= r_ptr->flagsr;
1281 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1282 * @param player_ptr プレーヤーへの参照ポインタ
1283 * @param st_ptr 店舗の参照ポインタ
1284 * @param o_ptr アイテムオブジェクト参照ポインタ
1287 * In all cases, return the slot (or -1) where the object was placed
1289 * Note that this is a hacked up version of "inven_carry()".
1291 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1292 * known, the player may have to pick stuff up and drop it again.
1294 static void home_carry(player_type *player_ptr, store_type *st_ptr, object_type *o_ptr)
1296 for (int i = 0; i < st_ptr->stock_num; i++)
1299 j_ptr = &st_ptr->stock[i];
1300 if (!object_similar(j_ptr, o_ptr)) continue;
1302 object_absorb(j_ptr, o_ptr);
1306 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) return;
1308 s32b value = object_value(o_ptr);
1310 for (slot = 0; slot < st_ptr->stock_num; slot++)
1312 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1315 for (int i = st_ptr->stock_num; i > slot; i--)
1317 st_ptr->stock[i] = st_ptr->stock[i - 1];
1320 st_ptr->stock_num++;
1321 st_ptr->stock[slot] = *o_ptr;
1322 chg_virtue(player_ptr, V_SACRIFICE, -1);
1327 * @brief 店舗情報を読み込む / Read a store
1328 * @param player_ptr プレーヤーへの参照ポインタ
1329 * @param town_number 街ID
1330 * @param store_number 店舗ID
1333 static errr rd_store(player_type *player_ptr, int town_number, int store_number)
1337 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1339 st_ptr = &town_info[1].store[store_number];
1340 if (st_ptr->stock_num) sort = TRUE;
1344 st_ptr = &town_info[town_number].store[store_number];
1350 rd_s32b(&st_ptr->store_open);
1351 rd_s16b(&st_ptr->insult_cur);
1353 if (z_older_than(11, 0, 4))
1363 rd_s16b(&st_ptr->good_buy);
1364 rd_s16b(&st_ptr->bad_buy);
1366 rd_s32b(&st_ptr->last_visit);
1367 st_ptr->owner = own;
1369 for (int j = 0; j < num; j++)
1378 bool is_valid_item = st_ptr->stock_num < (store_number == STORE_HOME ? STORE_INVEN_MAX * 10 : store_number == STORE_MUSEUM ? STORE_INVEN_MAX * 50 : STORE_INVEN_MAX);
1379 if (!is_valid_item) continue;
1383 home_carry(player_ptr, st_ptr, q_ptr);
1387 int k = st_ptr->stock_num++;
1388 object_copy(&st_ptr->stock[k], q_ptr);
1397 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1400 static void rd_randomizer(void)
1404 rd_u16b(&Rand_place);
1405 for (int i = 0; i < RAND_DEG; i++)
1407 rd_u32b(&Rand_state[i]);
1413 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1416 * Note that the normal options are now stored as a set of 256 bit flags,
1417 * plus a set of 256 bit masks to indicate which bit flags were defined
1418 * at the time the savefile was created. This will allow new options
1419 * to be added, and old options to be removed, at any time, without
1420 * hurting old savefiles.
1422 * The window options are stored in the same way, but note that each
1423 * window gets 32 options, and their order is fixed by certain defines.
1425 static void rd_options(void)
1436 if (h_older_than(1, 7, 0, 0))
1449 if (c & 0x0002) current_world_ptr->wizard = TRUE;
1451 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1452 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1453 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1454 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1455 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1456 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1457 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1458 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1459 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1460 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1462 rd_byte((byte *)&autosave_l);
1463 rd_byte((byte *)&autosave_t);
1464 rd_s16b(&autosave_freq);
1467 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1470 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1472 for (int n = 0; n < 8; n++)
1474 for (int i = 0; i < 32; i++)
1476 if (!(mask[n] & (1L << i))) continue;
1477 if (!(option_mask[n] & (1L << i))) continue;
1479 if (flag[n] & (1L << i))
1481 option_flag[n] |= (1L << i);
1485 option_flag[n] &= ~(1L << i);
1490 if (z_older_than(10, 4, 5))
1492 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1493 else option_flag[5] |= (0x00000001 << 4);
1494 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1495 else option_flag[2] |= (0x00000001 << 5);
1496 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1497 else option_flag[4] |= (0x00000001 << 5);
1498 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1499 else option_flag[5] |= (0x00000001 << 0);
1500 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1501 else option_flag[5] |= (0x00000001 << 12);
1502 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1503 else option_flag[1] |= (0x00000001 << 0);
1504 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1505 else option_flag[1] |= (0x00000001 << 18);
1506 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1507 else option_flag[1] |= (0x00000001 << 19);
1508 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1509 else option_flag[5] |= (0x00000001 << 3);
1512 extract_option_vars();
1513 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1515 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1517 for (int n = 0; n < 8; n++)
1519 for (int i = 0; i < 32; i++)
1521 if (!(mask[n] & (1L << i))) continue;
1522 if (!(window_mask[n] & (1L << i))) continue;
1524 if (flag[n] & (1L << i))
1526 window_flag[n] |= (1L << i);
1530 window_flag[n] &= ~(1L << i);
1538 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1541 * This is such a nasty hack it hurts.
1543 static void rd_ghost(void)
1546 rd_string(buf, sizeof(buf));
1552 * @brief クイックスタート情報を読み込む / Load quick start data
1555 static void load_quick_start(void)
1557 if (z_older_than(11, 0, 13))
1559 previous_char.quick_ok = FALSE;
1563 rd_byte(&previous_char.psex);
1566 previous_char.prace = (RACE_IDX)tmp8u;
1568 previous_char.pclass = (CLASS_IDX)tmp8u;
1570 previous_char.pseikaku = (CHARACTER_IDX)tmp8u;
1572 previous_char.realm1 = (REALM_IDX)tmp8u;
1574 previous_char.realm2 = (REALM_IDX)tmp8u;
1576 rd_s16b(&previous_char.age);
1577 rd_s16b(&previous_char.ht);
1578 rd_s16b(&previous_char.wt);
1579 rd_s16b(&previous_char.sc);
1580 rd_s32b(&previous_char.au);
1582 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1583 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1585 for (int i = 0; i < PY_MAX_LEVEL; i++)
1589 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1592 rd_s16b(&previous_char.chaos_patron);
1594 for (int i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1596 for (int i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1600 previous_char.quick_ok = (bool)tmp8u;
1605 * @brief その他の情報を読み込む / Read the "extra" information
1608 static void rd_extra(player_type *creature_ptr)
1610 rd_string(creature_ptr->name, sizeof(creature_ptr->name));
1611 rd_string(creature_ptr->died_from, sizeof(creature_ptr->died_from));
1612 if (!h_older_than(1, 7, 0, 1))
1615 rd_string(buf, sizeof buf);
1616 if (buf[0]) creature_ptr->last_message = string_make(buf);
1620 for (int i = 0; i < 4; i++)
1622 rd_string(creature_ptr->history[i], sizeof(creature_ptr->history[i]));
1627 creature_ptr->prace = (RACE_IDX)tmp8u;
1630 creature_ptr->pclass = (CLASS_IDX)tmp8u;
1633 creature_ptr->pseikaku = (CHARACTER_IDX)tmp8u;
1635 rd_byte(&creature_ptr->psex);
1637 creature_ptr->realm1 = (REALM_IDX)tmp8u;
1640 creature_ptr->realm2 = (REALM_IDX)tmp8u;
1643 if (z_older_than(10, 4, 4))
1645 if (creature_ptr->realm1 == 9) creature_ptr->realm1 = REALM_MUSIC;
1646 if (creature_ptr->realm2 == 9) creature_ptr->realm2 = REALM_MUSIC;
1647 if (creature_ptr->realm1 == 10) creature_ptr->realm1 = REALM_HISSATSU;
1648 if (creature_ptr->realm2 == 10) creature_ptr->realm2 = REALM_HISSATSU;
1652 creature_ptr->hitdie = tmp8u;
1653 rd_u16b(&creature_ptr->expfact);
1655 rd_s16b(&creature_ptr->age);
1656 rd_s16b(&creature_ptr->ht);
1657 rd_s16b(&creature_ptr->wt);
1659 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max[i]);
1660 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max_max[i]);
1661 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_cur[i]);
1664 rd_s32b(&creature_ptr->au);
1666 rd_s32b(&creature_ptr->max_exp);
1667 if (h_older_than(1, 5, 4, 1)) creature_ptr->max_max_exp = creature_ptr->max_exp;
1668 else rd_s32b(&creature_ptr->max_max_exp);
1669 rd_s32b(&creature_ptr->exp);
1671 if (h_older_than(1, 7, 0, 3))
1675 creature_ptr->exp_frac = (u32b)tmp16u;
1679 rd_u32b(&creature_ptr->exp_frac);
1682 rd_s16b(&creature_ptr->lev);
1684 for (int i = 0; i < 64; i++) rd_s16b(&creature_ptr->spell_exp[i]);
1685 if ((creature_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1687 for (int i = 0; i < 64; i++) creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1690 if (z_older_than(10, 3, 6))
1691 for (int i = 0; i < 5; i++) for (int j = 0; j < 60; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1693 for (int i = 0; i < 5; i++) for (int j = 0; j < 64; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1694 for (int i = 0; i < GINOU_MAX; i++) rd_s16b(&creature_ptr->skill_exp[i]);
1695 if (z_older_than(10, 4, 1))
1697 if (creature_ptr->pclass != CLASS_BEASTMASTER) creature_ptr->skill_exp[GINOU_RIDING] /= 2;
1698 creature_ptr->skill_exp[GINOU_RIDING] = MIN(creature_ptr->skill_exp[GINOU_RIDING], s_info[creature_ptr->pclass].s_max[GINOU_RIDING]);
1701 if (z_older_than(10, 3, 14))
1703 for (int i = 0; i < 108; i++) creature_ptr->magic_num1[i] = 0;
1704 for (int i = 0; i < 108; i++) creature_ptr->magic_num2[i] = 0;
1708 for (int i = 0; i < 108; i++) rd_s32b(&creature_ptr->magic_num1[i]);
1709 for (int i = 0; i < 108; i++) rd_byte(&creature_ptr->magic_num2[i]);
1710 if (h_older_than(1, 3, 0, 1))
1712 if (creature_ptr->pclass == CLASS_SMITH)
1714 creature_ptr->magic_num1[TR_ES_ATTACK] = creature_ptr->magic_num1[96];
1715 creature_ptr->magic_num1[96] = 0;
1716 creature_ptr->magic_num1[TR_ES_AC] = creature_ptr->magic_num1[97];
1717 creature_ptr->magic_num1[97] = 0;
1722 if (music_singing_any(creature_ptr)) creature_ptr->action = ACTION_SING;
1724 if (z_older_than(11, 0, 7))
1726 creature_ptr->start_race = creature_ptr->prace;
1727 creature_ptr->old_race1 = 0L;
1728 creature_ptr->old_race2 = 0L;
1729 creature_ptr->old_realm = 0;
1734 creature_ptr->start_race = (RACE_IDX)tmp8u;
1737 creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1739 creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1740 rd_s16b(&creature_ptr->old_realm);
1743 if (z_older_than(10, 0, 1))
1745 for (int i = 0; i < MAX_MANE; i++)
1747 creature_ptr->mane_spell[i] = -1;
1748 creature_ptr->mane_dam[i] = 0;
1750 creature_ptr->mane_num = 0;
1752 else if (z_older_than(10, 2, 3))
1755 for (int i = 0; i < OLD_MAX_MANE; i++)
1761 for (int i = 0; i < MAX_MANE; i++)
1763 creature_ptr->mane_spell[i] = -1;
1764 creature_ptr->mane_dam[i] = 0;
1768 creature_ptr->mane_num = 0;
1772 for (int i = 0; i < MAX_MANE; i++)
1776 creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1778 creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1781 rd_s16b(&creature_ptr->mane_num);
1784 if (z_older_than(10, 0, 3))
1786 determine_bounty_uniques(creature_ptr);
1788 for (int i = 0; i < MAX_BOUNTY; i++)
1790 /* Is this bounty unique already dead? */
1791 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1796 for (int i = 0; i < MAX_BOUNTY; i++)
1798 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1802 if (z_older_than(10, 0, 3))
1804 update_gambling_monsters(creature_ptr);
1808 for (int i = 0; i < 4; i++)
1810 rd_s16b(&battle_mon[i]);
1811 if (z_older_than(10, 3, 4))
1815 mon_odds[i] = tmp16s;
1817 else rd_u32b(&mon_odds[i]);
1821 rd_s16b(&creature_ptr->town_num);
1822 rd_s16b(&creature_ptr->arena_number);
1823 if (h_older_than(1, 5, 0, 1))
1825 if (creature_ptr->arena_number >= 99) creature_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1830 creature_ptr->current_floor_ptr->inside_arena = (bool)tmp16s;
1831 rd_s16b(&creature_ptr->current_floor_ptr->inside_quest);
1832 if (z_older_than(10, 3, 5)) creature_ptr->phase_out = FALSE;
1836 creature_ptr->phase_out = (bool)tmp16s;
1839 rd_byte(&creature_ptr->exit_bldg);
1843 creature_ptr->oldpx = (POSITION)tmp16s;
1846 creature_ptr->oldpy = (POSITION)tmp16s;
1847 if (z_older_than(10, 3, 13) && !creature_ptr->current_floor_ptr->dun_level && !creature_ptr->current_floor_ptr->inside_arena) { creature_ptr->oldpy = 33; creature_ptr->oldpx = 131; }
1850 for (int i = 0; i < tmp16s; i++)
1856 if (h_older_than(1, 7, 0, 3))
1859 creature_ptr->mhp = tmp16s;
1862 creature_ptr->chp = tmp16s;
1866 creature_ptr->chp_frac = (u32b)tmp16u;
1870 rd_s32b(&creature_ptr->mhp);
1871 rd_s32b(&creature_ptr->chp);
1872 rd_u32b(&creature_ptr->chp_frac);
1875 if (h_older_than(1, 7, 0, 3))
1878 creature_ptr->msp = tmp16s;
1881 creature_ptr->csp = tmp16s;
1885 creature_ptr->csp_frac = (u32b)tmp16u;
1889 rd_s32b(&creature_ptr->msp);
1890 rd_s32b(&creature_ptr->csp);
1891 rd_u32b(&creature_ptr->csp_frac);
1894 rd_s16b(&creature_ptr->max_plv);
1895 if (z_older_than(10, 3, 8))
1898 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1902 byte max = (byte)current_world_ptr->max_d_idx;
1906 for (int i = 0; i < max; i++)
1909 max_dlv[i] = tmp16s;
1910 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1914 if (creature_ptr->max_plv < creature_ptr->lev) creature_ptr->max_plv = creature_ptr->lev;
1917 rd_s16b(&creature_ptr->sc);
1918 rd_s16b(&creature_ptr->concent);
1920 strip_bytes(2); /* Old "rest" */
1921 rd_s16b(&creature_ptr->blind);
1922 rd_s16b(&creature_ptr->paralyzed);
1923 rd_s16b(&creature_ptr->confused);
1924 rd_s16b(&creature_ptr->food);
1925 strip_bytes(4); /* Old "food_digested" / "protection" */
1927 rd_s16b(&creature_ptr->energy_need);
1928 if (z_older_than(11, 0, 13))
1929 creature_ptr->energy_need = 100 - creature_ptr->energy_need;
1930 if (h_older_than(2, 1, 2, 0))
1931 creature_ptr->enchant_energy_need = 0;
1933 rd_s16b(&creature_ptr->enchant_energy_need);
1935 rd_s16b(&creature_ptr->fast);
1936 rd_s16b(&creature_ptr->slow);
1937 rd_s16b(&creature_ptr->afraid);
1938 rd_s16b(&creature_ptr->cut);
1939 rd_s16b(&creature_ptr->stun);
1940 rd_s16b(&creature_ptr->poisoned);
1941 rd_s16b(&creature_ptr->image);
1942 rd_s16b(&creature_ptr->protevil);
1943 rd_s16b(&creature_ptr->invuln);
1944 if (z_older_than(10, 0, 0))
1945 creature_ptr->ult_res = 0;
1947 rd_s16b(&creature_ptr->ult_res);
1948 rd_s16b(&creature_ptr->hero);
1949 rd_s16b(&creature_ptr->shero);
1950 rd_s16b(&creature_ptr->shield);
1951 rd_s16b(&creature_ptr->blessed);
1952 rd_s16b(&creature_ptr->tim_invis);
1953 rd_s16b(&creature_ptr->word_recall);
1954 if (z_older_than(10, 3, 8))
1955 creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
1959 creature_ptr->recall_dungeon = (byte)tmp16s;
1962 if (h_older_than(1, 5, 0, 0))
1963 creature_ptr->alter_reality = 0;
1965 rd_s16b(&creature_ptr->alter_reality);
1967 rd_s16b(&creature_ptr->see_infra);
1968 rd_s16b(&creature_ptr->tim_infra);
1969 rd_s16b(&creature_ptr->oppose_fire);
1970 rd_s16b(&creature_ptr->oppose_cold);
1971 rd_s16b(&creature_ptr->oppose_acid);
1972 rd_s16b(&creature_ptr->oppose_elec);
1973 rd_s16b(&creature_ptr->oppose_pois);
1974 if (z_older_than(10, 0, 2)) creature_ptr->tsuyoshi = 0;
1975 else rd_s16b(&creature_ptr->tsuyoshi);
1977 /* Old savefiles do not have the following fields... */
1978 if ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->z_patch == 6))
1980 creature_ptr->tim_esp = 0;
1981 creature_ptr->wraith_form = 0;
1982 creature_ptr->resist_magic = 0;
1983 creature_ptr->tim_regen = 0;
1984 creature_ptr->kabenuke = 0;
1985 creature_ptr->tim_stealth = 0;
1986 creature_ptr->tim_levitation = 0;
1987 creature_ptr->tim_sh_touki = 0;
1988 creature_ptr->lightspeed = 0;
1989 creature_ptr->tsubureru = 0;
1990 creature_ptr->tim_res_nether = 0;
1991 creature_ptr->tim_res_time = 0;
1992 creature_ptr->mimic_form = 0;
1993 creature_ptr->tim_mimic = 0;
1994 creature_ptr->tim_sh_fire = 0;
1995 creature_ptr->tim_reflect = 0;
1996 creature_ptr->multishadow = 0;
1997 creature_ptr->dustrobe = 0;
1998 creature_ptr->chaos_patron = ((creature_ptr->age + creature_ptr->sc) % MAX_PATRON);
1999 creature_ptr->muta1 = 0;
2000 creature_ptr->muta2 = 0;
2001 creature_ptr->muta3 = 0;
2002 get_virtues(creature_ptr);
2006 rd_s16b(&creature_ptr->tim_esp);
2007 rd_s16b(&creature_ptr->wraith_form);
2008 rd_s16b(&creature_ptr->resist_magic);
2009 rd_s16b(&creature_ptr->tim_regen);
2010 rd_s16b(&creature_ptr->kabenuke);
2011 rd_s16b(&creature_ptr->tim_stealth);
2012 rd_s16b(&creature_ptr->tim_levitation);
2013 rd_s16b(&creature_ptr->tim_sh_touki);
2014 rd_s16b(&creature_ptr->lightspeed);
2015 rd_s16b(&creature_ptr->tsubureru);
2016 if (z_older_than(10, 4, 7))
2017 creature_ptr->magicdef = 0;
2019 rd_s16b(&creature_ptr->magicdef);
2020 rd_s16b(&creature_ptr->tim_res_nether);
2021 if (z_older_than(10, 4, 11))
2023 creature_ptr->tim_res_time = 0;
2024 creature_ptr->mimic_form = 0;
2025 creature_ptr->tim_mimic = 0;
2026 creature_ptr->tim_sh_fire = 0;
2030 rd_s16b(&creature_ptr->tim_res_time);
2032 creature_ptr->mimic_form = (IDX)tmp8u;
2033 rd_s16b(&creature_ptr->tim_mimic);
2034 rd_s16b(&creature_ptr->tim_sh_fire);
2037 if (z_older_than(11, 0, 99))
2039 creature_ptr->tim_sh_holy = 0;
2040 creature_ptr->tim_eyeeye = 0;
2044 rd_s16b(&creature_ptr->tim_sh_holy);
2045 rd_s16b(&creature_ptr->tim_eyeeye);
2048 if (z_older_than(11, 0, 3)) {
2049 creature_ptr->tim_reflect = 0;
2050 creature_ptr->multishadow = 0;
2051 creature_ptr->dustrobe = 0;
2055 rd_s16b(&creature_ptr->tim_reflect);
2056 rd_s16b(&creature_ptr->multishadow);
2057 rd_s16b(&creature_ptr->dustrobe);
2060 rd_s16b(&creature_ptr->chaos_patron);
2061 rd_u32b(&creature_ptr->muta1);
2062 rd_u32b(&creature_ptr->muta2);
2063 rd_u32b(&creature_ptr->muta3);
2065 for (int i = 0; i < 8; i++)
2066 rd_s16b(&creature_ptr->virtues[i]);
2067 for (int i = 0; i < 8; i++)
2068 rd_s16b(&creature_ptr->vir_types[i]);
2071 creature_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod(creature_ptr);
2072 if (z_older_than(10, 0, 9))
2075 if (tmp8u) creature_ptr->special_attack = ATTACK_CONFUSE;
2076 creature_ptr->ele_attack = 0;
2080 rd_s16b(&creature_ptr->ele_attack);
2081 rd_u32b(&creature_ptr->special_attack);
2084 if (creature_ptr->special_attack & KAMAE_MASK) creature_ptr->action = ACTION_KAMAE;
2085 else if (creature_ptr->special_attack & KATA_MASK) creature_ptr->action = ACTION_KATA;
2086 if (z_older_than(10, 0, 12))
2088 creature_ptr->ele_immune = 0;
2089 creature_ptr->special_defense = 0;
2093 rd_s16b(&creature_ptr->ele_immune);
2094 rd_u32b(&creature_ptr->special_defense);
2097 rd_byte(&creature_ptr->knowledge);
2099 creature_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2103 creature_ptr->action = (ACTION_IDX)tmp8u;
2104 if (!z_older_than(10, 4, 3))
2107 if (tmp8u) creature_ptr->action = ACTION_LEARN;
2110 rd_byte((byte *)&preserve_mode);
2111 rd_byte((byte *)&creature_ptr->wait_report_score);
2113 for (int i = 0; i < 48; i++) rd_byte(&tmp8u);
2116 rd_u32b(¤t_world_ptr->seed_flavor);
2117 rd_u32b(¤t_world_ptr->seed_town);
2119 rd_u16b(&creature_ptr->panic_save);
2120 rd_u16b(¤t_world_ptr->total_winner);
2121 rd_u16b(¤t_world_ptr->noscore);
2124 creature_ptr->is_dead = tmp8u;
2126 rd_byte(&creature_ptr->feeling);
2128 switch (creature_ptr->start_race)
2134 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2137 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2141 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2142 rd_s32b(&creature_ptr->current_floor_ptr->generated_turn);
2143 if (h_older_than(1, 7, 0, 4))
2145 creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
2149 rd_s32b(&creature_ptr->feeling_turn);
2152 rd_s32b(¤t_world_ptr->game_turn);
2153 if (z_older_than(10, 3, 12))
2155 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2157 else rd_s32b(¤t_world_ptr->dungeon_turn);
2159 if (z_older_than(11, 0, 13))
2161 creature_ptr->current_floor_ptr->generated_turn /= 2;
2162 creature_ptr->feeling_turn /= 2;
2163 current_world_ptr->game_turn /= 2;
2164 current_world_ptr->dungeon_turn /= 2;
2167 if (z_older_than(10, 3, 13))
2169 current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
2171 else rd_s32b(¤t_world_ptr->arena_start_turn);
2173 if (z_older_than(10, 0, 3))
2175 determine_daily_bounty(creature_ptr, TRUE);
2179 rd_s16b(&today_mon);
2180 rd_s16b(&creature_ptr->today_mon);
2183 if (z_older_than(10, 0, 7))
2185 creature_ptr->riding = 0;
2189 rd_s16b(&creature_ptr->riding);
2192 if (h_older_than(1, 5, 0, 0))
2194 creature_ptr->floor_id = 0;
2198 rd_s16b(&creature_ptr->floor_id);
2201 if (h_older_than(1, 5, 0, 2))
2208 for (int i = 0; i < tmp16s; i++)
2210 monster_type dummy_mon;
2211 rd_monster(creature_ptr, &dummy_mon);
2215 if (z_older_than(10, 1, 2))
2217 current_world_ptr->play_time = 0;
2221 rd_u32b(¤t_world_ptr->play_time);
2224 if (z_older_than(10, 3, 9))
2226 creature_ptr->visit = 1L;
2228 else if (z_older_than(10, 3, 10))
2232 creature_ptr->visit = 1L;
2238 creature_ptr->visit = (BIT_FLAGS)tmp32s;
2241 if (!z_older_than(11, 0, 5))
2243 rd_u32b(&creature_ptr->count);
2249 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2250 * @param player_ptr プレーヤーへの参照ポインタ
2253 * Note that the inventory changed in Angband 2.7.4. Two extra
2254 * pack slots were added and the equipment was rearranged. Note
2255 * that these two features combine when parsing old save-files, in
2256 * which items from the old "aux" slot are "carried", perhaps into
2257 * one of the two new "inventory" slots.
2259 * Note that the inventory is "re-sorted" later by "dungeon()".
2261 static errr rd_inventory(player_type *player_ptr)
2263 player_ptr->total_weight = 0;
2264 player_ptr->inven_cnt = 0;
2265 player_ptr->equip_cnt = 0;
2267 if (player_ptr->inventory_list != NULL) C_WIPE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2268 C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2276 if (n == 0xFFFF) break;
2283 if (!q_ptr->k_idx) return (53);
2285 if (n >= INVEN_RARM)
2287 q_ptr->marked |= OM_TOUCHED;
2288 object_copy(&player_ptr->inventory_list[n], q_ptr);
2289 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2290 player_ptr->equip_cnt++;
2294 if (player_ptr->inven_cnt == INVEN_PACK)
2296 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
2301 q_ptr->marked |= OM_TOUCHED;
2302 object_copy(&player_ptr->inventory_list[n], q_ptr);
2303 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2304 player_ptr->inven_cnt++;
2312 * @brief メッセージログを読み込む / Read the saved messages
2315 static void rd_messages(void)
2317 if (h_older_than(2, 2, 0, 75))
2322 message_max = (int)num;
2324 for (int i = 0; i < message_max; i++)
2327 rd_string(buf, sizeof(buf));
2335 message_max = (int)num;
2337 for (int i = 0; i < message_max; i++)
2340 rd_string(buf, sizeof(buf));
2347 * @brief メッセージログを読み込む / Read the dungeon (old method)
2348 * @param creature_ptr プレーヤーへの参照ポインタ
2351 * The monsters/objects must be loaded in the same order
2352 * that they were stored, since the actual indexes matter.
2354 static errr rd_dungeon_old(player_type *creature_ptr)
2358 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2359 floor_ptr->dun_level = (DEPTH)tmp16s;
2360 if (z_older_than(10, 3, 8)) creature_ptr->dungeon_idx = DUNGEON_ANGBAND;
2365 creature_ptr->dungeon_idx = (IDX)tmp8u;
2368 floor_ptr->base_level = floor_ptr->dun_level;
2370 floor_ptr->base_level = (DEPTH)tmp16s;
2373 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2375 creature_ptr->y = (POSITION)tmp16s;
2377 creature_ptr->x = (POSITION)tmp16s;
2378 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) { creature_ptr->y = 33; creature_ptr->x = 131; }
2380 floor_ptr->height = (POSITION)tmp16s;
2382 floor_ptr->width = (POSITION)tmp16s;
2383 rd_s16b(&tmp16s); /* max_panel_rows */
2384 rd_s16b(&tmp16s); /* max_panel_cols */
2386 int ymax = floor_ptr->height;
2387 int xmax = floor_ptr->width;
2389 for (int x = 0, y = 0; y < ymax; )
2394 if (z_older_than(10, 3, 6))
2403 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2406 for (int i = count; i > 0; i--)
2409 g_ptr = &floor_ptr->grid_array[y][x];
2414 if (++y >= ymax) break;
2419 for (int x = 0, y = 0; y < ymax; )
2425 for (int i = count; i > 0; i--)
2428 g_ptr = &floor_ptr->grid_array[y][x];
2429 g_ptr->feat = (s16b)tmp8u;
2433 if (++y >= ymax) break;
2438 for (int x = 0, y = 0; y < ymax; )
2444 for (int i = count; i > 0; i--)
2447 g_ptr = &floor_ptr->grid_array[y][x];
2448 g_ptr->mimic = (s16b)tmp8u;
2452 if (++y >= ymax) break;
2457 for (int x = 0, y = 0; y < ymax; )
2462 for (int i = count; i > 0; i--)
2465 g_ptr = &floor_ptr->grid_array[y][x];
2466 g_ptr->special = tmp16s;
2470 if (++y >= ymax) break;
2475 if (z_older_than(11, 0, 99))
2477 for (int y = 0; y < ymax; y++)
2479 for (int x = 0; x < xmax; x++)
2481 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2486 if (h_older_than(1, 1, 1, 0))
2488 for (int y = 0; y < ymax; y++)
2490 for (int x = 0; x < xmax; x++)
2493 g_ptr = &floor_ptr->grid_array[y][x];
2496 if (g_ptr->feat == OLD_FEAT_INVIS)
2498 g_ptr->feat = feat_floor;
2499 g_ptr->info |= CAVE_TRAP;
2502 /* Older than 1.1.1 */
2503 if (g_ptr->feat == OLD_FEAT_MIRROR)
2505 g_ptr->feat = feat_floor;
2506 g_ptr->info |= CAVE_OBJECT;
2512 if (h_older_than(1, 3, 1, 0))
2514 for (int y = 0; y < ymax; y++)
2516 for (int x = 0; x < xmax; x++)
2519 g_ptr = &floor_ptr->grid_array[y][x];
2521 /* Old CAVE_IN_MIRROR flag */
2522 if (g_ptr->info & CAVE_OBJECT)
2524 g_ptr->mimic = feat_mirror;
2526 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2527 (g_ptr->feat == OLD_FEAT_GLYPH))
2529 g_ptr->info |= CAVE_OBJECT;
2530 g_ptr->mimic = g_ptr->feat;
2531 g_ptr->feat = feat_floor;
2533 else if (g_ptr->info & CAVE_TRAP)
2535 g_ptr->info &= ~CAVE_TRAP;
2536 g_ptr->mimic = g_ptr->feat;
2537 g_ptr->feat = choose_random_trap(creature_ptr);
2539 else if (g_ptr->feat == OLD_FEAT_INVIS)
2541 g_ptr->mimic = feat_floor;
2542 g_ptr->feat = feat_trap_open;
2548 /* Quest 18 was removed */
2549 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2551 for (int y = 0; y < ymax; y++)
2553 for (int x = 0; x < xmax; x++)
2556 g_ptr = &floor_ptr->grid_array[y][x];
2558 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2560 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2562 g_ptr->feat = feat_tree;
2565 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2567 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2570 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2571 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2573 g_ptr->feat = feat_up_stair;
2582 if (limit > current_world_ptr->max_o_idx)
2584 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2588 for (int i = 1; i < limit; i++)
2590 OBJECT_IDX o_idx = o_pop(floor_ptr);
2593 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2598 o_ptr = &floor_ptr->o_list[o_idx];
2600 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2602 monster_type *m_ptr;
2603 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2604 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2605 m_ptr->hold_o_idx = o_idx;
2610 g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2611 o_ptr->next_o_idx = g_ptr->o_idx;
2612 g_ptr->o_idx = o_idx;
2616 if (limit > current_world_ptr->max_m_idx)
2618 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2622 for (int i = 1; i < limit; i++)
2625 monster_type *m_ptr;
2626 m_idx = m_pop(creature_ptr);
2629 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2633 m_ptr = &floor_ptr->m_list[m_idx];
2634 rd_monster(creature_ptr, m_ptr);
2636 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2637 g_ptr->m_idx = m_idx;
2638 real_r_ptr(m_ptr)->cur_num++;
2641 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena)
2642 current_world_ptr->character_dungeon = FALSE;
2644 current_world_ptr->character_dungeon = TRUE;
2651 * @brief 保存されたフロアを読み込む / Read the saved floor
2652 * @param player_ptr プレーヤーへの参照ポインタ
2653 * @param sf_ptr 最後に保存されたフロアへの参照ポインタ
2654 * @return info読み込みエラーコード
2656 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2659 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2660 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2662 * The monsters/objects must be loaded in the same order
2663 * that they were stored, since the actual indexes matter.
2665 static errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
2667 grid_template_type *templates;
2668 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2669 clear_cave(player_ptr);
2670 player_ptr->x = player_ptr->y = 0;
2676 floor_ptr->dun_level = (DEPTH)tmp16s;
2677 floor_ptr->base_level = floor_ptr->dun_level;
2683 if (tmp16s != sf_ptr->floor_id) return 171;
2687 if (tmp8u != sf_ptr->savefile_id) return 171;
2690 if (tmp16s != sf_ptr->dun_level) return 171;
2691 floor_ptr->dun_level = sf_ptr->dun_level;
2695 if (tmp32s != sf_ptr->last_visit) return 171;
2699 if (tmp32u != sf_ptr->visit_mark) return 171;
2702 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2705 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2710 floor_ptr->base_level = (DEPTH)tmp16s;
2712 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2716 player_ptr->y = (POSITION)tmp16u;
2719 player_ptr->x = (POSITION)tmp16u;
2722 floor_ptr->height = (POSITION)tmp16s;
2724 floor_ptr->width = (POSITION)tmp16s;
2726 rd_byte(&player_ptr->feeling);
2730 C_MAKE(templates, limit, grid_template_type);
2732 for (int i = 0; i < limit; i++)
2734 grid_template_type *ct_ptr = &templates[i];
2736 ct_ptr->info = (BIT_FLAGS)tmp16u;
2737 if (h_older_than(1, 7, 0, 2))
2741 ct_ptr->feat = (s16b)tmp8u;
2743 ct_ptr->mimic = (s16b)tmp8u;
2747 rd_s16b(&ct_ptr->feat);
2748 rd_s16b(&ct_ptr->mimic);
2751 rd_s16b(&ct_ptr->special);
2754 POSITION ymax = floor_ptr->height;
2755 POSITION xmax = floor_ptr->width;
2756 for (POSITION x = 0, y = 0; y < ymax; )
2767 } while (tmp8u == MAX_UCHAR);
2769 for (int i = count; i > 0; i--)
2771 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2772 g_ptr->info = templates[id].info;
2773 g_ptr->feat = templates[id].feat;
2774 g_ptr->mimic = templates[id].mimic;
2775 g_ptr->special = templates[id].special;
2780 if (++y >= ymax) break;
2785 /* Quest 18 was removed */
2786 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2788 for (POSITION y = 0; y < ymax; y++)
2790 for (POSITION x = 0; x < xmax; x++)
2792 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2794 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2796 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2798 g_ptr->feat = feat_tree;
2801 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2803 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2806 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2807 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2809 g_ptr->feat = feat_up_stair;
2816 C_KILL(templates, limit, grid_template_type);
2818 if (limit > current_world_ptr->max_o_idx) return 151;
2819 for (int i = 1; i < limit; i++)
2823 o_idx = o_pop(floor_ptr);
2824 if (i != o_idx) return 152;
2826 o_ptr = &floor_ptr->o_list[o_idx];
2829 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2831 monster_type *m_ptr;
2832 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2833 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2834 m_ptr->hold_o_idx = o_idx;
2838 grid_type *g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2839 o_ptr->next_o_idx = g_ptr->o_idx;
2840 g_ptr->o_idx = o_idx;
2845 if (limit > current_world_ptr->max_m_idx) return 161;
2847 for (int i = 1; i < limit; i++)
2851 monster_type *m_ptr;
2852 m_idx = m_pop(player_ptr);
2853 if (i != m_idx) return 162;
2855 m_ptr = &floor_ptr->m_list[m_idx];
2856 rd_monster(player_ptr, m_ptr);
2857 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2858 g_ptr->m_idx = m_idx;
2859 real_r_ptr(m_ptr)->cur_num++;
2867 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
2868 * @param player_ptr プレーヤーへの参照ポインタ
2871 * The monsters/objects must be loaded in the same order
2872 * that they were stored, since the actual indexes matter.
2874 static errr rd_dungeon(player_type *player_ptr)
2876 init_saved_floors(player_ptr, FALSE);
2878 if (h_older_than(1, 5, 0, 0))
2880 err = rd_dungeon_old(player_ptr);
2881 if (player_ptr->dungeon_idx)
2883 player_ptr->floor_id = get_new_floor_id(player_ptr);
2884 get_sf_ptr(player_ptr->floor_id)->dun_level = player_ptr->current_floor_ptr->dun_level;
2890 rd_s16b(&max_floor_id);
2893 player_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
2898 err = rd_saved_floor(player_ptr, NULL);
2902 for (int i = 0; i < num; i++)
2904 saved_floor_type *sf_ptr = &saved_floors[i];
2906 rd_s16b(&sf_ptr->floor_id);
2908 sf_ptr->savefile_id = (s16b)tmp8u;
2912 sf_ptr->dun_level = (DEPTH)tmp16s;
2914 rd_s32b(&sf_ptr->last_visit);
2915 rd_u32b(&sf_ptr->visit_mark);
2916 rd_s16b(&sf_ptr->upper_floor_id);
2917 rd_s16b(&sf_ptr->lower_floor_id);
2920 for (int i = 0; i < num; i++)
2922 saved_floor_type *sf_ptr = &saved_floors[i];
2923 if (!sf_ptr->floor_id) continue;
2925 if (tmp8u) continue;
2927 err = rd_saved_floor(player_ptr, sf_ptr);
2930 if (!save_floor(player_ptr, sf_ptr, SLF_SECOND)) err = 182;
2937 if (!load_floor(player_ptr, get_sf_ptr(player_ptr->floor_id), SLF_SECOND)) err = 183;
2944 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
2948 note(_("アイテム配置エラー", "Object allocation error"));
2952 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
2956 note(_("モンスター配置エラー", "Monster allocation error"));
2960 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
2964 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporary files!"));
2968 note(_("Error 183", "Error 183"));
2972 current_world_ptr->character_dungeon = TRUE;
2978 * @brief ロード処理全体のサブ関数 / Actually read the savefile
2981 static errr rd_savefile_new_aux(player_type *creature_ptr)
2983 u32b n_x_check, n_v_check;
2984 u32b o_x_check, o_v_check;
2987 xor_byte = current_world_ptr->sf_extra;
2991 /* Old savefile will be version 0.0.0.3 */
2992 rd_byte(¤t_world_ptr->h_ver_extra);
2993 rd_byte(¤t_world_ptr->h_ver_patch);
2994 rd_byte(¤t_world_ptr->h_ver_minor);
2995 rd_byte(¤t_world_ptr->h_ver_major);
2998 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
2999 (current_world_ptr->h_ver_major > 9) ? current_world_ptr->h_ver_major - 10 : current_world_ptr->h_ver_major, current_world_ptr->h_ver_minor, current_world_ptr->h_ver_patch, current_world_ptr->h_ver_extra));
3001 rd_u32b(¤t_world_ptr->sf_system);
3002 rd_u32b(¤t_world_ptr->sf_when);
3003 rd_u16b(¤t_world_ptr->sf_lives);
3004 rd_u16b(¤t_world_ptr->sf_saves);
3014 rd_byte(&kanji_code);
3017 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3020 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3023 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3025 for (int i = 0; i < max_r_idx; i++)
3027 monster_race *r_ptr = &r_info[i];
3028 r_ptr->max_num = 100;
3030 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3031 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3035 if (tmp16u > max_r_idx)
3037 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3041 for (int i = 0; i < tmp16u; i++)
3043 rd_lore((MONRACE_IDX)i);
3046 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3049 if (tmp16u > max_k_idx)
3051 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3055 for (int i = 0; i < tmp16u; i++)
3057 object_kind *k_ptr = &k_info[i];
3059 k_ptr->aware = (tmp8u & 0x01) ? TRUE : FALSE;
3060 k_ptr->tried = (tmp8u & 0x02) ? TRUE : FALSE;
3062 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3064 /* 2.1.3 or newer version */
3066 u16b max_towns_load;
3067 u16b max_quests_load;
3068 byte max_rquests_load;
3069 s16b old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
3071 rd_u16b(&max_towns_load);
3072 if (max_towns_load > max_towns)
3074 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3078 rd_u16b(&max_quests_load);
3079 if (z_older_than(11, 0, 7))
3081 max_rquests_load = 10;
3085 rd_byte(&max_rquests_load);
3088 if (max_quests_load > max_q_idx)
3090 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3094 for (int i = 0; i < max_quests_load; i++)
3103 quest_type* const q_ptr = &quest[i];
3105 rd_s16b(&q_ptr->status);
3108 q_ptr->level = tmp16s;
3110 if (z_older_than(11, 0, 6))
3117 q_ptr->complev = tmp8u;
3119 if (h_older_than(2, 1, 2, 2))
3121 q_ptr->comptime = 0;
3125 rd_u32b(&q_ptr->comptime);
3128 bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
3129 is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
3130 is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
3131 if (!is_quest_running) continue;
3134 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3136 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3137 rd_s16b(&q_ptr->type);
3139 rd_s16b(&q_ptr->r_idx);
3140 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3142 determine_random_questor(creature_ptr, &quest[i]);
3145 rd_s16b(&q_ptr->k_idx);
3147 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3150 q_ptr->flags = tmp8u;
3152 if (z_older_than(10, 3, 11))
3154 if (q_ptr->flags & QUEST_FLAG_PRESET)
3160 init_flags = INIT_ASSIGN;
3161 creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)i;
3163 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
3164 creature_ptr->current_floor_ptr->inside_quest = old_inside_quest;
3170 q_ptr->dungeon = tmp8u;
3173 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3174 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3175 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3178 /* Quest 18 was removed */
3179 if (h_older_than(1, 7, 0, 6))
3181 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3182 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3185 rd_s32b(&creature_ptr->wilderness_x);
3186 rd_s32b(&creature_ptr->wilderness_y);
3187 if (z_older_than(10, 3, 13))
3189 creature_ptr->wilderness_x = 5;
3190 creature_ptr->wilderness_y = 48;
3193 if (z_older_than(10, 3, 7)) creature_ptr->wild_mode = FALSE;
3194 else rd_byte((byte *)&creature_ptr->wild_mode);
3195 if (z_older_than(10, 3, 7)) creature_ptr->ambush_flag = FALSE;
3196 else rd_byte((byte *)&creature_ptr->ambush_flag);
3200 rd_s32b(&wild_x_size);
3201 rd_s32b(&wild_y_size);
3203 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3205 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3209 for (int i = 0; i < wild_x_size; i++)
3211 for (int j = 0; j < wild_y_size; j++)
3213 rd_u32b(&wilderness[j][i].seed);
3218 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3221 if (tmp16u > max_a_idx)
3223 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3227 for (int i = 0; i < tmp16u; i++)
3229 artifact_type *a_ptr = &a_info[i];
3232 a_ptr->cur_num = tmp8u;
3234 if (h_older_than(1, 5, 0, 0))
3236 a_ptr->floor_id = 0;
3244 rd_s16b(&a_ptr->floor_id);
3248 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3250 rd_extra(creature_ptr);
3251 if (creature_ptr->energy_need < -999) creature_ptr->timewalk = TRUE;
3253 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3256 if (tmp16u > PY_MAX_LEVEL)
3258 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3262 for (int i = 0; i < tmp16u; i++)
3266 creature_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3269 sp_ptr = &sex_info[creature_ptr->psex];
3270 rp_ptr = &race_info[creature_ptr->prace];
3271 cp_ptr = &class_info[creature_ptr->pclass];
3272 ap_ptr = &seikaku_info[creature_ptr->pseikaku];
3274 if (z_older_than(10, 2, 2) && (creature_ptr->pclass == CLASS_BEASTMASTER) && !creature_ptr->is_dead)
3276 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3277 roll_hitdice(creature_ptr, 0L);
3280 if (z_older_than(10, 3, 2) && (creature_ptr->pclass == CLASS_ARCHER) && !creature_ptr->is_dead)
3282 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3283 roll_hitdice(creature_ptr, 0L);
3286 if (z_older_than(10, 2, 6) && (creature_ptr->pclass == CLASS_SORCERER) && !creature_ptr->is_dead)
3288 creature_ptr->hitdie = rp_ptr->r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3289 roll_hitdice(creature_ptr, 0L);
3292 if (z_older_than(10, 4, 7) && (creature_ptr->pclass == CLASS_BLUE_MAGE) && !creature_ptr->is_dead)
3294 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3295 roll_hitdice(creature_ptr, 0L);
3298 mp_ptr = &m_info[creature_ptr->pclass];
3300 rd_u32b(&creature_ptr->spell_learned1);
3301 rd_u32b(&creature_ptr->spell_learned2);
3302 rd_u32b(&creature_ptr->spell_worked1);
3303 rd_u32b(&creature_ptr->spell_worked2);
3304 rd_u32b(&creature_ptr->spell_forgotten1);
3305 rd_u32b(&creature_ptr->spell_forgotten2);
3307 if (z_older_than(10, 0, 5))
3309 creature_ptr->learned_spells = 0;
3310 for (int i = 0; i < 64; i++)
3313 (creature_ptr->spell_learned1 & (1L << i)) :
3314 (creature_ptr->spell_learned2 & (1L << (i - 32))))
3316 creature_ptr->learned_spells++;
3320 else rd_s16b(&creature_ptr->learned_spells);
3322 if (z_older_than(10, 0, 6))
3324 creature_ptr->add_spells = 0;
3326 else rd_s16b(&creature_ptr->add_spells);
3328 if (creature_ptr->pclass == CLASS_MINDCRAFTER) creature_ptr->add_spells = 0;
3330 for (int i = 0; i < 64; i++)
3333 creature_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3336 if (rd_inventory(creature_ptr))
3338 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3343 int town_count = tmp16u;
3346 for (int i = 1; i < town_count; i++)
3348 for (int j = 0; j < tmp16u; j++)
3350 if (rd_store(creature_ptr, i, j)) return (22);
3354 rd_s16b(&creature_ptr->pet_follow_distance);
3355 if (z_older_than(10, 4, 10))
3357 creature_ptr->pet_extra_flags = 0;
3359 if (tmp8u) creature_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3361 if (tmp8u) creature_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3363 if (z_older_than(10, 0, 4)) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3367 if (tmp8u) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3370 if (z_older_than(10, 0, 7)) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3374 if (tmp8u) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3377 if (z_older_than(10, 0, 8)) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3381 if (tmp8u) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3384 if (!z_older_than(10, 0, 8))
3387 if (tmp8u) creature_ptr->pet_extra_flags |= PF_BALL_SPELL;
3392 rd_s16b(&creature_ptr->pet_extra_flags);
3395 if (!z_older_than(11, 0, 9))
3397 char buf[SCREEN_BUF_MAX_SIZE];
3398 rd_string(buf, sizeof(buf));
3399 if (buf[0]) screen_dump = string_make(buf);
3402 if (creature_ptr->is_dead)
3404 for (int i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3406 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3410 if (!creature_ptr->is_dead)
3412 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3413 if (rd_dungeon(creature_ptr))
3415 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3424 strip_bytes(tmp32s);
3428 /* Quest 18 was removed */
3429 if (h_older_than(1, 7, 0, 6))
3431 if (creature_ptr->current_floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3433 creature_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3434 creature_ptr->current_floor_ptr->dun_level = 1;
3435 creature_ptr->current_floor_ptr->inside_quest = 0;
3439 n_v_check = v_check;
3440 rd_u32b(&o_v_check);
3441 if (o_v_check != n_v_check)
3443 note(_("チェックサムがおかしい", "Invalid checksum"));
3447 n_x_check = x_check;
3448 rd_u32b(&o_x_check);
3449 if (o_x_check != n_x_check)
3451 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3460 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3461 * @param player_ptr プレーヤーへの参照ポインタ
3464 errr rd_savefile_new(player_type *player_ptr)
3467 fff = my_fopen(savefile, "rb");
3469 if (!fff) return -1;
3470 errr err = rd_savefile_new_aux(player_ptr);
3472 if (ferror(fff)) err = -1;
3479 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3480 * @param player_ptr プレーヤーへの参照ポインタ
3481 * @param sf_ptr 保存フロア読み込み先
3484 static bool load_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
3486 u32b n_x_check, n_v_check;
3487 u32b o_x_check, o_v_check;
3496 current_world_ptr->h_ver_extra = H_VER_EXTRA;
3497 current_world_ptr->h_ver_patch = H_VER_PATCH;
3498 current_world_ptr->h_ver_minor = H_VER_MINOR;
3499 current_world_ptr->h_ver_major = H_VER_MAJOR;
3503 if (saved_floor_file_sign != tmp32u) return FALSE;
3505 if (rd_saved_floor(player_ptr, sf_ptr)) return FALSE;
3507 n_v_check = v_check;
3508 rd_u32b(&o_v_check);
3510 if (o_v_check != n_v_check) return FALSE;
3512 n_x_check = x_check;
3513 rd_u32b(&o_x_check);
3515 if (o_x_check != n_x_check) return FALSE;
3521 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporarily saved-floor data
3522 * @param player_ptr プレーヤーへの参照ポインタ
3523 * @param sf_ptr 保存フロア読み込み先
3527 bool load_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
3530 * Temporary files are always written in system depended kanji
3544 FILE *old_fff = NULL;
3545 byte old_xor_byte = 0;
3546 u32b old_v_check = 0;
3547 u32b old_x_check = 0;
3548 byte old_h_ver_major = 0;
3549 byte old_h_ver_minor = 0;
3550 byte old_h_ver_patch = 0;
3551 byte old_h_ver_extra = 0;
3552 if (mode & SLF_SECOND)
3555 old_xor_byte = xor_byte;
3556 old_v_check = v_check;
3557 old_x_check = x_check;
3558 old_h_ver_major = current_world_ptr->h_ver_major;
3559 old_h_ver_minor = current_world_ptr->h_ver_minor;
3560 old_h_ver_patch = current_world_ptr->h_ver_patch;
3561 old_h_ver_extra = current_world_ptr->h_ver_extra;
3564 char floor_savefile[1024];
3565 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3568 fff = my_fopen(floor_savefile, "rb");
3571 bool is_save_successful = TRUE;
3572 if (!fff) is_save_successful = FALSE;
3574 if (is_save_successful)
3576 is_save_successful = load_floor_aux(player_ptr, sf_ptr);
3577 if (ferror(fff)) is_save_successful = FALSE;
3581 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3586 if (mode & SLF_SECOND)
3589 xor_byte = old_xor_byte;
3590 v_check = old_v_check;
3591 x_check = old_x_check;
3592 current_world_ptr->h_ver_major = old_h_ver_major;
3593 current_world_ptr->h_ver_minor = old_h_ver_minor;
3594 current_world_ptr->h_ver_patch = old_h_ver_patch;
3595 current_world_ptr->h_ver_extra = old_h_ver_extra;
3598 byte old_kanji_code = kanji_code;
3599 kanji_code = old_kanji_code;
3600 return is_save_successful;