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_EXP); 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;
625 if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
626 else o_ptr->art_flags[4] = 0;
628 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
629 else o_ptr->curse_flags = 0;
631 /* Monster holding object */
632 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
633 else o_ptr->held_m_idx = 0;
636 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
637 else o_ptr->xtra1 = 0;
638 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
639 else o_ptr->xtra2 = 0;
641 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
642 else o_ptr->xtra3 = 0;
644 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
645 else o_ptr->xtra4 = 0;
646 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
647 else o_ptr->xtra5 = 0;
649 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
650 else o_ptr->feeling = 0;
652 if (flags & SAVE_ITEM_INSCRIPTION)
654 rd_string(buf, sizeof(buf));
655 o_ptr->inscription = quark_add(buf);
657 else o_ptr->inscription = 0;
659 if (flags & SAVE_ITEM_ART_NAME)
661 rd_string(buf, sizeof(buf));
662 o_ptr->art_name = quark_add(buf);
664 else o_ptr->art_name = 0;
666 if(h_older_than(2,1,2,4))
668 u32b flgs[TR_FLAG_SIZE];
669 object_flags(o_ptr, flgs);
671 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
673 add_flag(o_ptr->art_flags, TR_LITE_M1);
674 remove_flag(o_ptr->art_flags, TR_LITE_1);
675 remove_flag(o_ptr->art_flags, TR_LITE_2);
676 remove_flag(o_ptr->art_flags, TR_LITE_3);
678 else if (o_ptr->name2 == EGO_LITE_DARKNESS)
680 if (o_ptr->tval == TV_LITE)
682 if (o_ptr->sval == SV_LITE_TORCH)
684 add_flag(o_ptr->art_flags, TR_LITE_M1);
686 else if (o_ptr->sval == SV_LITE_LANTERN)
688 add_flag(o_ptr->art_flags, TR_LITE_M2);
690 else if (o_ptr->sval == SV_LITE_FEANOR)
692 add_flag(o_ptr->art_flags, TR_LITE_M3);
698 add_flag(o_ptr->art_flags, TR_LITE_M1);
701 else if (o_ptr->tval == TV_LITE)
703 if (object_is_fixed_artifact(o_ptr))
705 add_flag(o_ptr->art_flags, TR_LITE_3);
707 else if (o_ptr->sval == SV_LITE_TORCH)
709 add_flag(o_ptr->art_flags, TR_LITE_1);
710 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
712 else if (o_ptr->sval == SV_LITE_LANTERN)
714 add_flag(o_ptr->art_flags, TR_LITE_2);
715 add_flag(o_ptr->art_flags, TR_LITE_FUEL);
717 else if (o_ptr->sval == SV_LITE_FEANOR)
719 add_flag(o_ptr->art_flags, TR_LITE_2);
727 * Read a monster (Old method)
729 static void rd_monster_old(monster_type *m_ptr)
734 /* Read the monster race */
735 rd_s16b(&m_ptr->r_idx);
737 if (z_older_than(11, 0, 12))
738 m_ptr->ap_r_idx = m_ptr->r_idx;
740 rd_s16b(&m_ptr->ap_r_idx);
742 if (z_older_than(11, 0, 14))
744 monster_race *r_ptr = &r_info[m_ptr->r_idx];
746 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
747 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
748 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
751 rd_byte(&m_ptr->sub_align);
753 /* Read the other information */
757 rd_s16b(&m_ptr->maxhp);
758 if (z_older_than(11, 0, 5))
760 m_ptr->max_maxhp = m_ptr->maxhp;
764 rd_s16b(&m_ptr->max_maxhp);
766 if(h_older_than(2, 1, 2, 1))
768 m_ptr->dealt_damage = 0;
772 rd_u32b(&m_ptr->dealt_damage);
775 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
776 rd_byte(&m_ptr->mspeed);
777 if (z_older_than(10, 4, 2))
780 m_ptr->energy_need = (s16b)tmp8u;
782 else rd_s16b(&m_ptr->energy_need);
784 if (z_older_than(11, 0, 13))
785 m_ptr->energy_need = 100 - m_ptr->energy_need;
787 if (z_older_than(10,0,7))
789 m_ptr->mtimed[MTIMED_FAST] = 0;
790 m_ptr->mtimed[MTIMED_SLOW] = 0;
795 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
797 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
800 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
802 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
804 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
806 if (z_older_than(10,0,10))
810 else if (z_older_than(10,0,11))
818 rd_s16b(&m_ptr->target_y);
819 rd_s16b(&m_ptr->target_x);
823 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
825 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
826 rd_u32b(&m_ptr->smart);
830 if (z_older_than(10, 4, 5))
833 rd_u32b(&m_ptr->exp);
835 if (z_older_than(10, 2, 2))
837 if (m_ptr->r_idx < 0)
839 m_ptr->r_idx = (0-m_ptr->r_idx);
840 m_ptr->mflag2 |= MFLAG2_KAGE;
845 rd_byte(&m_ptr->mflag2);
848 if (z_older_than(11, 0, 12))
850 if (m_ptr->mflag2 & MFLAG2_KAGE)
851 m_ptr->ap_r_idx = MON_KAGE;
854 if (z_older_than(10, 1, 3))
860 rd_string(buf, sizeof(buf));
861 if (buf[0]) m_ptr->nickname = quark_add(buf);
869 * Read a monster (New method)
871 static void rd_monster(monster_type *m_ptr)
877 if (h_older_than(1, 5, 0, 0))
879 rd_monster_old(m_ptr);
883 /*** Monster save flags ***/
886 /*** Read un-obvious elements ***/
888 /* Read the monster race */
889 rd_s16b(&m_ptr->r_idx);
891 /* Read the other information */
895 rd_s16b(&m_ptr->maxhp);
896 rd_s16b(&m_ptr->max_maxhp);
897 if(h_older_than(2, 1, 2, 1))
899 m_ptr->dealt_damage = 0;
903 rd_u32b(&m_ptr->dealt_damage);
906 /* Monster race index of its appearance */
907 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
908 else m_ptr->ap_r_idx = m_ptr->r_idx;
910 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
911 else m_ptr->sub_align = 0;
913 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
914 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
916 rd_byte(&m_ptr->mspeed);
918 rd_s16b(&m_ptr->energy_need);
920 if (flags & SAVE_MON_FAST)
923 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
925 else m_ptr->mtimed[MTIMED_FAST] = 0;
926 if (flags & SAVE_MON_SLOW)
929 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
931 else m_ptr->mtimed[MTIMED_SLOW] = 0;
932 if (flags & SAVE_MON_STUNNED)
935 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
937 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
938 if (flags & SAVE_MON_CONFUSED)
941 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
943 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
944 if (flags & SAVE_MON_MONFEAR)
947 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
949 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
951 if (flags & SAVE_MON_TARGET_Y) rd_s16b(&m_ptr->target_y);
952 else m_ptr->target_y = 0;
953 if (flags & SAVE_MON_TARGET_X) rd_s16b(&m_ptr->target_x);
954 else m_ptr->target_x = 0;
956 if (flags & SAVE_MON_INVULNER)
959 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
961 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
963 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
964 else m_ptr->smart = 0;
966 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
969 m_ptr->mflag = 0; /* Not saved */
971 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
972 else m_ptr->mflag2 = 0;
974 if (flags & SAVE_MON_NICKNAME)
976 rd_string(buf, sizeof(buf));
977 m_ptr->nickname = quark_add(buf);
979 else m_ptr->nickname = 0;
981 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
982 else m_ptr->parent_m_idx = 0;
987 * Old monster bit flags of racial resistances
989 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
990 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
991 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
992 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
993 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
994 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
995 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
996 #define RF3_RES_WATE 0x00800000 /* Resist water */
997 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
998 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
999 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
1000 #define RF3_RES_ALL 0x08000000 /* Resist all */
1002 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
1004 if ((R_PTR)->r_flags3 & (RF3)) \
1006 (R_PTR)->r_flags3 &= ~(RF3); \
1007 (R_PTR)->r_flagsr |= (RFR); \
1011 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
1013 if ((R_PTR)->r_flags4 & (RF4_BR)) \
1015 (R_PTR)->r_flagsr |= (RFR); \
1019 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
1020 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
1021 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
1022 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
1023 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
1024 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
1025 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
1026 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
1027 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
1028 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
1030 * Read the monster lore
1032 static void rd_lore(int r_idx)
1036 monster_race *r_ptr = &r_info[r_idx];
1038 /* Count sights/deaths/kills */
1039 rd_s16b(&r_ptr->r_sights);
1040 rd_s16b(&r_ptr->r_deaths);
1041 rd_s16b(&r_ptr->r_pkills);
1042 if (h_older_than(1, 7, 0, 5))
1044 r_ptr->r_akills = r_ptr->r_pkills;
1048 rd_s16b(&r_ptr->r_akills);
1050 rd_s16b(&r_ptr->r_tkills);
1052 /* Count wakes and ignores */
1053 rd_byte(&r_ptr->r_wake);
1054 rd_byte(&r_ptr->r_ignore);
1057 rd_byte(&r_ptr->r_xtra1);
1058 rd_byte(&r_ptr->r_xtra2);
1061 rd_byte(&r_ptr->r_drop_gold);
1062 rd_byte(&r_ptr->r_drop_item);
1066 rd_byte(&r_ptr->r_cast_spell);
1068 /* Count blows of each type */
1069 rd_byte(&r_ptr->r_blows[0]);
1070 rd_byte(&r_ptr->r_blows[1]);
1071 rd_byte(&r_ptr->r_blows[2]);
1072 rd_byte(&r_ptr->r_blows[3]);
1074 /* Memorize flags */
1075 rd_u32b(&r_ptr->r_flags1);
1076 rd_u32b(&r_ptr->r_flags2);
1077 rd_u32b(&r_ptr->r_flags3);
1078 rd_u32b(&r_ptr->r_flags4);
1079 rd_u32b(&r_ptr->r_flags5);
1080 rd_u32b(&r_ptr->r_flags6);
1081 if (h_older_than(1, 5, 0, 3))
1083 r_ptr->r_flagsr = 0L;
1085 /* Move RF3 resistance flags to RFR */
1086 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1087 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1088 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1089 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1090 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1091 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1092 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1093 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1094 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1095 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1096 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1097 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1099 /* Separate breathers resistance from RF4 to RFR */
1100 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1101 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1102 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1103 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1104 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1105 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1106 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1107 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1108 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1110 /* Resist confusion is merged to RF3_NO_CONF */
1111 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1113 /* Misc resistance hack to RFR */
1114 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1115 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1119 rd_u32b(&r_ptr->r_flagsr);
1122 /* Read the "Racial" monster limit per level */
1123 rd_byte(&r_ptr->max_num);
1125 /* Location in saved floor */
1126 rd_s16b(&r_ptr->floor_id);
1131 /* Repair the lore flags */
1132 r_ptr->r_flags1 &= r_ptr->flags1;
1133 r_ptr->r_flags2 &= r_ptr->flags2;
1134 r_ptr->r_flags3 &= r_ptr->flags3;
1135 r_ptr->r_flags4 &= r_ptr->flags4;
1136 r_ptr->r_flags5 &= r_ptr->flags5;
1137 r_ptr->r_flags6 &= r_ptr->flags6;
1138 r_ptr->r_flagsr &= r_ptr->flagsr;
1145 * Add the item "o_ptr" to the inventory of the "Home"
1147 * In all cases, return the slot (or -1) where the object was placed
1149 * Note that this is a hacked up version of "inven_carry()".
1151 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1152 * known, the player may have to pick stuff up and drop it again.
1154 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1162 /* Check each existing item (try to combine) */
1163 for (slot = 0; slot < st_ptr->stock_num; slot++)
1165 /* Get the existing item */
1166 j_ptr = &st_ptr->stock[slot];
1168 /* The home acts just like the player */
1169 if (object_similar(j_ptr, o_ptr))
1171 /* Save the new number of items */
1172 object_absorb(j_ptr, o_ptr);
1180 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1184 /* Determine the "value" of the item */
1185 value = object_value(o_ptr);
1187 /* Check existing slots to see if we must "slide" */
1188 for (slot = 0; slot < st_ptr->stock_num; slot++)
1190 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1193 /* Slide the others up */
1194 for (i = st_ptr->stock_num; i > slot; i--)
1196 st_ptr->stock[i] = st_ptr->stock[i-1];
1199 /* More stuff now */
1200 st_ptr->stock_num++;
1202 /* Insert the new item */
1203 st_ptr->stock[slot] = *o_ptr;
1205 chg_virtue(V_SACRIFICE, -1);
1207 /* Return the location */
1215 static errr rd_store(int town_number, int store_number)
1227 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1229 st_ptr = &town[1].store[store_number];
1230 if (st_ptr->stock_num) sort = TRUE;
1234 st_ptr = &town[town_number].store[store_number];
1237 /* Read the basic info */
1238 rd_s32b(&st_ptr->store_open);
1239 rd_s16b(&st_ptr->insult_cur);
1241 if (z_older_than(11, 0, 4))
1250 rd_s16b(&st_ptr->good_buy);
1251 rd_s16b(&st_ptr->bad_buy);
1253 /* Read last visit */
1254 rd_s32b(&st_ptr->last_visit);
1256 /* Extract the owner (see above) */
1257 st_ptr->owner = own;
1259 /* Read the items */
1260 for (j = 0; j < num; j++)
1265 /* Get local object */
1268 /* Wipe the object */
1274 /* Acquire valid items */
1275 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1280 home_carry(st_ptr, q_ptr);
1284 k = st_ptr->stock_num++;
1286 /* Acquire the item */
1287 object_copy(&st_ptr->stock[k], q_ptr);
1299 * Read RNG state (added in 2.8.0)
1301 static void rd_randomizer(void)
1311 rd_u16b(&Rand_place);
1314 for (i = 0; i < RAND_DEG; i++)
1316 rd_u32b(&Rand_state[i]);
1323 * Read options (ignore most pre-2.8.0 options)
1325 * Note that the normal options are now stored as a set of 256 bit flags,
1326 * plus a set of 256 bit masks to indicate which bit flags were defined
1327 * at the time the savefile was created. This will allow new options
1328 * to be added, and old options to be removed, at any time, without
1329 * hurting old savefiles.
1331 * The window options are stored in the same way, but note that each
1332 * window gets 32 options, and their order is fixed by certain defines.
1334 static void rd_options(void)
1348 /* Ignore old options */
1352 /*** Special info */
1354 /* Read "delay_factor" */
1358 /* Read "hitpoint_warn" */
1362 /* Read "mana_warn" */
1363 if(h_older_than(1, 7, 0, 0))
1374 /*** Cheating options ***/
1378 if (c & 0x0002) p_ptr->wizard = TRUE;
1380 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1381 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1382 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1383 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1384 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1385 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1386 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1388 rd_byte((byte *)&autosave_l);
1389 rd_byte((byte *)&autosave_t);
1390 rd_s16b(&autosave_freq);
1393 /*** Normal Options ***/
1395 /* Read the option flags */
1396 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1398 /* Read the option masks */
1399 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1401 /* Analyze the options */
1402 for (n = 0; n < 8; n++)
1404 /* Analyze the options */
1405 for (i = 0; i < 32; i++)
1407 /* Process valid flags */
1408 if (mask[n] & (1L << i))
1410 /* Process valid flags */
1411 if (option_mask[n] & (1L << i))
1414 if (flag[n] & (1L << i))
1417 option_flag[n] |= (1L << i);
1424 option_flag[n] &= ~(1L << i);
1431 if (z_older_than(10, 4, 5))
1433 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1434 else option_flag[5] |= (0x00000001 << 4);
1435 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1436 else option_flag[2] |= (0x00000001 << 5);
1437 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1438 else option_flag[4] |= (0x00000001 << 5);
1439 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1440 else option_flag[5] |= (0x00000001 << 0);
1441 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1442 else option_flag[5] |= (0x00000001 << 12);
1443 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1444 else option_flag[1] |= (0x00000001 << 0);
1445 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1446 else option_flag[1] |= (0x00000001 << 18);
1447 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1448 else option_flag[1] |= (0x00000001 << 19);
1449 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1450 else option_flag[5] |= (0x00000001 << 3);
1453 /* Extract the options */
1454 extract_option_vars();
1457 /*** Window Options ***/
1459 /* Read the window flags */
1460 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1462 /* Read the window masks */
1463 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1465 /* Analyze the options */
1466 for (n = 0; n < 8; n++)
1468 /* Analyze the options */
1469 for (i = 0; i < 32; i++)
1471 /* Process valid flags */
1472 if (mask[n] & (1L << i))
1474 /* Process valid flags */
1475 if (window_mask[n] & (1L << i))
1478 if (flag[n] & (1L << i))
1481 window_flag[n] |= (1L << i);
1488 window_flag[n] &= ~(1L << i);
1501 * Hack -- strip the "ghost" info
1503 * XXX XXX XXX This is such a nasty hack it hurts.
1505 static void rd_ghost(void)
1510 rd_string(buf, sizeof(buf));
1512 /* Strip old data */
1518 * Save quick start data
1520 static void load_quick_start(void)
1525 if (z_older_than(11, 0, 13))
1527 previous_char.quick_ok = FALSE;
1531 rd_byte(&previous_char.psex);
1532 rd_byte(&previous_char.prace);
1533 rd_byte(&previous_char.pclass);
1534 rd_byte(&previous_char.pseikaku);
1535 rd_byte(&previous_char.realm1);
1536 rd_byte(&previous_char.realm2);
1538 rd_s16b(&previous_char.age);
1539 rd_s16b(&previous_char.ht);
1540 rd_s16b(&previous_char.wt);
1541 rd_s16b(&previous_char.sc);
1542 rd_s32b(&previous_char.au);
1544 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1545 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1547 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1549 rd_s16b(&previous_char.chaos_patron);
1551 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1553 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1555 /* UNUSED : Was number of random quests */
1559 previous_char.quick_ok = (bool)tmp8u;
1563 * Read the "extra" information
1565 static void rd_extra(void)
1573 rd_string(player_name, sizeof(player_name));
1575 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1577 if (!h_older_than(1, 7, 0, 1))
1581 /* Read the message */
1582 rd_string(buf, sizeof buf);
1583 if (buf[0]) p_ptr->last_message = string_make(buf);
1588 for (i = 0; i < 4; i++)
1590 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1593 /* Class/Race/Seikaku/Gender/Spells */
1594 rd_byte(&p_ptr->prace);
1595 rd_byte(&p_ptr->pclass);
1596 rd_byte(&p_ptr->pseikaku);
1597 rd_byte(&p_ptr->psex);
1598 rd_byte(&p_ptr->realm1);
1599 rd_byte(&p_ptr->realm2);
1600 rd_byte(&tmp8u); /* oops */
1602 if (z_older_than(10, 4, 4))
1604 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1605 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1606 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1607 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1610 /* Special Race/Class info */
1611 rd_byte(&p_ptr->hitdie);
1612 rd_u16b(&p_ptr->expfact);
1614 /* Age/Height/Weight */
1615 rd_s16b(&p_ptr->age);
1616 rd_s16b(&p_ptr->ht);
1617 rd_s16b(&p_ptr->wt);
1619 /* Read the stat info */
1620 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1621 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1622 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1624 strip_bytes(24); /* oops */
1626 rd_s32b(&p_ptr->au);
1628 rd_s32b(&p_ptr->max_exp);
1629 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1630 else rd_s32b(&p_ptr->max_max_exp);
1631 rd_s32b(&p_ptr->exp);
1633 if (h_older_than(1, 7, 0, 3))
1636 p_ptr->exp_frac = (u32b)tmp16u;
1640 rd_u32b(&p_ptr->exp_frac);
1643 rd_s16b(&p_ptr->lev);
1645 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1646 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1648 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1650 if (z_older_than(10, 3, 6))
1651 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1653 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1654 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1655 if (z_older_than(10, 4, 1))
1657 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1658 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1660 if (z_older_than(10, 3, 14))
1662 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1663 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1667 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1668 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1669 if (h_older_than(1, 3, 0, 1))
1671 if (p_ptr->pclass == CLASS_SMITH)
1673 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1674 p_ptr->magic_num1[96] = 0;
1675 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1676 p_ptr->magic_num1[97] = 0;
1680 if (music_singing_any()) p_ptr->action = ACTION_SING;
1682 if (z_older_than(11, 0, 7))
1684 p_ptr->start_race = p_ptr->prace;
1685 p_ptr->old_race1 = 0L;
1686 p_ptr->old_race2 = 0L;
1687 p_ptr->old_realm = 0;
1691 rd_byte(&p_ptr->start_race);
1692 rd_s32b(&p_ptr->old_race1);
1693 rd_s32b(&p_ptr->old_race2);
1694 rd_s16b(&p_ptr->old_realm);
1697 if (z_older_than(10, 0, 1))
1699 for (i = 0; i < OLD_MAX_MANE; i++)
1701 p_ptr->mane_spell[i] = -1;
1702 p_ptr->mane_dam[i] = 0;
1704 p_ptr->mane_num = 0;
1706 else if (z_older_than(10, 2, 3))
1708 for (i = 0; i < OLD_MAX_MANE; i++)
1713 for (i = 0; i < MAX_MANE; i++)
1715 p_ptr->mane_spell[i] = -1;
1716 p_ptr->mane_dam[i] = 0;
1719 p_ptr->mane_num = 0;
1723 for (i = 0; i < MAX_MANE; i++)
1725 rd_s16b(&p_ptr->mane_spell[i]);
1726 rd_s16b(&p_ptr->mane_dam[i]);
1728 rd_s16b(&p_ptr->mane_num);
1731 if (z_older_than(10, 0, 3))
1733 determine_bounty_uniques();
1735 for (i = 0; i < MAX_KUBI; i++)
1737 /* Is this bounty unique already dead? */
1738 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1743 for (i = 0; i < MAX_KUBI; i++)
1745 rd_s16b(&kubi_r_idx[i]);
1749 if (z_older_than(10, 0, 3))
1755 for (i = 0; i < 4; i++)
1757 rd_s16b(&battle_mon[i]);
1758 if (z_older_than(10, 3, 4))
1761 mon_odds[i] = tmp16s;
1763 else rd_u32b(&mon_odds[i]);
1767 rd_s16b(&p_ptr->town_num);
1769 /* Read arena and rewards information */
1770 rd_s16b(&p_ptr->arena_number);
1771 if (h_older_than(1, 5, 0, 1))
1773 /* Arena loser of previous version was marked number 99 */
1774 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1777 p_ptr->inside_arena = (bool)tmp16s;
1778 rd_s16b(&p_ptr->inside_quest);
1779 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1783 p_ptr->inside_battle = (bool)tmp16s;
1785 rd_byte(&p_ptr->exit_bldg);
1788 rd_s16b(&p_ptr->oldpx);
1789 rd_s16b(&p_ptr->oldpy);
1790 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1792 /* Was p_ptr->rewards[MAX_BACT] */
1794 for (i = 0; i < tmp16s; i++)
1800 if (h_older_than(1, 7, 0, 3))
1803 p_ptr->mhp = tmp16s;
1806 p_ptr->chp = tmp16s;
1809 p_ptr->chp_frac = (u32b)tmp16u;
1813 rd_s32b(&p_ptr->mhp);
1814 rd_s32b(&p_ptr->chp);
1815 rd_u32b(&p_ptr->chp_frac);
1818 if (h_older_than(1, 7, 0, 3))
1821 p_ptr->msp = tmp16s;
1824 p_ptr->csp = tmp16s;
1827 p_ptr->csp_frac = (u32b)tmp16u;
1831 rd_s32b(&p_ptr->msp);
1832 rd_s32b(&p_ptr->csp);
1833 rd_u32b(&p_ptr->csp_frac);
1836 rd_s16b(&p_ptr->max_plv);
1837 if (z_older_than(10, 3, 8))
1839 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1843 byte max = (byte)max_d_idx;
1847 for(i = 0; i < max; i++)
1849 rd_s16b(&max_dlv[i]);
1850 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1854 /* Repair maximum player level XXX XXX XXX */
1855 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1859 rd_s16b(&p_ptr->sc);
1860 rd_s16b(&p_ptr->concent);
1862 /* Read the flags */
1863 strip_bytes(2); /* Old "rest" */
1864 rd_s16b(&p_ptr->blind);
1865 rd_s16b(&p_ptr->paralyzed);
1866 rd_s16b(&p_ptr->confused);
1867 rd_s16b(&p_ptr->food);
1868 strip_bytes(4); /* Old "food_digested" / "protection" */
1870 rd_s16b(&p_ptr->energy_need);
1871 if (z_older_than(11, 0, 13))
1872 p_ptr->energy_need = 100 - p_ptr->energy_need;
1873 if (h_older_than(2, 1, 2, 0))
1874 p_ptr->enchant_energy_need = 0;
1876 rd_s16b(&p_ptr->enchant_energy_need);
1878 rd_s16b(&p_ptr->fast);
1879 rd_s16b(&p_ptr->slow);
1880 rd_s16b(&p_ptr->afraid);
1881 rd_s16b(&p_ptr->cut);
1882 rd_s16b(&p_ptr->stun);
1883 rd_s16b(&p_ptr->poisoned);
1884 rd_s16b(&p_ptr->image);
1885 rd_s16b(&p_ptr->protevil);
1886 rd_s16b(&p_ptr->invuln);
1887 if(z_older_than(10, 0, 0))
1890 rd_s16b(&p_ptr->ult_res);
1891 rd_s16b(&p_ptr->hero);
1892 rd_s16b(&p_ptr->shero);
1893 rd_s16b(&p_ptr->shield);
1894 rd_s16b(&p_ptr->blessed);
1895 rd_s16b(&p_ptr->tim_invis);
1896 rd_s16b(&p_ptr->word_recall);
1897 if (z_older_than(10, 3, 8))
1898 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1902 p_ptr->recall_dungeon = (byte)tmp16s;
1905 if (h_older_than(1, 5, 0, 0))
1906 p_ptr->alter_reality = 0;
1908 rd_s16b(&p_ptr->alter_reality);
1910 rd_s16b(&p_ptr->see_infra);
1911 rd_s16b(&p_ptr->tim_infra);
1912 rd_s16b(&p_ptr->oppose_fire);
1913 rd_s16b(&p_ptr->oppose_cold);
1914 rd_s16b(&p_ptr->oppose_acid);
1915 rd_s16b(&p_ptr->oppose_elec);
1916 rd_s16b(&p_ptr->oppose_pois);
1917 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1918 else rd_s16b(&p_ptr->tsuyoshi);
1920 /* Old savefiles do not have the following fields... */
1921 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1924 p_ptr->wraith_form = 0;
1925 p_ptr->resist_magic = 0;
1926 p_ptr->tim_regen = 0;
1927 p_ptr->kabenuke = 0;
1928 p_ptr->tim_stealth = 0;
1929 p_ptr->tim_levitation = 0;
1930 p_ptr->tim_sh_touki = 0;
1931 p_ptr->lightspeed = 0;
1932 p_ptr->tsubureru = 0;
1933 p_ptr->tim_res_nether = 0;
1934 p_ptr->tim_res_time = 0;
1935 p_ptr->mimic_form = 0;
1936 p_ptr->tim_mimic = 0;
1937 p_ptr->tim_sh_fire = 0;
1940 p_ptr->tim_reflect = 0;
1941 p_ptr->multishadow = 0;
1942 p_ptr->dustrobe = 0;
1944 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
1952 rd_s16b(&p_ptr->tim_esp);
1953 rd_s16b(&p_ptr->wraith_form);
1954 rd_s16b(&p_ptr->resist_magic);
1955 rd_s16b(&p_ptr->tim_regen);
1956 rd_s16b(&p_ptr->kabenuke);
1957 rd_s16b(&p_ptr->tim_stealth);
1958 rd_s16b(&p_ptr->tim_levitation);
1959 rd_s16b(&p_ptr->tim_sh_touki);
1960 rd_s16b(&p_ptr->lightspeed);
1961 rd_s16b(&p_ptr->tsubureru);
1962 if (z_older_than(10, 4, 7))
1963 p_ptr->magicdef = 0;
1965 rd_s16b(&p_ptr->magicdef);
1966 rd_s16b(&p_ptr->tim_res_nether);
1967 if (z_older_than(10, 4, 11))
1969 p_ptr->tim_res_time = 0;
1970 p_ptr->mimic_form = 0;
1971 p_ptr->tim_mimic = 0;
1972 p_ptr->tim_sh_fire = 0;
1976 rd_s16b(&p_ptr->tim_res_time);
1977 rd_byte(&p_ptr->mimic_form);
1978 rd_s16b(&p_ptr->tim_mimic);
1979 rd_s16b(&p_ptr->tim_sh_fire);
1982 if (z_older_than(11, 0, 99))
1984 p_ptr->tim_sh_holy = 0;
1985 p_ptr->tim_eyeeye = 0;
1989 rd_s16b(&p_ptr->tim_sh_holy);
1990 rd_s16b(&p_ptr->tim_eyeeye);
1994 if ( z_older_than(11,0,3) ){
1995 p_ptr->tim_reflect=0;
1996 p_ptr->multishadow=0;
2000 rd_s16b(&p_ptr->tim_reflect);
2001 rd_s16b(&p_ptr->multishadow);
2002 rd_s16b(&p_ptr->dustrobe);
2005 rd_s16b(&p_ptr->chaos_patron);
2006 rd_u32b(&p_ptr->muta1);
2007 rd_u32b(&p_ptr->muta2);
2008 rd_u32b(&p_ptr->muta3);
2010 for (i = 0; i < 8; i++)
2011 rd_s16b(&p_ptr->virtues[i]);
2012 for (i = 0; i < 8; i++)
2013 rd_s16b(&p_ptr->vir_types[i]);
2016 /* Calc the regeneration modifier for mutations */
2017 mutant_regenerate_mod = calc_mutant_regenerate_mod();
2019 if (z_older_than(10,0,9))
2022 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
2023 p_ptr->ele_attack = 0;
2027 rd_s16b(&p_ptr->ele_attack);
2028 rd_u32b(&p_ptr->special_attack);
2030 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
2031 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
2032 if (z_older_than(10,0,12))
2034 p_ptr->ele_immune = 0;
2035 p_ptr->special_defense = 0;
2039 rd_s16b(&p_ptr->ele_immune);
2040 rd_u32b(&p_ptr->special_defense);
2042 rd_byte(&p_ptr->knowledge);
2045 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
2047 rd_byte(&tmp8u); /* oops */
2048 rd_byte(&p_ptr->action);
2049 if (!z_older_than(10, 4, 3))
2052 if (tmp8u) p_ptr->action = ACTION_LEARN;
2054 rd_byte((byte *)&preserve_mode);
2055 rd_byte((byte *)&p_ptr->wait_report_score);
2058 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
2060 /* Skip the flags */
2064 /* Hack -- the two "special seeds" */
2065 rd_u32b(&seed_flavor);
2066 rd_u32b(&seed_town);
2070 rd_u16b(&p_ptr->panic_save);
2071 rd_u16b(&p_ptr->total_winner);
2072 rd_u16b(&p_ptr->noscore);
2077 p_ptr->is_dead = tmp8u;
2079 /* Read "feeling" */
2080 rd_byte(&p_ptr->feeling);
2082 switch (p_ptr->start_race)
2088 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2091 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2094 dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2096 /* Turn when level began */
2099 if (h_older_than(1, 7, 0, 4))
2101 p_ptr->feeling_turn = old_turn;
2105 /* Turn of last "feeling" */
2106 rd_s32b(&p_ptr->feeling_turn);
2112 if (z_older_than(10, 3, 12))
2114 dungeon_turn = turn;
2116 else rd_s32b(&dungeon_turn);
2118 if (z_older_than(11, 0, 13))
2121 p_ptr->feeling_turn /= 2;
2126 if (z_older_than(10, 3, 13))
2130 else rd_s32b(&old_battle);
2132 if (z_older_than(10,0,3))
2134 determine_today_mon(TRUE);
2138 rd_s16b(&today_mon);
2139 rd_s16b(&p_ptr->today_mon);
2142 if (z_older_than(10,0,7))
2148 rd_s16b(&p_ptr->riding);
2151 /* Current floor_id */
2152 if (h_older_than(1, 5, 0, 0))
2154 p_ptr->floor_id = 0;
2158 rd_s16b(&p_ptr->floor_id);
2161 if (h_older_than(1, 5, 0, 2))
2167 /* Get number of party_mon array */
2170 /* Strip old temporary preserved pets */
2171 for (i = 0; i < tmp16s; i++)
2173 monster_type dummy_mon;
2175 rd_monster(&dummy_mon);
2179 if (z_older_than(10,1,2))
2188 if (z_older_than(10,3,9))
2192 else if (z_older_than(10, 3, 10))
2200 rd_s32b(&p_ptr->visit);
2202 if (!z_older_than(11, 0, 5))
2204 rd_u32b(&p_ptr->count);
2212 * Read the player inventory
2214 * Note that the inventory changed in Angband 2.7.4. Two extra
2215 * pack slots were added and the equipment was rearranged. Note
2216 * that these two features combine when parsing old save-files, in
2217 * which items from the old "aux" slot are "carried", perhaps into
2218 * one of the two new "inventory" slots.
2220 * Note that the inventory is "re-sorted" later by "dungeon()".
2222 static errr rd_inventory(void)
2230 p_ptr->total_weight = 0;
2236 /* Read until done */
2241 /* Get the next item index */
2244 /* Nope, we reached the end */
2245 if (n == 0xFFFF) break;
2247 /* Get local object */
2250 /* Wipe the object */
2256 /* Hack -- verify item */
2257 if (!q_ptr->k_idx) return (53);
2259 /* Wield equipment */
2260 if (n >= INVEN_RARM)
2262 /* Player touches it */
2263 q_ptr->marked |= OM_TOUCHED;
2266 object_copy(&inventory[n], q_ptr);
2268 /* Add the weight */
2269 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2275 /* Warning -- backpack is full */
2276 else if (inven_cnt == INVEN_PACK)
2280 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
2282 note("Too many items in the inventory!");
2290 /* Carry inventory */
2296 /* Player touches it */
2297 q_ptr->marked |= OM_TOUCHED;
2300 object_copy(&inventory[n], q_ptr);
2302 /* Add the weight */
2303 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2317 * Read the saved messages
2319 static void rd_messages(void)
2329 /* Read the messages */
2330 for (i = 0; i < num; i++)
2332 /* Read the message */
2333 rd_string(buf, sizeof(buf));
2335 /* Save the message */
2342 /* Old hidden trap flag */
2343 #define CAVE_TRAP 0x8000
2345 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2346 #define OLD_FEAT_INVIS 0x02
2347 #define OLD_FEAT_GLYPH 0x03
2348 #define OLD_FEAT_QUEST_ENTER 0x08
2349 #define OLD_FEAT_QUEST_EXIT 0x09
2350 #define OLD_FEAT_MINOR_GLYPH 0x40
2351 #define OLD_FEAT_BLDG_1 0x81
2352 #define OLD_FEAT_MIRROR 0xc3
2355 #define OLD_QUEST_WATER_CAVE 18
2357 /* Quest constants */
2358 #define QUEST_OLD_CASTLE 27
2359 #define QUEST_ROYAL_CRYPT 28
2362 * Read the dungeon (old method)
2364 * The monsters/objects must be loaded in the same order
2365 * that they were stored, since the actual indexes matter.
2367 static errr rd_dungeon_old(void)
2378 /*** Basic info ***/
2381 rd_s16b(&dun_level);
2382 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2383 else rd_byte(&dungeon_type);
2385 /* Set the base level for old versions */
2386 base_level = dun_level;
2388 rd_s16b(&base_level);
2390 rd_s16b(&num_repro);
2395 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2398 rd_s16b(&tmp16s); /* max_panel_rows */
2399 rd_s16b(&tmp16s); /* max_panel_cols */
2402 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
2410 /*** Run length decoding ***/
2412 /* Load the dungeon data */
2413 for (x = y = 0; y < ymax; )
2419 if (z_older_than(10,3,6))
2428 /* Decline invalid flags */
2429 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2432 /* Apply the RLE info */
2433 for (i = count; i > 0; i--)
2435 /* Access the cave */
2436 c_ptr = &cave[y][x];
2438 /* Extract "info" */
2448 if (++y >= ymax) break;
2454 /*** Run length decoding ***/
2456 /* Load the dungeon data */
2457 for (x = y = 0; y < ymax; )
2463 /* Apply the RLE info */
2464 for (i = count; i > 0; i--)
2466 /* Access the cave */
2467 c_ptr = &cave[y][x];
2469 /* Extract "feat" */
2470 c_ptr->feat = (s16b)tmp8u;
2479 if (++y >= ymax) break;
2484 /*** Run length decoding ***/
2486 /* Load the dungeon data */
2487 for (x = y = 0; y < ymax; )
2493 /* Apply the RLE info */
2494 for (i = count; i > 0; i--)
2496 /* Access the cave */
2497 c_ptr = &cave[y][x];
2499 /* Extract "mimic" */
2500 c_ptr->mimic = (s16b)tmp8u;
2509 if (++y >= ymax) break;
2514 /*** Run length decoding ***/
2516 /* Load the dungeon data */
2517 for (x = y = 0; y < ymax; )
2523 /* Apply the RLE info */
2524 for (i = count; i > 0; i--)
2526 /* Access the cave */
2527 c_ptr = &cave[y][x];
2529 /* Extract "feat" */
2530 c_ptr->special = tmp16s;
2539 if (++y >= ymax) break;
2544 /* Convert cave data */
2545 if (z_older_than(11, 0, 99))
2547 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2549 /* Wipe old unused flags */
2550 cave[y][x].info &= ~(CAVE_MASK);
2554 if (h_older_than(1, 1, 1, 0))
2556 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2558 /* Access the cave */
2559 c_ptr = &cave[y][x];
2562 if (c_ptr->feat == OLD_FEAT_INVIS)
2564 c_ptr->feat = feat_floor;
2565 c_ptr->info |= CAVE_TRAP;
2568 /* Older than 1.1.1 */
2569 if (c_ptr->feat == OLD_FEAT_MIRROR)
2571 c_ptr->feat = feat_floor;
2572 c_ptr->info |= CAVE_OBJECT;
2577 if (h_older_than(1, 3, 1, 0))
2579 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2581 /* Access the cave */
2582 c_ptr = &cave[y][x];
2584 /* Old CAVE_IN_MIRROR flag */
2585 if (c_ptr->info & CAVE_OBJECT)
2587 c_ptr->mimic = feat_mirror;
2590 /* Runes will be mimics and flags */
2591 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2592 (c_ptr->feat == OLD_FEAT_GLYPH))
2594 c_ptr->info |= CAVE_OBJECT;
2595 c_ptr->mimic = c_ptr->feat;
2596 c_ptr->feat = feat_floor;
2599 /* Hidden traps will be trap terrains mimicing floor */
2600 else if (c_ptr->info & CAVE_TRAP)
2602 c_ptr->info &= ~CAVE_TRAP;
2603 c_ptr->mimic = c_ptr->feat;
2604 c_ptr->feat = choose_random_trap();
2607 /* Another hidden trap */
2608 else if (c_ptr->feat == OLD_FEAT_INVIS)
2610 c_ptr->mimic = feat_floor;
2611 c_ptr->feat = feat_trap_open;
2616 /* Quest 18 was removed */
2617 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2619 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2621 /* Access the cave */
2622 c_ptr = &cave[y][x];
2624 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2626 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2628 c_ptr->feat = feat_tree;
2631 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2633 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2636 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2637 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2639 c_ptr->feat = feat_up_stair;
2647 /* Read the item count */
2650 /* Verify maximum */
2651 if (limit > max_o_idx)
2654 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2656 note(format("Too many (%d) object entries!", limit));
2662 /* Read the dungeon items */
2663 for (i = 1; i < limit; i++)
2670 /* Get a new record */
2677 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2679 note(format("Object allocation error (%d <> %d)", i, o_idx));
2687 o_ptr = &o_list[o_idx];
2693 /* XXX XXX XXX XXX XXX */
2696 if (o_ptr->held_m_idx)
2698 monster_type *m_ptr;
2701 m_ptr = &m_list[o_ptr->held_m_idx];
2704 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2706 /* Place the object */
2707 m_ptr->hold_o_idx = o_idx;
2713 /* Access the item location */
2714 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2717 o_ptr->next_o_idx = c_ptr->o_idx;
2719 /* Place the object */
2720 c_ptr->o_idx = o_idx;
2727 /* Read the monster count */
2730 /* Hack -- verify */
2731 if (limit > max_m_idx)
2734 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2736 note(format("Too many (%d) monster entries!", limit));
2742 /* Read the monsters */
2743 for (i = 1; i < limit; i++)
2746 monster_type *m_ptr;
2748 /* Get a new record */
2755 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2757 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2764 /* Acquire monster */
2765 m_ptr = &m_list[m_idx];
2767 /* Read the monster */
2772 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2774 /* Mark the location */
2775 c_ptr->m_idx = m_idx;
2778 real_r_ptr(m_ptr)->cur_num++;
2783 /* The dungeon is ready */
2784 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2785 character_dungeon = FALSE;
2787 character_dungeon = TRUE;
2796 * Read the saved floor
2798 * The monsters/objects must be loaded in the same order
2799 * that they were stored, since the actual indexes matter.
2801 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2813 cave_template_type *templates;
2816 /*** Wipe all cave ***/
2820 /*** Basic info ***/
2822 /* Dungeon floor specific info follows */
2826 /*** Not a saved floor ***/
2828 rd_s16b(&dun_level);
2829 base_level = dun_level;
2833 /*** The saved floor ***/
2836 if (tmp16s != sf_ptr->floor_id) return 171;
2839 if (tmp8u != sf_ptr->savefile_id) return 171;
2842 if (tmp16s != sf_ptr->dun_level) return 171;
2843 dun_level = sf_ptr->dun_level;
2846 if (tmp32s != sf_ptr->last_visit) return 171;
2849 if (tmp32u != sf_ptr->visit_mark) return 171;
2852 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2855 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2858 rd_s16b(&base_level);
2859 rd_s16b(&num_repro);
2870 rd_byte(&p_ptr->feeling);
2874 /*** Read template for cave_type ***/
2876 /* Read the template count */
2879 /* Allocate the "template" array */
2880 C_MAKE(templates, limit, cave_template_type);
2882 /* Read the templates */
2883 for (i = 0; i < limit; i++)
2885 cave_template_type *ct_ptr = &templates[i];
2888 rd_u16b(&ct_ptr->info);
2889 if (h_older_than(1, 7, 0, 2))
2892 ct_ptr->feat = (s16b)tmp8u;
2894 ct_ptr->mimic = (s16b)tmp8u;
2898 rd_s16b(&ct_ptr->feat);
2899 rd_s16b(&ct_ptr->mimic);
2901 rd_s16b(&ct_ptr->special);
2909 /*** Run length decoding ***/
2911 /* Load the dungeon data */
2912 for (x = y = 0; y < ymax; )
2924 } while (tmp8u == MAX_UCHAR);
2926 /* Apply the RLE info */
2927 for (i = count; i > 0; i--)
2929 /* Access the cave */
2930 cave_type *c_ptr = &cave[y][x];
2932 /* Extract cave data */
2933 c_ptr->info = templates[id].info;
2934 c_ptr->feat = templates[id].feat;
2935 c_ptr->mimic = templates[id].mimic;
2936 c_ptr->special = templates[id].special;
2945 if (++y >= ymax) break;
2950 /* Quest 18 was removed */
2951 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2953 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2955 /* Access the cave */
2956 cave_type *c_ptr = &cave[y][x];
2958 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2960 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2962 c_ptr->feat = feat_tree;
2965 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2967 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2970 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2971 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2973 c_ptr->feat = feat_up_stair;
2979 /* Free the "template" array */
2980 C_KILL(templates, limit, cave_template_type);
2985 /* Read the item count */
2988 /* Verify maximum */
2989 if (limit > max_o_idx) return 151;
2992 /* Read the dungeon items */
2993 for (i = 1; i < limit; i++)
2999 /* Get a new record */
3003 if (i != o_idx) return 152;
3006 o_ptr = &o_list[o_idx];
3013 if (o_ptr->held_m_idx)
3015 monster_type *m_ptr;
3018 m_ptr = &m_list[o_ptr->held_m_idx];
3021 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3023 /* Place the object */
3024 m_ptr->hold_o_idx = o_idx;
3030 /* Access the item location */
3031 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3034 o_ptr->next_o_idx = c_ptr->o_idx;
3036 /* Place the object */
3037 c_ptr->o_idx = o_idx;
3044 /* Read the monster count */
3047 /* Hack -- verify */
3048 if (limit > max_m_idx) return 161;
3050 /* Read the monsters */
3051 for (i = 1; i < limit; i++)
3055 monster_type *m_ptr;
3057 /* Get a new record */
3061 if (i != m_idx) return 162;
3064 /* Acquire monster */
3065 m_ptr = &m_list[m_idx];
3067 /* Read the monster */
3072 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3074 /* Mark the location */
3075 c_ptr->m_idx = m_idx;
3078 real_r_ptr(m_ptr)->cur_num++;
3087 * Read the dungeon (new method)
3089 * The monsters/objects must be loaded in the same order
3090 * that they were stored, since the actual indexes matter.
3092 static errr rd_dungeon(void)
3098 /* Initialize saved_floors array and temporal files */
3099 init_saved_floors(FALSE);
3102 if (h_older_than(1, 5, 0, 0))
3104 err = rd_dungeon_old();
3106 /* Prepare floor_id of current floor */
3109 p_ptr->floor_id = get_new_floor_id();
3110 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3119 /* Number of floor_id used from birth */
3120 rd_s16b(&max_floor_id);
3122 /* Current dungeon type */
3123 rd_byte(&dungeon_type);
3126 /* Number of the saved_floors array elements */
3129 /*** No saved floor (On the surface etc.) ***/
3132 /* Read the current floor data */
3133 err = rd_saved_floor(NULL);
3136 /*** In the dungeon ***/
3140 /* Read the saved_floors array */
3141 for (i = 0; i < num; i++)
3143 saved_floor_type *sf_ptr = &saved_floors[i];
3145 rd_s16b(&sf_ptr->floor_id);
3146 rd_byte(&sf_ptr->savefile_id);
3147 rd_s16b(&sf_ptr->dun_level);
3148 rd_s32b(&sf_ptr->last_visit);
3149 rd_u32b(&sf_ptr->visit_mark);
3150 rd_s16b(&sf_ptr->upper_floor_id);
3151 rd_s16b(&sf_ptr->lower_floor_id);
3155 /* Move saved floors data to temporal files */
3156 for (i = 0; i < num; i++)
3158 saved_floor_type *sf_ptr = &saved_floors[i];
3161 /* Unused element */
3162 if (!sf_ptr->floor_id) continue;
3164 /* Read the failure mark */
3166 if (tmp8u) continue;
3168 /* Read from the save file */
3169 err = rd_saved_floor(sf_ptr);
3174 /* Re-save as temporal saved floor file */
3175 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3181 /* Finally load current floor data from temporal file */
3184 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3189 /*** Error messages ***/
3194 note("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
3196 note("Too many object entries!");
3202 note("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼");
3204 note("Object allocation error");
3210 note("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
3212 note("Too many monster entries!");
3218 note("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼");
3220 note("Monster allocation error");
3226 note("Êݸ¤µ¤ì¤¿¥Õ¥í¥¢¤Î¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡ª");
3228 note("Dungeon data of saved floors are broken!");
3234 note("¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
3236 note("Failed to make temporal files!");
3249 /* The dungeon is ready */
3250 character_dungeon = TRUE;
3252 /* Success or Error */
3258 * Actually read the savefile
3260 static errr rd_savefile_new_aux(void)
3272 #ifdef VERIFY_CHECKSUMS
3273 u32b n_x_check, n_v_check;
3274 u32b o_x_check, o_v_check;
3278 /* Mention the savefile version */
3281 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
3283 "Loading a %d.%d.%d savefile...",
3285 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
3288 /* Strip the version bytes */
3291 /* Hack -- decrypt */
3292 xor_byte = sf_extra;
3295 /* Clear the checksums */
3299 /* Read the version number of the savefile */
3300 /* Old savefile will be version 0.0.0.3 */
3301 rd_byte(&h_ver_extra);
3302 rd_byte(&h_ver_patch);
3303 rd_byte(&h_ver_minor);
3304 rd_byte(&h_ver_major);
3306 /* Operating system info */
3307 rd_u32b(&sf_system);
3309 /* Time of savefile creation */
3312 /* Number of resurrections */
3315 /* Number of times played */
3319 /* Later use (always zero) */
3322 /* Later use (always zero) */
3325 /* Later use (always zero) */
3329 rd_byte(&kanji_code);
3331 /* Read RNG state */
3334 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3336 if (arg_fiddle) note("Loaded Randomizer Info");
3341 /* Then the options */
3344 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3346 if (arg_fiddle) note("Loaded Option Flags");
3349 /* Then the "messages" */
3352 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3354 if (arg_fiddle) note("Loaded Messages");
3359 for (i = 0; i < max_r_idx; i++)
3361 /* Access that monster */
3362 monster_race *r_ptr = &r_info[i];
3364 /* Hack -- Reset the death counter */
3365 r_ptr->max_num = 100;
3367 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3369 /* Hack -- Non-unique Nazguls are semi-unique */
3370 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3373 /* Monster Memory */
3376 /* Incompatible save files */
3377 if (tmp16u > max_r_idx)
3380 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3382 note(format("Too many (%u) monster races!", tmp16u));
3388 /* Read the available records */
3389 for (i = 0; i < tmp16u; i++)
3396 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3398 if (arg_fiddle) note("Loaded Monster Memory");
3406 /* Incompatible save files */
3407 if (tmp16u > max_k_idx)
3410 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3412 note(format("Too many (%u) object kinds!", tmp16u));
3418 /* Read the object memory */
3419 for (i = 0; i < tmp16u; i++)
3422 object_kind *k_ptr = &k_info[i];
3426 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3427 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3430 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3432 if (arg_fiddle) note("Loaded Object Memory");
3436 /* Init the wilderness seeds */
3437 for (i = 0; i < max_wild_x; i++)
3439 for (j = 0; j < max_wild_y; j++)
3441 wilderness[j][i].seed = randint0(0x10000000);
3445 /* 2.1.3 or newer version */
3447 u16b max_towns_load;
3448 u16b max_quests_load;
3449 byte max_rquests_load;
3450 s16b old_inside_quest = p_ptr->inside_quest;
3452 /* Number of towns */
3453 rd_u16b(&max_towns_load);
3455 /* Incompatible save files */
3456 if (max_towns_load > max_towns)
3459 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
3461 note(format("Too many (%u) towns!", max_towns_load));
3467 /* Number of quests */
3468 rd_u16b(&max_quests_load);
3470 if (z_older_than(11, 0, 7))
3472 max_rquests_load = 10;
3476 rd_byte(&max_rquests_load);
3479 /* Incompatible save files */
3480 if (max_quests_load > max_quests)
3483 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
3485 note(format("Too many (%u) quests!", max_quests_load));
3491 for (i = 0; i < max_quests_load; i++)
3495 quest_type* const q_ptr = &quest[i];
3497 rd_s16b(&q_ptr->status);
3498 rd_s16b(&q_ptr->level);
3500 if (z_older_than(11, 0, 6))
3506 rd_byte(&q_ptr->complev);
3508 if(h_older_than(2, 1, 2, 2))
3510 q_ptr->comptime = 0;
3514 rd_u32b(&q_ptr->comptime);
3517 /* Load quest status if quest is running */
3518 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3519 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3520 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3522 rd_s16b(&q_ptr->cur_num);
3523 rd_s16b(&q_ptr->max_num);
3524 rd_s16b(&q_ptr->type);
3526 /* Load quest monster index */
3527 rd_s16b(&q_ptr->r_idx);
3529 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3531 determine_random_questor(&quest[i]);
3534 /* Load quest item index */
3535 rd_s16b(&q_ptr->k_idx);
3538 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3540 rd_byte(&q_ptr->flags);
3542 if (z_older_than(10, 3, 11))
3544 if (q_ptr->flags & QUEST_FLAG_PRESET)
3550 init_flags = INIT_ASSIGN;
3551 p_ptr->inside_quest = i;
3553 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3554 p_ptr->inside_quest = old_inside_quest;
3559 rd_byte(&q_ptr->dungeon);
3562 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3563 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3564 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3567 /* Ignore the empty quests from old versions */
3570 /* Ignore quest status */
3573 /* Ignore quest level */
3577 * We don't have to care about the other info,
3578 * since status should be 0 for these quests anyway
3583 /* Quest 18 was removed */
3584 if (h_older_than(1, 7, 0, 6))
3586 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3587 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3590 /* Position in the wilderness */
3591 rd_s32b(&p_ptr->wilderness_x);
3592 rd_s32b(&p_ptr->wilderness_y);
3593 if (z_older_than(10, 3, 13))
3595 p_ptr->wilderness_x = 5;
3596 p_ptr->wilderness_y = 48;
3599 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3600 else rd_byte((byte *)&p_ptr->wild_mode);
3601 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3602 else rd_byte((byte *)&ambush_flag);
3604 /* Size of the wilderness */
3605 rd_s32b(&wild_x_size);
3606 rd_s32b(&wild_y_size);
3608 /* Incompatible save files */
3609 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3612 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
3614 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
3620 /* Load the wilderness seeds */
3621 for (i = 0; i < wild_x_size; i++)
3623 for (j = 0; j < wild_y_size; j++)
3625 rd_u32b(&wilderness[j][i].seed);
3631 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3633 if (arg_fiddle) note("Loaded Quests");
3636 /* Load the Artifacts */
3639 /* Incompatible save files */
3640 if (tmp16u > max_a_idx)
3643 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3645 note(format("Too many (%u) artifacts!", tmp16u));
3651 /* Read the artifact flags */
3652 for (i = 0; i < tmp16u; i++)
3654 artifact_type *a_ptr = &a_info[i];
3657 a_ptr->cur_num = tmp8u;
3659 if (h_older_than(1, 5, 0, 0))
3661 a_ptr->floor_id = 0;
3669 rd_s16b(&a_ptr->floor_id);
3673 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3675 if (arg_fiddle) note("Loaded Artifacts");
3680 /* Read the extra stuff */
3682 if (p_ptr->energy_need < -999) world_player = TRUE;
3685 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3687 if (arg_fiddle) note("Loaded extra information");
3691 /* Read the player_hp array */
3694 /* Incompatible save files */
3695 if (tmp16u > PY_MAX_LEVEL)
3698 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
3700 note(format("Too many (%u) hitpoint entries!", tmp16u));
3706 /* Read the player_hp array */
3707 for (i = 0; i < tmp16u; i++)
3709 rd_s16b(&p_ptr->player_hp[i]);
3712 /* Important -- Initialize the sex */
3713 sp_ptr = &sex_info[p_ptr->psex];
3715 /* Important -- Initialize the race/class */
3716 rp_ptr = &race_info[p_ptr->prace];
3717 cp_ptr = &class_info[p_ptr->pclass];
3718 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3720 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3722 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3723 do_cmd_rerate(FALSE);
3725 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3727 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3728 do_cmd_rerate(FALSE);
3730 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3732 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3733 do_cmd_rerate(FALSE);
3735 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3737 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3738 do_cmd_rerate(FALSE);
3741 /* Important -- Initialize the magic */
3742 mp_ptr = &m_info[p_ptr->pclass];
3745 /* Read spell info */
3746 rd_u32b(&p_ptr->spell_learned1);
3747 rd_u32b(&p_ptr->spell_learned2);
3748 rd_u32b(&p_ptr->spell_worked1);
3749 rd_u32b(&p_ptr->spell_worked2);
3750 rd_u32b(&p_ptr->spell_forgotten1);
3751 rd_u32b(&p_ptr->spell_forgotten2);
3753 if (z_older_than(10,0,5))
3755 p_ptr->learned_spells = 0;
3756 for (i = 0; i < 64; i++)
3758 /* Count known spells */
3760 (p_ptr->spell_learned1 & (1L << i)) :
3761 (p_ptr->spell_learned2 & (1L << (i - 32))))
3763 p_ptr->learned_spells++;
3767 else rd_s16b(&p_ptr->learned_spells);
3769 if (z_older_than(10,0,6))
3771 p_ptr->add_spells = 0;
3773 else rd_s16b(&p_ptr->add_spells);
3774 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3776 for (i = 0; i < 64; i++)
3778 rd_byte(&p_ptr->spell_order[i]);
3782 /* Read the inventory */
3786 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
3788 note("Unable to read inventory");
3794 /* Read number of towns */
3796 town_count = tmp16u;
3798 /* Read the stores */
3800 for (i = 1; i < town_count; i++)
3802 for (j = 0; j < tmp16u; j++)
3804 if (rd_store(i, j)) return (22);
3808 rd_s16b(&p_ptr->pet_follow_distance);
3809 if (z_older_than(10, 4, 10))
3811 p_ptr->pet_extra_flags = 0;
3813 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3815 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3817 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3821 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3824 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3828 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3831 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3835 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3838 if (!z_older_than(10,0,8))
3841 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3846 rd_s16b(&p_ptr->pet_extra_flags);
3849 if (!z_older_than(11, 0, 9))
3851 char buf[SCREEN_BUF_SIZE];
3852 rd_string(buf, sizeof(buf));
3853 if (buf[0]) screen_dump = string_make(buf);
3858 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3860 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3865 /* I'm not dead yet... */
3866 if (!p_ptr->is_dead)
3868 /* Dead players have no dungeon */
3870 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
3872 note("Restoring Dungeon...");
3878 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
3880 note("Error reading dungeon data");
3886 /* Read the ghost info */
3893 strip_bytes(tmp32s);
3897 /* Quest 18 was removed */
3898 if (h_older_than(1, 7, 0, 6))
3900 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3902 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3904 p_ptr->inside_quest = 0;
3909 #ifdef VERIFY_CHECKSUMS
3911 /* Save the checksum */
3912 n_v_check = v_check;
3914 /* Read the old checksum */
3915 rd_u32b(&o_v_check);
3918 if (o_v_check != n_v_check)
3921 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3923 note("Invalid checksum");
3930 /* Save the encoded checksum */
3931 n_x_check = x_check;
3933 /* Read the checksum */
3934 rd_u32b(&o_x_check);
3938 if (o_x_check != n_x_check)
3941 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3943 note("Invalid encoded checksum");
3957 * Actually read the savefile
3959 errr rd_savefile_new(void)
3963 /* Grab permissions */
3966 /* The savefile is a binary file */
3967 fff = my_fopen(savefile, "rb");
3969 /* Drop permissions */
3973 if (!fff) return (-1);
3975 /* Call the sub-function */
3976 err = rd_savefile_new_aux();
3978 /* Check for errors */
3979 if (ferror(fff)) err = -1;
3981 /* Close the file */
3990 * Actually load and verify a floor save data
3992 static bool load_floor_aux(saved_floor_type *sf_ptr)
3997 #ifdef VERIFY_CHECKSUMS
3998 u32b n_x_check, n_v_check;
3999 u32b o_x_check, o_v_check;
4002 /* Hack -- decrypt (read xor_byte) */
4006 /* Clear the checksums */
4010 /* Set the version number to current version */
4011 /* Never load old temporal files */
4012 h_ver_extra = H_VER_EXTRA;
4013 h_ver_patch = H_VER_PATCH;
4014 h_ver_minor = H_VER_MINOR;
4015 h_ver_major = H_VER_MAJOR;
4017 /* Verify the sign */
4019 if (saved_floor_file_sign != tmp32u) return FALSE;
4021 /* Read -- have error? */
4022 if (rd_saved_floor(sf_ptr)) return FALSE;
4025 #ifdef VERIFY_CHECKSUMS
4026 /* Save the checksum */
4027 n_v_check = v_check;
4029 /* Read the old checksum */
4030 rd_u32b(&o_v_check);
4033 if (o_v_check != n_v_check) return FALSE;
4035 /* Save the encoded checksum */
4036 n_x_check = x_check;
4038 /* Read the checksum */
4039 rd_u32b(&o_x_check);
4042 if (o_x_check != n_x_check) return FALSE;
4051 * Attempt to load the temporally saved-floor data
4053 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
4055 FILE *old_fff = NULL;
4056 byte old_xor_byte = 0;
4057 u32b old_v_check = 0;
4058 u32b old_x_check = 0;
4059 byte old_h_ver_major = 0;
4060 byte old_h_ver_minor = 0;
4061 byte old_h_ver_patch = 0;
4062 byte old_h_ver_extra = 0;
4065 char floor_savefile[1024];
4067 byte old_kanji_code = kanji_code;
4070 * Temporal files are always written in system depended kanji
4075 /* EUC kanji code */
4079 /* SJIS kanji code */
4088 /* We have one file already opened */
4089 if (mode & SLF_SECOND)
4091 /* Backup original values */
4093 old_xor_byte = xor_byte;
4094 old_v_check = v_check;
4095 old_x_check = x_check;
4096 old_h_ver_major = h_ver_major;
4097 old_h_ver_minor = h_ver_minor;
4098 old_h_ver_patch = h_ver_patch;
4099 old_h_ver_extra = h_ver_extra;
4102 /* floor savefile */
4103 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4105 /* Grab permissions */
4108 /* The savefile is a binary file */
4109 fff = my_fopen(floor_savefile, "rb");
4111 /* Drop permissions */
4115 if (!fff) ok = FALSE;
4117 /* Attempt to load */
4120 /* Load saved floor data from file */
4121 ok = load_floor_aux(sf_ptr);
4123 /* Check for errors */
4124 if (ferror(fff)) ok = FALSE;
4126 /* Close the file */
4129 /* Grab permissions */
4132 /* Delete the file */
4133 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4135 /* Drop permissions */
4139 /* We have one file already opened */
4140 if (mode & SLF_SECOND)
4142 /* Restore original values */
4144 xor_byte = old_xor_byte;
4145 v_check = old_v_check;
4146 x_check = old_x_check;
4147 h_ver_major = old_h_ver_major;
4148 h_ver_minor = old_h_ver_minor;
4149 h_ver_patch = old_h_ver_patch;
4150 h_ver_extra = old_h_ver_extra;
4153 /* Restore old knowledge */
4154 kanji_code = old_kanji_code;