OSDN Git Service

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