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); 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;
667 * Read a monster (Old method)
669 static void rd_monster_old(monster_type *m_ptr)
674 /* Read the monster race */
675 rd_s16b(&m_ptr->r_idx);
677 if (z_older_than(11, 0, 12))
678 m_ptr->ap_r_idx = m_ptr->r_idx;
680 rd_s16b(&m_ptr->ap_r_idx);
682 if (z_older_than(11, 0, 14))
684 monster_race *r_ptr = &r_info[m_ptr->r_idx];
686 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
687 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
688 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
691 rd_byte(&m_ptr->sub_align);
693 /* Read the other information */
697 rd_s16b(&m_ptr->maxhp);
698 if (z_older_than(11, 0, 5))
700 m_ptr->max_maxhp = m_ptr->maxhp;
704 rd_s16b(&m_ptr->max_maxhp);
706 rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
707 rd_byte(&m_ptr->mspeed);
708 if (z_older_than(10, 4, 2))
711 m_ptr->energy_need = (s16b)tmp8u;
713 else rd_s16b(&m_ptr->energy_need);
715 if (z_older_than(11, 0, 13))
716 m_ptr->energy_need = 100 - m_ptr->energy_need;
718 if (z_older_than(10,0,7))
720 m_ptr->mtimed[MTIMED_FAST] = 0;
721 m_ptr->mtimed[MTIMED_SLOW] = 0;
726 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
728 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
731 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
733 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
735 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
737 if (z_older_than(10,0,10))
741 else if (z_older_than(10,0,11))
749 rd_s16b(&m_ptr->target_y);
750 rd_s16b(&m_ptr->target_x);
754 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
756 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
757 rd_u32b(&m_ptr->smart);
761 if (z_older_than(10, 4, 5))
764 rd_u32b(&m_ptr->exp);
766 if (z_older_than(10, 2, 2))
768 if (m_ptr->r_idx < 0)
770 m_ptr->r_idx = (0-m_ptr->r_idx);
771 m_ptr->mflag2 |= MFLAG2_KAGE;
776 rd_byte(&m_ptr->mflag2);
779 if (z_older_than(11, 0, 12))
781 if (m_ptr->mflag2 & MFLAG2_KAGE)
782 m_ptr->ap_r_idx = MON_KAGE;
785 if (z_older_than(10, 1, 3))
791 rd_string(buf, sizeof(buf));
792 if (buf[0]) m_ptr->nickname = quark_add(buf);
800 * Read a monster (New method)
802 static void rd_monster(monster_type *m_ptr)
808 if (h_older_than(1, 5, 0, 0))
810 rd_monster_old(m_ptr);
814 /*** Monster save flags ***/
817 /*** Read un-obvious elements ***/
819 /* Read the monster race */
820 rd_s16b(&m_ptr->r_idx);
822 /* Read the other information */
826 rd_s16b(&m_ptr->maxhp);
827 rd_s16b(&m_ptr->max_maxhp);
829 /* Monster race index of its appearance */
830 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
831 else m_ptr->ap_r_idx = m_ptr->r_idx;
833 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
834 else m_ptr->sub_align = 0;
836 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
837 else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
839 rd_byte(&m_ptr->mspeed);
841 rd_s16b(&m_ptr->energy_need);
843 if (flags & SAVE_MON_FAST)
846 m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
848 else m_ptr->mtimed[MTIMED_FAST] = 0;
849 if (flags & SAVE_MON_SLOW)
852 m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
854 else m_ptr->mtimed[MTIMED_SLOW] = 0;
855 if (flags & SAVE_MON_STUNNED)
858 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
860 else m_ptr->mtimed[MTIMED_STUNNED] = 0;
861 if (flags & SAVE_MON_CONFUSED)
864 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
866 else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
867 if (flags & SAVE_MON_MONFEAR)
870 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
872 else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
874 if (flags & SAVE_MON_TARGET_Y) rd_s16b(&m_ptr->target_y);
875 else m_ptr->target_y = 0;
876 if (flags & SAVE_MON_TARGET_X) rd_s16b(&m_ptr->target_x);
877 else m_ptr->target_x = 0;
879 if (flags & SAVE_MON_INVULNER)
882 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
884 else m_ptr->mtimed[MTIMED_INVULNER] = 0;
886 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
887 else m_ptr->smart = 0;
889 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
892 m_ptr->mflag = 0; /* Not saved */
894 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
895 else m_ptr->mflag2 = 0;
897 if (flags & SAVE_MON_NICKNAME)
899 rd_string(buf, sizeof(buf));
900 m_ptr->nickname = quark_add(buf);
902 else m_ptr->nickname = 0;
904 if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
905 else m_ptr->parent_m_idx = 0;
910 * Old monster bit flags of racial resistances
912 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
913 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
914 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
915 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
916 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
917 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
918 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
919 #define RF3_RES_WATE 0x00800000 /* Resist water */
920 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
921 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
922 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
923 #define RF3_RES_ALL 0x08000000 /* Resist all */
925 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
927 if ((R_PTR)->r_flags3 & (RF3)) \
929 (R_PTR)->r_flags3 &= ~(RF3); \
930 (R_PTR)->r_flagsr |= (RFR); \
934 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
936 if ((R_PTR)->r_flags4 & (RF4_BR)) \
938 (R_PTR)->r_flagsr |= (RFR); \
942 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
943 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
944 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
945 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
946 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
947 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
948 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
949 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
950 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
951 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
953 * Read the monster lore
955 static void rd_lore(int r_idx)
959 monster_race *r_ptr = &r_info[r_idx];
961 /* Count sights/deaths/kills */
962 rd_s16b(&r_ptr->r_sights);
963 rd_s16b(&r_ptr->r_deaths);
964 rd_s16b(&r_ptr->r_pkills);
965 if (h_older_than(1, 7, 0, 5))
967 r_ptr->r_akills = r_ptr->r_pkills;
971 rd_s16b(&r_ptr->r_akills);
973 rd_s16b(&r_ptr->r_tkills);
975 /* Count wakes and ignores */
976 rd_byte(&r_ptr->r_wake);
977 rd_byte(&r_ptr->r_ignore);
980 rd_byte(&r_ptr->r_xtra1);
981 rd_byte(&r_ptr->r_xtra2);
984 rd_byte(&r_ptr->r_drop_gold);
985 rd_byte(&r_ptr->r_drop_item);
989 rd_byte(&r_ptr->r_cast_spell);
991 /* Count blows of each type */
992 rd_byte(&r_ptr->r_blows[0]);
993 rd_byte(&r_ptr->r_blows[1]);
994 rd_byte(&r_ptr->r_blows[2]);
995 rd_byte(&r_ptr->r_blows[3]);
998 rd_u32b(&r_ptr->r_flags1);
999 rd_u32b(&r_ptr->r_flags2);
1000 rd_u32b(&r_ptr->r_flags3);
1001 rd_u32b(&r_ptr->r_flags4);
1002 rd_u32b(&r_ptr->r_flags5);
1003 rd_u32b(&r_ptr->r_flags6);
1004 if (h_older_than(1, 5, 0, 3))
1006 r_ptr->r_flagsr = 0L;
1008 /* Move RF3 resistance flags to RFR */
1009 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
1010 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
1011 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
1012 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
1013 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
1014 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
1015 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
1016 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
1017 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
1018 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
1019 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
1020 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
1022 /* Separate breathers resistance from RF4 to RFR */
1023 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
1024 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
1025 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
1026 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
1027 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
1028 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
1029 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
1030 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
1031 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
1033 /* Resist confusion is merged to RF3_NO_CONF */
1034 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
1036 /* Misc resistance hack to RFR */
1037 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
1038 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
1042 rd_u32b(&r_ptr->r_flagsr);
1045 /* Read the "Racial" monster limit per level */
1046 rd_byte(&r_ptr->max_num);
1048 /* Location in saved floor */
1049 rd_s16b(&r_ptr->floor_id);
1054 /* Repair the lore flags */
1055 r_ptr->r_flags1 &= r_ptr->flags1;
1056 r_ptr->r_flags2 &= r_ptr->flags2;
1057 r_ptr->r_flags3 &= r_ptr->flags3;
1058 r_ptr->r_flags4 &= r_ptr->flags4;
1059 r_ptr->r_flags5 &= r_ptr->flags5;
1060 r_ptr->r_flags6 &= r_ptr->flags6;
1061 r_ptr->r_flagsr &= r_ptr->flagsr;
1068 * Add the item "o_ptr" to the inventory of the "Home"
1070 * In all cases, return the slot (or -1) where the object was placed
1072 * Note that this is a hacked up version of "inven_carry()".
1074 * Also note that it may not correctly "adapt" to "knowledge" bacoming
1075 * known, the player may have to pick stuff up and drop it again.
1077 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1085 /* Check each existing item (try to combine) */
1086 for (slot = 0; slot < st_ptr->stock_num; slot++)
1088 /* Get the existing item */
1089 j_ptr = &st_ptr->stock[slot];
1091 /* The home acts just like the player */
1092 if (object_similar(j_ptr, o_ptr))
1094 /* Save the new number of items */
1095 object_absorb(j_ptr, o_ptr);
1103 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1107 /* Determine the "value" of the item */
1108 value = object_value(o_ptr);
1110 /* Check existing slots to see if we must "slide" */
1111 for (slot = 0; slot < st_ptr->stock_num; slot++)
1113 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1116 /* Slide the others up */
1117 for (i = st_ptr->stock_num; i > slot; i--)
1119 st_ptr->stock[i] = st_ptr->stock[i-1];
1122 /* More stuff now */
1123 st_ptr->stock_num++;
1125 /* Insert the new item */
1126 st_ptr->stock[slot] = *o_ptr;
1128 chg_virtue(V_SACRIFICE, -1);
1130 /* Return the location */
1138 static errr rd_store(int town_number, int store_number)
1150 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1152 st_ptr = &town[1].store[store_number];
1153 if (st_ptr->stock_num) sort = TRUE;
1157 st_ptr = &town[town_number].store[store_number];
1160 /* Read the basic info */
1161 rd_s32b(&st_ptr->store_open);
1162 rd_s16b(&st_ptr->insult_cur);
1164 if (z_older_than(11, 0, 4))
1173 rd_s16b(&st_ptr->good_buy);
1174 rd_s16b(&st_ptr->bad_buy);
1176 /* Read last visit */
1177 rd_s32b(&st_ptr->last_visit);
1179 /* Extract the owner (see above) */
1180 st_ptr->owner = own;
1182 /* Read the items */
1183 for (j = 0; j < num; j++)
1188 /* Get local object */
1191 /* Wipe the object */
1197 /* Acquire valid items */
1198 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1203 home_carry(st_ptr, q_ptr);
1207 k = st_ptr->stock_num++;
1209 /* Acquire the item */
1210 object_copy(&st_ptr->stock[k], q_ptr);
1222 * Read RNG state (added in 2.8.0)
1224 static void rd_randomizer(void)
1234 rd_u16b(&Rand_place);
1237 for (i = 0; i < RAND_DEG; i++)
1239 rd_u32b(&Rand_state[i]);
1249 * Read options (ignore most pre-2.8.0 options)
1251 * Note that the normal options are now stored as a set of 256 bit flags,
1252 * plus a set of 256 bit masks to indicate which bit flags were defined
1253 * at the time the savefile was created. This will allow new options
1254 * to be added, and old options to be removed, at any time, without
1255 * hurting old savefiles.
1257 * The window options are stored in the same way, but note that each
1258 * window gets 32 options, and their order is fixed by certain defines.
1260 static void rd_options(void)
1274 /* Ignore old options */
1278 /*** Special info */
1280 /* Read "delay_factor" */
1284 /* Read "hitpoint_warn" */
1288 /* Read "mana_warn" */
1289 if(h_older_than(1, 7, 0, 0))
1300 /*** Cheating options ***/
1304 if (c & 0x0002) p_ptr->wizard = TRUE;
1306 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1307 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1308 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1309 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1310 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1311 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1312 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1314 rd_byte((byte *)&autosave_l);
1315 rd_byte((byte *)&autosave_t);
1316 rd_s16b(&autosave_freq);
1319 /*** Normal Options ***/
1321 /* Read the option flags */
1322 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1324 /* Read the option masks */
1325 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1327 /* Analyze the options */
1328 for (n = 0; n < 8; n++)
1330 /* Analyze the options */
1331 for (i = 0; i < 32; i++)
1333 /* Process valid flags */
1334 if (mask[n] & (1L << i))
1336 /* Process valid flags */
1337 if (option_mask[n] & (1L << i))
1340 if (flag[n] & (1L << i))
1343 option_flag[n] |= (1L << i);
1350 option_flag[n] &= ~(1L << i);
1357 if (z_older_than(10, 4, 5))
1359 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1360 else option_flag[5] |= (0x00000001 << 4);
1361 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1362 else option_flag[2] |= (0x00000001 << 5);
1363 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1364 else option_flag[4] |= (0x00000001 << 5);
1365 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1366 else option_flag[5] |= (0x00000001 << 0);
1367 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1368 else option_flag[5] |= (0x00000001 << 12);
1369 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1370 else option_flag[1] |= (0x00000001 << 0);
1371 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1372 else option_flag[1] |= (0x00000001 << 18);
1373 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1374 else option_flag[1] |= (0x00000001 << 19);
1375 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1376 else option_flag[5] |= (0x00000001 << 3);
1379 /* Extract the options */
1380 extract_option_vars();
1383 /*** Window Options ***/
1385 /* Read the window flags */
1386 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1388 /* Read the window masks */
1389 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1391 /* Analyze the options */
1392 for (n = 0; n < 8; n++)
1394 /* Analyze the options */
1395 for (i = 0; i < 32; i++)
1397 /* Process valid flags */
1398 if (mask[n] & (1L << i))
1400 /* Process valid flags */
1401 if (window_mask[n] & (1L << i))
1404 if (flag[n] & (1L << i))
1407 window_flag[n] |= (1L << i);
1414 window_flag[n] &= ~(1L << i);
1427 * Hack -- strip the "ghost" info
1429 * XXX XXX XXX This is such a nasty hack it hurts.
1431 static void rd_ghost(void)
1436 rd_string(buf, sizeof(buf));
1438 /* Strip old data */
1444 * Save quick start data
1446 static void load_quick_start(void)
1451 if (z_older_than(11, 0, 13))
1453 previous_char.quick_ok = FALSE;
1457 rd_byte(&previous_char.psex);
1458 rd_byte(&previous_char.prace);
1459 rd_byte(&previous_char.pclass);
1460 rd_byte(&previous_char.pseikaku);
1461 rd_byte(&previous_char.realm1);
1462 rd_byte(&previous_char.realm2);
1464 rd_s16b(&previous_char.age);
1465 rd_s16b(&previous_char.ht);
1466 rd_s16b(&previous_char.wt);
1467 rd_s16b(&previous_char.sc);
1468 rd_s32b(&previous_char.au);
1470 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1471 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1473 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1475 rd_s16b(&previous_char.chaos_patron);
1477 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1479 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1481 /* UNUSED : Was number of random quests */
1485 previous_char.quick_ok = (bool)tmp8u;
1489 * Read the "extra" information
1491 static void rd_extra(void)
1499 rd_string(player_name, sizeof(player_name));
1501 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1503 if (!h_older_than(1, 7, 0, 1))
1507 /* Read the message */
1508 rd_string(buf, sizeof buf);
1509 if (buf[0]) p_ptr->last_message = string_make(buf);
1514 for (i = 0; i < 4; i++)
1516 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1519 /* Class/Race/Seikaku/Gender/Spells */
1520 rd_byte(&p_ptr->prace);
1521 rd_byte(&p_ptr->pclass);
1522 rd_byte(&p_ptr->pseikaku);
1523 rd_byte(&p_ptr->psex);
1524 rd_byte(&p_ptr->realm1);
1525 rd_byte(&p_ptr->realm2);
1526 rd_byte(&tmp8u); /* oops */
1528 if (z_older_than(10, 4, 4))
1530 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1531 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1532 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1533 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1536 /* Special Race/Class info */
1537 rd_byte(&p_ptr->hitdie);
1538 rd_u16b(&p_ptr->expfact);
1540 /* Age/Height/Weight */
1541 rd_s16b(&p_ptr->age);
1542 rd_s16b(&p_ptr->ht);
1543 rd_s16b(&p_ptr->wt);
1545 /* Read the stat info */
1546 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1547 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1548 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1550 strip_bytes(24); /* oops */
1552 rd_s32b(&p_ptr->au);
1554 rd_s32b(&p_ptr->max_exp);
1555 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1556 else rd_s32b(&p_ptr->max_max_exp);
1557 rd_s32b(&p_ptr->exp);
1559 if (h_older_than(1, 7, 0, 3))
1562 p_ptr->exp_frac = (u32b)tmp16u;
1566 rd_u32b(&p_ptr->exp_frac);
1569 rd_s16b(&p_ptr->lev);
1571 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1572 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1574 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1576 if (z_older_than(10, 3, 6))
1577 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1579 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1580 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1581 if (z_older_than(10, 4, 1))
1583 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1584 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1586 if (z_older_than(10, 3, 14))
1588 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1589 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1593 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1594 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1595 if (h_older_than(1, 3, 0, 1))
1597 if (p_ptr->pclass == CLASS_SMITH)
1599 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1600 p_ptr->magic_num1[96] = 0;
1601 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1602 p_ptr->magic_num1[97] = 0;
1606 if (music_singing_any()) p_ptr->action = ACTION_SING;
1608 if (z_older_than(11, 0, 7))
1610 p_ptr->start_race = p_ptr->prace;
1611 p_ptr->old_race1 = 0L;
1612 p_ptr->old_race2 = 0L;
1613 p_ptr->old_realm = 0;
1617 rd_byte(&p_ptr->start_race);
1618 rd_s32b(&p_ptr->old_race1);
1619 rd_s32b(&p_ptr->old_race2);
1620 rd_s16b(&p_ptr->old_realm);
1623 if (z_older_than(10, 0, 1))
1625 for (i = 0; i < OLD_MAX_MANE; i++)
1627 p_ptr->mane_spell[i] = -1;
1628 p_ptr->mane_dam[i] = 0;
1630 p_ptr->mane_num = 0;
1632 else if (z_older_than(10, 2, 3))
1634 for (i = 0; i < OLD_MAX_MANE; i++)
1639 for (i = 0; i < MAX_MANE; i++)
1641 p_ptr->mane_spell[i] = -1;
1642 p_ptr->mane_dam[i] = 0;
1645 p_ptr->mane_num = 0;
1649 for (i = 0; i < MAX_MANE; i++)
1651 rd_s16b(&p_ptr->mane_spell[i]);
1652 rd_s16b(&p_ptr->mane_dam[i]);
1654 rd_s16b(&p_ptr->mane_num);
1657 if (z_older_than(10, 0, 3))
1659 determine_bounty_uniques();
1661 for (i = 0; i < MAX_KUBI; i++)
1663 /* Is this bounty unique already dead? */
1664 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1669 for (i = 0; i < MAX_KUBI; i++)
1671 rd_s16b(&kubi_r_idx[i]);
1675 if (z_older_than(10, 0, 3))
1681 for (i = 0; i < 4; i++)
1683 rd_s16b(&battle_mon[i]);
1684 if (z_older_than(10, 3, 4))
1687 mon_odds[i] = tmp16s;
1689 else rd_u32b(&mon_odds[i]);
1693 rd_s16b(&p_ptr->town_num);
1695 /* Read arena and rewards information */
1696 rd_s16b(&p_ptr->arena_number);
1697 if (h_older_than(1, 5, 0, 1))
1699 /* Arena loser of previous version was marked number 99 */
1700 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1703 p_ptr->inside_arena = (bool)tmp16s;
1704 rd_s16b(&p_ptr->inside_quest);
1705 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1709 p_ptr->inside_battle = (bool)tmp16s;
1711 rd_byte(&p_ptr->exit_bldg);
1714 rd_s16b(&p_ptr->oldpx);
1715 rd_s16b(&p_ptr->oldpy);
1716 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1718 /* Was p_ptr->rewards[MAX_BACT] */
1720 for (i = 0; i < tmp16s; i++)
1726 if (h_older_than(1, 7, 0, 3))
1729 p_ptr->mhp = tmp16s;
1732 p_ptr->chp = tmp16s;
1735 p_ptr->chp_frac = (u32b)tmp16u;
1739 rd_s32b(&p_ptr->mhp);
1740 rd_s32b(&p_ptr->chp);
1741 rd_u32b(&p_ptr->chp_frac);
1744 if (h_older_than(1, 7, 0, 3))
1747 p_ptr->msp = tmp16s;
1750 p_ptr->csp = tmp16s;
1753 p_ptr->csp_frac = (u32b)tmp16u;
1757 rd_s32b(&p_ptr->msp);
1758 rd_s32b(&p_ptr->csp);
1759 rd_u32b(&p_ptr->csp_frac);
1762 rd_s16b(&p_ptr->max_plv);
1763 if (z_older_than(10, 3, 8))
1765 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1769 byte max = (byte)max_d_idx;
1773 for(i = 0; i < max; i++)
1775 rd_s16b(&max_dlv[i]);
1776 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1780 /* Repair maximum player level XXX XXX XXX */
1781 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1785 rd_s16b(&p_ptr->sc);
1786 rd_s16b(&p_ptr->concent);
1788 /* Read the flags */
1789 strip_bytes(2); /* Old "rest" */
1790 rd_s16b(&p_ptr->blind);
1791 rd_s16b(&p_ptr->paralyzed);
1792 rd_s16b(&p_ptr->confused);
1793 rd_s16b(&p_ptr->food);
1794 strip_bytes(4); /* Old "food_digested" / "protection" */
1796 rd_s16b(&p_ptr->energy_need);
1797 if (z_older_than(11, 0, 13))
1798 p_ptr->energy_need = 100 - p_ptr->energy_need;
1799 if (z_older_than(12, 1, 20))
1800 p_ptr->enchant_energy_need = 0;
1802 rd_s16b(&p_ptr->enchant_energy_need);
1804 rd_s16b(&p_ptr->fast);
1805 rd_s16b(&p_ptr->slow);
1806 rd_s16b(&p_ptr->afraid);
1807 rd_s16b(&p_ptr->cut);
1808 rd_s16b(&p_ptr->stun);
1809 rd_s16b(&p_ptr->poisoned);
1810 rd_s16b(&p_ptr->image);
1811 rd_s16b(&p_ptr->protevil);
1812 rd_s16b(&p_ptr->invuln);
1813 if(z_older_than(10, 0, 0))
1816 rd_s16b(&p_ptr->ult_res);
1817 rd_s16b(&p_ptr->hero);
1818 rd_s16b(&p_ptr->shero);
1819 rd_s16b(&p_ptr->shield);
1820 rd_s16b(&p_ptr->blessed);
1821 rd_s16b(&p_ptr->tim_invis);
1822 rd_s16b(&p_ptr->word_recall);
1823 if (z_older_than(10, 3, 8))
1824 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1828 p_ptr->recall_dungeon = (byte)tmp16s;
1831 if (h_older_than(1, 5, 0, 0))
1832 p_ptr->alter_reality = 0;
1834 rd_s16b(&p_ptr->alter_reality);
1836 rd_s16b(&p_ptr->see_infra);
1837 rd_s16b(&p_ptr->tim_infra);
1838 rd_s16b(&p_ptr->oppose_fire);
1839 rd_s16b(&p_ptr->oppose_cold);
1840 rd_s16b(&p_ptr->oppose_acid);
1841 rd_s16b(&p_ptr->oppose_elec);
1842 rd_s16b(&p_ptr->oppose_pois);
1843 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1844 else rd_s16b(&p_ptr->tsuyoshi);
1846 /* Old savefiles do not have the following fields... */
1847 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1850 p_ptr->wraith_form = 0;
1851 p_ptr->resist_magic = 0;
1852 p_ptr->tim_regen = 0;
1853 p_ptr->kabenuke = 0;
1854 p_ptr->tim_stealth = 0;
1855 p_ptr->tim_levitation = 0;
1856 p_ptr->tim_sh_touki = 0;
1857 p_ptr->lightspeed = 0;
1858 p_ptr->tsubureru = 0;
1859 p_ptr->tim_res_nether = 0;
1860 p_ptr->tim_res_time = 0;
1861 p_ptr->mimic_form = 0;
1862 p_ptr->tim_mimic = 0;
1863 p_ptr->tim_sh_fire = 0;
1866 p_ptr->tim_reflect = 0;
1867 p_ptr->multishadow = 0;
1868 p_ptr->dustrobe = 0;
1870 p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
1878 rd_s16b(&p_ptr->tim_esp);
1879 rd_s16b(&p_ptr->wraith_form);
1880 rd_s16b(&p_ptr->resist_magic);
1881 rd_s16b(&p_ptr->tim_regen);
1882 rd_s16b(&p_ptr->kabenuke);
1883 rd_s16b(&p_ptr->tim_stealth);
1884 rd_s16b(&p_ptr->tim_levitation);
1885 rd_s16b(&p_ptr->tim_sh_touki);
1886 rd_s16b(&p_ptr->lightspeed);
1887 rd_s16b(&p_ptr->tsubureru);
1888 if (z_older_than(10, 4, 7))
1889 p_ptr->magicdef = 0;
1891 rd_s16b(&p_ptr->magicdef);
1892 rd_s16b(&p_ptr->tim_res_nether);
1893 if (z_older_than(10, 4, 11))
1895 p_ptr->tim_res_time = 0;
1896 p_ptr->mimic_form = 0;
1897 p_ptr->tim_mimic = 0;
1898 p_ptr->tim_sh_fire = 0;
1902 rd_s16b(&p_ptr->tim_res_time);
1903 rd_byte(&p_ptr->mimic_form);
1904 rd_s16b(&p_ptr->tim_mimic);
1905 rd_s16b(&p_ptr->tim_sh_fire);
1908 if (z_older_than(11, 0, 99))
1910 p_ptr->tim_sh_holy = 0;
1911 p_ptr->tim_eyeeye = 0;
1915 rd_s16b(&p_ptr->tim_sh_holy);
1916 rd_s16b(&p_ptr->tim_eyeeye);
1920 if ( z_older_than(11,0,3) ){
1921 p_ptr->tim_reflect=0;
1922 p_ptr->multishadow=0;
1926 rd_s16b(&p_ptr->tim_reflect);
1927 rd_s16b(&p_ptr->multishadow);
1928 rd_s16b(&p_ptr->dustrobe);
1931 rd_s16b(&p_ptr->chaos_patron);
1932 rd_u32b(&p_ptr->muta1);
1933 rd_u32b(&p_ptr->muta2);
1934 rd_u32b(&p_ptr->muta3);
1936 for (i = 0; i < 8; i++)
1937 rd_s16b(&p_ptr->virtues[i]);
1938 for (i = 0; i < 8; i++)
1939 rd_s16b(&p_ptr->vir_types[i]);
1942 /* Calc the regeneration modifier for mutations */
1943 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1945 if (z_older_than(10,0,9))
1948 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1949 p_ptr->ele_attack = 0;
1953 rd_s16b(&p_ptr->ele_attack);
1954 rd_u32b(&p_ptr->special_attack);
1956 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1957 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1958 if (z_older_than(10,0,12))
1960 p_ptr->ele_immune = 0;
1961 p_ptr->special_defense = 0;
1965 rd_s16b(&p_ptr->ele_immune);
1966 rd_u32b(&p_ptr->special_defense);
1968 rd_byte(&p_ptr->knowledge);
1971 p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
1973 rd_byte(&tmp8u); /* oops */
1974 rd_byte(&p_ptr->action);
1975 if (!z_older_than(10, 4, 3))
1978 if (tmp8u) p_ptr->action = ACTION_LEARN;
1980 rd_byte((byte *)&preserve_mode);
1981 rd_byte((byte *)&p_ptr->wait_report_score);
1984 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1986 /* Skip the flags */
1990 /* Hack -- the two "special seeds" */
1991 rd_u32b(&seed_flavor);
1992 rd_u32b(&seed_town);
1996 rd_u16b(&p_ptr->panic_save);
1997 rd_u16b(&p_ptr->total_winner);
1998 rd_u16b(&p_ptr->noscore);
2003 p_ptr->is_dead = tmp8u;
2005 /* Read "feeling" */
2006 rd_byte(&p_ptr->feeling);
2008 switch (p_ptr->start_race)
2014 turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2017 turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2020 dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
2022 /* Turn when level began */
2025 if (h_older_than(1, 7, 0, 4))
2027 p_ptr->feeling_turn = old_turn;
2031 /* Turn of last "feeling" */
2032 rd_s32b(&p_ptr->feeling_turn);
2038 if (z_older_than(10, 3, 12))
2040 dungeon_turn = turn;
2042 else rd_s32b(&dungeon_turn);
2044 if (z_older_than(11, 0, 13))
2047 p_ptr->feeling_turn /= 2;
2052 if (z_older_than(10, 3, 13))
2056 else rd_s32b(&old_battle);
2058 if (z_older_than(10,0,3))
2060 determine_today_mon(TRUE);
2064 rd_s16b(&today_mon);
2065 rd_s16b(&p_ptr->today_mon);
2068 if (z_older_than(10,0,7))
2074 rd_s16b(&p_ptr->riding);
2077 /* Current floor_id */
2078 if (h_older_than(1, 5, 0, 0))
2080 p_ptr->floor_id = 0;
2084 rd_s16b(&p_ptr->floor_id);
2087 if (h_older_than(1, 5, 0, 2))
2093 /* Get number of party_mon array */
2096 /* Strip old temporary preserved pets */
2097 for (i = 0; i < tmp16s; i++)
2099 monster_type dummy_mon;
2101 rd_monster(&dummy_mon);
2105 if (z_older_than(10,1,2))
2114 if (z_older_than(10,3,9))
2118 else if (z_older_than(10, 3, 10))
2126 rd_s32b(&p_ptr->visit);
2128 if (!z_older_than(11, 0, 5))
2130 rd_u32b(&p_ptr->count);
2138 * Read the player inventory
2140 * Note that the inventory changed in Angband 2.7.4. Two extra
2141 * pack slots were added and the equipment was rearranged. Note
2142 * that these two features combine when parsing old save-files, in
2143 * which items from the old "aux" slot are "carried", perhaps into
2144 * one of the two new "inventory" slots.
2146 * Note that the inventory is "re-sorted" later by "dungeon()".
2148 static errr rd_inventory(void)
2156 p_ptr->total_weight = 0;
2162 /* Read until done */
2167 /* Get the next item index */
2170 /* Nope, we reached the end */
2171 if (n == 0xFFFF) break;
2173 /* Get local object */
2176 /* Wipe the object */
2182 /* Hack -- verify item */
2183 if (!q_ptr->k_idx) return (53);
2185 /* Wield equipment */
2186 if (n >= INVEN_RARM)
2188 /* Player touches it */
2189 q_ptr->marked |= OM_TOUCHED;
2192 object_copy(&inventory[n], q_ptr);
2194 /* Add the weight */
2195 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2201 /* Warning -- backpack is full */
2202 else if (inven_cnt == INVEN_PACK)
2206 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
2208 note("Too many items in the inventory!");
2216 /* Carry inventory */
2222 /* Player touches it */
2223 q_ptr->marked |= OM_TOUCHED;
2226 object_copy(&inventory[n], q_ptr);
2228 /* Add the weight */
2229 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2243 * Read the saved messages
2245 static void rd_messages(void)
2255 /* Read the messages */
2256 for (i = 0; i < num; i++)
2258 /* Read the message */
2259 rd_string(buf, sizeof(buf));
2261 /* Save the message */
2268 /* Old hidden trap flag */
2269 #define CAVE_TRAP 0x8000
2271 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2272 #define OLD_FEAT_INVIS 0x02
2273 #define OLD_FEAT_GLYPH 0x03
2274 #define OLD_FEAT_QUEST_ENTER 0x08
2275 #define OLD_FEAT_QUEST_EXIT 0x09
2276 #define OLD_FEAT_MINOR_GLYPH 0x40
2277 #define OLD_FEAT_BLDG_1 0x81
2278 #define OLD_FEAT_MIRROR 0xc3
2281 #define OLD_QUEST_WATER_CAVE 18
2283 /* Quest constants */
2284 #define QUEST_OLD_CASTLE 27
2285 #define QUEST_ROYAL_CRYPT 28
2288 * Read the dungeon (old method)
2290 * The monsters/objects must be loaded in the same order
2291 * that they were stored, since the actual indexes matter.
2293 static errr rd_dungeon_old(void)
2304 /*** Basic info ***/
2307 rd_s16b(&dun_level);
2308 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2309 else rd_byte(&dungeon_type);
2311 /* Set the base level for old versions */
2312 base_level = dun_level;
2314 rd_s16b(&base_level);
2316 rd_s16b(&num_repro);
2321 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2324 rd_s16b(&tmp16s); /* max_panel_rows */
2325 rd_s16b(&tmp16s); /* max_panel_cols */
2328 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
2336 /*** Run length decoding ***/
2338 /* Load the dungeon data */
2339 for (x = y = 0; y < ymax; )
2345 if (z_older_than(10,3,6))
2354 /* Decline invalid flags */
2355 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2358 /* Apply the RLE info */
2359 for (i = count; i > 0; i--)
2361 /* Access the cave */
2362 c_ptr = &cave[y][x];
2364 /* Extract "info" */
2374 if (++y >= ymax) break;
2380 /*** Run length decoding ***/
2382 /* Load the dungeon data */
2383 for (x = y = 0; y < ymax; )
2389 /* Apply the RLE info */
2390 for (i = count; i > 0; i--)
2392 /* Access the cave */
2393 c_ptr = &cave[y][x];
2395 /* Extract "feat" */
2396 c_ptr->feat = (s16b)tmp8u;
2405 if (++y >= ymax) break;
2410 /*** Run length decoding ***/
2412 /* Load the dungeon data */
2413 for (x = y = 0; y < ymax; )
2419 /* Apply the RLE info */
2420 for (i = count; i > 0; i--)
2422 /* Access the cave */
2423 c_ptr = &cave[y][x];
2425 /* Extract "mimic" */
2426 c_ptr->mimic = (s16b)tmp8u;
2435 if (++y >= ymax) break;
2440 /*** Run length decoding ***/
2442 /* Load the dungeon data */
2443 for (x = y = 0; y < ymax; )
2449 /* Apply the RLE info */
2450 for (i = count; i > 0; i--)
2452 /* Access the cave */
2453 c_ptr = &cave[y][x];
2455 /* Extract "feat" */
2456 c_ptr->special = tmp16s;
2465 if (++y >= ymax) break;
2470 /* Convert cave data */
2471 if (z_older_than(11, 0, 99))
2473 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2475 /* Wipe old unused flags */
2476 cave[y][x].info &= ~(CAVE_MASK);
2480 if (h_older_than(1, 1, 1, 0))
2482 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2484 /* Access the cave */
2485 c_ptr = &cave[y][x];
2488 if (c_ptr->feat == OLD_FEAT_INVIS)
2490 c_ptr->feat = feat_floor;
2491 c_ptr->info |= CAVE_TRAP;
2494 /* Older than 1.1.1 */
2495 if (c_ptr->feat == OLD_FEAT_MIRROR)
2497 c_ptr->feat = feat_floor;
2498 c_ptr->info |= CAVE_OBJECT;
2503 if (h_older_than(1, 3, 1, 0))
2505 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2507 /* Access the cave */
2508 c_ptr = &cave[y][x];
2510 /* Old CAVE_IN_MIRROR flag */
2511 if (c_ptr->info & CAVE_OBJECT)
2513 c_ptr->mimic = feat_mirror;
2516 /* Runes will be mimics and flags */
2517 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2518 (c_ptr->feat == OLD_FEAT_GLYPH))
2520 c_ptr->info |= CAVE_OBJECT;
2521 c_ptr->mimic = c_ptr->feat;
2522 c_ptr->feat = feat_floor;
2525 /* Hidden traps will be trap terrains mimicing floor */
2526 else if (c_ptr->info & CAVE_TRAP)
2528 c_ptr->info &= ~CAVE_TRAP;
2529 c_ptr->mimic = c_ptr->feat;
2530 c_ptr->feat = choose_random_trap();
2533 /* Another hidden trap */
2534 else if (c_ptr->feat == OLD_FEAT_INVIS)
2536 c_ptr->mimic = feat_floor;
2537 c_ptr->feat = feat_trap_open;
2542 /* Quest 18 was removed */
2543 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2545 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2547 /* Access the cave */
2548 c_ptr = &cave[y][x];
2550 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2552 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2554 c_ptr->feat = feat_tree;
2557 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2559 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2562 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2563 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2565 c_ptr->feat = feat_up_stair;
2573 /* Read the item count */
2576 /* Verify maximum */
2577 if (limit > max_o_idx)
2580 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2582 note(format("Too many (%d) object entries!", limit));
2588 /* Read the dungeon items */
2589 for (i = 1; i < limit; i++)
2596 /* Get a new record */
2603 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2605 note(format("Object allocation error (%d <> %d)", i, o_idx));
2613 o_ptr = &o_list[o_idx];
2619 /* XXX XXX XXX XXX XXX */
2622 if (o_ptr->held_m_idx)
2624 monster_type *m_ptr;
2627 m_ptr = &m_list[o_ptr->held_m_idx];
2630 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2632 /* Place the object */
2633 m_ptr->hold_o_idx = o_idx;
2639 /* Access the item location */
2640 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2643 o_ptr->next_o_idx = c_ptr->o_idx;
2645 /* Place the object */
2646 c_ptr->o_idx = o_idx;
2653 /* Read the monster count */
2656 /* Hack -- verify */
2657 if (limit > max_m_idx)
2660 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2662 note(format("Too many (%d) monster entries!", limit));
2668 /* Read the monsters */
2669 for (i = 1; i < limit; i++)
2672 monster_type *m_ptr;
2674 /* Get a new record */
2681 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2683 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2690 /* Acquire monster */
2691 m_ptr = &m_list[m_idx];
2693 /* Read the monster */
2698 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2700 /* Mark the location */
2701 c_ptr->m_idx = m_idx;
2704 real_r_ptr(m_ptr)->cur_num++;
2709 /* The dungeon is ready */
2710 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2711 character_dungeon = FALSE;
2713 character_dungeon = TRUE;
2722 * Read the saved floor
2724 * The monsters/objects must be loaded in the same order
2725 * that they were stored, since the actual indexes matter.
2727 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2739 cave_template_type *template;
2742 /*** Wipe all cave ***/
2746 /*** Basic info ***/
2748 /* Dungeon floor specific info follows */
2752 /*** Not a saved floor ***/
2754 rd_s16b(&dun_level);
2755 base_level = dun_level;
2759 /*** The saved floor ***/
2762 if (tmp16s != sf_ptr->floor_id) return 171;
2765 if (tmp8u != sf_ptr->savefile_id) return 171;
2768 if (tmp16s != sf_ptr->dun_level) return 171;
2769 dun_level = sf_ptr->dun_level;
2772 if (tmp32s != sf_ptr->last_visit) return 171;
2775 if (tmp32u != sf_ptr->visit_mark) return 171;
2778 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2781 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2784 rd_s16b(&base_level);
2785 rd_s16b(&num_repro);
2796 rd_byte(&p_ptr->feeling);
2800 /*** Read template for cave_type ***/
2802 /* Read the template count */
2805 /* Allocate the "template" array */
2806 C_MAKE(template, limit, cave_template_type);
2808 /* Read the templates */
2809 for (i = 0; i < limit; i++)
2811 cave_template_type *ct_ptr = &template[i];
2814 rd_u16b(&ct_ptr->info);
2815 if (h_older_than(1, 7, 0, 2))
2818 ct_ptr->feat = (s16b)tmp8u;
2820 ct_ptr->mimic = (s16b)tmp8u;
2824 rd_s16b(&ct_ptr->feat);
2825 rd_s16b(&ct_ptr->mimic);
2827 rd_s16b(&ct_ptr->special);
2835 /*** Run length decoding ***/
2837 /* Load the dungeon data */
2838 for (x = y = 0; y < ymax; )
2850 } while (tmp8u == MAX_UCHAR);
2852 /* Apply the RLE info */
2853 for (i = count; i > 0; i--)
2855 /* Access the cave */
2856 cave_type *c_ptr = &cave[y][x];
2858 /* Extract cave data */
2859 c_ptr->info = template[id].info;
2860 c_ptr->feat = template[id].feat;
2861 c_ptr->mimic = template[id].mimic;
2862 c_ptr->special = template[id].special;
2871 if (++y >= ymax) break;
2876 /* Quest 18 was removed */
2877 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2879 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2881 /* Access the cave */
2882 cave_type *c_ptr = &cave[y][x];
2884 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2886 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2888 c_ptr->feat = feat_tree;
2891 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2893 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2896 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2897 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2899 c_ptr->feat = feat_up_stair;
2905 /* Free the "template" array */
2906 C_FREE(template, limit, cave_template_type);
2911 /* Read the item count */
2914 /* Verify maximum */
2915 if (limit > max_o_idx) return 151;
2918 /* Read the dungeon items */
2919 for (i = 1; i < limit; i++)
2925 /* Get a new record */
2929 if (i != o_idx) return 152;
2932 o_ptr = &o_list[o_idx];
2939 if (o_ptr->held_m_idx)
2941 monster_type *m_ptr;
2944 m_ptr = &m_list[o_ptr->held_m_idx];
2947 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2949 /* Place the object */
2950 m_ptr->hold_o_idx = o_idx;
2956 /* Access the item location */
2957 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2960 o_ptr->next_o_idx = c_ptr->o_idx;
2962 /* Place the object */
2963 c_ptr->o_idx = o_idx;
2970 /* Read the monster count */
2973 /* Hack -- verify */
2974 if (limit > max_m_idx) return 161;
2976 /* Read the monsters */
2977 for (i = 1; i < limit; i++)
2981 monster_type *m_ptr;
2983 /* Get a new record */
2987 if (i != m_idx) return 162;
2990 /* Acquire monster */
2991 m_ptr = &m_list[m_idx];
2993 /* Read the monster */
2998 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3000 /* Mark the location */
3001 c_ptr->m_idx = m_idx;
3004 real_r_ptr(m_ptr)->cur_num++;
3013 * Read the dungeon (new method)
3015 * The monsters/objects must be loaded in the same order
3016 * that they were stored, since the actual indexes matter.
3018 static errr rd_dungeon(void)
3024 /* Initialize saved_floors array and temporal files */
3025 init_saved_floors(FALSE);
3028 if (h_older_than(1, 5, 0, 0))
3030 err = rd_dungeon_old();
3032 /* Prepare floor_id of current floor */
3035 p_ptr->floor_id = get_new_floor_id();
3036 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3045 /* Number of floor_id used from birth */
3046 rd_s16b(&max_floor_id);
3048 /* Current dungeon type */
3049 rd_byte(&dungeon_type);
3052 /* Number of the saved_floors array elements */
3055 /*** No saved floor (On the surface etc.) ***/
3058 /* Read the current floor data */
3059 err = rd_saved_floor(NULL);
3062 /*** In the dungeon ***/
3066 /* Read the saved_floors array */
3067 for (i = 0; i < num; i++)
3069 saved_floor_type *sf_ptr = &saved_floors[i];
3071 rd_s16b(&sf_ptr->floor_id);
3072 rd_byte(&sf_ptr->savefile_id);
3073 rd_s16b(&sf_ptr->dun_level);
3074 rd_s32b(&sf_ptr->last_visit);
3075 rd_u32b(&sf_ptr->visit_mark);
3076 rd_s16b(&sf_ptr->upper_floor_id);
3077 rd_s16b(&sf_ptr->lower_floor_id);
3081 /* Move saved floors data to temporal files */
3082 for (i = 0; i < num; i++)
3084 saved_floor_type *sf_ptr = &saved_floors[i];
3087 /* Unused element */
3088 if (!sf_ptr->floor_id) continue;
3090 /* Read the failure mark */
3092 if (tmp8u) continue;
3094 /* Read from the save file */
3095 err = rd_saved_floor(sf_ptr);
3100 /* Re-save as temporal saved floor file */
3101 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3107 /* Finally load current floor data from temporal file */
3110 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3115 /*** Error messages ***/
3120 note("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
3122 note("Too many object entries!");
3128 note("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼");
3130 note("Object allocation error");
3136 note("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
3138 note("Too many monster entries!");
3144 note("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼");
3146 note("Monster allocation error");
3152 note("Êݸ¤µ¤ì¤¿¥Õ¥í¥¢¤Î¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡ª");
3154 note("Dungeon data of saved floors are broken!");
3160 note("¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
3162 note("Failed to make temporal files!");
3175 /* The dungeon is ready */
3176 character_dungeon = TRUE;
3178 /* Success or Error */
3184 * Actually read the savefile
3186 static errr rd_savefile_new_aux(void)
3198 #ifdef VERIFY_CHECKSUMS
3199 u32b n_x_check, n_v_check;
3200 u32b o_x_check, o_v_check;
3204 /* Mention the savefile version */
3207 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
3209 "Loading a %d.%d.%d savefile...",
3211 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
3214 /* Strip the version bytes */
3217 /* Hack -- decrypt */
3218 xor_byte = sf_extra;
3221 /* Clear the checksums */
3225 /* Read the version number of the savefile */
3226 /* Old savefile will be version 0.0.0.3 */
3227 rd_byte(&h_ver_extra);
3228 rd_byte(&h_ver_patch);
3229 rd_byte(&h_ver_minor);
3230 rd_byte(&h_ver_major);
3232 /* Operating system info */
3233 rd_u32b(&sf_system);
3235 /* Time of savefile creation */
3238 /* Number of resurrections */
3241 /* Number of times played */
3245 /* Later use (always zero) */
3248 /* Later use (always zero) */
3251 /* Later use (always zero) */
3255 rd_byte(&kanji_code);
3257 /* Read RNG state */
3260 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3262 if (arg_fiddle) note("Loaded Randomizer Info");
3267 /* Then the options */
3270 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3272 if (arg_fiddle) note("Loaded Option Flags");
3275 /* Then the "messages" */
3278 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3280 if (arg_fiddle) note("Loaded Messages");
3285 for (i = 0; i < max_r_idx; i++)
3287 /* Access that monster */
3288 monster_race *r_ptr = &r_info[i];
3290 /* Hack -- Reset the death counter */
3291 r_ptr->max_num = 100;
3293 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3295 /* Hack -- Non-unique Nazguls are semi-unique */
3296 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3299 /* Monster Memory */
3302 /* Incompatible save files */
3303 if (tmp16u > max_r_idx)
3306 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3308 note(format("Too many (%u) monster races!", tmp16u));
3314 /* Read the available records */
3315 for (i = 0; i < tmp16u; i++)
3322 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3324 if (arg_fiddle) note("Loaded Monster Memory");
3332 /* Incompatible save files */
3333 if (tmp16u > max_k_idx)
3336 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3338 note(format("Too many (%u) object kinds!", tmp16u));
3344 /* Read the object memory */
3345 for (i = 0; i < tmp16u; i++)
3348 object_kind *k_ptr = &k_info[i];
3352 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3353 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3356 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3358 if (arg_fiddle) note("Loaded Object Memory");
3362 /* Init the wilderness seeds */
3363 for (i = 0; i < max_wild_x; i++)
3365 for (j = 0; j < max_wild_y; j++)
3367 wilderness[j][i].seed = randint0(0x10000000);
3371 /* 2.1.3 or newer version */
3373 u16b max_towns_load;
3374 u16b max_quests_load;
3375 byte max_rquests_load;
3376 s16b old_inside_quest = p_ptr->inside_quest;
3378 /* Number of towns */
3379 rd_u16b(&max_towns_load);
3381 /* Incompatible save files */
3382 if (max_towns_load > max_towns)
3385 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
3387 note(format("Too many (%u) towns!", max_towns_load));
3393 /* Number of quests */
3394 rd_u16b(&max_quests_load);
3396 if (z_older_than(11, 0, 7))
3398 max_rquests_load = 10;
3402 rd_byte(&max_rquests_load);
3405 /* Incompatible save files */
3406 if (max_quests_load > max_quests)
3409 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
3411 note(format("Too many (%u) quests!", max_quests_load));
3417 for (i = 0; i < max_quests_load; i++)
3421 rd_s16b(&quest[i].status);
3422 rd_s16b(&quest[i].level);
3424 if (z_older_than(11, 0, 6))
3426 quest[i].complev = 0;
3430 rd_byte(&quest[i].complev);
3433 /* Load quest status if quest is running */
3434 if ((quest[i].status == QUEST_STATUS_TAKEN) ||
3435 (!z_older_than(10, 3, 14) && (quest[i].status == QUEST_STATUS_COMPLETED)) ||
3436 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3438 rd_s16b(&quest[i].cur_num);
3439 rd_s16b(&quest[i].max_num);
3440 rd_s16b(&quest[i].type);
3442 /* Load quest monster index */
3443 rd_s16b(&quest[i].r_idx);
3445 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
3447 determine_random_questor(&quest[i]);
3450 /* Load quest item index */
3451 rd_s16b(&quest[i].k_idx);
3454 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
3456 rd_byte(&quest[i].flags);
3458 if (z_older_than(10, 3, 11))
3460 if (quest[i].flags & QUEST_FLAG_PRESET)
3462 quest[i].dungeon = 0;
3466 init_flags = INIT_ASSIGN;
3467 p_ptr->inside_quest = i;
3469 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3470 p_ptr->inside_quest = old_inside_quest;
3475 rd_byte(&quest[i].dungeon);
3478 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
3479 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
3480 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
3483 /* Ignore the empty quests from old versions */
3486 /* Ignore quest status */
3489 /* Ignore quest level */
3493 * We don't have to care about the other info,
3494 * since status should be 0 for these quests anyway
3499 /* Quest 18 was removed */
3500 if (h_older_than(1, 7, 0, 6))
3502 WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3503 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3506 /* Position in the wilderness */
3507 rd_s32b(&p_ptr->wilderness_x);
3508 rd_s32b(&p_ptr->wilderness_y);
3509 if (z_older_than(10, 3, 13))
3511 p_ptr->wilderness_x = 5;
3512 p_ptr->wilderness_y = 48;
3515 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3516 else rd_byte((byte *)&p_ptr->wild_mode);
3517 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3518 else rd_byte((byte *)&ambush_flag);
3520 /* Size of the wilderness */
3521 rd_s32b(&wild_x_size);
3522 rd_s32b(&wild_y_size);
3524 /* Incompatible save files */
3525 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3528 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
3530 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
3536 /* Load the wilderness seeds */
3537 for (i = 0; i < wild_x_size; i++)
3539 for (j = 0; j < wild_y_size; j++)
3541 rd_u32b(&wilderness[j][i].seed);
3547 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3549 if (arg_fiddle) note("Loaded Quests");
3552 /* Load the Artifacts */
3555 /* Incompatible save files */
3556 if (tmp16u > max_a_idx)
3559 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3561 note(format("Too many (%u) artifacts!", tmp16u));
3567 /* Read the artifact flags */
3568 for (i = 0; i < tmp16u; i++)
3570 artifact_type *a_ptr = &a_info[i];
3573 a_ptr->cur_num = tmp8u;
3575 if (h_older_than(1, 5, 0, 0))
3577 a_ptr->floor_id = 0;
3585 rd_s16b(&a_ptr->floor_id);
3589 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3591 if (arg_fiddle) note("Loaded Artifacts");
3596 /* Read the extra stuff */
3598 if (p_ptr->energy_need < -999) world_player = TRUE;
3601 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3603 if (arg_fiddle) note("Loaded extra information");
3607 /* Read the player_hp array */
3610 /* Incompatible save files */
3611 if (tmp16u > PY_MAX_LEVEL)
3614 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
3616 note(format("Too many (%u) hitpoint entries!", tmp16u));
3622 /* Read the player_hp array */
3623 for (i = 0; i < tmp16u; i++)
3625 rd_s16b(&p_ptr->player_hp[i]);
3628 /* Important -- Initialize the sex */
3629 sp_ptr = &sex_info[p_ptr->psex];
3631 /* Important -- Initialize the race/class */
3632 rp_ptr = &race_info[p_ptr->prace];
3633 cp_ptr = &class_info[p_ptr->pclass];
3634 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3636 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3638 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3639 do_cmd_rerate(FALSE);
3641 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3643 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3644 do_cmd_rerate(FALSE);
3646 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3648 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3649 do_cmd_rerate(FALSE);
3651 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3653 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3654 do_cmd_rerate(FALSE);
3657 /* Important -- Initialize the magic */
3658 mp_ptr = &m_info[p_ptr->pclass];
3661 /* Read spell info */
3662 rd_u32b(&p_ptr->spell_learned1);
3663 rd_u32b(&p_ptr->spell_learned2);
3664 rd_u32b(&p_ptr->spell_worked1);
3665 rd_u32b(&p_ptr->spell_worked2);
3666 rd_u32b(&p_ptr->spell_forgotten1);
3667 rd_u32b(&p_ptr->spell_forgotten2);
3669 if (z_older_than(10,0,5))
3671 p_ptr->learned_spells = 0;
3672 for (i = 0; i < 64; i++)
3674 /* Count known spells */
3676 (p_ptr->spell_learned1 & (1L << i)) :
3677 (p_ptr->spell_learned2 & (1L << (i - 32))))
3679 p_ptr->learned_spells++;
3683 else rd_s16b(&p_ptr->learned_spells);
3685 if (z_older_than(10,0,6))
3687 p_ptr->add_spells = 0;
3689 else rd_s16b(&p_ptr->add_spells);
3690 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3692 for (i = 0; i < 64; i++)
3694 rd_byte(&p_ptr->spell_order[i]);
3698 /* Read the inventory */
3702 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
3704 note("Unable to read inventory");
3710 /* Read number of towns */
3712 town_count = tmp16u;
3714 /* Read the stores */
3716 for (i = 1; i < town_count; i++)
3718 for (j = 0; j < tmp16u; j++)
3720 if (rd_store(i, j)) return (22);
3724 rd_s16b(&p_ptr->pet_follow_distance);
3725 if (z_older_than(10, 4, 10))
3727 p_ptr->pet_extra_flags = 0;
3729 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3731 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3733 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3737 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3740 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3744 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3747 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3751 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3754 if (!z_older_than(10,0,8))
3757 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3762 rd_s16b(&p_ptr->pet_extra_flags);
3765 if (!z_older_than(11, 0, 9))
3767 char buf[SCREEN_BUF_SIZE];
3768 rd_string(buf, sizeof(buf));
3769 if (buf[0]) screen_dump = string_make(buf);
3774 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3776 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3781 /* I'm not dead yet... */
3782 if (!p_ptr->is_dead)
3784 /* Dead players have no dungeon */
3786 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
3788 note("Restoring Dungeon...");
3794 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
3796 note("Error reading dungeon data");
3802 /* Read the ghost info */
3809 strip_bytes(tmp32s);
3813 /* Quest 18 was removed */
3814 if (h_older_than(1, 7, 0, 6))
3816 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3818 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3820 p_ptr->inside_quest = 0;
3825 #ifdef VERIFY_CHECKSUMS
3827 /* Save the checksum */
3828 n_v_check = v_check;
3830 /* Read the old checksum */
3831 rd_u32b(&o_v_check);
3834 if (o_v_check != n_v_check)
3837 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3839 note("Invalid checksum");
3846 /* Save the encoded checksum */
3847 n_x_check = x_check;
3849 /* Read the checksum */
3850 rd_u32b(&o_x_check);
3854 if (o_x_check != n_x_check)
3857 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3859 note("Invalid encoded checksum");
3873 * Actually read the savefile
3875 errr rd_savefile_new(void)
3879 /* Grab permissions */
3882 /* The savefile is a binary file */
3883 fff = my_fopen(savefile, "rb");
3885 /* Drop permissions */
3889 if (!fff) return (-1);
3891 /* Call the sub-function */
3892 err = rd_savefile_new_aux();
3894 /* Check for errors */
3895 if (ferror(fff)) err = -1;
3897 /* Close the file */
3906 * Actually load and verify a floor save data
3908 static bool load_floor_aux(saved_floor_type *sf_ptr)
3913 #ifdef VERIFY_CHECKSUMS
3914 u32b n_x_check, n_v_check;
3915 u32b o_x_check, o_v_check;
3918 /* Hack -- decrypt (read xor_byte) */
3922 /* Clear the checksums */
3926 /* Set the version number to current version */
3927 /* Never load old temporal files */
3928 h_ver_extra = H_VER_EXTRA;
3929 h_ver_patch = H_VER_PATCH;
3930 h_ver_minor = H_VER_MINOR;
3931 h_ver_major = H_VER_MAJOR;
3933 /* Verify the sign */
3935 if (saved_floor_file_sign != tmp32u) return FALSE;
3937 /* Read -- have error? */
3938 if (rd_saved_floor(sf_ptr)) return FALSE;
3941 #ifdef VERIFY_CHECKSUMS
3942 /* Save the checksum */
3943 n_v_check = v_check;
3945 /* Read the old checksum */
3946 rd_u32b(&o_v_check);
3949 if (o_v_check != n_v_check) return FALSE;
3951 /* Save the encoded checksum */
3952 n_x_check = x_check;
3954 /* Read the checksum */
3955 rd_u32b(&o_x_check);
3958 if (o_x_check != n_x_check) return FALSE;
3967 * Attempt to load the temporally saved-floor data
3969 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
3971 FILE *old_fff = NULL;
3972 byte old_xor_byte = 0;
3973 u32b old_v_check = 0;
3974 u32b old_x_check = 0;
3975 byte old_h_ver_major = 0;
3976 byte old_h_ver_minor = 0;
3977 byte old_h_ver_patch = 0;
3978 byte old_h_ver_extra = 0;
3981 char floor_savefile[1024];
3983 byte old_kanji_code = kanji_code;
3986 * Temporal files are always written in system depended kanji
3991 /* EUC kanji code */
3995 /* SJIS kanji code */
4004 /* We have one file already opened */
4005 if (mode & SLF_SECOND)
4007 /* Backup original values */
4009 old_xor_byte = xor_byte;
4010 old_v_check = v_check;
4011 old_x_check = x_check;
4012 old_h_ver_major = h_ver_major;
4013 old_h_ver_minor = h_ver_minor;
4014 old_h_ver_patch = h_ver_patch;
4015 old_h_ver_extra = h_ver_extra;
4018 /* floor savefile */
4019 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
4021 /* Grab permissions */
4024 /* The savefile is a binary file */
4025 fff = my_fopen(floor_savefile, "rb");
4027 /* Drop permissions */
4031 if (!fff) ok = FALSE;
4033 /* Attempt to load */
4036 /* Load saved floor data from file */
4037 ok = load_floor_aux(sf_ptr);
4039 /* Check for errors */
4040 if (ferror(fff)) ok = FALSE;
4042 /* Close the file */
4045 /* Grab permissions */
4048 /* Delete the file */
4049 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
4051 /* Drop permissions */
4055 /* We have one file already opened */
4056 if (mode & SLF_SECOND)
4058 /* Restore original values */
4060 xor_byte = old_xor_byte;
4061 v_check = old_v_check;
4062 x_check = old_x_check;
4063 h_ver_major = old_h_ver_major;
4064 h_ver_minor = old_h_ver_minor;
4065 h_ver_patch = old_h_ver_patch;
4066 h_ver_extra = old_h_ver_extra;
4069 /* Restore old knowledge */
4070 kanji_code = old_kanji_code;