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.
44 #include "birth/quick-start.h"
45 #include "cmd-item/cmd-smith.h"
46 #include "dungeon/dungeon-file.h"
47 #include "dungeon/dungeon.h"
48 #include "dungeon/quest.h"
49 #include "floor/floor-generate.h"
50 #include "floor/floor-save.h"
51 #include "floor/floor-town.h"
52 #include "floor/floor.h"
53 #include "floor/wild.h"
54 #include "grid/feature.h"
55 #include "grid/grid.h"
56 #include "grid/trap.h"
57 #include "io/files-util.h"
58 #include "io/report.h"
60 #include "io/uid-checker.h"
61 #include "locale/japanese.h"
62 #include "market/arena.h"
63 #include "market/bounty.h"
64 #include "monster/monster.h"
65 #include "mutation/mutation.h"
66 #include "object/artifact.h"
67 #include "object/object-ego.h"
68 #include "object/object-generator.h"
69 #include "object/object-hook.h"
70 #include "object/object-kind.h"
71 #include "object/object-mark-types.h"
72 #include "object/object2.h"
73 #include "object/old-ego-extra-values.h" // TODO v1.5.0以前のセーブファイルをロードする処理を分離する.
74 #include "object/object-value.h"
75 #include "object/sv-armor-types.h"
76 #include "object/sv-lite-types.h"
77 #include "object/tr-types.h"
78 #include "object/trc-types.h"
79 #include "pet/pet-util.h"
80 #include "player/avatar.h"
81 #include "player/patron.h"
82 #include "player/player-class.h"
83 #include "player/player-personality.h"
84 #include "player/player-races-table.h"
85 #include "player/player-sex.h"
86 #include "player/player-skill.h"
87 #include "player/race-info-table.h"
88 #include "spell/spells-status.h"
89 #include "store/store-util.h"
90 #include "store/store.h"
91 #include "system/angband-version.h"
92 #include "system/system-variables.h" // 暫定、init_flags の扱いを決めた上で消す.
93 #include "util/util.h"
94 #include "world/world-object.h"
95 #include "world/world.h"
98 * Maximum number of tries for selection of a proper quest monster
100 #define MAX_TRIES 100
102 #define OLD_MAX_MANE 22
104 /* Old hidden trap flag */
105 #define CAVE_TRAP 0x8000
107 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
108 #define OLD_FEAT_INVIS 0x02
109 #define OLD_FEAT_GLYPH 0x03
110 #define OLD_FEAT_QUEST_ENTER 0x08
111 #define OLD_FEAT_QUEST_EXIT 0x09
112 #define OLD_FEAT_MINOR_GLYPH 0x40
113 #define OLD_FEAT_BLDG_1 0x81
114 #define OLD_FEAT_MIRROR 0xc3
117 #define OLD_QUEST_WATER_CAVE 18
119 /* Quest constants */
120 #define QUEST_OLD_CASTLE 27
121 #define QUEST_ROYAL_CRYPT 28
124 * Local "savefile" pointer
129 * Hack -- old "encryption" byte
131 static byte xor_byte;
134 * Hack -- simple "checksum" on the actual values
136 static u32b v_check = 0L;
139 * Hack -- simple "checksum" on the encoded bytes
141 static u32b x_check = 0L;
144 * Hack -- Japanese Kanji code
150 static byte kanji_code = 0;
153 * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
154 * @param major メジャーバージョン値
155 * @param minor マイナーバージョン値
156 * @param patch パッチバージョン値
157 * @param extra エクストラパージョン値
158 * @return 現在のバージョンより値が古いならtrue
160 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
162 if (current_world_ptr->h_ver_major < major) return TRUE;
163 if (current_world_ptr->h_ver_major > major) return FALSE;
165 if (current_world_ptr->h_ver_minor < minor) return TRUE;
166 if (current_world_ptr->h_ver_minor > minor) return FALSE;
168 if (current_world_ptr->h_ver_patch < patch) return TRUE;
169 if (current_world_ptr->h_ver_patch > patch) return FALSE;
171 if (current_world_ptr->h_ver_extra < extra) return TRUE;
172 if (current_world_ptr->h_ver_extra > extra) return FALSE;
179 * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
180 * @param x メジャーバージョン値
181 * @param y マイナーバージョン値
183 * @return 現在のバージョンより値が古いならtrue
185 static bool z_older_than(byte x, byte y, byte z)
187 if (current_world_ptr->z_major < x) return TRUE;
188 if (current_world_ptr->z_major > x) return FALSE;
190 if (current_world_ptr->z_minor < y) return TRUE;
191 if (current_world_ptr->z_minor > y) return FALSE;
193 if (current_world_ptr->z_patch < z) return TRUE;
194 if (current_world_ptr->z_patch > z) return FALSE;
201 * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
205 * Avoid the top two lines, to avoid interference with "msg_print()".
207 static void note(concptr msg)
209 static TERM_LEN y = 2;
211 if (++y >= 24) y = 2;
218 * @brief ロードファイルポインタから1バイトを読み込む
221 * The following functions are used to load the basic building blocks
222 * of savefiles. They also maintain the "checksum" info for 2.7.0+
224 static byte sf_get(void)
226 byte c = getc(fff) & 0xFF;
227 byte v = c ^ xor_byte;
237 * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
241 static void rd_byte(byte *ip)
248 * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
252 static void rd_u16b(u16b *ip)
255 (*ip) |= ((u16b)(sf_get()) << 8);
260 * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
264 static void rd_s16b(s16b *ip)
271 * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
275 static void rd_u32b(u32b *ip)
278 (*ip) |= ((u32b)(sf_get()) << 8);
279 (*ip) |= ((u32b)(sf_get()) << 16);
280 (*ip) |= ((u32b)(sf_get()) << 24);
285 * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
289 static void rd_s32b(s32b *ip)
296 * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
297 * @param str 読み込みポインタ
298 * @param max 最大読み取りバイト数
301 static void rd_string(char *str, int max)
303 for (int i = 0; TRUE; i++)
307 if (i < max) str[i] = tmp8u;
330 byte code = codeconv(str);
332 /* 漢字コードが判明したら、それを記録 */
333 if (code) kanji_code = code;
345 * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
349 static void strip_bytes(int n)
352 while (n--) rd_byte(&tmp8u);
357 * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
358 * @param o_ptr アイテムオブジェクト読み取り先ポインタ
361 * This function attempts to "repair" old savefiles, and to extract
362 * the most up to date values for various object fields.
364 * Note that Angband 2.7.9 introduced a new method for object "flags"
365 * in which the "flags" on an object are actually extracted when they
366 * are needed from the object kind, artifact index, ego-item index,
367 * and two special "xtra" fields which are used to encode any "extra"
368 * power of certain ego-items. This had the side effect that items
369 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
370 * may have had, and also, all "uncursed" items will become "cursed"
371 * again, including Calris, even if it is being worn at the time. As
372 * a complete hack, items which are inscribed with "uncursed" will be
373 * "uncursed" when imported from pre-2.7.9 savefiles.
375 static void rd_item_old(object_type *o_ptr)
377 rd_s16b(&o_ptr->k_idx);
381 o_ptr->iy = (POSITION)tmp8u;
383 o_ptr->ix = (POSITION)tmp8u;
391 if (z_older_than(10, 4, 4))
393 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
394 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
395 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
398 rd_s16b(&o_ptr->pval);
399 rd_byte(&o_ptr->discount);
401 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);
414 rd_s16b(&o_ptr->to_h);
416 o_ptr->to_d = tmp16s;
418 rd_s16b(&o_ptr->to_a);
426 rd_byte(&o_ptr->ident);
427 rd_byte(&o_ptr->marked);
428 rd_u32b(&o_ptr->art_flags[0]);
429 rd_u32b(&o_ptr->art_flags[1]);
430 rd_u32b(&o_ptr->art_flags[2]);
431 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
432 else rd_u32b(&o_ptr->art_flags[3]);
434 if (h_older_than(1, 3, 0, 0))
436 if (o_ptr->name2 == EGO_TELEPATHY)
437 add_flag(o_ptr->art_flags, TR_TELEPATHY);
440 if (z_older_than(11, 0, 11))
442 o_ptr->curse_flags = 0L;
443 if (o_ptr->ident & 0x40)
445 o_ptr->curse_flags |= TRC_CURSED;
446 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
447 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
448 if (object_is_fixed_artifact(o_ptr))
450 artifact_type *a_ptr = &a_info[o_ptr->name1];
451 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
452 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
454 else if (object_is_ego(o_ptr))
456 ego_item_type *e_ptr = &e_info[o_ptr->name2];
457 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
458 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
461 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
465 rd_u32b(&o_ptr->curse_flags);
468 rd_s16b(&o_ptr->held_m_idx);
469 rd_byte(&o_ptr->xtra1);
470 rd_byte(&o_ptr->xtra2);
472 if (z_older_than(11, 0, 10))
474 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
476 switch (o_ptr->xtra2 % 6)
478 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
479 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
480 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
481 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
482 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
483 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
487 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
489 switch (o_ptr->xtra2 % 11)
491 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
492 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
493 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
494 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
495 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
496 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
497 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
498 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
499 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
500 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
501 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
505 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
507 switch (o_ptr->xtra2 % 8)
509 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
510 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
511 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
512 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
513 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
514 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
515 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
516 case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP); break;
523 if (z_older_than(10, 2, 3))
528 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
530 o_ptr->xtra3 = o_ptr->xtra1;
533 if (o_ptr->tval == TV_CAPTURE)
535 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
536 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
538 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
539 if (ironman_nightmare)
541 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5 * 2L);
543 o_ptr->xtra4 = o_ptr->xtra5;
548 rd_byte(&o_ptr->xtra3);
549 if (h_older_than(1, 3, 0, 1))
551 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1 + 96)
552 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
555 rd_s16b(&o_ptr->xtra4);
556 rd_s16b(&o_ptr->xtra5);
559 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)))
561 o_ptr->xtra4 = o_ptr->pval;
565 rd_byte(&o_ptr->feeling);
568 rd_string(buf, sizeof(buf));
569 if (buf[0]) o_ptr->inscription = quark_add(buf);
571 rd_string(buf, sizeof(buf));
573 /* todo 元々このif文には末尾に";"が付いていた、バグかもしれない */
574 if (buf[0]) o_ptr->art_name = quark_add(buf);
582 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
584 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
586 if (z_older_than(10, 4, 9))
588 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
590 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
591 add_flag(o_ptr->art_flags, TR_DEC_MANA);
595 if (object_is_fixed_artifact(o_ptr))
597 artifact_type *a_ptr;
598 a_ptr = &a_info[o_ptr->name1];
599 if (!a_ptr->name) o_ptr->name1 = 0;
602 if (object_is_ego(o_ptr))
604 ego_item_type *e_ptr;
605 e_ptr = &e_info[o_ptr->name2];
606 if (!e_ptr->name) o_ptr->name2 = 0;
612 * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
613 * @param o_ptr アイテムオブジェクト保存先ポインタ
616 static void rd_item(object_type *o_ptr)
618 if (h_older_than(1, 5, 0, 0))
626 rd_s16b(&o_ptr->k_idx);
630 o_ptr->iy = (POSITION)tmp8u;
632 o_ptr->ix = (POSITION)tmp8u;
635 k_ptr = &k_info[o_ptr->k_idx];
636 o_ptr->tval = k_ptr->tval;
637 o_ptr->sval = k_ptr->sval;
639 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
640 else o_ptr->pval = 0;
642 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
643 else o_ptr->discount = 0;
644 if (flags & SAVE_ITEM_NUMBER) {
646 o_ptr->number = tmp8u;
648 else o_ptr->number = 1;
652 o_ptr->weight = tmp16s;
654 if (flags & SAVE_ITEM_NAME1)
657 o_ptr->name1 = tmp8u;
659 else o_ptr->name1 = 0;
661 if (flags & SAVE_ITEM_NAME2)
664 o_ptr->name2 = tmp8u;
666 else o_ptr->name2 = 0;
668 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
669 else o_ptr->timeout = 0;
671 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
672 else o_ptr->to_h = 0;
674 if (flags & SAVE_ITEM_TO_D)
677 o_ptr->to_d = tmp16s;
679 else o_ptr->to_d = 0;
681 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
682 else o_ptr->to_a = 0;
684 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
687 if (flags & SAVE_ITEM_DD)
694 if (flags & SAVE_ITEM_DS)
701 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
702 else o_ptr->ident = 0;
704 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
705 else o_ptr->marked = 0;
708 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
709 else o_ptr->art_flags[0] = 0;
711 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
712 else o_ptr->art_flags[1] = 0;
714 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
715 else o_ptr->art_flags[2] = 0;
717 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
718 else o_ptr->art_flags[3] = 0;
720 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
721 else o_ptr->art_flags[4] = 0;
723 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
724 else o_ptr->curse_flags = 0;
726 /* Monster holding object */
727 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
728 else o_ptr->held_m_idx = 0;
731 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
732 else o_ptr->xtra1 = 0;
734 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
735 else o_ptr->xtra2 = 0;
737 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
738 else o_ptr->xtra3 = 0;
740 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
741 else o_ptr->xtra4 = 0;
743 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
744 else o_ptr->xtra5 = 0;
746 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
747 else o_ptr->feeling = 0;
749 if (flags & SAVE_ITEM_INSCRIPTION)
752 rd_string(buf, sizeof(buf));
753 o_ptr->inscription = quark_add(buf);
755 else o_ptr->inscription = 0;
757 if (flags & SAVE_ITEM_ART_NAME)
760 rd_string(buf, sizeof(buf));
761 o_ptr->art_name = quark_add(buf);
768 if (!h_older_than(2, 1, 2, 4)) return;
770 BIT_FLAGS flgs[TR_FLAG_SIZE];
771 object_flags(o_ptr, flgs);
773 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
775 add_flag(o_ptr->art_flags, TR_LITE_M1);
776 remove_flag(o_ptr->art_flags, TR_LITE_1);
777 remove_flag(o_ptr->art_flags, TR_LITE_2);
778 remove_flag(o_ptr->art_flags, TR_LITE_3);
782 if (o_ptr->name2 == EGO_LITE_DARKNESS)
784 if (o_ptr->tval != TV_LITE)
786 add_flag(o_ptr->art_flags, TR_LITE_M1);
790 if (o_ptr->sval == SV_LITE_TORCH)
792 add_flag(o_ptr->art_flags, TR_LITE_M1);
794 else if (o_ptr->sval == SV_LITE_LANTERN)
796 add_flag(o_ptr->art_flags, TR_LITE_M2);
798 else if (o_ptr->sval == SV_LITE_FEANOR)
800 add_flag(o_ptr->art_flags, TR_LITE_M3);
806 if (o_ptr->tval == TV_LITE)
808 if (object_is_fixed_artifact(o_ptr))
810 add_flag(o_ptr->art_flags, TR_LITE_3);
814 if (o_ptr->sval == SV_LITE_TORCH)
816 add_flag(o_ptr->art_flags, TR_LITE_1);
817 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
821 if (o_ptr->sval == SV_LITE_LANTERN)
823 add_flag(o_ptr->art_flags, TR_LITE_2);
824 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
828 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 player_ptr プレーヤーへの参照ポインタ
840 * @param m_ptr モンスター保存先ポインタ
843 static void rd_monster_old(player_type *player_ptr, monster_type *m_ptr)
845 rd_s16b(&m_ptr->r_idx);
847 if (z_older_than(11, 0, 12))
848 m_ptr->ap_r_idx = m_ptr->r_idx;
850 rd_s16b(&m_ptr->ap_r_idx);
852 if (z_older_than(11, 0, 14))
854 monster_race *r_ptr = &r_info[m_ptr->r_idx];
856 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
857 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
858 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
861 rd_byte(&m_ptr->sub_align);
865 m_ptr->fy = (POSITION)tmp8u;
867 m_ptr->fx = (POSITION)tmp8u;
868 m_ptr->current_floor_ptr = player_ptr->current_floor_ptr;
874 m_ptr->maxhp = tmp16s;
876 if (z_older_than(11, 0, 5))
878 m_ptr->max_maxhp = m_ptr->maxhp;
883 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
885 if (h_older_than(2, 1, 2, 1))
887 m_ptr->dealt_damage = 0;
891 rd_s32b(&m_ptr->dealt_damage);
894 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
896 m_ptr->mspeed = tmp8u;
898 if (z_older_than(10, 4, 2))
901 m_ptr->energy_need = (s16b)tmp8u;
903 else rd_s16b(&m_ptr->energy_need);
905 if (z_older_than(11, 0, 13))
906 m_ptr->energy_need = 100 - m_ptr->energy_need;
908 if (z_older_than(10, 0, 7))
910 m_ptr->mtimed[MTIMED_FAST] = 0;
911 m_ptr->mtimed[MTIMED_SLOW] = 0;
916 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
918 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
922 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
924 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
926 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
928 if (z_older_than(10, 0, 10))
932 else if (z_older_than(10, 0, 11))
940 m_ptr->target_y = (POSITION)tmp16s;
942 m_ptr->target_x = (POSITION)tmp16s;
946 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
948 if (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6))
949 rd_u32b(&m_ptr->smart);
954 if (z_older_than(10, 4, 5))
964 if (z_older_than(10, 2, 2))
966 if (m_ptr->r_idx < 0)
968 m_ptr->r_idx = (0 - m_ptr->r_idx);
969 m_ptr->mflag2 |= MFLAG2_KAGE;
974 rd_byte(&m_ptr->mflag2);
977 if (z_older_than(11, 0, 12))
979 if (m_ptr->mflag2 & MFLAG2_KAGE)
980 m_ptr->ap_r_idx = MON_KAGE;
983 if (z_older_than(10, 1, 3))
990 rd_string(buf, sizeof(buf));
991 if (buf[0]) m_ptr->nickname = quark_add(buf);
999 * @brief モンスターを読み込む(現版) / Read a monster (New method)
1000 * @param player_ptr プレーヤーへの参照ポインタ
1001 * @param m_ptr モンスター保存先ポインタ
1004 static void rd_monster(player_type *player_ptr, monster_type *m_ptr)
1006 if (h_older_than(1, 5, 0, 0))
1008 rd_monster_old(player_ptr, m_ptr);
1014 rd_s16b(&m_ptr->r_idx);
1017 m_ptr->fy = (POSITION)tmp8u;
1019 m_ptr->fx = (POSITION)tmp8u;
1023 m_ptr->hp = (HIT_POINT)tmp16s;
1025 m_ptr->maxhp = (HIT_POINT)tmp16s;
1027 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
1029 if (h_older_than(2, 1, 2, 1))
1031 m_ptr->dealt_damage = 0;
1035 rd_s32b(&m_ptr->dealt_damage);
1038 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1039 else m_ptr->ap_r_idx = m_ptr->r_idx;
1041 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1042 else m_ptr->sub_align = 0;
1044 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1045 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1048 m_ptr->mspeed = tmp8u;
1050 rd_s16b(&m_ptr->energy_need);
1052 if (flags & SAVE_MON_FAST)
1055 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1057 else m_ptr->mtimed[MTIMED_FAST] = 0;
1059 if (flags & SAVE_MON_SLOW)
1062 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1064 else m_ptr->mtimed[MTIMED_SLOW] = 0;
1066 if (flags & SAVE_MON_STUNNED)
1069 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1071 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1073 if (flags & SAVE_MON_CONFUSED)
1076 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1078 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1080 if (flags & SAVE_MON_MONFEAR)
1083 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1085 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1087 if (flags & SAVE_MON_TARGET_Y)
1090 m_ptr->target_y = (POSITION)tmp16s;
1092 else m_ptr->target_y = 0;
1094 if (flags & SAVE_MON_TARGET_X)
1097 m_ptr->target_x = (POSITION)tmp16s;
1099 else m_ptr->target_x = 0;
1101 if (flags & SAVE_MON_INVULNER)
1104 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1106 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1108 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1109 else m_ptr->smart = 0;
1111 if (flags & SAVE_MON_EXP)
1115 m_ptr->exp = (EXP)tmp32u;
1117 else m_ptr->exp = 0;
1119 m_ptr->mflag = 0; /* Not saved */
1121 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1122 else m_ptr->mflag2 = 0;
1124 if (flags & SAVE_MON_NICKNAME)
1127 rd_string(buf, sizeof(buf));
1128 m_ptr->nickname = quark_add(buf);
1130 else m_ptr->nickname = 0;
1132 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1133 else m_ptr->parent_m_idx = 0;
1138 * Old monster bit flags of racial resistances
1140 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
1141 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
1142 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
1143 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
1144 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
1145 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
1146 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
1147 #define RF3_RES_WATE 0x00800000 /* Resist water */
1148 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
1149 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
1150 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1151 #define RF3_RES_ALL 0x08000000 /* Resist all */
1153 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1155 if ((R_PTR)->r_flags3 & (RF3)) \
1157 (R_PTR)->r_flags3 &= ~(RF3); \
1158 (R_PTR)->r_flagsr |= (RFR); \
1162 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1164 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1166 (R_PTR)->r_flagsr |= (RFR); \
1170 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1171 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1172 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1173 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1174 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1175 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1176 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1177 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1178 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1179 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1182 * @brief モンスターの思い出を読み込む / Read the monster lore
1183 * @param r_idx 読み込み先モンスターID
1186 static void rd_lore(MONRACE_IDX r_idx)
1188 monster_race *r_ptr = &r_info[r_idx];
1192 r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
1195 r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
1198 r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
1200 if (h_older_than(1, 7, 0, 5))
1202 r_ptr->r_akills = r_ptr->r_pkills;
1207 r_ptr->r_akills = (MONSTER_NUMBER)tmp16s;
1211 r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
1213 rd_byte(&r_ptr->r_wake);
1214 rd_byte(&r_ptr->r_ignore);
1215 rd_byte(&r_ptr->r_xtra1);
1216 rd_byte(&r_ptr->r_xtra2);
1220 r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
1222 r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
1225 rd_byte(&r_ptr->r_cast_spell);
1227 rd_byte(&r_ptr->r_blows[0]);
1228 rd_byte(&r_ptr->r_blows[1]);
1229 rd_byte(&r_ptr->r_blows[2]);
1230 rd_byte(&r_ptr->r_blows[3]);
1232 rd_u32b(&r_ptr->r_flags1);
1233 rd_u32b(&r_ptr->r_flags2);
1234 rd_u32b(&r_ptr->r_flags3);
1235 rd_u32b(&r_ptr->r_flags4);
1236 rd_u32b(&r_ptr->r_flags5);
1237 rd_u32b(&r_ptr->r_flags6);
1238 if (h_older_than(1, 5, 0, 3))
1240 r_ptr->r_flagsr = 0L;
1241 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1242 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1243 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1244 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1245 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1246 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1247 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1248 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1249 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1250 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1251 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1252 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1254 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1255 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1256 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1257 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1258 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1259 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1260 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1261 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1262 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1264 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1265 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1266 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1270 rd_u32b(&r_ptr->r_flagsr);
1274 r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
1276 rd_s16b(&r_ptr->floor_id);
1279 r_ptr->r_flags1 &= r_ptr->flags1;
1280 r_ptr->r_flags2 &= r_ptr->flags2;
1281 r_ptr->r_flags3 &= r_ptr->flags3;
1282 r_ptr->r_flags4 &= r_ptr->flags4;
1283 r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1284 r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1285 r_ptr->r_flagsr &= r_ptr->flagsr;
1290 * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1291 * @param player_ptr プレーヤーへの参照ポインタ
1292 * @param store_ptr 店舗の参照ポインタ
1293 * @param o_ptr アイテムオブジェクト参照ポインタ
1296 * In all cases, return the slot (or -1) where the object was placed
1298 * Note that this is a hacked up version of "store_item_to_inventory()".
1300 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1301 * known, the player may have to pick stuff up and drop it again.
1303 static void home_carry(player_type *player_ptr, store_type *store_ptr, object_type *o_ptr)
1305 for (int i = 0; i < store_ptr->stock_num; i++)
1308 j_ptr = &store_ptr->stock[i];
1309 if (!object_similar(j_ptr, o_ptr)) continue;
1311 object_absorb(j_ptr, o_ptr);
1315 if (store_ptr->stock_num >= STORE_INVEN_MAX * 10) return;
1317 s32b value = object_value(o_ptr);
1319 for (slot = 0; slot < store_ptr->stock_num; slot++)
1321 if (object_sort_comp(o_ptr, value, &store_ptr->stock[slot])) break;
1324 for (int i = store_ptr->stock_num; i > slot; i--)
1326 store_ptr->stock[i] = store_ptr->stock[i - 1];
1329 store_ptr->stock_num++;
1330 store_ptr->stock[slot] = *o_ptr;
1331 chg_virtue(player_ptr, V_SACRIFICE, -1);
1336 * @brief 店舗情報を読み込む / Read a store
1337 * @param player_ptr プレーヤーへの参照ポインタ
1338 * @param town_number 街ID
1339 * @param store_number 店舗ID
1342 static errr rd_store(player_type *player_ptr, int town_number, int store_number)
1344 store_type *store_ptr;
1346 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1348 store_ptr = &town_info[1].store[store_number];
1349 if (store_ptr->stock_num) sort = TRUE;
1353 store_ptr = &town_info[town_number].store[store_number];
1359 rd_s32b(&store_ptr->store_open);
1360 rd_s16b(&store_ptr->insult_cur);
1362 if (z_older_than(11, 0, 4))
1372 rd_s16b(&store_ptr->good_buy);
1373 rd_s16b(&store_ptr->bad_buy);
1375 rd_s32b(&store_ptr->last_visit);
1376 store_ptr->owner = own;
1378 for (int j = 0; j < num; j++)
1387 bool is_valid_item = store_ptr->stock_num < (store_number == STORE_HOME ? STORE_INVEN_MAX * 10 : store_number == STORE_MUSEUM ? STORE_INVEN_MAX * 50 : STORE_INVEN_MAX);
1388 if (!is_valid_item) continue;
1392 home_carry(player_ptr, store_ptr, q_ptr);
1396 int k = store_ptr->stock_num++;
1397 object_copy(&store_ptr->stock[k], q_ptr);
1406 * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1409 static void rd_randomizer(void)
1413 rd_u16b(&Rand_place);
1414 for (int i = 0; i < RAND_DEG; i++)
1416 rd_u32b(&Rand_state[i]);
1422 * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1425 * Note that the normal options are now stored as a set of 256 bit flags,
1426 * plus a set of 256 bit masks to indicate which bit flags were defined
1427 * at the time the savefile was created. This will allow new options
1428 * to be added, and old options to be removed, at any time, without
1429 * hurting old savefiles.
1431 * The window options are stored in the same way, but note that each
1432 * window gets 32 options, and their order is fixed by certain defines.
1434 static void rd_options(void)
1445 if (h_older_than(1, 7, 0, 0))
1458 if (c & 0x0002) current_world_ptr->wizard = TRUE;
1460 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1461 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1462 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1463 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1464 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1465 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1466 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1467 cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1468 cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1469 cheat_sight = (c & 0x0040) ? TRUE : FALSE;
1471 rd_byte((byte *)&autosave_l);
1472 rd_byte((byte *)&autosave_t);
1473 rd_s16b(&autosave_freq);
1476 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1479 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1481 for (int n = 0; n < 8; n++)
1483 for (int i = 0; i < 32; i++)
1485 if (!(mask[n] & (1L << i))) continue;
1486 if (!(option_mask[n] & (1L << i))) continue;
1488 if (flag[n] & (1L << i))
1490 option_flag[n] |= (1L << i);
1494 option_flag[n] &= ~(1L << i);
1499 if (z_older_than(10, 4, 5))
1501 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1502 else option_flag[5] |= (0x00000001 << 4);
1503 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1504 else option_flag[2] |= (0x00000001 << 5);
1505 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1506 else option_flag[4] |= (0x00000001 << 5);
1507 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1508 else option_flag[5] |= (0x00000001 << 0);
1509 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1510 else option_flag[5] |= (0x00000001 << 12);
1511 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1512 else option_flag[1] |= (0x00000001 << 0);
1513 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1514 else option_flag[1] |= (0x00000001 << 18);
1515 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1516 else option_flag[1] |= (0x00000001 << 19);
1517 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1518 else option_flag[5] |= (0x00000001 << 3);
1521 extract_option_vars();
1522 for (int n = 0; n < 8; n++) rd_u32b(&flag[n]);
1524 for (int n = 0; n < 8; n++) rd_u32b(&mask[n]);
1526 for (int n = 0; n < 8; n++)
1528 for (int i = 0; i < 32; i++)
1530 if (!(mask[n] & (1L << i))) continue;
1531 if (!(window_mask[n] & (1L << i))) continue;
1533 if (flag[n] & (1L << i))
1535 window_flag[n] |= (1L << i);
1539 window_flag[n] &= ~(1L << i);
1547 * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1550 * This is such a nasty hack it hurts.
1552 static void rd_ghost(void)
1555 rd_string(buf, sizeof(buf));
1561 * @brief クイックスタート情報を読み込む / Load quick start data
1564 static void load_quick_start(void)
1566 if (z_older_than(11, 0, 13))
1568 previous_char.quick_ok = FALSE;
1572 rd_byte(&previous_char.psex);
1575 previous_char.prace = (player_race_type)tmp8u;
1577 previous_char.pclass = (player_class_type)tmp8u;
1579 previous_char.pseikaku = (player_personality_type)tmp8u;
1581 previous_char.realm1 = (REALM_IDX)tmp8u;
1583 previous_char.realm2 = (REALM_IDX)tmp8u;
1585 rd_s16b(&previous_char.age);
1586 rd_s16b(&previous_char.ht);
1587 rd_s16b(&previous_char.wt);
1588 rd_s16b(&previous_char.sc);
1589 rd_s32b(&previous_char.au);
1591 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max[i]);
1592 for (int i = 0; i < A_MAX; i++) rd_s16b(&previous_char.stat_max_max[i]);
1594 for (int i = 0; i < PY_MAX_LEVEL; i++)
1598 previous_char.player_hp[i] = (HIT_POINT)tmp16s;
1601 rd_s16b(&previous_char.chaos_patron);
1603 for (int i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1605 for (int i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1609 previous_char.quick_ok = (bool)tmp8u;
1614 * @brief その他の情報を読み込む / Read the "extra" information
1617 static void rd_extra(player_type *creature_ptr)
1619 rd_string(creature_ptr->name, sizeof(creature_ptr->name));
1620 rd_string(creature_ptr->died_from, sizeof(creature_ptr->died_from));
1621 if (!h_older_than(1, 7, 0, 1))
1624 rd_string(buf, sizeof buf);
1625 if (buf[0]) creature_ptr->last_message = string_make(buf);
1629 for (int i = 0; i < 4; i++)
1631 rd_string(creature_ptr->history[i], sizeof(creature_ptr->history[i]));
1636 creature_ptr->prace = (player_race_type)tmp8u;
1639 creature_ptr->pclass = (player_class_type)tmp8u;
1642 creature_ptr->pseikaku = (player_personality_type)tmp8u;
1644 rd_byte(&creature_ptr->psex);
1646 creature_ptr->realm1 = (REALM_IDX)tmp8u;
1649 creature_ptr->realm2 = (REALM_IDX)tmp8u;
1652 if (z_older_than(10, 4, 4))
1654 if (creature_ptr->realm1 == 9) creature_ptr->realm1 = REALM_MUSIC;
1655 if (creature_ptr->realm2 == 9) creature_ptr->realm2 = REALM_MUSIC;
1656 if (creature_ptr->realm1 == 10) creature_ptr->realm1 = REALM_HISSATSU;
1657 if (creature_ptr->realm2 == 10) creature_ptr->realm2 = REALM_HISSATSU;
1661 creature_ptr->hitdie = tmp8u;
1662 rd_u16b(&creature_ptr->expfact);
1664 rd_s16b(&creature_ptr->age);
1665 rd_s16b(&creature_ptr->ht);
1666 rd_s16b(&creature_ptr->wt);
1668 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max[i]);
1669 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_max_max[i]);
1670 for (int i = 0; i < A_MAX; i++) rd_s16b(&creature_ptr->stat_cur[i]);
1673 rd_s32b(&creature_ptr->au);
1675 rd_s32b(&creature_ptr->max_exp);
1676 if (h_older_than(1, 5, 4, 1)) creature_ptr->max_max_exp = creature_ptr->max_exp;
1677 else rd_s32b(&creature_ptr->max_max_exp);
1678 rd_s32b(&creature_ptr->exp);
1680 if (h_older_than(1, 7, 0, 3))
1684 creature_ptr->exp_frac = (u32b)tmp16u;
1688 rd_u32b(&creature_ptr->exp_frac);
1691 rd_s16b(&creature_ptr->lev);
1693 for (int i = 0; i < 64; i++) rd_s16b(&creature_ptr->spell_exp[i]);
1694 if ((creature_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1696 for (int i = 0; i < 64; i++) creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1699 if (z_older_than(10, 3, 6))
1700 for (int i = 0; i < 5; i++) for (int j = 0; j < 60; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1702 for (int i = 0; i < 5; i++) for (int j = 0; j < 64; j++) rd_s16b(&creature_ptr->weapon_exp[i][j]);
1703 for (int i = 0; i < GINOU_MAX; i++) rd_s16b(&creature_ptr->skill_exp[i]);
1704 if (z_older_than(10, 4, 1))
1706 if (creature_ptr->pclass != CLASS_BEASTMASTER) creature_ptr->skill_exp[GINOU_RIDING] /= 2;
1707 creature_ptr->skill_exp[GINOU_RIDING] = MIN(creature_ptr->skill_exp[GINOU_RIDING], s_info[creature_ptr->pclass].s_max[GINOU_RIDING]);
1710 if (z_older_than(10, 3, 14))
1712 for (int i = 0; i < 108; i++) creature_ptr->magic_num1[i] = 0;
1713 for (int i = 0; i < 108; i++) creature_ptr->magic_num2[i] = 0;
1717 for (int i = 0; i < 108; i++) rd_s32b(&creature_ptr->magic_num1[i]);
1718 for (int i = 0; i < 108; i++) rd_byte(&creature_ptr->magic_num2[i]);
1719 if (h_older_than(1, 3, 0, 1))
1721 if (creature_ptr->pclass == CLASS_SMITH)
1723 creature_ptr->magic_num1[TR_ES_ATTACK] = creature_ptr->magic_num1[96];
1724 creature_ptr->magic_num1[96] = 0;
1725 creature_ptr->magic_num1[TR_ES_AC] = creature_ptr->magic_num1[97];
1726 creature_ptr->magic_num1[97] = 0;
1731 if (music_singing_any(creature_ptr)) creature_ptr->action = ACTION_SING;
1733 if (z_older_than(11, 0, 7))
1735 creature_ptr->start_race = creature_ptr->prace;
1736 creature_ptr->old_race1 = 0L;
1737 creature_ptr->old_race2 = 0L;
1738 creature_ptr->old_realm = 0;
1743 creature_ptr->start_race = (player_race_type)tmp8u;
1746 creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
1748 creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
1749 rd_s16b(&creature_ptr->old_realm);
1752 if (z_older_than(10, 0, 1))
1754 for (int i = 0; i < MAX_MANE; i++)
1756 creature_ptr->mane_spell[i] = -1;
1757 creature_ptr->mane_dam[i] = 0;
1759 creature_ptr->mane_num = 0;
1761 else if (z_older_than(10, 2, 3))
1764 for (int i = 0; i < OLD_MAX_MANE; i++)
1770 for (int i = 0; i < MAX_MANE; i++)
1772 creature_ptr->mane_spell[i] = -1;
1773 creature_ptr->mane_dam[i] = 0;
1777 creature_ptr->mane_num = 0;
1781 for (int i = 0; i < MAX_MANE; i++)
1785 creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
1787 creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
1790 rd_s16b(&creature_ptr->mane_num);
1793 if (z_older_than(10, 0, 3))
1795 determine_bounty_uniques(creature_ptr);
1797 for (int i = 0; i < MAX_BOUNTY; i++)
1799 /* Is this bounty unique already dead? */
1800 if (!r_info[current_world_ptr->bounty_r_idx[i]].max_num) current_world_ptr->bounty_r_idx[i] += 10000;
1805 for (int i = 0; i < MAX_BOUNTY; i++)
1807 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
1811 if (z_older_than(10, 0, 3))
1813 update_gambling_monsters(creature_ptr);
1817 for (int i = 0; i < 4; i++)
1819 rd_s16b(&battle_mon[i]);
1820 if (z_older_than(10, 3, 4))
1824 mon_odds[i] = tmp16s;
1826 else rd_u32b(&mon_odds[i]);
1830 rd_s16b(&creature_ptr->town_num);
1831 rd_s16b(&creature_ptr->arena_number);
1832 if (h_older_than(1, 5, 0, 1))
1834 if (creature_ptr->arena_number >= 99) creature_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1839 creature_ptr->current_floor_ptr->inside_arena = (bool)tmp16s;
1840 rd_s16b(&creature_ptr->current_floor_ptr->inside_quest);
1841 if (z_older_than(10, 3, 5)) creature_ptr->phase_out = FALSE;
1845 creature_ptr->phase_out = (bool)tmp16s;
1848 rd_byte(&creature_ptr->exit_bldg);
1852 creature_ptr->oldpx = (POSITION)tmp16s;
1855 creature_ptr->oldpy = (POSITION)tmp16s;
1856 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; }
1859 for (int i = 0; i < tmp16s; i++)
1865 if (h_older_than(1, 7, 0, 3))
1868 creature_ptr->mhp = tmp16s;
1871 creature_ptr->chp = tmp16s;
1875 creature_ptr->chp_frac = (u32b)tmp16u;
1879 rd_s32b(&creature_ptr->mhp);
1880 rd_s32b(&creature_ptr->chp);
1881 rd_u32b(&creature_ptr->chp_frac);
1884 if (h_older_than(1, 7, 0, 3))
1887 creature_ptr->msp = tmp16s;
1890 creature_ptr->csp = tmp16s;
1894 creature_ptr->csp_frac = (u32b)tmp16u;
1898 rd_s32b(&creature_ptr->msp);
1899 rd_s32b(&creature_ptr->csp);
1900 rd_u32b(&creature_ptr->csp_frac);
1903 rd_s16b(&creature_ptr->max_plv);
1904 if (z_older_than(10, 3, 8))
1907 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1911 byte max = (byte)current_world_ptr->max_d_idx;
1915 for (int i = 0; i < max; i++)
1918 max_dlv[i] = tmp16s;
1919 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1923 if (creature_ptr->max_plv < creature_ptr->lev) creature_ptr->max_plv = creature_ptr->lev;
1926 rd_s16b(&creature_ptr->sc);
1927 rd_s16b(&creature_ptr->concent);
1929 strip_bytes(2); /* Old "rest" */
1930 rd_s16b(&creature_ptr->blind);
1931 rd_s16b(&creature_ptr->paralyzed);
1932 rd_s16b(&creature_ptr->confused);
1933 rd_s16b(&creature_ptr->food);
1934 strip_bytes(4); /* Old "food_digested" / "protection" */
1936 rd_s16b(&creature_ptr->energy_need);
1937 if (z_older_than(11, 0, 13))
1938 creature_ptr->energy_need = 100 - creature_ptr->energy_need;
1939 if (h_older_than(2, 1, 2, 0))
1940 creature_ptr->enchant_energy_need = 0;
1942 rd_s16b(&creature_ptr->enchant_energy_need);
1944 rd_s16b(&creature_ptr->fast);
1945 rd_s16b(&creature_ptr->slow);
1946 rd_s16b(&creature_ptr->afraid);
1947 rd_s16b(&creature_ptr->cut);
1948 rd_s16b(&creature_ptr->stun);
1949 rd_s16b(&creature_ptr->poisoned);
1950 rd_s16b(&creature_ptr->image);
1951 rd_s16b(&creature_ptr->protevil);
1952 rd_s16b(&creature_ptr->invuln);
1953 if (z_older_than(10, 0, 0))
1954 creature_ptr->ult_res = 0;
1956 rd_s16b(&creature_ptr->ult_res);
1957 rd_s16b(&creature_ptr->hero);
1958 rd_s16b(&creature_ptr->shero);
1959 rd_s16b(&creature_ptr->shield);
1960 rd_s16b(&creature_ptr->blessed);
1961 rd_s16b(&creature_ptr->tim_invis);
1962 rd_s16b(&creature_ptr->word_recall);
1963 if (z_older_than(10, 3, 8))
1964 creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
1968 creature_ptr->recall_dungeon = (byte)tmp16s;
1971 if (h_older_than(1, 5, 0, 0))
1972 creature_ptr->alter_reality = 0;
1974 rd_s16b(&creature_ptr->alter_reality);
1976 rd_s16b(&creature_ptr->see_infra);
1977 rd_s16b(&creature_ptr->tim_infra);
1978 rd_s16b(&creature_ptr->oppose_fire);
1979 rd_s16b(&creature_ptr->oppose_cold);
1980 rd_s16b(&creature_ptr->oppose_acid);
1981 rd_s16b(&creature_ptr->oppose_elec);
1982 rd_s16b(&creature_ptr->oppose_pois);
1983 if (z_older_than(10, 0, 2)) creature_ptr->tsuyoshi = 0;
1984 else rd_s16b(&creature_ptr->tsuyoshi);
1986 /* Old savefiles do not have the following fields... */
1987 if ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->z_patch == 6))
1989 creature_ptr->tim_esp = 0;
1990 creature_ptr->wraith_form = 0;
1991 creature_ptr->resist_magic = 0;
1992 creature_ptr->tim_regen = 0;
1993 creature_ptr->kabenuke = 0;
1994 creature_ptr->tim_stealth = 0;
1995 creature_ptr->tim_levitation = 0;
1996 creature_ptr->tim_sh_touki = 0;
1997 creature_ptr->lightspeed = 0;
1998 creature_ptr->tsubureru = 0;
1999 creature_ptr->tim_res_nether = 0;
2000 creature_ptr->tim_res_time = 0;
2001 creature_ptr->mimic_form = 0;
2002 creature_ptr->tim_mimic = 0;
2003 creature_ptr->tim_sh_fire = 0;
2004 creature_ptr->tim_reflect = 0;
2005 creature_ptr->multishadow = 0;
2006 creature_ptr->dustrobe = 0;
2007 creature_ptr->chaos_patron = ((creature_ptr->age + creature_ptr->sc) % MAX_PATRON);
2008 creature_ptr->muta1 = 0;
2009 creature_ptr->muta2 = 0;
2010 creature_ptr->muta3 = 0;
2011 get_virtues(creature_ptr);
2015 rd_s16b(&creature_ptr->tim_esp);
2016 rd_s16b(&creature_ptr->wraith_form);
2017 rd_s16b(&creature_ptr->resist_magic);
2018 rd_s16b(&creature_ptr->tim_regen);
2019 rd_s16b(&creature_ptr->kabenuke);
2020 rd_s16b(&creature_ptr->tim_stealth);
2021 rd_s16b(&creature_ptr->tim_levitation);
2022 rd_s16b(&creature_ptr->tim_sh_touki);
2023 rd_s16b(&creature_ptr->lightspeed);
2024 rd_s16b(&creature_ptr->tsubureru);
2025 if (z_older_than(10, 4, 7))
2026 creature_ptr->magicdef = 0;
2028 rd_s16b(&creature_ptr->magicdef);
2029 rd_s16b(&creature_ptr->tim_res_nether);
2030 if (z_older_than(10, 4, 11))
2032 creature_ptr->tim_res_time = 0;
2033 creature_ptr->mimic_form = 0;
2034 creature_ptr->tim_mimic = 0;
2035 creature_ptr->tim_sh_fire = 0;
2039 rd_s16b(&creature_ptr->tim_res_time);
2041 creature_ptr->mimic_form = (IDX)tmp8u;
2042 rd_s16b(&creature_ptr->tim_mimic);
2043 rd_s16b(&creature_ptr->tim_sh_fire);
2046 if (z_older_than(11, 0, 99))
2048 creature_ptr->tim_sh_holy = 0;
2049 creature_ptr->tim_eyeeye = 0;
2053 rd_s16b(&creature_ptr->tim_sh_holy);
2054 rd_s16b(&creature_ptr->tim_eyeeye);
2057 if (z_older_than(11, 0, 3)) {
2058 creature_ptr->tim_reflect = 0;
2059 creature_ptr->multishadow = 0;
2060 creature_ptr->dustrobe = 0;
2064 rd_s16b(&creature_ptr->tim_reflect);
2065 rd_s16b(&creature_ptr->multishadow);
2066 rd_s16b(&creature_ptr->dustrobe);
2069 rd_s16b(&creature_ptr->chaos_patron);
2070 rd_u32b(&creature_ptr->muta1);
2071 rd_u32b(&creature_ptr->muta2);
2072 rd_u32b(&creature_ptr->muta3);
2074 for (int i = 0; i < 8; i++)
2075 rd_s16b(&creature_ptr->virtues[i]);
2076 for (int i = 0; i < 8; i++)
2077 rd_s16b(&creature_ptr->vir_types[i]);
2080 creature_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod(creature_ptr);
2081 if (z_older_than(10, 0, 9))
2084 if (tmp8u) creature_ptr->special_attack = ATTACK_CONFUSE;
2085 creature_ptr->ele_attack = 0;
2089 rd_s16b(&creature_ptr->ele_attack);
2090 rd_u32b(&creature_ptr->special_attack);
2093 if (creature_ptr->special_attack & KAMAE_MASK) creature_ptr->action = ACTION_KAMAE;
2094 else if (creature_ptr->special_attack & KATA_MASK) creature_ptr->action = ACTION_KATA;
2095 if (z_older_than(10, 0, 12))
2097 creature_ptr->ele_immune = 0;
2098 creature_ptr->special_defense = 0;
2102 rd_s16b(&creature_ptr->ele_immune);
2103 rd_u32b(&creature_ptr->special_defense);
2106 rd_byte(&creature_ptr->knowledge);
2108 creature_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2112 creature_ptr->action = (ACTION_IDX)tmp8u;
2113 if (!z_older_than(10, 4, 3))
2116 if (tmp8u) creature_ptr->action = ACTION_LEARN;
2119 rd_byte((byte *)&preserve_mode);
2120 rd_byte((byte *)&creature_ptr->wait_report_score);
2122 for (int i = 0; i < 48; i++) rd_byte(&tmp8u);
2125 rd_u32b(¤t_world_ptr->seed_flavor);
2126 rd_u32b(¤t_world_ptr->seed_town);
2128 rd_u16b(&creature_ptr->panic_save);
2129 rd_u16b(¤t_world_ptr->total_winner);
2130 rd_u16b(¤t_world_ptr->noscore);
2133 creature_ptr->is_dead = tmp8u;
2135 rd_byte(&creature_ptr->feeling);
2137 switch (creature_ptr->start_race)
2143 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2146 current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2150 current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2151 rd_s32b(&creature_ptr->current_floor_ptr->generated_turn);
2152 if (h_older_than(1, 7, 0, 4))
2154 creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
2158 rd_s32b(&creature_ptr->feeling_turn);
2161 rd_s32b(¤t_world_ptr->game_turn);
2162 if (z_older_than(10, 3, 12))
2164 current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
2166 else rd_s32b(¤t_world_ptr->dungeon_turn);
2168 if (z_older_than(11, 0, 13))
2170 creature_ptr->current_floor_ptr->generated_turn /= 2;
2171 creature_ptr->feeling_turn /= 2;
2172 current_world_ptr->game_turn /= 2;
2173 current_world_ptr->dungeon_turn /= 2;
2176 if (z_older_than(10, 3, 13))
2178 current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
2180 else rd_s32b(¤t_world_ptr->arena_start_turn);
2182 if (z_older_than(10, 0, 3))
2184 determine_daily_bounty(creature_ptr, TRUE);
2188 rd_s16b(&today_mon);
2189 rd_s16b(&creature_ptr->today_mon);
2192 if (z_older_than(10, 0, 7))
2194 creature_ptr->riding = 0;
2198 rd_s16b(&creature_ptr->riding);
2201 if (h_older_than(1, 5, 0, 0))
2203 creature_ptr->floor_id = 0;
2207 rd_s16b(&creature_ptr->floor_id);
2210 if (h_older_than(1, 5, 0, 2))
2217 for (int i = 0; i < tmp16s; i++)
2219 monster_type dummy_mon;
2220 rd_monster(creature_ptr, &dummy_mon);
2224 if (z_older_than(10, 1, 2))
2226 current_world_ptr->play_time = 0;
2230 rd_u32b(¤t_world_ptr->play_time);
2233 if (z_older_than(10, 3, 9))
2235 creature_ptr->visit = 1L;
2237 else if (z_older_than(10, 3, 10))
2241 creature_ptr->visit = 1L;
2247 creature_ptr->visit = (BIT_FLAGS)tmp32s;
2250 if (!z_older_than(11, 0, 5))
2252 rd_u32b(&creature_ptr->count);
2258 * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2259 * @param player_ptr プレーヤーへの参照ポインタ
2262 * Note that the inventory changed in Angband 2.7.4. Two extra
2263 * pack slots were added and the equipment was rearranged. Note
2264 * that these two features combine when parsing old save-files, in
2265 * which items from the old "aux" slot are "carried", perhaps into
2266 * one of the two new "inventory" slots.
2268 * Note that the inventory is "re-sorted" later by "dungeon()".
2270 static errr rd_inventory(player_type *player_ptr)
2272 player_ptr->total_weight = 0;
2273 player_ptr->inven_cnt = 0;
2274 player_ptr->equip_cnt = 0;
2276 if (player_ptr->inventory_list != NULL) C_WIPE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2277 C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
2285 if (n == 0xFFFF) break;
2292 if (!q_ptr->k_idx) return (53);
2294 if (n >= INVEN_RARM)
2296 q_ptr->marked |= OM_TOUCHED;
2297 object_copy(&player_ptr->inventory_list[n], q_ptr);
2298 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2299 player_ptr->equip_cnt++;
2303 if (player_ptr->inven_cnt == INVEN_PACK)
2305 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
2310 q_ptr->marked |= OM_TOUCHED;
2311 object_copy(&player_ptr->inventory_list[n], q_ptr);
2312 player_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2313 player_ptr->inven_cnt++;
2321 * @brief メッセージログを読み込む / Read the saved messages
2324 static void rd_messages(void)
2326 if (h_older_than(2, 2, 0, 75))
2331 message_max = (int)num;
2333 for (int i = 0; i < message_max; i++)
2336 rd_string(buf, sizeof(buf));
2344 message_max = (int)num;
2346 for (int i = 0; i < message_max; i++)
2349 rd_string(buf, sizeof(buf));
2356 * @brief メッセージログを読み込む / Read the dungeon (old method)
2357 * @param creature_ptr プレーヤーへの参照ポインタ
2360 * The monsters/objects must be loaded in the same order
2361 * that they were stored, since the actual indexes matter.
2363 static errr rd_dungeon_old(player_type *creature_ptr)
2367 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2368 floor_ptr->dun_level = (DEPTH)tmp16s;
2369 if (z_older_than(10, 3, 8)) creature_ptr->dungeon_idx = DUNGEON_ANGBAND;
2374 creature_ptr->dungeon_idx = (IDX)tmp8u;
2377 floor_ptr->base_level = floor_ptr->dun_level;
2379 floor_ptr->base_level = (DEPTH)tmp16s;
2382 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2384 creature_ptr->y = (POSITION)tmp16s;
2386 creature_ptr->x = (POSITION)tmp16s;
2387 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) { creature_ptr->y = 33; creature_ptr->x = 131; }
2389 floor_ptr->height = (POSITION)tmp16s;
2391 floor_ptr->width = (POSITION)tmp16s;
2392 rd_s16b(&tmp16s); /* max_panel_rows */
2393 rd_s16b(&tmp16s); /* max_panel_cols */
2395 int ymax = floor_ptr->height;
2396 int xmax = floor_ptr->width;
2398 for (int x = 0, y = 0; y < ymax; )
2403 if (z_older_than(10, 3, 6))
2412 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2415 for (int i = count; i > 0; i--)
2418 g_ptr = &floor_ptr->grid_array[y][x];
2423 if (++y >= ymax) break;
2428 for (int x = 0, y = 0; y < ymax; )
2434 for (int i = count; i > 0; i--)
2437 g_ptr = &floor_ptr->grid_array[y][x];
2438 g_ptr->feat = (s16b)tmp8u;
2442 if (++y >= ymax) break;
2447 for (int x = 0, y = 0; y < ymax; )
2453 for (int i = count; i > 0; i--)
2456 g_ptr = &floor_ptr->grid_array[y][x];
2457 g_ptr->mimic = (s16b)tmp8u;
2461 if (++y >= ymax) break;
2466 for (int x = 0, y = 0; y < ymax; )
2471 for (int i = count; i > 0; i--)
2474 g_ptr = &floor_ptr->grid_array[y][x];
2475 g_ptr->special = tmp16s;
2479 if (++y >= ymax) break;
2484 if (z_older_than(11, 0, 99))
2486 for (int y = 0; y < ymax; y++)
2488 for (int x = 0; x < xmax; x++)
2490 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
2495 if (h_older_than(1, 1, 1, 0))
2497 for (int y = 0; y < ymax; y++)
2499 for (int x = 0; x < xmax; x++)
2502 g_ptr = &floor_ptr->grid_array[y][x];
2505 if (g_ptr->feat == OLD_FEAT_INVIS)
2507 g_ptr->feat = feat_floor;
2508 g_ptr->info |= CAVE_TRAP;
2511 /* Older than 1.1.1 */
2512 if (g_ptr->feat == OLD_FEAT_MIRROR)
2514 g_ptr->feat = feat_floor;
2515 g_ptr->info |= CAVE_OBJECT;
2521 if (h_older_than(1, 3, 1, 0))
2523 for (int y = 0; y < ymax; y++)
2525 for (int x = 0; x < xmax; x++)
2528 g_ptr = &floor_ptr->grid_array[y][x];
2530 /* Old CAVE_IN_MIRROR flag */
2531 if (g_ptr->info & CAVE_OBJECT)
2533 g_ptr->mimic = feat_mirror;
2535 else if ((g_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2536 (g_ptr->feat == OLD_FEAT_GLYPH))
2538 g_ptr->info |= CAVE_OBJECT;
2539 g_ptr->mimic = g_ptr->feat;
2540 g_ptr->feat = feat_floor;
2542 else if (g_ptr->info & CAVE_TRAP)
2544 g_ptr->info &= ~CAVE_TRAP;
2545 g_ptr->mimic = g_ptr->feat;
2546 g_ptr->feat = choose_random_trap(creature_ptr);
2548 else if (g_ptr->feat == OLD_FEAT_INVIS)
2550 g_ptr->mimic = feat_floor;
2551 g_ptr->feat = feat_trap_open;
2557 /* Quest 18 was removed */
2558 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2560 for (int y = 0; y < ymax; y++)
2562 for (int x = 0; x < xmax; x++)
2565 g_ptr = &floor_ptr->grid_array[y][x];
2567 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2569 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2571 g_ptr->feat = feat_tree;
2574 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2576 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2579 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2580 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2582 g_ptr->feat = feat_up_stair;
2591 if (limit > current_world_ptr->max_o_idx)
2593 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2597 for (int i = 1; i < limit; i++)
2599 OBJECT_IDX o_idx = o_pop(floor_ptr);
2602 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2607 o_ptr = &floor_ptr->o_list[o_idx];
2609 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2611 monster_type *m_ptr;
2612 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2613 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2614 m_ptr->hold_o_idx = o_idx;
2619 g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2620 o_ptr->next_o_idx = g_ptr->o_idx;
2621 g_ptr->o_idx = o_idx;
2625 if (limit > current_world_ptr->max_m_idx)
2627 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2631 for (int i = 1; i < limit; i++)
2634 monster_type *m_ptr;
2635 m_idx = m_pop(creature_ptr);
2638 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2642 m_ptr = &floor_ptr->m_list[m_idx];
2643 rd_monster(creature_ptr, m_ptr);
2645 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2646 g_ptr->m_idx = m_idx;
2647 real_r_ptr(m_ptr)->cur_num++;
2650 if (z_older_than(10, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena)
2651 current_world_ptr->character_dungeon = FALSE;
2653 current_world_ptr->character_dungeon = TRUE;
2660 * @brief 保存されたフロアを読み込む / Read the saved floor
2661 * @param player_ptr プレーヤーへの参照ポインタ
2662 * @param sf_ptr 最後に保存されたフロアへの参照ポインタ
2663 * @return info読み込みエラーコード
2665 * この関数は、セーブデータの互換性を保つために多くのデータ改変処理を備えている。
2668 * <li>1.7.0.2で8bitだったgrid_typeのfeat,mimicのID値を16bitに拡張する処理。</li>
2669 * <li>1.7.0.8までに廃止、IDなどを差し替えたクエスト番号を置換する処理。</li>
2671 * The monsters/objects must be loaded in the same order
2672 * that they were stored, since the actual indexes matter.
2674 static errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
2676 grid_template_type *templates;
2677 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2678 clear_cave(player_ptr);
2679 player_ptr->x = player_ptr->y = 0;
2685 floor_ptr->dun_level = (DEPTH)tmp16s;
2686 floor_ptr->base_level = floor_ptr->dun_level;
2692 if (tmp16s != sf_ptr->floor_id) return 171;
2696 if (tmp8u != sf_ptr->savefile_id) return 171;
2699 if (tmp16s != sf_ptr->dun_level) return 171;
2700 floor_ptr->dun_level = sf_ptr->dun_level;
2704 if (tmp32s != sf_ptr->last_visit) return 171;
2708 if (tmp32u != sf_ptr->visit_mark) return 171;
2711 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2714 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2719 floor_ptr->base_level = (DEPTH)tmp16s;
2721 floor_ptr->num_repro = (MONSTER_NUMBER)tmp16s;
2725 player_ptr->y = (POSITION)tmp16u;
2728 player_ptr->x = (POSITION)tmp16u;
2731 floor_ptr->height = (POSITION)tmp16s;
2733 floor_ptr->width = (POSITION)tmp16s;
2735 rd_byte(&player_ptr->feeling);
2739 C_MAKE(templates, limit, grid_template_type);
2741 for (int i = 0; i < limit; i++)
2743 grid_template_type *ct_ptr = &templates[i];
2745 ct_ptr->info = (BIT_FLAGS)tmp16u;
2746 if (h_older_than(1, 7, 0, 2))
2750 ct_ptr->feat = (s16b)tmp8u;
2752 ct_ptr->mimic = (s16b)tmp8u;
2756 rd_s16b(&ct_ptr->feat);
2757 rd_s16b(&ct_ptr->mimic);
2760 rd_s16b(&ct_ptr->special);
2763 POSITION ymax = floor_ptr->height;
2764 POSITION xmax = floor_ptr->width;
2765 for (POSITION x = 0, y = 0; y < ymax; )
2776 } while (tmp8u == MAX_UCHAR);
2778 for (int i = count; i > 0; i--)
2780 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2781 g_ptr->info = templates[id].info;
2782 g_ptr->feat = templates[id].feat;
2783 g_ptr->mimic = templates[id].mimic;
2784 g_ptr->special = templates[id].special;
2789 if (++y >= ymax) break;
2794 /* Quest 18 was removed */
2795 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2797 for (POSITION y = 0; y < ymax; y++)
2799 for (POSITION x = 0; x < xmax; x++)
2801 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2803 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level)
2805 if (g_ptr->feat == OLD_FEAT_QUEST_ENTER)
2807 g_ptr->feat = feat_tree;
2810 else if (g_ptr->feat == OLD_FEAT_BLDG_1)
2812 g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2815 else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2816 (floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2818 g_ptr->feat = feat_up_stair;
2825 C_KILL(templates, limit, grid_template_type);
2827 if (limit > current_world_ptr->max_o_idx) return 151;
2828 for (int i = 1; i < limit; i++)
2832 o_idx = o_pop(floor_ptr);
2833 if (i != o_idx) return 152;
2835 o_ptr = &floor_ptr->o_list[o_idx];
2838 if (OBJECT_IS_HELD_MONSTER(o_ptr))
2840 monster_type *m_ptr;
2841 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
2842 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2843 m_ptr->hold_o_idx = o_idx;
2847 grid_type *g_ptr = &floor_ptr->grid_array[o_ptr->iy][o_ptr->ix];
2848 o_ptr->next_o_idx = g_ptr->o_idx;
2849 g_ptr->o_idx = o_idx;
2854 if (limit > current_world_ptr->max_m_idx) return 161;
2856 for (int i = 1; i < limit; i++)
2860 monster_type *m_ptr;
2861 m_idx = m_pop(player_ptr);
2862 if (i != m_idx) return 162;
2864 m_ptr = &floor_ptr->m_list[m_idx];
2865 rd_monster(player_ptr, m_ptr);
2866 g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
2867 g_ptr->m_idx = m_idx;
2868 real_r_ptr(m_ptr)->cur_num++;
2876 * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
2877 * @param player_ptr プレーヤーへの参照ポインタ
2880 * The monsters/objects must be loaded in the same order
2881 * that they were stored, since the actual indexes matter.
2883 static errr rd_dungeon(player_type *player_ptr)
2885 init_saved_floors(player_ptr, FALSE);
2887 if (h_older_than(1, 5, 0, 0))
2889 err = rd_dungeon_old(player_ptr);
2890 if (player_ptr->dungeon_idx)
2892 player_ptr->floor_id = get_new_floor_id(player_ptr);
2893 get_sf_ptr(player_ptr->floor_id)->dun_level = player_ptr->current_floor_ptr->dun_level;
2899 rd_s16b(&max_floor_id);
2902 player_ptr->dungeon_idx = (DUNGEON_IDX)tmp8u;
2907 err = rd_saved_floor(player_ptr, NULL);
2911 for (int i = 0; i < num; i++)
2913 saved_floor_type *sf_ptr = &saved_floors[i];
2915 rd_s16b(&sf_ptr->floor_id);
2917 sf_ptr->savefile_id = (s16b)tmp8u;
2921 sf_ptr->dun_level = (DEPTH)tmp16s;
2923 rd_s32b(&sf_ptr->last_visit);
2924 rd_u32b(&sf_ptr->visit_mark);
2925 rd_s16b(&sf_ptr->upper_floor_id);
2926 rd_s16b(&sf_ptr->lower_floor_id);
2929 for (int i = 0; i < num; i++)
2931 saved_floor_type *sf_ptr = &saved_floors[i];
2932 if (!sf_ptr->floor_id) continue;
2934 if (tmp8u) continue;
2936 err = rd_saved_floor(player_ptr, sf_ptr);
2939 if (!save_floor(player_ptr, sf_ptr, SLF_SECOND)) err = 182;
2946 if (!load_floor(player_ptr, get_sf_ptr(player_ptr->floor_id), SLF_SECOND)) err = 183;
2953 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
2957 note(_("アイテム配置エラー", "Object allocation error"));
2961 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
2965 note(_("モンスター配置エラー", "Monster allocation error"));
2969 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
2973 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporary files!"));
2977 note(_("Error 183", "Error 183"));
2981 current_world_ptr->character_dungeon = TRUE;
2987 * @brief ロード処理全体のサブ関数 / Actually read the savefile
2990 static errr rd_savefile_new_aux(player_type *creature_ptr)
2992 u32b n_x_check, n_v_check;
2993 u32b o_x_check, o_v_check;
2996 xor_byte = current_world_ptr->sf_extra;
3000 /* Old savefile will be version 0.0.0.3 */
3001 rd_byte(¤t_world_ptr->h_ver_extra);
3002 rd_byte(¤t_world_ptr->h_ver_patch);
3003 rd_byte(¤t_world_ptr->h_ver_minor);
3004 rd_byte(¤t_world_ptr->h_ver_major);
3007 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3008 (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));
3010 rd_u32b(¤t_world_ptr->sf_system);
3011 rd_u32b(¤t_world_ptr->sf_when);
3012 rd_u16b(¤t_world_ptr->sf_lives);
3013 rd_u16b(¤t_world_ptr->sf_saves);
3023 rd_byte(&kanji_code);
3026 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3029 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3032 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3034 for (int i = 0; i < max_r_idx; i++)
3036 monster_race *r_ptr = &r_info[i];
3037 r_ptr->max_num = 100;
3039 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3040 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3044 if (tmp16u > max_r_idx)
3046 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3050 for (int i = 0; i < tmp16u; i++)
3052 rd_lore((MONRACE_IDX)i);
3055 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3058 if (tmp16u > max_k_idx)
3060 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3064 for (int i = 0; i < tmp16u; i++)
3066 object_kind *k_ptr = &k_info[i];
3068 k_ptr->aware = (tmp8u & 0x01) ? TRUE : FALSE;
3069 k_ptr->tried = (tmp8u & 0x02) ? TRUE : FALSE;
3071 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3073 /* 2.1.3 or newer version */
3075 u16b max_towns_load;
3076 u16b max_quests_load;
3077 byte max_rquests_load;
3078 s16b old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
3080 rd_u16b(&max_towns_load);
3081 if (max_towns_load > max_towns)
3083 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3087 rd_u16b(&max_quests_load);
3088 if (z_older_than(11, 0, 7))
3090 max_rquests_load = 10;
3094 rd_byte(&max_rquests_load);
3097 if (max_quests_load > max_q_idx)
3099 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3103 for (int i = 0; i < max_quests_load; i++)
3112 quest_type* const q_ptr = &quest[i];
3114 rd_s16b(&q_ptr->status);
3117 q_ptr->level = tmp16s;
3119 if (z_older_than(11, 0, 6))
3126 q_ptr->complev = tmp8u;
3128 if (h_older_than(2, 1, 2, 2))
3130 q_ptr->comptime = 0;
3134 rd_u32b(&q_ptr->comptime);
3137 bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
3138 is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
3139 is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
3140 if (!is_quest_running) continue;
3143 q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
3145 q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
3146 rd_s16b(&q_ptr->type);
3148 rd_s16b(&q_ptr->r_idx);
3149 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3151 determine_random_questor(creature_ptr, &quest[i]);
3154 rd_s16b(&q_ptr->k_idx);
3156 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3159 q_ptr->flags = tmp8u;
3161 if (z_older_than(10, 3, 11))
3163 if (q_ptr->flags & QUEST_FLAG_PRESET)
3169 init_flags = INIT_ASSIGN;
3170 creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)i;
3172 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
3173 creature_ptr->current_floor_ptr->inside_quest = old_inside_quest;
3179 q_ptr->dungeon = tmp8u;
3182 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3183 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3184 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3187 /* Quest 18 was removed */
3188 if (h_older_than(1, 7, 0, 6))
3190 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3191 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3194 rd_s32b(&creature_ptr->wilderness_x);
3195 rd_s32b(&creature_ptr->wilderness_y);
3196 if (z_older_than(10, 3, 13))
3198 creature_ptr->wilderness_x = 5;
3199 creature_ptr->wilderness_y = 48;
3202 if (z_older_than(10, 3, 7)) creature_ptr->wild_mode = FALSE;
3203 else rd_byte((byte *)&creature_ptr->wild_mode);
3204 if (z_older_than(10, 3, 7)) creature_ptr->ambush_flag = FALSE;
3205 else rd_byte((byte *)&creature_ptr->ambush_flag);
3209 rd_s32b(&wild_x_size);
3210 rd_s32b(&wild_y_size);
3212 if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y))
3214 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3218 for (int i = 0; i < wild_x_size; i++)
3220 for (int j = 0; j < wild_y_size; j++)
3222 rd_u32b(&wilderness[j][i].seed);
3227 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3230 if (tmp16u > max_a_idx)
3232 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3236 for (int i = 0; i < tmp16u; i++)
3238 artifact_type *a_ptr = &a_info[i];
3241 a_ptr->cur_num = tmp8u;
3243 if (h_older_than(1, 5, 0, 0))
3245 a_ptr->floor_id = 0;
3253 rd_s16b(&a_ptr->floor_id);
3257 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3259 rd_extra(creature_ptr);
3260 if (creature_ptr->energy_need < -999) creature_ptr->timewalk = TRUE;
3262 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3265 if (tmp16u > PY_MAX_LEVEL)
3267 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3271 for (int i = 0; i < tmp16u; i++)
3275 creature_ptr->player_hp[i] = (HIT_POINT)tmp16s;
3278 sp_ptr = &sex_info[creature_ptr->psex];
3279 rp_ptr = &race_info[creature_ptr->prace];
3280 cp_ptr = &class_info[creature_ptr->pclass];
3281 ap_ptr = &seikaku_info[creature_ptr->pseikaku];
3283 if (z_older_than(10, 2, 2) && (creature_ptr->pclass == CLASS_BEASTMASTER) && !creature_ptr->is_dead)
3285 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3286 roll_hitdice(creature_ptr, 0L);
3289 if (z_older_than(10, 3, 2) && (creature_ptr->pclass == CLASS_ARCHER) && !creature_ptr->is_dead)
3291 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3292 roll_hitdice(creature_ptr, 0L);
3295 if (z_older_than(10, 2, 6) && (creature_ptr->pclass == CLASS_SORCERER) && !creature_ptr->is_dead)
3297 creature_ptr->hitdie = rp_ptr->r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3298 roll_hitdice(creature_ptr, 0L);
3301 if (z_older_than(10, 4, 7) && (creature_ptr->pclass == CLASS_BLUE_MAGE) && !creature_ptr->is_dead)
3303 creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3304 roll_hitdice(creature_ptr, 0L);
3307 mp_ptr = &m_info[creature_ptr->pclass];
3309 rd_u32b(&creature_ptr->spell_learned1);
3310 rd_u32b(&creature_ptr->spell_learned2);
3311 rd_u32b(&creature_ptr->spell_worked1);
3312 rd_u32b(&creature_ptr->spell_worked2);
3313 rd_u32b(&creature_ptr->spell_forgotten1);
3314 rd_u32b(&creature_ptr->spell_forgotten2);
3316 if (z_older_than(10, 0, 5))
3318 creature_ptr->learned_spells = 0;
3319 for (int i = 0; i < 64; i++)
3322 (creature_ptr->spell_learned1 & (1L << i)) :
3323 (creature_ptr->spell_learned2 & (1L << (i - 32))))
3325 creature_ptr->learned_spells++;
3329 else rd_s16b(&creature_ptr->learned_spells);
3331 if (z_older_than(10, 0, 6))
3333 creature_ptr->add_spells = 0;
3335 else rd_s16b(&creature_ptr->add_spells);
3337 if (creature_ptr->pclass == CLASS_MINDCRAFTER) creature_ptr->add_spells = 0;
3339 for (int i = 0; i < 64; i++)
3342 creature_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
3345 if (rd_inventory(creature_ptr))
3347 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3352 int town_count = tmp16u;
3355 for (int i = 1; i < town_count; i++)
3357 for (int j = 0; j < tmp16u; j++)
3359 if (rd_store(creature_ptr, i, j)) return (22);
3363 rd_s16b(&creature_ptr->pet_follow_distance);
3364 if (z_older_than(10, 4, 10))
3366 creature_ptr->pet_extra_flags = 0;
3368 if (tmp8u) creature_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3370 if (tmp8u) creature_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3372 if (z_older_than(10, 0, 4)) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3376 if (tmp8u) creature_ptr->pet_extra_flags |= PF_TELEPORT;
3379 if (z_older_than(10, 0, 7)) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3383 if (tmp8u) creature_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3386 if (z_older_than(10, 0, 8)) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3390 if (tmp8u) creature_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3393 if (!z_older_than(10, 0, 8))
3396 if (tmp8u) creature_ptr->pet_extra_flags |= PF_BALL_SPELL;
3401 rd_s16b(&creature_ptr->pet_extra_flags);
3404 if (!z_older_than(11, 0, 9))
3406 char buf[SCREEN_BUF_MAX_SIZE];
3407 rd_string(buf, sizeof(buf));
3408 if (buf[0]) screen_dump = string_make(buf);
3411 if (creature_ptr->is_dead)
3413 for (int i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3415 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3419 if (!creature_ptr->is_dead)
3421 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3422 if (rd_dungeon(creature_ptr))
3424 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3433 strip_bytes(tmp32s);
3437 /* Quest 18 was removed */
3438 if (h_older_than(1, 7, 0, 6))
3440 if (creature_ptr->current_floor_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3442 creature_ptr->dungeon_idx = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3443 creature_ptr->current_floor_ptr->dun_level = 1;
3444 creature_ptr->current_floor_ptr->inside_quest = 0;
3448 n_v_check = v_check;
3449 rd_u32b(&o_v_check);
3450 if (o_v_check != n_v_check)
3452 note(_("チェックサムがおかしい", "Invalid checksum"));
3456 n_x_check = x_check;
3457 rd_u32b(&o_x_check);
3458 if (o_x_check != n_x_check)
3460 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3469 * @brief ロード処理全体のメイン関数 / Actually read the savefile
3470 * @param player_ptr プレーヤーへの参照ポインタ
3473 errr rd_savefile_new(player_type *player_ptr)
3476 fff = my_fopen(savefile, "rb");
3478 if (!fff) return -1;
3479 errr err = rd_savefile_new_aux(player_ptr);
3481 if (ferror(fff)) err = -1;
3488 * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3489 * @param player_ptr プレーヤーへの参照ポインタ
3490 * @param sf_ptr 保存フロア読み込み先
3493 static bool load_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
3495 u32b n_x_check, n_v_check;
3496 u32b o_x_check, o_v_check;
3505 current_world_ptr->h_ver_extra = H_VER_EXTRA;
3506 current_world_ptr->h_ver_patch = H_VER_PATCH;
3507 current_world_ptr->h_ver_minor = H_VER_MINOR;
3508 current_world_ptr->h_ver_major = H_VER_MAJOR;
3512 if (saved_floor_file_sign != tmp32u) return FALSE;
3514 if (rd_saved_floor(player_ptr, sf_ptr)) return FALSE;
3516 n_v_check = v_check;
3517 rd_u32b(&o_v_check);
3519 if (o_v_check != n_v_check) return FALSE;
3521 n_x_check = x_check;
3522 rd_u32b(&o_x_check);
3524 if (o_x_check != n_x_check) return FALSE;
3530 * @brief 一時保存フロア情報を読み込む / Attempt to load the temporarily saved-floor data
3531 * @param player_ptr プレーヤーへの参照ポインタ
3532 * @param sf_ptr 保存フロア読み込み先
3536 bool load_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
3539 * Temporary files are always written in system depended kanji
3553 FILE *old_fff = NULL;
3554 byte old_xor_byte = 0;
3555 u32b old_v_check = 0;
3556 u32b old_x_check = 0;
3557 byte old_h_ver_major = 0;
3558 byte old_h_ver_minor = 0;
3559 byte old_h_ver_patch = 0;
3560 byte old_h_ver_extra = 0;
3561 if (mode & SLF_SECOND)
3564 old_xor_byte = xor_byte;
3565 old_v_check = v_check;
3566 old_x_check = x_check;
3567 old_h_ver_major = current_world_ptr->h_ver_major;
3568 old_h_ver_minor = current_world_ptr->h_ver_minor;
3569 old_h_ver_patch = current_world_ptr->h_ver_patch;
3570 old_h_ver_extra = current_world_ptr->h_ver_extra;
3573 char floor_savefile[1024];
3574 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3577 fff = my_fopen(floor_savefile, "rb");
3580 bool is_save_successful = TRUE;
3581 if (!fff) is_save_successful = FALSE;
3583 if (is_save_successful)
3585 is_save_successful = load_floor_aux(player_ptr, sf_ptr);
3586 if (ferror(fff)) is_save_successful = FALSE;
3590 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3595 if (mode & SLF_SECOND)
3598 xor_byte = old_xor_byte;
3599 v_check = old_v_check;
3600 x_check = old_x_check;
3601 current_world_ptr->h_ver_major = old_h_ver_major;
3602 current_world_ptr->h_ver_minor = old_h_ver_minor;
3603 current_world_ptr->h_ver_patch = old_h_ver_patch;
3604 current_world_ptr->h_ver_extra = old_h_ver_extra;
3607 byte old_kanji_code = kanji_code;
3608 kanji_code = old_kanji_code;
3609 return is_save_successful;