OSDN Git Service

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