OSDN Git Service

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