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)
2279 note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
2285 /* Carry inventory */
2291 /* Player touches it */
2292 q_ptr->marked |= OM_TOUCHED;
2295 object_copy(&inventory[n], q_ptr);
2297 /* Add the weight */
2298 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2312 * Read the saved messages
2314 static void rd_messages(void)
2324 /* Read the messages */
2325 for (i = 0; i < num; i++)
2327 /* Read the message */
2328 rd_string(buf, sizeof(buf));
2330 /* Save the message */
2337 /* Old hidden trap flag */
2338 #define CAVE_TRAP 0x8000
2340 /*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
2341 #define OLD_FEAT_INVIS 0x02
2342 #define OLD_FEAT_GLYPH 0x03
2343 #define OLD_FEAT_QUEST_ENTER 0x08
2344 #define OLD_FEAT_QUEST_EXIT 0x09
2345 #define OLD_FEAT_MINOR_GLYPH 0x40
2346 #define OLD_FEAT_BLDG_1 0x81
2347 #define OLD_FEAT_MIRROR 0xc3
2350 #define OLD_QUEST_WATER_CAVE 18
2352 /* Quest constants */
2353 #define QUEST_OLD_CASTLE 27
2354 #define QUEST_ROYAL_CRYPT 28
2357 * Read the dungeon (old method)
2359 * The monsters/objects must be loaded in the same order
2360 * that they were stored, since the actual indexes matter.
2362 static errr rd_dungeon_old(void)
2373 /*** Basic info ***/
2376 rd_s16b(&dun_level);
2377 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2378 else rd_byte(&dungeon_type);
2380 /* Set the base level for old versions */
2381 base_level = dun_level;
2383 rd_s16b(&base_level);
2385 rd_s16b(&num_repro);
2390 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2393 rd_s16b(&tmp16s); /* max_panel_rows */
2394 rd_s16b(&tmp16s); /* max_panel_cols */
2397 if (!py || !px) {py = 10;px = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
2405 /*** Run length decoding ***/
2407 /* Load the dungeon data */
2408 for (x = y = 0; y < ymax; )
2414 if (z_older_than(10,3,6))
2423 /* Decline invalid flags */
2424 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2427 /* Apply the RLE info */
2428 for (i = count; i > 0; i--)
2430 /* Access the cave */
2431 c_ptr = &cave[y][x];
2433 /* Extract "info" */
2443 if (++y >= ymax) break;
2449 /*** Run length decoding ***/
2451 /* Load the dungeon data */
2452 for (x = y = 0; y < ymax; )
2458 /* Apply the RLE info */
2459 for (i = count; i > 0; i--)
2461 /* Access the cave */
2462 c_ptr = &cave[y][x];
2464 /* Extract "feat" */
2465 c_ptr->feat = (s16b)tmp8u;
2474 if (++y >= ymax) break;
2479 /*** Run length decoding ***/
2481 /* Load the dungeon data */
2482 for (x = y = 0; y < ymax; )
2488 /* Apply the RLE info */
2489 for (i = count; i > 0; i--)
2491 /* Access the cave */
2492 c_ptr = &cave[y][x];
2494 /* Extract "mimic" */
2495 c_ptr->mimic = (s16b)tmp8u;
2504 if (++y >= ymax) break;
2509 /*** Run length decoding ***/
2511 /* Load the dungeon data */
2512 for (x = y = 0; y < ymax; )
2518 /* Apply the RLE info */
2519 for (i = count; i > 0; i--)
2521 /* Access the cave */
2522 c_ptr = &cave[y][x];
2524 /* Extract "feat" */
2525 c_ptr->special = tmp16s;
2534 if (++y >= ymax) break;
2539 /* Convert cave data */
2540 if (z_older_than(11, 0, 99))
2542 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2544 /* Wipe old unused flags */
2545 cave[y][x].info &= ~(CAVE_MASK);
2549 if (h_older_than(1, 1, 1, 0))
2551 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2553 /* Access the cave */
2554 c_ptr = &cave[y][x];
2557 if (c_ptr->feat == OLD_FEAT_INVIS)
2559 c_ptr->feat = feat_floor;
2560 c_ptr->info |= CAVE_TRAP;
2563 /* Older than 1.1.1 */
2564 if (c_ptr->feat == OLD_FEAT_MIRROR)
2566 c_ptr->feat = feat_floor;
2567 c_ptr->info |= CAVE_OBJECT;
2572 if (h_older_than(1, 3, 1, 0))
2574 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2576 /* Access the cave */
2577 c_ptr = &cave[y][x];
2579 /* Old CAVE_IN_MIRROR flag */
2580 if (c_ptr->info & CAVE_OBJECT)
2582 c_ptr->mimic = feat_mirror;
2585 /* Runes will be mimics and flags */
2586 else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
2587 (c_ptr->feat == OLD_FEAT_GLYPH))
2589 c_ptr->info |= CAVE_OBJECT;
2590 c_ptr->mimic = c_ptr->feat;
2591 c_ptr->feat = feat_floor;
2594 /* Hidden traps will be trap terrains mimicing floor */
2595 else if (c_ptr->info & CAVE_TRAP)
2597 c_ptr->info &= ~CAVE_TRAP;
2598 c_ptr->mimic = c_ptr->feat;
2599 c_ptr->feat = choose_random_trap();
2602 /* Another hidden trap */
2603 else if (c_ptr->feat == OLD_FEAT_INVIS)
2605 c_ptr->mimic = feat_floor;
2606 c_ptr->feat = feat_trap_open;
2611 /* Quest 18 was removed */
2612 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2614 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2616 /* Access the cave */
2617 c_ptr = &cave[y][x];
2619 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2621 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2623 c_ptr->feat = feat_tree;
2626 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2628 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2631 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2632 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2634 c_ptr->feat = feat_up_stair;
2642 /* Read the item count */
2645 /* Verify maximum */
2646 if (limit > max_o_idx)
2648 note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
2652 /* Read the dungeon items */
2653 for (i = 1; i < limit; i++)
2660 /* Get a new record */
2666 note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
2672 o_ptr = &o_list[o_idx];
2678 /* XXX XXX XXX XXX XXX */
2681 if (o_ptr->held_m_idx)
2683 monster_type *m_ptr;
2686 m_ptr = &m_list[o_ptr->held_m_idx];
2689 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2691 /* Place the object */
2692 m_ptr->hold_o_idx = o_idx;
2698 /* Access the item location */
2699 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2702 o_ptr->next_o_idx = c_ptr->o_idx;
2704 /* Place the object */
2705 c_ptr->o_idx = o_idx;
2712 /* Read the monster count */
2715 /* Hack -- verify */
2716 if (limit > max_m_idx)
2718 note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
2722 /* Read the monsters */
2723 for (i = 1; i < limit; i++)
2726 monster_type *m_ptr;
2728 /* Get a new record */
2734 note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
2739 /* Acquire monster */
2740 m_ptr = &m_list[m_idx];
2742 /* Read the monster */
2747 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2749 /* Mark the location */
2750 c_ptr->m_idx = m_idx;
2753 real_r_ptr(m_ptr)->cur_num++;
2758 /* The dungeon is ready */
2759 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2760 character_dungeon = FALSE;
2762 character_dungeon = TRUE;
2771 * Read the saved floor
2773 * The monsters/objects must be loaded in the same order
2774 * that they were stored, since the actual indexes matter.
2776 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2788 cave_template_type *templates;
2791 /*** Wipe all cave ***/
2795 /*** Basic info ***/
2797 /* Dungeon floor specific info follows */
2801 /*** Not a saved floor ***/
2803 rd_s16b(&dun_level);
2804 base_level = dun_level;
2808 /*** The saved floor ***/
2811 if (tmp16s != sf_ptr->floor_id) return 171;
2814 if (tmp8u != sf_ptr->savefile_id) return 171;
2817 if (tmp16s != sf_ptr->dun_level) return 171;
2818 dun_level = sf_ptr->dun_level;
2821 if (tmp32s != sf_ptr->last_visit) return 171;
2824 if (tmp32u != sf_ptr->visit_mark) return 171;
2827 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2830 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2833 rd_s16b(&base_level);
2834 rd_s16b(&num_repro);
2845 rd_byte(&p_ptr->feeling);
2849 /*** Read template for cave_type ***/
2851 /* Read the template count */
2854 /* Allocate the "template" array */
2855 C_MAKE(templates, limit, cave_template_type);
2857 /* Read the templates */
2858 for (i = 0; i < limit; i++)
2860 cave_template_type *ct_ptr = &templates[i];
2863 rd_u16b(&ct_ptr->info);
2864 if (h_older_than(1, 7, 0, 2))
2867 ct_ptr->feat = (s16b)tmp8u;
2869 ct_ptr->mimic = (s16b)tmp8u;
2873 rd_s16b(&ct_ptr->feat);
2874 rd_s16b(&ct_ptr->mimic);
2876 rd_s16b(&ct_ptr->special);
2884 /*** Run length decoding ***/
2886 /* Load the dungeon data */
2887 for (x = y = 0; y < ymax; )
2899 } while (tmp8u == MAX_UCHAR);
2901 /* Apply the RLE info */
2902 for (i = count; i > 0; i--)
2904 /* Access the cave */
2905 cave_type *c_ptr = &cave[y][x];
2907 /* Extract cave data */
2908 c_ptr->info = templates[id].info;
2909 c_ptr->feat = templates[id].feat;
2910 c_ptr->mimic = templates[id].mimic;
2911 c_ptr->special = templates[id].special;
2920 if (++y >= ymax) break;
2925 /* Quest 18 was removed */
2926 if (h_older_than(1, 7, 0, 6) && !vanilla_town)
2928 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2930 /* Access the cave */
2931 cave_type *c_ptr = &cave[y][x];
2933 if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
2935 if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
2937 c_ptr->feat = feat_tree;
2940 else if (c_ptr->feat == OLD_FEAT_BLDG_1)
2942 c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
2945 else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
2946 (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
2948 c_ptr->feat = feat_up_stair;
2954 /* Free the "template" array */
2955 C_KILL(templates, limit, cave_template_type);
2960 /* Read the item count */
2963 /* Verify maximum */
2964 if (limit > max_o_idx) return 151;
2967 /* Read the dungeon items */
2968 for (i = 1; i < limit; i++)
2974 /* Get a new record */
2978 if (i != o_idx) return 152;
2981 o_ptr = &o_list[o_idx];
2988 if (o_ptr->held_m_idx)
2990 monster_type *m_ptr;
2993 m_ptr = &m_list[o_ptr->held_m_idx];
2996 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2998 /* Place the object */
2999 m_ptr->hold_o_idx = o_idx;
3005 /* Access the item location */
3006 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
3009 o_ptr->next_o_idx = c_ptr->o_idx;
3011 /* Place the object */
3012 c_ptr->o_idx = o_idx;
3019 /* Read the monster count */
3022 /* Hack -- verify */
3023 if (limit > max_m_idx) return 161;
3025 /* Read the monsters */
3026 for (i = 1; i < limit; i++)
3030 monster_type *m_ptr;
3032 /* Get a new record */
3036 if (i != m_idx) return 162;
3039 /* Acquire monster */
3040 m_ptr = &m_list[m_idx];
3042 /* Read the monster */
3047 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
3049 /* Mark the location */
3050 c_ptr->m_idx = m_idx;
3053 real_r_ptr(m_ptr)->cur_num++;
3062 * Read the dungeon (new method)
3064 * The monsters/objects must be loaded in the same order
3065 * that they were stored, since the actual indexes matter.
3067 static errr rd_dungeon(void)
3073 /* Initialize saved_floors array and temporal files */
3074 init_saved_floors(FALSE);
3077 if (h_older_than(1, 5, 0, 0))
3079 err = rd_dungeon_old();
3081 /* Prepare floor_id of current floor */
3084 p_ptr->floor_id = get_new_floor_id();
3085 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
3094 /* Number of floor_id used from birth */
3095 rd_s16b(&max_floor_id);
3097 /* Current dungeon type */
3098 rd_byte(&dungeon_type);
3101 /* Number of the saved_floors array elements */
3104 /*** No saved floor (On the surface etc.) ***/
3107 /* Read the current floor data */
3108 err = rd_saved_floor(NULL);
3111 /*** In the dungeon ***/
3115 /* Read the saved_floors array */
3116 for (i = 0; i < num; i++)
3118 saved_floor_type *sf_ptr = &saved_floors[i];
3120 rd_s16b(&sf_ptr->floor_id);
3121 rd_byte(&sf_ptr->savefile_id);
3122 rd_s16b(&sf_ptr->dun_level);
3123 rd_s32b(&sf_ptr->last_visit);
3124 rd_u32b(&sf_ptr->visit_mark);
3125 rd_s16b(&sf_ptr->upper_floor_id);
3126 rd_s16b(&sf_ptr->lower_floor_id);
3130 /* Move saved floors data to temporal files */
3131 for (i = 0; i < num; i++)
3133 saved_floor_type *sf_ptr = &saved_floors[i];
3136 /* Unused element */
3137 if (!sf_ptr->floor_id) continue;
3139 /* Read the failure mark */
3141 if (tmp8u) continue;
3143 /* Read from the save file */
3144 err = rd_saved_floor(sf_ptr);
3149 /* Re-save as temporal saved floor file */
3150 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
3156 /* Finally load current floor data from temporal file */
3159 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
3164 /*** Error messages ***/
3168 note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
3172 note(_("アイテム配置エラー", "Object allocation error"));
3176 note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
3180 note(_("モンスター配置エラー", "Monster allocation error"));
3184 note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
3188 note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
3192 note(_("Error 183", "Error 183"));
3196 /* The dungeon is ready */
3197 character_dungeon = TRUE;
3199 /* Success or Error */
3205 * Actually read the savefile
3207 static errr rd_savefile_new_aux(void)
3219 #ifdef VERIFY_CHECKSUMS
3220 u32b n_x_check, n_v_check;
3221 u32b o_x_check, o_v_check;
3225 /* Mention the savefile version */
3227 _("バージョン %d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d savefile..."),
3228 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
3231 /* Strip the version bytes */
3234 /* Hack -- decrypt */
3235 xor_byte = sf_extra;
3238 /* Clear the checksums */
3242 /* Read the version number of the savefile */
3243 /* Old savefile will be version 0.0.0.3 */
3244 rd_byte(&h_ver_extra);
3245 rd_byte(&h_ver_patch);
3246 rd_byte(&h_ver_minor);
3247 rd_byte(&h_ver_major);
3249 /* Operating system info */
3250 rd_u32b(&sf_system);
3252 /* Time of savefile creation */
3255 /* Number of resurrections */
3258 /* Number of times played */
3262 /* Later use (always zero) */
3265 /* Later use (always zero) */
3268 /* Later use (always zero) */
3272 rd_byte(&kanji_code);
3274 /* Read RNG state */
3276 if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
3278 /* Then the options */
3280 if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
3282 /* Then the "messages" */
3284 if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
3286 for (i = 0; i < max_r_idx; i++)
3288 /* Access that monster */
3289 monster_race *r_ptr = &r_info[i];
3291 /* Hack -- Reset the death counter */
3292 r_ptr->max_num = 100;
3294 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3296 /* Hack -- Non-unique Nazguls are semi-unique */
3297 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3300 /* Monster Memory */
3303 /* Incompatible save files */
3304 if (tmp16u > max_r_idx)
3306 note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
3310 /* Read the available records */
3311 for (i = 0; i < tmp16u; i++)
3317 if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
3322 /* Incompatible save files */
3323 if (tmp16u > max_k_idx)
3325 note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
3329 /* Read the object memory */
3330 for (i = 0; i < tmp16u; i++)
3333 object_kind *k_ptr = &k_info[i];
3337 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3338 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3340 if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
3342 /* 2.1.3 or newer version */
3344 u16b max_towns_load;
3345 u16b max_quests_load;
3346 byte max_rquests_load;
3347 s16b old_inside_quest = p_ptr->inside_quest;
3349 /* Number of towns */
3350 rd_u16b(&max_towns_load);
3352 /* Incompatible save files */
3353 if (max_towns_load > max_towns)
3355 note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
3359 /* Number of quests */
3360 rd_u16b(&max_quests_load);
3362 if (z_older_than(11, 0, 7))
3364 max_rquests_load = 10;
3368 rd_byte(&max_rquests_load);
3371 /* Incompatible save files */
3372 if (max_quests_load > max_quests)
3374 note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
3378 for (i = 0; i < max_quests_load; i++)
3382 quest_type* const q_ptr = &quest[i];
3384 rd_s16b(&q_ptr->status);
3385 rd_s16b(&q_ptr->level);
3387 if (z_older_than(11, 0, 6))
3393 rd_byte(&q_ptr->complev);
3395 if(h_older_than(2, 1, 2, 2))
3397 q_ptr->comptime = 0;
3401 rd_u32b(&q_ptr->comptime);
3404 /* Load quest status if quest is running */
3405 if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
3406 (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
3407 (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
3409 rd_s16b(&q_ptr->cur_num);
3410 rd_s16b(&q_ptr->max_num);
3411 rd_s16b(&q_ptr->type);
3413 /* Load quest monster index */
3414 rd_s16b(&q_ptr->r_idx);
3416 if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
3418 determine_random_questor(&quest[i]);
3421 /* Load quest item index */
3422 rd_s16b(&q_ptr->k_idx);
3425 a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
3427 rd_byte(&q_ptr->flags);
3429 if (z_older_than(10, 3, 11))
3431 if (q_ptr->flags & QUEST_FLAG_PRESET)
3437 init_flags = INIT_ASSIGN;
3438 p_ptr->inside_quest = i;
3440 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3441 p_ptr->inside_quest = old_inside_quest;
3446 rd_byte(&q_ptr->dungeon);
3449 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
3450 if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
3451 r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
3454 /* Ignore the empty quests from old versions */
3457 /* Ignore quest status */
3460 /* Ignore quest level */
3464 * We don't have to care about the other info,
3465 * since status should be 0 for these quests anyway
3470 /* Quest 18 was removed */
3471 if (h_older_than(1, 7, 0, 6))
3473 (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
3474 quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
3477 /* Position in the wilderness */
3478 rd_s32b(&p_ptr->wilderness_x);
3479 rd_s32b(&p_ptr->wilderness_y);
3480 if (z_older_than(10, 3, 13))
3482 p_ptr->wilderness_x = 5;
3483 p_ptr->wilderness_y = 48;
3486 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3487 else rd_byte((byte *)&p_ptr->wild_mode);
3488 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3489 else rd_byte((byte *)&ambush_flag);
3491 /* Size of the wilderness */
3492 rd_s32b(&wild_x_size);
3493 rd_s32b(&wild_y_size);
3495 /* Incompatible save files */
3496 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3498 note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
3502 /* Load the wilderness seeds */
3503 for (i = 0; i < wild_x_size; i++)
3505 for (j = 0; j < wild_y_size; j++)
3507 rd_u32b(&wilderness[j][i].seed);
3512 if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
3514 /* Load the Artifacts */
3517 /* Incompatible save files */
3518 if (tmp16u > max_a_idx)
3520 note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
3524 /* Read the artifact flags */
3525 for (i = 0; i < tmp16u; i++)
3527 artifact_type *a_ptr = &a_info[i];
3530 a_ptr->cur_num = tmp8u;
3532 if (h_older_than(1, 5, 0, 0))
3534 a_ptr->floor_id = 0;
3542 rd_s16b(&a_ptr->floor_id);
3545 if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
3547 /* Read the extra stuff */
3549 if (p_ptr->energy_need < -999) world_player = TRUE;
3551 if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
3554 /* Read the player_hp array */
3557 /* Incompatible save files */
3558 if (tmp16u > PY_MAX_LEVEL)
3560 note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
3564 /* Read the player_hp array */
3565 for (i = 0; i < tmp16u; i++)
3567 rd_s16b(&p_ptr->player_hp[i]);
3570 /* Important -- Initialize the sex */
3571 sp_ptr = &sex_info[p_ptr->psex];
3573 /* Important -- Initialize the race/class */
3574 rp_ptr = &race_info[p_ptr->prace];
3575 cp_ptr = &class_info[p_ptr->pclass];
3576 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3578 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3580 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3581 do_cmd_rerate(FALSE);
3583 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3585 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3586 do_cmd_rerate(FALSE);
3588 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3590 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3591 do_cmd_rerate(FALSE);
3593 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3595 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3596 do_cmd_rerate(FALSE);
3599 /* Important -- Initialize the magic */
3600 mp_ptr = &m_info[p_ptr->pclass];
3603 /* Read spell info */
3604 rd_u32b(&p_ptr->spell_learned1);
3605 rd_u32b(&p_ptr->spell_learned2);
3606 rd_u32b(&p_ptr->spell_worked1);
3607 rd_u32b(&p_ptr->spell_worked2);
3608 rd_u32b(&p_ptr->spell_forgotten1);
3609 rd_u32b(&p_ptr->spell_forgotten2);
3611 if (z_older_than(10,0,5))
3613 p_ptr->learned_spells = 0;
3614 for (i = 0; i < 64; i++)
3616 /* Count known spells */
3618 (p_ptr->spell_learned1 & (1L << i)) :
3619 (p_ptr->spell_learned2 & (1L << (i - 32))))
3621 p_ptr->learned_spells++;
3625 else rd_s16b(&p_ptr->learned_spells);
3627 if (z_older_than(10,0,6))
3629 p_ptr->add_spells = 0;
3631 else rd_s16b(&p_ptr->add_spells);
3632 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3634 for (i = 0; i < 64; i++)
3636 rd_byte(&p_ptr->spell_order[i]);
3640 /* Read the inventory */
3643 note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
3647 /* Read number of towns */
3649 town_count = tmp16u;
3651 /* Read the stores */
3653 for (i = 1; i < town_count; i++)
3655 for (j = 0; j < tmp16u; j++)
3657 if (rd_store(i, j)) return (22);
3661 rd_s16b(&p_ptr->pet_follow_distance);
3662 if (z_older_than(10, 4, 10))
3664 p_ptr->pet_extra_flags = 0;
3666 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3668 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3670 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3674 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3677 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3681 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3684 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3688 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3691 if (!z_older_than(10,0,8))
3694 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3699 rd_s16b(&p_ptr->pet_extra_flags);
3702 if (!z_older_than(11, 0, 9))
3704 char buf[SCREEN_BUF_SIZE];
3705 rd_string(buf, sizeof(buf));
3706 if (buf[0]) screen_dump = string_make(buf);
3711 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3713 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3718 /* I'm not dead yet... */
3719 if (!p_ptr->is_dead)
3721 /* Dead players have no dungeon */
3722 note(_("ダンジョン復元中...", "Restoring Dungeon..."));
3726 note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
3730 /* Read the ghost info */
3737 strip_bytes(tmp32s);
3741 /* Quest 18 was removed */
3742 if (h_older_than(1, 7, 0, 6))
3744 if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
3746 dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
3748 p_ptr->inside_quest = 0;
3753 #ifdef VERIFY_CHECKSUMS
3755 /* Save the checksum */
3756 n_v_check = v_check;
3758 /* Read the old checksum */
3759 rd_u32b(&o_v_check);
3762 if (o_v_check != n_v_check)
3764 note(_("チェックサムがおかしい", "Invalid checksum"));
3769 /* Save the encoded checksum */
3770 n_x_check = x_check;
3772 /* Read the checksum */
3773 rd_u32b(&o_x_check);
3777 if (o_x_check != n_x_check)
3779 note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
3791 * Actually read the savefile
3793 errr rd_savefile_new(void)
3797 /* Grab permissions */
3800 /* The savefile is a binary file */
3801 fff = my_fopen(savefile, "rb");
3803 /* Drop permissions */
3807 if (!fff) return (-1);
3809 /* Call the sub-function */
3810 err = rd_savefile_new_aux();
3812 /* Check for errors */
3813 if (ferror(fff)) err = -1;
3815 /* Close the file */
3824 * Actually load and verify a floor save data
3826 static bool load_floor_aux(saved_floor_type *sf_ptr)
3831 #ifdef VERIFY_CHECKSUMS
3832 u32b n_x_check, n_v_check;
3833 u32b o_x_check, o_v_check;
3836 /* Hack -- decrypt (read xor_byte) */
3840 /* Clear the checksums */
3844 /* Set the version number to current version */
3845 /* Never load old temporal files */
3846 h_ver_extra = H_VER_EXTRA;
3847 h_ver_patch = H_VER_PATCH;
3848 h_ver_minor = H_VER_MINOR;
3849 h_ver_major = H_VER_MAJOR;
3851 /* Verify the sign */
3853 if (saved_floor_file_sign != tmp32u) return FALSE;
3855 /* Read -- have error? */
3856 if (rd_saved_floor(sf_ptr)) return FALSE;
3859 #ifdef VERIFY_CHECKSUMS
3860 /* Save the checksum */
3861 n_v_check = v_check;
3863 /* Read the old checksum */
3864 rd_u32b(&o_v_check);
3867 if (o_v_check != n_v_check) return FALSE;
3869 /* Save the encoded checksum */
3870 n_x_check = x_check;
3872 /* Read the checksum */
3873 rd_u32b(&o_x_check);
3876 if (o_x_check != n_x_check) return FALSE;
3885 * Attempt to load the temporally saved-floor data
3887 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
3889 FILE *old_fff = NULL;
3890 byte old_xor_byte = 0;
3891 u32b old_v_check = 0;
3892 u32b old_x_check = 0;
3893 byte old_h_ver_major = 0;
3894 byte old_h_ver_minor = 0;
3895 byte old_h_ver_patch = 0;
3896 byte old_h_ver_extra = 0;
3899 char floor_savefile[1024];
3901 byte old_kanji_code = kanji_code;
3904 * Temporal files are always written in system depended kanji
3909 /* EUC kanji code */
3913 /* SJIS kanji code */
3922 /* We have one file already opened */
3923 if (mode & SLF_SECOND)
3925 /* Backup original values */
3927 old_xor_byte = xor_byte;
3928 old_v_check = v_check;
3929 old_x_check = x_check;
3930 old_h_ver_major = h_ver_major;
3931 old_h_ver_minor = h_ver_minor;
3932 old_h_ver_patch = h_ver_patch;
3933 old_h_ver_extra = h_ver_extra;
3936 /* floor savefile */
3937 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3939 /* Grab permissions */
3942 /* The savefile is a binary file */
3943 fff = my_fopen(floor_savefile, "rb");
3945 /* Drop permissions */
3949 if (!fff) ok = FALSE;
3951 /* Attempt to load */
3954 /* Load saved floor data from file */
3955 ok = load_floor_aux(sf_ptr);
3957 /* Check for errors */
3958 if (ferror(fff)) ok = FALSE;
3960 /* Close the file */
3963 /* Grab permissions */
3966 /* Delete the file */
3967 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3969 /* Drop permissions */
3973 /* We have one file already opened */
3974 if (mode & SLF_SECOND)
3976 /* Restore original values */
3978 xor_byte = old_xor_byte;
3979 v_check = old_v_check;
3980 x_check = old_x_check;
3981 h_ver_major = old_h_ver_major;
3982 h_ver_minor = old_h_ver_minor;
3983 h_ver_patch = old_h_ver_patch;
3984 h_ver_extra = old_h_ver_extra;
3987 /* Restore old knowledge */
3988 kanji_code = old_kanji_code;