4 * Copyright (c) 1997 Ben Harrison, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: support for loading savefiles -BEN- */
17 * This file loads savefiles from Angband 2.7.X and 2.8.X
19 * Ancient savefiles (pre-2.7.0) are loaded by another file.
21 * Note that Angband 2.7.0 through 2.7.3 are now officially obsolete,
22 * and savefiles from those versions may not be successfully converted.
24 * We attempt to prevent corrupt savefiles from inducing memory errors.
26 * Note that this file should not use the random number generator, the
27 * object flavors, the visual attr/char mappings, or anything else which
28 * is initialized *after* or *during* the "load character" function.
30 * This file assumes that the monster/object records are initialized
31 * to zero, and the race/kind tables have been loaded correctly. The
32 * order of object stacks is currently not saved in the savefiles, but
33 * the "next" pointers are saved, so all necessary knowledge is present.
35 * We should implement simple "savefile extenders" using some form of
36 * "sized" chunks of bytes, with a {size,type,data} format, so everyone
37 * can know the size, interested people can know the type, and the actual
38 * data is available to the parsing routines that acknowledge the type.
40 * Consider changing the "globe of invulnerability" code so that it
41 * takes some form of "maximum damage to protect from" in addition to
42 * the existing "number of turns to protect for", and where each hit
43 * by a monster will reduce the shield by that amount.
51 * Maximum number of tries for selection of a proper quest monster
57 * Local "savefile" pointer
62 * Hack -- old "encryption" byte
67 * Hack -- simple "checksum" on the actual values
69 static u32b v_check = 0L;
72 * Hack -- simple "checksum" on the encoded bytes
74 static u32b x_check = 0L;
79 * This function determines if the version of the savefile
80 * currently being read is older than version "major.minor.patch.extra".
82 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
84 /* Much older, or much more recent */
85 if (h_ver_major < major) return (TRUE);
86 if (h_ver_major > major) return (FALSE);
88 /* Distinctly older, or distinctly more recent */
89 if (h_ver_minor < minor) return (TRUE);
90 if (h_ver_minor > minor) return (FALSE);
92 /* Barely older, or barely more recent */
93 if (h_ver_patch < patch) return (TRUE);
94 if (h_ver_patch > patch) return (FALSE);
96 /* Barely older, or barely more recent */
97 if (h_ver_extra < extra) return (TRUE);
98 if (h_ver_extra > extra) return (FALSE);
100 /* Identical versions */
106 * The above function, adapted for Zangband
108 static bool z_older_than(byte x, byte y, byte z)
110 /* Much older, or much more recent */
111 if (z_major < x) return (TRUE);
112 if (z_major > x) return (FALSE);
114 /* Distinctly older, or distinctly more recent */
115 if (z_minor < y) return (TRUE);
116 if (z_minor > y) return (FALSE);
118 /* Barely older, or barely more recent */
119 if (z_patch < z) return (TRUE);
120 if (z_patch > z) return (FALSE);
122 /* Identical versions */
128 * Hack -- Show information on the screen, one line at a time.
130 * Avoid the top two lines, to avoid interference with "msg_print()".
132 static void note(cptr msg)
136 /* Draw the message */
139 /* Advance one line (wrap if needed) */
140 if (++y >= 24) y = 2;
148 * The following functions are used to load the basic building blocks
149 * of savefiles. They also maintain the "checksum" info for 2.7.0+
152 static byte sf_get(void)
156 /* Get a character, decode the value */
157 c = getc(fff) & 0xFF;
161 /* Maintain the checksum info */
165 /* Return the value */
169 static void rd_byte(byte *ip)
174 static void rd_u16b(u16b *ip)
177 (*ip) |= ((u16b)(sf_get()) << 8);
180 static void rd_s16b(s16b *ip)
185 static void rd_u32b(u32b *ip)
188 (*ip) |= ((u32b)(sf_get()) << 8);
189 (*ip) |= ((u32b)(sf_get()) << 16);
190 (*ip) |= ((u32b)(sf_get()) << 24);
193 static void rd_s32b(s32b *ip)
200 * Hack -- read a string
202 static void rd_string(char *str, int max)
206 /* Read the string */
207 for (i = 0; TRUE; i++)
214 /* Collect string while legal */
215 if (i < max) str[i] = tmp8u;
230 * Hack -- strip some bytes
232 static void strip_bytes(int n)
236 /* Strip the bytes */
237 while (n--) rd_byte(&tmp8u);
240 #define OLD_MAX_MANE 22
243 * Read an object (Old method)
245 * This function attempts to "repair" old savefiles, and to extract
246 * the most up to date values for various object fields.
248 * Note that Angband 2.7.9 introduced a new method for object "flags"
249 * in which the "flags" on an object are actually extracted when they
250 * are needed from the object kind, artifact index, ego-item index,
251 * and two special "xtra" fields which are used to encode any "extra"
252 * power of certain ego-items. This had the side effect that items
253 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
254 * may have had, and also, all "uncursed" items will become "cursed"
255 * again, including Calris, even if it is being worn at the time. As
256 * a complete hack, items which are inscribed with "uncursed" will be
257 * "uncursed" when imported from pre-2.7.9 savefiles.
259 static void rd_item_old(object_type *o_ptr)
265 rd_s16b(&o_ptr->k_idx);
272 rd_byte(&o_ptr->tval);
273 rd_byte(&o_ptr->sval);
275 if (z_older_than(10, 4, 4))
277 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
278 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
279 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
283 rd_s16b(&o_ptr->pval);
285 rd_byte(&o_ptr->discount);
286 rd_byte(&o_ptr->number);
287 rd_s16b(&o_ptr->weight);
289 rd_byte(&o_ptr->name1);
290 rd_byte(&o_ptr->name2);
291 rd_s16b(&o_ptr->timeout);
293 rd_s16b(&o_ptr->to_h);
294 rd_s16b(&o_ptr->to_d);
295 rd_s16b(&o_ptr->to_a);
302 rd_byte(&o_ptr->ident);
304 rd_byte(&o_ptr->marked);
307 rd_u32b(&o_ptr->art_flags[0]);
308 rd_u32b(&o_ptr->art_flags[1]);
309 rd_u32b(&o_ptr->art_flags[2]);
310 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
311 else rd_u32b(&o_ptr->art_flags[3]);
313 if (h_older_than(1, 3, 0, 0))
315 if (o_ptr->name2 == EGO_TELEPATHY)
316 add_flag(o_ptr->art_flags, TR_TELEPATHY);
319 if (z_older_than(11, 0, 11))
321 o_ptr->curse_flags = 0L;
322 if (o_ptr->ident & 0x40)
324 o_ptr->curse_flags |= TRC_CURSED;
325 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
326 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
329 artifact_type *a_ptr = &a_info[o_ptr->name1];
330 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
331 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
333 else if (o_ptr->name2)
335 ego_item_type *e_ptr = &e_info[o_ptr->name2];
336 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
337 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
340 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
344 rd_u32b(&o_ptr->curse_flags);
347 /* Monster holding object */
348 rd_s16b(&o_ptr->held_m_idx);
351 rd_byte(&o_ptr->xtra1);
352 rd_byte(&o_ptr->xtra2);
354 if (z_older_than(11, 0, 10))
356 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
358 switch (o_ptr->xtra2 % 6)
360 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
361 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
362 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
363 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
364 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
365 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
369 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
371 switch (o_ptr->xtra2 % 11)
373 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
374 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
375 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
376 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
377 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
378 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
379 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
380 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
381 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
382 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
383 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
387 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
389 switch (o_ptr->xtra2 % 8)
391 case 0: add_flag(o_ptr->art_flags, TR_FEATHER); break;
392 case 1: add_flag(o_ptr->art_flags, TR_LITE); break;
393 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
394 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
395 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
396 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
397 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
398 case 7: add_flag(o_ptr->art_flags, TR_HOLD_LIFE); break;
405 if (z_older_than(10, 2, 3))
410 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
412 o_ptr->xtra3 = o_ptr->xtra1;
415 if (o_ptr->tval == TV_CAPTURE)
417 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
418 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
420 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
421 if (ironman_nightmare)
423 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
425 o_ptr->xtra4 = o_ptr->xtra5;
430 rd_byte(&o_ptr->xtra3);
431 if (h_older_than(1, 3, 0, 1))
433 if (item_tester_hook_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
434 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
437 rd_s16b(&o_ptr->xtra4);
438 rd_s16b(&o_ptr->xtra5);
441 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)))
443 o_ptr->xtra4 = o_ptr->pval;
447 rd_byte(&o_ptr->feeling);
450 rd_string(buf, sizeof(buf));
452 /* Save the inscription */
453 if (buf[0]) o_ptr->inscription = quark_add(buf);
455 rd_string(buf, sizeof(buf));
456 if (buf[0]) o_ptr->art_name = quark_add(buf);
458 /* The Python object */
466 /* Mega-Hack -- handle "dungeon objects" later */
467 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
469 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
471 if (z_older_than(10, 4, 9))
473 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
475 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
476 add_flag(o_ptr->art_flags, TR_DEC_MANA);
483 artifact_type *a_ptr;
485 /* Obtain the artifact info */
486 a_ptr = &a_info[o_ptr->name1];
488 /* Verify that artifact */
489 if (!a_ptr->name) o_ptr->name1 = 0;
495 ego_item_type *e_ptr;
497 /* Obtain the ego-item info */
498 e_ptr = &e_info[o_ptr->name2];
500 /* Verify that ego-item */
501 if (!e_ptr->name) o_ptr->name2 = 0;
508 * Read an object (New method)
510 static void rd_item(object_type *o_ptr)
516 if (h_older_than(1, 5, 0, 0))
522 /*** Item save flags ***/
525 /*** Read un-obvious elements ***/
527 rd_s16b(&o_ptr->k_idx);
534 k_ptr = &k_info[o_ptr->k_idx];
535 o_ptr->tval = k_ptr->tval;
536 o_ptr->sval = k_ptr->sval;
539 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
540 else o_ptr->pval = 0;
542 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
543 else o_ptr->discount = 0;
544 if (flags & SAVE_ITEM_NUMBER) rd_byte(&o_ptr->number);
545 else o_ptr->number = 1;
547 rd_s16b(&o_ptr->weight);
549 if (flags & SAVE_ITEM_NAME1) rd_byte(&o_ptr->name1);
550 else o_ptr->name1 = 0;
551 if (flags & SAVE_ITEM_NAME2) rd_byte(&o_ptr->name2);
552 else o_ptr->name2 = 0;
553 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
554 else o_ptr->timeout = 0;
556 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
557 else o_ptr->to_h = 0;
558 if (flags & SAVE_ITEM_TO_D) rd_s16b(&o_ptr->to_d);
559 else o_ptr->to_d = 0;
560 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
561 else o_ptr->to_a = 0;
563 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
566 if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
568 if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
571 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
572 else o_ptr->ident = 0;
574 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
575 else o_ptr->marked = 0;
578 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
579 else o_ptr->art_flags[0] = 0;
580 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
581 else o_ptr->art_flags[1] = 0;
582 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
583 else o_ptr->art_flags[2] = 0;
584 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
585 else o_ptr->art_flags[3] = 0;
587 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
588 else o_ptr->curse_flags = 0;
590 /* Monster holding object */
591 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
592 else o_ptr->held_m_idx = 0;
595 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
596 else o_ptr->xtra1 = 0;
597 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
598 else o_ptr->xtra2 = 0;
600 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
601 else o_ptr->xtra3 = 0;
603 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
604 else o_ptr->xtra4 = 0;
605 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
606 else o_ptr->xtra5 = 0;
608 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
609 else o_ptr->feeling = 0;
611 if (flags & SAVE_ITEM_INSCRIPTION)
613 rd_string(buf, sizeof(buf));
614 if (buf[0]) o_ptr->inscription = quark_add(buf);
615 else o_ptr->inscription = 0;
617 else o_ptr->inscription = 0;
619 if (flags & SAVE_ITEM_ART_NAME)
621 rd_string(buf, sizeof(buf));
622 if (buf[0]) o_ptr->art_name = quark_add(buf);
623 else o_ptr->art_name = 0;
625 else o_ptr->art_name = 0;
630 * Read a monster (Old method)
632 static void rd_monster_old(monster_type *m_ptr)
637 /* Read the monster race */
638 rd_s16b(&m_ptr->r_idx);
640 if (z_older_than(11, 0, 12))
641 m_ptr->ap_r_idx = m_ptr->r_idx;
643 rd_s16b(&m_ptr->ap_r_idx);
645 if (z_older_than(11, 0, 14))
647 monster_race *r_ptr = &r_info[m_ptr->r_idx];
649 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
650 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
651 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
654 rd_byte(&m_ptr->sub_align);
656 /* Read the other information */
660 rd_s16b(&m_ptr->maxhp);
661 if (z_older_than(11, 0, 5))
663 m_ptr->max_maxhp = m_ptr->maxhp;
667 rd_s16b(&m_ptr->max_maxhp);
669 rd_s16b(&m_ptr->csleep);
670 rd_byte(&m_ptr->mspeed);
671 if (z_older_than(10, 4, 2))
674 m_ptr->energy_need = (s16b)tmp8u;
676 else rd_s16b(&m_ptr->energy_need);
678 if (z_older_than(11, 0, 13))
679 m_ptr->energy_need = 100 - m_ptr->energy_need;
681 if (z_older_than(10,0,7))
688 rd_byte(&m_ptr->fast);
689 rd_byte(&m_ptr->slow);
691 rd_byte(&m_ptr->stunned);
692 rd_byte(&m_ptr->confused);
693 rd_byte(&m_ptr->monfear);
695 if (z_older_than(10,0,10))
699 else if (z_older_than(10,0,11))
707 rd_s16b(&m_ptr->target_y);
708 rd_s16b(&m_ptr->target_x);
711 rd_byte(&m_ptr->invulner);
713 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
714 rd_u32b(&m_ptr->smart);
718 if (z_older_than(10, 4, 5))
721 rd_u32b(&m_ptr->exp);
723 if (z_older_than(10, 2, 2))
725 if (m_ptr->r_idx < 0)
727 m_ptr->r_idx = (0-m_ptr->r_idx);
728 m_ptr->mflag2 |= MFLAG2_KAGE;
733 rd_byte(&m_ptr->mflag2);
736 if (z_older_than(11, 0, 12))
738 if (m_ptr->mflag2 & MFLAG2_KAGE)
739 m_ptr->ap_r_idx = MON_KAGE;
742 if (z_older_than(10, 1, 3))
748 rd_string(buf, sizeof(buf));
749 if (buf[0]) m_ptr->nickname = quark_add(buf);
757 * Read a monster (New method)
759 static void rd_monster(monster_type *m_ptr)
764 if (h_older_than(1, 5, 0, 0))
766 rd_monster_old(m_ptr);
770 /*** Monster save flags ***/
773 /*** Read un-obvious elements ***/
775 /* Read the monster race */
776 rd_s16b(&m_ptr->r_idx);
778 /* Read the other information */
782 rd_s16b(&m_ptr->maxhp);
783 rd_s16b(&m_ptr->max_maxhp);
785 /* Monster race index of its appearance */
786 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
787 else m_ptr->ap_r_idx = m_ptr->r_idx;
789 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
790 else m_ptr->sub_align = 0;
792 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->csleep);
793 else m_ptr->csleep = 0;
795 rd_byte(&m_ptr->mspeed);
797 rd_s16b(&m_ptr->energy_need);
799 if (flags & SAVE_MON_FAST) rd_byte(&m_ptr->fast);
800 else m_ptr->fast = 0;
801 if (flags & SAVE_MON_SLOW) rd_byte(&m_ptr->slow);
802 else m_ptr->slow = 0;
803 if (flags & SAVE_MON_STUNNED) rd_byte(&m_ptr->stunned);
804 else m_ptr->stunned = 0;
805 if (flags & SAVE_MON_CONFUSED) rd_byte(&m_ptr->confused);
806 else m_ptr->confused = 0;
807 if (flags & SAVE_MON_MONFEAR) rd_byte(&m_ptr->monfear);
808 else m_ptr->monfear = 0;
810 if (flags & SAVE_MON_TARGET_Y) rd_s16b(&m_ptr->target_y);
811 else m_ptr->target_y = 0;
812 if (flags & SAVE_MON_TARGET_X) rd_s16b(&m_ptr->target_x);
813 else m_ptr->target_x = 0;
815 if (flags & SAVE_MON_INVULNER) rd_byte(&m_ptr->invulner);
816 else m_ptr->invulner = 0;
818 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
819 else m_ptr->smart = 0;
821 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
824 m_ptr->mflag = 0; /* Not saved */
826 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
827 else m_ptr->mflag2 = 0;
829 if (flags & SAVE_MON_NICKNAME)
831 rd_string(buf, sizeof(buf));
832 if (buf[0]) m_ptr->nickname = quark_add(buf);
833 else m_ptr->nickname = 0;
835 else m_ptr->nickname = 0;
841 * Read the monster lore
843 static void rd_lore(int r_idx)
847 monster_race *r_ptr = &r_info[r_idx];
849 /* Count sights/deaths/kills */
850 rd_s16b(&r_ptr->r_sights);
851 rd_s16b(&r_ptr->r_deaths);
852 rd_s16b(&r_ptr->r_pkills);
853 rd_s16b(&r_ptr->r_tkills);
855 /* Count wakes and ignores */
856 rd_byte(&r_ptr->r_wake);
857 rd_byte(&r_ptr->r_ignore);
860 rd_byte(&r_ptr->r_xtra1);
861 rd_byte(&r_ptr->r_xtra2);
864 rd_byte(&r_ptr->r_drop_gold);
865 rd_byte(&r_ptr->r_drop_item);
869 rd_byte(&r_ptr->r_cast_spell);
871 /* Count blows of each type */
872 rd_byte(&r_ptr->r_blows[0]);
873 rd_byte(&r_ptr->r_blows[1]);
874 rd_byte(&r_ptr->r_blows[2]);
875 rd_byte(&r_ptr->r_blows[3]);
878 rd_u32b(&r_ptr->r_flags1);
879 rd_u32b(&r_ptr->r_flags2);
880 rd_u32b(&r_ptr->r_flags3);
881 rd_u32b(&r_ptr->r_flags4);
882 rd_u32b(&r_ptr->r_flags5);
883 rd_u32b(&r_ptr->r_flags6);
885 /* Read the "Racial" monster limit per level */
886 rd_byte(&r_ptr->max_num);
888 /* Location in saved floor */
889 rd_s16b(&r_ptr->floor_id);
894 /* Repair the lore flags */
895 r_ptr->r_flags1 &= r_ptr->flags1;
896 r_ptr->r_flags2 &= r_ptr->flags2;
897 r_ptr->r_flags3 &= r_ptr->flags3;
898 r_ptr->r_flags4 &= r_ptr->flags4;
899 r_ptr->r_flags5 &= r_ptr->flags5;
900 r_ptr->r_flags6 &= r_ptr->flags6;
907 * Add the item "o_ptr" to the inventory of the "Home"
909 * In all cases, return the slot (or -1) where the object was placed
911 * Note that this is a hacked up version of "inven_carry()".
913 * Also note that it may not correctly "adapt" to "knowledge" bacoming
914 * known, the player may have to pick stuff up and drop it again.
916 static void home_carry(store_type *st_ptr, object_type *o_ptr)
924 /* Check each existing item (try to combine) */
925 for (slot = 0; slot < st_ptr->stock_num; slot++)
927 /* Get the existing item */
928 j_ptr = &st_ptr->stock[slot];
930 /* The home acts just like the player */
931 if (object_similar(j_ptr, o_ptr))
933 /* Save the new number of items */
934 object_absorb(j_ptr, o_ptr);
942 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
946 /* Determine the "value" of the item */
947 value = object_value(o_ptr);
949 /* Check existing slots to see if we must "slide" */
950 for (slot = 0; slot < st_ptr->stock_num; slot++)
953 j_ptr = &st_ptr->stock[slot];
955 /* Hack -- readable books always come first */
956 if ((o_ptr->tval == mp_ptr->spell_book) &&
957 (j_ptr->tval != mp_ptr->spell_book)) break;
958 if ((j_ptr->tval == mp_ptr->spell_book) &&
959 (o_ptr->tval != mp_ptr->spell_book)) continue;
961 /* Objects sort by decreasing type */
962 if (o_ptr->tval > j_ptr->tval) break;
963 if (o_ptr->tval < j_ptr->tval) continue;
965 /* Can happen in the home */
966 if (!object_aware_p(o_ptr)) continue;
967 if (!object_aware_p(j_ptr)) break;
969 /* Objects sort by increasing sval */
970 if (o_ptr->sval < j_ptr->sval) break;
971 if (o_ptr->sval > j_ptr->sval) continue;
973 /* Objects in the home can be unknown */
974 if (!object_known_p(o_ptr)) continue;
975 if (!object_known_p(j_ptr)) break;
978 * Hack: otherwise identical rods sort by
979 * increasing recharge time --dsb
981 if (o_ptr->tval == TV_ROD)
983 if (o_ptr->pval < j_ptr->pval) break;
984 if (o_ptr->pval > j_ptr->pval) continue;
987 /* Objects sort by decreasing value */
988 j_value = object_value(j_ptr);
989 if (value > j_value) break;
990 if (value < j_value) continue;
993 /* Slide the others up */
994 for (i = st_ptr->stock_num; i > slot; i--)
996 st_ptr->stock[i] = st_ptr->stock[i-1];
1000 st_ptr->stock_num++;
1002 /* Insert the new item */
1003 st_ptr->stock[slot] = *o_ptr;
1005 chg_virtue(V_SACRIFICE, -1);
1007 /* Return the location */
1015 static errr rd_store(int town_number, int store_number)
1027 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1029 st_ptr = &town[1].store[store_number];
1030 if (st_ptr->stock_num) sort = TRUE;
1034 st_ptr = &town[town_number].store[store_number];
1037 /* Read the basic info */
1038 rd_s32b(&st_ptr->store_open);
1039 rd_s16b(&st_ptr->insult_cur);
1041 if (z_older_than(11, 0, 4))
1050 rd_s16b(&st_ptr->good_buy);
1051 rd_s16b(&st_ptr->bad_buy);
1053 /* Read last visit */
1054 rd_s32b(&st_ptr->last_visit);
1056 /* Extract the owner (see above) */
1057 st_ptr->owner = own;
1059 /* Read the items */
1060 for (j = 0; j < num; j++)
1065 /* Get local object */
1068 /* Wipe the object */
1074 /* Acquire valid items */
1075 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1080 home_carry(st_ptr, q_ptr);
1084 k = st_ptr->stock_num++;
1086 /* Acquire the item */
1087 object_copy(&st_ptr->stock[k], q_ptr);
1099 * Read RNG state (added in 2.8.0)
1101 static void rd_randomizer(void)
1111 rd_u16b(&Rand_place);
1114 for (i = 0; i < RAND_DEG; i++)
1116 rd_u32b(&Rand_state[i]);
1126 * Read options (ignore most pre-2.8.0 options)
1128 * Note that the normal options are now stored as a set of 256 bit flags,
1129 * plus a set of 256 bit masks to indicate which bit flags were defined
1130 * at the time the savefile was created. This will allow new options
1131 * to be added, and old options to be removed, at any time, without
1132 * hurting old savefiles.
1134 * The window options are stored in the same way, but note that each
1135 * window gets 32 options, and their order is fixed by certain defines.
1137 static void rd_options(void)
1151 /* Ignore old options */
1155 /*** Special info */
1157 /* Read "delay_factor" */
1161 /* Read "hitpoint_warn" */
1166 /*** Cheating options ***/
1170 if (c & 0x0002) p_ptr->wizard = TRUE;
1172 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1173 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1174 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1175 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1176 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1177 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1178 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1180 rd_byte((byte *)&autosave_l);
1181 rd_byte((byte *)&autosave_t);
1182 rd_s16b(&autosave_freq);
1185 /*** Normal Options ***/
1187 /* Read the option flags */
1188 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1190 /* Read the option masks */
1191 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1193 /* Analyze the options */
1194 for (n = 0; n < 8; n++)
1196 /* Analyze the options */
1197 for (i = 0; i < 32; i++)
1199 /* Process valid flags */
1200 if (mask[n] & (1L << i))
1202 /* Process valid flags */
1203 if (option_mask[n] & (1L << i))
1206 if (flag[n] & (1L << i))
1209 option_flag[n] |= (1L << i);
1216 option_flag[n] &= ~(1L << i);
1223 if (z_older_than(10, 4, 5))
1225 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1226 else option_flag[5] |= (0x00000001 << 4);
1227 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1228 else option_flag[2] |= (0x00000001 << 5);
1229 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1230 else option_flag[4] |= (0x00000001 << 5);
1231 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1232 else option_flag[5] |= (0x00000001 << 0);
1233 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1234 else option_flag[5] |= (0x00000001 << 12);
1235 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1236 else option_flag[1] |= (0x00000001 << 0);
1237 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1238 else option_flag[1] |= (0x00000001 << 18);
1239 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1240 else option_flag[1] |= (0x00000001 << 19);
1241 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1242 else option_flag[5] |= (0x00000001 << 3);
1245 /* Extract the options */
1246 extract_option_vars();
1249 /*** Window Options ***/
1251 /* Read the window flags */
1252 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1254 /* Read the window masks */
1255 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1257 /* Analyze the options */
1258 for (n = 0; n < 8; n++)
1260 /* Analyze the options */
1261 for (i = 0; i < 32; i++)
1263 /* Process valid flags */
1264 if (mask[n] & (1L << i))
1266 /* Process valid flags */
1267 if (window_mask[n] & (1L << i))
1270 if (flag[n] & (1L << i))
1273 window_flag[n] |= (1L << i);
1280 window_flag[n] &= ~(1L << i);
1293 * Hack -- strip the "ghost" info
1295 * XXX XXX XXX This is such a nasty hack it hurts.
1297 static void rd_ghost(void)
1302 rd_string(buf, sizeof(buf));
1304 /* Strip old data */
1310 * Save quick start data
1312 static void load_quick_start(void)
1317 if (z_older_than(11, 0, 13))
1319 previous_char.quick_ok = FALSE;
1323 rd_byte(&previous_char.psex);
1324 rd_byte(&previous_char.prace);
1325 rd_byte(&previous_char.pclass);
1326 rd_byte(&previous_char.pseikaku);
1327 rd_byte(&previous_char.realm1);
1328 rd_byte(&previous_char.realm2);
1330 rd_s16b(&previous_char.age);
1331 rd_s16b(&previous_char.ht);
1332 rd_s16b(&previous_char.wt);
1333 rd_s16b(&previous_char.sc);
1334 rd_s32b(&previous_char.au);
1336 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1337 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1339 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1341 rd_s16b(&previous_char.chaos_patron);
1343 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1345 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1347 rd_byte(&previous_char.quests);
1350 previous_char.quick_ok = (bool)tmp8u;
1354 * Read the "extra" information
1356 static void rd_extra(void)
1363 rd_string(player_name, sizeof(player_name));
1365 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1369 for (i = 0; i < 4; i++)
1371 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1374 /* Class/Race/Seikaku/Gender/Spells */
1375 rd_byte(&p_ptr->prace);
1376 rd_byte(&p_ptr->pclass);
1377 rd_byte(&p_ptr->pseikaku);
1378 rd_byte(&p_ptr->psex);
1379 rd_byte(&p_ptr->realm1);
1380 rd_byte(&p_ptr->realm2);
1381 rd_byte(&tmp8u); /* oops */
1383 if (z_older_than(10, 4, 4))
1385 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1386 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1387 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1388 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1391 /* Special Race/Class info */
1392 rd_byte(&p_ptr->hitdie);
1393 rd_u16b(&p_ptr->expfact);
1395 /* Age/Height/Weight */
1396 rd_s16b(&p_ptr->age);
1397 rd_s16b(&p_ptr->ht);
1398 rd_s16b(&p_ptr->wt);
1400 /* Read the stat info */
1401 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1402 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1403 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1405 strip_bytes(24); /* oops */
1407 rd_s32b(&p_ptr->au);
1409 rd_s32b(&p_ptr->max_exp);
1410 rd_s32b(&p_ptr->exp);
1411 rd_u16b(&p_ptr->exp_frac);
1413 rd_s16b(&p_ptr->lev);
1415 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1416 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1418 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1420 if (z_older_than(10, 3, 6))
1421 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1423 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1424 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1425 if (z_older_than(10, 4, 1))
1427 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1428 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1430 if (z_older_than(10, 3, 14))
1432 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1433 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1437 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1438 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1439 if (h_older_than(1, 3, 0, 1))
1441 if (p_ptr->pclass == CLASS_SMITH)
1443 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1444 p_ptr->magic_num1[96] = 0;
1445 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1446 p_ptr->magic_num1[97] = 0;
1450 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1452 if (z_older_than(11, 0, 7))
1454 p_ptr->start_race = p_ptr->prace;
1455 p_ptr->old_race1 = 0L;
1456 p_ptr->old_race2 = 0L;
1457 p_ptr->old_realm = 0;
1461 rd_byte(&p_ptr->start_race);
1462 rd_s32b(&p_ptr->old_race1);
1463 rd_s32b(&p_ptr->old_race2);
1464 rd_s16b(&p_ptr->old_realm);
1467 if (z_older_than(10, 0, 1))
1469 for (i = 0; i < OLD_MAX_MANE; i++)
1471 p_ptr->mane_spell[i] = -1;
1472 p_ptr->mane_dam[i] = 0;
1474 p_ptr->mane_num = 0;
1476 else if (z_older_than(10, 2, 3))
1478 for (i = 0; i < OLD_MAX_MANE; i++)
1483 for (i = 0; i < MAX_MANE; i++)
1485 p_ptr->mane_spell[i] = -1;
1486 p_ptr->mane_dam[i] = 0;
1489 p_ptr->mane_num = 0;
1493 for (i = 0; i < MAX_MANE; i++)
1495 rd_s16b(&p_ptr->mane_spell[i]);
1496 rd_s16b(&p_ptr->mane_dam[i]);
1498 rd_s16b(&p_ptr->mane_num);
1501 if (z_older_than(10, 0, 3))
1503 get_mon_num_prep(NULL, NULL);
1504 for (i = 0; i < MAX_KUBI; i++)
1506 monster_race *r_ptr;
1511 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1512 r_ptr = &r_info[kubi_r_idx[i]];
1514 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1516 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1518 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1520 for (j = 0; j < i; j++)
1521 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1526 for (i = 0; i < MAX_KUBI -1; i++)
1529 for (j = i; j < MAX_KUBI; j++)
1531 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1533 tmp = kubi_r_idx[i];
1534 kubi_r_idx[i] = kubi_r_idx[j];
1535 kubi_r_idx[j] = tmp;
1539 for (i = 0; i < MAX_KUBI; i++)
1541 if(!r_info[kubi_r_idx[i]].max_num)
1542 kubi_r_idx[i] += 10000;
1547 for (i = 0; i < MAX_KUBI; i++)
1549 rd_s16b(&kubi_r_idx[i]);
1553 if (z_older_than(10, 0, 3))
1559 for (i = 0; i < 4; i++)
1561 rd_s16b(&battle_mon[i]);
1562 if (z_older_than(10, 3, 4))
1565 mon_odds[i] = tmp16s;
1567 else rd_u32b(&mon_odds[i]);
1571 rd_s16b(&p_ptr->town_num);
1573 /* Read arena and rewards information */
1574 rd_s16b(&p_ptr->arena_number);
1575 if (h_older_than(1, 5, 0, 1))
1577 /* Arena loser of previous version was marked number 99 */
1578 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1581 p_ptr->inside_arena = (bool)tmp16s;
1582 rd_s16b(&p_ptr->inside_quest);
1583 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1587 p_ptr->inside_battle = (bool)tmp16s;
1589 rd_byte(&p_ptr->exit_bldg);
1590 rd_byte(&p_ptr->leftbldg);
1592 rd_s16b(&p_ptr->oldpx);
1593 rd_s16b(&p_ptr->oldpy);
1594 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1598 if (tmp16s > MAX_BACT)
1601 note(format("¤ÎÃæ", tmp16s));
1603 note(format("Too many (%d) building rewards!", tmp16s));
1608 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1610 rd_s16b(&p_ptr->mhp);
1611 rd_s16b(&p_ptr->chp);
1612 rd_u16b(&p_ptr->chp_frac);
1614 rd_s16b(&p_ptr->msp);
1615 rd_s16b(&p_ptr->csp);
1616 rd_u16b(&p_ptr->csp_frac);
1618 rd_s16b(&p_ptr->max_plv);
1619 if (z_older_than(10, 3, 8))
1621 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1625 byte max = (byte)max_d_idx;
1629 for(i = 0; i < max; i++)
1631 rd_s16b(&max_dlv[i]);
1632 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1636 /* Repair maximum player level XXX XXX XXX */
1637 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1641 rd_s16b(&p_ptr->sc);
1644 /* Read the flags */
1645 strip_bytes(2); /* Old "rest" */
1646 rd_s16b(&p_ptr->blind);
1647 rd_s16b(&p_ptr->paralyzed);
1648 rd_s16b(&p_ptr->confused);
1649 rd_s16b(&p_ptr->food);
1650 strip_bytes(4); /* Old "food_digested" / "protection" */
1652 rd_s16b(&p_ptr->energy_need);
1653 if (z_older_than(11, 0, 13))
1654 p_ptr->energy_need = 100 - p_ptr->energy_need;
1656 rd_s16b(&p_ptr->fast);
1657 rd_s16b(&p_ptr->slow);
1658 rd_s16b(&p_ptr->afraid);
1659 rd_s16b(&p_ptr->cut);
1660 rd_s16b(&p_ptr->stun);
1661 rd_s16b(&p_ptr->poisoned);
1662 rd_s16b(&p_ptr->image);
1663 rd_s16b(&p_ptr->protevil);
1664 rd_s16b(&p_ptr->invuln);
1665 if(z_older_than(10, 0, 0))
1668 rd_s16b(&p_ptr->ult_res);
1669 rd_s16b(&p_ptr->hero);
1670 rd_s16b(&p_ptr->shero);
1671 rd_s16b(&p_ptr->shield);
1672 rd_s16b(&p_ptr->blessed);
1673 rd_s16b(&p_ptr->tim_invis);
1674 rd_s16b(&p_ptr->word_recall);
1675 if (z_older_than(10, 3, 8))
1676 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1680 p_ptr->recall_dungeon = (byte)tmp16s;
1683 if (h_older_than(1, 5, 0, 0))
1684 p_ptr->alter_reality = 0;
1686 rd_s16b(&p_ptr->alter_reality);
1688 rd_s16b(&p_ptr->see_infra);
1689 rd_s16b(&p_ptr->tim_infra);
1690 rd_s16b(&p_ptr->oppose_fire);
1691 rd_s16b(&p_ptr->oppose_cold);
1692 rd_s16b(&p_ptr->oppose_acid);
1693 rd_s16b(&p_ptr->oppose_elec);
1694 rd_s16b(&p_ptr->oppose_pois);
1695 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1696 else rd_s16b(&p_ptr->tsuyoshi);
1698 /* Old savefiles do not have the following fields... */
1699 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1702 p_ptr->wraith_form = 0;
1703 p_ptr->resist_magic = 0;
1704 p_ptr->tim_regen = 0;
1705 p_ptr->kabenuke = 0;
1706 p_ptr->tim_stealth = 0;
1707 p_ptr->tim_ffall = 0;
1708 p_ptr->tim_sh_touki = 0;
1709 p_ptr->lightspeed = 0;
1710 p_ptr->tsubureru = 0;
1711 p_ptr->tim_res_nether = 0;
1712 p_ptr->tim_res_time = 0;
1713 p_ptr->mimic_form = 0;
1714 p_ptr->tim_mimic = 0;
1715 p_ptr->tim_sh_fire = 0;
1718 p_ptr->tim_reflect = 0;
1719 p_ptr->multishadow = 0;
1720 p_ptr->dustrobe = 0;
1722 p_ptr->chaos_patron = get_chaos_patron();
1730 rd_s16b(&p_ptr->tim_esp);
1731 rd_s16b(&p_ptr->wraith_form);
1732 rd_s16b(&p_ptr->resist_magic);
1733 rd_s16b(&p_ptr->tim_regen);
1734 rd_s16b(&p_ptr->kabenuke);
1735 rd_s16b(&p_ptr->tim_stealth);
1736 rd_s16b(&p_ptr->tim_ffall);
1737 rd_s16b(&p_ptr->tim_sh_touki);
1738 rd_s16b(&p_ptr->lightspeed);
1739 rd_s16b(&p_ptr->tsubureru);
1740 if (z_older_than(10, 4, 7))
1741 p_ptr->magicdef = 0;
1743 rd_s16b(&p_ptr->magicdef);
1744 rd_s16b(&p_ptr->tim_res_nether);
1745 if (z_older_than(10, 4, 11))
1747 p_ptr->tim_res_time = 0;
1748 p_ptr->mimic_form = 0;
1749 p_ptr->tim_mimic = 0;
1750 p_ptr->tim_sh_fire = 0;
1754 rd_s16b(&p_ptr->tim_res_time);
1755 rd_byte(&p_ptr->mimic_form);
1756 rd_s16b(&p_ptr->tim_mimic);
1757 rd_s16b(&p_ptr->tim_sh_fire);
1760 if (z_older_than(11, 0, 99))
1762 p_ptr->tim_sh_holy = 0;
1763 p_ptr->tim_eyeeye = 0;
1767 rd_s16b(&p_ptr->tim_sh_holy);
1768 rd_s16b(&p_ptr->tim_eyeeye);
1772 if ( z_older_than(11,0,3) ){
1773 p_ptr->tim_reflect=0;
1774 p_ptr->multishadow=0;
1778 rd_s16b(&p_ptr->tim_reflect);
1779 rd_s16b(&p_ptr->multishadow);
1780 rd_s16b(&p_ptr->dustrobe);
1783 rd_s16b(&p_ptr->chaos_patron);
1784 rd_u32b(&p_ptr->muta1);
1785 rd_u32b(&p_ptr->muta2);
1786 rd_u32b(&p_ptr->muta3);
1788 for (i = 0; i < 8; i++)
1789 rd_s16b(&p_ptr->virtues[i]);
1790 for (i = 0; i < 8; i++)
1791 rd_s16b(&p_ptr->vir_types[i]);
1794 /* Calc the regeneration modifier for mutations */
1795 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1797 if (z_older_than(10,0,9))
1800 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1801 p_ptr->ele_attack = 0;
1805 rd_s16b(&p_ptr->ele_attack);
1806 rd_u32b(&p_ptr->special_attack);
1808 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1809 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1810 if (z_older_than(10,0,12))
1812 p_ptr->ele_immune = 0;
1813 p_ptr->special_defense = 0;
1817 rd_s16b(&p_ptr->ele_immune);
1818 rd_u32b(&p_ptr->special_defense);
1820 rd_byte(&p_ptr->knowledge);
1821 rd_byte(&tmp8u); /* oops */
1822 rd_byte(&tmp8u); /* oops */
1823 rd_byte(&p_ptr->action);
1824 if (!z_older_than(10, 4, 3))
1827 if (tmp8u) p_ptr->action = ACTION_LEARN;
1829 rd_byte((byte *)&preserve_mode);
1830 rd_byte((byte *)&p_ptr->wait_report_score);
1833 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1835 /* Skip the flags */
1839 /* Hack -- the two "special seeds" */
1840 rd_u32b(&seed_flavor);
1841 rd_u32b(&seed_town);
1845 rd_u16b(&p_ptr->panic_save);
1846 rd_u16b(&p_ptr->total_winner);
1847 rd_u16b(&p_ptr->noscore);
1852 p_ptr->is_dead = tmp8u;
1854 /* Read "feeling" */
1858 /* Turn of last "feeling" */
1864 if (z_older_than(10, 3, 12))
1866 dungeon_turn = turn;
1868 else rd_s32b(&dungeon_turn);
1870 if (z_older_than(11, 0, 13))
1877 if (z_older_than(10, 3, 13))
1881 else rd_s32b(&old_battle);
1883 if (z_older_than(10,0,3))
1885 monster_race *r_ptr;
1889 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1890 r_ptr = &r_info[today_mon];
1892 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1893 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1894 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1895 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1896 if (r_ptr->rarity > 10) continue;
1897 if (r_ptr->level == 0) continue;
1901 p_ptr->today_mon = 0;
1905 rd_s16b(&today_mon);
1906 rd_s16b(&p_ptr->today_mon);
1909 if (z_older_than(10,0,7))
1915 rd_s16b(&p_ptr->riding);
1918 /* Current floor_id */
1919 if (h_older_than(1, 5, 0, 0))
1921 p_ptr->floor_id = 0;
1925 rd_s16b(&p_ptr->floor_id);
1928 if (h_older_than(1, 5, 0, 2))
1930 C_WIPE(&party_mon[i], MAX_PARTY_MON, monster_type);
1935 monster_type dummy_mon;
1936 bool removed = FALSE;
1939 max_num = MIN(MAX_PARTY_MON, tmp16s);
1941 /* Load temporary preserved pets */
1942 for (i = 0; i < max_num; i++)
1944 rd_monster(&party_mon[i]);
1947 real_r_ptr(&party_mon[i])->cur_num++;
1950 /* Remove excess pets */
1951 for (i = max_num; i < tmp16s; i++)
1953 rd_monster(&dummy_mon);
1955 if (dummy_mon.r_idx)
1957 if (record_named_pet && dummy_mon.nickname)
1960 monster_desc(m_name, &dummy_mon, MD_INDEF_VISIBLE);
1961 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
1967 if (removed) note("°ì»þÊݸ¥Ú¥Ã¥È¤¬Â¿¤¹¤®¤ë¤Î¤Ç°ìÉôºï½ü¤·¤Þ¤¹¡£");
1969 if (removed) note("Temporary pets are too many, so some are removed.");
1973 if (z_older_than(10,1,2))
1982 if (z_older_than(10,3,9))
1986 else if (z_older_than(10, 3, 10))
1994 rd_s32b(&p_ptr->visit);
1996 if (!z_older_than(11, 0, 5))
1998 rd_u32b(&p_ptr->count);
2006 * Read the player inventory
2008 * Note that the inventory changed in Angband 2.7.4. Two extra
2009 * pack slots were added and the equipment was rearranged. Note
2010 * that these two features combine when parsing old save-files, in
2011 * which items from the old "aux" slot are "carried", perhaps into
2012 * one of the two new "inventory" slots.
2014 * Note that the inventory is "re-sorted" later by "dungeon()".
2016 static errr rd_inventory(void)
2024 p_ptr->total_weight = 0;
2030 /* Read until done */
2035 /* Get the next item index */
2038 /* Nope, we reached the end */
2039 if (n == 0xFFFF) break;
2041 /* Get local object */
2044 /* Wipe the object */
2050 /* Hack -- verify item */
2051 if (!q_ptr->k_idx) return (53);
2053 /* Wield equipment */
2054 if (n >= INVEN_RARM)
2057 object_copy(&inventory[n], q_ptr);
2059 /* Add the weight */
2060 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2066 /* Warning -- backpack is full */
2067 else if (inven_cnt == INVEN_PACK)
2071 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
2073 note("Too many items in the inventory!");
2081 /* Carry inventory */
2088 object_copy(&inventory[n], q_ptr);
2090 /* Add the weight */
2091 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2105 * Read the saved messages
2107 static void rd_messages(void)
2117 /* Read the messages */
2118 for (i = 0; i < num; i++)
2120 /* Read the message */
2121 rd_string(buf, sizeof(buf));
2123 /* Save the message */
2130 /* Old hidden trap flag */
2131 #define CAVE_TRAP 0x8000
2134 * Read the dungeon (old method)
2136 * The monsters/objects must be loaded in the same order
2137 * that they were stored, since the actual indexes matter.
2139 static errr rd_dungeon_old(void)
2150 /*** Basic info ***/
2153 rd_s16b(&dun_level);
2154 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2155 else rd_byte(&dungeon_type);
2157 /* Set the base level for old versions */
2158 base_level = dun_level;
2160 rd_s16b(&base_level);
2162 rd_s16b(&num_repro);
2167 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2170 rd_s16b(&tmp16s); /* max_panel_rows */
2171 rd_s16b(&tmp16s); /* max_panel_cols */
2174 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
2182 /*** Run length decoding ***/
2184 /* Load the dungeon data */
2185 for (x = y = 0; y < ymax; )
2191 if (z_older_than(10,3,6))
2200 /* Decline invalid flags */
2201 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT);
2204 /* Apply the RLE info */
2205 for (i = count; i > 0; i--)
2207 /* Access the cave */
2208 c_ptr = &cave[y][x];
2210 /* Extract "info" */
2220 if (++y >= ymax) break;
2226 /*** Run length decoding ***/
2228 /* Load the dungeon data */
2229 for (x = y = 0; y < ymax; )
2235 /* Apply the RLE info */
2236 for (i = count; i > 0; i--)
2238 /* Access the cave */
2239 c_ptr = &cave[y][x];
2241 /* Extract "feat" */
2242 c_ptr->feat = tmp8u;
2251 if (++y >= ymax) break;
2256 /*** Run length decoding ***/
2258 /* Load the dungeon data */
2259 for (x = y = 0; y < ymax; )
2265 /* Apply the RLE info */
2266 for (i = count; i > 0; i--)
2268 /* Access the cave */
2269 c_ptr = &cave[y][x];
2271 /* Extract "feat" */
2272 c_ptr->mimic = tmp8u;
2281 if (++y >= ymax) break;
2286 /*** Run length decoding ***/
2288 /* Load the dungeon data */
2289 for (x = y = 0; y < ymax; )
2295 /* Apply the RLE info */
2296 for (i = count; i > 0; i--)
2298 /* Access the cave */
2299 c_ptr = &cave[y][x];
2301 /* Extract "feat" */
2302 c_ptr->special = tmp16s;
2311 if (++y >= ymax) break;
2316 /* Convert cave data */
2317 if (z_older_than(11, 0, 99))
2319 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2321 /* Wipe old unused flags */
2322 cave[y][x].info &= ~(CAVE_MASK);
2326 if (h_older_than(1, 1, 1, 0))
2328 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2330 /* Access the cave */
2331 c_ptr = &cave[y][x];
2334 if (c_ptr->feat == FEAT_INVIS)
2336 c_ptr->feat = FEAT_FLOOR;
2337 c_ptr->info |= CAVE_TRAP;
2340 /* Older than 1.1.1 */
2341 if (c_ptr->feat == FEAT_MIRROR)
2343 c_ptr->feat = FEAT_FLOOR;
2344 c_ptr->info |= CAVE_OBJECT;
2349 if (h_older_than(1, 3, 1, 0))
2351 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2353 /* Access the cave */
2354 c_ptr = &cave[y][x];
2356 /* Old CAVE_IN_MIRROR flag */
2357 if (c_ptr->info & CAVE_OBJECT)
2359 c_ptr->mimic = FEAT_MIRROR;
2362 /* Runes will be mimics and flags */
2363 else if (c_ptr->feat == FEAT_MINOR_GLYPH ||
2364 c_ptr->feat == FEAT_GLYPH)
2366 c_ptr->info |= CAVE_OBJECT;
2367 c_ptr->mimic = c_ptr->feat;
2368 c_ptr->feat = FEAT_FLOOR;
2371 /* Hidden traps will be trap terrains mimicing floor */
2372 else if (c_ptr->info & CAVE_TRAP)
2374 c_ptr->info &= ~CAVE_TRAP;
2375 c_ptr->mimic = c_ptr->feat;
2376 c_ptr->feat = choose_random_trap();
2379 /* Another hidden trap */
2380 else if (c_ptr->feat == FEAT_INVIS)
2382 c_ptr->mimic = FEAT_FLOOR;
2383 c_ptr->feat = FEAT_TRAP_OPEN;
2386 /* Hidden doors will be closed doors mimicing wall */
2387 else if (c_ptr->feat == FEAT_SECRET)
2389 place_closed_door(y, x);
2390 c_ptr->mimic = FEAT_WALL_EXTRA;
2397 /* Read the item count */
2400 /* Verify maximum */
2401 if (limit > max_o_idx)
2404 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2406 note(format("Too many (%d) object entries!", limit));
2412 /* Read the dungeon items */
2413 for (i = 1; i < limit; i++)
2420 /* Get a new record */
2427 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2429 note(format("Object allocation error (%d <> %d)", i, o_idx));
2437 o_ptr = &o_list[o_idx];
2443 /* XXX XXX XXX XXX XXX */
2446 if (o_ptr->held_m_idx)
2448 monster_type *m_ptr;
2451 m_ptr = &m_list[o_ptr->held_m_idx];
2454 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2456 /* Place the object */
2457 m_ptr->hold_o_idx = o_idx;
2463 /* Access the item location */
2464 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2467 o_ptr->next_o_idx = c_ptr->o_idx;
2469 /* Place the object */
2470 c_ptr->o_idx = o_idx;
2477 /* Read the monster count */
2480 /* Hack -- verify */
2481 if (limit > max_m_idx)
2484 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2486 note(format("Too many (%d) monster entries!", limit));
2492 /* Read the monsters */
2493 for (i = 1; i < limit; i++)
2496 monster_type *m_ptr;
2498 /* Get a new record */
2505 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2507 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2514 /* Acquire monster */
2515 m_ptr = &m_list[m_idx];
2517 /* Read the monster */
2522 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2524 /* Mark the location */
2525 c_ptr->m_idx = m_idx;
2528 real_r_ptr(m_ptr)->cur_num++;
2533 /* The dungeon is ready */
2534 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2535 character_dungeon = FALSE;
2537 character_dungeon = TRUE;
2546 * Read the saved floor
2548 * The monsters/objects must be loaded in the same order
2549 * that they were stored, since the actual indexes matter.
2551 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2563 cave_template_type *template;
2566 /*** Wipe all cave ***/
2570 /*** Basic info ***/
2572 /* Dungeon floor specific info follows */
2576 /*** Not a saved floor ***/
2578 rd_s16b(&dun_level);
2579 base_level = dun_level;
2583 /*** The saved floor ***/
2586 if (tmp16s != sf_ptr->floor_id) return 171;
2589 if (tmp8u != sf_ptr->savefile_id) return 171;
2592 if (tmp16s != sf_ptr->dun_level) return 171;
2593 dun_level = sf_ptr->dun_level;
2596 if (tmp32s != sf_ptr->last_visit) return 171;
2599 if (tmp32u != sf_ptr->visit_mark) return 171;
2602 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2605 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2608 rd_s16b(&base_level);
2609 rd_s16b(&num_repro);
2624 /*** Read template for cave_type ***/
2626 /* Read the template count */
2629 /* Allocate the "template" array */
2630 C_MAKE(template, limit, cave_template_type);
2632 /* Read the templates */
2633 for (i = 0; i < limit; i++)
2635 cave_template_type *ct_ptr = &template[i];
2638 rd_u16b(&ct_ptr->info);
2639 rd_byte(&ct_ptr->feat);
2640 rd_byte(&ct_ptr->mimic);
2641 rd_s16b(&ct_ptr->special);
2649 /*** Run length decoding ***/
2651 /* Load the dungeon data */
2652 for (x = y = 0; y < ymax; )
2664 } while (tmp8u == MAX_UCHAR);
2666 /* Apply the RLE info */
2667 for (i = count; i > 0; i--)
2669 /* Access the cave */
2670 cave_type *c_ptr = &cave[y][x];
2672 /* Extract cave data */
2673 c_ptr->info = template[id].info;
2674 c_ptr->feat = template[id].feat;
2675 c_ptr->mimic = template[id].mimic;
2676 c_ptr->special = template[id].special;
2685 if (++y >= ymax) break;
2690 /* Free the "template" array */
2691 C_FREE(template, limit, cave_template_type);
2696 /* Read the item count */
2699 /* Verify maximum */
2700 if (limit > max_o_idx) return 151;
2703 /* Read the dungeon items */
2704 for (i = 1; i < limit; i++)
2710 /* Get a new record */
2714 if (i != o_idx) return 152;
2717 o_ptr = &o_list[o_idx];
2724 if (o_ptr->held_m_idx)
2726 monster_type *m_ptr;
2729 m_ptr = &m_list[o_ptr->held_m_idx];
2732 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2734 /* Place the object */
2735 m_ptr->hold_o_idx = o_idx;
2741 /* Access the item location */
2742 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2745 o_ptr->next_o_idx = c_ptr->o_idx;
2747 /* Place the object */
2748 c_ptr->o_idx = o_idx;
2755 /* Read the monster count */
2758 /* Hack -- verify */
2759 if (limit > max_m_idx) return 161;
2761 /* Read the monsters */
2762 for (i = 1; i < limit; i++)
2766 monster_type *m_ptr;
2768 /* Get a new record */
2772 if (i != m_idx) return 162;
2775 /* Acquire monster */
2776 m_ptr = &m_list[m_idx];
2778 /* Read the monster */
2783 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2785 /* Mark the location */
2786 c_ptr->m_idx = m_idx;
2789 real_r_ptr(m_ptr)->cur_num++;
2798 * Read the dungeon (new method)
2800 * The monsters/objects must be loaded in the same order
2801 * that they were stored, since the actual indexes matter.
2803 static errr rd_dungeon(void)
2809 /* Initialize saved_floors array and temporal files */
2810 init_saved_floors();
2813 if (h_older_than(1, 5, 0, 0))
2815 err = rd_dungeon_old();
2817 /* Prepare floor_id of current floor */
2820 p_ptr->floor_id = get_new_floor_id();
2821 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
2830 /* Number of floor_id used from birth */
2831 rd_s16b(&max_floor_id);
2833 /* Current dungeon type */
2834 rd_byte(&dungeon_type);
2837 /*** On the surface ***/
2838 if (!p_ptr->floor_id)
2840 /* Number of array elements?? */
2843 /* It should be 0 */
2846 /* Read the current floor data */
2847 err = rd_saved_floor(NULL);
2850 /*** In the dungeon ***/
2853 /* Number of array elements */
2856 /* Read the saved_floors array */
2857 for (i = 0; i < num; i++)
2859 saved_floor_type *sf_ptr = &saved_floors[i];
2861 rd_s16b(&sf_ptr->floor_id);
2862 rd_byte(&sf_ptr->savefile_id);
2863 rd_s16b(&sf_ptr->dun_level);
2864 rd_s32b(&sf_ptr->last_visit);
2865 rd_u32b(&sf_ptr->visit_mark);
2866 rd_s16b(&sf_ptr->upper_floor_id);
2867 rd_s16b(&sf_ptr->lower_floor_id);
2871 /* Move saved floors data to temporal files */
2872 for (i = 0; i < num; i++)
2874 saved_floor_type *sf_ptr = &saved_floors[i];
2877 /* Unused element */
2878 if (!sf_ptr->floor_id) continue;
2880 /* Read the failure mark */
2882 if (tmp8u) continue;
2884 /* Read from the save file */
2885 err = rd_saved_floor(sf_ptr);
2890 /* Re-save as temporal saved floor file */
2891 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
2897 /* Finally load current floor data from temporal file */
2900 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
2905 /*** Error messages ***/
2910 note("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
2912 note("Too many object entries!");
2918 note("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼");
2920 note("Object allocation error");
2926 note("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
2928 note("Too many monster entries!");
2934 note("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼");
2936 note("Monster allocation error");
2942 note("Êݸ¤µ¤ì¤¿¥Õ¥í¥¢¤Î¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡ª");
2944 note("Dungeon data of saved floors are broken!");
2958 note("¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
2960 note("Failed to make temporal files!");
2973 /* The dungeon is ready */
2974 character_dungeon = TRUE;
2976 /* Success or Error */
2982 * Actually read the savefile
2984 static errr rd_savefile_new_aux(void)
2996 #ifdef VERIFY_CHECKSUMS
2997 u32b n_x_check, n_v_check;
2998 u32b o_x_check, o_v_check;
3002 /* Mention the savefile version */
3005 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
3007 "Loading a %d.%d.%d savefile...",
3009 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
3012 /* Strip the version bytes */
3015 /* Hack -- decrypt */
3016 xor_byte = sf_extra;
3019 /* Clear the checksums */
3023 /* Read the version number of the savefile */
3024 /* Old savefile will be version 0.0.0.3 */
3025 rd_byte(&h_ver_extra);
3026 rd_byte(&h_ver_patch);
3027 rd_byte(&h_ver_minor);
3028 rd_byte(&h_ver_major);
3030 /* Operating system info */
3031 rd_u32b(&sf_system);
3033 /* Time of savefile creation */
3036 /* Number of resurrections */
3039 /* Number of times played */
3043 /* Later use (always zero) */
3046 /* Later use (always zero) */
3050 /* Read RNG state */
3053 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3055 if (arg_fiddle) note("Loaded Randomizer Info");
3060 /* Then the options */
3063 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3065 if (arg_fiddle) note("Loaded Option Flags");
3068 /* Then the "messages" */
3071 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3073 if (arg_fiddle) note("Loaded Messages");
3078 for (i = 0; i < max_r_idx; i++)
3080 /* Access that monster */
3081 monster_race *r_ptr = &r_info[i];
3083 /* Hack -- Reset the death counter */
3084 r_ptr->max_num = 100;
3085 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3086 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
3089 /* Monster Memory */
3092 /* Incompatible save files */
3093 if (tmp16u > max_r_idx)
3096 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3098 note(format("Too many (%u) monster races!", tmp16u));
3104 /* Read the available records */
3105 for (i = 0; i < tmp16u; i++)
3112 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3114 if (arg_fiddle) note("Loaded Monster Memory");
3122 /* Incompatible save files */
3123 if (tmp16u > max_k_idx)
3126 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3128 note(format("Too many (%u) object kinds!", tmp16u));
3134 /* Read the object memory */
3135 for (i = 0; i < tmp16u; i++)
3138 object_kind *k_ptr = &k_info[i];
3142 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3143 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3146 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3148 if (arg_fiddle) note("Loaded Object Memory");
3154 * Initialize arena and rewards information
3156 p_ptr->arena_number = 0;
3157 p_ptr->inside_arena = 0;
3158 p_ptr->inside_quest = 0;
3159 p_ptr->leftbldg = FALSE;
3160 p_ptr->exit_bldg = TRUE;
3162 /* Start in town 1 */
3163 p_ptr->town_num = 1;
3165 p_ptr->wilderness_x = 4;
3166 p_ptr->wilderness_y = 4;
3170 /* Init the wilderness seeds */
3171 for (i = 0; i < max_wild_x; i++)
3173 for (j = 0; j < max_wild_y; j++)
3175 wilderness[j][i].seed = randint0(0x10000000);
3179 /* 2.1.3 or newer version */
3181 u16b max_towns_load;
3182 u16b max_quests_load;
3183 byte max_rquests_load;
3184 s16b old_inside_quest = p_ptr->inside_quest;
3186 /* Number of towns */
3187 rd_u16b(&max_towns_load);
3189 /* Incompatible save files */
3190 if (max_towns_load > max_towns)
3193 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
3195 note(format("Too many (%u) towns!", max_towns_load));
3201 /* Number of quests */
3202 rd_u16b(&max_quests_load);
3204 if (z_older_than(11, 0, 7))
3206 max_rquests_load = 10;
3210 rd_byte(&max_rquests_load);
3213 /* Incompatible save files */
3214 if (max_quests_load > max_quests)
3217 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
3219 note(format("Too many (%u) quests!", max_quests_load));
3225 for (i = 0; i < max_quests_load; i++)
3229 rd_s16b(&quest[i].status);
3230 rd_s16b(&quest[i].level);
3232 if (z_older_than(11, 0, 6))
3234 quest[i].complev = 0;
3238 rd_byte(&quest[i].complev);
3241 /* Load quest status if quest is running */
3242 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))))
3244 rd_s16b(&quest[i].cur_num);
3245 rd_s16b(&quest[i].max_num);
3246 rd_s16b(&quest[i].type);
3248 /* Load quest monster index */
3249 rd_s16b(&quest[i].r_idx);
3251 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
3256 monster_race *r_ptr;
3259 * Random monster 5 - 10 levels out of depth
3260 * (depending on level)
3262 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
3263 r_ptr = &r_info[r_idx];
3265 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
3267 if(r_ptr->flags6 & RF6_SPECIAL) continue;
3269 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
3271 if(r_ptr->flags7 & RF7_AQUATIC) continue;
3273 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
3276 * Accept monsters that are 2 - 6 levels
3277 * out of depth depending on the quest level
3279 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
3282 quest[i].r_idx = r_idx;
3285 /* Load quest item index */
3286 rd_s16b(&quest[i].k_idx);
3289 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
3291 rd_byte(&quest[i].flags);
3293 if (z_older_than(10, 3, 11))
3295 if (quest[i].flags & QUEST_FLAG_PRESET)
3297 quest[i].dungeon = 0;
3301 init_flags = INIT_ASSIGN;
3302 p_ptr->inside_quest = i;
3304 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3305 p_ptr->inside_quest = old_inside_quest;
3310 rd_byte(&quest[i].dungeon);
3313 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
3314 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
3315 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
3318 /* Ignore the empty quests from old versions */
3321 /* Ignore quest status */
3324 /* Ignore quest level */
3328 * We don't have to care about the other info,
3329 * since status should be 0 for these quests anyway
3334 /* Position in the wilderness */
3335 rd_s32b(&p_ptr->wilderness_x);
3336 rd_s32b(&p_ptr->wilderness_y);
3337 if (z_older_than(10, 3, 13))
3339 p_ptr->wilderness_x = 5;
3340 p_ptr->wilderness_y = 48;
3343 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3344 else rd_byte((byte *)&p_ptr->wild_mode);
3345 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3346 else rd_byte((byte *)&ambush_flag);
3348 /* Size of the wilderness */
3349 rd_s32b(&wild_x_size);
3350 rd_s32b(&wild_y_size);
3352 /* Incompatible save files */
3353 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3356 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
3358 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
3364 /* Load the wilderness seeds */
3365 for (i = 0; i < wild_x_size; i++)
3367 for (j = 0; j < wild_y_size; j++)
3369 rd_u32b(&wilderness[j][i].seed);
3375 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3377 if (arg_fiddle) note("Loaded Quests");
3380 /* Load the Artifacts */
3383 /* Incompatible save files */
3384 if (tmp16u > max_a_idx)
3387 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3389 note(format("Too many (%u) artifacts!", tmp16u));
3395 /* Read the artifact flags */
3396 for (i = 0; i < tmp16u; i++)
3398 artifact_type *a_ptr = &a_info[i];
3401 a_ptr->cur_num = tmp8u;
3403 if (h_older_than(1, 5, 0, 0))
3405 a_ptr->floor_id = 0;
3413 rd_s16b(&a_ptr->floor_id);
3417 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3419 if (arg_fiddle) note("Loaded Artifacts");
3424 /* Read the extra stuff */
3426 if (p_ptr->energy_need < -999) world_player = TRUE;
3429 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3431 if (arg_fiddle) note("Loaded extra information");
3435 /* Read the player_hp array */
3438 /* Incompatible save files */
3439 if (tmp16u > PY_MAX_LEVEL)
3442 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
3444 note(format("Too many (%u) hitpoint entries!", tmp16u));
3450 /* Read the player_hp array */
3451 for (i = 0; i < tmp16u; i++)
3453 rd_s16b(&p_ptr->player_hp[i]);
3456 /* Important -- Initialize the sex */
3457 sp_ptr = &sex_info[p_ptr->psex];
3459 /* Important -- Initialize the race/class */
3460 rp_ptr = &race_info[p_ptr->prace];
3461 cp_ptr = &class_info[p_ptr->pclass];
3462 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3464 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3466 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3467 do_cmd_rerate(FALSE);
3469 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3471 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3472 do_cmd_rerate(FALSE);
3474 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3476 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3477 do_cmd_rerate(FALSE);
3479 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3481 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3482 do_cmd_rerate(FALSE);
3485 /* Important -- Initialize the magic */
3486 mp_ptr = &m_info[p_ptr->pclass];
3489 /* Read spell info */
3490 rd_u32b(&p_ptr->spell_learned1);
3491 rd_u32b(&p_ptr->spell_learned2);
3492 rd_u32b(&p_ptr->spell_worked1);
3493 rd_u32b(&p_ptr->spell_worked2);
3494 rd_u32b(&p_ptr->spell_forgotten1);
3495 rd_u32b(&p_ptr->spell_forgotten2);
3497 if (z_older_than(10,0,5))
3499 p_ptr->learned_spells = 0;
3500 for (i = 0; i < 64; i++)
3502 /* Count known spells */
3504 (p_ptr->spell_learned1 & (1L << i)) :
3505 (p_ptr->spell_learned2 & (1L << (i - 32))))
3507 p_ptr->learned_spells++;
3511 else rd_s16b(&p_ptr->learned_spells);
3513 if (z_older_than(10,0,6))
3515 p_ptr->add_spells = 0;
3517 else rd_s16b(&p_ptr->add_spells);
3518 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3520 for (i = 0; i < 64; i++)
3522 rd_byte(&p_ptr->spell_order[i]);
3526 /* Read the inventory */
3530 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
3532 note("Unable to read inventory");
3538 /* Read number of towns */
3540 town_count = tmp16u;
3542 /* Read the stores */
3544 for (i = 1; i < town_count; i++)
3546 for (j = 0; j < tmp16u; j++)
3548 if (rd_store(i, j)) return (22);
3552 rd_s16b(&p_ptr->pet_follow_distance);
3553 if (z_older_than(10, 4, 10))
3555 p_ptr->pet_extra_flags = 0;
3557 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3559 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3561 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3565 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3568 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3572 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3575 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3579 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3582 if (!z_older_than(10,0,8))
3585 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3590 rd_s16b(&p_ptr->pet_extra_flags);
3593 if (!z_older_than(11, 0, 9))
3595 char buf[SCREEN_BUF_SIZE];
3596 rd_string(buf, sizeof(buf));
3597 if (buf[0]) screen_dump = string_make(buf);
3602 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3604 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3609 /* I'm not dead yet... */
3610 if (!p_ptr->is_dead)
3612 /* Dead players have no dungeon */
3614 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
3616 note("Restoring Dungeon...");
3622 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
3624 note("Error reading dungeon data");
3630 /* Read the ghost info */
3637 strip_bytes(tmp32s);
3642 #ifdef VERIFY_CHECKSUMS
3644 /* Save the checksum */
3645 n_v_check = v_check;
3647 /* Read the old checksum */
3648 rd_u32b(&o_v_check);
3651 if (o_v_check != n_v_check)
3654 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3656 note("Invalid checksum");
3663 /* Save the encoded checksum */
3664 n_x_check = x_check;
3666 /* Read the checksum */
3667 rd_u32b(&o_x_check);
3671 if (o_x_check != n_x_check)
3674 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3676 note("Invalid encoded checksum");
3690 * Actually read the savefile
3692 errr rd_savefile_new(void)
3696 /* Grab permissions */
3699 /* The savefile is a binary file */
3700 fff = my_fopen(savefile, "rb");
3702 /* Drop permissions */
3706 if (!fff) return (-1);
3708 /* Call the sub-function */
3709 err = rd_savefile_new_aux();
3711 /* Check for errors */
3712 if (ferror(fff)) err = -1;
3714 /* Close the file */
3723 * Actually load and verify a floor save data
3725 static bool load_floor_aux(saved_floor_type *sf_ptr)
3730 #ifdef VERIFY_CHECKSUMS
3731 u32b n_x_check, n_v_check;
3732 u32b o_x_check, o_v_check;
3735 /* Hack -- decrypt (read xor_byte) */
3739 /* Clear the checksums */
3743 /* Set the version number to current version */
3744 /* Never load old temporal files */
3745 h_ver_extra = H_VER_EXTRA;
3746 h_ver_patch = H_VER_PATCH;
3747 h_ver_minor = H_VER_MINOR;
3748 h_ver_major = H_VER_MAJOR;
3750 /* Verify the sign */
3752 if (saved_floor_file_sign != tmp32u) return FALSE;
3754 /* Read -- have error? */
3755 if (rd_saved_floor(sf_ptr)) return FALSE;
3758 #ifdef VERIFY_CHECKSUMS
3759 /* Save the checksum */
3760 n_v_check = v_check;
3762 /* Read the old checksum */
3763 rd_u32b(&o_v_check);
3766 if (o_v_check != n_v_check) return FALSE;
3768 /* Save the encoded checksum */
3769 n_x_check = x_check;
3771 /* Read the checksum */
3772 rd_u32b(&o_x_check);
3775 if (o_x_check != n_x_check) return FALSE;
3784 * Attempt to load the temporally saved-floor data
3786 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
3788 FILE *old_fff = NULL;
3789 byte old_xor_byte = 0;
3790 u32b old_v_check = 0;
3791 u32b old_x_check = 0;
3792 byte old_h_ver_major = 0;
3793 byte old_h_ver_minor = 0;
3794 byte old_h_ver_patch = 0;
3795 byte old_h_ver_extra = 0;
3798 char floor_savefile[1024];
3800 /* We have one file already opened */
3801 if (mode & SLF_SECOND)
3803 /* Backup original values */
3805 old_xor_byte = xor_byte;
3806 old_v_check = v_check;
3807 old_x_check = x_check;
3808 old_h_ver_major = h_ver_major;
3809 old_h_ver_minor = h_ver_minor;
3810 old_h_ver_patch = h_ver_patch;
3811 old_h_ver_extra = h_ver_extra;
3814 /* floor savefile */
3815 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3817 /* Grab permissions */
3820 /* The savefile is a binary file */
3821 fff = my_fopen(floor_savefile, "rb");
3823 /* Drop permissions */
3827 if (!fff) ok = FALSE;
3829 /* Attempt to load */
3832 /* Load saved floor data from file */
3833 ok = load_floor_aux(sf_ptr);
3835 /* Check for errors */
3836 if (ferror(fff)) ok = FALSE;
3838 /* Close the file */
3841 /* Grab permissions */
3844 /* Delete the file */
3845 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3847 /* Drop permissions */
3851 /* We have one file already opened */
3852 if (mode & SLF_SECOND)
3854 /* Restore original values */
3856 xor_byte = old_xor_byte;
3857 v_check = old_v_check;
3858 x_check = old_x_check;
3859 h_ver_major = old_h_ver_major;
3860 h_ver_minor = old_h_ver_minor;
3861 h_ver_patch = old_h_ver_patch;
3862 h_ver_extra = old_h_ver_extra;