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;
77 * Hack -- Japanese Kanji code
83 static byte kanji_code = 0;
86 * This function determines if the version of the savefile
87 * currently being read is older than version "major.minor.patch.extra".
89 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
91 /* Much older, or much more recent */
92 if (h_ver_major < major) return (TRUE);
93 if (h_ver_major > major) return (FALSE);
95 /* Distinctly older, or distinctly more recent */
96 if (h_ver_minor < minor) return (TRUE);
97 if (h_ver_minor > minor) return (FALSE);
99 /* Barely older, or barely more recent */
100 if (h_ver_patch < patch) return (TRUE);
101 if (h_ver_patch > patch) return (FALSE);
103 /* Barely older, or barely more recent */
104 if (h_ver_extra < extra) return (TRUE);
105 if (h_ver_extra > extra) return (FALSE);
107 /* Identical versions */
113 * The above function, adapted for Zangband
115 static bool z_older_than(byte x, byte y, byte z)
117 /* Much older, or much more recent */
118 if (z_major < x) return (TRUE);
119 if (z_major > x) return (FALSE);
121 /* Distinctly older, or distinctly more recent */
122 if (z_minor < y) return (TRUE);
123 if (z_minor > y) return (FALSE);
125 /* Barely older, or barely more recent */
126 if (z_patch < z) return (TRUE);
127 if (z_patch > z) return (FALSE);
129 /* Identical versions */
135 * Hack -- Show information on the screen, one line at a time.
137 * Avoid the top two lines, to avoid interference with "msg_print()".
139 static void note(cptr msg)
143 /* Draw the message */
146 /* Advance one line (wrap if needed) */
147 if (++y >= 24) y = 2;
155 * The following functions are used to load the basic building blocks
156 * of savefiles. They also maintain the "checksum" info for 2.7.0+
159 static byte sf_get(void)
163 /* Get a character, decode the value */
164 c = getc(fff) & 0xFF;
168 /* Maintain the checksum info */
172 /* Return the value */
176 static void rd_byte(byte *ip)
181 static void rd_u16b(u16b *ip)
184 (*ip) |= ((u16b)(sf_get()) << 8);
187 static void rd_s16b(s16b *ip)
192 static void rd_u32b(u32b *ip)
195 (*ip) |= ((u32b)(sf_get()) << 8);
196 (*ip) |= ((u32b)(sf_get()) << 16);
197 (*ip) |= ((u32b)(sf_get()) << 24);
200 static void rd_s32b(s32b *ip)
207 * Hack -- read a string
209 static void rd_string(char *str, int max)
213 /* Read the string */
214 for (i = 0; TRUE; i++)
221 /* Collect string while legal */
222 if (i < max) str[i] = tmp8u;
233 /* Convert Kanji code */
252 /* ÉÔÌÀ¤Î´Á»ú¥³¡¼¥É¤«¤é¥·¥¹¥Æ¥à¤Î´Á»ú¥³¡¼¥É¤ËÊÑ´¹ */
253 byte code = codeconv(str);
255 /* ´Á»ú¥³¡¼¥É¤¬È½ÌÀ¤·¤¿¤é¡¢¤½¤ì¤òµÏ¿ */
256 if (code) kanji_code = code;
261 /* No conversion needed */
269 * Hack -- strip some bytes
271 static void strip_bytes(int n)
275 /* Strip the bytes */
276 while (n--) rd_byte(&tmp8u);
279 #define OLD_MAX_MANE 22
282 * Read an object (Old method)
284 * This function attempts to "repair" old savefiles, and to extract
285 * the most up to date values for various object fields.
287 * Note that Angband 2.7.9 introduced a new method for object "flags"
288 * in which the "flags" on an object are actually extracted when they
289 * are needed from the object kind, artifact index, ego-item index,
290 * and two special "xtra" fields which are used to encode any "extra"
291 * power of certain ego-items. This had the side effect that items
292 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
293 * may have had, and also, all "uncursed" items will become "cursed"
294 * again, including Calris, even if it is being worn at the time. As
295 * a complete hack, items which are inscribed with "uncursed" will be
296 * "uncursed" when imported from pre-2.7.9 savefiles.
298 static void rd_item_old(object_type *o_ptr)
304 rd_s16b(&o_ptr->k_idx);
311 rd_byte(&o_ptr->tval);
312 rd_byte(&o_ptr->sval);
314 if (z_older_than(10, 4, 4))
316 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
317 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
318 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
322 rd_s16b(&o_ptr->pval);
324 rd_byte(&o_ptr->discount);
325 rd_byte(&o_ptr->number);
326 rd_s16b(&o_ptr->weight);
328 rd_byte(&o_ptr->name1);
329 rd_byte(&o_ptr->name2);
330 rd_s16b(&o_ptr->timeout);
332 rd_s16b(&o_ptr->to_h);
333 rd_s16b(&o_ptr->to_d);
334 rd_s16b(&o_ptr->to_a);
341 rd_byte(&o_ptr->ident);
343 rd_byte(&o_ptr->marked);
346 rd_u32b(&o_ptr->art_flags[0]);
347 rd_u32b(&o_ptr->art_flags[1]);
348 rd_u32b(&o_ptr->art_flags[2]);
349 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
350 else rd_u32b(&o_ptr->art_flags[3]);
352 if (h_older_than(1, 3, 0, 0))
354 if (o_ptr->name2 == EGO_TELEPATHY)
355 add_flag(o_ptr->art_flags, TR_TELEPATHY);
358 if (z_older_than(11, 0, 11))
360 o_ptr->curse_flags = 0L;
361 if (o_ptr->ident & 0x40)
363 o_ptr->curse_flags |= TRC_CURSED;
364 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
365 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
366 if (object_is_fixed_artifact(o_ptr))
368 artifact_type *a_ptr = &a_info[o_ptr->name1];
369 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
370 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
372 else if (object_is_ego(o_ptr))
374 ego_item_type *e_ptr = &e_info[o_ptr->name2];
375 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
376 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
379 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
383 rd_u32b(&o_ptr->curse_flags);
386 /* Monster holding object */
387 rd_s16b(&o_ptr->held_m_idx);
390 rd_byte(&o_ptr->xtra1);
391 rd_byte(&o_ptr->xtra2);
393 if (z_older_than(11, 0, 10))
395 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
397 switch (o_ptr->xtra2 % 6)
399 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
400 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
401 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
402 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
403 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
404 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
408 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
410 switch (o_ptr->xtra2 % 11)
412 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
413 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
414 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
415 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
416 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
417 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
418 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
419 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
420 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
421 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
422 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
426 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
428 switch (o_ptr->xtra2 % 8)
430 case 0: add_flag(o_ptr->art_flags, TR_LEVITATION); break;
431 case 1: add_flag(o_ptr->art_flags, TR_LITE_1); break;
432 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
433 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
434 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
435 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
436 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
437 case 7: add_flag(o_ptr->art_flags, TR_HOLD_LIFE); break;
444 if (z_older_than(10, 2, 3))
449 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
451 o_ptr->xtra3 = o_ptr->xtra1;
454 if (o_ptr->tval == TV_CAPTURE)
456 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
457 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
459 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
460 if (ironman_nightmare)
462 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
464 o_ptr->xtra4 = o_ptr->xtra5;
469 rd_byte(&o_ptr->xtra3);
470 if (h_older_than(1, 3, 0, 1))
472 if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
473 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
476 rd_s16b(&o_ptr->xtra4);
477 rd_s16b(&o_ptr->xtra5);
480 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)))
482 o_ptr->xtra4 = o_ptr->pval;
486 rd_byte(&o_ptr->feeling);
489 rd_string(buf, sizeof(buf));
491 /* Save the inscription */
492 if (buf[0]) o_ptr->inscription = quark_add(buf);
494 rd_string(buf, sizeof(buf));
495 if (buf[0]) o_ptr->art_name = quark_add(buf);
497 /* The Python object */
505 /* Mega-Hack -- handle "dungeon objects" later */
506 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
508 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
510 if (z_older_than(10, 4, 9))
512 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
514 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
515 add_flag(o_ptr->art_flags, TR_DEC_MANA);
520 if (object_is_fixed_artifact(o_ptr))
522 artifact_type *a_ptr;
524 /* Obtain the artifact info */
525 a_ptr = &a_info[o_ptr->name1];
527 /* Verify that artifact */
528 if (!a_ptr->name) o_ptr->name1 = 0;
532 if (object_is_ego(o_ptr))
534 ego_item_type *e_ptr;
536 /* Obtain the ego-item info */
537 e_ptr = &e_info[o_ptr->name2];
539 /* Verify that ego-item */
540 if (!e_ptr->name) o_ptr->name2 = 0;
547 * Read an object (New method)
549 static void rd_item(object_type *o_ptr)
555 if (h_older_than(1, 5, 0, 0))
561 /*** Item save flags ***/
564 /*** Read un-obvious elements ***/
566 rd_s16b(&o_ptr->k_idx);
573 k_ptr = &k_info[o_ptr->k_idx];
574 o_ptr->tval = k_ptr->tval;
575 o_ptr->sval = k_ptr->sval;
578 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
579 else o_ptr->pval = 0;
581 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
582 else o_ptr->discount = 0;
583 if (flags & SAVE_ITEM_NUMBER) rd_byte(&o_ptr->number);
584 else o_ptr->number = 1;
586 rd_s16b(&o_ptr->weight);
588 if (flags & SAVE_ITEM_NAME1) rd_byte(&o_ptr->name1);
589 else o_ptr->name1 = 0;
590 if (flags & SAVE_ITEM_NAME2) rd_byte(&o_ptr->name2);
591 else o_ptr->name2 = 0;
592 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
593 else o_ptr->timeout = 0;
595 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
596 else o_ptr->to_h = 0;
597 if (flags & SAVE_ITEM_TO_D) rd_s16b(&o_ptr->to_d);
598 else o_ptr->to_d = 0;
599 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
600 else o_ptr->to_a = 0;
602 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
605 if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
607 if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
610 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
611 else o_ptr->ident = 0;
613 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
614 else o_ptr->marked = 0;
617 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
618 else o_ptr->art_flags[0] = 0;
619 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
620 else o_ptr->art_flags[1] = 0;
621 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
622 else o_ptr->art_flags[2] = 0;
623 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
624 else o_ptr->art_flags[3] = 0;
626 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
627 else o_ptr->curse_flags = 0;
629 /* Monster holding object */
630 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
631 else o_ptr->held_m_idx = 0;
634 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
635 else o_ptr->xtra1 = 0;
636 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
637 else o_ptr->xtra2 = 0;
639 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
640 else o_ptr->xtra3 = 0;
642 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
643 else o_ptr->xtra4 = 0;
644 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
645 else o_ptr->xtra5 = 0;
647 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
648 else o_ptr->feeling = 0;
650 if (flags & SAVE_ITEM_INSCRIPTION)
652 rd_string(buf, sizeof(buf));
653 o_ptr->inscription = quark_add(buf);
655 else o_ptr->inscription = 0;
657 if (flags & SAVE_ITEM_ART_NAME)
659 rd_string(buf, sizeof(buf));
660 o_ptr->art_name = quark_add(buf);
662 else o_ptr->art_name = 0;
664 if(h_older_than(2,1,2,3))
666 u32b flgs[TR_FLAG_SIZE];
667 object_flags(o_ptr, flgs);
669 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
671 add_flag(o_ptr->art_flags, TR_LITE_M1);
672 remove_flag(o_ptr->art_flags, TR_LITE_1);
673 remove_flag(o_ptr->art_flags, TR_LITE_2);
674 remove_flag(o_ptr->art_flags, TR_LITE_3);
677 if (o_ptr->name2 == EGO_LITE_DARKNESS)
679 if (o_ptr->sval == SV_LITE_TORCH)
681 add_flag(o_ptr->art_flags, TR_LITE_M1);
683 else if (o_ptr->sval == SV_LITE_LANTERN)
685 add_flag(o_ptr->art_flags, TR_LITE_M2);
687 else if (o_ptr->sval == SV_LITE_FEANOR)
689 add_flag(o_ptr->art_flags, TR_LITE_M3);
692 else if (o_ptr->sval == SV_LITE_TORCH)
694 add_flag(o_ptr->art_flags, TR_LITE_1);
695 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
697 else if (o_ptr->sval == SV_LITE_LANTERN)
699 add_flag(o_ptr->art_flags, TR_LITE_2);
700 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
702 else if (o_ptr->sval == SV_LITE_FEANOR)
704 add_flag(o_ptr->art_flags, TR_LITE_2);
706 else if ((o_ptr->tval == TV_LITE) && object_is_fixed_artifact(o_ptr))
708 add_flag(o_ptr->art_flags, TR_LITE_3);
715 * Read a monster (Old method)
717 static void rd_monster_old(monster_type *m_ptr)
722 /* Read the monster race */
723 rd_s16b(&m_ptr->r_idx);
725 if (z_older_than(11, 0, 12))
726 m_ptr->ap_r_idx = m_ptr->r_idx;
728 rd_s16b(&m_ptr->ap_r_idx);
730 if (z_older_than(11, 0, 14))
732 monster_race *r_ptr = &r_info[m_ptr->r_idx];
734 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
735 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
736 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
739 rd_byte(&m_ptr->sub_align);
741 /* Read the other information */
745 rd_s16b(&m_ptr->maxhp);
746 if (z_older_than(11, 0, 5))
748 m_ptr->max_maxhp = m_ptr->maxhp;
752 rd_s16b(&m_ptr->max_maxhp);
754 if(h_older_than(2, 1, 2, 1))
756 m_ptr->dealt_damage = 0;
760 rd_u32b(&m_ptr->dealt_damage);
763 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
764 rd_byte(&m_ptr->mspeed);
765 if (z_older_than(10, 4, 2))
768 m_ptr->energy_need = (s16b)tmp8u;
770 else rd_s16b(&m_ptr->energy_need);
772 if (z_older_than(11, 0, 13))
773 m_ptr->energy_need = 100 - m_ptr->energy_need;
775 if (z_older_than(10,0,7))
777 m_ptr->mtimed[MTIMED_FAST] = 0;
778 m_ptr->mtimed[MTIMED_SLOW] = 0;
783 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
785 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
788 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
790 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
792 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
794 if (z_older_than(10,0,10))
798 else if (z_older_than(10,0,11))
806 rd_s16b(&m_ptr->target_y);
807 rd_s16b(&m_ptr->target_x);
811 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
813 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
814 rd_u32b(&m_ptr->smart);
818 if (z_older_than(10, 4, 5))
821 rd_u32b(&m_ptr->exp);
823 if (z_older_than(10, 2, 2))
825 if (m_ptr->r_idx < 0)
827 m_ptr->r_idx = (0-m_ptr->r_idx);
828 m_ptr->mflag2 |= MFLAG2_KAGE;
833 rd_byte(&m_ptr->mflag2);
836 if (z_older_than(11, 0, 12))
838 if (m_ptr->mflag2 & MFLAG2_KAGE)
839 m_ptr->ap_r_idx = MON_KAGE;
842 if (z_older_than(10, 1, 3))
848 rd_string(buf, sizeof(buf));
849 if (buf[0]) m_ptr->nickname = quark_add(buf);
857 * Read a monster (New method)
859 static void rd_monster(monster_type *m_ptr)
865 if (h_older_than(1, 5, 0, 0))
867 rd_monster_old(m_ptr);
871 /*** Monster save flags ***/
874 /*** Read un-obvious elements ***/
876 /* Read the monster race */
877 rd_s16b(&m_ptr->r_idx);
879 /* Read the other information */
883 rd_s16b(&m_ptr->maxhp);
884 rd_s16b(&m_ptr->max_maxhp);
885 if(h_older_than(2, 1, 2, 1))
887 m_ptr->dealt_damage = 0;
891 rd_u32b(&m_ptr->dealt_damage);
894 /* Monster race index of its appearance */
895 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
896 else m_ptr->ap_r_idx = m_ptr->r_idx;
898 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
899 else m_ptr->sub_align = 0;
901 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
902 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
904 rd_byte(&m_ptr->mspeed);
906 rd_s16b(&m_ptr->energy_need);
908 if (flags & SAVE_MON_FAST)
911 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
913 else m_ptr->mtimed[MTIMED_FAST] = 0;
914 if (flags & SAVE_MON_SLOW)
917 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
919 else m_ptr->mtimed[MTIMED_SLOW] = 0;
920 if (flags & SAVE_MON_STUNNED)
923 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
925 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
926 if (flags & SAVE_MON_CONFUSED)
929 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
931 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
932 if (flags & SAVE_MON_MONFEAR)
935 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
937 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
939 if (flags & SAVE_MON_TARGET_Y) rd_s16b(&m_ptr->target_y);
940 else m_ptr->target_y = 0;
941 if (flags & SAVE_MON_TARGET_X) rd_s16b(&m_ptr->target_x);
942 else m_ptr->target_x = 0;
944 if (flags & SAVE_MON_INVULNER)
947 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
949 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
951 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
952 else m_ptr->smart = 0;
954 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
957 m_ptr->mflag = 0; /* Not saved */
959 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
960 else m_ptr->mflag2 = 0;
962 if (flags & SAVE_MON_NICKNAME)
964 rd_string(buf, sizeof(buf));
965 m_ptr->nickname = quark_add(buf);
967 else m_ptr->nickname = 0;
969 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
970 else m_ptr->parent_m_idx = 0;
975 * Old monster bit flags of racial resistances
977 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
978 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
979 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
980 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
981 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
982 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
983 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
984 #define RF3_RES_WATE 0x00800000 /* Resist water */
985 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
986 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
987 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
988 #define RF3_RES_ALL 0x08000000 /* Resist all */
990 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
992 if ((R_PTR)->r_flags3 & (RF3)) \
994 (R_PTR)->r_flags3 &= ~(RF3); \
995 (R_PTR)->r_flagsr |= (RFR); \
999 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1001 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1003 (R_PTR)->r_flagsr |= (RFR); \
1007 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1008 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1009 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1010 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1011 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1012 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1013 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1014 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1015 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1016 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1018 * Read the monster lore
1020 static void rd_lore(int r_idx)
1024 monster_race *r_ptr = &r_info[r_idx];
1026 /* Count sights/deaths/kills */
1027 rd_s16b(&r_ptr->r_sights);
1028 rd_s16b(&r_ptr->r_deaths);
1029 rd_s16b(&r_ptr->r_pkills);
1030 if (h_older_than(1, 7, 0, 5))
1032 r_ptr->r_akills = r_ptr->r_pkills;
1036 rd_s16b(&r_ptr->r_akills);
1038 rd_s16b(&r_ptr->r_tkills);
1040 /* Count wakes and ignores */
1041 rd_byte(&r_ptr->r_wake);
1042 rd_byte(&r_ptr->r_ignore);
1045 rd_byte(&r_ptr->r_xtra1);
1046 rd_byte(&r_ptr->r_xtra2);
1049 rd_byte(&r_ptr->r_drop_gold);
1050 rd_byte(&r_ptr->r_drop_item);
1054 rd_byte(&r_ptr->r_cast_spell);
1056 /* Count blows of each type */
1057 rd_byte(&r_ptr->r_blows[0]);
1058 rd_byte(&r_ptr->r_blows[1]);
1059 rd_byte(&r_ptr->r_blows[2]);
1060 rd_byte(&r_ptr->r_blows[3]);
1062 /* Memorize flags */
1063 rd_u32b(&r_ptr->r_flags1);
1064 rd_u32b(&r_ptr->r_flags2);
1065 rd_u32b(&r_ptr->r_flags3);
1066 rd_u32b(&r_ptr->r_flags4);
1067 rd_u32b(&r_ptr->r_flags5);
1068 rd_u32b(&r_ptr->r_flags6);
1069 if (h_older_than(1, 5, 0, 3))
1071 r_ptr->r_flagsr = 0L;
1073 /* Move RF3 resistance flags to RFR */
1074 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1075 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1076 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1077 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1078 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1079 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1080 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1081 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1082 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1083 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1084 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1085 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1087 /* Separate breathers resistance from RF4 to RFR */
1088 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1089 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1090 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1091 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1092 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1093 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1094 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1095 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1096 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1098 /* Resist confusion is merged to RF3_NO_CONF */
1099 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1101 /* Misc resistance hack to RFR */
1102 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1103 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1107 rd_u32b(&r_ptr->r_flagsr);
1110 /* Read the "Racial" monster limit per level */
1111 rd_byte(&r_ptr->max_num);
1113 /* Location in saved floor */
1114 rd_s16b(&r_ptr->floor_id);
1119 /* Repair the lore flags */
1120 r_ptr->r_flags1 &= r_ptr->flags1;
1121 r_ptr->r_flags2 &= r_ptr->flags2;
1122 r_ptr->r_flags3 &= r_ptr->flags3;
1123 r_ptr->r_flags4 &= r_ptr->flags4;
1124 r_ptr->r_flags5 &= r_ptr->flags5;
1125 r_ptr->r_flags6 &= r_ptr->flags6;
1126 r_ptr->r_flagsr &= r_ptr->flagsr;
1133 * Add the item "o_ptr" to the inventory of the "Home"
1135 * In all cases, return the slot (or -1) where the object was placed
1137 * Note that this is a hacked up version of "inven_carry()".
1139 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1140 * known, the player may have to pick stuff up and drop it again.
1142 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1150 /* Check each existing item (try to combine) */
1151 for (slot = 0; slot < st_ptr->stock_num; slot++)
1153 /* Get the existing item */
1154 j_ptr = &st_ptr->stock[slot];
1156 /* The home acts just like the player */
1157 if (object_similar(j_ptr, o_ptr))
1159 /* Save the new number of items */
1160 object_absorb(j_ptr, o_ptr);
1168 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1172 /* Determine the "value" of the item */
1173 value = object_value(o_ptr);
1175 /* Check existing slots to see if we must "slide" */
1176 for (slot = 0; slot < st_ptr->stock_num; slot++)
1178 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1181 /* Slide the others up */
1182 for (i = st_ptr->stock_num; i > slot; i--)
1184 st_ptr->stock[i] = st_ptr->stock[i-1];
1187 /* More stuff now */
1188 st_ptr->stock_num++;
1190 /* Insert the new item */
1191 st_ptr->stock[slot] = *o_ptr;
1193 chg_virtue(V_SACRIFICE, -1);
1195 /* Return the location */
1203 static errr rd_store(int town_number, int store_number)
1215 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1217 st_ptr = &town[1].store[store_number];
1218 if (st_ptr->stock_num) sort = TRUE;
1222 st_ptr = &town[town_number].store[store_number];
1225 /* Read the basic info */
1226 rd_s32b(&st_ptr->store_open);
1227 rd_s16b(&st_ptr->insult_cur);
1229 if (z_older_than(11, 0, 4))
1238 rd_s16b(&st_ptr->good_buy);
1239 rd_s16b(&st_ptr->bad_buy);
1241 /* Read last visit */
1242 rd_s32b(&st_ptr->last_visit);
1244 /* Extract the owner (see above) */
1245 st_ptr->owner = own;
1247 /* Read the items */
1248 for (j = 0; j < num; j++)
1253 /* Get local object */
1256 /* Wipe the object */
1262 /* Acquire valid items */
1263 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1268 home_carry(st_ptr, q_ptr);
1272 k = st_ptr->stock_num++;
1274 /* Acquire the item */
1275 object_copy(&st_ptr->stock[k], q_ptr);
1287 * Read RNG state (added in 2.8.0)
1289 static void rd_randomizer(void)
1299 rd_u16b(&Rand_place);
1302 for (i = 0; i < RAND_DEG; i++)
1304 rd_u32b(&Rand_state[i]);
1311 * Read options (ignore most pre-2.8.0 options)
1313 * Note that the normal options are now stored as a set of 256 bit flags,
1314 * plus a set of 256 bit masks to indicate which bit flags were defined
1315 * at the time the savefile was created. This will allow new options
1316 * to be added, and old options to be removed, at any time, without
1317 * hurting old savefiles.
1319 * The window options are stored in the same way, but note that each
1320 * window gets 32 options, and their order is fixed by certain defines.
1322 static void rd_options(void)
1336 /* Ignore old options */
1340 /*** Special info */
1342 /* Read "delay_factor" */
1346 /* Read "hitpoint_warn" */
1350 /* Read "mana_warn" */
1351 if(h_older_than(1, 7, 0, 0))
1362 /*** Cheating options ***/
1366 if (c & 0x0002) p_ptr->wizard = TRUE;
1368 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1369 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1370 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1371 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1372 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1373 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1374 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1376 rd_byte((byte *)&autosave_l);
1377 rd_byte((byte *)&autosave_t);
1378 rd_s16b(&autosave_freq);
1381 /*** Normal Options ***/
1383 /* Read the option flags */
1384 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1386 /* Read the option masks */
1387 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1389 /* Analyze the options */
1390 for (n = 0; n < 8; n++)
1392 /* Analyze the options */
1393 for (i = 0; i < 32; i++)
1395 /* Process valid flags */
1396 if (mask[n] & (1L << i))
1398 /* Process valid flags */
1399 if (option_mask[n] & (1L << i))
1402 if (flag[n] & (1L << i))
1405 option_flag[n] |= (1L << i);
1412 option_flag[n] &= ~(1L << i);
1419 if (z_older_than(10, 4, 5))
1421 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1422 else option_flag[5] |= (0x00000001 << 4);
1423 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1424 else option_flag[2] |= (0x00000001 << 5);
1425 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1426 else option_flag[4] |= (0x00000001 << 5);
1427 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1428 else option_flag[5] |= (0x00000001 << 0);
1429 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1430 else option_flag[5] |= (0x00000001 << 12);
1431 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1432 else option_flag[1] |= (0x00000001 << 0);
1433 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1434 else option_flag[1] |= (0x00000001 << 18);
1435 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1436 else option_flag[1] |= (0x00000001 << 19);
1437 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1438 else option_flag[5] |= (0x00000001 << 3);
1441 /* Extract the options */
1442 extract_option_vars();
1445 /*** Window Options ***/
1447 /* Read the window flags */
1448 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1450 /* Read the window masks */
1451 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1453 /* Analyze the options */
1454 for (n = 0; n < 8; n++)
1456 /* Analyze the options */
1457 for (i = 0; i < 32; i++)
1459 /* Process valid flags */
1460 if (mask[n] & (1L << i))
1462 /* Process valid flags */
1463 if (window_mask[n] & (1L << i))
1466 if (flag[n] & (1L << i))
1469 window_flag[n] |= (1L << i);
1476 window_flag[n] &= ~(1L << i);
1489 * Hack -- strip the "ghost" info
1491 * XXX XXX XXX This is such a nasty hack it hurts.
1493 static void rd_ghost(void)
1498 rd_string(buf, sizeof(buf));
1500 /* Strip old data */
1506 * Save quick start data
1508 static void load_quick_start(void)
1513 if (z_older_than(11, 0, 13))
1515 previous_char.quick_ok = FALSE;
1519 rd_byte(&previous_char.psex);
1520 rd_byte(&previous_char.prace);
1521 rd_byte(&previous_char.pclass);
1522 rd_byte(&previous_char.pseikaku);
1523 rd_byte(&previous_char.realm1);
1524 rd_byte(&previous_char.realm2);
1526 rd_s16b(&previous_char.age);
1527 rd_s16b(&previous_char.ht);
1528 rd_s16b(&previous_char.wt);
1529 rd_s16b(&previous_char.sc);
1530 rd_s32b(&previous_char.au);
1532 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1533 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1535 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1537 rd_s16b(&previous_char.chaos_patron);
1539 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1541 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1543 /* UNUSED : Was number of random quests */
1547 previous_char.quick_ok = (bool)tmp8u;
1551 * Read the "extra" information
1553 static void rd_extra(void)
1561 rd_string(player_name, sizeof(player_name));
1563 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1565 if (!h_older_than(1, 7, 0, 1))
1569 /* Read the message */
1570 rd_string(buf, sizeof buf);
1571 if (buf[0]) p_ptr->last_message = string_make(buf);
1576 for (i = 0; i < 4; i++)
1578 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1581 /* Class/Race/Seikaku/Gender/Spells */
1582 rd_byte(&p_ptr->prace);
1583 rd_byte(&p_ptr->pclass);
1584 rd_byte(&p_ptr->pseikaku);
1585 rd_byte(&p_ptr->psex);
1586 rd_byte(&p_ptr->realm1);
1587 rd_byte(&p_ptr->realm2);
1588 rd_byte(&tmp8u); /* oops */
1590 if (z_older_than(10, 4, 4))
1592 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1593 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1594 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1595 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1598 /* Special Race/Class info */
1599 rd_byte(&p_ptr->hitdie);
1600 rd_u16b(&p_ptr->expfact);
1602 /* Age/Height/Weight */
1603 rd_s16b(&p_ptr->age);
1604 rd_s16b(&p_ptr->ht);
1605 rd_s16b(&p_ptr->wt);
1607 /* Read the stat info */
1608 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1609 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1610 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1612 strip_bytes(24); /* oops */
1614 rd_s32b(&p_ptr->au);
1616 rd_s32b(&p_ptr->max_exp);
1617 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1618 else rd_s32b(&p_ptr->max_max_exp);
1619 rd_s32b(&p_ptr->exp);
1621 if (h_older_than(1, 7, 0, 3))
1624 p_ptr->exp_frac = (u32b)tmp16u;
1628 rd_u32b(&p_ptr->exp_frac);
1631 rd_s16b(&p_ptr->lev);
1633 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1634 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1636 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1638 if (z_older_than(10, 3, 6))
1639 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1641 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1642 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1643 if (z_older_than(10, 4, 1))
1645 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1646 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1648 if (z_older_than(10, 3, 14))
1650 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1651 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1655 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1656 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1657 if (h_older_than(1, 3, 0, 1))
1659 if (p_ptr->pclass == CLASS_SMITH)
1661 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1662 p_ptr->magic_num1[96] = 0;
1663 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1664 p_ptr->magic_num1[97] = 0;
1668 if (music_singing_any()) p_ptr->action = ACTION_SING;
1670 if (z_older_than(11, 0, 7))
1672 p_ptr->start_race = p_ptr->prace;
1673 p_ptr->old_race1 = 0L;
1674 p_ptr->old_race2 = 0L;
1675 p_ptr->old_realm = 0;
1679 rd_byte(&p_ptr->start_race);
1680 rd_s32b(&p_ptr->old_race1);
1681 rd_s32b(&p_ptr->old_race2);
1682 rd_s16b(&p_ptr->old_realm);
1685 if (z_older_than(10, 0, 1))
1687 for (i = 0; i < OLD_MAX_MANE; i++)
1689 p_ptr->mane_spell[i] = -1;
1690 p_ptr->mane_dam[i] = 0;
1692 p_ptr->mane_num = 0;
1694 else if (z_older_than(10, 2, 3))
1696 for (i = 0; i < OLD_MAX_MANE; i++)
1701 for (i = 0; i < MAX_MANE; i++)
1703 p_ptr->mane_spell[i] = -1;
1704 p_ptr->mane_dam[i] = 0;
1707 p_ptr->mane_num = 0;
1711 for (i = 0; i < MAX_MANE; i++)
1713 rd_s16b(&p_ptr->mane_spell[i]);
1714 rd_s16b(&p_ptr->mane_dam[i]);
1716 rd_s16b(&p_ptr->mane_num);
1719 if (z_older_than(10, 0, 3))
1721 determine_bounty_uniques();
1723 for (i = 0; i < MAX_KUBI; i++)
1725 /* Is this bounty unique already dead? */
1726 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1731 for (i = 0; i < MAX_KUBI; i++)
1733 rd_s16b(&kubi_r_idx[i]);
1737 if (z_older_than(10, 0, 3))
1743 for (i = 0; i < 4; i++)
1745 rd_s16b(&battle_mon[i]);
1746 if (z_older_than(10, 3, 4))
1749 mon_odds[i] = tmp16s;
1751 else rd_u32b(&mon_odds[i]);
1755 rd_s16b(&p_ptr->town_num);
1757 /* Read arena and rewards information */
1758 rd_s16b(&p_ptr->arena_number);
1759 if (h_older_than(1, 5, 0, 1))
1761 /* Arena loser of previous version was marked number 99 */
1762 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1765 p_ptr->inside_arena = (bool)tmp16s;
1766 rd_s16b(&p_ptr->inside_quest);
1767 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1771 p_ptr->inside_battle = (bool)tmp16s;
1773 rd_byte(&p_ptr->exit_bldg);
1776 rd_s16b(&p_ptr->oldpx);
1777 rd_s16b(&p_ptr->oldpy);
1778 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1780 /* Was p_ptr->rewards[MAX_BACT] */
1782 for (i = 0; i < tmp16s; i++)
1788 if (h_older_than(1, 7, 0, 3))
1791 p_ptr->mhp = tmp16s;
1794 p_ptr->chp = tmp16s;
1797 p_ptr->chp_frac = (u32b)tmp16u;
1801 rd_s32b(&p_ptr->mhp);
1802 rd_s32b(&p_ptr->chp);
1803 rd_u32b(&p_ptr->chp_frac);
1806 if (h_older_than(1, 7, 0, 3))
1809 p_ptr->msp = tmp16s;
1812 p_ptr->csp = tmp16s;
1815 p_ptr->csp_frac = (u32b)tmp16u;
1819 rd_s32b(&p_ptr->msp);
1820 rd_s32b(&p_ptr->csp);
1821 rd_u32b(&p_ptr->csp_frac);
1824 rd_s16b(&p_ptr->max_plv);
1825 if (z_older_than(10, 3, 8))
1827 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1831 byte max = (byte)max_d_idx;
1835 for(i = 0; i < max; i++)
1837 rd_s16b(&max_dlv[i]);
1838 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1842 /* Repair maximum player level XXX XXX XXX */
1843 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1847 rd_s16b(&p_ptr->sc);
1848 rd_s16b(&p_ptr->concent);
1850 /* Read the flags */
1851 strip_bytes(2); /* Old "rest" */
1852 rd_s16b(&p_ptr->blind);
1853 rd_s16b(&p_ptr->paralyzed);
1854 rd_s16b(&p_ptr->confused);
1855 rd_s16b(&p_ptr->food);
1856 strip_bytes(4); /* Old "food_digested" / "protection" */
1858 rd_s16b(&p_ptr->energy_need);
1859 if (z_older_than(11, 0, 13))
1860 p_ptr->energy_need = 100 - p_ptr->energy_need;
1861 if (h_older_than(2, 1, 2, 0))
1862 p_ptr->enchant_energy_need = 0;
1864 rd_s16b(&p_ptr->enchant_energy_need);
1866 rd_s16b(&p_ptr->fast);
1867 rd_s16b(&p_ptr->slow);
1868 rd_s16b(&p_ptr->afraid);
1869 rd_s16b(&p_ptr->cut);
1870 rd_s16b(&p_ptr->stun);
1871 rd_s16b(&p_ptr->poisoned);
1872 rd_s16b(&p_ptr->image);
1873 rd_s16b(&p_ptr->protevil);
1874 rd_s16b(&p_ptr->invuln);
1875 if(z_older_than(10, 0, 0))
1878 rd_s16b(&p_ptr->ult_res);
1879 rd_s16b(&p_ptr->hero);
1880 rd_s16b(&p_ptr->shero);
1881 rd_s16b(&p_ptr->shield);
1882 rd_s16b(&p_ptr->blessed);
1883 rd_s16b(&p_ptr->tim_invis);
1884 rd_s16b(&p_ptr->word_recall);
1885 if (z_older_than(10, 3, 8))
1886 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1890 p_ptr->recall_dungeon = (byte)tmp16s;
1893 if (h_older_than(1, 5, 0, 0))
1894 p_ptr->alter_reality = 0;
1896 rd_s16b(&p_ptr->alter_reality);
1898 rd_s16b(&p_ptr->see_infra);
1899 rd_s16b(&p_ptr->tim_infra);
1900 rd_s16b(&p_ptr->oppose_fire);
1901 rd_s16b(&p_ptr->oppose_cold);
1902 rd_s16b(&p_ptr->oppose_acid);
1903 rd_s16b(&p_ptr->oppose_elec);
1904 rd_s16b(&p_ptr->oppose_pois);
1905 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1906 else rd_s16b(&p_ptr->tsuyoshi);
1908 /* Old savefiles do not have the following fields... */
1909 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1912 p_ptr->wraith_form = 0;
1913 p_ptr->resist_magic = 0;
1914 p_ptr->tim_regen = 0;
1915 p_ptr->kabenuke = 0;
1916 p_ptr->tim_stealth = 0;
1917 p_ptr->tim_levitation = 0;
1918 p_ptr->tim_sh_touki = 0;
1919 p_ptr->lightspeed = 0;
1920 p_ptr->tsubureru = 0;
1921 p_ptr->tim_res_nether = 0;
1922 p_ptr->tim_res_time = 0;
1923 p_ptr->mimic_form = 0;
1924 p_ptr->tim_mimic = 0;
1925 p_ptr->tim_sh_fire = 0;
1928 p_ptr->tim_reflect = 0;
1929 p_ptr->multishadow = 0;
1930 p_ptr->dustrobe = 0;
1932 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
1940 rd_s16b(&p_ptr->tim_esp);
1941 rd_s16b(&p_ptr->wraith_form);
1942 rd_s16b(&p_ptr->resist_magic);
1943 rd_s16b(&p_ptr->tim_regen);
1944 rd_s16b(&p_ptr->kabenuke);
1945 rd_s16b(&p_ptr->tim_stealth);
1946 rd_s16b(&p_ptr->tim_levitation);
1947 rd_s16b(&p_ptr->tim_sh_touki);
1948 rd_s16b(&p_ptr->lightspeed);
1949 rd_s16b(&p_ptr->tsubureru);
1950 if (z_older_than(10, 4, 7))
1951 p_ptr->magicdef = 0;
1953 rd_s16b(&p_ptr->magicdef);
1954 rd_s16b(&p_ptr->tim_res_nether);
1955 if (z_older_than(10, 4, 11))
1957 p_ptr->tim_res_time = 0;
1958 p_ptr->mimic_form = 0;
1959 p_ptr->tim_mimic = 0;
1960 p_ptr->tim_sh_fire = 0;
1964 rd_s16b(&p_ptr->tim_res_time);
1965 rd_byte(&p_ptr->mimic_form);
1966 rd_s16b(&p_ptr->tim_mimic);
1967 rd_s16b(&p_ptr->tim_sh_fire);
1970 if (z_older_than(11, 0, 99))
1972 p_ptr->tim_sh_holy = 0;
1973 p_ptr->tim_eyeeye = 0;
1977 rd_s16b(&p_ptr->tim_sh_holy);
1978 rd_s16b(&p_ptr->tim_eyeeye);
1982 if ( z_older_than(11,0,3) ){
1983 p_ptr->tim_reflect=0;
1984 p_ptr->multishadow=0;
1988 rd_s16b(&p_ptr->tim_reflect);
1989 rd_s16b(&p_ptr->multishadow);
1990 rd_s16b(&p_ptr->dustrobe);
1993 rd_s16b(&p_ptr->chaos_patron);
1994 rd_u32b(&p_ptr->muta1);
1995 rd_u32b(&p_ptr->muta2);
1996 rd_u32b(&p_ptr->muta3);
1998 for (i = 0; i < 8; i++)
1999 rd_s16b(&p_ptr->virtues[i]);
2000 for (i = 0; i < 8; i++)
2001 rd_s16b(&p_ptr->vir_types[i]);
2004 /* Calc the regeneration modifier for mutations */
2005 mutant_regenerate_mod = calc_mutant_regenerate_mod();
2007 if (z_older_than(10,0,9))
2010 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2011 p_ptr->ele_attack = 0;
2015 rd_s16b(&p_ptr->ele_attack);
2016 rd_u32b(&p_ptr->special_attack);
2018 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2019 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2020 if (z_older_than(10,0,12))
2022 p_ptr->ele_immune = 0;
2023 p_ptr->special_defense = 0;
2027 rd_s16b(&p_ptr->ele_immune);
2028 rd_u32b(&p_ptr->special_defense);
2030 rd_byte(&p_ptr->knowledge);
2033 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2035 rd_byte(&tmp8u); /* oops */
2036 rd_byte(&p_ptr->action);
2037 if (!z_older_than(10, 4, 3))
2040 if (tmp8u) p_ptr->action = ACTION_LEARN;
2042 rd_byte((byte *)&preserve_mode);
2043 rd_byte((byte *)&p_ptr->wait_report_score);
2046 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2048 /* Skip the flags */
2052 /* Hack -- the two "special seeds" */
2053 rd_u32b(&seed_flavor);
2054 rd_u32b(&seed_town);
2058 rd_u16b(&p_ptr->panic_save);
2059 rd_u16b(&p_ptr->total_winner);
2060 rd_u16b(&p_ptr->noscore);
2065 p_ptr->is_dead = tmp8u;
2067 /* Read "feeling" */
2068 rd_byte(&p_ptr->feeling);
2070 switch (p_ptr->start_race)
2076 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2079 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2082 dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2084 /* Turn when level began */
2087 if (h_older_than(1, 7, 0, 4))
2089 p_ptr->feeling_turn = old_turn;
2093 /* Turn of last "feeling" */
2094 rd_s32b(&p_ptr->feeling_turn);
2100 if (z_older_than(10, 3, 12))
2102 dungeon_turn = turn;
2104 else rd_s32b(&dungeon_turn);
2106 if (z_older_than(11, 0, 13))
2109 p_ptr->feeling_turn /= 2;
2114 if (z_older_than(10, 3, 13))
2118 else rd_s32b(&old_battle);
2120 if (z_older_than(10,0,3))
2122 determine_today_mon(TRUE);
2126 rd_s16b(&today_mon);
2127 rd_s16b(&p_ptr->today_mon);
2130 if (z_older_than(10,0,7))
2136 rd_s16b(&p_ptr->riding);
2139 /* Current floor_id */
2140 if (h_older_than(1, 5, 0, 0))
2142 p_ptr->floor_id = 0;
2146 rd_s16b(&p_ptr->floor_id);
2149 if (h_older_than(1, 5, 0, 2))
2155 /* Get number of party_mon array */
2158 /* Strip old temporary preserved pets */
2159 for (i = 0; i < tmp16s; i++)
2161 monster_type dummy_mon;
2163 rd_monster(&dummy_mon);
2167 if (z_older_than(10,1,2))
2176 if (z_older_than(10,3,9))
2180 else if (z_older_than(10, 3, 10))
2188 rd_s32b(&p_ptr->visit);
2190 if (!z_older_than(11, 0, 5))
2192 rd_u32b(&p_ptr->count);
2200 * Read the player inventory
2202 * Note that the inventory changed in Angband 2.7.4. Two extra
2203 * pack slots were added and the equipment was rearranged. Note
2204 * that these two features combine when parsing old save-files, in
2205 * which items from the old "aux" slot are "carried", perhaps into
2206 * one of the two new "inventory" slots.
2208 * Note that the inventory is "re-sorted" later by "dungeon()".
2210 static errr rd_inventory(void)
2218 p_ptr->total_weight = 0;
2224 /* Read until done */
2229 /* Get the next item index */
2232 /* Nope, we reached the end */
2233 if (n == 0xFFFF) break;
2235 /* Get local object */
2238 /* Wipe the object */
2244 /* Hack -- verify item */
2245 if (!q_ptr->k_idx) return (53);
2247 /* Wield equipment */
2248 if (n >= INVEN_RARM)
2250 /* Player touches it */
2251 q_ptr->marked |= OM_TOUCHED;
2254 object_copy(&inventory[n], q_ptr);
2256 /* Add the weight */
2257 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2263 /* Warning -- backpack is full */
2264 else if (inven_cnt == INVEN_PACK)
2268 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
2270 note("Too many items in the inventory!");
2278 /* Carry inventory */
2284 /* Player touches it */
2285 q_ptr->marked |= OM_TOUCHED;
2288 object_copy(&inventory[n], q_ptr);
2290 /* Add the weight */
2291 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2305 * Read the saved messages
2307 static void rd_messages(void)
2317 /* Read the messages */
2318 for (i = 0; i < num; i++)
2320 /* Read the message */
2321 rd_string(buf, sizeof(buf));
2323 /* Save the message */
2330 /* Old hidden trap flag */
2331 #define CAVE_TRAP 0x8000
2333 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2334 #define OLD_FEAT_INVIS 0x02
2335 #define OLD_FEAT_GLYPH 0x03
2336 #define OLD_FEAT_QUEST_ENTER 0x08
2337 #define OLD_FEAT_QUEST_EXIT 0x09
2338 #define OLD_FEAT_MINOR_GLYPH 0x40
2339 #define OLD_FEAT_BLDG_1 0x81
2340 #define OLD_FEAT_MIRROR 0xc3
2343 #define OLD_QUEST_WATER_CAVE 18
2345 /* Quest constants */
2346 #define QUEST_OLD_CASTLE 27
2347 #define QUEST_ROYAL_CRYPT 28
2350 * Read the dungeon (old method)
2352 * The monsters/objects must be loaded in the same order
2353 * that they were stored, since the actual indexes matter.
2355 static errr rd_dungeon_old(void)
2366 /*** Basic info ***/
2369 rd_s16b(&dun_level);
2370 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2371 else rd_byte(&dungeon_type);
2373 /* Set the base level for old versions */
2374 base_level = dun_level;
2376 rd_s16b(&base_level);
2378 rd_s16b(&num_repro);
2383 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2386 rd_s16b(&tmp16s); /* max_panel_rows */
2387 rd_s16b(&tmp16s); /* max_panel_cols */
2390 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
2398 /*** Run length decoding ***/
2400 /* Load the dungeon data */
2401 for (x = y = 0; y < ymax; )
2407 if (z_older_than(10,3,6))
2416 /* Decline invalid flags */
2417 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2420 /* Apply the RLE info */
2421 for (i = count; i > 0; i--)
2423 /* Access the cave */
2424 c_ptr = &cave[y][x];
2426 /* Extract "info" */
2436 if (++y >= ymax) break;
2442 /*** Run length decoding ***/
2444 /* Load the dungeon data */
2445 for (x = y = 0; y < ymax; )
2451 /* Apply the RLE info */
2452 for (i = count; i > 0; i--)
2454 /* Access the cave */
2455 c_ptr = &cave[y][x];
2457 /* Extract "feat" */
2458 c_ptr->feat = (s16b)tmp8u;
2467 if (++y >= ymax) break;
2472 /*** Run length decoding ***/
2474 /* Load the dungeon data */
2475 for (x = y = 0; y < ymax; )
2481 /* Apply the RLE info */
2482 for (i = count; i > 0; i--)
2484 /* Access the cave */
2485 c_ptr = &cave[y][x];
2487 /* Extract "mimic" */
2488 c_ptr->mimic = (s16b)tmp8u;
2497 if (++y >= ymax) break;
2502 /*** Run length decoding ***/
2504 /* Load the dungeon data */
2505 for (x = y = 0; y < ymax; )
2511 /* Apply the RLE info */
2512 for (i = count; i > 0; i--)
2514 /* Access the cave */
2515 c_ptr = &cave[y][x];
2517 /* Extract "feat" */
2518 c_ptr->special = tmp16s;
2527 if (++y >= ymax) break;
2532 /* Convert cave data */
2533 if (z_older_than(11, 0, 99))
2535 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2537 /* Wipe old unused flags */
2538 cave[y][x].info &= ~(CAVE_MASK);
2542 if (h_older_than(1, 1, 1, 0))
2544 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2546 /* Access the cave */
2547 c_ptr = &cave[y][x];
2550 if (c_ptr->feat == OLD_FEAT_INVIS)
2552 c_ptr->feat = feat_floor;
2553 c_ptr->info |= CAVE_TRAP;
2556 /* Older than 1.1.1 */
2557 if (c_ptr->feat == OLD_FEAT_MIRROR)
2559 c_ptr->feat = feat_floor;
2560 c_ptr->info |= CAVE_OBJECT;
2565 if (h_older_than(1, 3, 1, 0))
2567 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2569 /* Access the cave */
2570 c_ptr = &cave[y][x];
2572 /* Old CAVE_IN_MIRROR flag */
2573 if (c_ptr->info & CAVE_OBJECT)
2575 c_ptr->mimic = feat_mirror;
2578 /* Runes will be mimics and flags */
2579 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2580 (c_ptr->feat == OLD_FEAT_GLYPH))
2582 c_ptr->info |= CAVE_OBJECT;
2583 c_ptr->mimic = c_ptr->feat;
2584 c_ptr->feat = feat_floor;
2587 /* Hidden traps will be trap terrains mimicing floor */
2588 else if (c_ptr->info & CAVE_TRAP)
2590 c_ptr->info &= ~CAVE_TRAP;
2591 c_ptr->mimic = c_ptr->feat;
2592 c_ptr->feat = choose_random_trap();
2595 /* Another hidden trap */
2596 else if (c_ptr->feat == OLD_FEAT_INVIS)
2598 c_ptr->mimic = feat_floor;
2599 c_ptr->feat = feat_trap_open;
2604 /* Quest 18 was removed */
2605 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2607 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2609 /* Access the cave */
2610 c_ptr = &cave[y][x];
2612 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2614 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2616 c_ptr->feat = feat_tree;
2619 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2621 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2624 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2625 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2627 c_ptr->feat = feat_up_stair;
2635 /* Read the item count */
2638 /* Verify maximum */
2639 if (limit > max_o_idx)
2642 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2644 note(format("Too many (%d) object entries!", limit));
2650 /* Read the dungeon items */
2651 for (i = 1; i < limit; i++)
2658 /* Get a new record */
2665 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2667 note(format("Object allocation error (%d <> %d)", i, o_idx));
2675 o_ptr = &o_list[o_idx];
2681 /* XXX XXX XXX XXX XXX */
2684 if (o_ptr->held_m_idx)
2686 monster_type *m_ptr;
2689 m_ptr = &m_list[o_ptr->held_m_idx];
2692 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2694 /* Place the object */
2695 m_ptr->hold_o_idx = o_idx;
2701 /* Access the item location */
2702 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2705 o_ptr->next_o_idx = c_ptr->o_idx;
2707 /* Place the object */
2708 c_ptr->o_idx = o_idx;
2715 /* Read the monster count */
2718 /* Hack -- verify */
2719 if (limit > max_m_idx)
2722 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2724 note(format("Too many (%d) monster entries!", limit));
2730 /* Read the monsters */
2731 for (i = 1; i < limit; i++)
2734 monster_type *m_ptr;
2736 /* Get a new record */
2743 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2745 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2752 /* Acquire monster */
2753 m_ptr = &m_list[m_idx];
2755 /* Read the monster */
2760 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2762 /* Mark the location */
2763 c_ptr->m_idx = m_idx;
2766 real_r_ptr(m_ptr)->cur_num++;
2771 /* The dungeon is ready */
2772 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2773 character_dungeon = FALSE;
2775 character_dungeon = TRUE;
2784 * Read the saved floor
2786 * The monsters/objects must be loaded in the same order
2787 * that they were stored, since the actual indexes matter.
2789 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2801 cave_template_type *templates;
2804 /*** Wipe all cave ***/
2808 /*** Basic info ***/
2810 /* Dungeon floor specific info follows */
2814 /*** Not a saved floor ***/
2816 rd_s16b(&dun_level);
2817 base_level = dun_level;
2821 /*** The saved floor ***/
2824 if (tmp16s != sf_ptr->floor_id) return 171;
2827 if (tmp8u != sf_ptr->savefile_id) return 171;
2830 if (tmp16s != sf_ptr->dun_level) return 171;
2831 dun_level = sf_ptr->dun_level;
2834 if (tmp32s != sf_ptr->last_visit) return 171;
2837 if (tmp32u != sf_ptr->visit_mark) return 171;
2840 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2843 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2846 rd_s16b(&base_level);
2847 rd_s16b(&num_repro);
2858 rd_byte(&p_ptr->feeling);
2862 /*** Read template for cave_type ***/
2864 /* Read the template count */
2867 /* Allocate the "template" array */
2868 C_MAKE(templates, limit, cave_template_type);
2870 /* Read the templates */
2871 for (i = 0; i < limit; i++)
2873 cave_template_type *ct_ptr = &templates[i];
2876 rd_u16b(&ct_ptr->info);
2877 if (h_older_than(1, 7, 0, 2))
2880 ct_ptr->feat = (s16b)tmp8u;
2882 ct_ptr->mimic = (s16b)tmp8u;
2886 rd_s16b(&ct_ptr->feat);
2887 rd_s16b(&ct_ptr->mimic);
2889 rd_s16b(&ct_ptr->special);
2897 /*** Run length decoding ***/
2899 /* Load the dungeon data */
2900 for (x = y = 0; y < ymax; )
2912 } while (tmp8u == MAX_UCHAR);
2914 /* Apply the RLE info */
2915 for (i = count; i > 0; i--)
2917 /* Access the cave */
2918 cave_type *c_ptr = &cave[y][x];
2920 /* Extract cave data */
2921 c_ptr->info = templates[id].info;
2922 c_ptr->feat = templates[id].feat;
2923 c_ptr->mimic = templates[id].mimic;
2924 c_ptr->special = templates[id].special;
2933 if (++y >= ymax) break;
2938 /* Quest 18 was removed */
2939 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2941 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2943 /* Access the cave */
2944 cave_type *c_ptr = &cave[y][x];
2946 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2948 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2950 c_ptr->feat = feat_tree;
2953 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2955 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2958 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2959 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2961 c_ptr->feat = feat_up_stair;
2967 /* Free the "template" array */
2968 C_KILL(templates, limit, cave_template_type);
2973 /* Read the item count */
2976 /* Verify maximum */
2977 if (limit > max_o_idx) return 151;
2980 /* Read the dungeon items */
2981 for (i = 1; i < limit; i++)
2987 /* Get a new record */
2991 if (i != o_idx) return 152;
2994 o_ptr = &o_list[o_idx];
3001 if (o_ptr->held_m_idx)
3003 monster_type *m_ptr;
3006 m_ptr = &m_list[o_ptr->held_m_idx];
3009 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3011 /* Place the object */
3012 m_ptr->hold_o_idx = o_idx;
3018 /* Access the item location */
3019 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3022 o_ptr->next_o_idx = c_ptr->o_idx;
3024 /* Place the object */
3025 c_ptr->o_idx = o_idx;
3032 /* Read the monster count */
3035 /* Hack -- verify */
3036 if (limit > max_m_idx) return 161;
3038 /* Read the monsters */
3039 for (i = 1; i < limit; i++)
3043 monster_type *m_ptr;
3045 /* Get a new record */
3049 if (i != m_idx) return 162;
3052 /* Acquire monster */
3053 m_ptr = &m_list[m_idx];
3055 /* Read the monster */
3060 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3062 /* Mark the location */
3063 c_ptr->m_idx = m_idx;
3066 real_r_ptr(m_ptr)->cur_num++;
3075 * Read the dungeon (new method)
3077 * The monsters/objects must be loaded in the same order
3078 * that they were stored, since the actual indexes matter.
3080 static errr rd_dungeon(void)
3086 /* Initialize saved_floors array and temporal files */
3087 init_saved_floors(FALSE);
3090 if (h_older_than(1, 5, 0, 0))
3092 err = rd_dungeon_old();
3094 /* Prepare floor_id of current floor */
3097 p_ptr->floor_id = get_new_floor_id();
3098 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3107 /* Number of floor_id used from birth */
3108 rd_s16b(&max_floor_id);
3110 /* Current dungeon type */
3111 rd_byte(&dungeon_type);
3114 /* Number of the saved_floors array elements */
3117 /*** No saved floor (On the surface etc.) ***/
3120 /* Read the current floor data */
3121 err = rd_saved_floor(NULL);
3124 /*** In the dungeon ***/
3128 /* Read the saved_floors array */
3129 for (i = 0; i < num; i++)
3131 saved_floor_type *sf_ptr = &saved_floors[i];
3133 rd_s16b(&sf_ptr->floor_id);
3134 rd_byte(&sf_ptr->savefile_id);
3135 rd_s16b(&sf_ptr->dun_level);
3136 rd_s32b(&sf_ptr->last_visit);
3137 rd_u32b(&sf_ptr->visit_mark);
3138 rd_s16b(&sf_ptr->upper_floor_id);
3139 rd_s16b(&sf_ptr->lower_floor_id);
3143 /* Move saved floors data to temporal files */
3144 for (i = 0; i < num; i++)
3146 saved_floor_type *sf_ptr = &saved_floors[i];
3149 /* Unused element */
3150 if (!sf_ptr->floor_id) continue;
3152 /* Read the failure mark */
3154 if (tmp8u) continue;
3156 /* Read from the save file */
3157 err = rd_saved_floor(sf_ptr);
3162 /* Re-save as temporal saved floor file */
3163 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3169 /* Finally load current floor data from temporal file */
3172 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3177 /*** Error messages ***/
3182 note("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
3184 note("Too many object entries!");
3190 note("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼");
3192 note("Object allocation error");
3198 note("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
3200 note("Too many monster entries!");
3206 note("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼");
3208 note("Monster allocation error");
3214 note("Êݸ¤µ¤ì¤¿¥Õ¥í¥¢¤Î¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡ª");
3216 note("Dungeon data of saved floors are broken!");
3222 note("¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
3224 note("Failed to make temporal files!");
3237 /* The dungeon is ready */
3238 character_dungeon = TRUE;
3240 /* Success or Error */
3246 * Actually read the savefile
3248 static errr rd_savefile_new_aux(void)
3260 #ifdef VERIFY_CHECKSUMS
3261 u32b n_x_check, n_v_check;
3262 u32b o_x_check, o_v_check;
3266 /* Mention the savefile version */
3269 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
3271 "Loading a %d.%d.%d savefile...",
3273 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
3276 /* Strip the version bytes */
3279 /* Hack -- decrypt */
3280 xor_byte = sf_extra;
3283 /* Clear the checksums */
3287 /* Read the version number of the savefile */
3288 /* Old savefile will be version 0.0.0.3 */
3289 rd_byte(&h_ver_extra);
3290 rd_byte(&h_ver_patch);
3291 rd_byte(&h_ver_minor);
3292 rd_byte(&h_ver_major);
3294 /* Operating system info */
3295 rd_u32b(&sf_system);
3297 /* Time of savefile creation */
3300 /* Number of resurrections */
3303 /* Number of times played */
3307 /* Later use (always zero) */
3310 /* Later use (always zero) */
3313 /* Later use (always zero) */
3317 rd_byte(&kanji_code);
3319 /* Read RNG state */
3322 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3324 if (arg_fiddle) note("Loaded Randomizer Info");
3329 /* Then the options */
3332 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3334 if (arg_fiddle) note("Loaded Option Flags");
3337 /* Then the "messages" */
3340 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3342 if (arg_fiddle) note("Loaded Messages");
3347 for (i = 0; i < max_r_idx; i++)
3349 /* Access that monster */
3350 monster_race *r_ptr = &r_info[i];
3352 /* Hack -- Reset the death counter */
3353 r_ptr->max_num = 100;
3355 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3357 /* Hack -- Non-unique Nazguls are semi-unique */
3358 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3361 /* Monster Memory */
3364 /* Incompatible save files */
3365 if (tmp16u > max_r_idx)
3368 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3370 note(format("Too many (%u) monster races!", tmp16u));
3376 /* Read the available records */
3377 for (i = 0; i < tmp16u; i++)
3384 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3386 if (arg_fiddle) note("Loaded Monster Memory");
3394 /* Incompatible save files */
3395 if (tmp16u > max_k_idx)
3398 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3400 note(format("Too many (%u) object kinds!", tmp16u));
3406 /* Read the object memory */
3407 for (i = 0; i < tmp16u; i++)
3410 object_kind *k_ptr = &k_info[i];
3414 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3415 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3418 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3420 if (arg_fiddle) note("Loaded Object Memory");
3424 /* Init the wilderness seeds */
3425 for (i = 0; i < max_wild_x; i++)
3427 for (j = 0; j < max_wild_y; j++)
3429 wilderness[j][i].seed = randint0(0x10000000);
3433 /* 2.1.3 or newer version */
3435 u16b max_towns_load;
3436 u16b max_quests_load;
3437 byte max_rquests_load;
3438 s16b old_inside_quest = p_ptr->inside_quest;
3440 /* Number of towns */
3441 rd_u16b(&max_towns_load);
3443 /* Incompatible save files */
3444 if (max_towns_load > max_towns)
3447 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
3449 note(format("Too many (%u) towns!", max_towns_load));
3455 /* Number of quests */
3456 rd_u16b(&max_quests_load);
3458 if (z_older_than(11, 0, 7))
3460 max_rquests_load = 10;
3464 rd_byte(&max_rquests_load);
3467 /* Incompatible save files */
3468 if (max_quests_load > max_quests)
3471 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
3473 note(format("Too many (%u) quests!", max_quests_load));
3479 for (i = 0; i < max_quests_load; i++)
3483 quest_type* const q_ptr = &quest[i];
3485 rd_s16b(&q_ptr->status);
3486 rd_s16b(&q_ptr->level);
3488 if (z_older_than(11, 0, 6))
3494 rd_byte(&q_ptr->complev);
3496 if(h_older_than(2, 1, 2, 2))
3498 q_ptr->comptime = 0;
3502 rd_u32b(&q_ptr->comptime);
3505 /* Load quest status if quest is running */
3506 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3507 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3508 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3510 rd_s16b(&q_ptr->cur_num);
3511 rd_s16b(&q_ptr->max_num);
3512 rd_s16b(&q_ptr->type);
3514 /* Load quest monster index */
3515 rd_s16b(&q_ptr->r_idx);
3517 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3519 determine_random_questor(&quest[i]);
3522 /* Load quest item index */
3523 rd_s16b(&q_ptr->k_idx);
3526 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3528 rd_byte(&q_ptr->flags);
3530 if (z_older_than(10, 3, 11))
3532 if (q_ptr->flags & QUEST_FLAG_PRESET)
3538 init_flags = INIT_ASSIGN;
3539 p_ptr->inside_quest = i;
3541 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3542 p_ptr->inside_quest = old_inside_quest;
3547 rd_byte(&q_ptr->dungeon);
3550 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3551 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3552 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3555 /* Ignore the empty quests from old versions */
3558 /* Ignore quest status */
3561 /* Ignore quest level */
3565 * We don't have to care about the other info,
3566 * since status should be 0 for these quests anyway
3571 /* Quest 18 was removed */
3572 if (h_older_than(1, 7, 0, 6))
3574 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3575 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3578 /* Position in the wilderness */
3579 rd_s32b(&p_ptr->wilderness_x);
3580 rd_s32b(&p_ptr->wilderness_y);
3581 if (z_older_than(10, 3, 13))
3583 p_ptr->wilderness_x = 5;
3584 p_ptr->wilderness_y = 48;
3587 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3588 else rd_byte((byte *)&p_ptr->wild_mode);
3589 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3590 else rd_byte((byte *)&ambush_flag);
3592 /* Size of the wilderness */
3593 rd_s32b(&wild_x_size);
3594 rd_s32b(&wild_y_size);
3596 /* Incompatible save files */
3597 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3600 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
3602 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
3608 /* Load the wilderness seeds */
3609 for (i = 0; i < wild_x_size; i++)
3611 for (j = 0; j < wild_y_size; j++)
3613 rd_u32b(&wilderness[j][i].seed);
3619 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3621 if (arg_fiddle) note("Loaded Quests");
3624 /* Load the Artifacts */
3627 /* Incompatible save files */
3628 if (tmp16u > max_a_idx)
3631 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3633 note(format("Too many (%u) artifacts!", tmp16u));
3639 /* Read the artifact flags */
3640 for (i = 0; i < tmp16u; i++)
3642 artifact_type *a_ptr = &a_info[i];
3645 a_ptr->cur_num = tmp8u;
3647 if (h_older_than(1, 5, 0, 0))
3649 a_ptr->floor_id = 0;
3657 rd_s16b(&a_ptr->floor_id);
3661 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3663 if (arg_fiddle) note("Loaded Artifacts");
3668 /* Read the extra stuff */
3670 if (p_ptr->energy_need < -999) world_player = TRUE;
3673 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3675 if (arg_fiddle) note("Loaded extra information");
3679 /* Read the player_hp array */
3682 /* Incompatible save files */
3683 if (tmp16u > PY_MAX_LEVEL)
3686 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
3688 note(format("Too many (%u) hitpoint entries!", tmp16u));
3694 /* Read the player_hp array */
3695 for (i = 0; i < tmp16u; i++)
3697 rd_s16b(&p_ptr->player_hp[i]);
3700 /* Important -- Initialize the sex */
3701 sp_ptr = &sex_info[p_ptr->psex];
3703 /* Important -- Initialize the race/class */
3704 rp_ptr = &race_info[p_ptr->prace];
3705 cp_ptr = &class_info[p_ptr->pclass];
3706 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3708 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3710 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3711 do_cmd_rerate(FALSE);
3713 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3715 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3716 do_cmd_rerate(FALSE);
3718 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3720 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3721 do_cmd_rerate(FALSE);
3723 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3725 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3726 do_cmd_rerate(FALSE);
3729 /* Important -- Initialize the magic */
3730 mp_ptr = &m_info[p_ptr->pclass];
3733 /* Read spell info */
3734 rd_u32b(&p_ptr->spell_learned1);
3735 rd_u32b(&p_ptr->spell_learned2);
3736 rd_u32b(&p_ptr->spell_worked1);
3737 rd_u32b(&p_ptr->spell_worked2);
3738 rd_u32b(&p_ptr->spell_forgotten1);
3739 rd_u32b(&p_ptr->spell_forgotten2);
3741 if (z_older_than(10,0,5))
3743 p_ptr->learned_spells = 0;
3744 for (i = 0; i < 64; i++)
3746 /* Count known spells */
3748 (p_ptr->spell_learned1 & (1L << i)) :
3749 (p_ptr->spell_learned2 & (1L << (i - 32))))
3751 p_ptr->learned_spells++;
3755 else rd_s16b(&p_ptr->learned_spells);
3757 if (z_older_than(10,0,6))
3759 p_ptr->add_spells = 0;
3761 else rd_s16b(&p_ptr->add_spells);
3762 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3764 for (i = 0; i < 64; i++)
3766 rd_byte(&p_ptr->spell_order[i]);
3770 /* Read the inventory */
3774 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
3776 note("Unable to read inventory");
3782 /* Read number of towns */
3784 town_count = tmp16u;
3786 /* Read the stores */
3788 for (i = 1; i < town_count; i++)
3790 for (j = 0; j < tmp16u; j++)
3792 if (rd_store(i, j)) return (22);
3796 rd_s16b(&p_ptr->pet_follow_distance);
3797 if (z_older_than(10, 4, 10))
3799 p_ptr->pet_extra_flags = 0;
3801 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3803 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3805 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3809 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3812 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3816 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3819 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3823 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3826 if (!z_older_than(10,0,8))
3829 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3834 rd_s16b(&p_ptr->pet_extra_flags);
3837 if (!z_older_than(11, 0, 9))
3839 char buf[SCREEN_BUF_SIZE];
3840 rd_string(buf, sizeof(buf));
3841 if (buf[0]) screen_dump = string_make(buf);
3846 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3848 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3853 /* I'm not dead yet... */
3854 if (!p_ptr->is_dead)
3856 /* Dead players have no dungeon */
3858 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
3860 note("Restoring Dungeon...");
3866 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
3868 note("Error reading dungeon data");
3874 /* Read the ghost info */
3881 strip_bytes(tmp32s);
3885 /* Quest 18 was removed */
3886 if (h_older_than(1, 7, 0, 6))
3888 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3890 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3892 p_ptr->inside_quest = 0;
3897 #ifdef VERIFY_CHECKSUMS
3899 /* Save the checksum */
3900 n_v_check = v_check;
3902 /* Read the old checksum */
3903 rd_u32b(&o_v_check);
3906 if (o_v_check != n_v_check)
3909 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3911 note("Invalid checksum");
3918 /* Save the encoded checksum */
3919 n_x_check = x_check;
3921 /* Read the checksum */
3922 rd_u32b(&o_x_check);
3926 if (o_x_check != n_x_check)
3929 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3931 note("Invalid encoded checksum");
3945 * Actually read the savefile
3947 errr rd_savefile_new(void)
3951 /* Grab permissions */
3954 /* The savefile is a binary file */
3955 fff = my_fopen(savefile, "rb");
3957 /* Drop permissions */
3961 if (!fff) return (-1);
3963 /* Call the sub-function */
3964 err = rd_savefile_new_aux();
3966 /* Check for errors */
3967 if (ferror(fff)) err = -1;
3969 /* Close the file */
3978 * Actually load and verify a floor save data
3980 static bool load_floor_aux(saved_floor_type *sf_ptr)
3985 #ifdef VERIFY_CHECKSUMS
3986 u32b n_x_check, n_v_check;
3987 u32b o_x_check, o_v_check;
3990 /* Hack -- decrypt (read xor_byte) */
3994 /* Clear the checksums */
3998 /* Set the version number to current version */
3999 /* Never load old temporal files */
4000 h_ver_extra = H_VER_EXTRA;
4001 h_ver_patch = H_VER_PATCH;
4002 h_ver_minor = H_VER_MINOR;
4003 h_ver_major = H_VER_MAJOR;
4005 /* Verify the sign */
4007 if (saved_floor_file_sign != tmp32u) return FALSE;
4009 /* Read -- have error? */
4010 if (rd_saved_floor(sf_ptr)) return FALSE;
4013 #ifdef VERIFY_CHECKSUMS
4014 /* Save the checksum */
4015 n_v_check = v_check;
4017 /* Read the old checksum */
4018 rd_u32b(&o_v_check);
4021 if (o_v_check != n_v_check) return FALSE;
4023 /* Save the encoded checksum */
4024 n_x_check = x_check;
4026 /* Read the checksum */
4027 rd_u32b(&o_x_check);
4030 if (o_x_check != n_x_check) return FALSE;
4039 * Attempt to load the temporally saved-floor data
4041 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
4043 FILE *old_fff = NULL;
4044 byte old_xor_byte = 0;
4045 u32b old_v_check = 0;
4046 u32b old_x_check = 0;
4047 byte old_h_ver_major = 0;
4048 byte old_h_ver_minor = 0;
4049 byte old_h_ver_patch = 0;
4050 byte old_h_ver_extra = 0;
4053 char floor_savefile[1024];
4055 byte old_kanji_code = kanji_code;
4058 * Temporal files are always written in system depended kanji
4063 /* EUC kanji code */
4067 /* SJIS kanji code */
4076 /* We have one file already opened */
4077 if (mode & SLF_SECOND)
4079 /* Backup original values */
4081 old_xor_byte = xor_byte;
4082 old_v_check = v_check;
4083 old_x_check = x_check;
4084 old_h_ver_major = h_ver_major;
4085 old_h_ver_minor = h_ver_minor;
4086 old_h_ver_patch = h_ver_patch;
4087 old_h_ver_extra = h_ver_extra;
4090 /* floor savefile */
4091 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4093 /* Grab permissions */
4096 /* The savefile is a binary file */
4097 fff = my_fopen(floor_savefile, "rb");
4099 /* Drop permissions */
4103 if (!fff) ok = FALSE;
4105 /* Attempt to load */
4108 /* Load saved floor data from file */
4109 ok = load_floor_aux(sf_ptr);
4111 /* Check for errors */
4112 if (ferror(fff)) ok = FALSE;
4114 /* Close the file */
4117 /* Grab permissions */
4120 /* Delete the file */
4121 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4123 /* Drop permissions */
4127 /* We have one file already opened */
4128 if (mode & SLF_SECOND)
4130 /* Restore original values */
4132 xor_byte = old_xor_byte;
4133 v_check = old_v_check;
4134 x_check = old_x_check;
4135 h_ver_major = old_h_ver_major;
4136 h_ver_minor = old_h_ver_minor;
4137 h_ver_patch = old_h_ver_patch;
4138 h_ver_extra = old_h_ver_extra;
4141 /* Restore old knowledge */
4142 kanji_code = old_kanji_code;