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 (o_ptr->tval > TV_CAPTURE && 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 /* Extract the options */
1224 extract_option_vars();
1226 if (z_older_than(10, 4, 5))
1228 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1229 else option_flag[5] |= (0x00000001 << 4);
1230 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1231 else option_flag[2] |= (0x00000001 << 5);
1232 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1233 else option_flag[4] |= (0x00000001 << 5);
1234 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1235 else option_flag[5] |= (0x00000001 << 0);
1236 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1237 else option_flag[5] |= (0x00000001 << 12);
1238 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1239 else option_flag[1] |= (0x00000001 << 0);
1240 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1241 else option_flag[1] |= (0x00000001 << 18);
1242 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1243 else option_flag[1] |= (0x00000001 << 19);
1244 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1245 else option_flag[5] |= (0x00000001 << 3);
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);
1576 p_ptr->inside_arena = (bool)tmp16s;
1577 rd_s16b(&p_ptr->inside_quest);
1578 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1582 p_ptr->inside_battle = (bool)tmp16s;
1584 rd_byte(&p_ptr->exit_bldg);
1585 rd_byte(&p_ptr->leftbldg);
1587 rd_s16b(&p_ptr->oldpx);
1588 rd_s16b(&p_ptr->oldpy);
1589 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1593 if (tmp16s > MAX_BACT)
1596 note(format("¤ÎÃæ", tmp16s));
1598 note(format("Too many (%d) building rewards!", tmp16s));
1603 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1605 rd_s16b(&p_ptr->mhp);
1606 rd_s16b(&p_ptr->chp);
1607 rd_u16b(&p_ptr->chp_frac);
1609 rd_s16b(&p_ptr->msp);
1610 rd_s16b(&p_ptr->csp);
1611 rd_u16b(&p_ptr->csp_frac);
1613 rd_s16b(&p_ptr->max_plv);
1614 if (z_older_than(10, 3, 8))
1616 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1620 byte max = (byte)max_d_idx;
1624 for(i = 0; i < max; i++)
1626 rd_s16b(&max_dlv[i]);
1627 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1631 /* Repair maximum player level XXX XXX XXX */
1632 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1636 rd_s16b(&p_ptr->sc);
1639 /* Read the flags */
1640 strip_bytes(2); /* Old "rest" */
1641 rd_s16b(&p_ptr->blind);
1642 rd_s16b(&p_ptr->paralyzed);
1643 rd_s16b(&p_ptr->confused);
1644 rd_s16b(&p_ptr->food);
1645 strip_bytes(4); /* Old "food_digested" / "protection" */
1647 rd_s16b(&p_ptr->energy_need);
1648 if (z_older_than(11, 0, 13))
1649 p_ptr->energy_need = 100 - p_ptr->energy_need;
1651 rd_s16b(&p_ptr->fast);
1652 rd_s16b(&p_ptr->slow);
1653 rd_s16b(&p_ptr->afraid);
1654 rd_s16b(&p_ptr->cut);
1655 rd_s16b(&p_ptr->stun);
1656 rd_s16b(&p_ptr->poisoned);
1657 rd_s16b(&p_ptr->image);
1658 rd_s16b(&p_ptr->protevil);
1659 rd_s16b(&p_ptr->invuln);
1660 if(z_older_than(10, 0, 0))
1663 rd_s16b(&p_ptr->ult_res);
1664 rd_s16b(&p_ptr->hero);
1665 rd_s16b(&p_ptr->shero);
1666 rd_s16b(&p_ptr->shield);
1667 rd_s16b(&p_ptr->blessed);
1668 rd_s16b(&p_ptr->tim_invis);
1669 rd_s16b(&p_ptr->word_recall);
1670 if (z_older_than(10, 3, 8))
1671 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1675 p_ptr->recall_dungeon = (byte)tmp16s;
1678 if (h_older_than(1, 5, 0, 0))
1679 p_ptr->alter_reality = 0;
1681 rd_s16b(&p_ptr->alter_reality);
1683 rd_s16b(&p_ptr->see_infra);
1684 rd_s16b(&p_ptr->tim_infra);
1685 rd_s16b(&p_ptr->oppose_fire);
1686 rd_s16b(&p_ptr->oppose_cold);
1687 rd_s16b(&p_ptr->oppose_acid);
1688 rd_s16b(&p_ptr->oppose_elec);
1689 rd_s16b(&p_ptr->oppose_pois);
1690 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1691 else rd_s16b(&p_ptr->tsuyoshi);
1693 /* Old savefiles do not have the following fields... */
1694 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1697 p_ptr->wraith_form = 0;
1698 p_ptr->resist_magic = 0;
1699 p_ptr->tim_regen = 0;
1700 p_ptr->kabenuke = 0;
1701 p_ptr->tim_stealth = 0;
1702 p_ptr->tim_ffall = 0;
1703 p_ptr->tim_sh_touki = 0;
1704 p_ptr->lightspeed = 0;
1705 p_ptr->tsubureru = 0;
1706 p_ptr->tim_res_nether = 0;
1707 p_ptr->tim_res_time = 0;
1708 p_ptr->mimic_form = 0;
1709 p_ptr->tim_mimic = 0;
1710 p_ptr->tim_sh_fire = 0;
1713 p_ptr->tim_reflect = 0;
1714 p_ptr->multishadow = 0;
1715 p_ptr->dustrobe = 0;
1717 p_ptr->chaos_patron = get_chaos_patron();
1725 rd_s16b(&p_ptr->tim_esp);
1726 rd_s16b(&p_ptr->wraith_form);
1727 rd_s16b(&p_ptr->resist_magic);
1728 rd_s16b(&p_ptr->tim_regen);
1729 rd_s16b(&p_ptr->kabenuke);
1730 rd_s16b(&p_ptr->tim_stealth);
1731 rd_s16b(&p_ptr->tim_ffall);
1732 rd_s16b(&p_ptr->tim_sh_touki);
1733 rd_s16b(&p_ptr->lightspeed);
1734 rd_s16b(&p_ptr->tsubureru);
1735 if (z_older_than(10, 4, 7))
1736 p_ptr->magicdef = 0;
1738 rd_s16b(&p_ptr->magicdef);
1739 rd_s16b(&p_ptr->tim_res_nether);
1740 if (z_older_than(10, 4, 11))
1742 p_ptr->tim_res_time = 0;
1743 p_ptr->mimic_form = 0;
1744 p_ptr->tim_mimic = 0;
1745 p_ptr->tim_sh_fire = 0;
1749 rd_s16b(&p_ptr->tim_res_time);
1750 rd_byte(&p_ptr->mimic_form);
1751 rd_s16b(&p_ptr->tim_mimic);
1752 rd_s16b(&p_ptr->tim_sh_fire);
1755 if (z_older_than(11, 0, 99))
1757 p_ptr->tim_sh_holy = 0;
1758 p_ptr->tim_eyeeye = 0;
1762 rd_s16b(&p_ptr->tim_sh_holy);
1763 rd_s16b(&p_ptr->tim_eyeeye);
1767 if ( z_older_than(11,0,3) ){
1768 p_ptr->tim_reflect=0;
1769 p_ptr->multishadow=0;
1773 rd_s16b(&p_ptr->tim_reflect);
1774 rd_s16b(&p_ptr->multishadow);
1775 rd_s16b(&p_ptr->dustrobe);
1778 rd_s16b(&p_ptr->chaos_patron);
1779 rd_u32b(&p_ptr->muta1);
1780 rd_u32b(&p_ptr->muta2);
1781 rd_u32b(&p_ptr->muta3);
1783 for (i = 0; i < 8; i++)
1784 rd_s16b(&p_ptr->virtues[i]);
1785 for (i = 0; i < 8; i++)
1786 rd_s16b(&p_ptr->vir_types[i]);
1789 /* Calc the regeneration modifier for mutations */
1790 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1792 if (z_older_than(10,0,9))
1795 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1796 p_ptr->ele_attack = 0;
1800 rd_s16b(&p_ptr->ele_attack);
1801 rd_u32b(&p_ptr->special_attack);
1803 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1804 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1805 if (z_older_than(10,0,12))
1807 p_ptr->ele_immune = 0;
1808 p_ptr->special_defense = 0;
1812 rd_s16b(&p_ptr->ele_immune);
1813 rd_u32b(&p_ptr->special_defense);
1815 rd_byte(&p_ptr->knowledge);
1816 rd_byte(&tmp8u); /* oops */
1817 rd_byte(&tmp8u); /* oops */
1818 rd_byte(&p_ptr->action);
1819 if (!z_older_than(10, 4, 3))
1822 if (tmp8u) p_ptr->action = ACTION_LEARN;
1824 rd_byte((byte *)&preserve_mode);
1825 rd_byte((byte *)&p_ptr->wait_report_score);
1828 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1830 /* Skip the flags */
1834 /* Hack -- the two "special seeds" */
1835 rd_u32b(&seed_flavor);
1836 rd_u32b(&seed_town);
1840 rd_u16b(&p_ptr->panic_save);
1841 rd_u16b(&p_ptr->total_winner);
1842 rd_u16b(&p_ptr->noscore);
1847 p_ptr->is_dead = tmp8u;
1849 /* Read "feeling" */
1853 /* Turn of last "feeling" */
1859 if (z_older_than(10, 3, 12))
1861 dungeon_turn = turn;
1863 else rd_s32b(&dungeon_turn);
1865 if (z_older_than(11, 0, 13))
1872 if (z_older_than(10, 3, 13))
1876 else rd_s32b(&old_battle);
1878 if (z_older_than(10,0,3))
1880 monster_race *r_ptr;
1884 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1885 r_ptr = &r_info[today_mon];
1887 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1888 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1889 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1890 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1891 if (r_ptr->rarity > 10) continue;
1892 if (r_ptr->level == 0) continue;
1896 p_ptr->today_mon = 0;
1900 rd_s16b(&today_mon);
1901 rd_s16b(&p_ptr->today_mon);
1904 if (z_older_than(10,0,7))
1910 rd_s16b(&p_ptr->riding);
1913 /* Current floor_id */
1914 if (h_older_than(1, 5, 0, 0))
1916 p_ptr->floor_id = 0;
1920 rd_s16b(&p_ptr->floor_id);
1923 if (z_older_than(10,1,2))
1932 if (z_older_than(10,3,9))
1936 else if (z_older_than(10, 3, 10))
1944 rd_s32b(&p_ptr->visit);
1946 if (!z_older_than(11, 0, 5))
1948 rd_u32b(&p_ptr->count);
1956 * Read the player inventory
1958 * Note that the inventory changed in Angband 2.7.4. Two extra
1959 * pack slots were added and the equipment was rearranged. Note
1960 * that these two features combine when parsing old save-files, in
1961 * which items from the old "aux" slot are "carried", perhaps into
1962 * one of the two new "inventory" slots.
1964 * Note that the inventory is "re-sorted" later by "dungeon()".
1966 static errr rd_inventory(void)
1974 p_ptr->total_weight = 0;
1980 /* Read until done */
1985 /* Get the next item index */
1988 /* Nope, we reached the end */
1989 if (n == 0xFFFF) break;
1991 /* Get local object */
1994 /* Wipe the object */
2000 /* Hack -- verify item */
2001 if (!q_ptr->k_idx) return (53);
2003 /* Wield equipment */
2004 if (n >= INVEN_RARM)
2007 object_copy(&inventory[n], q_ptr);
2009 /* Add the weight */
2010 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2016 /* Warning -- backpack is full */
2017 else if (inven_cnt == INVEN_PACK)
2021 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
2023 note("Too many items in the inventory!");
2031 /* Carry inventory */
2038 object_copy(&inventory[n], q_ptr);
2040 /* Add the weight */
2041 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2055 * Read the saved messages
2057 static void rd_messages(void)
2067 /* Read the messages */
2068 for (i = 0; i < num; i++)
2070 /* Read the message */
2071 rd_string(buf, sizeof(buf));
2073 /* Save the message */
2080 /* Old hidden trap flag */
2081 #define CAVE_TRAP 0x8000
2084 * Read the dungeon (old method)
2086 * The monsters/objects must be loaded in the same order
2087 * that they were stored, since the actual indexes matter.
2089 static errr rd_dungeon_old(void)
2100 /*** Basic info ***/
2103 rd_s16b(&dun_level);
2104 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2105 else rd_byte(&dungeon_type);
2107 /* Set the base level for old versions */
2108 base_level = dun_level;
2110 rd_s16b(&base_level);
2112 rd_s16b(&num_repro);
2117 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2120 rd_s16b(&tmp16s); /* max_panel_rows */
2121 rd_s16b(&tmp16s); /* max_panel_cols */
2124 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
2132 /*** Run length decoding ***/
2134 /* Load the dungeon data */
2135 for (x = y = 0; y < ymax; )
2141 if (z_older_than(10,3,6))
2150 /* Decline invalid flags */
2151 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT);
2154 /* Apply the RLE info */
2155 for (i = count; i > 0; i--)
2157 /* Access the cave */
2158 c_ptr = &cave[y][x];
2160 /* Extract "info" */
2170 if (++y >= ymax) break;
2176 /*** Run length decoding ***/
2178 /* Load the dungeon data */
2179 for (x = y = 0; y < ymax; )
2185 /* Apply the RLE info */
2186 for (i = count; i > 0; i--)
2188 /* Access the cave */
2189 c_ptr = &cave[y][x];
2191 /* Extract "feat" */
2192 c_ptr->feat = tmp8u;
2201 if (++y >= ymax) break;
2206 /*** Run length decoding ***/
2208 /* Load the dungeon data */
2209 for (x = y = 0; y < ymax; )
2215 /* Apply the RLE info */
2216 for (i = count; i > 0; i--)
2218 /* Access the cave */
2219 c_ptr = &cave[y][x];
2221 /* Extract "feat" */
2222 c_ptr->mimic = tmp8u;
2231 if (++y >= ymax) break;
2236 /*** Run length decoding ***/
2238 /* Load the dungeon data */
2239 for (x = y = 0; y < ymax; )
2245 /* Apply the RLE info */
2246 for (i = count; i > 0; i--)
2248 /* Access the cave */
2249 c_ptr = &cave[y][x];
2251 /* Extract "feat" */
2252 c_ptr->special = tmp16s;
2261 if (++y >= ymax) break;
2266 /* Convert cave data */
2267 if (z_older_than(11, 0, 99))
2269 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2271 /* Wipe old unused flags */
2272 cave[y][x].info &= ~(CAVE_MASK);
2276 if (h_older_than(1, 1, 1, 0))
2278 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2280 /* Access the cave */
2281 c_ptr = &cave[y][x];
2284 if (c_ptr->feat == FEAT_INVIS)
2286 c_ptr->feat = FEAT_FLOOR;
2287 c_ptr->info |= CAVE_TRAP;
2290 /* Older than 1.1.1 */
2291 if (c_ptr->feat == FEAT_MIRROR)
2293 c_ptr->feat = FEAT_FLOOR;
2294 c_ptr->info |= CAVE_OBJECT;
2299 if (h_older_than(1, 3, 1, 0))
2301 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2303 /* Access the cave */
2304 c_ptr = &cave[y][x];
2306 /* Old CAVE_IN_MIRROR flag */
2307 if (c_ptr->info & CAVE_OBJECT)
2309 c_ptr->mimic = FEAT_MIRROR;
2312 /* Runes will be mimics and flags */
2313 else if (c_ptr->feat == FEAT_MINOR_GLYPH ||
2314 c_ptr->feat == FEAT_GLYPH)
2316 c_ptr->info |= CAVE_OBJECT;
2317 c_ptr->mimic = c_ptr->feat;
2318 c_ptr->feat = FEAT_FLOOR;
2321 /* Hidden traps will be trap terrains mimicing floor */
2322 else if (c_ptr->info & CAVE_TRAP)
2324 c_ptr->info &= ~CAVE_TRAP;
2325 c_ptr->mimic = c_ptr->feat;
2326 c_ptr->feat = choose_random_trap();
2329 /* Another hidden trap */
2330 else if (c_ptr->feat == FEAT_INVIS)
2332 c_ptr->mimic = FEAT_FLOOR;
2333 c_ptr->feat = FEAT_TRAP_OPEN;
2336 /* Hidden doors will be closed doors mimicing wall */
2337 else if (c_ptr->feat == FEAT_SECRET)
2339 place_closed_door(y, x);
2340 c_ptr->mimic = FEAT_WALL_EXTRA;
2347 /* Read the item count */
2350 /* Verify maximum */
2351 if (limit > max_o_idx)
2354 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2356 note(format("Too many (%d) object entries!", limit));
2362 /* Read the dungeon items */
2363 for (i = 1; i < limit; i++)
2370 /* Get a new record */
2377 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2379 note(format("Object allocation error (%d <> %d)", i, o_idx));
2387 o_ptr = &o_list[o_idx];
2393 /* XXX XXX XXX XXX XXX */
2396 if (o_ptr->held_m_idx)
2398 monster_type *m_ptr;
2401 m_ptr = &m_list[o_ptr->held_m_idx];
2404 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2406 /* Place the object */
2407 m_ptr->hold_o_idx = o_idx;
2413 /* Access the item location */
2414 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2417 o_ptr->next_o_idx = c_ptr->o_idx;
2419 /* Place the object */
2420 c_ptr->o_idx = o_idx;
2427 /* Read the monster count */
2430 /* Hack -- verify */
2431 if (limit > max_m_idx)
2434 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2436 note(format("Too many (%d) monster entries!", limit));
2442 /* Read the monsters */
2443 for (i = 1; i < limit; i++)
2446 monster_type *m_ptr;
2448 /* Get a new record */
2455 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2457 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2464 /* Acquire monster */
2465 m_ptr = &m_list[m_idx];
2467 /* Read the monster */
2472 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2474 /* Mark the location */
2475 c_ptr->m_idx = m_idx;
2478 real_r_ptr(m_ptr)->cur_num++;
2483 /* The dungeon is ready */
2484 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2485 character_dungeon = FALSE;
2487 character_dungeon = TRUE;
2496 * Read the saved floor
2498 * The monsters/objects must be loaded in the same order
2499 * that they were stored, since the actual indexes matter.
2501 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2513 cave_template_type *template;
2516 /*** Wipe all cave ***/
2520 /*** Basic info ***/
2522 /* Dungeon floor specific info follows */
2526 /*** Not a saved floor ***/
2528 rd_s16b(&dun_level);
2529 base_level = dun_level;
2533 /*** The saved floor ***/
2536 if (tmp16s != sf_ptr->floor_id) return 171;
2539 if (tmp8u != sf_ptr->savefile_id) return 171;
2542 if (tmp16s != sf_ptr->dun_level) return 171;
2543 dun_level = sf_ptr->dun_level;
2546 if (tmp32s != sf_ptr->last_visit) return 171;
2549 if (tmp32u != sf_ptr->visit_mark) return 171;
2552 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2555 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2558 rd_s16b(&base_level);
2559 rd_s16b(&num_repro);
2574 /*** Read template for cave_type ***/
2576 /* Read the template count */
2579 /* Allocate the "template" array */
2580 C_MAKE(template, limit, cave_template_type);
2582 /* Read the templates */
2583 for (i = 0; i < limit; i++)
2585 cave_template_type *ct_ptr = &template[i];
2588 rd_u16b(&ct_ptr->info);
2589 rd_byte(&ct_ptr->feat);
2590 rd_byte(&ct_ptr->mimic);
2591 rd_s16b(&ct_ptr->special);
2599 /*** Run length decoding ***/
2601 /* Load the dungeon data */
2602 for (x = y = 0; y < ymax; )
2614 } while (tmp8u == MAX_UCHAR);
2616 /* Apply the RLE info */
2617 for (i = count; i > 0; i--)
2619 /* Access the cave */
2620 cave_type *c_ptr = &cave[y][x];
2622 /* Extract cave data */
2623 c_ptr->info = template[id].info;
2624 c_ptr->feat = template[id].feat;
2625 c_ptr->mimic = template[id].mimic;
2626 c_ptr->special = template[id].special;
2635 if (++y >= ymax) break;
2640 /* Free the "template" array */
2641 C_FREE(template, limit, cave_template_type);
2646 /* Read the item count */
2649 /* Verify maximum */
2650 if (limit > max_o_idx) return 151;
2653 /* Read the dungeon items */
2654 for (i = 1; i < limit; i++)
2660 /* Get a new record */
2664 if (i != o_idx) return 152;
2667 o_ptr = &o_list[o_idx];
2674 if (o_ptr->held_m_idx)
2676 monster_type *m_ptr;
2679 m_ptr = &m_list[o_ptr->held_m_idx];
2682 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2684 /* Place the object */
2685 m_ptr->hold_o_idx = o_idx;
2691 /* Access the item location */
2692 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2695 o_ptr->next_o_idx = c_ptr->o_idx;
2697 /* Place the object */
2698 c_ptr->o_idx = o_idx;
2705 /* Read the monster count */
2708 /* Hack -- verify */
2709 if (limit > max_m_idx) return 161;
2711 /* Read the monsters */
2712 for (i = 1; i < limit; i++)
2716 monster_type *m_ptr;
2718 /* Get a new record */
2722 if (i != m_idx) return 162;
2725 /* Acquire monster */
2726 m_ptr = &m_list[m_idx];
2728 /* Read the monster */
2733 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2735 /* Mark the location */
2736 c_ptr->m_idx = m_idx;
2739 real_r_ptr(m_ptr)->cur_num++;
2748 * Read the dungeon (new method)
2750 * The monsters/objects must be loaded in the same order
2751 * that they were stored, since the actual indexes matter.
2753 static errr rd_dungeon(void)
2759 /* Initialize saved_floors array and temporal files */
2760 init_saved_floors();
2763 if (h_older_than(1, 5, 0, 0))
2765 err = rd_dungeon_old();
2767 /* Prepare floor_id of current floor */
2770 p_ptr->floor_id = get_new_floor_id();
2771 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
2780 /* Number of floor_id used from birth */
2781 rd_s16b(&max_floor_id);
2783 /* Current dungeon type */
2784 rd_byte(&dungeon_type);
2787 /*** On the surface ***/
2788 if (!p_ptr->floor_id)
2790 /* Number of array elements?? */
2793 /* It should be 0 */
2796 /* Read the current floor data */
2797 err = rd_saved_floor(NULL);
2800 /*** In the dungeon ***/
2803 /* Number of array elements */
2806 /* Read the saved_floors array */
2807 for (i = 0; i < num; i++)
2809 saved_floor_type *sf_ptr = &saved_floors[i];
2811 rd_s16b(&sf_ptr->floor_id);
2812 rd_byte(&sf_ptr->savefile_id);
2813 rd_s16b(&sf_ptr->dun_level);
2814 rd_s32b(&sf_ptr->last_visit);
2815 rd_u32b(&sf_ptr->visit_mark);
2816 rd_s16b(&sf_ptr->upper_floor_id);
2817 rd_s16b(&sf_ptr->lower_floor_id);
2821 /* Move saved floors data to temporal files */
2822 for (i = 0; i < num; i++)
2824 saved_floor_type *sf_ptr = &saved_floors[i];
2827 /* Unused element */
2828 if (!sf_ptr->floor_id) continue;
2830 /* Read the failure mark */
2832 if (tmp8u) continue;
2834 /* Read from the save file */
2835 err = rd_saved_floor(sf_ptr);
2840 /* Re-save as temporal saved floor file */
2841 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
2847 /* Finally load current floor data from temporal file */
2850 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
2855 /*** Error messages ***/
2860 note("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
2862 note("Too many object entries!");
2868 note("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼");
2870 note("Object allocation error");
2876 note("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
2878 note("Too many monster entries!");
2884 note("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼");
2886 note("Monster allocation error");
2892 note("Êݸ¤µ¤ì¤¿¥Õ¥í¥¢¤Î¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡ª");
2894 note("Dungeon data of saved floors are broken!");
2908 note("¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
2910 note("Failed to make temporal files!");
2923 /* The dungeon is ready */
2924 character_dungeon = TRUE;
2926 /* Success or Error */
2932 * Actually read the savefile
2934 static errr rd_savefile_new_aux(void)
2946 #ifdef VERIFY_CHECKSUMS
2947 u32b n_x_check, n_v_check;
2948 u32b o_x_check, o_v_check;
2952 /* Mention the savefile version */
2955 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2957 "Loading a %d.%d.%d savefile...",
2959 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2962 /* Strip the version bytes */
2965 /* Hack -- decrypt */
2966 xor_byte = sf_extra;
2969 /* Clear the checksums */
2973 /* Read the version number of the savefile */
2974 /* Old savefile will be version 0.0.0.3 */
2975 rd_byte(&h_ver_extra);
2976 rd_byte(&h_ver_patch);
2977 rd_byte(&h_ver_minor);
2978 rd_byte(&h_ver_major);
2980 /* Operating system info */
2981 rd_u32b(&sf_system);
2983 /* Time of savefile creation */
2986 /* Number of resurrections */
2989 /* Number of times played */
2993 /* Later use (always zero) */
2996 /* Later use (always zero) */
3000 /* Read RNG state */
3003 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3005 if (arg_fiddle) note("Loaded Randomizer Info");
3010 /* Then the options */
3013 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3015 if (arg_fiddle) note("Loaded Option Flags");
3018 /* Then the "messages" */
3021 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3023 if (arg_fiddle) note("Loaded Messages");
3028 for (i = 0; i < max_r_idx; i++)
3030 /* Access that monster */
3031 monster_race *r_ptr = &r_info[i];
3033 /* Hack -- Reset the death counter */
3034 r_ptr->max_num = 100;
3035 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3036 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
3039 /* Monster Memory */
3042 /* Incompatible save files */
3043 if (tmp16u > max_r_idx)
3046 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3048 note(format("Too many (%u) monster races!", tmp16u));
3054 /* Read the available records */
3055 for (i = 0; i < tmp16u; i++)
3062 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3064 if (arg_fiddle) note("Loaded Monster Memory");
3072 /* Incompatible save files */
3073 if (tmp16u > max_k_idx)
3076 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3078 note(format("Too many (%u) object kinds!", tmp16u));
3084 /* Read the object memory */
3085 for (i = 0; i < tmp16u; i++)
3088 object_kind *k_ptr = &k_info[i];
3092 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3093 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3096 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3098 if (arg_fiddle) note("Loaded Object Memory");
3104 * Initialize arena and rewards information
3106 p_ptr->arena_number = 0;
3107 p_ptr->inside_arena = 0;
3108 p_ptr->inside_quest = 0;
3109 p_ptr->leftbldg = FALSE;
3110 p_ptr->exit_bldg = TRUE;
3112 /* Start in town 1 */
3113 p_ptr->town_num = 1;
3115 p_ptr->wilderness_x = 4;
3116 p_ptr->wilderness_y = 4;
3120 /* Init the wilderness seeds */
3121 for (i = 0; i < max_wild_x; i++)
3123 for (j = 0; j < max_wild_y; j++)
3125 wilderness[j][i].seed = randint0(0x10000000);
3129 /* 2.1.3 or newer version */
3131 u16b max_towns_load;
3132 u16b max_quests_load;
3133 byte max_rquests_load;
3134 s16b old_inside_quest = p_ptr->inside_quest;
3136 /* Number of towns */
3137 rd_u16b(&max_towns_load);
3139 /* Incompatible save files */
3140 if (max_towns_load > max_towns)
3143 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
3145 note(format("Too many (%u) towns!", max_towns_load));
3151 /* Number of quests */
3152 rd_u16b(&max_quests_load);
3154 if (z_older_than(11, 0, 7))
3156 max_rquests_load = 10;
3160 rd_byte(&max_rquests_load);
3163 /* Incompatible save files */
3164 if (max_quests_load > max_quests)
3167 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
3169 note(format("Too many (%u) quests!", max_quests_load));
3175 for (i = 0; i < max_quests_load; i++)
3179 rd_s16b(&quest[i].status);
3180 rd_s16b(&quest[i].level);
3182 if (z_older_than(11, 0, 6))
3184 quest[i].complev = 0;
3188 rd_byte(&quest[i].complev);
3191 /* Load quest status if quest is running */
3192 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))))
3194 rd_s16b(&quest[i].cur_num);
3195 rd_s16b(&quest[i].max_num);
3196 rd_s16b(&quest[i].type);
3198 /* Load quest monster index */
3199 rd_s16b(&quest[i].r_idx);
3201 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
3206 monster_race *r_ptr;
3209 * Random monster 5 - 10 levels out of depth
3210 * (depending on level)
3212 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
3213 r_ptr = &r_info[r_idx];
3215 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
3217 if(r_ptr->flags6 & RF6_SPECIAL) continue;
3219 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
3221 if(r_ptr->flags7 & RF7_AQUATIC) continue;
3223 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
3226 * Accept monsters that are 2 - 6 levels
3227 * out of depth depending on the quest level
3229 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
3232 quest[i].r_idx = r_idx;
3235 /* Load quest item index */
3236 rd_s16b(&quest[i].k_idx);
3239 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
3241 rd_byte(&quest[i].flags);
3243 if (z_older_than(10, 3, 11))
3245 if (quest[i].flags & QUEST_FLAG_PRESET)
3247 quest[i].dungeon = 0;
3251 init_flags = INIT_ASSIGN;
3252 p_ptr->inside_quest = i;
3254 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3255 p_ptr->inside_quest = old_inside_quest;
3260 rd_byte(&quest[i].dungeon);
3263 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
3264 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
3265 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
3268 /* Ignore the empty quests from old versions */
3271 /* Ignore quest status */
3274 /* Ignore quest level */
3278 * We don't have to care about the other info,
3279 * since status should be 0 for these quests anyway
3284 /* Position in the wilderness */
3285 rd_s32b(&p_ptr->wilderness_x);
3286 rd_s32b(&p_ptr->wilderness_y);
3287 if (z_older_than(10, 3, 13))
3289 p_ptr->wilderness_x = 5;
3290 p_ptr->wilderness_y = 48;
3293 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3294 else rd_byte((byte *)&p_ptr->wild_mode);
3295 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3296 else rd_byte((byte *)&ambush_flag);
3298 /* Size of the wilderness */
3299 rd_s32b(&wild_x_size);
3300 rd_s32b(&wild_y_size);
3302 /* Incompatible save files */
3303 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3306 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
3308 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
3314 /* Load the wilderness seeds */
3315 for (i = 0; i < wild_x_size; i++)
3317 for (j = 0; j < wild_y_size; j++)
3319 rd_u32b(&wilderness[j][i].seed);
3325 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3327 if (arg_fiddle) note("Loaded Quests");
3330 /* Load the Artifacts */
3333 /* Incompatible save files */
3334 if (tmp16u > max_a_idx)
3337 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3339 note(format("Too many (%u) artifacts!", tmp16u));
3345 /* Read the artifact flags */
3346 for (i = 0; i < tmp16u; i++)
3348 artifact_type *a_ptr = &a_info[i];
3351 a_ptr->cur_num = tmp8u;
3353 if (h_older_than(1, 5, 0, 0))
3355 a_ptr->floor_id = 0;
3363 rd_s16b(&a_ptr->floor_id);
3367 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3369 if (arg_fiddle) note("Loaded Artifacts");
3374 /* Read the extra stuff */
3376 if (p_ptr->energy_need < -999) world_player = TRUE;
3379 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3381 if (arg_fiddle) note("Loaded extra information");
3385 /* Read the player_hp array */
3388 /* Incompatible save files */
3389 if (tmp16u > PY_MAX_LEVEL)
3392 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
3394 note(format("Too many (%u) hitpoint entries!", tmp16u));
3400 /* Read the player_hp array */
3401 for (i = 0; i < tmp16u; i++)
3403 rd_s16b(&p_ptr->player_hp[i]);
3406 /* Important -- Initialize the sex */
3407 sp_ptr = &sex_info[p_ptr->psex];
3409 /* Important -- Initialize the race/class */
3410 rp_ptr = &race_info[p_ptr->prace];
3411 cp_ptr = &class_info[p_ptr->pclass];
3412 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3414 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3416 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3417 do_cmd_rerate(FALSE);
3419 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3421 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3422 do_cmd_rerate(FALSE);
3424 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3426 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3427 do_cmd_rerate(FALSE);
3429 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3431 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3432 do_cmd_rerate(FALSE);
3435 /* Important -- Initialize the magic */
3436 mp_ptr = &m_info[p_ptr->pclass];
3439 /* Read spell info */
3440 rd_u32b(&p_ptr->spell_learned1);
3441 rd_u32b(&p_ptr->spell_learned2);
3442 rd_u32b(&p_ptr->spell_worked1);
3443 rd_u32b(&p_ptr->spell_worked2);
3444 rd_u32b(&p_ptr->spell_forgotten1);
3445 rd_u32b(&p_ptr->spell_forgotten2);
3447 if (z_older_than(10,0,5))
3449 p_ptr->learned_spells = 0;
3450 for (i = 0; i < 64; i++)
3452 /* Count known spells */
3454 (p_ptr->spell_learned1 & (1L << i)) :
3455 (p_ptr->spell_learned2 & (1L << (i - 32))))
3457 p_ptr->learned_spells++;
3461 else rd_s16b(&p_ptr->learned_spells);
3463 if (z_older_than(10,0,6))
3465 p_ptr->add_spells = 0;
3467 else rd_s16b(&p_ptr->add_spells);
3468 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3470 for (i = 0; i < 64; i++)
3472 rd_byte(&p_ptr->spell_order[i]);
3476 /* Read the inventory */
3480 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
3482 note("Unable to read inventory");
3488 /* Read number of towns */
3490 town_count = tmp16u;
3492 /* Read the stores */
3494 for (i = 1; i < town_count; i++)
3496 for (j = 0; j < tmp16u; j++)
3498 if (rd_store(i, j)) return (22);
3502 rd_s16b(&p_ptr->pet_follow_distance);
3503 if (z_older_than(10, 4, 10))
3505 p_ptr->pet_extra_flags = 0;
3507 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3509 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3511 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3515 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3518 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3522 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3525 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3529 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3532 if (!z_older_than(10,0,8))
3535 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3540 rd_s16b(&p_ptr->pet_extra_flags);
3543 if (!z_older_than(11, 0, 9))
3545 char buf[SCREEN_BUF_SIZE];
3546 rd_string(buf, sizeof(buf));
3547 if (buf[0]) screen_dump = string_make(buf);
3552 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3554 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3559 /* I'm not dead yet... */
3560 if (!p_ptr->is_dead)
3562 /* Dead players have no dungeon */
3564 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
3566 note("Restoring Dungeon...");
3572 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
3574 note("Error reading dungeon data");
3580 /* Read the ghost info */
3587 strip_bytes(tmp32s);
3592 #ifdef VERIFY_CHECKSUMS
3594 /* Save the checksum */
3595 n_v_check = v_check;
3597 /* Read the old checksum */
3598 rd_u32b(&o_v_check);
3601 if (o_v_check != n_v_check)
3604 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3606 note("Invalid checksum");
3613 /* Save the encoded checksum */
3614 n_x_check = x_check;
3616 /* Read the checksum */
3617 rd_u32b(&o_x_check);
3621 if (o_x_check != n_x_check)
3624 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3626 note("Invalid encoded checksum");
3640 * Actually read the savefile
3642 errr rd_savefile_new(void)
3646 /* Grab permissions */
3649 /* The savefile is a binary file */
3650 fff = my_fopen(savefile, "rb");
3652 /* Drop permissions */
3656 if (!fff) return (-1);
3658 /* Call the sub-function */
3659 err = rd_savefile_new_aux();
3661 /* Check for errors */
3662 if (ferror(fff)) err = -1;
3664 /* Close the file */
3673 * Actually load and verify a floor save data
3675 static bool load_floor_aux(saved_floor_type *sf_ptr)
3680 #ifdef VERIFY_CHECKSUMS
3681 u32b n_x_check, n_v_check;
3682 u32b o_x_check, o_v_check;
3685 /* Hack -- decrypt (read xor_byte) */
3689 /* Clear the checksums */
3693 /* Set the version number to current version */
3694 /* Never load old temporal files */
3695 h_ver_extra = H_VER_EXTRA;
3696 h_ver_patch = H_VER_PATCH;
3697 h_ver_minor = H_VER_MINOR;
3698 h_ver_major = H_VER_MAJOR;
3700 /* Verify the sign */
3702 if (saved_floor_file_sign != tmp32u) return FALSE;
3704 /* Read -- have error? */
3705 if (rd_saved_floor(sf_ptr)) return FALSE;
3708 #ifdef VERIFY_CHECKSUMS
3709 /* Save the checksum */
3710 n_v_check = v_check;
3712 /* Read the old checksum */
3713 rd_u32b(&o_v_check);
3716 if (o_v_check != n_v_check) return FALSE;
3718 /* Save the encoded checksum */
3719 n_x_check = x_check;
3721 /* Read the checksum */
3722 rd_u32b(&o_x_check);
3725 if (o_x_check != n_x_check) return FALSE;
3734 * Attempt to load the temporally saved-floor data
3736 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
3738 FILE *old_fff = NULL;
3739 byte old_xor_byte = 0;
3740 u32b old_v_check = 0;
3741 u32b old_x_check = 0;
3742 byte old_h_ver_major = 0;
3743 byte old_h_ver_minor = 0;
3744 byte old_h_ver_patch = 0;
3745 byte old_h_ver_extra = 0;
3748 char floor_savefile[1024];
3750 /* We have one file already opened */
3751 if (mode & SLF_SECOND)
3753 /* Backup original values */
3755 old_xor_byte = xor_byte;
3756 old_v_check = v_check;
3757 old_x_check = x_check;
3758 old_h_ver_major = h_ver_major;
3759 old_h_ver_minor = h_ver_minor;
3760 old_h_ver_patch = h_ver_patch;
3761 old_h_ver_extra = h_ver_extra;
3764 /* floor savefile */
3765 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3767 /* Grab permissions */
3770 /* The savefile is a binary file */
3771 fff = my_fopen(floor_savefile, "rb");
3773 /* Drop permissions */
3777 if (!fff) ok = FALSE;
3779 /* Attempt to load */
3782 /* Load saved floor data from file */
3783 ok = load_floor_aux(sf_ptr);
3785 /* Check for errors */
3786 if (ferror(fff)) ok = FALSE;
3788 /* Close the file */
3791 /* Grab permissions */
3794 /* Delete the file */
3795 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3797 /* Drop permissions */
3801 /* We have one file already opened */
3802 if (mode & SLF_SECOND)
3804 /* Restore original values */
3806 xor_byte = old_xor_byte;
3807 v_check = old_v_check;
3808 x_check = old_x_check;
3809 h_ver_major = old_h_ver_major;
3810 h_ver_minor = old_h_ver_minor;
3811 h_ver_patch = old_h_ver_patch;
3812 h_ver_extra = old_h_ver_extra;