3 /* Purpose: support for loading savefiles -BEN- */
9 * This file loads savefiles from Angband 2.7.X and 2.8.X
11 * Ancient savefiles (pre-2.7.0) are loaded by another file.
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.
16 * We attempt to prevent corrupt savefiles from inducing memory errors.
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.
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.
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.
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.
43 * Maximum number of tries for selection of a proper quest monster
49 * Local "savefile" pointer
54 * Hack -- old "encryption" byte
59 * Hack -- simple "checksum" on the actual values
61 static u32b v_check = 0L;
64 * Hack -- simple "checksum" on the encoded bytes
66 static u32b x_check = 0L;
71 * This function determines if the version of the savefile
72 * currently being read is older than version "major.minor.patch.extra".
74 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
76 /* Much older, or much more recent */
77 if (h_ver_major < major) return (TRUE);
78 if (h_ver_major > major) return (FALSE);
80 /* Distinctly older, or distinctly more recent */
81 if (h_ver_minor < minor) return (TRUE);
82 if (h_ver_minor > minor) return (FALSE);
84 /* Barely older, or barely more recent */
85 if (h_ver_patch < patch) return (TRUE);
86 if (h_ver_patch > patch) return (FALSE);
88 /* Barely older, or barely more recent */
89 if (h_ver_extra < extra) return (TRUE);
90 if (h_ver_extra > extra) return (FALSE);
92 /* Identical versions */
98 * The above function, adapted for Zangband
100 static bool z_older_than(byte x, byte y, byte z)
102 /* Much older, or much more recent */
103 if (z_major < x) return (TRUE);
104 if (z_major > x) return (FALSE);
106 /* Distinctly older, or distinctly more recent */
107 if (z_minor < y) return (TRUE);
108 if (z_minor > y) return (FALSE);
110 /* Barely older, or barely more recent */
111 if (z_patch < z) return (TRUE);
112 if (z_patch > z) return (FALSE);
114 /* Identical versions */
120 * Hack -- Show information on the screen, one line at a time.
122 * Avoid the top two lines, to avoid interference with "msg_print()".
124 static void note(cptr msg)
128 /* Draw the message */
131 /* Advance one line (wrap if needed) */
132 if (++y >= 24) y = 2;
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+
144 static byte sf_get(void)
148 /* Get a character, decode the value */
149 c = getc(fff) & 0xFF;
153 /* Maintain the checksum info */
157 /* Return the value */
161 static void rd_byte(byte *ip)
166 static void rd_u16b(u16b *ip)
169 (*ip) |= ((u16b)(sf_get()) << 8);
172 static void rd_s16b(s16b *ip)
177 static void rd_u32b(u32b *ip)
180 (*ip) |= ((u32b)(sf_get()) << 8);
181 (*ip) |= ((u32b)(sf_get()) << 16);
182 (*ip) |= ((u32b)(sf_get()) << 24);
185 static void rd_s32b(s32b *ip)
192 * Hack -- read a string
194 static void rd_string(char *str, int max)
198 /* Read the string */
199 for (i = 0; TRUE; i++)
206 /* Collect string while legal */
207 if (i < max) str[i] = tmp8u;
222 * Hack -- strip some bytes
224 static void strip_bytes(int n)
228 /* Strip the bytes */
229 while (n--) rd_byte(&tmp8u);
232 #define OLD_MAX_MANE 22
235 * Read an object (Old method)
237 * This function attempts to "repair" old savefiles, and to extract
238 * the most up to date values for various object fields.
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.
251 static void rd_item_old(object_type *o_ptr)
257 rd_s16b(&o_ptr->k_idx);
264 rd_byte(&o_ptr->tval);
265 rd_byte(&o_ptr->sval);
267 if (z_older_than(10, 4, 4))
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;
275 rd_s16b(&o_ptr->pval);
277 rd_byte(&o_ptr->discount);
278 rd_byte(&o_ptr->number);
279 rd_s16b(&o_ptr->weight);
281 rd_byte(&o_ptr->name1);
282 rd_byte(&o_ptr->name2);
283 rd_s16b(&o_ptr->timeout);
285 rd_s16b(&o_ptr->to_h);
286 rd_s16b(&o_ptr->to_d);
287 rd_s16b(&o_ptr->to_a);
294 rd_byte(&o_ptr->ident);
296 rd_byte(&o_ptr->marked);
299 rd_u32b(&o_ptr->art_flags[0]);
300 rd_u32b(&o_ptr->art_flags[1]);
301 rd_u32b(&o_ptr->art_flags[2]);
302 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
303 else rd_u32b(&o_ptr->art_flags[3]);
305 if (h_older_than(1, 3, 0, 0))
307 if (o_ptr->name2 == EGO_TELEPATHY)
308 add_flag(o_ptr->art_flags, TR_TELEPATHY);
311 if (z_older_than(11, 0, 11))
313 o_ptr->curse_flags = 0L;
314 if (o_ptr->ident & 0x40)
316 o_ptr->curse_flags |= TRC_CURSED;
317 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
318 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
321 artifact_type *a_ptr = &a_info[o_ptr->name1];
322 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
323 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
325 else if (o_ptr->name2)
327 ego_item_type *e_ptr = &e_info[o_ptr->name2];
328 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
329 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
332 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
336 rd_u32b(&o_ptr->curse_flags);
339 /* Monster holding object */
340 rd_s16b(&o_ptr->held_m_idx);
343 rd_byte(&o_ptr->xtra1);
344 rd_byte(&o_ptr->xtra2);
346 if (z_older_than(11, 0, 10))
348 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
350 switch (o_ptr->xtra2 % 6)
352 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
353 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
354 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
355 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
356 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
357 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
361 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
363 switch (o_ptr->xtra2 % 11)
365 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
366 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
367 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
368 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
369 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
370 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
371 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
372 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
373 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
374 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
375 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
379 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
381 switch (o_ptr->xtra2 % 8)
383 case 0: add_flag(o_ptr->art_flags, TR_FEATHER); break;
384 case 1: add_flag(o_ptr->art_flags, TR_LITE); break;
385 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
386 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
387 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
388 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
389 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
390 case 7: add_flag(o_ptr->art_flags, TR_HOLD_LIFE); break;
397 if (z_older_than(10, 2, 3))
402 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
404 o_ptr->xtra3 = o_ptr->xtra1;
407 if (o_ptr->tval == TV_CAPTURE)
409 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
410 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
412 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
413 if (ironman_nightmare)
415 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
417 o_ptr->xtra4 = o_ptr->xtra5;
422 rd_byte(&o_ptr->xtra3);
423 if (h_older_than(1, 3, 0, 1))
425 if (o_ptr->tval > TV_CAPTURE && o_ptr->xtra3 >= 1+96)
426 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
429 rd_s16b(&o_ptr->xtra4);
430 rd_s16b(&o_ptr->xtra5);
433 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)))
435 o_ptr->xtra4 = o_ptr->pval;
439 rd_byte(&o_ptr->feeling);
442 rd_string(buf, sizeof(buf));
444 /* Save the inscription */
445 if (buf[0]) o_ptr->inscription = quark_add(buf);
447 rd_string(buf, sizeof(buf));
448 if (buf[0]) o_ptr->art_name = quark_add(buf);
450 /* The Python object */
458 /* Mega-Hack -- handle "dungeon objects" later */
459 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
461 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
463 if (z_older_than(10, 4, 9))
465 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
467 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
468 add_flag(o_ptr->art_flags, TR_DEC_MANA);
475 artifact_type *a_ptr;
477 /* Obtain the artifact info */
478 a_ptr = &a_info[o_ptr->name1];
480 /* Verify that artifact */
481 if (!a_ptr->name) o_ptr->name1 = 0;
487 ego_item_type *e_ptr;
489 /* Obtain the ego-item info */
490 e_ptr = &e_info[o_ptr->name2];
492 /* Verify that ego-item */
493 if (!e_ptr->name) o_ptr->name2 = 0;
500 * Read an object (New method)
502 static void rd_item(object_type *o_ptr)
508 if (h_older_than(1, 5, 0, 0))
514 /*** Item save flags ***/
517 /*** Read un-obvious elements ***/
519 rd_s16b(&o_ptr->k_idx);
526 k_ptr = &k_info[o_ptr->k_idx];
527 o_ptr->tval = k_ptr->tval;
528 o_ptr->sval = k_ptr->sval;
531 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
532 else o_ptr->pval = 0;
534 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
535 else o_ptr->discount = 0;
536 if (flags & SAVE_ITEM_NUMBER) rd_byte(&o_ptr->number);
537 else o_ptr->number = 1;
539 rd_s16b(&o_ptr->weight);
541 if (flags & SAVE_ITEM_NAME1) rd_byte(&o_ptr->name1);
542 else o_ptr->name1 = 0;
543 if (flags & SAVE_ITEM_NAME2) rd_byte(&o_ptr->name2);
544 else o_ptr->name2 = 0;
545 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
546 else o_ptr->timeout = 0;
548 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
549 else o_ptr->to_h = 0;
550 if (flags & SAVE_ITEM_TO_D) rd_s16b(&o_ptr->to_d);
551 else o_ptr->to_d = 0;
552 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
553 else o_ptr->to_a = 0;
555 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
558 if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
560 if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
563 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
564 else o_ptr->ident = 0;
566 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
567 else o_ptr->marked = 0;
570 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
571 else o_ptr->art_flags[0] = 0;
572 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
573 else o_ptr->art_flags[1] = 0;
574 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
575 else o_ptr->art_flags[2] = 0;
576 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
577 else o_ptr->art_flags[3] = 0;
579 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
580 else o_ptr->curse_flags = 0;
582 /* Monster holding object */
583 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
584 else o_ptr->held_m_idx = 0;
587 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
588 else o_ptr->xtra1 = 0;
589 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
590 else o_ptr->xtra2 = 0;
592 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
593 else o_ptr->xtra3 = 0;
595 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
596 else o_ptr->xtra4 = 0;
597 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
598 else o_ptr->xtra5 = 0;
600 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
601 else o_ptr->feeling = 0;
603 if (flags & SAVE_ITEM_INSCRIPTION)
605 rd_string(buf, sizeof(buf));
606 if (buf[0]) o_ptr->inscription = quark_add(buf);
607 else o_ptr->inscription = 0;
609 else o_ptr->inscription = 0;
611 if (flags & SAVE_ITEM_ART_NAME)
613 rd_string(buf, sizeof(buf));
614 if (buf[0]) o_ptr->art_name = quark_add(buf);
615 else o_ptr->art_name = 0;
617 else o_ptr->art_name = 0;
622 * Read a monster (Old method)
624 static void rd_monster_old(monster_type *m_ptr)
629 /* Read the monster race */
630 rd_s16b(&m_ptr->r_idx);
632 if (z_older_than(11, 0, 12))
633 m_ptr->ap_r_idx = m_ptr->r_idx;
635 rd_s16b(&m_ptr->ap_r_idx);
637 if (z_older_than(11, 0, 14))
639 monster_race *r_ptr = &r_info[m_ptr->r_idx];
641 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
642 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
643 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
646 rd_byte(&m_ptr->sub_align);
648 /* Read the other information */
652 rd_s16b(&m_ptr->maxhp);
653 if (z_older_than(11, 0, 5))
655 m_ptr->max_maxhp = m_ptr->maxhp;
659 rd_s16b(&m_ptr->max_maxhp);
661 rd_s16b(&m_ptr->csleep);
662 rd_byte(&m_ptr->mspeed);
663 if (z_older_than(10, 4, 2))
666 m_ptr->energy_need = (s16b)tmp8u;
668 else rd_s16b(&m_ptr->energy_need);
670 if (z_older_than(11, 0, 13))
671 m_ptr->energy_need = 100 - m_ptr->energy_need;
673 if (z_older_than(10,0,7))
680 rd_byte(&m_ptr->fast);
681 rd_byte(&m_ptr->slow);
683 rd_byte(&m_ptr->stunned);
684 rd_byte(&m_ptr->confused);
685 rd_byte(&m_ptr->monfear);
687 if (z_older_than(10,0,10))
691 else if (z_older_than(10,0,11))
699 rd_s16b(&m_ptr->target_y);
700 rd_s16b(&m_ptr->target_x);
703 rd_byte(&m_ptr->invulner);
705 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
706 rd_u32b(&m_ptr->smart);
710 if (z_older_than(10, 4, 5))
713 rd_u32b(&m_ptr->exp);
715 if (z_older_than(10, 2, 2))
717 if (m_ptr->r_idx < 0)
719 m_ptr->r_idx = (0-m_ptr->r_idx);
720 m_ptr->mflag2 |= MFLAG_KAGE;
725 rd_byte(&m_ptr->mflag2);
728 if (z_older_than(11, 0, 12))
730 if (m_ptr->mflag2 & MFLAG_KAGE)
731 m_ptr->ap_r_idx = MON_KAGE;
734 if (z_older_than(10, 1, 3))
740 rd_string(buf, sizeof(buf));
741 if (buf[0]) m_ptr->nickname = quark_add(buf);
749 * Read a monster (New method)
751 static void rd_monster(monster_type *m_ptr)
756 if (h_older_than(1, 5, 0, 0))
758 rd_monster_old(m_ptr);
762 /*** Monster save flags ***/
765 /*** Read un-obvious elements ***/
767 /* Read the monster race */
768 rd_s16b(&m_ptr->r_idx);
770 /* Read the other information */
774 rd_s16b(&m_ptr->maxhp);
775 rd_s16b(&m_ptr->max_maxhp);
777 /* Monster race index of its appearance */
778 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
779 else m_ptr->ap_r_idx = m_ptr->r_idx;
781 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
782 else m_ptr->sub_align = 0;
784 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->csleep);
785 else m_ptr->csleep = 0;
787 rd_byte(&m_ptr->mspeed);
789 rd_s16b(&m_ptr->energy_need);
791 if (flags & SAVE_MON_FAST) rd_byte(&m_ptr->fast);
792 else m_ptr->fast = 0;
793 if (flags & SAVE_MON_SLOW) rd_byte(&m_ptr->slow);
794 else m_ptr->slow = 0;
795 if (flags & SAVE_MON_STUNNED) rd_byte(&m_ptr->stunned);
796 else m_ptr->stunned = 0;
797 if (flags & SAVE_MON_CONFUSED) rd_byte(&m_ptr->confused);
798 else m_ptr->confused = 0;
799 if (flags & SAVE_MON_MONFEAR) rd_byte(&m_ptr->monfear);
800 else m_ptr->monfear = 0;
802 if (flags & SAVE_MON_TARGET_Y) rd_s16b(&m_ptr->target_y);
803 else m_ptr->target_y = 0;
804 if (flags & SAVE_MON_TARGET_X) rd_s16b(&m_ptr->target_x);
805 else m_ptr->target_x = 0;
807 if (flags & SAVE_MON_INVULNER) rd_byte(&m_ptr->invulner);
808 else m_ptr->invulner = 0;
810 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
811 else m_ptr->smart = 0;
813 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
816 m_ptr->mflag = 0; /* Not saved */
818 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
819 else m_ptr->mflag2 = 0;
821 if (flags & SAVE_MON_NICKNAME)
823 rd_string(buf, sizeof(buf));
824 if (buf[0]) m_ptr->nickname = quark_add(buf);
825 else m_ptr->nickname = 0;
827 else m_ptr->nickname = 0;
833 * Read the monster lore
835 static void rd_lore(int r_idx)
839 monster_race *r_ptr = &r_info[r_idx];
841 /* Count sights/deaths/kills */
842 rd_s16b(&r_ptr->r_sights);
843 rd_s16b(&r_ptr->r_deaths);
844 rd_s16b(&r_ptr->r_pkills);
845 rd_s16b(&r_ptr->r_tkills);
847 /* Count wakes and ignores */
848 rd_byte(&r_ptr->r_wake);
849 rd_byte(&r_ptr->r_ignore);
852 rd_byte(&r_ptr->r_xtra1);
853 rd_byte(&r_ptr->r_xtra2);
856 rd_byte(&r_ptr->r_drop_gold);
857 rd_byte(&r_ptr->r_drop_item);
861 rd_byte(&r_ptr->r_cast_spell);
863 /* Count blows of each type */
864 rd_byte(&r_ptr->r_blows[0]);
865 rd_byte(&r_ptr->r_blows[1]);
866 rd_byte(&r_ptr->r_blows[2]);
867 rd_byte(&r_ptr->r_blows[3]);
870 rd_u32b(&r_ptr->r_flags1);
871 rd_u32b(&r_ptr->r_flags2);
872 rd_u32b(&r_ptr->r_flags3);
873 rd_u32b(&r_ptr->r_flags4);
874 rd_u32b(&r_ptr->r_flags5);
875 rd_u32b(&r_ptr->r_flags6);
877 /* Read the "Racial" monster limit per level */
878 rd_byte(&r_ptr->max_num);
880 /* Location in saved floor */
881 rd_s16b(&r_ptr->floor_id);
886 /* Repair the lore flags */
887 r_ptr->r_flags1 &= r_ptr->flags1;
888 r_ptr->r_flags2 &= r_ptr->flags2;
889 r_ptr->r_flags3 &= r_ptr->flags3;
890 r_ptr->r_flags4 &= r_ptr->flags4;
891 r_ptr->r_flags5 &= r_ptr->flags5;
892 r_ptr->r_flags6 &= r_ptr->flags6;
899 * Add the item "o_ptr" to the inventory of the "Home"
901 * In all cases, return the slot (or -1) where the object was placed
903 * Note that this is a hacked up version of "inven_carry()".
905 * Also note that it may not correctly "adapt" to "knowledge" bacoming
906 * known, the player may have to pick stuff up and drop it again.
908 static void home_carry(store_type *st_ptr, object_type *o_ptr)
916 /* Check each existing item (try to combine) */
917 for (slot = 0; slot < st_ptr->stock_num; slot++)
919 /* Get the existing item */
920 j_ptr = &st_ptr->stock[slot];
922 /* The home acts just like the player */
923 if (object_similar(j_ptr, o_ptr))
925 /* Save the new number of items */
926 object_absorb(j_ptr, o_ptr);
934 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
938 /* Determine the "value" of the item */
939 value = object_value(o_ptr);
941 /* Check existing slots to see if we must "slide" */
942 for (slot = 0; slot < st_ptr->stock_num; slot++)
945 j_ptr = &st_ptr->stock[slot];
947 /* Hack -- readable books always come first */
948 if ((o_ptr->tval == mp_ptr->spell_book) &&
949 (j_ptr->tval != mp_ptr->spell_book)) break;
950 if ((j_ptr->tval == mp_ptr->spell_book) &&
951 (o_ptr->tval != mp_ptr->spell_book)) continue;
953 /* Objects sort by decreasing type */
954 if (o_ptr->tval > j_ptr->tval) break;
955 if (o_ptr->tval < j_ptr->tval) continue;
957 /* Can happen in the home */
958 if (!object_aware_p(o_ptr)) continue;
959 if (!object_aware_p(j_ptr)) break;
961 /* Objects sort by increasing sval */
962 if (o_ptr->sval < j_ptr->sval) break;
963 if (o_ptr->sval > j_ptr->sval) continue;
965 /* Objects in the home can be unknown */
966 if (!object_known_p(o_ptr)) continue;
967 if (!object_known_p(j_ptr)) break;
970 * Hack: otherwise identical rods sort by
971 * increasing recharge time --dsb
973 if (o_ptr->tval == TV_ROD)
975 if (o_ptr->pval < j_ptr->pval) break;
976 if (o_ptr->pval > j_ptr->pval) continue;
979 /* Objects sort by decreasing value */
980 j_value = object_value(j_ptr);
981 if (value > j_value) break;
982 if (value < j_value) continue;
985 /* Slide the others up */
986 for (i = st_ptr->stock_num; i > slot; i--)
988 st_ptr->stock[i] = st_ptr->stock[i-1];
994 /* Insert the new item */
995 st_ptr->stock[slot] = *o_ptr;
997 chg_virtue(V_SACRIFICE, -1);
999 /* Return the location */
1007 static errr rd_store(int town_number, int store_number)
1019 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1021 st_ptr = &town[1].store[store_number];
1022 if (st_ptr->stock_num) sort = TRUE;
1026 st_ptr = &town[town_number].store[store_number];
1029 /* Read the basic info */
1030 rd_s32b(&st_ptr->store_open);
1031 rd_s16b(&st_ptr->insult_cur);
1033 if (z_older_than(11, 0, 4))
1042 rd_s16b(&st_ptr->good_buy);
1043 rd_s16b(&st_ptr->bad_buy);
1045 /* Read last visit */
1046 rd_s32b(&st_ptr->last_visit);
1048 /* Extract the owner (see above) */
1049 st_ptr->owner = own;
1051 /* Read the items */
1052 for (j = 0; j < num; j++)
1057 /* Get local object */
1060 /* Wipe the object */
1066 /* Acquire valid items */
1067 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1072 home_carry(st_ptr, q_ptr);
1076 k = st_ptr->stock_num++;
1078 /* Acquire the item */
1079 object_copy(&st_ptr->stock[k], q_ptr);
1091 * Read RNG state (added in 2.8.0)
1093 static void rd_randomizer(void)
1103 rd_u16b(&Rand_place);
1106 for (i = 0; i < RAND_DEG; i++)
1108 rd_u32b(&Rand_state[i]);
1118 * Read options (ignore most pre-2.8.0 options)
1120 * Note that the normal options are now stored as a set of 256 bit flags,
1121 * plus a set of 256 bit masks to indicate which bit flags were defined
1122 * at the time the savefile was created. This will allow new options
1123 * to be added, and old options to be removed, at any time, without
1124 * hurting old savefiles.
1126 * The window options are stored in the same way, but note that each
1127 * window gets 32 options, and their order is fixed by certain defines.
1129 static void rd_options(void)
1143 /* Ignore old options */
1147 /*** Special info */
1149 /* Read "delay_factor" */
1153 /* Read "hitpoint_warn" */
1158 /*** Cheating options ***/
1162 if (c & 0x0002) p_ptr->wizard = TRUE;
1164 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1165 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1166 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1167 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1168 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1169 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1170 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1172 rd_byte((byte *)&autosave_l);
1173 rd_byte((byte *)&autosave_t);
1174 rd_s16b(&autosave_freq);
1177 /*** Normal Options ***/
1179 /* Read the option flags */
1180 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1182 /* Read the option masks */
1183 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1185 /* Analyze the options */
1186 for (n = 0; n < 8; n++)
1188 /* Analyze the options */
1189 for (i = 0; i < 32; i++)
1191 /* Process valid flags */
1192 if (mask[n] & (1L << i))
1194 /* Process valid flags */
1195 if (option_mask[n] & (1L << i))
1198 if (flag[n] & (1L << i))
1201 option_flag[n] |= (1L << i);
1208 option_flag[n] &= ~(1L << i);
1215 if (z_older_than(10, 4, 5))
1217 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1218 else option_flag[5] |= (0x00000001 << 4);
1219 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1220 else option_flag[2] |= (0x00000001 << 5);
1221 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1222 else option_flag[4] |= (0x00000001 << 5);
1223 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1224 else option_flag[5] |= (0x00000001 << 0);
1225 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1226 else option_flag[5] |= (0x00000001 << 12);
1227 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1228 else option_flag[1] |= (0x00000001 << 0);
1229 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1230 else option_flag[1] |= (0x00000001 << 18);
1231 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1232 else option_flag[1] |= (0x00000001 << 19);
1233 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1234 else option_flag[5] |= (0x00000001 << 3);
1238 /*** Window Options ***/
1240 /* Read the window flags */
1241 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1243 /* Read the window masks */
1244 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1246 /* Analyze the options */
1247 for (n = 0; n < 8; n++)
1249 /* Analyze the options */
1250 for (i = 0; i < 32; i++)
1252 /* Process valid flags */
1253 if (mask[n] & (1L << i))
1255 /* Process valid flags */
1256 if (window_mask[n] & (1L << i))
1259 if (flag[n] & (1L << i))
1262 window_flag[n] |= (1L << i);
1269 window_flag[n] &= ~(1L << i);
1282 * Hack -- strip the "ghost" info
1284 * XXX XXX XXX This is such a nasty hack it hurts.
1286 static void rd_ghost(void)
1291 rd_string(buf, sizeof(buf));
1293 /* Strip old data */
1299 * Save quick start data
1301 static void load_quick_start(void)
1306 if (z_older_than(11, 0, 13))
1308 previous_char.quick_ok = FALSE;
1312 rd_byte(&previous_char.psex);
1313 rd_byte(&previous_char.prace);
1314 rd_byte(&previous_char.pclass);
1315 rd_byte(&previous_char.pseikaku);
1316 rd_byte(&previous_char.realm1);
1317 rd_byte(&previous_char.realm2);
1319 rd_s16b(&previous_char.age);
1320 rd_s16b(&previous_char.ht);
1321 rd_s16b(&previous_char.wt);
1322 rd_s16b(&previous_char.sc);
1323 rd_s32b(&previous_char.au);
1325 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1326 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1328 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1330 rd_s16b(&previous_char.chaos_patron);
1332 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1334 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1336 rd_byte(&previous_char.quests);
1339 previous_char.quick_ok = (bool)tmp8u;
1343 * Read the "extra" information
1345 static void rd_extra(void)
1352 rd_string(player_name, sizeof(player_name));
1354 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1358 for (i = 0; i < 4; i++)
1360 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1363 /* Class/Race/Seikaku/Gender/Spells */
1364 rd_byte(&p_ptr->prace);
1365 rd_byte(&p_ptr->pclass);
1366 rd_byte(&p_ptr->pseikaku);
1367 rd_byte(&p_ptr->psex);
1368 rd_byte(&p_ptr->realm1);
1369 rd_byte(&p_ptr->realm2);
1370 rd_byte(&tmp8u); /* oops */
1372 if (z_older_than(10, 4, 4))
1374 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1375 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1376 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1377 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1380 /* Special Race/Class info */
1381 rd_byte(&p_ptr->hitdie);
1382 rd_u16b(&p_ptr->expfact);
1384 /* Age/Height/Weight */
1385 rd_s16b(&p_ptr->age);
1386 rd_s16b(&p_ptr->ht);
1387 rd_s16b(&p_ptr->wt);
1389 /* Read the stat info */
1390 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1391 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1392 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1394 strip_bytes(24); /* oops */
1396 rd_s32b(&p_ptr->au);
1398 rd_s32b(&p_ptr->max_exp);
1399 rd_s32b(&p_ptr->exp);
1400 rd_u16b(&p_ptr->exp_frac);
1402 rd_s16b(&p_ptr->lev);
1404 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1405 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1407 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = 1600;
1409 if (z_older_than(10, 3, 6))
1410 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1412 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1413 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1414 if (z_older_than(10, 4, 1))
1416 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1417 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1419 if (z_older_than(10, 3, 14))
1421 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1422 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1426 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1427 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1428 if (h_older_than(1, 3, 0, 1))
1430 if (p_ptr->pclass == CLASS_SMITH)
1432 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1433 p_ptr->magic_num1[96] = 0;
1434 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1435 p_ptr->magic_num1[97] = 0;
1439 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1441 if (z_older_than(11, 0, 7))
1443 p_ptr->start_race = p_ptr->prace;
1444 p_ptr->old_race1 = 0L;
1445 p_ptr->old_race2 = 0L;
1446 p_ptr->old_realm = 0;
1450 rd_byte(&p_ptr->start_race);
1451 rd_s32b(&p_ptr->old_race1);
1452 rd_s32b(&p_ptr->old_race2);
1453 rd_s16b(&p_ptr->old_realm);
1456 if (z_older_than(10, 0, 1))
1458 for (i = 0; i < OLD_MAX_MANE; i++)
1460 p_ptr->mane_spell[i] = -1;
1461 p_ptr->mane_dam[i] = 0;
1463 p_ptr->mane_num = 0;
1465 else if (z_older_than(10, 2, 3))
1467 for (i = 0; i < OLD_MAX_MANE; i++)
1472 for (i = 0; i < MAX_MANE; i++)
1474 p_ptr->mane_spell[i] = -1;
1475 p_ptr->mane_dam[i] = 0;
1478 p_ptr->mane_num = 0;
1482 for (i = 0; i < MAX_MANE; i++)
1484 rd_s16b(&p_ptr->mane_spell[i]);
1485 rd_s16b(&p_ptr->mane_dam[i]);
1487 rd_s16b(&p_ptr->mane_num);
1490 if (z_older_than(10, 0, 3))
1492 get_mon_num_prep(NULL, NULL);
1493 for (i = 0; i < MAX_KUBI; i++)
1495 monster_race *r_ptr;
1500 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1501 r_ptr = &r_info[kubi_r_idx[i]];
1503 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1505 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1507 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1509 for (j = 0; j < i; j++)
1510 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1515 for (i = 0; i < MAX_KUBI -1; i++)
1518 for (j = i; j < MAX_KUBI; j++)
1520 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1522 tmp = kubi_r_idx[i];
1523 kubi_r_idx[i] = kubi_r_idx[j];
1524 kubi_r_idx[j] = tmp;
1528 for (i = 0; i < MAX_KUBI; i++)
1530 if(!r_info[kubi_r_idx[i]].max_num)
1531 kubi_r_idx[i] += 10000;
1536 for (i = 0; i < MAX_KUBI; i++)
1538 rd_s16b(&kubi_r_idx[i]);
1542 if (z_older_than(10, 0, 3))
1548 for (i = 0; i < 4; i++)
1550 rd_s16b(&battle_mon[i]);
1551 if (z_older_than(10, 3, 4))
1554 mon_odds[i] = tmp16s;
1556 else rd_u32b(&mon_odds[i]);
1560 rd_s16b(&p_ptr->town_num);
1562 /* Read arena and rewards information */
1563 rd_s16b(&p_ptr->arena_number);
1565 p_ptr->inside_arena = (bool)tmp16s;
1566 rd_s16b(&p_ptr->inside_quest);
1567 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1571 p_ptr->inside_battle = (bool)tmp16s;
1573 rd_byte(&p_ptr->exit_bldg);
1574 rd_byte(&p_ptr->leftbldg);
1576 rd_s16b(&p_ptr->oldpx);
1577 rd_s16b(&p_ptr->oldpy);
1578 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1582 if (tmp16s > MAX_BACT)
1585 note(format("¤ÎÃæ", tmp16s));
1587 note(format("Too many (%d) building rewards!", tmp16s));
1592 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1594 rd_s16b(&p_ptr->mhp);
1595 rd_s16b(&p_ptr->chp);
1596 rd_u16b(&p_ptr->chp_frac);
1598 rd_s16b(&p_ptr->msp);
1599 rd_s16b(&p_ptr->csp);
1600 rd_u16b(&p_ptr->csp_frac);
1602 rd_s16b(&p_ptr->max_plv);
1603 if (z_older_than(10, 3, 8))
1605 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1609 byte max = (byte)max_d_idx;
1613 for(i = 0; i < max; i++)
1615 rd_s16b(&max_dlv[i]);
1616 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1620 /* Repair maximum player level XXX XXX XXX */
1621 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1625 rd_s16b(&p_ptr->sc);
1628 /* Read the flags */
1629 strip_bytes(2); /* Old "rest" */
1630 rd_s16b(&p_ptr->blind);
1631 rd_s16b(&p_ptr->paralyzed);
1632 rd_s16b(&p_ptr->confused);
1633 rd_s16b(&p_ptr->food);
1634 strip_bytes(4); /* Old "food_digested" / "protection" */
1636 rd_s16b(&p_ptr->energy_need);
1637 if (z_older_than(11, 0, 13))
1638 p_ptr->energy_need = 100 - p_ptr->energy_need;
1640 rd_s16b(&p_ptr->fast);
1641 rd_s16b(&p_ptr->slow);
1642 rd_s16b(&p_ptr->afraid);
1643 rd_s16b(&p_ptr->cut);
1644 rd_s16b(&p_ptr->stun);
1645 rd_s16b(&p_ptr->poisoned);
1646 rd_s16b(&p_ptr->image);
1647 rd_s16b(&p_ptr->protevil);
1648 rd_s16b(&p_ptr->invuln);
1649 if(z_older_than(10, 0, 0))
1652 rd_s16b(&p_ptr->ult_res);
1653 rd_s16b(&p_ptr->hero);
1654 rd_s16b(&p_ptr->shero);
1655 rd_s16b(&p_ptr->shield);
1656 rd_s16b(&p_ptr->blessed);
1657 rd_s16b(&p_ptr->tim_invis);
1658 rd_s16b(&p_ptr->word_recall);
1659 if (z_older_than(10, 3, 8))
1660 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1664 p_ptr->recall_dungeon = (byte)tmp16s;
1667 if (h_older_than(1, 5, 0, 0))
1668 p_ptr->alter_reality = 0;
1670 rd_s16b(&p_ptr->alter_reality);
1672 rd_s16b(&p_ptr->see_infra);
1673 rd_s16b(&p_ptr->tim_infra);
1674 rd_s16b(&p_ptr->oppose_fire);
1675 rd_s16b(&p_ptr->oppose_cold);
1676 rd_s16b(&p_ptr->oppose_acid);
1677 rd_s16b(&p_ptr->oppose_elec);
1678 rd_s16b(&p_ptr->oppose_pois);
1679 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1680 else rd_s16b(&p_ptr->tsuyoshi);
1682 /* Old savefiles do not have the following fields... */
1683 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1686 p_ptr->wraith_form = 0;
1687 p_ptr->resist_magic = 0;
1688 p_ptr->tim_regen = 0;
1689 p_ptr->kabenuke = 0;
1690 p_ptr->tim_stealth = 0;
1691 p_ptr->tim_ffall = 0;
1692 p_ptr->tim_sh_touki = 0;
1693 p_ptr->lightspeed = 0;
1694 p_ptr->tsubureru = 0;
1695 p_ptr->tim_res_nether = 0;
1696 p_ptr->tim_res_time = 0;
1697 p_ptr->mimic_form = 0;
1698 p_ptr->tim_mimic = 0;
1699 p_ptr->tim_sh_fire = 0;
1702 p_ptr->tim_reflect = 0;
1703 p_ptr->multishadow = 0;
1704 p_ptr->dustrobe = 0;
1706 p_ptr->chaos_patron = get_chaos_patron();
1714 rd_s16b(&p_ptr->tim_esp);
1715 rd_s16b(&p_ptr->wraith_form);
1716 rd_s16b(&p_ptr->resist_magic);
1717 rd_s16b(&p_ptr->tim_regen);
1718 rd_s16b(&p_ptr->kabenuke);
1719 rd_s16b(&p_ptr->tim_stealth);
1720 rd_s16b(&p_ptr->tim_ffall);
1721 rd_s16b(&p_ptr->tim_sh_touki);
1722 rd_s16b(&p_ptr->lightspeed);
1723 rd_s16b(&p_ptr->tsubureru);
1724 if (z_older_than(10, 4, 7))
1725 p_ptr->magicdef = 0;
1727 rd_s16b(&p_ptr->magicdef);
1728 rd_s16b(&p_ptr->tim_res_nether);
1729 if (z_older_than(10, 4, 11))
1731 p_ptr->tim_res_time = 0;
1732 p_ptr->mimic_form = 0;
1733 p_ptr->tim_mimic = 0;
1734 p_ptr->tim_sh_fire = 0;
1738 rd_s16b(&p_ptr->tim_res_time);
1739 rd_byte(&p_ptr->mimic_form);
1740 rd_s16b(&p_ptr->tim_mimic);
1741 rd_s16b(&p_ptr->tim_sh_fire);
1744 if (z_older_than(11, 0, 99))
1746 p_ptr->tim_sh_holy = 0;
1747 p_ptr->tim_eyeeye = 0;
1751 rd_s16b(&p_ptr->tim_sh_holy);
1752 rd_s16b(&p_ptr->tim_eyeeye);
1756 if ( z_older_than(11,0,3) ){
1757 p_ptr->tim_reflect=0;
1758 p_ptr->multishadow=0;
1762 rd_s16b(&p_ptr->tim_reflect);
1763 rd_s16b(&p_ptr->multishadow);
1764 rd_s16b(&p_ptr->dustrobe);
1767 rd_s16b(&p_ptr->chaos_patron);
1768 rd_u32b(&p_ptr->muta1);
1769 rd_u32b(&p_ptr->muta2);
1770 rd_u32b(&p_ptr->muta3);
1772 for (i = 0; i < 8; i++)
1773 rd_s16b(&p_ptr->virtues[i]);
1774 for (i = 0; i < 8; i++)
1775 rd_s16b(&p_ptr->vir_types[i]);
1778 /* Calc the regeneration modifier for mutations */
1779 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1781 if (z_older_than(10,0,9))
1784 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1785 p_ptr->ele_attack = 0;
1789 rd_s16b(&p_ptr->ele_attack);
1790 rd_u32b(&p_ptr->special_attack);
1792 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1793 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1794 if (z_older_than(10,0,12))
1796 p_ptr->ele_immune = 0;
1797 p_ptr->special_defense = 0;
1801 rd_s16b(&p_ptr->ele_immune);
1802 rd_u32b(&p_ptr->special_defense);
1804 rd_byte(&p_ptr->knowledge);
1805 rd_byte(&tmp8u); /* oops */
1806 rd_byte(&tmp8u); /* oops */
1807 rd_byte(&p_ptr->action);
1808 if (!z_older_than(10, 4, 3))
1811 if (tmp8u) p_ptr->action = ACTION_LEARN;
1813 rd_byte((byte *)&preserve_mode);
1814 rd_byte((byte *)&p_ptr->wait_report_score);
1817 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1819 /* Skip the flags */
1823 /* Hack -- the two "special seeds" */
1824 rd_u32b(&seed_flavor);
1825 rd_u32b(&seed_town);
1829 rd_u16b(&p_ptr->panic_save);
1830 rd_u16b(&p_ptr->total_winner);
1831 rd_u16b(&p_ptr->noscore);
1836 p_ptr->is_dead = tmp8u;
1838 /* Read "feeling" */
1842 /* Turn of last "feeling" */
1848 if (z_older_than(10, 3, 12))
1850 dungeon_turn = turn;
1852 else rd_s32b(&dungeon_turn);
1854 if (z_older_than(11, 0, 13))
1861 if (z_older_than(10, 3, 13))
1865 else rd_s32b(&old_battle);
1867 if (z_older_than(10,0,3))
1869 monster_race *r_ptr;
1873 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1874 r_ptr = &r_info[today_mon];
1876 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1877 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1878 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1879 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1880 if (r_ptr->rarity > 10) continue;
1881 if (r_ptr->level == 0) continue;
1885 p_ptr->today_mon = 0;
1889 rd_s16b(&today_mon);
1890 rd_s16b(&p_ptr->today_mon);
1893 if (z_older_than(10,0,7))
1899 rd_s16b(&p_ptr->riding);
1902 /* Current floor_id */
1903 if (h_older_than(1, 5, 0, 0))
1905 p_ptr->floor_id = 0;
1909 rd_s16b(&p_ptr->floor_id);
1912 if (z_older_than(10,1,2))
1921 if (z_older_than(10,3,9))
1925 else if (z_older_than(10, 3, 10))
1933 rd_s32b(&p_ptr->visit);
1935 if (!z_older_than(11, 0, 5))
1937 rd_u32b(&p_ptr->count);
1945 * Read the player inventory
1947 * Note that the inventory changed in Angband 2.7.4. Two extra
1948 * pack slots were added and the equipment was rearranged. Note
1949 * that these two features combine when parsing old save-files, in
1950 * which items from the old "aux" slot are "carried", perhaps into
1951 * one of the two new "inventory" slots.
1953 * Note that the inventory is "re-sorted" later by "dungeon()".
1955 static errr rd_inventory(void)
1963 p_ptr->total_weight = 0;
1969 /* Read until done */
1974 /* Get the next item index */
1977 /* Nope, we reached the end */
1978 if (n == 0xFFFF) break;
1980 /* Get local object */
1983 /* Wipe the object */
1989 /* Hack -- verify item */
1990 if (!q_ptr->k_idx) return (53);
1992 /* Wield equipment */
1993 if (n >= INVEN_RARM)
1996 object_copy(&inventory[n], q_ptr);
1998 /* Add the weight */
1999 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2005 /* Warning -- backpack is full */
2006 else if (inven_cnt == INVEN_PACK)
2010 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
2012 note("Too many items in the inventory!");
2020 /* Carry inventory */
2027 object_copy(&inventory[n], q_ptr);
2029 /* Add the weight */
2030 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2044 * Read the saved messages
2046 static void rd_messages(void)
2056 /* Read the messages */
2057 for (i = 0; i < num; i++)
2059 /* Read the message */
2060 rd_string(buf, sizeof(buf));
2062 /* Save the message */
2069 /* Old hidden trap flag */
2070 #define CAVE_TRAP 0x8000
2073 * Read the dungeon (old method)
2075 * The monsters/objects must be loaded in the same order
2076 * that they were stored, since the actual indexes matter.
2078 static errr rd_dungeon_old(void)
2089 /*** Basic info ***/
2092 rd_s16b(&dun_level);
2093 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2094 else rd_byte(&dungeon_type);
2096 /* Set the base level for old versions */
2097 base_level = dun_level;
2099 rd_s16b(&base_level);
2101 rd_s16b(&num_repro);
2106 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2109 rd_s16b(&tmp16s); /* max_panel_rows */
2110 rd_s16b(&tmp16s); /* max_panel_cols */
2113 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
2121 /*** Run length decoding ***/
2123 /* Load the dungeon data */
2124 for (x = y = 0; y < ymax; )
2130 if (z_older_than(10,3,6))
2139 /* Decline invalid flags */
2140 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT);
2143 /* Apply the RLE info */
2144 for (i = count; i > 0; i--)
2146 /* Access the cave */
2147 c_ptr = &cave[y][x];
2149 /* Extract "info" */
2159 if (++y >= ymax) break;
2165 /*** Run length decoding ***/
2167 /* Load the dungeon data */
2168 for (x = y = 0; y < ymax; )
2174 /* Apply the RLE info */
2175 for (i = count; i > 0; i--)
2177 /* Access the cave */
2178 c_ptr = &cave[y][x];
2180 /* Extract "feat" */
2181 c_ptr->feat = tmp8u;
2190 if (++y >= ymax) break;
2195 /*** Run length decoding ***/
2197 /* Load the dungeon data */
2198 for (x = y = 0; y < ymax; )
2204 /* Apply the RLE info */
2205 for (i = count; i > 0; i--)
2207 /* Access the cave */
2208 c_ptr = &cave[y][x];
2210 /* Extract "feat" */
2211 c_ptr->mimic = tmp8u;
2220 if (++y >= ymax) break;
2225 /*** Run length decoding ***/
2227 /* Load the dungeon data */
2228 for (x = y = 0; y < ymax; )
2234 /* Apply the RLE info */
2235 for (i = count; i > 0; i--)
2237 /* Access the cave */
2238 c_ptr = &cave[y][x];
2240 /* Extract "feat" */
2241 c_ptr->special = tmp16s;
2250 if (++y >= ymax) break;
2255 /* Convert cave data */
2256 if (z_older_than(11, 0, 99))
2258 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2260 /* Wipe old unused flags */
2261 cave[y][x].info &= ~(CAVE_MASK);
2265 if (h_older_than(1, 1, 1, 0))
2267 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2269 /* Access the cave */
2270 c_ptr = &cave[y][x];
2273 if (c_ptr->feat == FEAT_INVIS)
2275 c_ptr->feat = FEAT_FLOOR;
2276 c_ptr->info |= CAVE_TRAP;
2279 /* Older than 1.1.1 */
2280 if (c_ptr->feat == FEAT_MIRROR)
2282 c_ptr->feat = FEAT_FLOOR;
2283 c_ptr->info |= CAVE_OBJECT;
2288 if (h_older_than(1, 3, 1, 0))
2290 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2292 /* Access the cave */
2293 c_ptr = &cave[y][x];
2295 /* Old CAVE_IN_MIRROR flag */
2296 if (c_ptr->info & CAVE_OBJECT)
2298 c_ptr->mimic = FEAT_MIRROR;
2301 /* Runes will be mimics and flags */
2302 else if (c_ptr->feat == FEAT_MINOR_GLYPH ||
2303 c_ptr->feat == FEAT_GLYPH)
2305 c_ptr->info |= CAVE_OBJECT;
2306 c_ptr->mimic = c_ptr->feat;
2307 c_ptr->feat = FEAT_FLOOR;
2310 /* Hidden traps will be trap terrains mimicing floor */
2311 else if (c_ptr->info & CAVE_TRAP)
2313 c_ptr->info &= ~CAVE_TRAP;
2314 c_ptr->mimic = c_ptr->feat;
2315 c_ptr->feat = choose_random_trap();
2318 /* Another hidden trap */
2319 else if (c_ptr->feat == FEAT_INVIS)
2321 c_ptr->mimic = FEAT_FLOOR;
2322 c_ptr->feat = FEAT_TRAP_OPEN;
2325 /* Hidden doors will be closed doors mimicing wall */
2326 else if (c_ptr->feat == FEAT_SECRET)
2328 place_closed_door(y, x);
2329 c_ptr->mimic = FEAT_WALL_EXTRA;
2336 /* Read the item count */
2339 /* Verify maximum */
2340 if (limit > max_o_idx)
2343 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2345 note(format("Too many (%d) object entries!", limit));
2351 /* Read the dungeon items */
2352 for (i = 1; i < limit; i++)
2359 /* Get a new record */
2366 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2368 note(format("Object allocation error (%d <> %d)", i, o_idx));
2376 o_ptr = &o_list[o_idx];
2382 /* XXX XXX XXX XXX XXX */
2385 if (o_ptr->held_m_idx)
2387 monster_type *m_ptr;
2390 m_ptr = &m_list[o_ptr->held_m_idx];
2393 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2395 /* Place the object */
2396 m_ptr->hold_o_idx = o_idx;
2402 /* Access the item location */
2403 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2406 o_ptr->next_o_idx = c_ptr->o_idx;
2408 /* Place the object */
2409 c_ptr->o_idx = o_idx;
2416 /* Read the monster count */
2419 /* Hack -- verify */
2420 if (limit > max_m_idx)
2423 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2425 note(format("Too many (%d) monster entries!", limit));
2431 /* Read the monsters */
2432 for (i = 1; i < limit; i++)
2435 monster_type *m_ptr;
2437 /* Get a new record */
2444 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2446 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2453 /* Acquire monster */
2454 m_ptr = &m_list[m_idx];
2456 /* Read the monster */
2461 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2463 /* Mark the location */
2464 c_ptr->m_idx = m_idx;
2467 real_r_ptr(m_ptr)->cur_num++;
2472 /* The dungeon is ready */
2473 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2474 character_dungeon = FALSE;
2476 character_dungeon = TRUE;
2485 * Read the saved floor
2487 * The monsters/objects must be loaded in the same order
2488 * that they were stored, since the actual indexes matter.
2490 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2502 cave_template_type *template;
2505 /*** Wipe all cave ***/
2509 /*** Basic info ***/
2511 /* Dungeon floor specific info follows */
2515 /*** Not a saved floor ***/
2517 rd_s16b(&dun_level);
2518 base_level = dun_level;
2522 /*** The saved floor ***/
2525 if (tmp16s != sf_ptr->floor_id) return 171;
2528 if (tmp8u != sf_ptr->savefile_id) return 171;
2531 if (tmp16s != sf_ptr->dun_level) return 171;
2532 dun_level = sf_ptr->dun_level;
2535 if (tmp32s != sf_ptr->last_visit) return 171;
2538 if (tmp32u != sf_ptr->visit_mark) return 171;
2541 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2544 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2547 rd_s16b(&base_level);
2548 rd_s16b(&num_repro);
2563 /*** Read template for cave_type ***/
2565 /* Read the template count */
2568 /* Allocate the "template" array */
2569 C_MAKE(template, limit, cave_template_type);
2571 /* Read the templates */
2572 for (i = 0; i < limit; i++)
2574 cave_template_type *ct_ptr = &template[i];
2577 rd_u16b(&ct_ptr->info);
2578 rd_byte(&ct_ptr->feat);
2579 rd_byte(&ct_ptr->mimic);
2580 rd_s16b(&ct_ptr->special);
2588 /*** Run length decoding ***/
2590 /* Load the dungeon data */
2591 for (x = y = 0; y < ymax; )
2603 } while (tmp8u == MAX_UCHAR);
2605 /* Apply the RLE info */
2606 for (i = count; i > 0; i--)
2608 /* Access the cave */
2609 cave_type *c_ptr = &cave[y][x];
2611 /* Extract cave data */
2612 c_ptr->info = template[id].info;
2613 c_ptr->feat = template[id].feat;
2614 c_ptr->mimic = template[id].mimic;
2615 c_ptr->special = template[id].special;
2624 if (++y >= ymax) break;
2629 /* Free the "template" array */
2630 C_FREE(template, limit, cave_template_type);
2635 /* Read the item count */
2638 /* Verify maximum */
2639 if (limit > max_o_idx) return 151;
2642 /* Read the dungeon items */
2643 for (i = 1; i < limit; i++)
2649 /* Get a new record */
2653 if (i != o_idx) return 152;
2656 o_ptr = &o_list[o_idx];
2663 if (o_ptr->held_m_idx)
2665 monster_type *m_ptr;
2668 m_ptr = &m_list[o_ptr->held_m_idx];
2671 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2673 /* Place the object */
2674 m_ptr->hold_o_idx = o_idx;
2680 /* Access the item location */
2681 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2684 o_ptr->next_o_idx = c_ptr->o_idx;
2686 /* Place the object */
2687 c_ptr->o_idx = o_idx;
2694 /* Read the monster count */
2697 /* Hack -- verify */
2698 if (limit > max_m_idx) return 161;
2700 /* Read the monsters */
2701 for (i = 1; i < limit; i++)
2705 monster_type *m_ptr;
2707 /* Get a new record */
2711 if (i != m_idx) return 162;
2714 /* Acquire monster */
2715 m_ptr = &m_list[m_idx];
2717 /* Read the monster */
2722 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2724 /* Mark the location */
2725 c_ptr->m_idx = m_idx;
2728 real_r_ptr(m_ptr)->cur_num++;
2737 * Read the dungeon (new method)
2739 * The monsters/objects must be loaded in the same order
2740 * that they were stored, since the actual indexes matter.
2742 static errr rd_dungeon(void)
2748 /* Initialize saved_floors array and temporal files */
2749 init_saved_floors();
2752 if (h_older_than(1, 5, 0, 0))
2754 err = rd_dungeon_old();
2756 /* Prepare floor_id of current floor */
2759 p_ptr->floor_id = get_new_floor_id();
2760 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
2769 /* Number of floor_id used from birth */
2770 rd_s16b(&max_floor_id);
2772 /* Current dungeon type */
2773 rd_byte(&dungeon_type);
2776 /*** On the surface ***/
2777 if (!p_ptr->floor_id)
2779 /* Number of array elements?? */
2782 /* It should be 0 */
2785 /* Read the current floor data */
2786 err = rd_saved_floor(NULL);
2789 /*** In the dungeon ***/
2792 /* Number of array elements */
2795 /* Read the saved_floors array */
2796 for (i = 0; i < num; i++)
2798 saved_floor_type *sf_ptr = &saved_floors[i];
2800 rd_s16b(&sf_ptr->floor_id);
2801 rd_byte(&sf_ptr->savefile_id);
2802 rd_s16b(&sf_ptr->dun_level);
2803 rd_s32b(&sf_ptr->last_visit);
2804 rd_u32b(&sf_ptr->visit_mark);
2805 rd_s16b(&sf_ptr->upper_floor_id);
2806 rd_s16b(&sf_ptr->lower_floor_id);
2810 /* Move saved floors data to temporal files */
2811 for (i = 0; i < num; i++)
2813 saved_floor_type *sf_ptr = &saved_floors[i];
2816 /* Unused element */
2817 if (!sf_ptr->floor_id) continue;
2819 /* Read the failure mark */
2821 if (tmp8u) continue;
2823 /* Read from the save file */
2824 err = rd_saved_floor(sf_ptr);
2829 /* Re-save as temporal saved floor file */
2830 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
2836 /* Finally load current floor data from temporal file */
2839 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
2844 /*** Error messages ***/
2849 note("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
2851 note("Too many object entries!");
2857 note("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼");
2859 note("Object allocation error");
2865 note("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
2867 note("Too many monster entries!");
2873 note("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼");
2875 note("Monster allocation error");
2881 note("Êݸ¤µ¤ì¤¿¥Õ¥í¥¢¤Î¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡ª");
2883 note("Dungeon data of saved floors are broken!");
2897 note("¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
2899 note("Failed to make temporal files!");
2912 /* The dungeon is ready */
2913 character_dungeon = TRUE;
2915 /* Success or Error */
2921 * Actually read the savefile
2923 static errr rd_savefile_new_aux(void)
2935 #ifdef VERIFY_CHECKSUMS
2936 u32b n_x_check, n_v_check;
2937 u32b o_x_check, o_v_check;
2941 /* Mention the savefile version */
2944 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2946 "Loading a %d.%d.%d savefile...",
2948 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2951 /* Strip the version bytes */
2954 /* Hack -- decrypt */
2955 xor_byte = sf_extra;
2958 /* Clear the checksums */
2962 /* Read the version number of the savefile */
2963 /* Old savefile will be version 0.0.0.3 */
2964 rd_byte(&h_ver_extra);
2965 rd_byte(&h_ver_patch);
2966 rd_byte(&h_ver_minor);
2967 rd_byte(&h_ver_major);
2969 /* Operating system info */
2970 rd_u32b(&sf_system);
2972 /* Time of savefile creation */
2975 /* Number of resurrections */
2978 /* Number of times played */
2982 /* Later use (always zero) */
2985 /* Later use (always zero) */
2989 /* Read RNG state */
2992 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2994 if (arg_fiddle) note("Loaded Randomizer Info");
2999 /* Then the options */
3002 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3004 if (arg_fiddle) note("Loaded Option Flags");
3007 /* Then the "messages" */
3010 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3012 if (arg_fiddle) note("Loaded Messages");
3017 for (i = 0; i < max_r_idx; i++)
3019 /* Access that monster */
3020 monster_race *r_ptr = &r_info[i];
3022 /* Hack -- Reset the death counter */
3023 r_ptr->max_num = 100;
3024 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3025 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
3028 /* Monster Memory */
3031 /* Incompatible save files */
3032 if (tmp16u > max_r_idx)
3035 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3037 note(format("Too many (%u) monster races!", tmp16u));
3043 /* Read the available records */
3044 for (i = 0; i < tmp16u; i++)
3051 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3053 if (arg_fiddle) note("Loaded Monster Memory");
3061 /* Incompatible save files */
3062 if (tmp16u > max_k_idx)
3065 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3067 note(format("Too many (%u) object kinds!", tmp16u));
3073 /* Read the object memory */
3074 for (i = 0; i < tmp16u; i++)
3077 object_kind *k_ptr = &k_info[i];
3081 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3082 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3085 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3087 if (arg_fiddle) note("Loaded Object Memory");
3093 * Initialize arena and rewards information
3095 p_ptr->arena_number = 0;
3096 p_ptr->inside_arena = 0;
3097 p_ptr->inside_quest = 0;
3098 p_ptr->leftbldg = FALSE;
3099 p_ptr->exit_bldg = TRUE;
3101 /* Start in town 1 */
3102 p_ptr->town_num = 1;
3104 p_ptr->wilderness_x = 4;
3105 p_ptr->wilderness_y = 4;
3109 /* Init the wilderness seeds */
3110 for (i = 0; i < max_wild_x; i++)
3112 for (j = 0; j < max_wild_y; j++)
3114 wilderness[j][i].seed = randint0(0x10000000);
3118 /* 2.1.3 or newer version */
3120 u16b max_towns_load;
3121 u16b max_quests_load;
3122 byte max_rquests_load;
3123 s16b old_inside_quest = p_ptr->inside_quest;
3125 /* Number of towns */
3126 rd_u16b(&max_towns_load);
3128 /* Incompatible save files */
3129 if (max_towns_load > max_towns)
3132 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
3134 note(format("Too many (%u) towns!", max_towns_load));
3140 /* Number of quests */
3141 rd_u16b(&max_quests_load);
3143 if (z_older_than(11, 0, 7))
3145 max_rquests_load = 10;
3149 rd_byte(&max_rquests_load);
3152 /* Incompatible save files */
3153 if (max_quests_load > max_quests)
3156 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
3158 note(format("Too many (%u) quests!", max_quests_load));
3164 for (i = 0; i < max_quests_load; i++)
3168 rd_s16b(&quest[i].status);
3169 rd_s16b(&quest[i].level);
3171 if (z_older_than(11, 0, 6))
3173 quest[i].complev = 0;
3177 rd_byte(&quest[i].complev);
3180 /* Load quest status if quest is running */
3181 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))))
3183 rd_s16b(&quest[i].cur_num);
3184 rd_s16b(&quest[i].max_num);
3185 rd_s16b(&quest[i].type);
3187 /* Load quest monster index */
3188 rd_s16b(&quest[i].r_idx);
3190 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
3195 monster_race *r_ptr;
3198 * Random monster 5 - 10 levels out of depth
3199 * (depending on level)
3201 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
3202 r_ptr = &r_info[r_idx];
3204 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
3206 if(r_ptr->flags6 & RF6_SPECIAL) continue;
3208 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
3210 if(r_ptr->flags7 & RF7_AQUATIC) continue;
3212 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
3215 * Accept monsters that are 2 - 6 levels
3216 * out of depth depending on the quest level
3218 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
3221 quest[i].r_idx = r_idx;
3224 /* Load quest item index */
3225 rd_s16b(&quest[i].k_idx);
3228 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
3230 rd_byte(&quest[i].flags);
3232 if (z_older_than(10, 3, 11))
3234 if (quest[i].flags & QUEST_FLAG_PRESET)
3236 quest[i].dungeon = 0;
3240 init_flags = INIT_ASSIGN;
3241 p_ptr->inside_quest = i;
3243 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3244 p_ptr->inside_quest = old_inside_quest;
3249 rd_byte(&quest[i].dungeon);
3252 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
3253 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
3254 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
3257 /* Ignore the empty quests from old versions */
3260 /* Ignore quest status */
3263 /* Ignore quest level */
3267 * We don't have to care about the other info,
3268 * since status should be 0 for these quests anyway
3273 /* Position in the wilderness */
3274 rd_s32b(&p_ptr->wilderness_x);
3275 rd_s32b(&p_ptr->wilderness_y);
3276 if (z_older_than(10, 3, 13))
3278 p_ptr->wilderness_x = 5;
3279 p_ptr->wilderness_y = 48;
3282 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3283 else rd_byte((byte *)&p_ptr->wild_mode);
3284 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3285 else rd_byte((byte *)&ambush_flag);
3287 /* Size of the wilderness */
3288 rd_s32b(&wild_x_size);
3289 rd_s32b(&wild_y_size);
3291 /* Incompatible save files */
3292 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3295 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
3297 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
3303 /* Load the wilderness seeds */
3304 for (i = 0; i < wild_x_size; i++)
3306 for (j = 0; j < wild_y_size; j++)
3308 rd_u32b(&wilderness[j][i].seed);
3314 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3316 if (arg_fiddle) note("Loaded Quests");
3319 /* Load the Artifacts */
3322 /* Incompatible save files */
3323 if (tmp16u > max_a_idx)
3326 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3328 note(format("Too many (%u) artifacts!", tmp16u));
3334 /* Read the artifact flags */
3335 for (i = 0; i < tmp16u; i++)
3337 artifact_type *a_ptr = &a_info[i];
3340 a_ptr->cur_num = tmp8u;
3342 if (h_older_than(1, 5, 0, 0))
3344 a_ptr->floor_id = 0;
3352 rd_s16b(&a_ptr->floor_id);
3356 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3358 if (arg_fiddle) note("Loaded Artifacts");
3363 /* Read the extra stuff */
3365 if (p_ptr->energy_need < -999) world_player = TRUE;
3368 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3370 if (arg_fiddle) note("Loaded extra information");
3374 /* Read the player_hp array */
3377 /* Incompatible save files */
3378 if (tmp16u > PY_MAX_LEVEL)
3381 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
3383 note(format("Too many (%u) hitpoint entries!", tmp16u));
3389 /* Read the player_hp array */
3390 for (i = 0; i < tmp16u; i++)
3392 rd_s16b(&p_ptr->player_hp[i]);
3395 /* Important -- Initialize the sex */
3396 sp_ptr = &sex_info[p_ptr->psex];
3398 /* Important -- Initialize the race/class */
3399 rp_ptr = &race_info[p_ptr->prace];
3400 cp_ptr = &class_info[p_ptr->pclass];
3401 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3403 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3405 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3406 do_cmd_rerate(FALSE);
3408 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3410 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3411 do_cmd_rerate(FALSE);
3413 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3415 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3416 do_cmd_rerate(FALSE);
3418 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3420 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3421 do_cmd_rerate(FALSE);
3424 /* Important -- Initialize the magic */
3425 mp_ptr = &m_info[p_ptr->pclass];
3428 /* Read spell info */
3429 rd_u32b(&p_ptr->spell_learned1);
3430 rd_u32b(&p_ptr->spell_learned2);
3431 rd_u32b(&p_ptr->spell_worked1);
3432 rd_u32b(&p_ptr->spell_worked2);
3433 rd_u32b(&p_ptr->spell_forgotten1);
3434 rd_u32b(&p_ptr->spell_forgotten2);
3436 if (z_older_than(10,0,5))
3438 p_ptr->learned_spells = 0;
3439 for (i = 0; i < 64; i++)
3441 /* Count known spells */
3443 (p_ptr->spell_learned1 & (1L << i)) :
3444 (p_ptr->spell_learned2 & (1L << (i - 32))))
3446 p_ptr->learned_spells++;
3450 else rd_s16b(&p_ptr->learned_spells);
3452 if (z_older_than(10,0,6))
3454 p_ptr->add_spells = 0;
3456 else rd_s16b(&p_ptr->add_spells);
3457 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3459 for (i = 0; i < 64; i++)
3461 rd_byte(&p_ptr->spell_order[i]);
3465 /* Read the inventory */
3469 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
3471 note("Unable to read inventory");
3477 /* Read number of towns */
3479 town_count = tmp16u;
3481 /* Read the stores */
3483 for (i = 1; i < town_count; i++)
3485 for (j = 0; j < tmp16u; j++)
3487 if (rd_store(i, j)) return (22);
3491 rd_s16b(&p_ptr->pet_follow_distance);
3492 if (z_older_than(10, 4, 10))
3494 p_ptr->pet_extra_flags = 0;
3496 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3498 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3500 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3504 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3507 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3511 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3514 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3518 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3521 if (!z_older_than(10,0,8))
3524 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3529 rd_s16b(&p_ptr->pet_extra_flags);
3532 if (!z_older_than(11, 0, 9))
3534 char buf[SCREEN_BUF_SIZE];
3535 rd_string(buf, sizeof(buf));
3536 if (buf[0]) screen_dump = string_make(buf);
3541 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3543 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3548 /* I'm not dead yet... */
3549 if (!p_ptr->is_dead)
3551 /* Dead players have no dungeon */
3553 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
3555 note("Restoring Dungeon...");
3561 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
3563 note("Error reading dungeon data");
3569 /* Read the ghost info */
3576 strip_bytes(tmp32s);
3581 #ifdef VERIFY_CHECKSUMS
3583 /* Save the checksum */
3584 n_v_check = v_check;
3586 /* Read the old checksum */
3587 rd_u32b(&o_v_check);
3590 if (o_v_check != n_v_check)
3593 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3595 note("Invalid checksum");
3602 /* Save the encoded checksum */
3603 n_x_check = x_check;
3605 /* Read the checksum */
3606 rd_u32b(&o_x_check);
3610 if (o_x_check != n_x_check)
3613 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3615 note("Invalid encoded checksum");
3629 * Actually read the savefile
3631 errr rd_savefile_new(void)
3635 /* Grab permissions */
3638 /* The savefile is a binary file */
3639 fff = my_fopen(savefile, "rb");
3641 /* Drop permissions */
3645 if (!fff) return (-1);
3647 /* Call the sub-function */
3648 err = rd_savefile_new_aux();
3650 /* Check for errors */
3651 if (ferror(fff)) err = -1;
3653 /* Close the file */
3662 * Actually load and verify a floor save data
3664 static bool load_floor_aux(saved_floor_type *sf_ptr)
3669 #ifdef VERIFY_CHECKSUMS
3670 u32b n_x_check, n_v_check;
3671 u32b o_x_check, o_v_check;
3674 /* Hack -- decrypt (read xor_byte) */
3678 /* Clear the checksums */
3682 /* Set the version number to current version */
3683 /* Never load old temporal files */
3684 h_ver_extra = H_VER_EXTRA;
3685 h_ver_patch = H_VER_PATCH;
3686 h_ver_minor = H_VER_MINOR;
3687 h_ver_major = H_VER_MAJOR;
3689 /* Verify the sign */
3691 if (saved_floor_file_sign != tmp32u) return FALSE;
3693 /* Read -- have error? */
3694 if (rd_saved_floor(sf_ptr)) return FALSE;
3697 #ifdef VERIFY_CHECKSUMS
3698 /* Save the checksum */
3699 n_v_check = v_check;
3701 /* Read the old checksum */
3702 rd_u32b(&o_v_check);
3705 if (o_v_check != n_v_check) return FALSE;
3707 /* Save the encoded checksum */
3708 n_x_check = x_check;
3710 /* Read the checksum */
3711 rd_u32b(&o_x_check);
3714 if (o_x_check != n_x_check) return FALSE;
3723 * Attempt to load the temporally saved-floor data
3725 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
3727 FILE *old_fff = NULL;
3728 byte old_xor_byte = 0;
3729 u32b old_v_check = 0;
3730 u32b old_x_check = 0;
3731 byte old_h_ver_major = 0;
3732 byte old_h_ver_minor = 0;
3733 byte old_h_ver_patch = 0;
3734 byte old_h_ver_extra = 0;
3737 char floor_savefile[1024];
3739 /* We have one file already opened */
3740 if (mode & SLF_SECOND)
3742 /* Backup original values */
3744 old_xor_byte = xor_byte;
3745 old_v_check = v_check;
3746 old_x_check = x_check;
3747 old_h_ver_major = h_ver_major;
3748 old_h_ver_minor = h_ver_minor;
3749 old_h_ver_patch = h_ver_patch;
3750 old_h_ver_extra = h_ver_extra;
3753 /* floor savefile */
3754 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3756 /* Grab permissions */
3759 /* The savefile is a binary file */
3760 fff = my_fopen(floor_savefile, "rb");
3762 /* Drop permissions */
3766 if (!fff) ok = FALSE;
3768 /* Attempt to load */
3771 /* Load saved floor data from file */
3772 ok = load_floor_aux(sf_ptr);
3774 /* Check for errors */
3775 if (ferror(fff)) ok = FALSE;
3777 /* Close the file */
3780 /* Grab permissions */
3783 /* Delete the file */
3784 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3786 /* Drop permissions */
3790 /* We have one file already opened */
3791 if (mode & SLF_SECOND)
3793 /* Restore original values */
3795 xor_byte = old_xor_byte;
3796 v_check = old_v_check;
3797 x_check = old_x_check;
3798 h_ver_major = old_h_ver_major;
3799 h_ver_minor = old_h_ver_minor;
3800 h_ver_patch = old_h_ver_patch;
3801 h_ver_extra = old_h_ver_extra;