OSDN Git Service

d170d744ba914f48fbe0119fe336131c1e733d8d
[hengband/hengband.git] / src / load.c
1 /* File: load.c */
2
3 /* Purpose: support for loading savefiles -BEN- */
4
5 #include "angband.h"
6
7
8 /*
9  * This file loads savefiles from Angband 2.7.X and 2.8.X
10  *
11  * Ancient savefiles (pre-2.7.0) are loaded by another file.
12  *
13  * Note that Angband 2.7.0 through 2.7.3 are now officially obsolete,
14  * and savefiles from those versions may not be successfully converted.
15  *
16  * We attempt to prevent corrupt savefiles from inducing memory errors.
17  *
18  * Note that this file should not use the random number generator, the
19  * object flavors, the visual attr/char mappings, or anything else which
20  * is initialized *after* or *during* the "load character" function.
21  *
22  * This file assumes that the monster/object records are initialized
23  * to zero, and the race/kind tables have been loaded correctly.  The
24  * order of object stacks is currently not saved in the savefiles, but
25  * the "next" pointers are saved, so all necessary knowledge is present.
26  *
27  * We should implement simple "savefile extenders" using some form of
28  * "sized" chunks of bytes, with a {size,type,data} format, so everyone
29  * can know the size, interested people can know the type, and the actual
30  * data is available to the parsing routines that acknowledge the type.
31  *
32  * Consider changing the "globe of invulnerability" code so that it
33  * takes some form of "maximum damage to protect from" in addition to
34  * the existing "number of turns to protect for", and where each hit
35  * by a monster will reduce the shield by that amount.
36  *
37  * XXX XXX XXX
38  */
39
40
41
42 /*
43  * Maximum number of tries for selection of a proper quest monster
44  */
45 #define MAX_TRIES 100
46
47
48 /*
49  * Local "savefile" pointer
50  */
51 static FILE     *fff;
52
53 /*
54  * Hack -- old "encryption" byte
55  */
56 static byte     xor_byte;
57
58 /*
59  * Hack -- simple "checksum" on the actual values
60  */
61 static u32b     v_check = 0L;
62
63 /*
64  * Hack -- simple "checksum" on the encoded bytes
65  */
66 static u32b     x_check = 0L;
67
68
69
70 #if 0
71 /*
72  * This function determines if the version of the savefile
73  * currently being read is older than version "x.y.z".
74  */
75 static bool older_than(byte x, byte y, byte z)
76 {
77         /* Much older, or much more recent */
78         if (sf_major < x) return (TRUE);
79         if (sf_major > x) return (FALSE);
80
81         /* Distinctly older, or distinctly more recent */
82         if (sf_minor < y) return (TRUE);
83         if (sf_minor > y) return (FALSE);
84
85         /* Barely older, or barely more recent */
86         if (sf_patch < z) return (TRUE);
87         if (sf_patch > z) return (FALSE);
88
89         /* Identical versions */
90         return (FALSE);
91 }
92 #endif
93
94 /*
95  * The above function, adapted for Zangband
96  */
97 static bool z_older_than(byte x, byte y, byte z)
98 {
99         /* Much older, or much more recent */
100         if (z_major < x) return (TRUE);
101         if (z_major > x) return (FALSE);
102
103         /* Distinctly older, or distinctly more recent */
104         if (z_minor < y) return (TRUE);
105         if (z_minor > y) return (FALSE);
106
107         /* Barely older, or barely more recent */
108         if (z_patch < z) return (TRUE);
109         if (z_patch > z) return (FALSE);
110
111         /* Identical versions */
112         return (FALSE);
113 }
114
115
116 /*
117  * Hack -- Show information on the screen, one line at a time.
118  *
119  * Avoid the top two lines, to avoid interference with "msg_print()".
120  */
121 static void note(cptr msg)
122 {
123         static int y = 2;
124
125         /* Draw the message */
126         prt(msg, y, 0);
127
128         /* Advance one line (wrap if needed) */
129         if (++y >= 24) y = 2;
130
131         /* Flush it */
132         Term_fresh();
133 }
134
135
136 /*
137  * The following functions are used to load the basic building blocks
138  * of savefiles.  They also maintain the "checksum" info for 2.7.0+
139  */
140
141 static byte sf_get(void)
142 {
143         byte c, v;
144
145         /* Get a character, decode the value */
146         c = getc(fff) & 0xFF;
147         v = c ^ xor_byte;
148         xor_byte = c;
149
150         /* Maintain the checksum info */
151         v_check += v;
152         x_check += xor_byte;
153
154         /* Return the value */
155         return (v);
156 }
157
158 static void rd_byte(byte *ip)
159 {
160         *ip = sf_get();
161 }
162
163 static void rd_u16b(u16b *ip)
164 {
165         (*ip) = sf_get();
166         (*ip) |= ((u16b)(sf_get()) << 8);
167 }
168
169 static void rd_s16b(s16b *ip)
170 {
171         rd_u16b((u16b*)ip);
172 }
173
174 static void rd_u32b(u32b *ip)
175 {
176         (*ip) = sf_get();
177         (*ip) |= ((u32b)(sf_get()) << 8);
178         (*ip) |= ((u32b)(sf_get()) << 16);
179         (*ip) |= ((u32b)(sf_get()) << 24);
180 }
181
182 static void rd_s32b(s32b *ip)
183 {
184         rd_u32b((u32b*)ip);
185 }
186
187
188 /*
189  * Hack -- read a string
190  */
191 static void rd_string(char *str, int max)
192 {
193         int i;
194
195         /* Read the string */
196         for (i = 0; TRUE; i++)
197         {
198                 byte tmp8u;
199
200                 /* Read a byte */
201                 rd_byte(&tmp8u);
202
203                 /* Collect string while legal */
204                 if (i < max) str[i] = tmp8u;
205
206                 /* End of string */
207                 if (!tmp8u) break;
208         }
209
210         /* Terminate */
211         str[max-1] = '\0';
212 #ifdef JP
213         codeconv(str);
214 #endif
215 }
216
217
218 /*
219  * Hack -- strip some bytes
220  */
221 static void strip_bytes(int n)
222 {
223         byte tmp8u;
224
225         /* Strip the bytes */
226         while (n--) rd_byte(&tmp8u);
227 }
228
229 #define OLD_MAX_MANE 22
230
231 /*
232  * Read an object
233  *
234  * This function attempts to "repair" old savefiles, and to extract
235  * the most up to date values for various object fields.
236  *
237  * Note that Angband 2.7.9 introduced a new method for object "flags"
238  * in which the "flags" on an object are actually extracted when they
239  * are needed from the object kind, artifact index, ego-item index,
240  * and two special "xtra" fields which are used to encode any "extra"
241  * power of certain ego-items.  This had the side effect that items
242  * imported from pre-2.7.9 savefiles will lose any "extra" powers they
243  * may have had, and also, all "uncursed" items will become "cursed"
244  * again, including Calris, even if it is being worn at the time.  As
245  * a complete hack, items which are inscribed with "uncursed" will be
246  * "uncursed" when imported from pre-2.7.9 savefiles.
247  */
248 static void rd_item(object_type *o_ptr)
249 {
250         char buf[128];
251
252
253         /* Kind */
254         rd_s16b(&o_ptr->k_idx);
255
256         /* Location */
257         rd_byte(&o_ptr->iy);
258         rd_byte(&o_ptr->ix);
259
260         /* Type/Subtype */
261         rd_byte(&o_ptr->tval);
262         rd_byte(&o_ptr->sval);
263
264         if (z_older_than(10, 4, 4))
265         {
266                 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
267                 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
268                 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
269         }
270
271         /* Special pval */
272         rd_s16b(&o_ptr->pval);
273
274         rd_byte(&o_ptr->discount);
275         rd_byte(&o_ptr->number);
276         rd_s16b(&o_ptr->weight);
277
278         rd_byte(&o_ptr->name1);
279         rd_byte(&o_ptr->name2);
280         rd_s16b(&o_ptr->timeout);
281
282         rd_s16b(&o_ptr->to_h);
283         rd_s16b(&o_ptr->to_d);
284         rd_s16b(&o_ptr->to_a);
285
286         rd_s16b(&o_ptr->ac);
287
288         rd_byte(&o_ptr->dd);
289         rd_byte(&o_ptr->ds);
290
291         rd_byte(&o_ptr->ident);
292
293         rd_byte(&o_ptr->marked);
294
295         /* Old flags */
296         rd_u32b(&o_ptr->art_flags1);
297         rd_u32b(&o_ptr->art_flags2);
298         rd_u32b(&o_ptr->art_flags3);
299
300         if (z_older_than(11, 0, 11))
301         {
302                 o_ptr->curse_flags = 0L;
303                 if (o_ptr->ident & 0x40)
304                 {
305                         o_ptr->curse_flags |= TRC_CURSED;
306                         if (o_ptr->art_flags3 & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
307                         if (o_ptr->art_flags3 & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
308                         if (o_ptr->name1)
309                         {
310                                 artifact_type *a_ptr = &a_info[o_ptr->name1];
311                                 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
312                                 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
313                         }
314                         else if (o_ptr->name2)
315                         {
316                                 ego_item_type *e_ptr = &e_info[o_ptr->name2];
317                                 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
318                                 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
319                         }
320                 }
321                 o_ptr->art_flags3 &= (0x1FFFFFFFL);
322         }
323         else
324         {
325                 rd_u32b(&o_ptr->curse_flags);
326         }
327
328         /* Monster holding object */
329         rd_s16b(&o_ptr->held_m_idx);
330
331         /* Special powers */
332         rd_byte(&o_ptr->xtra1);
333         rd_byte(&o_ptr->xtra2);
334
335         if (z_older_than(11, 0, 10))
336         {
337                 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
338                 {
339                         switch (o_ptr->xtra2 % 6)
340                         {
341                         case 0: o_ptr->art_flags2 |= (TR2_SUST_STR); break;
342                         case 1: o_ptr->art_flags2 |= (TR2_SUST_INT); break;
343                         case 2: o_ptr->art_flags2 |= (TR2_SUST_WIS); break;
344                         case 3: o_ptr->art_flags2 |= (TR2_SUST_DEX); break;
345                         case 4: o_ptr->art_flags2 |= (TR2_SUST_CON); break;
346                         case 5: o_ptr->art_flags2 |= (TR2_SUST_CHR); break;
347                         }
348                         o_ptr->xtra2 = 0;
349                 }
350                 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
351                 {
352                         switch (o_ptr->xtra2 % 11)
353                         {
354                         case  0: o_ptr->art_flags2 |= (TR2_RES_BLIND);  break;
355                         case  1: o_ptr->art_flags2 |= (TR2_RES_CONF);   break;
356                         case  2: o_ptr->art_flags2 |= (TR2_RES_SOUND);  break;
357                         case  3: o_ptr->art_flags2 |= (TR2_RES_SHARDS); break;
358                         case  4: o_ptr->art_flags2 |= (TR2_RES_NETHER); break;
359                         case  5: o_ptr->art_flags2 |= (TR2_RES_NEXUS);  break;
360                         case  6: o_ptr->art_flags2 |= (TR2_RES_CHAOS);  break;
361                         case  7: o_ptr->art_flags2 |= (TR2_RES_DISEN);  break;
362                         case  8: o_ptr->art_flags2 |= (TR2_RES_POIS);   break;
363                         case  9: o_ptr->art_flags2 |= (TR2_RES_DARK);   break;
364                         case 10: o_ptr->art_flags2 |= (TR2_RES_LITE);   break;
365                         }
366                         o_ptr->xtra2 = 0;
367                 }               
368                 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
369                 {
370                         switch (o_ptr->xtra2 % 8)
371                         {
372                         case 0: o_ptr->art_flags3 |= (TR3_FEATHER);     break;
373                         case 1: o_ptr->art_flags3 |= (TR3_LITE);        break;
374                         case 2: o_ptr->art_flags3 |= (TR3_SEE_INVIS);   break;
375                         case 3: o_ptr->art_flags3 |= (TR3_WARNING);     break;
376                         case 4: o_ptr->art_flags3 |= (TR3_SLOW_DIGEST); break;
377                         case 5: o_ptr->art_flags3 |= (TR3_REGEN);       break;
378                         case 6: o_ptr->art_flags2 |= (TR2_FREE_ACT);    break;
379                         case 7: o_ptr->art_flags2 |= (TR2_HOLD_LIFE);   break;
380                         }
381                         o_ptr->xtra2 = 0;
382                 }
383                 o_ptr->xtra1 = 0;
384         }
385
386         if (z_older_than(10, 2, 3))
387         {
388                 o_ptr->xtra3 = 0;
389                 o_ptr->xtra4 = 0;
390                 o_ptr->xtra5 = 0;
391                 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
392                 {
393                         o_ptr->xtra3 = o_ptr->xtra1;
394                         o_ptr->xtra1 = 0;
395                 }
396                 if (o_ptr->tval == TV_CAPTURE)
397                 {
398                         if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
399                                 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
400                         else
401                                 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
402                         if (ironman_nightmare)
403                         {
404                                 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
405                         }
406                         o_ptr->xtra4 = o_ptr->xtra5;
407                 }
408         }
409         else
410         {
411                 rd_byte(&o_ptr->xtra3);
412                 rd_s16b(&o_ptr->xtra4);
413                 rd_s16b(&o_ptr->xtra5);
414         }
415
416         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)))
417         {
418                 o_ptr->xtra4 = o_ptr->pval;
419                 o_ptr->pval = 0;
420         }
421
422         /* Feeling - from 2.3.1, "savefile version 1" */
423         if (sf_version >= 1)
424         {
425                 rd_byte(&o_ptr->feeling);
426         }
427
428         /* Inscription */
429         rd_string(buf, 128);
430
431         /* If this savefile is old, maybe we need to translate the feeling */
432         if (sf_version < 1)
433         {
434                 byte i;
435
436                 for (i = 0; i <= FEEL_MAX; i++)
437                 {
438                         if (game_inscriptions[i] == NULL)
439                         {
440                                 continue;
441                         }
442
443                         if (streq(buf, game_inscriptions[i]))
444                         {
445                                 o_ptr->feeling = i;
446                                 buf[0] = 0;
447                                 break;
448                         }
449                 }
450         }
451
452         /* Save the inscription */
453         if (buf[0]) o_ptr->inscription = quark_add(buf);
454
455         rd_string(buf, 128);
456         if (buf[0]) o_ptr->art_name = quark_add(buf);
457
458         /* The Python object */
459         {
460                 s32b tmp32s;
461
462                 rd_s32b(&tmp32s);
463                 strip_bytes(tmp32s);
464         }
465
466         /* Mega-Hack -- handle "dungeon objects" later */
467         if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
468
469         if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
470
471         if (z_older_than(10, 4, 9))
472         {
473                 if (o_ptr->art_flags1 & TR1_MAGIC_MASTERY)
474                 {
475                         o_ptr->art_flags1 &= ~(TR1_MAGIC_MASTERY);
476                         o_ptr->art_flags3 |= (TR3_DEC_MANA);
477                 }
478         }
479
480         /* Paranoia */
481         if (o_ptr->name1)
482         {
483                 artifact_type *a_ptr;
484
485                 /* Obtain the artifact info */
486                 a_ptr = &a_info[o_ptr->name1];
487
488                 /* Verify that artifact */
489                 if (!a_ptr->name) o_ptr->name1 = 0;
490         }
491
492         /* Paranoia */
493         if (o_ptr->name2)
494         {
495                 ego_item_type *e_ptr;
496
497                 /* Obtain the ego-item info */
498                 e_ptr = &e_info[o_ptr->name2];
499
500                 /* Verify that ego-item */
501                 if (!e_ptr->name) o_ptr->name2 = 0;
502
503         }
504 }
505
506
507
508
509 /*
510  * Read a monster
511  */
512 static void rd_monster(monster_type *m_ptr)
513 {
514         byte tmp8u;
515         char buf[128];
516
517         /* Read the monster race */
518         rd_s16b(&m_ptr->r_idx);
519
520         if (z_older_than(11, 0, 12))
521                 m_ptr->ap_r_idx = m_ptr->r_idx;
522         else
523                 rd_s16b(&m_ptr->ap_r_idx);
524
525         if (z_older_than(11, 0, 14))
526         {
527                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
528
529                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
530                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
531                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
532         }
533         else
534                 rd_byte(&m_ptr->sub_align);
535
536         /* Read the other information */
537         rd_byte(&m_ptr->fy);
538         rd_byte(&m_ptr->fx);
539         rd_s16b(&m_ptr->hp);
540         rd_s16b(&m_ptr->maxhp);
541         if (z_older_than(11, 0, 5))
542         {
543                 m_ptr->max_maxhp = m_ptr->maxhp;
544         }
545         else
546         {
547                 rd_s16b(&m_ptr->max_maxhp);
548         }
549         rd_s16b(&m_ptr->csleep);
550         rd_byte(&m_ptr->mspeed);
551         if (z_older_than(10, 4, 2))
552         {
553                 rd_byte(&tmp8u);
554                 m_ptr->energy_need = (s16b)tmp8u;
555         }
556         else rd_s16b(&m_ptr->energy_need);
557
558         if (z_older_than(11, 0, 13))
559                 m_ptr->energy_need = 100 - m_ptr->energy_need;
560
561         if (z_older_than(10,0,7))
562         {
563                 m_ptr->fast = 0;
564                 m_ptr->slow = 0;
565         }
566         else
567         {
568                 rd_byte(&m_ptr->fast);
569                 rd_byte(&m_ptr->slow);
570         }
571         rd_byte(&m_ptr->stunned);
572         rd_byte(&m_ptr->confused);
573         rd_byte(&m_ptr->monfear);
574
575         if (z_older_than(10,0,10))
576         {
577                 reset_target(m_ptr);
578         }
579         else if (z_older_than(10,0,11))
580         {
581                 s16b tmp16s;
582                 rd_s16b(&tmp16s);
583                 reset_target(m_ptr);
584         }
585         else
586         {
587                 rd_s16b(&m_ptr->target_y);
588                 rd_s16b(&m_ptr->target_x);
589         }
590
591         /* Monster invulnerability introduced from 2.3.2+ */
592         if (sf_version < 2)
593                 m_ptr->invulner = 0;
594         else
595                 rd_byte(&m_ptr->invulner);
596
597         if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
598                 rd_u32b(&m_ptr->smart);
599         else
600                 m_ptr->smart = 0;
601
602         if (z_older_than(10, 4, 5))
603                 m_ptr->exp = 0;
604         else
605                 rd_u32b(&m_ptr->exp);
606
607         if (z_older_than(10, 2, 2))
608         {
609                 if (m_ptr->r_idx < 0)
610                 {
611                         m_ptr->r_idx = (0-m_ptr->r_idx);
612                         m_ptr->mflag2 |= MFLAG_KAGE;
613                 }
614         }
615         else
616         {
617                 rd_byte(&m_ptr->mflag2);
618         }
619
620         if (z_older_than(11, 0, 12))
621         {
622                 if (m_ptr->mflag2 & MFLAG_KAGE)
623                         m_ptr->ap_r_idx = MON_KAGE;
624         }
625
626         if (z_older_than(10, 1, 3))
627         {
628                 m_ptr->nickname = 0;
629         }
630         else
631         {
632                 rd_string(buf, 128);
633                 if (buf[0]) m_ptr->nickname = quark_add(buf);
634         }
635
636         rd_byte(&tmp8u);
637 }
638
639
640
641
642
643 /*
644  * Read the monster lore
645  */
646 static void rd_lore(int r_idx)
647 {
648         byte tmp8u;
649
650         monster_race *r_ptr = &r_info[r_idx];
651
652         /* Count sights/deaths/kills */
653         rd_s16b(&r_ptr->r_sights);
654         rd_s16b(&r_ptr->r_deaths);
655         rd_s16b(&r_ptr->r_pkills);
656         rd_s16b(&r_ptr->r_tkills);
657
658         /* Count wakes and ignores */
659         rd_byte(&r_ptr->r_wake);
660         rd_byte(&r_ptr->r_ignore);
661
662         /* Extra stuff */
663         rd_byte(&r_ptr->r_xtra1);
664         rd_byte(&r_ptr->r_xtra2);
665
666         /* Count drops */
667         rd_byte(&r_ptr->r_drop_gold);
668         rd_byte(&r_ptr->r_drop_item);
669
670         /* Count spells */
671         rd_byte(&r_ptr->r_cast_inate);
672         rd_byte(&r_ptr->r_cast_spell);
673
674         /* Count blows of each type */
675         rd_byte(&r_ptr->r_blows[0]);
676         rd_byte(&r_ptr->r_blows[1]);
677         rd_byte(&r_ptr->r_blows[2]);
678         rd_byte(&r_ptr->r_blows[3]);
679
680         /* Memorize flags */
681         rd_u32b(&r_ptr->r_flags1);
682         rd_u32b(&r_ptr->r_flags2);
683         rd_u32b(&r_ptr->r_flags3);
684         rd_u32b(&r_ptr->r_flags4);
685         rd_u32b(&r_ptr->r_flags5);
686         rd_u32b(&r_ptr->r_flags6);
687
688         /* Read the "Racial" monster limit per level */
689         rd_byte(&r_ptr->max_num);
690
691         /* Later (?) */
692         rd_byte(&tmp8u);
693         rd_byte(&tmp8u);
694         rd_byte(&tmp8u);
695
696         /* Repair the lore flags */
697         r_ptr->r_flags1 &= r_ptr->flags1;
698         r_ptr->r_flags2 &= r_ptr->flags2;
699         r_ptr->r_flags3 &= r_ptr->flags3;
700         r_ptr->r_flags4 &= r_ptr->flags4;
701         r_ptr->r_flags5 &= r_ptr->flags5;
702         r_ptr->r_flags6 &= r_ptr->flags6;
703 }
704
705
706
707
708 /*
709  * Add the item "o_ptr" to the inventory of the "Home"
710  *
711  * In all cases, return the slot (or -1) where the object was placed
712  *
713  * Note that this is a hacked up version of "inven_carry()".
714  *
715  * Also note that it may not correctly "adapt" to "knowledge" bacoming
716  * known, the player may have to pick stuff up and drop it again.
717  */
718 static void home_carry(store_type *st_ptr, object_type *o_ptr)
719 {
720         int                             slot;
721         s32b                       value, j_value;
722         int     i;
723         object_type *j_ptr;
724
725
726         /* Check each existing item (try to combine) */
727         for (slot = 0; slot < st_ptr->stock_num; slot++)
728         {
729                 /* Get the existing item */
730                 j_ptr = &st_ptr->stock[slot];
731
732                 /* The home acts just like the player */
733                 if (object_similar(j_ptr, o_ptr))
734                 {
735                         /* Save the new number of items */
736                         object_absorb(j_ptr, o_ptr);
737
738                         /* All done */
739                         return;
740                 }
741         }
742
743         /* No space? */
744         if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
745                 return;
746         }
747
748         /* Determine the "value" of the item */
749         value = object_value(o_ptr);
750
751         /* Check existing slots to see if we must "slide" */
752         for (slot = 0; slot < st_ptr->stock_num; slot++)
753         {
754                 /* Get that item */
755                 j_ptr = &st_ptr->stock[slot];
756
757                 /* Hack -- readable books always come first */
758                 if ((o_ptr->tval == mp_ptr->spell_book) &&
759                         (j_ptr->tval != mp_ptr->spell_book)) break;
760                 if ((j_ptr->tval == mp_ptr->spell_book) &&
761                         (o_ptr->tval != mp_ptr->spell_book)) continue;
762
763                 /* Objects sort by decreasing type */
764                 if (o_ptr->tval > j_ptr->tval) break;
765                 if (o_ptr->tval < j_ptr->tval) continue;
766
767                 /* Can happen in the home */
768                 if (!object_aware_p(o_ptr)) continue;
769                 if (!object_aware_p(j_ptr)) break;
770
771                 /* Objects sort by increasing sval */
772                 if (o_ptr->sval < j_ptr->sval) break;
773                 if (o_ptr->sval > j_ptr->sval) continue;
774
775                 /* Objects in the home can be unknown */
776                 if (!object_known_p(o_ptr)) continue;
777                 if (!object_known_p(j_ptr)) break;
778
779                 /*
780                  * Hack:  otherwise identical rods sort by
781                  * increasing recharge time --dsb
782                  */
783                 if (o_ptr->tval == TV_ROD)
784                 {
785                         if (o_ptr->pval < j_ptr->pval) break;
786                         if (o_ptr->pval > j_ptr->pval) continue;
787                 }
788
789                 /* Objects sort by decreasing value */
790                 j_value = object_value(j_ptr);
791                 if (value > j_value) break;
792                 if (value < j_value) continue;
793         }
794
795         /* Slide the others up */
796         for (i = st_ptr->stock_num; i > slot; i--)
797         {
798                 st_ptr->stock[i] = st_ptr->stock[i-1];
799         }
800
801         /* More stuff now */
802         st_ptr->stock_num++;
803
804         /* Insert the new item */
805         st_ptr->stock[slot] = *o_ptr;
806
807         chg_virtue(V_SACRIFICE, -1);
808
809         /* Return the location */
810         return;
811 }
812
813
814 /*
815  * Read a store
816  */
817 static errr rd_store(int town_number, int store_number)
818 {
819         store_type *st_ptr;
820
821         int j;
822
823         byte own;
824         byte tmp8u;
825         s16b num;
826
827         bool sort = FALSE;
828
829         if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
830         {
831                 st_ptr = &town[1].store[store_number];
832                 if (st_ptr->stock_num) sort = TRUE;
833         }
834         else
835         {
836                 st_ptr = &town[town_number].store[store_number];
837         }
838
839         /* Read the basic info */
840         rd_s32b(&st_ptr->store_open);
841         rd_s16b(&st_ptr->insult_cur);
842         rd_byte(&own);
843         if (z_older_than(11, 0, 4))
844         {
845                 rd_byte(&tmp8u);
846                 num = tmp8u;
847         }
848         else
849         {
850                 rd_s16b(&num);
851         }
852         rd_s16b(&st_ptr->good_buy);
853         rd_s16b(&st_ptr->bad_buy);
854
855         /* Read last visit */
856         rd_s32b(&st_ptr->last_visit);
857
858         /* Extract the owner (see above) */
859         st_ptr->owner = own;
860
861         /* Read the items */
862         for (j = 0; j < num; j++)
863         {
864                 object_type forge;
865                 object_type *q_ptr;
866
867                 /* Get local object */
868                 q_ptr = &forge;
869
870                 /* Wipe the object */
871                 object_wipe(q_ptr);
872
873                 /* Read the item */
874                 rd_item(q_ptr);
875
876                 /* Acquire valid items */
877                 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
878                 {
879                         int k;
880                         if (sort)
881                         {
882                                 home_carry(st_ptr, q_ptr);
883                         }
884                         else
885                         {
886                                 k = st_ptr->stock_num++;
887
888                                 /* Acquire the item */
889                                 object_copy(&st_ptr->stock[k], q_ptr);
890                         }
891                 }
892         }
893
894         /* Success */
895         return (0);
896 }
897
898
899
900 /*
901  * Read RNG state (added in 2.8.0)
902  */
903 static void rd_randomizer(void)
904 {
905         int i;
906
907         u16b tmp16u;
908
909         /* Tmp */
910         rd_u16b(&tmp16u);
911
912         /* Place */
913         rd_u16b(&Rand_place);
914
915         /* State */
916         for (i = 0; i < RAND_DEG; i++)
917         {
918                 rd_u32b(&Rand_state[i]);
919         }
920
921         /* Accept */
922         Rand_quick = FALSE;
923 }
924
925
926
927 /*
928  * Read options (ignore most pre-2.8.0 options)
929  *
930  * Note that the normal options are now stored as a set of 256 bit flags,
931  * plus a set of 256 bit masks to indicate which bit flags were defined
932  * at the time the savefile was created.  This will allow new options
933  * to be added, and old options to be removed, at any time, without
934  * hurting old savefiles.
935  *
936  * The window options are stored in the same way, but note that each
937  * window gets 32 options, and their order is fixed by certain defines.
938  */
939 static void rd_options(void)
940 {
941         int i, n;
942
943         byte b;
944
945         u16b c;
946
947         u32b flag[8];
948         u32b mask[8];
949
950
951         /*** Oops ***/
952
953         /* Ignore old options */
954         strip_bytes(16);
955
956
957         /*** Special info */
958
959         /* Read "delay_factor" */
960         rd_byte(&b);
961         delay_factor = b;
962
963         /* Read "hitpoint_warn" */
964         rd_byte(&b);
965         hitpoint_warn = b;
966
967
968         /*** Cheating options ***/
969
970         rd_u16b(&c);
971
972         if (c & 0x0002) p_ptr->wizard = TRUE;
973
974         cheat_peek = (c & 0x0100) ? TRUE : FALSE;
975         cheat_hear = (c & 0x0200) ? TRUE : FALSE;
976         cheat_room = (c & 0x0400) ? TRUE : FALSE;
977         cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
978         cheat_know = (c & 0x1000) ? TRUE : FALSE;
979         cheat_live = (c & 0x2000) ? TRUE : FALSE;
980
981         rd_byte((byte *)&autosave_l);
982         rd_byte((byte *)&autosave_t);
983         rd_s16b(&autosave_freq);
984
985
986         /*** Normal Options ***/
987
988         /* Read the option flags */
989         for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
990
991         /* Read the option masks */
992         for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
993
994         /* Analyze the options */
995         for (n = 0; n < 8; n++)
996         {
997                 /* Analyze the options */
998                 for (i = 0; i < 32; i++)
999                 {
1000                         /* Process valid flags */
1001                         if (mask[n] & (1L << i))
1002                         {
1003                                 /* Process valid flags */
1004                                 if (option_mask[n] & (1L << i))
1005                                 {
1006                                         /* Set */
1007                                         if (flag[n] & (1L << i))
1008                                         {
1009                                                 /* Set */
1010                                                 option_flag[n] |= (1L << i);
1011                                         }
1012
1013                                         /* Clear */
1014                                         else
1015                                         {
1016                                                 /* Clear */
1017                                                 option_flag[n] &= ~(1L << i);
1018                                         }
1019                                 }
1020                         }
1021                 }
1022         }
1023
1024         if (z_older_than(10, 4, 5))
1025         {
1026                 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1027                 else option_flag[5] |= (0x00000001 << 4);
1028                 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1029                 else option_flag[2] |= (0x00000001 << 5);
1030                 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1031                 else option_flag[4] |= (0x00000001 << 5);
1032                 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1033                 else option_flag[5] |= (0x00000001 << 0);
1034                 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1035                 else option_flag[5] |= (0x00000001 << 12);
1036                 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1037                 else option_flag[1] |= (0x00000001 << 0);
1038                 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1039                 else option_flag[1] |= (0x00000001 << 18);
1040                 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1041                 else option_flag[1] |= (0x00000001 << 19);
1042                 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1043                 else option_flag[5] |= (0x00000001 << 3);
1044         }
1045
1046
1047         /*** Window Options ***/
1048
1049         /* Read the window flags */
1050         for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1051
1052         /* Read the window masks */
1053         for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1054
1055         /* Analyze the options */
1056         for (n = 0; n < 8; n++)
1057         {
1058                 /* Analyze the options */
1059                 for (i = 0; i < 32; i++)
1060                 {
1061                         /* Process valid flags */
1062                         if (mask[n] & (1L << i))
1063                         {
1064                                 /* Process valid flags */
1065                                 if (window_mask[n] & (1L << i))
1066                                 {
1067                                         /* Set */
1068                                         if (flag[n] & (1L << i))
1069                                         {
1070                                                 /* Set */
1071                                                 window_flag[n] |= (1L << i);
1072                                         }
1073
1074                                         /* Clear */
1075                                         else
1076                                         {
1077                                                 /* Clear */
1078                                                 window_flag[n] &= ~(1L << i);
1079                                         }
1080                                 }
1081                         }
1082                 }
1083         }
1084 }
1085
1086
1087
1088
1089
1090 /*
1091  * Hack -- strip the "ghost" info
1092  *
1093  * XXX XXX XXX This is such a nasty hack it hurts.
1094  */
1095 static void rd_ghost(void)
1096 {
1097         char buf[64];
1098
1099         /* Strip name */
1100         rd_string(buf, 64);
1101
1102         /* Strip old data */
1103         strip_bytes(60);
1104 }
1105
1106
1107 /*
1108  * Save quick start data
1109  */
1110 static void load_quick_start(void)
1111 {
1112         byte tmp8u;
1113         int i;
1114
1115         if (z_older_than(11, 0, 13))
1116         {
1117                 previous_char.quick_ok = FALSE;
1118                 return;
1119         }
1120
1121         rd_byte(&previous_char.psex);
1122         rd_byte(&previous_char.prace);
1123         rd_byte(&previous_char.pclass);
1124         rd_byte(&previous_char.pseikaku);
1125         rd_byte(&previous_char.realm1);
1126         rd_byte(&previous_char.realm2);
1127
1128         rd_s16b(&previous_char.age);
1129         rd_s16b(&previous_char.ht);
1130         rd_s16b(&previous_char.wt);
1131         rd_s16b(&previous_char.sc);
1132         rd_s32b(&previous_char.au);
1133
1134         for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1135         for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1136
1137         for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1138
1139         rd_s16b(&previous_char.chaos_patron);
1140
1141         for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1142
1143         for (i = 0; i < 4; i++) rd_string(previous_char.history[i], 60);
1144
1145         rd_byte(&previous_char.quests);
1146
1147         rd_byte(&tmp8u);
1148         previous_char.quick_ok = (bool)tmp8u;
1149 }
1150
1151 /*
1152  * Read the "extra" information
1153  */
1154 static void rd_extra(void)
1155 {
1156         int i,j;
1157
1158         byte tmp8u;
1159         s16b tmp16s;
1160
1161         rd_string(player_name, 32);
1162
1163         rd_string(p_ptr->died_from, 80);
1164
1165         load_quick_start();
1166
1167         for (i = 0; i < 4; i++)
1168         {
1169                 rd_string(p_ptr->history[i], 60);
1170         }
1171
1172         /* Class/Race/Seikaku/Gender/Spells */
1173         rd_byte(&p_ptr->prace);
1174         rd_byte(&p_ptr->pclass);
1175         rd_byte(&p_ptr->pseikaku);
1176         rd_byte(&p_ptr->psex);
1177         rd_byte(&p_ptr->realm1);
1178         rd_byte(&p_ptr->realm2);
1179         rd_byte(&tmp8u); /* oops */
1180
1181         if (z_older_than(10, 4, 4))
1182         {
1183                 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1184                 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1185                 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1186                 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1187         }
1188
1189         /* Special Race/Class info */
1190         rd_byte(&p_ptr->hitdie);
1191         rd_u16b(&p_ptr->expfact);
1192
1193         /* Age/Height/Weight */
1194         rd_s16b(&p_ptr->age);
1195         rd_s16b(&p_ptr->ht);
1196         rd_s16b(&p_ptr->wt);
1197
1198         /* Read the stat info */
1199         for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1200         for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1201         for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1202
1203         strip_bytes(24); /* oops */
1204
1205         rd_s32b(&p_ptr->au);
1206
1207         rd_s32b(&p_ptr->max_exp);
1208         rd_s32b(&p_ptr->exp);
1209         rd_u16b(&p_ptr->exp_frac);
1210
1211         rd_s16b(&p_ptr->lev);
1212
1213         for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1214         if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1215         {
1216                 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = 1600;
1217         }
1218         if (z_older_than(10, 3, 6))
1219                 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1220         else
1221                 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1222         for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1223         if (z_older_than(10, 4, 1))
1224         {
1225                 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1226                 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1227         }
1228         if (z_older_than(10, 3, 14))
1229         {
1230                 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1231                 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1232         }
1233         else
1234         {
1235                 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1236                 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1237         }
1238         if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1239
1240         if (z_older_than(11, 0, 7))
1241         {
1242                 p_ptr->start_race = p_ptr->prace;
1243                 p_ptr->old_race1 = 0L;
1244                 p_ptr->old_race2 = 0L;
1245                 p_ptr->old_realm = 0;
1246         }
1247         else
1248         {
1249                 rd_byte(&p_ptr->start_race);
1250                 rd_s32b(&p_ptr->old_race1);
1251                 rd_s32b(&p_ptr->old_race2);
1252                 rd_s16b(&p_ptr->old_realm);
1253         }
1254
1255         if (z_older_than(10, 0, 1))
1256         {
1257                 for (i = 0; i < OLD_MAX_MANE; i++)
1258                 {
1259                         p_ptr->mane_spell[i] = -1;
1260                         p_ptr->mane_dam[i] = 0;
1261                 }
1262                 p_ptr->mane_num = 0;
1263         }
1264         else if (z_older_than(10, 2, 3))
1265         {
1266                 for (i = 0; i < OLD_MAX_MANE; i++)
1267                 {
1268                         rd_s16b(&tmp16s);
1269                         rd_s16b(&tmp16s);
1270                 }
1271                 for (i = 0; i < MAX_MANE; i++)
1272                 {
1273                         p_ptr->mane_spell[i] = -1;
1274                         p_ptr->mane_dam[i] = 0;
1275                 }
1276                 rd_s16b(&tmp16s);
1277                 p_ptr->mane_num = 0;
1278         }
1279         else
1280         {
1281                 for (i = 0; i < MAX_MANE; i++)
1282                 {
1283                         rd_s16b(&p_ptr->mane_spell[i]);
1284                         rd_s16b(&p_ptr->mane_dam[i]);
1285                 }
1286                 rd_s16b(&p_ptr->mane_num);
1287         }
1288
1289         if (z_older_than(10, 0, 3))
1290         {
1291                 get_mon_num_prep(NULL, NULL);
1292                 for (i = 0; i < MAX_KUBI; i++)
1293                 {
1294                         monster_race *r_ptr;
1295                         while (1)
1296                         {
1297                                 int j;
1298
1299                                 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1300                                 r_ptr = &r_info[kubi_r_idx[i]];
1301
1302                                 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1303
1304                                 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1305
1306                                 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1307
1308                                 for (j = 0; j < i; j++)
1309                                         if (kubi_r_idx[i] == kubi_r_idx[j])break;
1310
1311                                 if (j == i) break;
1312                         }
1313                 }
1314                 for (i = 0; i < MAX_KUBI -1; i++)
1315                 {
1316                         int j,tmp;
1317                         for (j = i; j < MAX_KUBI; j++)
1318                         {
1319                                 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1320                                 {
1321                                         tmp = kubi_r_idx[i];
1322                                         kubi_r_idx[i] = kubi_r_idx[j];
1323                                         kubi_r_idx[j] = tmp;
1324                                 }
1325                         }
1326                 }
1327                 for (i = 0; i < MAX_KUBI; i++)
1328                 {
1329                         if(!r_info[kubi_r_idx[i]].max_num)
1330                                 kubi_r_idx[i] += 10000;
1331                 }
1332         }
1333         else
1334         {
1335                 for (i = 0; i < MAX_KUBI; i++)
1336                 {
1337                         rd_s16b(&kubi_r_idx[i]);
1338                 }
1339         }
1340
1341         if (z_older_than(10, 0, 3))
1342         {
1343                 battle_monsters();
1344         }
1345         else
1346         {
1347                 for (i = 0; i < 4; i++)
1348                 {
1349                         rd_s16b(&battle_mon[i]);
1350                         if (z_older_than(10, 3, 4))
1351                         {
1352                                 rd_s16b(&tmp16s);
1353                                 mon_odds[i] = tmp16s;
1354                         }
1355                         else rd_u32b(&mon_odds[i]);
1356                 }
1357         }
1358
1359         rd_s16b(&p_ptr->town_num);
1360
1361         /* Read arena and rewards information */
1362         rd_s16b(&p_ptr->arena_number);
1363         rd_s16b(&tmp16s);
1364         p_ptr->inside_arena = (bool)tmp16s;
1365         rd_s16b(&p_ptr->inside_quest);
1366         if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1367         else
1368         {
1369                 rd_s16b(&tmp16s);
1370                 p_ptr->inside_battle = (bool)tmp16s;
1371         }
1372         rd_byte(&p_ptr->exit_bldg);
1373         rd_byte(&p_ptr->leftbldg);
1374
1375         rd_s16b(&p_ptr->oldpx);
1376         rd_s16b(&p_ptr->oldpy);
1377         if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1378
1379         rd_s16b(&tmp16s);
1380
1381         if (tmp16s > MAX_BACT)
1382         {
1383 #ifdef JP
1384 note(format("¤ÎÃæ", tmp16s));
1385 #else
1386                 note(format("Too many (%d) building rewards!", tmp16s));
1387 #endif
1388
1389         }
1390
1391         for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1392
1393         rd_s16b(&p_ptr->mhp);
1394         rd_s16b(&p_ptr->chp);
1395         rd_u16b(&p_ptr->chp_frac);
1396
1397         rd_s16b(&p_ptr->msp);
1398         rd_s16b(&p_ptr->csp);
1399         rd_u16b(&p_ptr->csp_frac);
1400
1401         rd_s16b(&p_ptr->max_plv);
1402         if (z_older_than(10, 3, 8))
1403         {
1404                 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1405         }
1406         else
1407         {
1408                 byte max = (byte)max_d_idx;
1409
1410                 rd_byte(&max);
1411
1412                 for(i = 0; i < max; i++)
1413                 {
1414                         rd_s16b(&max_dlv[i]);
1415                         if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1416                 }
1417         }
1418
1419         /* Repair maximum player level XXX XXX XXX */
1420         if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1421
1422         /* More info */
1423         strip_bytes(8);
1424         rd_s16b(&p_ptr->sc);
1425         strip_bytes(2);
1426
1427         /* Read the flags */
1428         strip_bytes(2); /* Old "rest" */
1429         rd_s16b(&p_ptr->blind);
1430         rd_s16b(&p_ptr->paralyzed);
1431         rd_s16b(&p_ptr->confused);
1432         rd_s16b(&p_ptr->food);
1433         strip_bytes(4); /* Old "food_digested" / "protection" */
1434
1435         rd_s16b(&p_ptr->energy_need);
1436         if (z_older_than(11, 0, 13))
1437                 p_ptr->energy_need = 100 - p_ptr->energy_need;
1438
1439         rd_s16b(&p_ptr->fast);
1440         rd_s16b(&p_ptr->slow);
1441         rd_s16b(&p_ptr->afraid);
1442         rd_s16b(&p_ptr->cut);
1443         rd_s16b(&p_ptr->stun);
1444         rd_s16b(&p_ptr->poisoned);
1445         rd_s16b(&p_ptr->image);
1446         rd_s16b(&p_ptr->protevil);
1447         rd_s16b(&p_ptr->invuln);
1448         if(z_older_than(10, 0, 0))
1449                 p_ptr->ult_res = 0;
1450         else
1451                 rd_s16b(&p_ptr->ult_res);
1452         rd_s16b(&p_ptr->hero);
1453         rd_s16b(&p_ptr->shero);
1454         rd_s16b(&p_ptr->shield);
1455         rd_s16b(&p_ptr->blessed);
1456         rd_s16b(&p_ptr->tim_invis);
1457         rd_s16b(&p_ptr->word_recall);
1458         if (z_older_than(10, 3, 8))
1459                 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1460         else
1461         {
1462                 rd_s16b(&tmp16s);
1463                 p_ptr->recall_dungeon = (byte)tmp16s;
1464         }
1465         rd_s16b(&p_ptr->see_infra);
1466         rd_s16b(&p_ptr->tim_infra);
1467         rd_s16b(&p_ptr->oppose_fire);
1468         rd_s16b(&p_ptr->oppose_cold);
1469         rd_s16b(&p_ptr->oppose_acid);
1470         rd_s16b(&p_ptr->oppose_elec);
1471         rd_s16b(&p_ptr->oppose_pois);
1472         if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1473         else rd_s16b(&p_ptr->tsuyoshi);
1474
1475         /* Old savefiles do not have the following fields... */
1476         if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1477         {
1478                 p_ptr->tim_esp = 0;
1479                 p_ptr->wraith_form = 0;
1480                 p_ptr->resist_magic = 0;
1481                 p_ptr->tim_regen = 0;
1482                 p_ptr->kabenuke = 0;
1483                 p_ptr->tim_stealth = 0;
1484                 p_ptr->tim_ffall = 0;
1485                 p_ptr->tim_sh_touki = 0;
1486                 p_ptr->lightspeed = 0;
1487                 p_ptr->tsubureru = 0;
1488                 p_ptr->tim_res_nether = 0;
1489                 p_ptr->tim_res_time = 0;
1490                 p_ptr->mimic_form = 0;
1491                 p_ptr->tim_mimic = 0;
1492                 p_ptr->tim_sh_fire = 0;
1493
1494                 /* by henkma */
1495                 p_ptr->tim_reflect = 0;
1496                 p_ptr->multishadow = 0;
1497                 p_ptr->dustrobe = 0;
1498
1499                 p_ptr->chaos_patron = get_chaos_patron();
1500                 p_ptr->muta1 = 0;
1501                 p_ptr->muta2 = 0;
1502                 p_ptr->muta3 = 0;
1503                 get_virtues();
1504         }
1505         else
1506         {
1507                 rd_s16b(&p_ptr->tim_esp);
1508                 rd_s16b(&p_ptr->wraith_form);
1509                 rd_s16b(&p_ptr->resist_magic);
1510                 rd_s16b(&p_ptr->tim_regen);
1511                 rd_s16b(&p_ptr->kabenuke);
1512                 rd_s16b(&p_ptr->tim_stealth);
1513                 rd_s16b(&p_ptr->tim_ffall);
1514                 rd_s16b(&p_ptr->tim_sh_touki);
1515                 rd_s16b(&p_ptr->lightspeed);
1516                 rd_s16b(&p_ptr->tsubureru);
1517                 if (z_older_than(10, 4, 7))
1518                         p_ptr->magicdef = 0;
1519                 else
1520                         rd_s16b(&p_ptr->magicdef);
1521                 rd_s16b(&p_ptr->tim_res_nether);
1522                 if (z_older_than(10, 4, 11))
1523                 {
1524                         p_ptr->tim_res_time = 0;
1525                         p_ptr->mimic_form = 0;
1526                         p_ptr->tim_mimic = 0;
1527                         p_ptr->tim_sh_fire = 0;
1528                 }
1529                 else
1530                 {
1531                         rd_s16b(&p_ptr->tim_res_time);
1532                         rd_byte(&p_ptr->mimic_form);
1533                         rd_s16b(&p_ptr->tim_mimic);
1534                         rd_s16b(&p_ptr->tim_sh_fire);
1535                 }
1536
1537                 if (z_older_than(11, 0, 99))
1538                 {
1539                         p_ptr->tim_sh_holy = 0;
1540                         p_ptr->tim_eyeeye = 0;
1541                 }
1542                 else
1543                 {
1544                         rd_s16b(&p_ptr->tim_sh_holy);
1545                         rd_s16b(&p_ptr->tim_eyeeye);
1546                 }
1547
1548                 /* by henkma */
1549                 if ( z_older_than(11,0,3) ){
1550                   p_ptr->tim_reflect=0;
1551                   p_ptr->multishadow=0;
1552                   p_ptr->dustrobe=0;
1553                 }
1554                 else {
1555                   rd_s16b(&p_ptr->tim_reflect);
1556                   rd_s16b(&p_ptr->multishadow);
1557                   rd_s16b(&p_ptr->dustrobe);
1558                 }
1559
1560                 rd_s16b(&p_ptr->chaos_patron);
1561                 rd_u32b(&p_ptr->muta1);
1562                 rd_u32b(&p_ptr->muta2);
1563                 rd_u32b(&p_ptr->muta3);
1564
1565                 for (i = 0; i < 8; i++)
1566                         rd_s16b(&p_ptr->virtues[i]);
1567                 for (i = 0; i < 8; i++)
1568                         rd_s16b(&p_ptr->vir_types[i]);
1569         }
1570
1571         /* Calc the regeneration modifier for mutations */
1572         mutant_regenerate_mod = calc_mutant_regenerate_mod();
1573
1574         if (z_older_than(10,0,9))
1575         {
1576                 rd_byte(&tmp8u);
1577                 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1578                 p_ptr->ele_attack = 0;
1579         }
1580         else
1581         {
1582                 rd_s16b(&p_ptr->ele_attack);
1583                 rd_u32b(&p_ptr->special_attack);
1584         }
1585         if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1586         else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1587         if (z_older_than(10,0,12))
1588         {
1589                 p_ptr->ele_immune = 0;
1590                 p_ptr->special_defense = 0;
1591         }
1592         else
1593         {
1594                 rd_s16b(&p_ptr->ele_immune);
1595                 rd_u32b(&p_ptr->special_defense);
1596         }
1597         rd_byte(&p_ptr->knowledge);
1598         rd_byte(&tmp8u); /* oops */
1599         rd_byte(&tmp8u); /* oops */
1600         rd_byte(&p_ptr->action);
1601         if (!z_older_than(10, 4, 3))
1602         {
1603                 rd_byte(&tmp8u);
1604                 if (tmp8u) p_ptr->action = ACTION_LEARN;
1605         }
1606         rd_byte((byte *)&preserve_mode);
1607         rd_byte((byte *)&p_ptr->wait_report_score);
1608
1609         /* Future use */
1610         for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1611
1612         /* Skip the flags */
1613         strip_bytes(12);
1614
1615
1616         /* Hack -- the two "special seeds" */
1617         rd_u32b(&seed_flavor);
1618         rd_u32b(&seed_town);
1619
1620
1621         /* Special stuff */
1622         rd_u16b(&p_ptr->panic_save);
1623         rd_u16b(&p_ptr->total_winner);
1624         rd_u16b(&p_ptr->noscore);
1625
1626
1627         /* Read "death" */
1628         rd_byte(&tmp8u);
1629         p_ptr->is_dead = tmp8u;
1630
1631         /* Read "feeling" */
1632         rd_byte(&tmp8u);
1633         feeling = tmp8u;
1634
1635         /* Turn of last "feeling" */
1636         rd_s32b(&old_turn);
1637
1638         /* Current turn */
1639         rd_s32b(&turn);
1640
1641         if (z_older_than(10, 3, 12))
1642         {
1643                 dungeon_turn = turn;
1644         }
1645         else rd_s32b(&dungeon_turn);
1646
1647         if (z_older_than(11, 0, 13))
1648         {
1649                 old_turn /= 2;
1650                 turn /= 2;
1651                 dungeon_turn /= 2;
1652         }
1653
1654         if (z_older_than(10, 3, 13))
1655         {
1656                 old_battle = turn;
1657         }
1658         else rd_s32b(&old_battle);
1659
1660         if (z_older_than(10,0,3))
1661         {
1662                 monster_race *r_ptr;
1663
1664                 while (1)
1665                 {
1666                         today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1667                         r_ptr = &r_info[today_mon];
1668                 
1669                         if (r_ptr->flags1 & RF1_UNIQUE) continue;
1670                         if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1671                         if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1672                         if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1673                         if (r_ptr->rarity > 10) continue;
1674                         if (r_ptr->level == 0) continue;
1675                         break;
1676                 }
1677
1678                 p_ptr->today_mon = 0;
1679         }
1680         else
1681         {
1682                 rd_s16b(&today_mon);
1683                 rd_s16b(&p_ptr->today_mon);
1684         }
1685
1686         if (z_older_than(10,0,7))
1687         {
1688                 p_ptr->riding = 0;
1689         }
1690         else
1691         {
1692                 rd_s16b(&p_ptr->riding);
1693         }
1694
1695         if (z_older_than(10,1,2))
1696         {
1697                 playtime = 0;
1698         }
1699         else
1700         {
1701                 rd_u32b(&playtime);
1702         }
1703
1704         if (z_older_than(10,3,9))
1705         {
1706                 p_ptr->visit = 1L;
1707         }
1708         else if (z_older_than(10, 3, 10))
1709         {
1710                 s32b tmp32s;
1711                 rd_s32b(&tmp32s);
1712                 p_ptr->visit = 1L;
1713         }
1714         else
1715         {
1716                 rd_s32b(&p_ptr->visit);
1717         }
1718         if (!z_older_than(11, 0, 5))
1719         {
1720                 rd_u32b(&p_ptr->count);
1721         }
1722 }
1723
1724
1725
1726
1727 /*
1728  * Read the player inventory
1729  *
1730  * Note that the inventory changed in Angband 2.7.4.  Two extra
1731  * pack slots were added and the equipment was rearranged.  Note
1732  * that these two features combine when parsing old save-files, in
1733  * which items from the old "aux" slot are "carried", perhaps into
1734  * one of the two new "inventory" slots.
1735  *
1736  * Note that the inventory is "re-sorted" later by "dungeon()".
1737  */
1738 static errr rd_inventory(void)
1739 {
1740         int slot = 0;
1741
1742         object_type forge;
1743         object_type *q_ptr;
1744
1745         /* No weight */
1746         p_ptr->total_weight = 0;
1747
1748         /* No items */
1749         inven_cnt = 0;
1750         equip_cnt = 0;
1751
1752         /* Read until done */
1753         while (1)
1754         {
1755                 u16b n;
1756
1757                 /* Get the next item index */
1758                 rd_u16b(&n);
1759
1760                 /* Nope, we reached the end */
1761                 if (n == 0xFFFF) break;
1762
1763                 /* Get local object */
1764                 q_ptr = &forge;
1765
1766                 /* Wipe the object */
1767                 object_wipe(q_ptr);
1768
1769                 /* Read the item */
1770                 rd_item(q_ptr);
1771
1772                 /* Hack -- verify item */
1773                 if (!q_ptr->k_idx) return (53);
1774
1775                 /* Wield equipment */
1776                 if (n >= INVEN_RARM)
1777                 {
1778                         /* Copy object */
1779                         object_copy(&inventory[n], q_ptr);
1780
1781                         /* Add the weight */
1782                         p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1783
1784                         /* One more item */
1785                         equip_cnt++;
1786                 }
1787
1788                 /* Warning -- backpack is full */
1789                 else if (inven_cnt == INVEN_PACK)
1790                 {
1791                         /* Oops */
1792 #ifdef JP
1793 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1794 #else
1795                         note("Too many items in the inventory!");
1796 #endif
1797
1798
1799                         /* Fail */
1800                         return (54);
1801                 }
1802
1803                 /* Carry inventory */
1804                 else
1805                 {
1806                         /* Get a slot */
1807                         n = slot++;
1808
1809                         /* Copy object */
1810                         object_copy(&inventory[n], q_ptr);
1811
1812                         /* Add the weight */
1813                         p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1814
1815                         /* One more item */
1816                         inven_cnt++;
1817                 }
1818         }
1819
1820         /* Success */
1821         return (0);
1822 }
1823
1824
1825
1826 /*
1827  * Read the saved messages
1828  */
1829 static void rd_messages(void)
1830 {
1831         int i;
1832         char buf[128];
1833
1834         s16b num;
1835
1836         /* Total */
1837         rd_s16b(&num);
1838
1839         /* Read the messages */
1840         for (i = 0; i < num; i++)
1841         {
1842                 /* Read the message */
1843                 rd_string(buf, 128);
1844
1845                 /* Save the message */
1846                 message_add(buf);
1847         }
1848 }
1849
1850
1851
1852 /*
1853  * Read the dungeon
1854  *
1855  * The monsters/objects must be loaded in the same order
1856  * that they were stored, since the actual indexes matter.
1857  */
1858 static errr rd_dungeon(void)
1859 {
1860         int i, y, x;
1861         int ymax, xmax;
1862         byte count;
1863         byte tmp8u;
1864         s16b tmp16s;
1865         u16b limit;
1866         cave_type *c_ptr;
1867
1868
1869         /*** Basic info ***/
1870
1871         /* Header info */
1872         rd_s16b(&dun_level);
1873         if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1874         else rd_byte(&dungeon_type);
1875
1876         /* Set the base level for old versions */
1877         base_level = dun_level;
1878
1879         rd_s16b(&base_level);
1880
1881         rd_s16b(&num_repro);
1882         rd_s16b(&tmp16s);
1883         py = (int)tmp16s;
1884         rd_s16b(&tmp16s);
1885         px = (int)tmp16s;
1886         if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1887         rd_s16b(&cur_hgt);
1888         rd_s16b(&cur_wid);
1889         rd_s16b(&tmp16s); /* max_panel_rows */
1890         rd_s16b(&tmp16s); /* max_panel_cols */
1891
1892 #if 0
1893         if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤­¤ÎÉüµìÍÑ */
1894 #endif
1895
1896         /* Maximal size */
1897         ymax = cur_hgt;
1898         xmax = cur_wid;
1899
1900
1901         /*** Run length decoding ***/
1902
1903         /* Load the dungeon data */
1904         for (x = y = 0; y < ymax; )
1905         {
1906                 /* Grab RLE info */
1907                 rd_byte(&count);
1908                 if (z_older_than(10,3,6))
1909                         rd_byte(&tmp8u);
1910                 else
1911                         rd_s16b(&tmp16s);
1912
1913                 /* Apply the RLE info */
1914                 for (i = count; i > 0; i--)
1915                 {
1916                         /* Access the cave */
1917                         c_ptr = &cave[y][x];
1918
1919                         /* Extract "info" */
1920                         if (z_older_than(10,3,6))
1921                                 c_ptr->info = tmp8u;
1922                         else c_ptr->info = tmp16s;
1923
1924                         /* Advance/Wrap */
1925                         if (++x >= xmax)
1926                         {
1927                                 /* Wrap */
1928                                 x = 0;
1929
1930                                 /* Advance/Wrap */
1931                                 if (++y >= ymax) break;
1932                         }
1933                 }
1934         }
1935
1936
1937         /*** Run length decoding ***/
1938
1939         /* Load the dungeon data */
1940         for (x = y = 0; y < ymax; )
1941         {
1942                 /* Grab RLE info */
1943                 rd_byte(&count);
1944                 rd_byte(&tmp8u);
1945
1946                 /* Apply the RLE info */
1947                 for (i = count; i > 0; i--)
1948                 {
1949                         /* Access the cave */
1950                         c_ptr = &cave[y][x];
1951
1952                         /* Extract "feat" */
1953                         c_ptr->feat = tmp8u;
1954
1955                         if (c_ptr->feat == FEAT_INVIS)
1956                         {
1957                                 c_ptr->feat = FEAT_FLOOR;
1958                                 c_ptr->info |= CAVE_TRAP;
1959                         }
1960
1961                         /* Older than 1.1.1 */
1962                         if (c_ptr->feat == FEAT_MIRROR)
1963                         {
1964                                 c_ptr->feat = FEAT_FLOOR;
1965                                 c_ptr->info |= CAVE_IN_MIRROR;
1966                         }
1967
1968                         /* Advance/Wrap */
1969                         if (++x >= xmax)
1970                         {
1971                                 /* Wrap */
1972                                 x = 0;
1973
1974                                 /* Advance/Wrap */
1975                                 if (++y >= ymax) break;
1976                         }
1977                 }
1978         }
1979
1980         /*** Run length decoding ***/
1981
1982         /* Load the dungeon data */
1983         for (x = y = 0; y < ymax; )
1984         {
1985                 /* Grab RLE info */
1986                 rd_byte(&count);
1987                 rd_byte(&tmp8u);
1988
1989                 /* Apply the RLE info */
1990                 for (i = count; i > 0; i--)
1991                 {
1992                         /* Access the cave */
1993                         c_ptr = &cave[y][x];
1994
1995                         /* Extract "feat" */
1996                         c_ptr->mimic = tmp8u;
1997
1998                         /* Advance/Wrap */
1999                         if (++x >= xmax)
2000                         {
2001                                 /* Wrap */
2002                                 x = 0;
2003
2004                                 /* Advance/Wrap */
2005                                 if (++y >= ymax) break;
2006                         }
2007                 }
2008         }
2009
2010         /*** Run length decoding ***/
2011
2012         /* Load the dungeon data */
2013         for (x = y = 0; y < ymax; )
2014         {
2015                 /* Grab RLE info */
2016                 rd_byte(&count);
2017                 rd_s16b(&tmp16s);
2018
2019                 /* Apply the RLE info */
2020                 for (i = count; i > 0; i--)
2021                 {
2022                         /* Access the cave */
2023                         c_ptr = &cave[y][x];
2024
2025                         /* Extract "feat" */
2026                         c_ptr->special = tmp16s;
2027
2028                         /* Advance/Wrap */
2029                         if (++x >= xmax)
2030                         {
2031                                 /* Wrap */
2032                                 x = 0;
2033
2034                                 /* Advance/Wrap */
2035                                 if (++y >= ymax) break;
2036                         }
2037                 }
2038         }
2039
2040         /*** Objects ***/
2041
2042         /* Read the item count */
2043         rd_u16b(&limit);
2044
2045         /* Verify maximum */
2046         if (limit >= max_o_idx)
2047         {
2048 #ifdef JP
2049 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礭¤¹¤®¤ë(%d)¡ª", limit));
2050 #else
2051                 note(format("Too many (%d) object entries!", limit));
2052 #endif
2053
2054                 return (151);
2055         }
2056
2057         /* Read the dungeon items */
2058         for (i = 1; i < limit; i++)
2059         {
2060                 int o_idx;
2061
2062                 object_type *o_ptr;
2063
2064
2065                 /* Get a new record */
2066                 o_idx = o_pop();
2067
2068                 /* Oops */
2069                 if (i != o_idx)
2070                 {
2071 #ifdef JP
2072 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2073 #else
2074                         note(format("Object allocation error (%d <> %d)", i, o_idx));
2075 #endif
2076
2077                         return (152);
2078                 }
2079
2080
2081                 /* Acquire place */
2082                 o_ptr = &o_list[o_idx];
2083
2084                 /* Read the item */
2085                 rd_item(o_ptr);
2086
2087
2088                 /* XXX XXX XXX XXX XXX */
2089
2090                 /* Monster */
2091                 if (o_ptr->held_m_idx)
2092                 {
2093                         monster_type *m_ptr;
2094
2095                         /* Monster */
2096                         m_ptr = &m_list[o_ptr->held_m_idx];
2097
2098                         /* Build a stack */
2099                         o_ptr->next_o_idx = m_ptr->hold_o_idx;
2100
2101                         /* Place the object */
2102                         m_ptr->hold_o_idx = o_idx;
2103                 }
2104
2105                 /* Dungeon */
2106                 else
2107                 {
2108                         /* Access the item location */
2109                         c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2110
2111                         /* Build a stack */
2112                         o_ptr->next_o_idx = c_ptr->o_idx;
2113
2114                         /* Place the object */
2115                         c_ptr->o_idx = o_idx;
2116                 }
2117         }
2118
2119
2120         /*** Monsters ***/
2121
2122         /* Read the monster count */
2123         rd_u16b(&limit);
2124
2125         /* Hack -- verify */
2126         if (limit >= max_m_idx)
2127         {
2128 #ifdef JP
2129 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礭¤¹¤®¤ë(%d)¡ª", limit));
2130 #else
2131                 note(format("Too many (%d) monster entries!", limit));
2132 #endif
2133
2134                 return (161);
2135         }
2136
2137         /* Read the monsters */
2138         for (i = 1; i < limit; i++)
2139         {
2140                 int m_idx;
2141
2142                 monster_type *m_ptr;
2143
2144                 monster_race *r_ptr;
2145
2146
2147                 /* Get a new record */
2148                 m_idx = m_pop();
2149
2150                 /* Oops */
2151                 if (i != m_idx)
2152                 {
2153 #ifdef JP
2154 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2155 #else
2156                         note(format("Monster allocation error (%d <> %d)", i, m_idx));
2157 #endif
2158
2159                         return (162);
2160                 }
2161
2162
2163                 /* Acquire monster */
2164                 m_ptr = &m_list[m_idx];
2165
2166                 /* Read the monster */
2167                 rd_monster(m_ptr);
2168
2169
2170                 /* Access grid */
2171                 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2172
2173                 /* Mark the location */
2174                 c_ptr->m_idx = m_idx;
2175
2176
2177                 /* Access race */
2178                 r_ptr = &r_info[m_ptr->r_idx];
2179
2180                 /* Count XXX XXX XXX */
2181                 r_ptr->cur_num++;
2182         }
2183
2184         /*** Success ***/
2185
2186         /* The dungeon is ready */
2187         if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2188                 character_dungeon = FALSE;
2189         else
2190                 character_dungeon = TRUE;
2191
2192         /* Success */
2193         return (0);
2194 }
2195
2196
2197
2198 /*
2199  * Actually read the savefile
2200  */
2201 static errr rd_savefile_new_aux(void)
2202 {
2203         int i, j;
2204         int town_count;
2205
2206         s32b wild_x_size;
2207         s32b wild_y_size;
2208
2209         byte tmp8u;
2210         u16b tmp16u;
2211         u32b tmp32u;
2212
2213 #ifdef VERIFY_CHECKSUMS
2214         u32b n_x_check, n_v_check;
2215         u32b o_x_check, o_v_check;
2216 #endif
2217
2218
2219         /* Mention the savefile version */
2220 #ifdef JP
2221 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2222 #else
2223         note(format("Loading a %d.%d.%d savefile...",
2224 #endif
2225
2226                 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2227
2228
2229         /* Strip the version bytes */
2230         strip_bytes(4);
2231
2232         /* Hack -- decrypt */
2233         xor_byte = sf_extra;
2234
2235
2236         /* Clear the checksums */
2237         v_check = 0L;
2238         x_check = 0L;
2239
2240 #if SAVEFILE_VERSION
2241         /* Read the version number of the savefile */
2242         rd_u32b(&sf_version);
2243 #endif /* SAVEFILE_VERSION */
2244
2245         /* Operating system info */
2246         rd_u32b(&sf_xtra);
2247
2248         /* Time of savefile creation */
2249         rd_u32b(&sf_when);
2250
2251         /* Number of resurrections */
2252         rd_u16b(&sf_lives);
2253
2254         /* Number of times played */
2255         rd_u16b(&sf_saves);
2256
2257
2258         /* Later use (always zero) */
2259         rd_u32b(&tmp32u);
2260
2261         /* Later use (always zero) */
2262         rd_u32b(&tmp32u);
2263
2264
2265         /* Read RNG state */
2266         rd_randomizer();
2267 #ifdef JP
2268 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2269 #else
2270         if (arg_fiddle) note("Loaded Randomizer Info");
2271 #endif
2272
2273
2274
2275         /* Then the options */
2276         rd_options();
2277 #ifdef JP
2278 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2279 #else
2280         if (arg_fiddle) note("Loaded Option Flags");
2281 #endif
2282
2283         /*
2284          * Munchkin players are marked
2285          *
2286          * XXX - should be replaced with a better method,
2287          * after the new scorefile-handling is implemented.
2288          */
2289         if (munchkin_death)
2290         {
2291                 /* Mark savefile */
2292                 p_ptr->noscore |= 0x0001;
2293         }
2294
2295         /* Then the "messages" */
2296         rd_messages();
2297 #ifdef JP
2298 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2299 #else
2300         if (arg_fiddle) note("Loaded Messages");
2301 #endif
2302
2303
2304
2305         for (i = 0; i < max_r_idx; i++)
2306         {
2307                 monster_race *r_ptr;
2308                 /* Access that monster */
2309                 r_ptr = &r_info[i];
2310
2311                 /* Hack -- Reset the death counter */
2312                 r_ptr->max_num = 100;
2313                 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2314                 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2315         }
2316
2317         /* Monster Memory */
2318         rd_u16b(&tmp16u);
2319
2320         /* Incompatible save files */
2321         if (tmp16u > max_r_idx)
2322         {
2323 #ifdef JP
2324 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2325 #else
2326                 note(format("Too many (%u) monster races!", tmp16u));
2327 #endif
2328
2329                 return (21);
2330         }
2331
2332         /* Read the available records */
2333         for (i = 0; i < tmp16u; i++)
2334         {
2335                 monster_race *r_ptr;
2336
2337                 /* Read the lore */
2338                 rd_lore(i);
2339
2340                 /* Access that monster */
2341                 r_ptr = &r_info[i];
2342         }
2343
2344 #ifdef JP
2345 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2346 #else
2347         if (arg_fiddle) note("Loaded Monster Memory");
2348 #endif
2349
2350
2351
2352         /* Object Memory */
2353         rd_u16b(&tmp16u);
2354
2355         /* Incompatible save files */
2356         if (tmp16u > max_k_idx)
2357         {
2358 #ifdef JP
2359 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2360 #else
2361                 note(format("Too many (%u) object kinds!", tmp16u));
2362 #endif
2363
2364                 return (22);
2365         }
2366
2367         /* Read the object memory */
2368         for (i = 0; i < tmp16u; i++)
2369         {
2370                 byte tmp8u;
2371                 object_kind *k_ptr = &k_info[i];
2372
2373                 rd_byte(&tmp8u);
2374
2375                 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2376                 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2377         }
2378 #ifdef JP
2379 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤Îµ­Ï¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2380 #else
2381         if (arg_fiddle) note("Loaded Object Memory");
2382 #endif
2383
2384
2385 #if 0
2386         /*
2387          * Initialize arena and rewards information
2388          */
2389         p_ptr->arena_number = 0;
2390         p_ptr->inside_arena = 0;
2391         p_ptr->inside_quest = 0;
2392         p_ptr->leftbldg = FALSE;
2393         p_ptr->exit_bldg = TRUE;
2394
2395         /* Start in town 1 */
2396         p_ptr->town_num = 1;
2397
2398         p_ptr->wilderness_x = 4;
2399         p_ptr->wilderness_y = 4;
2400
2401 #endif
2402
2403         /* Init the wilderness seeds */
2404         for (i = 0; i < max_wild_x; i++)
2405         {
2406                 for (j = 0; j < max_wild_y; j++)
2407                 {
2408                         wilderness[j][i].seed = randint0(0x10000000);
2409                 }
2410         }
2411
2412         /* 2.1.3 or newer version */
2413         {
2414                 u16b max_towns_load;
2415                 u16b max_quests_load;
2416                 byte max_rquests_load;
2417                 s16b old_inside_quest = p_ptr->inside_quest;
2418
2419                 /* Number of towns */
2420                 rd_u16b(&max_towns_load);
2421
2422                 /* Incompatible save files */
2423                 if (max_towns_load > max_towns)
2424                 {
2425 #ifdef JP
2426 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2427 #else
2428                         note(format("Too many (%u) towns!", max_towns_load));
2429 #endif
2430
2431                         return (23);
2432                 }
2433
2434                 /* Number of quests */
2435                 rd_u16b(&max_quests_load);
2436
2437                 if (z_older_than(11, 0, 7))
2438                 {
2439                         max_rquests_load = 10;
2440                 }
2441                 else
2442                 {
2443                         rd_byte(&max_rquests_load);
2444                 }
2445
2446                 /* Incompatible save files */
2447                 if (max_quests_load > max_quests)
2448                 {
2449 #ifdef JP
2450 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2451 #else
2452                         note(format("Too many (%u) quests!", max_quests_load));
2453 #endif
2454
2455                         return (23);
2456                 }
2457
2458                 for (i = 0; i < max_quests_load; i++)
2459                 {
2460                         if (i < max_quests)
2461                         {
2462                                 rd_s16b(&quest[i].status);
2463                                 rd_s16b(&quest[i].level);
2464
2465                                 if (z_older_than(11, 0, 6))
2466                                 {
2467                                         quest[i].complev = 0;
2468                                 }
2469                                 else
2470                                 {
2471                                         rd_byte(&quest[i].complev);
2472                                 }
2473
2474                                 /* Load quest status if quest is running */
2475                                 if (quest[i].status == QUEST_STATUS_TAKEN || (!z_older_than(10, 3, 14) && (quest[i].status == QUEST_STATUS_COMPLETED)) || (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST+max_rquests_load))))
2476                                 {
2477                                         rd_s16b(&quest[i].cur_num);
2478                                         rd_s16b(&quest[i].max_num);
2479                                         rd_s16b(&quest[i].type);
2480
2481                                         /* Load quest monster index */
2482                                         rd_s16b(&quest[i].r_idx);
2483
2484                                         if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2485                                         {
2486                                                 int r_idx;
2487                                                 while (1)
2488                                                 {
2489                                                          monster_race *r_ptr;
2490
2491                                                         /*
2492                                                          * Random monster 5 - 10 levels out of depth
2493                                                          * (depending on level)
2494                                                          */
2495                                                         r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
2496                                                         r_ptr = &r_info[r_idx];
2497
2498                                                         if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2499
2500                                                         if(r_ptr->flags6 & RF6_SPECIAL) continue;
2501
2502                                                         if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2503
2504                                                         if(r_ptr->flags7 & RF7_AQUATIC) continue;
2505
2506                                                         if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2507
2508                                                         /*
2509                                                          * Accept monsters that are 2 - 6 levels
2510                                                          * out of depth depending on the quest level
2511                                                          */
2512                                                         if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2513                                                 }
2514
2515                                                 quest[i].r_idx = r_idx;
2516                                         }
2517
2518                                         /* Load quest item index */
2519                                         rd_s16b(&quest[i].k_idx);
2520
2521                                         if (quest[i].k_idx)
2522                                                 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
2523
2524                                         rd_byte(&quest[i].flags);
2525
2526                                         if (z_older_than(10, 3, 11))
2527                                         {
2528                                                 if (quest[i].flags & QUEST_FLAG_PRESET)
2529                                                 {
2530                                                         quest[i].dungeon = 0;
2531                                                 }
2532                                                 else
2533                                                 {
2534                                                         init_flags = INIT_ASSIGN;
2535                                                         p_ptr->inside_quest = i;
2536
2537                                                         process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2538                                                         p_ptr->inside_quest = old_inside_quest;
2539                                                 }
2540                                         }
2541                                         else
2542                                         {
2543                                                 rd_byte(&quest[i].dungeon);
2544                                         }
2545                                         /* Mark uniques */
2546                                         if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2547                                                 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2548                                                         r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2549                                 }
2550                         }
2551                         /* Ignore the empty quests from old versions */
2552                         else
2553                         {
2554                                 /* Ignore quest status */
2555                                 strip_bytes(2);
2556
2557                                 /* Ignore quest level */
2558                                 strip_bytes(2);
2559
2560                                 /*
2561                                  * We don't have to care about the other info,
2562                                  * since status should be 0 for these quests anyway
2563                                  */
2564                         }
2565                 }
2566
2567                 /* Position in the wilderness */
2568                 rd_s32b(&p_ptr->wilderness_x);
2569                 rd_s32b(&p_ptr->wilderness_y);
2570                 if (z_older_than(10, 3, 13))
2571                 {
2572                         p_ptr->wilderness_x = 5;
2573                         p_ptr->wilderness_y = 48;
2574                 }
2575
2576                 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2577                 else rd_byte((byte *)&p_ptr->wild_mode);
2578                 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2579                 else rd_byte((byte *)&ambush_flag);
2580
2581                 /* Size of the wilderness */
2582                 rd_s32b(&wild_x_size);
2583                 rd_s32b(&wild_y_size);
2584
2585                 /* Incompatible save files */
2586                 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2587                 {
2588 #ifdef JP
2589 note(format("¹ÓÌÂ礭¤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2590 #else
2591                         note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2592 #endif
2593
2594                         return (23);
2595                 }
2596
2597                 /* Load the wilderness seeds */
2598                 for (i = 0; i < wild_x_size; i++)
2599                 {
2600                         for (j = 0; j < wild_y_size; j++)
2601                         {
2602                                 rd_u32b(&wilderness[j][i].seed);
2603                         }
2604                 }
2605         }
2606
2607 #ifdef JP
2608 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2609 #else
2610         if (arg_fiddle) note("Loaded Quests");
2611 #endif
2612
2613         /* Load the Artifacts */
2614         rd_u16b(&tmp16u);
2615
2616         /* Incompatible save files */
2617         if (tmp16u > max_a_idx)
2618         {
2619 #ifdef JP
2620 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2621 #else
2622                 note(format("Too many (%u) artifacts!", tmp16u));
2623 #endif
2624
2625                 return (24);
2626         }
2627
2628         /* Read the artifact flags */
2629         for (i = 0; i < tmp16u; i++)
2630         {
2631                 rd_byte(&tmp8u);
2632                 a_info[i].cur_num = tmp8u;
2633                 rd_byte(&tmp8u);
2634                 rd_byte(&tmp8u);
2635                 rd_byte(&tmp8u);
2636         }
2637 #ifdef JP
2638 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2639 #else
2640         if (arg_fiddle) note("Loaded Artifacts");
2641 #endif
2642
2643
2644
2645         /* Read the extra stuff */
2646         rd_extra();
2647         if (p_ptr->energy_need < -999) world_player = TRUE;
2648
2649 #ifdef JP
2650 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2651 #else
2652         if (arg_fiddle) note("Loaded extra information");
2653 #endif
2654
2655
2656         /* Read the player_hp array */
2657         rd_u16b(&tmp16u);
2658
2659         /* Incompatible save files */
2660         if (tmp16u > PY_MAX_LEVEL)
2661         {
2662 #ifdef JP
2663 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礭¤¹¤®¤ë(%u)¡ª", tmp16u));
2664 #else
2665                 note(format("Too many (%u) hitpoint entries!", tmp16u));
2666 #endif
2667
2668                 return (25);
2669         }
2670
2671         /* Read the player_hp array */
2672         for (i = 0; i < tmp16u; i++)
2673         {
2674                 rd_s16b(&p_ptr->player_hp[i]);
2675         }
2676
2677         /* Important -- Initialize the sex */
2678         sp_ptr = &sex_info[p_ptr->psex];
2679
2680         /* Important -- Initialize the race/class */
2681         rp_ptr = &race_info[p_ptr->prace];
2682         cp_ptr = &class_info[p_ptr->pclass];
2683         ap_ptr = &seikaku_info[p_ptr->pseikaku];
2684
2685         if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
2686         {
2687                 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2688                 do_cmd_rerate(FALSE);
2689         }
2690         if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
2691         {
2692                 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2693                 do_cmd_rerate(FALSE);
2694         }
2695         if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
2696         {
2697                 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2698                 do_cmd_rerate(FALSE);
2699         }
2700         if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
2701         {
2702                 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2703                 do_cmd_rerate(FALSE);
2704         }
2705
2706         /* Important -- Initialize the magic */
2707         mp_ptr = &m_info[p_ptr->pclass];
2708
2709
2710         /* Read spell info */
2711         rd_u32b(&p_ptr->spell_learned1);
2712         rd_u32b(&p_ptr->spell_learned2);
2713         rd_u32b(&p_ptr->spell_worked1);
2714         rd_u32b(&p_ptr->spell_worked2);
2715         rd_u32b(&p_ptr->spell_forgotten1);
2716         rd_u32b(&p_ptr->spell_forgotten2);
2717
2718         if (z_older_than(10,0,5))
2719         {
2720                 p_ptr->learned_spells = 0;
2721                 for (i = 0; i < 64; i++)
2722                 {
2723                         /* Count known spells */
2724                         if ((i < 32) ?
2725                             (p_ptr->spell_learned1 & (1L << i)) :
2726                             (p_ptr->spell_learned2 & (1L << (i - 32))))
2727                         {
2728                                 p_ptr->learned_spells++;
2729                         }
2730                 }
2731         }
2732         else rd_s16b(&p_ptr->learned_spells);
2733
2734         if (z_older_than(10,0,6))
2735         {
2736                 p_ptr->add_spells = 0;
2737         }
2738         else rd_s16b(&p_ptr->add_spells);
2739         if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2740
2741         for (i = 0; i < 64; i++)
2742         {
2743                 rd_byte(&p_ptr->spell_order[i]);
2744         }
2745
2746
2747         /* Read the inventory */
2748         if (rd_inventory())
2749         {
2750 #ifdef JP
2751 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó");
2752 #else
2753                 note("Unable to read inventory");
2754 #endif
2755
2756                 return (21);
2757         }
2758
2759         /* Read number of towns */
2760         rd_u16b(&tmp16u);
2761         town_count = tmp16u;
2762
2763         /* Read the stores */
2764         rd_u16b(&tmp16u);
2765         for (i = 1; i < town_count; i++)
2766         {
2767                 for (j = 0; j < tmp16u; j++)
2768                 {
2769                         if (rd_store(i, j)) return (22);
2770                 }
2771         }
2772
2773         rd_s16b(&p_ptr->pet_follow_distance);
2774         if (z_older_than(10, 4, 10))
2775         {
2776                 p_ptr->pet_extra_flags = 0;
2777                 rd_byte(&tmp8u);
2778                 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2779                 rd_byte(&tmp8u);
2780                 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2781
2782                 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2783                 else
2784                 {
2785                         rd_byte(&tmp8u);
2786                         if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2787                 }
2788
2789                 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2790                 else
2791                 {
2792                         rd_byte(&tmp8u);
2793                         if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2794                 }
2795
2796                 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2797                 else
2798                 {
2799                         rd_byte(&tmp8u);
2800                         if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2801                 }
2802
2803                 if (!z_older_than(10,0,8))
2804                 {
2805                         rd_byte(&tmp8u);
2806                         if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2807                 }
2808         }
2809         else
2810         {
2811                 rd_s16b(&p_ptr->pet_extra_flags);
2812         }
2813
2814         if (!z_older_than(11, 0, 9))
2815         {
2816                 char buf[SCREEN_BUF_SIZE];
2817                 rd_string(buf, SCREEN_BUF_SIZE);
2818                 if (buf[0]) screen_dump = string_make(buf);
2819         }
2820
2821         if (p_ptr->is_dead)
2822         {
2823                 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2824                 {
2825                         r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2826                 }
2827         }
2828
2829
2830         /* I'm not dead yet... */
2831         if (!p_ptr->is_dead)
2832         {
2833                 /* Dead players have no dungeon */
2834 #ifdef JP
2835 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2836 #else
2837                 note("Restoring Dungeon...");
2838 #endif
2839
2840                 if (rd_dungeon())
2841                 {
2842 #ifdef JP
2843 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2844 #else
2845                         note("Error reading dungeon data");
2846 #endif
2847
2848                         return (34);
2849                 }
2850
2851                 /* Read the ghost info */
2852                 rd_ghost();
2853
2854                 {
2855                         s32b tmp32s;
2856
2857                         rd_s32b(&tmp32s);
2858                         strip_bytes(tmp32s);
2859                 }
2860         }
2861
2862
2863 #ifdef VERIFY_CHECKSUMS
2864
2865         /* Save the checksum */
2866         n_v_check = v_check;
2867
2868         /* Read the old checksum */
2869         rd_u32b(&o_v_check);
2870
2871         /* Verify */
2872         if (o_v_check != n_v_check)
2873         {
2874 #ifdef JP
2875 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2876 #else
2877                 note("Invalid checksum");
2878 #endif
2879
2880                 return (11);
2881         }
2882
2883
2884         /* Save the encoded checksum */
2885         n_x_check = x_check;
2886
2887         /* Read the checksum */
2888         rd_u32b(&o_x_check);
2889
2890
2891         /* Verify */
2892         if (o_x_check != n_x_check)
2893         {
2894 #ifdef JP
2895 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2896 #else
2897                 note("Invalid encoded checksum");
2898 #endif
2899
2900                 return (11);
2901         }
2902
2903 #endif
2904
2905         /* Success */
2906         return (0);
2907 }
2908
2909
2910 /*
2911  * Actually read the savefile
2912  */
2913 errr rd_savefile_new(void)
2914 {
2915         errr err;
2916
2917         /* The savefile is a binary file */
2918         fff = my_fopen(savefile, "rb");
2919
2920         /* Paranoia */
2921         if (!fff) return (-1);
2922
2923         /* Call the sub-function */
2924         err = rd_savefile_new_aux();
2925
2926         /* Check for errors */
2927         if (ferror(fff)) err = -1;
2928
2929         /* Close the file */
2930         my_fclose(fff);
2931
2932         /* Result */
2933         return (err);
2934 }
2935
2936