OSDN Git Service

#37287 #37353 (2.2.0.89) ITEM_NUMBERをs32bに再定義、型の置換を継続中。 / Redefine ITEM_NUMBER to...
[hengband/hengband.git] / src / load.c
1 /*!
2  * @file load.c
3  * @brief セーブファイル読み込み処理 / Purpose: support for loading savefiles -BEN-
4  * @date 2014/07/07
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
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.
11  * @details
12  * This file loads savefiles from Angband 2.7.X and 2.8.X
13  *
14  * Ancient savefiles (pre-2.7.0) are loaded by another file.
15  *
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.
18  *
19  * We attempt to prevent corrupt savefiles from inducing memory errors.
20  *
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.
24  *
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.
29  *
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.
34  *
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.
39  *
40  * XXX XXX XXX
41  */
42
43 #include "angband.h"
44
45
46 /*
47  * Maximum number of tries for selection of a proper quest monster
48  */
49 #define MAX_TRIES 100
50
51
52 /*
53  * Local "savefile" pointer
54  */
55 static FILE     *fff;
56
57 /*
58  * Hack -- old "encryption" byte
59  */
60 static byte     xor_byte;
61
62 /*
63  * Hack -- simple "checksum" on the actual values
64  */
65 static u32b     v_check = 0L;
66
67 /*
68  * Hack -- simple "checksum" on the encoded bytes
69  */
70 static u32b     x_check = 0L;
71
72 /*
73  * Hack -- Japanese Kanji code
74  * 0: Unknown
75  * 1: ASCII
76  * 2: EUC
77  * 3: SJIS
78  */
79 static byte kanji_code = 0;
80
81 /*!
82  * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
83  * @param major メジャーバージョン値
84  * @param minor マイナーバージョン値
85  * @param patch パッチバージョン値
86  * @param extra エクストラパージョン値
87  * @return 現在のバージョンより値が古いならtrue
88  */
89 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
90 {
91         /* Much older, or much more recent */
92         if (h_ver_major < major) return (TRUE);
93         if (h_ver_major > major) return (FALSE);
94
95         /* Distinctly older, or distinctly more recent */
96         if (h_ver_minor < minor) return (TRUE);
97         if (h_ver_minor > minor) return (FALSE);
98
99         /* Barely older, or barely more recent */
100         if (h_ver_patch < patch) return (TRUE);
101         if (h_ver_patch > patch) return (FALSE);
102
103         /* Barely older, or barely more recent */
104         if (h_ver_extra < extra) return (TRUE);
105         if (h_ver_extra > extra) return (FALSE);
106
107         /* Identical versions */
108         return (FALSE);
109 }
110
111
112 /*!
113  * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
114  * @param x メジャーバージョン値
115  * @param y マイナーバージョン値
116  * @param z パッチバージョン値
117  * @return 現在のバージョンより値が古いならtrue
118  */
119 static bool z_older_than(byte x, byte y, byte z)
120 {
121         /* Much older, or much more recent */
122         if (z_major < x) return (TRUE);
123         if (z_major > x) return (FALSE);
124
125         /* Distinctly older, or distinctly more recent */
126         if (z_minor < y) return (TRUE);
127         if (z_minor > y) return (FALSE);
128
129         /* Barely older, or barely more recent */
130         if (z_patch < z) return (TRUE);
131         if (z_patch > z) return (FALSE);
132
133         /* Identical versions */
134         return (FALSE);
135 }
136
137
138 /*!
139  * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
140  * @param msg 表示文字列
141  * @return なし
142  * @details
143  * Avoid the top two lines, to avoid interference with "msg_print()".
144  */
145 static void note(cptr msg)
146 {
147         static int y = 2;
148
149         /* Draw the message */
150         prt(msg, y, 0);
151
152         /* Advance one line (wrap if needed) */
153         if (++y >= 24) y = 2;
154
155         /* Flush it */
156         Term_fresh();
157 }
158
159
160 /*!
161  * @brief ロードファイルポインタから1バイトを読み込む
162  * @return 読み込んだバイト値
163  * @details
164  * The following functions are used to load the basic building blocks
165  * of savefiles.  They also maintain the "checksum" info for 2.7.0+
166  */
167 static byte sf_get(void)
168 {
169         byte c, v;
170
171         /* Get a character, decode the value */
172         c = getc(fff) & 0xFF;
173         v = c ^ xor_byte;
174         xor_byte = c;
175
176         /* Maintain the checksum info */
177         v_check += v;
178         x_check += xor_byte;
179
180         /* Return the value */
181         return (v);
182 }
183
184 /*!
185  * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
186  * @param ip 読み込みポインタ
187  * @return なし
188  */
189 static void rd_byte(byte *ip)
190 {
191         *ip = sf_get();
192 }
193
194 /*!
195  * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
196  * @param ip 読み込みポインタ
197  * @return なし
198  */
199 static void rd_u16b(u16b *ip)
200 {
201         (*ip) = sf_get();
202         (*ip) |= ((u16b)(sf_get()) << 8);
203 }
204
205 /*!
206  * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
207  * @param ip 読み込みポインタ
208  * @return なし
209  */
210 static void rd_s16b(s16b *ip)
211 {
212         rd_u16b((u16b*)ip);
213 }
214
215 /*!
216  * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
217  * @param ip 読み込みポインタ
218  * @return なし
219  */
220 static void rd_u32b(u32b *ip)
221 {
222         (*ip) = sf_get();
223         (*ip) |= ((u32b)(sf_get()) << 8);
224         (*ip) |= ((u32b)(sf_get()) << 16);
225         (*ip) |= ((u32b)(sf_get()) << 24);
226 }
227
228 /*!
229  * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
230  * @param ip 読み込みポインタ
231  * @return なし
232  */
233 static void rd_s32b(s32b *ip)
234 {
235         rd_u32b((u32b*)ip);
236 }
237
238
239 /*!
240  * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
241  * @param str 読み込みポインタ
242  * @param max 最大読み取りバイト数
243  * @return なし
244  */
245 static void rd_string(char *str, int max)
246 {
247         int i;
248
249         /* Read the string */
250         for (i = 0; TRUE; i++)
251         {
252                 byte tmp8u;
253
254                 /* Read a byte */
255                 rd_byte(&tmp8u);
256
257                 /* Collect string while legal */
258                 if (i < max) str[i] = tmp8u;
259
260                 /* End of string */
261                 if (!tmp8u) break;
262         }
263
264         /* Terminate */
265         str[max-1] = '\0';
266
267
268 #ifdef JP
269         /* Convert Kanji code */
270         switch (kanji_code)
271         {
272 #ifdef SJIS
273         case 2:
274                 /* EUC to SJIS */
275                 euc2sjis(str);
276                 break;
277 #endif
278
279 #ifdef EUC
280         case 3:
281                 /* SJIS to EUC */
282                 sjis2euc(str);
283                 break;
284 #endif
285
286         case 0:
287         {
288                 /* 不明の漢字コードからシステムの漢字コードに変換 */
289                 byte code = codeconv(str);
290
291                 /* 漢字コードが判明したら、それを記録 */
292                 if (code) kanji_code = code;
293
294                 break;
295         }
296         default:
297                 /* No conversion needed */
298                 break;
299         }
300 #endif
301 }
302
303
304 /*!
305  * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
306  * @param n スキップバイト数
307  * @return なし
308  */
309 static void strip_bytes(int n)
310 {
311         byte tmp8u;
312
313         /* Strip the bytes */
314         while (n--) rd_byte(&tmp8u);
315 }
316
317 #define OLD_MAX_MANE 22
318
319 /*!
320  * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
321  * @param o_ptr アイテムオブジェクト読み取り先ポインタ
322  * @return なし
323  * @details
324  * This function attempts to "repair" old savefiles, and to extract
325  * the most up to date values for various object fields.
326  *
327  * Note that Angband 2.7.9 introduced a new method for object "flags"
328  * in which the "flags" on an object are actually extracted when they
329  * are needed from the object kind, artifact index, ego-item index,
330  * and two special "xtra" fields which are used to encode any "extra"
331  * power of certain ego-items.  This had the side effect that items
332  * imported from pre-2.7.9 savefiles will lose any "extra" powers they
333  * may have had, and also, all "uncursed" items will become "cursed"
334  * again, including Calris, even if it is being worn at the time.  As
335  * a complete hack, items which are inscribed with "uncursed" will be
336  * "uncursed" when imported from pre-2.7.9 savefiles.
337  */
338 static void rd_item_old(object_type *o_ptr)
339 {
340         char buf[128];
341         byte_hack tmp8u;
342         s16b tmp16s;
343
344
345         /* Kind */
346         rd_s16b(&o_ptr->k_idx);
347
348         /* Location */
349         rd_byte(&tmp8u);
350         o_ptr->iy = (POSITION)tmp8u;
351         rd_byte(&tmp8u);
352         o_ptr->ix = (POSITION)tmp8u;
353
354         /* Type/Subtype */
355         rd_byte(&o_ptr->tval);
356         rd_byte(&o_ptr->sval);
357
358         if (z_older_than(10, 4, 4))
359         {
360                 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
361                 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
362                 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
363         }
364
365         /* Special pval */
366         rd_s16b(&o_ptr->pval);
367
368         rd_byte(&o_ptr->discount);
369         rd_byte(&tmp8u);
370         o_ptr->number = (ITEM_NUMBER)tmp8u;
371         rd_s16b(&o_ptr->weight);
372
373         rd_byte(&tmp8u);
374         o_ptr->name1 = tmp8u;
375
376         rd_byte(&tmp8u);
377         o_ptr->name2 = tmp8u;
378
379         rd_s16b(&o_ptr->timeout);
380
381         rd_s16b(&o_ptr->to_h);
382         
383         rd_s16b(&tmp16s);
384         o_ptr->to_d = tmp16s;
385         rd_s16b(&o_ptr->to_a);
386
387         rd_s16b(&o_ptr->ac);
388
389         rd_byte(&o_ptr->dd);
390         rd_byte(&o_ptr->ds);
391
392         rd_byte(&o_ptr->ident);
393
394         rd_byte(&o_ptr->marked);
395
396         /* Object flags */
397         rd_u32b(&o_ptr->art_flags[0]);
398         rd_u32b(&o_ptr->art_flags[1]);
399         rd_u32b(&o_ptr->art_flags[2]);
400         if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
401         else rd_u32b(&o_ptr->art_flags[3]);
402
403         if (h_older_than(1, 3, 0, 0))
404         {
405                 if (o_ptr->name2 == EGO_TELEPATHY)
406                         add_flag(o_ptr->art_flags, TR_TELEPATHY);
407         }
408
409         if (z_older_than(11, 0, 11))
410         {
411                 o_ptr->curse_flags = 0L;
412                 if (o_ptr->ident & 0x40)
413                 {
414                         o_ptr->curse_flags |= TRC_CURSED;
415                         if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
416                         if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
417                         if (object_is_fixed_artifact(o_ptr))
418                         {
419                                 artifact_type *a_ptr = &a_info[o_ptr->name1];
420                                 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
421                                 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
422                         }
423                         else if (object_is_ego(o_ptr))
424                         {
425                                 ego_item_type *e_ptr = &e_info[o_ptr->name2];
426                                 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
427                                 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
428                         }
429                 }
430                 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
431         }
432         else
433         {
434                 rd_u32b(&o_ptr->curse_flags);
435         }
436
437         /* Monster holding object */
438         rd_s16b(&o_ptr->held_m_idx);
439
440         /* Special powers */
441         rd_byte(&o_ptr->xtra1);
442         rd_byte(&o_ptr->xtra2);
443
444         if (z_older_than(11, 0, 10))
445         {
446                 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
447                 {
448                         switch (o_ptr->xtra2 % 6)
449                         {
450                         case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
451                         case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
452                         case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
453                         case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
454                         case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
455                         case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
456                         }
457                         o_ptr->xtra2 = 0;
458                 }
459                 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
460                 {
461                         switch (o_ptr->xtra2 % 11)
462                         {
463                         case  0: add_flag(o_ptr->art_flags, TR_RES_BLIND);  break;
464                         case  1: add_flag(o_ptr->art_flags, TR_RES_CONF);   break;
465                         case  2: add_flag(o_ptr->art_flags, TR_RES_SOUND);  break;
466                         case  3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
467                         case  4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
468                         case  5: add_flag(o_ptr->art_flags, TR_RES_NEXUS);  break;
469                         case  6: add_flag(o_ptr->art_flags, TR_RES_CHAOS);  break;
470                         case  7: add_flag(o_ptr->art_flags, TR_RES_DISEN);  break;
471                         case  8: add_flag(o_ptr->art_flags, TR_RES_POIS);   break;
472                         case  9: add_flag(o_ptr->art_flags, TR_RES_DARK);   break;
473                         case 10: add_flag(o_ptr->art_flags, TR_RES_LITE);   break;
474                         }
475                         o_ptr->xtra2 = 0;
476                 }               
477                 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
478                 {
479                         switch (o_ptr->xtra2 % 8)
480                         {
481                         case 0: add_flag(o_ptr->art_flags, TR_LEVITATION);     break;
482                         case 1: add_flag(o_ptr->art_flags, TR_LITE_1);        break;
483                         case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS);   break;
484                         case 3: add_flag(o_ptr->art_flags, TR_WARNING);     break;
485                         case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
486                         case 5: add_flag(o_ptr->art_flags, TR_REGEN);       break;
487                         case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT);    break;
488                         case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP);   break;
489                         }
490                         o_ptr->xtra2 = 0;
491                 }
492                 o_ptr->xtra1 = 0;
493         }
494
495         if (z_older_than(10, 2, 3))
496         {
497                 o_ptr->xtra3 = 0;
498                 o_ptr->xtra4 = 0;
499                 o_ptr->xtra5 = 0;
500                 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
501                 {
502                         o_ptr->xtra3 = o_ptr->xtra1;
503                         o_ptr->xtra1 = 0;
504                 }
505                 if (o_ptr->tval == TV_CAPTURE)
506                 {
507                         if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
508                                 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
509                         else
510                                 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
511                         if (ironman_nightmare)
512                         {
513                                 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
514                         }
515                         o_ptr->xtra4 = o_ptr->xtra5;
516                 }
517         }
518         else
519         {
520                 rd_byte(&o_ptr->xtra3);
521                 if (h_older_than(1, 3, 0, 1))
522                 {
523                         if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
524                                 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
525                 }
526
527                 rd_s16b(&o_ptr->xtra4);
528                 rd_s16b(&o_ptr->xtra5);
529         }
530
531         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)))
532         {
533                 o_ptr->xtra4 = o_ptr->pval;
534                 o_ptr->pval = 0;
535         }
536
537         rd_byte(&o_ptr->feeling);
538
539         /* Inscription */
540         rd_string(buf, sizeof(buf));
541
542         /* Save the inscription */
543         if (buf[0]) o_ptr->inscription = quark_add(buf);
544
545         rd_string(buf, sizeof(buf));
546         if (buf[0]) o_ptr->art_name = quark_add(buf);
547
548         /* The Python object */
549         {
550                 s32b tmp32s;
551
552                 rd_s32b(&tmp32s);
553                 strip_bytes(tmp32s);
554         }
555
556         /* Mega-Hack -- handle "dungeon objects" later */
557         if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
558
559         if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
560
561         if (z_older_than(10, 4, 9))
562         {
563                 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
564                 {
565                         remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
566                         add_flag(o_ptr->art_flags, TR_DEC_MANA);
567                 }
568         }
569
570         /* Paranoia */
571         if (object_is_fixed_artifact(o_ptr))
572         {
573                 artifact_type *a_ptr;
574
575                 /* Obtain the artifact info */
576                 a_ptr = &a_info[o_ptr->name1];
577
578                 /* Verify that artifact */
579                 if (!a_ptr->name) o_ptr->name1 = 0;
580         }
581
582         /* Paranoia */
583         if (object_is_ego(o_ptr))
584         {
585                 ego_item_type *e_ptr;
586
587                 /* Obtain the ego-item info */
588                 e_ptr = &e_info[o_ptr->name2];
589
590                 /* Verify that ego-item */
591                 if (!e_ptr->name) o_ptr->name2 = 0;
592
593         }
594 }
595
596
597 /*!
598  * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
599  * @param o_ptr アイテムオブジェクト保存先ポインタ
600  * @return なし
601  */
602 static void rd_item(object_type *o_ptr)
603 {
604         object_kind *k_ptr;
605         u32b flags;
606         char buf[128];
607         byte_hack tmp8u;
608         s16b tmp16s;
609
610         if (h_older_than(1, 5, 0, 0))
611         {
612                 rd_item_old(o_ptr);
613                 return;
614         }
615
616         /*** Item save flags ***/
617         rd_u32b(&flags);
618
619         /*** Read un-obvious elements ***/
620         /* Kind */
621         rd_s16b(&o_ptr->k_idx);
622
623         /* Location */
624         rd_byte(&tmp8u);
625         o_ptr->iy = (POSITION)tmp8u;
626         rd_byte(&tmp8u);
627         o_ptr->ix = (POSITION)tmp8u;
628
629         /* Type/Subtype */
630         k_ptr = &k_info[o_ptr->k_idx];
631         o_ptr->tval = k_ptr->tval;
632         o_ptr->sval = k_ptr->sval;
633
634         /* Special pval */
635         if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
636         else o_ptr->pval = 0;
637
638         if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
639         else o_ptr->discount = 0;
640         if (flags & SAVE_ITEM_NUMBER) {
641                 rd_byte(&tmp8u);
642                 o_ptr->number = tmp8u;
643         }       
644         else o_ptr->number = 1;
645
646         rd_s16b(&o_ptr->weight);
647
648         if (flags & SAVE_ITEM_NAME1)
649         {
650                 rd_byte(&tmp8u);
651                 o_ptr->name1 = tmp8u;
652         }
653         else o_ptr->name1 = 0;
654         if (flags & SAVE_ITEM_NAME2)
655         {
656                 rd_byte(&tmp8u);
657                 o_ptr->name2 = tmp8u;
658         }
659         else o_ptr->name2 = 0;
660         if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
661         else o_ptr->timeout = 0;
662
663         if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
664         else o_ptr->to_h = 0;
665         if (flags & SAVE_ITEM_TO_D)
666         {
667                 rd_s16b(&tmp16s);
668                 o_ptr->to_d = tmp16s;
669         }
670         else o_ptr->to_d = 0;
671         if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
672         else o_ptr->to_a = 0;
673
674         if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
675         else o_ptr->ac = 0;
676
677         if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
678         else o_ptr->dd = 0;
679         if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
680         else o_ptr->ds = 0;
681
682         if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
683         else o_ptr->ident = 0;
684
685         if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
686         else o_ptr->marked = 0;
687
688         /* Object flags */
689         if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
690         else o_ptr->art_flags[0] = 0;
691         if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
692         else o_ptr->art_flags[1] = 0;
693         if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
694         else o_ptr->art_flags[2] = 0;
695         if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
696         else o_ptr->art_flags[3] = 0;
697         if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
698         else o_ptr->art_flags[4] = 0;
699
700         if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
701         else o_ptr->curse_flags = 0;
702
703         /* Monster holding object */
704         if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
705         else o_ptr->held_m_idx = 0;
706
707         /* Special powers */
708         if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
709         else o_ptr->xtra1 = 0;
710         if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
711         else o_ptr->xtra2 = 0;
712
713         if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
714         else o_ptr->xtra3 = 0;
715
716         if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
717         else o_ptr->xtra4 = 0;
718         if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
719         else o_ptr->xtra5 = 0;
720
721         if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
722         else o_ptr->feeling = 0;
723
724         if (flags & SAVE_ITEM_INSCRIPTION)
725         {
726                 rd_string(buf, sizeof(buf));
727                 o_ptr->inscription = quark_add(buf);
728         }
729         else o_ptr->inscription = 0;
730
731         if (flags & SAVE_ITEM_ART_NAME)
732         {
733                 rd_string(buf, sizeof(buf));
734                 o_ptr->art_name = quark_add(buf);
735         }
736         else o_ptr->art_name = 0;
737         
738         if(h_older_than(2,1,2,4))
739         {
740                 u32b flgs[TR_FLAG_SIZE];
741                 object_flags(o_ptr, flgs);
742                 
743                 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
744                 {
745                         add_flag(o_ptr->art_flags, TR_LITE_M1);
746                         remove_flag(o_ptr->art_flags, TR_LITE_1);
747                         remove_flag(o_ptr->art_flags, TR_LITE_2);
748                         remove_flag(o_ptr->art_flags, TR_LITE_3);
749                 }
750                 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
751                 {
752                         if (o_ptr->tval == TV_LITE)
753                         {
754                                 if (o_ptr->sval == SV_LITE_TORCH)
755                                 {
756                                         add_flag(o_ptr->art_flags, TR_LITE_M1);
757                                 }
758                                 else if (o_ptr->sval == SV_LITE_LANTERN)
759                                 {
760                                         add_flag(o_ptr->art_flags, TR_LITE_M2);
761                                 }
762                                 else if (o_ptr->sval == SV_LITE_FEANOR)
763                                 {
764                                         add_flag(o_ptr->art_flags, TR_LITE_M3);
765                                 }
766                         }
767                         else
768                         {
769                                 /* Paranoia */
770                                 add_flag(o_ptr->art_flags, TR_LITE_M1);
771                         }
772                 }
773                 else if (o_ptr->tval == TV_LITE)
774                 {
775                         if (object_is_fixed_artifact(o_ptr))
776                         {
777                                 add_flag(o_ptr->art_flags, TR_LITE_3);
778                         }
779                         else if (o_ptr->sval == SV_LITE_TORCH)
780                         {
781                                 add_flag(o_ptr->art_flags, TR_LITE_1);
782                                 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
783                         }
784                         else if (o_ptr->sval == SV_LITE_LANTERN)
785                         {
786                                 add_flag(o_ptr->art_flags, TR_LITE_2);
787                                 add_flag(o_ptr->art_flags, TR_LITE_FUEL);       
788                         }
789                         else if (o_ptr->sval == SV_LITE_FEANOR)
790                         {
791                                 add_flag(o_ptr->art_flags, TR_LITE_2);
792                         }
793                 }
794         }
795 }
796
797
798 /*!
799  * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
800  * @param m_ptr モンスター保存先ポインタ
801  * @return なし
802  */
803 static void rd_monster_old(monster_type *m_ptr)
804 {
805         byte tmp8u;
806         s16b tmp16s;
807         char buf[128];
808
809         /* Read the monster race */
810         rd_s16b(&m_ptr->r_idx);
811
812         if (z_older_than(11, 0, 12))
813                 m_ptr->ap_r_idx = m_ptr->r_idx;
814         else
815                 rd_s16b(&m_ptr->ap_r_idx);
816
817         if (z_older_than(11, 0, 14))
818         {
819                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
820
821                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
822                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
823                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
824         }
825         else
826                 rd_byte(&m_ptr->sub_align);
827
828         /* Read the other information */
829         rd_byte(&tmp8u);
830         m_ptr->fy = (POSITION)tmp8u;
831         rd_byte(&tmp8u);
832         m_ptr->fx = (POSITION)tmp8u;
833
834         rd_s16b(&tmp16s);
835         m_ptr->hp = tmp16s;
836         rd_s16b(&tmp16s);
837         m_ptr->maxhp = tmp16s;
838
839         if (z_older_than(11, 0, 5))
840         {
841                 m_ptr->max_maxhp = m_ptr->maxhp;
842         }
843         else
844         {
845                 rd_s16b(&tmp16s);
846                 m_ptr->max_maxhp = (HIT_POINT)tmp16s;
847         }
848         if(h_older_than(2, 1, 2, 1))
849         {
850                 m_ptr->dealt_damage = 0;
851         }
852         else
853         {
854                 rd_u32b(&m_ptr->dealt_damage); 
855         }
856         
857         rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
858         rd_byte(&m_ptr->mspeed);
859         if (z_older_than(10, 4, 2))
860         {
861                 rd_byte(&tmp8u);
862                 m_ptr->energy_need = (s16b)tmp8u;
863         }
864         else rd_s16b(&m_ptr->energy_need);
865
866         if (z_older_than(11, 0, 13))
867                 m_ptr->energy_need = 100 - m_ptr->energy_need;
868
869         if (z_older_than(10,0,7))
870         {
871                 m_ptr->mtimed[MTIMED_FAST] = 0;
872                 m_ptr->mtimed[MTIMED_SLOW] = 0;
873         }
874         else
875         {
876                 rd_byte(&tmp8u);
877                 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
878                 rd_byte(&tmp8u);
879                 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
880         }
881         rd_byte(&tmp8u);
882         m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
883         rd_byte(&tmp8u);
884         m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
885         rd_byte(&tmp8u);
886         m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
887
888         if (z_older_than(10,0,10))
889         {
890                 reset_target(m_ptr);
891         }
892         else if (z_older_than(10,0,11))
893         {
894                 rd_s16b(&tmp16s);
895                 reset_target(m_ptr);
896         }
897         else
898         {
899                 rd_s16b(&tmp16s);
900                 m_ptr->target_y = (POSITION)tmp16s;
901                 rd_s16b(&tmp16s);
902                 m_ptr->target_x = (POSITION)tmp16s;
903         }
904
905         rd_byte(&tmp8u);
906         m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
907
908         if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
909                 rd_u32b(&m_ptr->smart);
910         else
911                 m_ptr->smart = 0;
912
913         if (z_older_than(10, 4, 5))
914                 m_ptr->exp = 0;
915         else
916                 rd_u32b(&m_ptr->exp);
917
918         if (z_older_than(10, 2, 2))
919         {
920                 if (m_ptr->r_idx < 0)
921                 {
922                         m_ptr->r_idx = (0-m_ptr->r_idx);
923                         m_ptr->mflag2 |= MFLAG2_KAGE;
924                 }
925         }
926         else
927         {
928                 rd_byte(&m_ptr->mflag2);
929         }
930
931         if (z_older_than(11, 0, 12))
932         {
933                 if (m_ptr->mflag2 & MFLAG2_KAGE)
934                         m_ptr->ap_r_idx = MON_KAGE;
935         }
936
937         if (z_older_than(10, 1, 3))
938         {
939                 m_ptr->nickname = 0;
940         }
941         else
942         {
943                 rd_string(buf, sizeof(buf));
944                 if (buf[0]) m_ptr->nickname = quark_add(buf);
945         }
946
947         rd_byte(&tmp8u);
948 }
949
950
951 /*!
952  * @brief モンスターを読み込む(現版) / Read a monster (New method)
953  * @param m_ptr モンスター保存先ポインタ
954  * @return なし
955  */
956 static void rd_monster(monster_type *m_ptr)
957 {
958         u32b flags;
959         char buf[128];
960         byte tmp8u;
961         s16b tmp16s;
962
963         if (h_older_than(1, 5, 0, 0))
964         {
965                 rd_monster_old(m_ptr);
966                 return;
967         }
968
969         /*** Monster save flags ***/
970         rd_u32b(&flags);
971
972         /*** Read un-obvious elements ***/
973
974         /* Read the monster race */
975         rd_s16b(&m_ptr->r_idx);
976
977         /* Read the other information */
978         rd_byte(&tmp8u);
979         m_ptr->fy = (POSITION)tmp8u;
980         rd_byte(&tmp8u);
981         m_ptr->fx = (POSITION)tmp8u;
982
983         rd_s16b(&tmp16s);
984         m_ptr->hp = (HIT_POINT)tmp16s;
985         rd_s16b(&tmp16s);
986         m_ptr->maxhp = (HIT_POINT)tmp16s;
987         rd_s16b(&tmp16s);
988         m_ptr->max_maxhp = (HIT_POINT)tmp16s;
989
990         if(h_older_than(2, 1, 2, 1))
991         {
992                 m_ptr->dealt_damage = 0;
993         }
994         else
995         {
996                 rd_u32b(&m_ptr->dealt_damage); 
997         }
998
999         /* Monster race index of its appearance */
1000         if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
1001         else m_ptr->ap_r_idx = m_ptr->r_idx;
1002
1003         if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
1004         else m_ptr->sub_align = 0;
1005
1006         if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
1007         else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
1008
1009         rd_byte(&m_ptr->mspeed);
1010
1011         rd_s16b(&m_ptr->energy_need);
1012
1013         if (flags & SAVE_MON_FAST)
1014         {
1015                 rd_byte(&tmp8u);
1016                 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
1017         }
1018         else m_ptr->mtimed[MTIMED_FAST] = 0;
1019         if (flags & SAVE_MON_SLOW)
1020         {
1021                 rd_byte(&tmp8u);
1022                 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
1023         }
1024         else m_ptr->mtimed[MTIMED_SLOW] = 0;
1025         if (flags & SAVE_MON_STUNNED)
1026         {
1027                 rd_byte(&tmp8u);
1028                 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
1029         }
1030         else m_ptr->mtimed[MTIMED_STUNNED] = 0;
1031         if (flags & SAVE_MON_CONFUSED)
1032         {
1033                 rd_byte(&tmp8u);
1034                 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
1035         }
1036         else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
1037         if (flags & SAVE_MON_MONFEAR)
1038         {
1039                 rd_byte(&tmp8u);
1040                 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
1041         }
1042         else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
1043
1044         if (flags & SAVE_MON_TARGET_Y)
1045         {
1046                 rd_s16b(&tmp16s);
1047                 m_ptr->target_y = (POSITION)tmp16s;
1048         }
1049         else m_ptr->target_y = 0;
1050         if (flags & SAVE_MON_TARGET_X)
1051         {
1052                 rd_s16b(&tmp16s);
1053                 m_ptr->target_x = (POSITION)tmp16s;
1054         }
1055         else m_ptr->target_x = 0;
1056
1057         if (flags & SAVE_MON_INVULNER)
1058         {
1059                 rd_byte(&tmp8u);
1060                 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
1061         }
1062         else m_ptr->mtimed[MTIMED_INVULNER] = 0;
1063
1064         if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
1065         else m_ptr->smart = 0;
1066
1067         if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
1068         else m_ptr->exp = 0;
1069
1070         m_ptr->mflag = 0; /* Not saved */
1071
1072         if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
1073         else m_ptr->mflag2 = 0;
1074
1075         if (flags & SAVE_MON_NICKNAME) 
1076         {
1077                 rd_string(buf, sizeof(buf));
1078                 m_ptr->nickname = quark_add(buf);
1079         }
1080         else m_ptr->nickname = 0;
1081
1082         if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
1083         else m_ptr->parent_m_idx = 0;
1084 }
1085
1086
1087 /*
1088  * Old monster bit flags of racial resistances
1089  */
1090 #define RF3_IM_ACID         0x00010000  /* Resist acid a lot */
1091 #define RF3_IM_ELEC         0x00020000  /* Resist elec a lot */
1092 #define RF3_IM_FIRE         0x00040000  /* Resist fire a lot */
1093 #define RF3_IM_COLD         0x00080000  /* Resist cold a lot */
1094 #define RF3_IM_POIS         0x00100000  /* Resist poison a lot */
1095 #define RF3_RES_TELE        0x00200000  /* Resist teleportation */
1096 #define RF3_RES_NETH        0x00400000  /* Resist nether a lot */
1097 #define RF3_RES_WATE        0x00800000  /* Resist water */
1098 #define RF3_RES_PLAS        0x01000000  /* Resist plasma */
1099 #define RF3_RES_NEXU        0x02000000  /* Resist nexus */
1100 #define RF3_RES_DISE        0x04000000  /* Resist disenchantment */
1101 #define RF3_RES_ALL         0x08000000  /* Resist all */
1102
1103 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1104 {\
1105         if ((R_PTR)->r_flags3 & (RF3)) \
1106         { \
1107                 (R_PTR)->r_flags3 &= ~(RF3); \
1108                 (R_PTR)->r_flagsr |= (RFR); \
1109         } \
1110 }
1111
1112 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1113 {\
1114         if ((R_PTR)->r_flags4 & (RF4_BR)) \
1115         { \
1116                 (R_PTR)->r_flagsr |= (RFR); \
1117         } \
1118 }
1119
1120 #define RF4_BR_LITE         0x00004000  /* Breathe Lite */
1121 #define RF4_BR_DARK         0x00008000  /* Breathe Dark */
1122 #define RF4_BR_CONF         0x00010000  /* Breathe Confusion */
1123 #define RF4_BR_SOUN         0x00020000  /* Breathe Sound */
1124 #define RF4_BR_CHAO         0x00040000  /* Breathe Chaos */
1125 #define RF4_BR_TIME         0x00200000  /* Breathe Time */
1126 #define RF4_BR_INER         0x00400000  /* Breathe Inertia */
1127 #define RF4_BR_GRAV         0x00800000  /* Breathe Gravity */
1128 #define RF4_BR_SHAR         0x01000000  /* Breathe Shards */
1129 #define RF4_BR_WALL         0x04000000  /* Breathe Force */
1130
1131 /*!
1132  * @brief モンスターの思い出を読み込む / Read the monster lore
1133  * @param r_idx 読み込み先モンスターID
1134  * @return なし
1135  */
1136 static void rd_lore(int r_idx)
1137 {
1138         byte tmp8u;
1139
1140         monster_race *r_ptr = &r_info[r_idx];
1141
1142         /* Count sights/deaths/kills */
1143         rd_s16b(&r_ptr->r_sights);
1144         rd_s16b(&r_ptr->r_deaths);
1145         rd_s16b(&r_ptr->r_pkills);
1146         if (h_older_than(1, 7, 0, 5))
1147         {
1148                 r_ptr->r_akills = r_ptr->r_pkills;
1149         }
1150         else
1151         {
1152                 rd_s16b(&r_ptr->r_akills);
1153         }
1154         rd_s16b(&r_ptr->r_tkills);
1155
1156         /* Count wakes and ignores */
1157         rd_byte(&r_ptr->r_wake);
1158         rd_byte(&r_ptr->r_ignore);
1159
1160         /* Extra stuff */
1161         rd_byte(&r_ptr->r_xtra1);
1162         rd_byte(&r_ptr->r_xtra2);
1163
1164         /* Count drops */
1165         rd_byte(&r_ptr->r_drop_gold);
1166         rd_byte(&r_ptr->r_drop_item);
1167
1168         /* Count spells */
1169         rd_byte(&tmp8u);
1170         rd_byte(&r_ptr->r_cast_spell);
1171
1172         /* Count blows of each type */
1173         rd_byte(&r_ptr->r_blows[0]);
1174         rd_byte(&r_ptr->r_blows[1]);
1175         rd_byte(&r_ptr->r_blows[2]);
1176         rd_byte(&r_ptr->r_blows[3]);
1177
1178         /* Memorize flags */
1179         rd_u32b(&r_ptr->r_flags1);
1180         rd_u32b(&r_ptr->r_flags2);
1181         rd_u32b(&r_ptr->r_flags3);
1182         rd_u32b(&r_ptr->r_flags4);
1183         rd_u32b(&r_ptr->r_flags5);
1184         rd_u32b(&r_ptr->r_flags6);
1185         if (h_older_than(1, 5, 0, 3))
1186         {
1187                 r_ptr->r_flagsr = 0L;
1188
1189                 /* Move RF3 resistance flags to RFR */
1190                 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID,  RFR_IM_ACID);
1191                 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC,  RFR_IM_ELEC);
1192                 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE,  RFR_IM_FIRE);
1193                 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD,  RFR_IM_COLD);
1194                 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS,  RFR_IM_POIS);
1195                 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1196                 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1197                 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1198                 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1199                 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1200                 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1201                 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL,  RFR_RES_ALL);
1202
1203                 /* Separate breathers resistance from RF4 to RFR */
1204                 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1205                 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1206                 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1207                 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1208                 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1209                 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1210                 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1211                 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1212                 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1213
1214                 /* Resist confusion is merged to RF3_NO_CONF */
1215                 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1216
1217                 /* Misc resistance hack to RFR */
1218                 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1219                 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1220         }
1221         else
1222         {
1223                 rd_u32b(&r_ptr->r_flagsr);
1224         }
1225
1226         /* Read the "Racial" monster limit per level */
1227         rd_byte(&r_ptr->max_num);
1228
1229         /* Location in saved floor */
1230         rd_s16b(&r_ptr->floor_id);
1231
1232         /* Later (?) */
1233         rd_byte(&tmp8u);
1234
1235         /* Repair the lore flags */
1236         r_ptr->r_flags1 &= r_ptr->flags1;
1237         r_ptr->r_flags2 &= r_ptr->flags2;
1238         r_ptr->r_flags3 &= r_ptr->flags3;
1239         r_ptr->r_flags4 &= r_ptr->flags4;
1240         r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
1241         r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
1242         r_ptr->r_flagsr &= r_ptr->flagsr;
1243 }
1244
1245 /*!
1246  * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
1247  * @param st_ptr 店舗の参照ポインタ
1248  * @param o_ptr アイテムオブジェクト参照ポインタ
1249  * @return なし
1250  * @details
1251  * In all cases, return the slot (or -1) where the object was placed
1252  *
1253  * Note that this is a hacked up version of "inven_carry()".
1254  *
1255  * Also note that it may not correctly "adapt" to "knowledge" bacoming
1256  * known, the player may have to pick stuff up and drop it again.
1257  */
1258 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1259 {
1260         int                             slot;
1261         s32b                       value;
1262         int     i;
1263         object_type *j_ptr;
1264
1265
1266         /* Check each existing item (try to combine) */
1267         for (slot = 0; slot < st_ptr->stock_num; slot++)
1268         {
1269                 /* Get the existing item */
1270                 j_ptr = &st_ptr->stock[slot];
1271
1272                 /* The home acts just like the player */
1273                 if (object_similar(j_ptr, o_ptr))
1274                 {
1275                         /* Save the new number of items */
1276                         object_absorb(j_ptr, o_ptr);
1277
1278                         /* All done */
1279                         return;
1280                 }
1281         }
1282
1283         /* No space? */
1284         if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1285                 return;
1286         }
1287
1288         /* Determine the "value" of the item */
1289         value = object_value(o_ptr);
1290
1291         /* Check existing slots to see if we must "slide" */
1292         for (slot = 0; slot < st_ptr->stock_num; slot++)
1293         {
1294                 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1295         }
1296
1297         /* Slide the others up */
1298         for (i = st_ptr->stock_num; i > slot; i--)
1299         {
1300                 st_ptr->stock[i] = st_ptr->stock[i-1];
1301         }
1302
1303         /* More stuff now */
1304         st_ptr->stock_num++;
1305
1306         /* Insert the new item */
1307         st_ptr->stock[slot] = *o_ptr;
1308
1309         chg_virtue(V_SACRIFICE, -1);
1310
1311         /* Return the location */
1312         return;
1313 }
1314
1315 /*!
1316  * @brief 店舗情報を読み込む / Read a store
1317  * @param town_number 街ID 
1318  * @param store_number 店舗ID
1319  * @return エラーID
1320  */
1321 static errr rd_store(int town_number, int store_number)
1322 {
1323         store_type *st_ptr;
1324
1325         int j;
1326
1327         byte own;
1328         byte tmp8u;
1329         s16b num;
1330
1331         bool sort = FALSE;
1332
1333         if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1334         {
1335                 st_ptr = &town[1].store[store_number];
1336                 if (st_ptr->stock_num) sort = TRUE;
1337         }
1338         else
1339         {
1340                 st_ptr = &town[town_number].store[store_number];
1341         }
1342
1343         /* Read the basic info */
1344         rd_s32b(&st_ptr->store_open);
1345         rd_s16b(&st_ptr->insult_cur);
1346         rd_byte(&own);
1347         if (z_older_than(11, 0, 4))
1348         {
1349                 rd_byte(&tmp8u);
1350                 num = tmp8u;
1351         }
1352         else
1353         {
1354                 rd_s16b(&num);
1355         }
1356         rd_s16b(&st_ptr->good_buy);
1357         rd_s16b(&st_ptr->bad_buy);
1358
1359         /* Read last visit */
1360         rd_s32b(&st_ptr->last_visit);
1361
1362         /* Extract the owner (see above) */
1363         st_ptr->owner = own;
1364
1365         /* Read the items */
1366         for (j = 0; j < num; j++)
1367         {
1368                 object_type forge;
1369                 object_type *q_ptr;
1370
1371                 /* Get local object */
1372                 q_ptr = &forge;
1373
1374                 /* Wipe the object */
1375                 object_wipe(q_ptr);
1376
1377                 /* Read the item */
1378                 rd_item(q_ptr);
1379
1380                 /* Acquire valid items */
1381                 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1382                 {
1383                         int k;
1384                         if (sort)
1385                         {
1386                                 home_carry(st_ptr, q_ptr);
1387                         }
1388                         else
1389                         {
1390                                 k = st_ptr->stock_num++;
1391
1392                                 /* Acquire the item */
1393                                 object_copy(&st_ptr->stock[k], q_ptr);
1394                         }
1395                 }
1396         }
1397
1398         /* Success */
1399         return (0);
1400 }
1401
1402
1403 /*!
1404  * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
1405  * @return なし
1406  */
1407 static void rd_randomizer(void)
1408 {
1409         int i;
1410
1411         u16b tmp16u;
1412
1413         /* Tmp */
1414         rd_u16b(&tmp16u);
1415
1416         /* Place */
1417         rd_u16b(&Rand_place);
1418
1419         /* State */
1420         for (i = 0; i < RAND_DEG; i++)
1421         {
1422                 rd_u32b(&Rand_state[i]);
1423         }
1424 }
1425
1426
1427
1428 /*!
1429  * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
1430  * @return なし
1431  * @details
1432  * Note that the normal options are now stored as a set of 256 bit flags,
1433  * plus a set of 256 bit masks to indicate which bit flags were defined
1434  * at the time the savefile was created.  This will allow new options
1435  * to be added, and old options to be removed, at any time, without
1436  * hurting old savefiles.
1437  *
1438  * The window options are stored in the same way, but note that each
1439  * window gets 32 options, and their order is fixed by certain defines.
1440  */
1441 static void rd_options(void)
1442 {
1443         int i, n;
1444
1445         byte b;
1446
1447         u16b c;
1448
1449         u32b flag[8];
1450         u32b mask[8];
1451
1452
1453         /*** Oops ***/
1454
1455         /* Ignore old options */
1456         strip_bytes(16);
1457
1458
1459         /*** Special info */
1460
1461         /* Read "delay_factor" */
1462         rd_byte(&b);
1463         delay_factor = b;
1464
1465         /* Read "hitpoint_warn" */
1466         rd_byte(&b);
1467         hitpoint_warn = b;
1468
1469         /* Read "mana_warn" */
1470         if(h_older_than(1, 7, 0, 0))
1471         {
1472                 mana_warn=2;
1473         }
1474         else 
1475         {
1476                 rd_byte(&b);
1477                 mana_warn = b;
1478         }
1479
1480
1481         /*** Cheating options ***/
1482
1483         rd_u16b(&c);
1484
1485         if (c & 0x0002) p_ptr->wizard = TRUE;
1486
1487         cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1488         cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1489         cheat_room = (c & 0x0400) ? TRUE : FALSE;
1490         cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1491         cheat_know = (c & 0x1000) ? TRUE : FALSE;
1492         cheat_live = (c & 0x2000) ? TRUE : FALSE;
1493         cheat_save = (c & 0x4000) ? TRUE : FALSE;
1494         cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
1495         cheat_turn = (c & 0x0080) ? TRUE : FALSE;
1496
1497         rd_byte((byte *)&autosave_l);
1498         rd_byte((byte *)&autosave_t);
1499         rd_s16b(&autosave_freq);
1500
1501
1502         /*** Normal Options ***/
1503
1504         /* Read the option flags */
1505         for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1506
1507         /* Read the option masks */
1508         for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1509
1510         /* Analyze the options */
1511         for (n = 0; n < 8; n++)
1512         {
1513                 /* Analyze the options */
1514                 for (i = 0; i < 32; i++)
1515                 {
1516                         /* Process valid flags */
1517                         if (mask[n] & (1L << i))
1518                         {
1519                                 /* Process valid flags */
1520                                 if (option_mask[n] & (1L << i))
1521                                 {
1522                                         /* Set */
1523                                         if (flag[n] & (1L << i))
1524                                         {
1525                                                 /* Set */
1526                                                 option_flag[n] |= (1L << i);
1527                                         }
1528
1529                                         /* Clear */
1530                                         else
1531                                         {
1532                                                 /* Clear */
1533                                                 option_flag[n] &= ~(1L << i);
1534                                         }
1535                                 }
1536                         }
1537                 }
1538         }
1539
1540         if (z_older_than(10, 4, 5))
1541         {
1542                 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1543                 else option_flag[5] |= (0x00000001 << 4);
1544                 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1545                 else option_flag[2] |= (0x00000001 << 5);
1546                 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1547                 else option_flag[4] |= (0x00000001 << 5);
1548                 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1549                 else option_flag[5] |= (0x00000001 << 0);
1550                 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1551                 else option_flag[5] |= (0x00000001 << 12);
1552                 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1553                 else option_flag[1] |= (0x00000001 << 0);
1554                 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1555                 else option_flag[1] |= (0x00000001 << 18);
1556                 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1557                 else option_flag[1] |= (0x00000001 << 19);
1558                 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1559                 else option_flag[5] |= (0x00000001 << 3);
1560         }
1561
1562         /* Extract the options */
1563         extract_option_vars();
1564
1565
1566         /*** Window Options ***/
1567
1568         /* Read the window flags */
1569         for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1570
1571         /* Read the window masks */
1572         for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1573
1574         /* Analyze the options */
1575         for (n = 0; n < 8; n++)
1576         {
1577                 /* Analyze the options */
1578                 for (i = 0; i < 32; i++)
1579                 {
1580                         /* Process valid flags */
1581                         if (mask[n] & (1L << i))
1582                         {
1583                                 /* Process valid flags */
1584                                 if (window_mask[n] & (1L << i))
1585                                 {
1586                                         /* Set */
1587                                         if (flag[n] & (1L << i))
1588                                         {
1589                                                 /* Set */
1590                                                 window_flag[n] |= (1L << i);
1591                                         }
1592
1593                                         /* Clear */
1594                                         else
1595                                         {
1596                                                 /* Clear */
1597                                                 window_flag[n] &= ~(1L << i);
1598                                         }
1599                                 }
1600                         }
1601                 }
1602         }
1603 }
1604
1605
1606
1607 /*!
1608  * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
1609  * @return なし
1610  * @details
1611  * XXX XXX XXX This is such a nasty hack it hurts.
1612  */
1613 static void rd_ghost(void)
1614 {
1615         char buf[64];
1616
1617         /* Strip name */
1618         rd_string(buf, sizeof(buf));
1619
1620         /* Strip old data */
1621         strip_bytes(60);
1622 }
1623
1624
1625 /*!
1626  * @brief クイックスタート情報を読み込む / Load quick start data
1627  * @return なし
1628  */
1629 static void load_quick_start(void)
1630 {
1631         byte tmp8u;
1632         int i;
1633
1634         if (z_older_than(11, 0, 13))
1635         {
1636                 previous_char.quick_ok = FALSE;
1637                 return;
1638         }
1639
1640         rd_byte(&previous_char.psex);
1641         rd_byte(&previous_char.prace);
1642         rd_byte(&previous_char.pclass);
1643         rd_byte(&previous_char.pseikaku);
1644         rd_byte(&previous_char.realm1);
1645         rd_byte(&previous_char.realm2);
1646
1647         rd_s16b(&previous_char.age);
1648         rd_s16b(&previous_char.ht);
1649         rd_s16b(&previous_char.wt);
1650         rd_s16b(&previous_char.sc);
1651         rd_s32b(&previous_char.au);
1652
1653         for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1654         for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1655
1656         for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1657
1658         rd_s16b(&previous_char.chaos_patron);
1659
1660         for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1661
1662         for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1663
1664         /* UNUSED : Was number of random quests */
1665         rd_byte(&tmp8u);
1666
1667         rd_byte(&tmp8u);
1668         previous_char.quick_ok = (bool)tmp8u;
1669 }
1670
1671 /*!
1672  * @brief その他の情報を読み込む / Read the "extra" information
1673  * @return なし
1674  */
1675 static void rd_extra(void)
1676 {
1677         int i,j;
1678
1679         byte tmp8u;
1680         s16b tmp16s;
1681         u16b tmp16u;
1682
1683         rd_string(p_ptr->name, sizeof(p_ptr->name));
1684
1685         rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1686
1687         if (!h_older_than(1, 7, 0, 1))
1688         {
1689                 char buf[1024];
1690
1691                 /* Read the message */
1692                 rd_string(buf, sizeof buf);
1693                 if (buf[0]) p_ptr->last_message = string_make(buf);
1694         }
1695
1696         load_quick_start();
1697
1698         for (i = 0; i < 4; i++)
1699         {
1700                 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1701         }
1702
1703         /* Class/Race/Seikaku/Gender/Spells */
1704         rd_byte(&p_ptr->prace);
1705         rd_byte(&p_ptr->pclass);
1706         rd_byte(&p_ptr->pseikaku);
1707         rd_byte(&p_ptr->psex);
1708         rd_byte(&p_ptr->realm1);
1709         rd_byte(&p_ptr->realm2);
1710         rd_byte(&tmp8u); /* oops */
1711
1712         if (z_older_than(10, 4, 4))
1713         {
1714                 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1715                 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1716                 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1717                 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1718         }
1719
1720         /* Special Race/Class info */
1721         rd_byte(&tmp8u);
1722         p_ptr->hitdie = tmp8u;
1723         rd_u16b(&p_ptr->expfact);
1724
1725         /* Age/Height/Weight */
1726         rd_s16b(&p_ptr->age);
1727         rd_s16b(&p_ptr->ht);
1728         rd_s16b(&p_ptr->wt);
1729
1730         /* Read the stat info */
1731         for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1732         for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1733         for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1734
1735         strip_bytes(24); /* oops */
1736
1737         rd_s32b(&p_ptr->au);
1738
1739         rd_s32b(&p_ptr->max_exp);
1740         if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1741         else rd_s32b(&p_ptr->max_max_exp);
1742         rd_s32b(&p_ptr->exp);
1743
1744         if (h_older_than(1, 7, 0, 3))
1745         {
1746                 rd_u16b(&tmp16u);
1747                 p_ptr->exp_frac = (u32b)tmp16u;
1748         }
1749         else
1750         {
1751                 rd_u32b(&p_ptr->exp_frac);
1752         }
1753
1754         rd_s16b(&p_ptr->lev);
1755
1756         for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1757         if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1758         {
1759                 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1760         }
1761         if (z_older_than(10, 3, 6))
1762                 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1763         else
1764                 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1765         for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
1766         if (z_older_than(10, 4, 1))
1767         {
1768                 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1769                 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1770         }
1771         if (z_older_than(10, 3, 14))
1772         {
1773                 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1774                 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1775         }
1776         else
1777         {
1778                 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1779                 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1780                 if (h_older_than(1, 3, 0, 1))
1781                 {
1782                         if (p_ptr->pclass == CLASS_SMITH)
1783                         {
1784                                 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1785                                 p_ptr->magic_num1[96] = 0;
1786                                 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1787                                 p_ptr->magic_num1[97] = 0;
1788                         }
1789                 }
1790         }
1791         if (music_singing_any()) p_ptr->action = ACTION_SING;
1792
1793         if (z_older_than(11, 0, 7))
1794         {
1795                 p_ptr->start_race = p_ptr->prace;
1796                 p_ptr->old_race1 = 0L;
1797                 p_ptr->old_race2 = 0L;
1798                 p_ptr->old_realm = 0;
1799         }
1800         else
1801         {
1802                 rd_byte(&p_ptr->start_race);
1803                 rd_s32b(&p_ptr->old_race1);
1804                 rd_s32b(&p_ptr->old_race2);
1805                 rd_s16b(&p_ptr->old_realm);
1806         }
1807
1808         if (z_older_than(10, 0, 1))
1809         {
1810                 for (i = 0; i < MAX_MANE; i++)
1811                 {
1812                         p_ptr->mane_spell[i] = -1;
1813                         p_ptr->mane_dam[i] = 0;
1814                 }
1815                 p_ptr->mane_num = 0;
1816         }
1817         else if (z_older_than(10, 2, 3))
1818         {
1819                 for (i = 0; i < OLD_MAX_MANE; i++)
1820                 {
1821                         rd_s16b(&tmp16s);
1822                         rd_s16b(&tmp16s);
1823                 }
1824                 for (i = 0; i < MAX_MANE; i++)
1825                 {
1826                         p_ptr->mane_spell[i] = -1;
1827                         p_ptr->mane_dam[i] = 0;
1828                 }
1829                 rd_s16b(&tmp16s);
1830                 p_ptr->mane_num = 0;
1831         }
1832         else
1833         {
1834                 for (i = 0; i < MAX_MANE; i++)
1835                 {
1836                         rd_s16b(&p_ptr->mane_spell[i]);
1837                         rd_s16b(&p_ptr->mane_dam[i]);
1838                 }
1839                 rd_s16b(&p_ptr->mane_num);
1840         }
1841
1842         if (z_older_than(10, 0, 3))
1843         {
1844                 determine_bounty_uniques();
1845
1846                 for (i = 0; i < MAX_KUBI; i++)
1847                 {
1848                         /* Is this bounty unique already dead? */
1849                         if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1850                 }
1851         }
1852         else
1853         {
1854                 for (i = 0; i < MAX_KUBI; i++)
1855                 {
1856                         rd_s16b(&kubi_r_idx[i]);
1857                 }
1858         }
1859
1860         if (z_older_than(10, 0, 3))
1861         {
1862                 battle_monsters();
1863         }
1864         else
1865         {
1866                 for (i = 0; i < 4; i++)
1867                 {
1868                         rd_s16b(&battle_mon[i]);
1869                         if (z_older_than(10, 3, 4))
1870                         {
1871                                 rd_s16b(&tmp16s);
1872                                 mon_odds[i] = tmp16s;
1873                         }
1874                         else rd_u32b(&mon_odds[i]);
1875                 }
1876         }
1877
1878         rd_s16b(&p_ptr->town_num);
1879
1880         /* Read arena and rewards information */
1881         rd_s16b(&p_ptr->arena_number);
1882         if (h_older_than(1, 5, 0, 1))
1883         {
1884                 /* Arena loser of previous version was marked number 99 */
1885                 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1886         }
1887         rd_s16b(&tmp16s);
1888         p_ptr->inside_arena = (bool)tmp16s;
1889         rd_s16b(&p_ptr->inside_quest);
1890         if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1891         else
1892         {
1893                 rd_s16b(&tmp16s);
1894                 p_ptr->inside_battle = (bool)tmp16s;
1895         }
1896         rd_byte(&p_ptr->exit_bldg);
1897         rd_byte(&tmp8u);
1898
1899         rd_s16b(&tmp16s);
1900         p_ptr->oldpx = (POSITION)tmp16s;
1901         rd_s16b(&tmp16s);
1902         p_ptr->oldpy = (POSITION)tmp16s;
1903
1904         if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1905
1906         /* Was p_ptr->rewards[MAX_BACT] */
1907         rd_s16b(&tmp16s);
1908         for (i = 0; i < tmp16s; i++)
1909         {
1910                 s16b tmp16s2;
1911                 rd_s16b(&tmp16s2);
1912         }
1913
1914         if (h_older_than(1, 7, 0, 3))
1915         {
1916                 rd_s16b(&tmp16s);
1917                 p_ptr->mhp = tmp16s;
1918
1919                 rd_s16b(&tmp16s);
1920                 p_ptr->chp = tmp16s;
1921
1922                 rd_u16b(&tmp16u);
1923                 p_ptr->chp_frac = (u32b)tmp16u;
1924         }
1925         else
1926         {
1927                 rd_s32b(&p_ptr->mhp);
1928                 rd_s32b(&p_ptr->chp);
1929                 rd_u32b(&p_ptr->chp_frac);
1930         }
1931
1932         if (h_older_than(1, 7, 0, 3))
1933         {
1934                 rd_s16b(&tmp16s);
1935                 p_ptr->msp = tmp16s;
1936
1937                 rd_s16b(&tmp16s);
1938                 p_ptr->csp = tmp16s;
1939
1940                 rd_u16b(&tmp16u);
1941                 p_ptr->csp_frac = (u32b)tmp16u;
1942         }
1943         else
1944         {
1945                 rd_s32b(&p_ptr->msp);
1946                 rd_s32b(&p_ptr->csp);
1947                 rd_u32b(&p_ptr->csp_frac);
1948         }
1949
1950         rd_s16b(&p_ptr->max_plv);
1951         if (z_older_than(10, 3, 8))
1952         {
1953                 rd_s16b(&tmp16s);
1954                 max_dlv[DUNGEON_ANGBAND] = tmp16s;
1955         }
1956         else
1957         {
1958                 byte max = (byte)max_d_idx;
1959
1960                 rd_byte(&max);
1961
1962                 for(i = 0; i < max; i++)
1963                 {
1964                         rd_s16b(&tmp16s);
1965                         max_dlv[i] = tmp16s;
1966                         if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1967                 }
1968         }
1969
1970         /* Repair maximum player level XXX XXX XXX */
1971         if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1972
1973         /* More info */
1974         strip_bytes(8);
1975         rd_s16b(&p_ptr->sc);
1976         rd_s16b(&p_ptr->concent);
1977
1978         /* Read the flags */
1979         strip_bytes(2); /* Old "rest" */
1980         rd_s16b(&p_ptr->blind);
1981         rd_s16b(&p_ptr->paralyzed);
1982         rd_s16b(&p_ptr->confused);
1983         rd_s16b(&p_ptr->food);
1984         strip_bytes(4); /* Old "food_digested" / "protection" */
1985
1986         rd_s16b(&p_ptr->energy_need);
1987         if (z_older_than(11, 0, 13))
1988                 p_ptr->energy_need = 100 - p_ptr->energy_need;
1989         if (h_older_than(2, 1, 2, 0))
1990                 p_ptr->enchant_energy_need = 0;
1991         else
1992                 rd_s16b(&p_ptr->enchant_energy_need);
1993
1994         rd_s16b(&p_ptr->fast);
1995         rd_s16b(&p_ptr->slow);
1996         rd_s16b(&p_ptr->afraid);
1997         rd_s16b(&p_ptr->cut);
1998         rd_s16b(&p_ptr->stun);
1999         rd_s16b(&p_ptr->poisoned);
2000         rd_s16b(&p_ptr->image);
2001         rd_s16b(&p_ptr->protevil);
2002         rd_s16b(&p_ptr->invuln);
2003         if(z_older_than(10, 0, 0))
2004                 p_ptr->ult_res = 0;
2005         else
2006                 rd_s16b(&p_ptr->ult_res);
2007         rd_s16b(&p_ptr->hero);
2008         rd_s16b(&p_ptr->shero);
2009         rd_s16b(&p_ptr->shield);
2010         rd_s16b(&p_ptr->blessed);
2011         rd_s16b(&p_ptr->tim_invis);
2012         rd_s16b(&p_ptr->word_recall);
2013         if (z_older_than(10, 3, 8))
2014                 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
2015         else
2016         {
2017                 rd_s16b(&tmp16s);
2018                 p_ptr->recall_dungeon = (byte)tmp16s;
2019         }
2020
2021         if (h_older_than(1, 5, 0, 0))
2022                 p_ptr->alter_reality = 0;
2023         else
2024                 rd_s16b(&p_ptr->alter_reality);
2025
2026         rd_s16b(&p_ptr->see_infra);
2027         rd_s16b(&p_ptr->tim_infra);
2028         rd_s16b(&p_ptr->oppose_fire);
2029         rd_s16b(&p_ptr->oppose_cold);
2030         rd_s16b(&p_ptr->oppose_acid);
2031         rd_s16b(&p_ptr->oppose_elec);
2032         rd_s16b(&p_ptr->oppose_pois);
2033         if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
2034         else rd_s16b(&p_ptr->tsuyoshi);
2035
2036         /* Old savefiles do not have the following fields... */
2037         if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
2038         {
2039                 p_ptr->tim_esp = 0;
2040                 p_ptr->wraith_form = 0;
2041                 p_ptr->resist_magic = 0;
2042                 p_ptr->tim_regen = 0;
2043                 p_ptr->kabenuke = 0;
2044                 p_ptr->tim_stealth = 0;
2045                 p_ptr->tim_levitation = 0;
2046                 p_ptr->tim_sh_touki = 0;
2047                 p_ptr->lightspeed = 0;
2048                 p_ptr->tsubureru = 0;
2049                 p_ptr->tim_res_nether = 0;
2050                 p_ptr->tim_res_time = 0;
2051                 p_ptr->mimic_form = 0;
2052                 p_ptr->tim_mimic = 0;
2053                 p_ptr->tim_sh_fire = 0;
2054
2055                 /* by henkma */
2056                 p_ptr->tim_reflect = 0;
2057                 p_ptr->multishadow = 0;
2058                 p_ptr->dustrobe = 0;
2059
2060                 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
2061                 p_ptr->muta1 = 0;
2062                 p_ptr->muta2 = 0;
2063                 p_ptr->muta3 = 0;
2064                 get_virtues();
2065         }
2066         else
2067         {
2068                 rd_s16b(&p_ptr->tim_esp);
2069                 rd_s16b(&p_ptr->wraith_form);
2070                 rd_s16b(&p_ptr->resist_magic);
2071                 rd_s16b(&p_ptr->tim_regen);
2072                 rd_s16b(&p_ptr->kabenuke);
2073                 rd_s16b(&p_ptr->tim_stealth);
2074                 rd_s16b(&p_ptr->tim_levitation);
2075                 rd_s16b(&p_ptr->tim_sh_touki);
2076                 rd_s16b(&p_ptr->lightspeed);
2077                 rd_s16b(&p_ptr->tsubureru);
2078                 if (z_older_than(10, 4, 7))
2079                         p_ptr->magicdef = 0;
2080                 else
2081                         rd_s16b(&p_ptr->magicdef);
2082                 rd_s16b(&p_ptr->tim_res_nether);
2083                 if (z_older_than(10, 4, 11))
2084                 {
2085                         p_ptr->tim_res_time = 0;
2086                         p_ptr->mimic_form = 0;
2087                         p_ptr->tim_mimic = 0;
2088                         p_ptr->tim_sh_fire = 0;
2089                 }
2090                 else
2091                 {
2092                         rd_s16b(&p_ptr->tim_res_time);
2093                         rd_byte(&p_ptr->mimic_form);
2094                         rd_s16b(&p_ptr->tim_mimic);
2095                         rd_s16b(&p_ptr->tim_sh_fire);
2096                 }
2097
2098                 if (z_older_than(11, 0, 99))
2099                 {
2100                         p_ptr->tim_sh_holy = 0;
2101                         p_ptr->tim_eyeeye = 0;
2102                 }
2103                 else
2104                 {
2105                         rd_s16b(&p_ptr->tim_sh_holy);
2106                         rd_s16b(&p_ptr->tim_eyeeye);
2107                 }
2108
2109                 /* by henkma */
2110                 if ( z_older_than(11,0,3) ){
2111                   p_ptr->tim_reflect=0;
2112                   p_ptr->multishadow=0;
2113                   p_ptr->dustrobe=0;
2114                 }
2115                 else {
2116                   rd_s16b(&p_ptr->tim_reflect);
2117                   rd_s16b(&p_ptr->multishadow);
2118                   rd_s16b(&p_ptr->dustrobe);
2119                 }
2120
2121                 rd_s16b(&p_ptr->chaos_patron);
2122                 rd_u32b(&p_ptr->muta1);
2123                 rd_u32b(&p_ptr->muta2);
2124                 rd_u32b(&p_ptr->muta3);
2125
2126                 for (i = 0; i < 8; i++)
2127                         rd_s16b(&p_ptr->virtues[i]);
2128                 for (i = 0; i < 8; i++)
2129                         rd_s16b(&p_ptr->vir_types[i]);
2130         }
2131
2132         /* Calc the regeneration modifier for mutations */
2133         mutant_regenerate_mod = calc_mutant_regenerate_mod();
2134
2135         if (z_older_than(10,0,9))
2136         {
2137                 rd_byte(&tmp8u);
2138                 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2139                 p_ptr->ele_attack = 0;
2140         }
2141         else
2142         {
2143                 rd_s16b(&p_ptr->ele_attack);
2144                 rd_u32b(&p_ptr->special_attack);
2145         }
2146         if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2147         else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2148         if (z_older_than(10,0,12))
2149         {
2150                 p_ptr->ele_immune = 0;
2151                 p_ptr->special_defense = 0;
2152         }
2153         else
2154         {
2155                 rd_s16b(&p_ptr->ele_immune);
2156                 rd_u32b(&p_ptr->special_defense);
2157         }
2158         rd_byte(&p_ptr->knowledge);
2159
2160         rd_byte(&tmp8u);
2161         p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2162
2163         rd_byte(&tmp8u); /* oops */
2164         rd_byte(&p_ptr->action);
2165         if (!z_older_than(10, 4, 3))
2166         {
2167                 rd_byte(&tmp8u);
2168                 if (tmp8u) p_ptr->action = ACTION_LEARN;
2169         }
2170         rd_byte((byte *)&preserve_mode);
2171         rd_byte((byte *)&p_ptr->wait_report_score);
2172
2173         /* Future use */
2174         for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2175
2176         /* Skip the flags */
2177         strip_bytes(12);
2178
2179
2180         /* Hack -- the two "special seeds" */
2181         rd_u32b(&seed_flavor);
2182         rd_u32b(&seed_town);
2183
2184
2185         /* Special stuff */
2186         rd_u16b(&p_ptr->panic_save);
2187         rd_u16b(&p_ptr->total_winner);
2188         rd_u16b(&p_ptr->noscore);
2189
2190
2191         /* Read "death" */
2192         rd_byte(&tmp8u);
2193         p_ptr->is_dead = tmp8u;
2194
2195         /* Read "feeling" */
2196         rd_byte(&p_ptr->feeling);
2197
2198         switch (p_ptr->start_race)
2199         {
2200         case RACE_VAMPIRE:
2201         case RACE_SKELETON:
2202         case RACE_ZOMBIE:
2203         case RACE_SPECTRE:
2204                 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2205                 break;
2206         default:
2207                 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2208                 break;
2209         }
2210         dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2211
2212         /* Turn when level began */
2213         rd_s32b(&old_turn);
2214
2215         if (h_older_than(1, 7, 0, 4))
2216         {
2217                 p_ptr->feeling_turn = old_turn;
2218         }
2219         else
2220         {
2221                 /* Turn of last "feeling" */
2222                 rd_s32b(&p_ptr->feeling_turn);
2223         }
2224
2225         /* Current turn */
2226         rd_s32b(&turn);
2227
2228         if (z_older_than(10, 3, 12))
2229         {
2230                 dungeon_turn = turn;
2231         }
2232         else rd_s32b(&dungeon_turn);
2233
2234         if (z_older_than(11, 0, 13))
2235         {
2236                 old_turn /= 2;
2237                 p_ptr->feeling_turn /= 2;
2238                 turn /= 2;
2239                 dungeon_turn /= 2;
2240         }
2241
2242         if (z_older_than(10, 3, 13))
2243         {
2244                 old_battle = turn;
2245         }
2246         else rd_s32b(&old_battle);
2247
2248         if (z_older_than(10,0,3))
2249         {
2250                 determine_today_mon(TRUE);
2251         }
2252         else
2253         {
2254                 rd_s16b(&today_mon);
2255                 rd_s16b(&p_ptr->today_mon);
2256         }
2257
2258         if (z_older_than(10,0,7))
2259         {
2260                 p_ptr->riding = 0;
2261         }
2262         else
2263         {
2264                 rd_s16b(&p_ptr->riding);
2265         }
2266
2267         /* Current floor_id */
2268         if (h_older_than(1, 5, 0, 0))
2269         {
2270                 p_ptr->floor_id = 0;
2271         }
2272         else
2273         {
2274                 rd_s16b(&p_ptr->floor_id);
2275         }
2276
2277         if (h_older_than(1, 5, 0, 2))
2278         {
2279                 /* Nothing to do */
2280         }
2281         else
2282         {
2283                 /* Get number of party_mon array */
2284                 rd_s16b(&tmp16s);
2285
2286                 /* Strip old temporary preserved pets */
2287                 for (i = 0; i < tmp16s; i++)
2288                 {
2289                         monster_type dummy_mon;
2290
2291                         rd_monster(&dummy_mon);
2292                 }
2293         }
2294
2295         if (z_older_than(10,1,2))
2296         {
2297                 playtime = 0;
2298         }
2299         else
2300         {
2301                 rd_u32b(&playtime);
2302         }
2303
2304         if (z_older_than(10,3,9))
2305         {
2306                 p_ptr->visit = 1L;
2307         }
2308         else if (z_older_than(10, 3, 10))
2309         {
2310                 s32b tmp32s;
2311                 rd_s32b(&tmp32s);
2312                 p_ptr->visit = 1L;
2313         }
2314         else
2315         {
2316                 rd_s32b(&p_ptr->visit);
2317         }
2318         if (!z_older_than(11, 0, 5))
2319         {
2320                 rd_u32b(&p_ptr->count);
2321         }
2322 }
2323
2324
2325 /*!
2326  * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
2327  * @return なし
2328  * @details
2329  * Note that the inventory changed in Angband 2.7.4.  Two extra
2330  * pack slots were added and the equipment was rearranged.  Note
2331  * that these two features combine when parsing old save-files, in
2332  * which items from the old "aux" slot are "carried", perhaps into
2333  * one of the two new "inventory" slots.
2334  *
2335  * Note that the inventory is "re-sorted" later by "dungeon()".
2336  */
2337 static errr rd_inventory(void)
2338 {
2339         int slot = 0;
2340
2341         object_type forge;
2342         object_type *q_ptr;
2343
2344         /* No weight */
2345         p_ptr->total_weight = 0;
2346
2347         /* No items */
2348         inven_cnt = 0;
2349         equip_cnt = 0;
2350
2351         /* Read until done */
2352         while (1)
2353         {
2354                 u16b n;
2355
2356                 /* Get the next item index */
2357                 rd_u16b(&n);
2358
2359                 /* Nope, we reached the end */
2360                 if (n == 0xFFFF) break;
2361
2362                 /* Get local object */
2363                 q_ptr = &forge;
2364
2365                 /* Wipe the object */
2366                 object_wipe(q_ptr);
2367
2368                 /* Read the item */
2369                 rd_item(q_ptr);
2370
2371                 /* Hack -- verify item */
2372                 if (!q_ptr->k_idx) return (53);
2373
2374                 /* Wield equipment */
2375                 if (n >= INVEN_RARM)
2376                 {
2377                         /* Player touches it */
2378                         q_ptr->marked |= OM_TOUCHED;
2379
2380                         /* Copy object */
2381                         object_copy(&inventory[n], q_ptr);
2382
2383                         /* Add the weight */
2384                         p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2385
2386                         /* One more item */
2387                         equip_cnt++;
2388                 }
2389
2390                 /* Warning -- backpack is full */
2391                 else if (inven_cnt == INVEN_PACK)
2392                 {
2393                         /* Oops */
2394                         note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
2395
2396                         /* Fail */
2397                         return (54);
2398                 }
2399
2400                 /* Carry inventory */
2401                 else
2402                 {
2403                         /* Get a slot */
2404                         n = slot++;
2405
2406                         /* Player touches it */
2407                         q_ptr->marked |= OM_TOUCHED;
2408
2409                         /* Copy object */
2410                         object_copy(&inventory[n], q_ptr);
2411
2412                         /* Add the weight */
2413                         p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2414
2415                         /* One more item */
2416                         inven_cnt++;
2417                 }
2418         }
2419
2420         /* Success */
2421         return (0);
2422 }
2423
2424
2425 /*!
2426  * @brief メッセージログを読み込む / Read the saved messages
2427  * @return なし
2428  */
2429 static void rd_messages(void)
2430 {
2431         int i;
2432         char buf[128];
2433
2434
2435         if (h_older_than(2, 2, 0, 75))
2436         {
2437                 u16b num;
2438                 /* Total */
2439                 rd_u16b(&num);
2440
2441                 /* Read the messages */
2442                 for (i = 0; i < num; i++)
2443                 {
2444                         /* Read the message */
2445                         rd_string(buf, sizeof(buf));
2446
2447                         /* Save the message */
2448                         message_add(buf);
2449                 }
2450         }
2451         else
2452         {
2453                 u32b num;
2454                 /* Total */
2455                 rd_u32b(&num);
2456
2457                 /* Read the messages */
2458                 for (i = 0; i < num; i++)
2459                 {
2460                         /* Read the message */
2461                         rd_string(buf, sizeof(buf));
2462
2463                         /* Save the message */
2464                         message_add(buf);
2465                 }
2466         }
2467
2468 }
2469
2470
2471
2472 /* Old hidden trap flag */
2473 #define CAVE_TRAP       0x8000
2474
2475 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2476 #define OLD_FEAT_INVIS              0x02
2477 #define OLD_FEAT_GLYPH              0x03
2478 #define OLD_FEAT_QUEST_ENTER        0x08
2479 #define OLD_FEAT_QUEST_EXIT         0x09
2480 #define OLD_FEAT_MINOR_GLYPH        0x40
2481 #define OLD_FEAT_BLDG_1             0x81
2482 #define OLD_FEAT_MIRROR             0xc3
2483
2484 /* Old quests */
2485 #define OLD_QUEST_WATER_CAVE 18
2486
2487 /* Quest constants */
2488 #define QUEST_OLD_CASTLE  27
2489 #define QUEST_ROYAL_CRYPT 28
2490
2491 /*!
2492  * @brief メッセージログを読み込む / Read the dungeon (old method)
2493  * @return なし
2494  * @details
2495  * The monsters/objects must be loaded in the same order
2496  * that they were stored, since the actual indexes matter.
2497  */
2498 static errr rd_dungeon_old(void)
2499 {
2500         int i, y, x;
2501         int ymax, xmax;
2502         byte count;
2503         byte tmp8u;
2504         s16b tmp16s;
2505         u16b limit;
2506         cave_type *c_ptr;
2507
2508
2509         /*** Basic info ***/
2510
2511         /* Header info */
2512         rd_s16b(&tmp16s);
2513         dun_level = (DEPTH)tmp16s;
2514         if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2515         else rd_byte(&dungeon_type);
2516
2517         /* Set the base level for old versions */
2518         base_level = dun_level;
2519
2520         rd_s16b(&tmp16s);
2521         base_level = (DEPTH)tmp16s;
2522
2523         rd_s16b(&num_repro);
2524         rd_s16b(&tmp16s);
2525         p_ptr->y = (int)tmp16s;
2526         rd_s16b(&tmp16s);
2527         p_ptr->x = (int)tmp16s;
2528         if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
2529         rd_s16b(&tmp16s);
2530         cur_hgt = (POSITION)tmp16s;
2531         rd_s16b(&tmp16s);
2532         cur_wid = (POSITION)tmp16s;
2533         rd_s16b(&tmp16s); /* max_panel_rows */
2534         rd_s16b(&tmp16s); /* max_panel_cols */
2535
2536 #if 0
2537         if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2538 #endif
2539
2540         /* Maximal size */
2541         ymax = cur_hgt;
2542         xmax = cur_wid;
2543
2544
2545         /*** Run length decoding ***/
2546
2547         /* Load the dungeon data */
2548         for (x = y = 0; y < ymax; )
2549         {
2550                 u16b info;
2551
2552                 /* Grab RLE info */
2553                 rd_byte(&count);
2554                 if (z_older_than(10,3,6))
2555                 {
2556                         rd_byte(&tmp8u);
2557                         info = (u16b)tmp8u;
2558                 }
2559                 else
2560                 {
2561                         rd_u16b(&info);
2562
2563                         /* Decline invalid flags */
2564                         info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2565                 }
2566
2567                 /* Apply the RLE info */
2568                 for (i = count; i > 0; i--)
2569                 {
2570                         /* Access the cave */
2571                         c_ptr = &cave[y][x];
2572
2573                         /* Extract "info" */
2574                         c_ptr->info = info;
2575
2576                         /* Advance/Wrap */
2577                         if (++x >= xmax)
2578                         {
2579                                 /* Wrap */
2580                                 x = 0;
2581
2582                                 /* Advance/Wrap */
2583                                 if (++y >= ymax) break;
2584                         }
2585                 }
2586         }
2587
2588
2589         /*** Run length decoding ***/
2590
2591         /* Load the dungeon data */
2592         for (x = y = 0; y < ymax; )
2593         {
2594                 /* Grab RLE info */
2595                 rd_byte(&count);
2596                 rd_byte(&tmp8u);
2597
2598                 /* Apply the RLE info */
2599                 for (i = count; i > 0; i--)
2600                 {
2601                         /* Access the cave */
2602                         c_ptr = &cave[y][x];
2603
2604                         /* Extract "feat" */
2605                         c_ptr->feat = (s16b)tmp8u;
2606
2607                         /* Advance/Wrap */
2608                         if (++x >= xmax)
2609                         {
2610                                 /* Wrap */
2611                                 x = 0;
2612
2613                                 /* Advance/Wrap */
2614                                 if (++y >= ymax) break;
2615                         }
2616                 }
2617         }
2618
2619         /*** Run length decoding ***/
2620
2621         /* Load the dungeon data */
2622         for (x = y = 0; y < ymax; )
2623         {
2624                 /* Grab RLE info */
2625                 rd_byte(&count);
2626                 rd_byte(&tmp8u);
2627
2628                 /* Apply the RLE info */
2629                 for (i = count; i > 0; i--)
2630                 {
2631                         /* Access the cave */
2632                         c_ptr = &cave[y][x];
2633
2634                         /* Extract "mimic" */
2635                         c_ptr->mimic = (s16b)tmp8u;
2636
2637                         /* Advance/Wrap */
2638                         if (++x >= xmax)
2639                         {
2640                                 /* Wrap */
2641                                 x = 0;
2642
2643                                 /* Advance/Wrap */
2644                                 if (++y >= ymax) break;
2645                         }
2646                 }
2647         }
2648
2649         /*** Run length decoding ***/
2650
2651         /* Load the dungeon data */
2652         for (x = y = 0; y < ymax; )
2653         {
2654                 /* Grab RLE info */
2655                 rd_byte(&count);
2656                 rd_s16b(&tmp16s);
2657
2658                 /* Apply the RLE info */
2659                 for (i = count; i > 0; i--)
2660                 {
2661                         /* Access the cave */
2662                         c_ptr = &cave[y][x];
2663
2664                         /* Extract "feat" */
2665                         c_ptr->special = tmp16s;
2666
2667                         /* Advance/Wrap */
2668                         if (++x >= xmax)
2669                         {
2670                                 /* Wrap */
2671                                 x = 0;
2672
2673                                 /* Advance/Wrap */
2674                                 if (++y >= ymax) break;
2675                         }
2676                 }
2677         }
2678
2679         /* Convert cave data */
2680         if (z_older_than(11, 0, 99))
2681         {
2682                 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2683                 {
2684                         /* Wipe old unused flags */
2685                         cave[y][x].info &= ~(CAVE_MASK);
2686                 }
2687         }
2688
2689         if (h_older_than(1, 1, 1, 0))
2690         {
2691                 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2692                 {
2693                         /* Access the cave */
2694                         c_ptr = &cave[y][x];
2695
2696                         /* Very old */
2697                         if (c_ptr->feat == OLD_FEAT_INVIS)
2698                         {
2699                                 c_ptr->feat = feat_floor;
2700                                 c_ptr->info |= CAVE_TRAP;
2701                         }
2702
2703                         /* Older than 1.1.1 */
2704                         if (c_ptr->feat == OLD_FEAT_MIRROR)
2705                         {
2706                                 c_ptr->feat = feat_floor;
2707                                 c_ptr->info |= CAVE_OBJECT;
2708                         }
2709                 }
2710         }
2711
2712         if (h_older_than(1, 3, 1, 0))
2713         {
2714                 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2715                 {
2716                         /* Access the cave */
2717                         c_ptr = &cave[y][x];
2718
2719                         /* Old CAVE_IN_MIRROR flag */
2720                         if (c_ptr->info & CAVE_OBJECT)
2721                         {
2722                                 c_ptr->mimic = feat_mirror;
2723                         }
2724
2725                         /* Runes will be mimics and flags */
2726                         else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2727                                  (c_ptr->feat == OLD_FEAT_GLYPH))
2728                         {
2729                                 c_ptr->info |= CAVE_OBJECT;
2730                                 c_ptr->mimic = c_ptr->feat;
2731                                 c_ptr->feat = feat_floor;
2732                         }
2733
2734                         /* Hidden traps will be trap terrains mimicing floor */
2735                         else if (c_ptr->info & CAVE_TRAP)
2736                         {
2737                                 c_ptr->info &= ~CAVE_TRAP;
2738                                 c_ptr->mimic = c_ptr->feat;
2739                                 c_ptr->feat = choose_random_trap();
2740                         }
2741
2742                         /* Another hidden trap */
2743                         else if (c_ptr->feat == OLD_FEAT_INVIS)
2744                         {
2745                                 c_ptr->mimic = feat_floor;
2746                                 c_ptr->feat = feat_trap_open;
2747                         }
2748                 }
2749         }
2750
2751         /* Quest 18 was removed */
2752         if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2753         {
2754                 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2755                 {
2756                         /* Access the cave */
2757                         c_ptr = &cave[y][x];
2758
2759                         if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2760                         {
2761                                 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2762                                 {
2763                                         c_ptr->feat = feat_tree;
2764                                         c_ptr->special = 0;
2765                                 }
2766                                 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2767                                 {
2768                                         c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2769                                 }
2770                         }
2771                         else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2772                                  (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2773                         {
2774                                 c_ptr->feat = feat_up_stair;
2775                                 c_ptr->special = 0;
2776                         }
2777                 }
2778         }
2779
2780         /*** Objects ***/
2781
2782         /* Read the item count */
2783         rd_u16b(&limit);
2784
2785         /* Verify maximum */
2786         if (limit > max_o_idx)
2787         {
2788                 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2789                 return (151);
2790         }
2791
2792         /* Read the dungeon items */
2793         for (i = 1; i < limit; i++)
2794         {
2795                 IDX o_idx;
2796
2797                 object_type *o_ptr;
2798
2799
2800                 /* Get a new record */
2801                 o_idx = o_pop();
2802
2803                 /* Oops */
2804                 if (i != o_idx)
2805                 {
2806                         note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2807                         return (152);
2808                 }
2809
2810
2811                 /* Acquire place */
2812                 o_ptr = &o_list[o_idx];
2813
2814                 /* Read the item */
2815                 rd_item(o_ptr);
2816
2817
2818                 /* XXX XXX XXX XXX XXX */
2819
2820                 /* Monster */
2821                 if (o_ptr->held_m_idx)
2822                 {
2823                         monster_type *m_ptr;
2824
2825                         /* Monster */
2826                         m_ptr = &m_list[o_ptr->held_m_idx];
2827
2828                         /* Build a stack */
2829                         o_ptr->next_o_idx = m_ptr->hold_o_idx;
2830
2831                         /* Place the object */
2832                         m_ptr->hold_o_idx = o_idx;
2833                 }
2834
2835                 /* Dungeon */
2836                 else
2837                 {
2838                         /* Access the item location */
2839                         c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2840
2841                         /* Build a stack */
2842                         o_ptr->next_o_idx = c_ptr->o_idx;
2843
2844                         /* Place the object */
2845                         c_ptr->o_idx = o_idx;
2846                 }
2847         }
2848
2849
2850         /*** Monsters ***/
2851
2852         /* Read the monster count */
2853         rd_u16b(&limit);
2854
2855         /* Hack -- verify */
2856         if (limit > max_m_idx)
2857         {
2858                 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2859                 return (161);
2860         }
2861
2862         /* Read the monsters */
2863         for (i = 1; i < limit; i++)
2864         {
2865                 IDX m_idx;
2866                 monster_type *m_ptr;
2867
2868                 /* Get a new record */
2869                 m_idx = m_pop();
2870
2871                 /* Oops */
2872                 if (i != m_idx)
2873                 {
2874                         note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2875                         return (162);
2876                 }
2877
2878
2879                 /* Acquire monster */
2880                 m_ptr = &m_list[m_idx];
2881
2882                 /* Read the monster */
2883                 rd_monster(m_ptr);
2884
2885
2886                 /* Access grid */
2887                 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2888
2889                 /* Mark the location */
2890                 c_ptr->m_idx = m_idx;
2891
2892                 /* Count */
2893                 real_r_ptr(m_ptr)->cur_num++;
2894         }
2895
2896         /*** Success ***/
2897
2898         /* The dungeon is ready */
2899         if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2900                 character_dungeon = FALSE;
2901         else
2902                 character_dungeon = TRUE;
2903
2904         /* Success */
2905         return (0);
2906 }
2907
2908
2909 /*!
2910  * @brief 保存されたフロアを読み込む / Read the saved floor
2911  * @return なし
2912  * @details
2913  * The monsters/objects must be loaded in the same order
2914  * that they were stored, since the actual indexes matter.
2915  */
2916 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2917 {
2918         int ymax, xmax;
2919         int i, y, x;
2920         byte count;
2921         byte tmp8u;
2922         s16b tmp16s;
2923         u16b tmp16u;
2924         s32b tmp32s;
2925         u32b tmp32u;
2926         u16b limit;
2927
2928         cave_template_type *templates;
2929
2930
2931         /*** Wipe all cave ***/
2932         clear_cave();
2933
2934
2935         /*** Basic info ***/
2936
2937         /* Dungeon floor specific info follows */
2938
2939         if (!sf_ptr)
2940         {
2941                 /*** Not a saved floor ***/
2942
2943                 rd_s16b(&tmp16s);
2944                 dun_level = (DEPTH)tmp16s;
2945                 base_level = dun_level;
2946         }
2947         else
2948         {
2949                 /*** The saved floor ***/
2950
2951                 rd_s16b(&tmp16s);
2952                 if (tmp16s != sf_ptr->floor_id) return 171;
2953
2954                 rd_byte(&tmp8u);
2955                 if (tmp8u != sf_ptr->savefile_id) return 171;
2956
2957                 rd_s16b(&tmp16s);
2958                 if (tmp16s != sf_ptr->dun_level) return 171;
2959                 dun_level = sf_ptr->dun_level;
2960
2961                 rd_s32b(&tmp32s);
2962                 if (tmp32s != sf_ptr->last_visit) return 171;
2963
2964                 rd_u32b(&tmp32u);
2965                 if (tmp32u != sf_ptr->visit_mark) return 171;
2966
2967                 rd_s16b(&tmp16s);
2968                 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2969
2970                 rd_s16b(&tmp16s);
2971                 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2972         }
2973
2974         rd_s16b(&tmp16s);
2975         base_level = (DEPTH)tmp16s;
2976         rd_s16b(&num_repro);
2977
2978         rd_u16b(&tmp16u);
2979         p_ptr->y = (int)tmp16u;
2980
2981         rd_u16b(&tmp16u);
2982         p_ptr->x = (int)tmp16u;
2983
2984         rd_s16b(&tmp16s);
2985         cur_hgt = (POSITION)tmp16s;
2986         rd_s16b(&tmp16s);
2987         cur_wid = (POSITION)tmp16s;
2988
2989         rd_byte(&p_ptr->feeling);
2990
2991
2992
2993         /*** Read template for cave_type ***/
2994
2995         /* Read the template count */
2996         rd_u16b(&limit);
2997
2998         /* Allocate the "template" array */
2999         C_MAKE(templates, limit, cave_template_type);
3000
3001         /* Read the templates */
3002         for (i = 0; i < limit; i++)
3003         {
3004                 cave_template_type *ct_ptr = &templates[i];
3005
3006                 /* Read it */
3007                 rd_u16b(&ct_ptr->info);
3008                 if (h_older_than(1, 7, 0, 2))
3009                 {
3010                         rd_byte(&tmp8u);
3011                         ct_ptr->feat = (s16b)tmp8u;
3012                         rd_byte(&tmp8u);
3013                         ct_ptr->mimic = (s16b)tmp8u;
3014                 }
3015                 else
3016                 {
3017                         rd_s16b(&ct_ptr->feat);
3018                         rd_s16b(&ct_ptr->mimic);
3019                 }
3020                 rd_s16b(&ct_ptr->special);
3021         }
3022
3023         /* Maximal size */
3024         ymax = cur_hgt;
3025         xmax = cur_wid;
3026
3027
3028         /*** Run length decoding ***/
3029
3030         /* Load the dungeon data */
3031         for (x = y = 0; y < ymax; )
3032         {
3033                 u16b id;
3034
3035                 /* Grab RLE info */
3036                 rd_byte(&count);
3037
3038                 id = 0;
3039                 do 
3040                 {
3041                         rd_byte(&tmp8u);
3042                         id += tmp8u;
3043                 } while (tmp8u == MAX_UCHAR);
3044
3045                 /* Apply the RLE info */
3046                 for (i = count; i > 0; i--)
3047                 {
3048                         /* Access the cave */
3049                         cave_type *c_ptr = &cave[y][x];
3050
3051                         /* Extract cave data */
3052                         c_ptr->info = templates[id].info;
3053                         c_ptr->feat = templates[id].feat;
3054                         c_ptr->mimic = templates[id].mimic;
3055                         c_ptr->special = templates[id].special;
3056
3057                         /* Advance/Wrap */
3058                         if (++x >= xmax)
3059                         {
3060                                 /* Wrap */
3061                                 x = 0;
3062
3063                                 /* Advance/Wrap */
3064                                 if (++y >= ymax) break;
3065                         }
3066                 }
3067         }
3068
3069         /* Quest 18 was removed */
3070         if (h_older_than(1, 7, 0, 6) && !vanilla_town)
3071         {
3072                 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
3073                 {
3074                         /* Access the cave */
3075                         cave_type *c_ptr = &cave[y][x];
3076
3077                         if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
3078                         {
3079                                 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
3080                                 {
3081                                         c_ptr->feat = feat_tree;
3082                                         c_ptr->special = 0;
3083                                 }
3084                                 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
3085                                 {
3086                                         c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
3087                                 }
3088                         }
3089                         else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
3090                                  (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
3091                         {
3092                                 c_ptr->feat = feat_up_stair;
3093                                 c_ptr->special = 0;
3094                         }
3095                 }
3096         }
3097
3098         /* Free the "template" array */
3099         C_KILL(templates, limit, cave_template_type);
3100
3101
3102         /*** Objects ***/
3103
3104         /* Read the item count */
3105         rd_u16b(&limit);
3106
3107         /* Verify maximum */
3108         if (limit > max_o_idx) return 151;
3109
3110
3111         /* Read the dungeon items */
3112         for (i = 1; i < limit; i++)
3113         {
3114                 IDX o_idx;
3115                 object_type *o_ptr;
3116
3117
3118                 /* Get a new record */
3119                 o_idx = o_pop();
3120
3121                 /* Oops */
3122                 if (i != o_idx) return 152;
3123
3124                 /* Acquire place */
3125                 o_ptr = &o_list[o_idx];
3126
3127                 /* Read the item */
3128                 rd_item(o_ptr);
3129
3130
3131                 /* Monster */
3132                 if (o_ptr->held_m_idx)
3133                 {
3134                         monster_type *m_ptr;
3135
3136                         /* Monster */
3137                         m_ptr = &m_list[o_ptr->held_m_idx];
3138
3139                         /* Build a stack */
3140                         o_ptr->next_o_idx = m_ptr->hold_o_idx;
3141
3142                         /* Place the object */
3143                         m_ptr->hold_o_idx = o_idx;
3144                 }
3145
3146                 /* Dungeon */
3147                 else
3148                 {
3149                         /* Access the item location */
3150                         cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3151
3152                         /* Build a stack */
3153                         o_ptr->next_o_idx = c_ptr->o_idx;
3154
3155                         /* Place the object */
3156                         c_ptr->o_idx = o_idx;
3157                 }
3158         }
3159
3160
3161         /*** Monsters ***/
3162
3163         /* Read the monster count */
3164         rd_u16b(&limit);
3165
3166         /* Hack -- verify */
3167         if (limit > max_m_idx) return 161;
3168
3169         /* Read the monsters */
3170         for (i = 1; i < limit; i++)
3171         {
3172                 cave_type *c_ptr;
3173                 int m_idx;
3174                 monster_type *m_ptr;
3175
3176                 /* Get a new record */
3177                 m_idx = m_pop();
3178
3179                 /* Oops */
3180                 if (i != m_idx) return 162;
3181
3182
3183                 /* Acquire monster */
3184                 m_ptr = &m_list[m_idx];
3185
3186                 /* Read the monster */
3187                 rd_monster(m_ptr);
3188
3189
3190                 /* Access grid */
3191                 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3192
3193                 /* Mark the location */
3194                 c_ptr->m_idx = m_idx;
3195
3196                 /* Count */
3197                 real_r_ptr(m_ptr)->cur_num++;
3198         }
3199
3200         /* Success */
3201         return 0;
3202 }
3203
3204
3205 /*!
3206  * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
3207  * @return なし
3208  * @details
3209  * The monsters/objects must be loaded in the same order
3210  * that they were stored, since the actual indexes matter.
3211  */
3212 static errr rd_dungeon(void)
3213 {
3214         errr err = 0;
3215         s16b tmp16s;
3216         byte num;
3217         int i;
3218
3219         /* Initialize saved_floors array and temporal files */
3220         init_saved_floors(FALSE);
3221
3222         /* Older method */
3223         if (h_older_than(1, 5, 0, 0))
3224         {
3225                 err = rd_dungeon_old();
3226
3227                 /* Prepare floor_id of current floor */
3228                 if (dungeon_type)
3229                 {
3230                         p_ptr->floor_id = get_new_floor_id();
3231                         get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3232                 }
3233
3234                 return err;
3235         }
3236
3237
3238         /*** Meta info ***/
3239
3240         /* Number of floor_id used from birth */
3241         rd_s16b(&max_floor_id);
3242
3243         /* Current dungeon type */
3244         rd_byte(&dungeon_type);
3245
3246
3247         /* Number of the saved_floors array elements */
3248         rd_byte(&num);
3249
3250         /*** No saved floor (On the surface etc.) ***/
3251         if (!num)
3252         {
3253                 /* Read the current floor data */
3254                 err = rd_saved_floor(NULL);
3255         }
3256
3257         /*** In the dungeon ***/
3258         else
3259         {
3260
3261                 /* Read the saved_floors array */
3262                 for (i = 0; i < num; i++)
3263                 {
3264                         saved_floor_type *sf_ptr = &saved_floors[i];
3265
3266                         rd_s16b(&sf_ptr->floor_id);
3267                         rd_byte(&sf_ptr->savefile_id);
3268
3269                         rd_s16b(&tmp16s);
3270                         sf_ptr->dun_level = (DEPTH)tmp16s;
3271
3272                         rd_s32b(&sf_ptr->last_visit);
3273                         rd_u32b(&sf_ptr->visit_mark);
3274                         rd_s16b(&sf_ptr->upper_floor_id);
3275                         rd_s16b(&sf_ptr->lower_floor_id);
3276                 }
3277
3278
3279                 /* Move saved floors data to temporal files */
3280                 for (i = 0; i < num; i++)
3281                 {
3282                         saved_floor_type *sf_ptr = &saved_floors[i];
3283                         byte tmp8u;
3284
3285                         /* Unused element */
3286                         if (!sf_ptr->floor_id) continue;
3287
3288                         /* Read the failure mark */
3289                         rd_byte(&tmp8u);
3290                         if (tmp8u) continue;
3291
3292                         /* Read from the save file */
3293                         err = rd_saved_floor(sf_ptr);
3294
3295                         /* Error? */
3296                         if (err) break;
3297
3298                         /* Re-save as temporal saved floor file */
3299                         if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3300
3301                         /* Error? */
3302                         if (err) break;
3303                 }
3304
3305                 /* Finally load current floor data from temporal file */
3306                 if (!err)
3307                 {
3308                         if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3309                 }
3310         }
3311
3312
3313         /*** Error messages ***/
3314         switch (err)
3315         {
3316         case 151:
3317                 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3318                 break;
3319
3320         case 152:
3321                 note(_("アイテム配置エラー", "Object allocation error"));
3322                 break;
3323
3324         case 161:
3325                 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3326                 break;
3327
3328         case 162:
3329                 note(_("モンスター配置エラー", "Monster allocation error"));
3330                 break;
3331
3332         case 171:
3333                 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3334                 break;
3335
3336         case 182:
3337                 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3338                 break;
3339
3340         case 183:
3341                 note(_("Error 183", "Error 183"));
3342                 break;
3343         }
3344
3345         /* The dungeon is ready */
3346         character_dungeon = TRUE;
3347
3348         /* Success or Error */
3349         return err;
3350 }
3351
3352
3353 /*!
3354  * @brief ロード処理全体のサブ関数 / Actually read the savefile
3355  * @return エラーコード
3356  */
3357 static errr rd_savefile_new_aux(void)
3358 {
3359         int i, j;
3360         int town_count;
3361
3362         s32b wild_x_size;
3363         s32b wild_y_size;
3364
3365         byte tmp8u;
3366         u16b tmp16u;
3367         u32b tmp32u;
3368
3369 #ifdef VERIFY_CHECKSUMS
3370         u32b n_x_check, n_v_check;
3371         u32b o_x_check, o_v_check;
3372 #endif
3373
3374
3375         /* Strip the version bytes */
3376         strip_bytes(4);
3377
3378         /* Hack -- decrypt */
3379         xor_byte = sf_extra;
3380
3381
3382         /* Clear the checksums */
3383         v_check = 0L;
3384         x_check = 0L;
3385
3386         /* Read the version number of the savefile */
3387         /* Old savefile will be version 0.0.0.3 */
3388         rd_byte(&h_ver_extra);
3389         rd_byte(&h_ver_patch);
3390         rd_byte(&h_ver_minor);
3391         rd_byte(&h_ver_major);
3392
3393         /* Mention the savefile version */
3394         note(format(
3395                 _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
3396                 (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
3397
3398
3399         /* Operating system info */
3400         rd_u32b(&sf_system);
3401
3402         /* Time of savefile creation */
3403         rd_u32b(&sf_when);
3404
3405         /* Number of resurrections */
3406         rd_u16b(&sf_lives);
3407
3408         /* Number of times played */
3409         rd_u16b(&sf_saves);
3410
3411
3412         /* Later use (always zero) */
3413         rd_u32b(&tmp32u);
3414
3415         /* Later use (always zero) */
3416         rd_u16b(&tmp16u);
3417
3418         /* Later use (always zero) */
3419         rd_byte(&tmp8u);
3420
3421         /* Kanji code */
3422         rd_byte(&kanji_code);
3423
3424         /* Read RNG state */
3425         rd_randomizer();
3426         if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3427
3428         /* Then the options */
3429         rd_options();
3430         if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3431
3432         /* Then the "messages" */
3433         rd_messages();
3434         if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3435
3436         for (i = 0; i < max_r_idx; i++)
3437         {
3438                 /* Access that monster */
3439                 monster_race *r_ptr = &r_info[i];
3440
3441                 /* Hack -- Reset the death counter */
3442                 r_ptr->max_num = 100;
3443
3444                 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3445
3446                 /* Hack -- Non-unique Nazguls are semi-unique */
3447                 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3448         }
3449
3450         /* Monster Memory */
3451         rd_u16b(&tmp16u);
3452
3453         /* Incompatible save files */
3454         if (tmp16u > max_r_idx)
3455         {
3456                 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3457                 return (21);
3458         }
3459
3460         /* Read the available records */
3461         for (i = 0; i < tmp16u; i++)
3462         {
3463                 /* Read the lore */
3464                 rd_lore(i);
3465         }
3466
3467         if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3468
3469         /* Object Memory */
3470         rd_u16b(&tmp16u);
3471
3472         /* Incompatible save files */
3473         if (tmp16u > max_k_idx)
3474         {
3475                 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3476                 return (22);
3477         }
3478
3479         /* Read the object memory */
3480         for (i = 0; i < tmp16u; i++)
3481         {
3482                 object_kind *k_ptr = &k_info[i];
3483
3484                 rd_byte(&tmp8u);
3485
3486                 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3487                 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3488         }
3489         if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3490
3491         /* 2.1.3 or newer version */
3492         {
3493                 u16b max_towns_load;
3494                 u16b max_quests_load;
3495                 byte max_rquests_load;
3496                 s16b old_inside_quest = p_ptr->inside_quest;
3497
3498                 /* Number of towns */
3499                 rd_u16b(&max_towns_load);
3500
3501                 /* Incompatible save files */
3502                 if (max_towns_load > max_towns)
3503                 {
3504                         note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3505                         return (23);
3506                 }
3507
3508                 /* Number of quests */
3509                 rd_u16b(&max_quests_load);
3510
3511                 if (z_older_than(11, 0, 7))
3512                 {
3513                         max_rquests_load = 10;
3514                 }
3515                 else
3516                 {
3517                         rd_byte(&max_rquests_load);
3518                 }
3519
3520                 /* Incompatible save files */
3521                 if (max_quests_load > max_quests)
3522                 {
3523                         note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3524                         return (23);
3525                 }
3526
3527                 for (i = 0; i < max_quests_load; i++)
3528                 {
3529                         if (i < max_quests)
3530                         {
3531                                 quest_type* const q_ptr = &quest[i];
3532                                 
3533                                 rd_s16b(&q_ptr->status);
3534                                 rd_s16b(&q_ptr->level);
3535
3536                                 if (z_older_than(11, 0, 6))
3537                                 {
3538                                         q_ptr->complev = 0;
3539                                 }
3540                                 else
3541                                 {
3542                                         rd_byte(&q_ptr->complev);
3543                                 }
3544                                 if(h_older_than(2, 1, 2, 2))
3545                                 {
3546                                         q_ptr->comptime = 0;
3547                                 }
3548                                 else
3549                                 {
3550                                         rd_u32b(&q_ptr->comptime);
3551                                 }
3552
3553                                 /* Load quest status if quest is running */
3554                                 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3555                                     (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3556                                     (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3557                                 {
3558                                         rd_s16b(&q_ptr->cur_num);
3559                                         rd_s16b(&q_ptr->max_num);
3560                                         rd_s16b(&q_ptr->type);
3561
3562                                         /* Load quest monster index */
3563                                         rd_s16b(&q_ptr->r_idx);
3564
3565                                         if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3566                                         {
3567                                                 determine_random_questor(&quest[i]);
3568                                         }
3569
3570                                         /* Load quest item index */
3571                                         rd_s16b(&q_ptr->k_idx);
3572
3573                                         if (q_ptr->k_idx)
3574                                                 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3575
3576                                         rd_byte(&q_ptr->flags);
3577
3578                                         if (z_older_than(10, 3, 11))
3579                                         {
3580                                                 if (q_ptr->flags & QUEST_FLAG_PRESET)
3581                                                 {
3582                                                         q_ptr->dungeon = 0;
3583                                                 }
3584                                                 else
3585                                                 {
3586                                                         init_flags = INIT_ASSIGN;
3587                                                         p_ptr->inside_quest = i;
3588
3589                                                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3590                                                         p_ptr->inside_quest = old_inside_quest;
3591                                                 }
3592                                         }
3593                                         else
3594                                         {
3595                                                 rd_byte(&q_ptr->dungeon);
3596                                         }
3597                                         /* Mark uniques */
3598                                         if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3599                                                 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3600                                                         r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3601                                 }
3602                         }
3603                         /* Ignore the empty quests from old versions */
3604                         else
3605                         {
3606                                 /* Ignore quest status */
3607                                 strip_bytes(2);
3608
3609                                 /* Ignore quest level */
3610                                 strip_bytes(2);
3611
3612                                 /*
3613                                  * We don't have to care about the other info,
3614                                  * since status should be 0 for these quests anyway
3615                                  */
3616                         }
3617                 }
3618
3619                 /* Quest 18 was removed */
3620                 if (h_older_than(1, 7, 0, 6))
3621                 {
3622                         (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3623                         quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3624                 }
3625
3626                 /* Position in the wilderness */
3627                 rd_s32b(&p_ptr->wilderness_x);
3628                 rd_s32b(&p_ptr->wilderness_y);
3629                 if (z_older_than(10, 3, 13))
3630                 {
3631                         p_ptr->wilderness_x = 5;
3632                         p_ptr->wilderness_y = 48;
3633                 }
3634
3635                 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3636                 else rd_byte((byte *)&p_ptr->wild_mode);
3637                 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3638                 else rd_byte((byte *)&ambush_flag);
3639
3640                 /* Size of the wilderness */
3641                 rd_s32b(&wild_x_size);
3642                 rd_s32b(&wild_y_size);
3643
3644                 /* Incompatible save files */
3645                 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3646                 {
3647                         note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3648                         return (23);
3649                 }
3650
3651                 /* Load the wilderness seeds */
3652                 for (i = 0; i < wild_x_size; i++)
3653                 {
3654                         for (j = 0; j < wild_y_size; j++)
3655                         {
3656                                 rd_u32b(&wilderness[j][i].seed);
3657                         }
3658                 }
3659         }
3660
3661         if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3662
3663         /* Load the Artifacts */
3664         rd_u16b(&tmp16u);
3665
3666         /* Incompatible save files */
3667         if (tmp16u > max_a_idx)
3668         {
3669                 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3670                 return (24);
3671         }
3672
3673         /* Read the artifact flags */
3674         for (i = 0; i < tmp16u; i++)
3675         {
3676                 artifact_type *a_ptr = &a_info[i];
3677
3678                 rd_byte(&tmp8u);
3679                 a_ptr->cur_num = tmp8u;
3680
3681                 if (h_older_than(1, 5, 0, 0))
3682                 {
3683                         a_ptr->floor_id = 0;
3684
3685                         rd_byte(&tmp8u);
3686                         rd_byte(&tmp8u);
3687                         rd_byte(&tmp8u);
3688                 }
3689                 else
3690                 {
3691                         rd_s16b(&a_ptr->floor_id);
3692                 }
3693         }
3694         if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3695
3696         /* Read the extra stuff */
3697         rd_extra();
3698         if (p_ptr->energy_need < -999) world_player = TRUE;
3699
3700         if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3701
3702
3703         /* Read the player_hp array */
3704         rd_u16b(&tmp16u);
3705
3706         /* Incompatible save files */
3707         if (tmp16u > PY_MAX_LEVEL)
3708         {
3709                 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3710                 return (25);
3711         }
3712
3713         /* Read the player_hp array */
3714         for (i = 0; i < tmp16u; i++)
3715         {
3716                 rd_s16b(&p_ptr->player_hp[i]);
3717         }
3718
3719         /* Important -- Initialize the sex */
3720         sp_ptr = &sex_info[p_ptr->psex];
3721
3722         /* Important -- Initialize the race/class */
3723         rp_ptr = &race_info[p_ptr->prace];
3724         cp_ptr = &class_info[p_ptr->pclass];
3725         ap_ptr = &seikaku_info[p_ptr->pseikaku];
3726
3727         if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3728         {
3729                 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3730                 do_cmd_rerate(FALSE);
3731         }
3732         if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3733         {
3734                 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3735                 do_cmd_rerate(FALSE);
3736         }
3737         if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3738         {
3739                 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3740                 do_cmd_rerate(FALSE);
3741         }
3742         if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3743         {
3744                 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3745                 do_cmd_rerate(FALSE);
3746         }
3747
3748         /* Important -- Initialize the magic */
3749         mp_ptr = &m_info[p_ptr->pclass];
3750
3751
3752         /* Read spell info */
3753         rd_u32b(&p_ptr->spell_learned1);
3754         rd_u32b(&p_ptr->spell_learned2);
3755         rd_u32b(&p_ptr->spell_worked1);
3756         rd_u32b(&p_ptr->spell_worked2);
3757         rd_u32b(&p_ptr->spell_forgotten1);
3758         rd_u32b(&p_ptr->spell_forgotten2);
3759
3760         if (z_older_than(10,0,5))
3761         {
3762                 p_ptr->learned_spells = 0;
3763                 for (i = 0; i < 64; i++)
3764                 {
3765                         /* Count known spells */
3766                         if ((i < 32) ?
3767                             (p_ptr->spell_learned1 & (1L << i)) :
3768                             (p_ptr->spell_learned2 & (1L << (i - 32))))
3769                         {
3770                                 p_ptr->learned_spells++;
3771                         }
3772                 }
3773         }
3774         else rd_s16b(&p_ptr->learned_spells);
3775
3776         if (z_older_than(10,0,6))
3777         {
3778                 p_ptr->add_spells = 0;
3779         }
3780         else rd_s16b(&p_ptr->add_spells);
3781         if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3782
3783         for (i = 0; i < 64; i++)
3784         {
3785                 rd_byte(&p_ptr->spell_order[i]);
3786         }
3787
3788
3789         /* Read the inventory */
3790         if (rd_inventory())
3791         {
3792                 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3793                 return (21);
3794         }
3795
3796         /* Read number of towns */
3797         rd_u16b(&tmp16u);
3798         town_count = tmp16u;
3799
3800         /* Read the stores */
3801         rd_u16b(&tmp16u);
3802         for (i = 1; i < town_count; i++)
3803         {
3804                 for (j = 0; j < tmp16u; j++)
3805                 {
3806                         if (rd_store(i, j)) return (22);
3807                 }
3808         }
3809
3810         rd_s16b(&p_ptr->pet_follow_distance);
3811         if (z_older_than(10, 4, 10))
3812         {
3813                 p_ptr->pet_extra_flags = 0;
3814                 rd_byte(&tmp8u);
3815                 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3816                 rd_byte(&tmp8u);
3817                 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3818
3819                 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3820                 else
3821                 {
3822                         rd_byte(&tmp8u);
3823                         if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3824                 }
3825
3826                 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3827                 else
3828                 {
3829                         rd_byte(&tmp8u);
3830                         if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3831                 }
3832
3833                 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3834                 else
3835                 {
3836                         rd_byte(&tmp8u);
3837                         if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3838                 }
3839
3840                 if (!z_older_than(10,0,8))
3841                 {
3842                         rd_byte(&tmp8u);
3843                         if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3844                 }
3845         }
3846         else
3847         {
3848                 rd_s16b(&p_ptr->pet_extra_flags);
3849         }
3850
3851         if (!z_older_than(11, 0, 9))
3852         {
3853                 char buf[SCREEN_BUF_SIZE];
3854                 rd_string(buf, sizeof(buf));
3855                 if (buf[0]) screen_dump = string_make(buf);
3856         }
3857
3858         if (p_ptr->is_dead)
3859         {
3860                 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3861                 {
3862                         r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3863                 }
3864         }
3865
3866
3867         /* I'm not dead yet... */
3868         if (!p_ptr->is_dead)
3869         {
3870                 /* Dead players have no dungeon */
3871                 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3872
3873                 if (rd_dungeon())
3874                 {
3875                         note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3876                         return (34);
3877                 }
3878
3879                 /* Read the ghost info */
3880                 rd_ghost();
3881
3882                 {
3883                         s32b tmp32s;
3884
3885                         rd_s32b(&tmp32s);
3886                         strip_bytes(tmp32s);
3887                 }
3888         }
3889
3890         /* Quest 18 was removed */
3891         if (h_older_than(1, 7, 0, 6))
3892         {
3893                 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3894                 {
3895                         dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3896                         dun_level = 1;
3897                         p_ptr->inside_quest = 0;
3898                 }
3899         }
3900
3901
3902 #ifdef VERIFY_CHECKSUMS
3903
3904         /* Save the checksum */
3905         n_v_check = v_check;
3906
3907         /* Read the old checksum */
3908         rd_u32b(&o_v_check);
3909
3910         /* Verify */
3911         if (o_v_check != n_v_check)
3912         {
3913                 note(_("チェックサムがおかしい", "Invalid checksum"));
3914                 return (11);
3915         }
3916
3917
3918         /* Save the encoded checksum */
3919         n_x_check = x_check;
3920
3921         /* Read the checksum */
3922         rd_u32b(&o_x_check);
3923
3924
3925         /* Verify */
3926         if (o_x_check != n_x_check)
3927         {
3928                 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3929                 return (11);
3930         }
3931
3932 #endif
3933
3934         /* Success */
3935         return (0);
3936 }
3937
3938 /*!
3939  * @brief ロード処理全体のメイン関数 / Actually read the savefile
3940  * @return エラーコード
3941  */
3942 errr rd_savefile_new(void)
3943 {
3944         errr err;
3945
3946         /* Grab permissions */
3947         safe_setuid_grab();
3948
3949         /* The savefile is a binary file */
3950         fff = my_fopen(savefile, "rb");
3951
3952         /* Drop permissions */
3953         safe_setuid_drop();
3954
3955         /* Paranoia */
3956         if (!fff) return (-1);
3957
3958         /* Call the sub-function */
3959         err = rd_savefile_new_aux();
3960
3961         /* Check for errors */
3962         if (ferror(fff)) err = -1;
3963
3964         /* Close the file */
3965         my_fclose(fff);
3966
3967         /* Result */
3968         return (err);
3969 }
3970
3971
3972 /*!
3973  * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
3974  * @param sf_ptr 保存フロア読み込み先
3975  * @return 成功したらtrue
3976  */
3977 static bool load_floor_aux(saved_floor_type *sf_ptr)
3978 {
3979         byte tmp8u;
3980         u32b tmp32u;
3981
3982 #ifdef VERIFY_CHECKSUMS
3983         u32b n_x_check, n_v_check;
3984         u32b o_x_check, o_v_check;
3985 #endif
3986
3987         /* Hack -- decrypt (read xor_byte) */
3988         xor_byte = 0;
3989         rd_byte(&tmp8u);
3990
3991         /* Clear the checksums */
3992         v_check = 0L;
3993         x_check = 0L;
3994
3995         /* Set the version number to current version */
3996         /* Never load old temporal files */
3997         h_ver_extra = H_VER_EXTRA;
3998         h_ver_patch = H_VER_PATCH;
3999         h_ver_minor = H_VER_MINOR;
4000         h_ver_major = H_VER_MAJOR;
4001
4002         /* Verify the sign */
4003         rd_u32b(&tmp32u);
4004         if (saved_floor_file_sign != tmp32u) return FALSE;
4005
4006         /* Read -- have error? */
4007         if (rd_saved_floor(sf_ptr)) return FALSE;
4008
4009
4010 #ifdef VERIFY_CHECKSUMS
4011         /* Save the checksum */
4012         n_v_check = v_check;
4013
4014         /* Read the old checksum */
4015         rd_u32b(&o_v_check);
4016
4017         /* Verify */
4018         if (o_v_check != n_v_check) return FALSE;
4019
4020         /* Save the encoded checksum */
4021         n_x_check = x_check;
4022
4023         /* Read the checksum */
4024         rd_u32b(&o_x_check);
4025
4026         /* Verify */
4027         if (o_x_check != n_x_check) return FALSE;
4028 #endif
4029
4030         /* Success */
4031         return TRUE;
4032 }
4033
4034
4035 /*!
4036  * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
4037  * @param sf_ptr 保存フロア読み込み先
4038  * @param mode オプション
4039  * @return 成功したらtrue
4040  */
4041 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
4042 {
4043         FILE *old_fff = NULL;
4044         byte old_xor_byte = 0;
4045         u32b old_v_check = 0;
4046         u32b old_x_check = 0;
4047         byte old_h_ver_major = 0;
4048         byte old_h_ver_minor = 0;
4049         byte old_h_ver_patch = 0;
4050         byte old_h_ver_extra = 0;
4051  
4052         bool ok = TRUE;
4053         char floor_savefile[1024];
4054
4055         byte old_kanji_code = kanji_code;
4056
4057         /*
4058          * Temporal files are always written in system depended kanji
4059          * code.
4060          */
4061 #ifdef JP
4062 # ifdef EUC
4063         /* EUC kanji code */
4064         kanji_code = 2;
4065 # endif
4066 # ifdef SJIS
4067         /* SJIS kanji code */
4068         kanji_code = 3;
4069 # endif
4070 #else
4071         /* ASCII */
4072         kanji_code = 1;
4073 #endif
4074
4075
4076         /* We have one file already opened */
4077         if (mode & SLF_SECOND)
4078         {
4079                 /* Backup original values */
4080                 old_fff = fff;
4081                 old_xor_byte = xor_byte;
4082                 old_v_check = v_check;
4083                 old_x_check = x_check;
4084                 old_h_ver_major = h_ver_major;
4085                 old_h_ver_minor = h_ver_minor;
4086                 old_h_ver_patch = h_ver_patch;
4087                 old_h_ver_extra = h_ver_extra;
4088         }
4089
4090         /* floor savefile */
4091         sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4092
4093         /* Grab permissions */
4094         safe_setuid_grab();
4095
4096         /* The savefile is a binary file */
4097         fff = my_fopen(floor_savefile, "rb");
4098
4099         /* Drop permissions */
4100         safe_setuid_drop();
4101
4102         /* Couldn't read */
4103         if (!fff) ok = FALSE;
4104
4105         /* Attempt to load */
4106         if (ok)
4107         {
4108                 /* Load saved floor data from file */
4109                 ok = load_floor_aux(sf_ptr);
4110
4111                 /* Check for errors */
4112                 if (ferror(fff)) ok = FALSE;
4113
4114                 /* Close the file */
4115                 my_fclose(fff);
4116
4117                 /* Grab permissions */
4118                 safe_setuid_grab();
4119
4120                 /* Delete the file */
4121                 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4122
4123                 /* Drop permissions */
4124                 safe_setuid_drop();
4125         }
4126
4127         /* We have one file already opened */
4128         if (mode & SLF_SECOND)
4129         {
4130                 /* Restore original values */
4131                 fff = old_fff;
4132                 xor_byte = old_xor_byte;
4133                 v_check = old_v_check;
4134                 x_check = old_x_check;
4135                 h_ver_major = old_h_ver_major;
4136                 h_ver_minor = old_h_ver_minor;
4137                 h_ver_patch = old_h_ver_patch;
4138                 h_ver_extra = old_h_ver_extra;
4139         }
4140
4141         /* Restore old knowledge */
4142         kanji_code = old_kanji_code;
4143
4144         /* Result */
4145         return ok;
4146 }