OSDN Git Service

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