OSDN Git Service

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