OSDN Git Service

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