3 /* Purpose: support for loading savefiles -BEN- */
9 * This file loads savefiles from Angband 2.7.X and 2.8.X
11 * Ancient savefiles (pre-2.7.0) are loaded by another file.
13 * Note that Angband 2.7.0 through 2.7.3 are now officially obsolete,
14 * and savefiles from those versions may not be successfully converted.
16 * We attempt to prevent corrupt savefiles from inducing memory errors.
18 * Note that this file should not use the random number generator, the
19 * object flavors, the visual attr/char mappings, or anything else which
20 * is initialized *after* or *during* the "load character" function.
22 * This file assumes that the monster/object records are initialized
23 * to zero, and the race/kind tables have been loaded correctly. The
24 * order of object stacks is currently not saved in the savefiles, but
25 * the "next" pointers are saved, so all necessary knowledge is present.
27 * We should implement simple "savefile extenders" using some form of
28 * "sized" chunks of bytes, with a {size,type,data} format, so everyone
29 * can know the size, interested people can know the type, and the actual
30 * data is available to the parsing routines that acknowledge the type.
32 * Consider changing the "globe of invulnerability" code so that it
33 * takes some form of "maximum damage to protect from" in addition to
34 * the existing "number of turns to protect for", and where each hit
35 * by a monster will reduce the shield by that amount.
43 * Maximum number of tries for selection of a proper quest monster
49 * Local "savefile" pointer
54 * Hack -- old "encryption" byte
59 * Hack -- simple "checksum" on the actual values
61 static u32b v_check = 0L;
64 * Hack -- simple "checksum" on the encoded bytes
66 static u32b x_check = 0L;
72 * This function determines if the version of the savefile
73 * currently being read is older than version "x.y.z".
75 static bool older_than(byte x, byte y, byte z)
77 /* Much older, or much more recent */
78 if (sf_major < x) return (TRUE);
79 if (sf_major > x) return (FALSE);
81 /* Distinctly older, or distinctly more recent */
82 if (sf_minor < y) return (TRUE);
83 if (sf_minor > y) return (FALSE);
85 /* Barely older, or barely more recent */
86 if (sf_patch < z) return (TRUE);
87 if (sf_patch > z) return (FALSE);
89 /* Identical versions */
95 * The above function, adapted for Zangband
97 static bool z_older_than(byte x, byte y, byte z)
99 /* Much older, or much more recent */
100 if (z_major < x) return (TRUE);
101 if (z_major > x) return (FALSE);
103 /* Distinctly older, or distinctly more recent */
104 if (z_minor < y) return (TRUE);
105 if (z_minor > y) return (FALSE);
107 /* Barely older, or barely more recent */
108 if (z_patch < z) return (TRUE);
109 if (z_patch > z) return (FALSE);
111 /* Identical versions */
117 * Hack -- Show information on the screen, one line at a time.
119 * Avoid the top two lines, to avoid interference with "msg_print()".
121 static void note(cptr msg)
125 /* Draw the message */
128 /* Advance one line (wrap if needed) */
129 if (++y >= 24) y = 2;
137 * The following functions are used to load the basic building blocks
138 * of savefiles. They also maintain the "checksum" info for 2.7.0+
141 static byte sf_get(void)
145 /* Get a character, decode the value */
146 c = getc(fff) & 0xFF;
150 /* Maintain the checksum info */
154 /* Return the value */
158 static void rd_byte(byte *ip)
163 static void rd_u16b(u16b *ip)
166 (*ip) |= ((u16b)(sf_get()) << 8);
169 static void rd_s16b(s16b *ip)
174 static void rd_u32b(u32b *ip)
177 (*ip) |= ((u32b)(sf_get()) << 8);
178 (*ip) |= ((u32b)(sf_get()) << 16);
179 (*ip) |= ((u32b)(sf_get()) << 24);
182 static void rd_s32b(s32b *ip)
189 * Hack -- read a string
191 static void rd_string(char *str, int max)
195 /* Read the string */
196 for (i = 0; TRUE; i++)
203 /* Collect string while legal */
204 if (i < max) str[i] = tmp8u;
219 * Hack -- strip some bytes
221 static void strip_bytes(int n)
225 /* Strip the bytes */
226 while (n--) rd_byte(&tmp8u);
229 #define OLD_MAX_MANE 22
234 * This function attempts to "repair" old savefiles, and to extract
235 * the most up to date values for various object fields.
237 * Note that Angband 2.7.9 introduced a new method for object "flags"
238 * in which the "flags" on an object are actually extracted when they
239 * are needed from the object kind, artifact index, ego-item index,
240 * and two special "xtra" fields which are used to encode any "extra"
241 * power of certain ego-items. This had the side effect that items
242 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
243 * may have had, and also, all "uncursed" items will become "cursed"
244 * again, including Calris, even if it is being worn at the time. As
245 * a complete hack, items which are inscribed with "uncursed" will be
246 * "uncursed" when imported from pre-2.7.9 savefiles.
248 static void rd_item(object_type *o_ptr)
254 rd_s16b(&o_ptr->k_idx);
261 rd_byte(&o_ptr->tval);
262 rd_byte(&o_ptr->sval);
264 if (z_older_than(10, 4, 4))
266 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
267 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
268 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
272 rd_s16b(&o_ptr->pval);
274 rd_byte(&o_ptr->discount);
275 rd_byte(&o_ptr->number);
276 rd_s16b(&o_ptr->weight);
278 rd_byte(&o_ptr->name1);
279 rd_byte(&o_ptr->name2);
280 rd_s16b(&o_ptr->timeout);
282 rd_s16b(&o_ptr->to_h);
283 rd_s16b(&o_ptr->to_d);
284 rd_s16b(&o_ptr->to_a);
291 rd_byte(&o_ptr->ident);
293 rd_byte(&o_ptr->marked);
296 rd_u32b(&o_ptr->art_flags1);
297 rd_u32b(&o_ptr->art_flags2);
298 rd_u32b(&o_ptr->art_flags3);
300 if (z_older_than(11, 0, 11))
302 o_ptr->curse_flags = 0L;
303 if (o_ptr->ident & 0x40)
305 o_ptr->curse_flags |= TRC_CURSED;
306 if (o_ptr->art_flags3 & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
307 if (o_ptr->art_flags3 & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
310 artifact_type *a_ptr = &a_info[o_ptr->name1];
311 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
312 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
314 else if (o_ptr->name2)
316 ego_item_type *e_ptr = &e_info[o_ptr->name2];
317 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
318 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
321 o_ptr->art_flags3 &= (0x1FFFFFFFL);
325 rd_u32b(&o_ptr->curse_flags);
328 /* Monster holding object */
329 rd_s16b(&o_ptr->held_m_idx);
332 rd_byte(&o_ptr->xtra1);
333 rd_byte(&o_ptr->xtra2);
335 if (z_older_than(11, 0, 10))
337 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
339 switch (o_ptr->xtra2 % 6)
341 case 0: o_ptr->art_flags2 |= (TR2_SUST_STR); break;
342 case 1: o_ptr->art_flags2 |= (TR2_SUST_INT); break;
343 case 2: o_ptr->art_flags2 |= (TR2_SUST_WIS); break;
344 case 3: o_ptr->art_flags2 |= (TR2_SUST_DEX); break;
345 case 4: o_ptr->art_flags2 |= (TR2_SUST_CON); break;
346 case 5: o_ptr->art_flags2 |= (TR2_SUST_CHR); break;
350 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
352 switch (o_ptr->xtra2 % 11)
354 case 0: o_ptr->art_flags2 |= (TR2_RES_BLIND); break;
355 case 1: o_ptr->art_flags2 |= (TR2_RES_CONF); break;
356 case 2: o_ptr->art_flags2 |= (TR2_RES_SOUND); break;
357 case 3: o_ptr->art_flags2 |= (TR2_RES_SHARDS); break;
358 case 4: o_ptr->art_flags2 |= (TR2_RES_NETHER); break;
359 case 5: o_ptr->art_flags2 |= (TR2_RES_NEXUS); break;
360 case 6: o_ptr->art_flags2 |= (TR2_RES_CHAOS); break;
361 case 7: o_ptr->art_flags2 |= (TR2_RES_DISEN); break;
362 case 8: o_ptr->art_flags2 |= (TR2_RES_POIS); break;
363 case 9: o_ptr->art_flags2 |= (TR2_RES_DARK); break;
364 case 10: o_ptr->art_flags2 |= (TR2_RES_LITE); break;
368 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
370 switch (o_ptr->xtra2 % 8)
372 case 0: o_ptr->art_flags3 |= (TR3_FEATHER); break;
373 case 1: o_ptr->art_flags3 |= (TR3_LITE); break;
374 case 2: o_ptr->art_flags3 |= (TR3_SEE_INVIS); break;
375 case 3: o_ptr->art_flags3 |= (TR3_WARNING); break;
376 case 4: o_ptr->art_flags3 |= (TR3_SLOW_DIGEST); break;
377 case 5: o_ptr->art_flags3 |= (TR3_REGEN); break;
378 case 6: o_ptr->art_flags2 |= (TR2_FREE_ACT); break;
379 case 7: o_ptr->art_flags2 |= (TR2_HOLD_LIFE); break;
386 if (z_older_than(10, 2, 3))
391 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
393 o_ptr->xtra3 = o_ptr->xtra1;
396 if (o_ptr->tval == TV_CAPTURE)
398 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
399 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
401 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
402 if (ironman_nightmare)
404 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
406 o_ptr->xtra4 = o_ptr->xtra5;
411 rd_byte(&o_ptr->xtra3);
412 rd_s16b(&o_ptr->xtra4);
413 rd_s16b(&o_ptr->xtra5);
416 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)))
418 o_ptr->xtra4 = o_ptr->pval;
422 /* Feeling - from 2.3.1, "savefile version 1" */
425 rd_byte(&o_ptr->feeling);
431 /* If this savefile is old, maybe we need to translate the feeling */
436 for (i = 0; i <= FEEL_MAX; i++)
438 if (game_inscriptions[i] == NULL)
443 if (streq(buf, game_inscriptions[i]))
452 /* Save the inscription */
453 if (buf[0]) o_ptr->inscription = quark_add(buf);
456 if (buf[0]) o_ptr->art_name = quark_add(buf);
458 /* The Python object */
466 /* Mega-Hack -- handle "dungeon objects" later */
467 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
469 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
471 if (z_older_than(10, 4, 9))
473 if (o_ptr->art_flags1 & TR1_MAGIC_MASTERY)
475 o_ptr->art_flags1 &= ~(TR1_MAGIC_MASTERY);
476 o_ptr->art_flags3 |= (TR3_DEC_MANA);
483 artifact_type *a_ptr;
485 /* Obtain the artifact info */
486 a_ptr = &a_info[o_ptr->name1];
488 /* Verify that artifact */
489 if (!a_ptr->name) o_ptr->name1 = 0;
495 ego_item_type *e_ptr;
497 /* Obtain the ego-item info */
498 e_ptr = &e_info[o_ptr->name2];
500 /* Verify that ego-item */
501 if (!e_ptr->name) o_ptr->name2 = 0;
512 static void rd_monster(monster_type *m_ptr)
517 /* Read the monster race */
518 rd_s16b(&m_ptr->r_idx);
520 if (z_older_than(11, 0, 12))
521 m_ptr->ap_r_idx = m_ptr->r_idx;
523 rd_s16b(&m_ptr->ap_r_idx);
525 if (z_older_than(11, 0, 14))
527 monster_race *r_ptr = &r_info[m_ptr->r_idx];
529 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
530 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
531 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
534 rd_byte(&m_ptr->sub_align);
536 /* Read the other information */
540 rd_s16b(&m_ptr->maxhp);
541 if (z_older_than(11, 0, 5))
543 m_ptr->max_maxhp = m_ptr->maxhp;
547 rd_s16b(&m_ptr->max_maxhp);
549 rd_s16b(&m_ptr->csleep);
550 rd_byte(&m_ptr->mspeed);
551 if (z_older_than(10, 4, 2))
554 m_ptr->energy_need = (s16b)tmp8u;
556 else rd_s16b(&m_ptr->energy_need);
558 if (z_older_than(11, 0, 13))
559 m_ptr->energy_need = 100 - m_ptr->energy_need;
561 if (z_older_than(10,0,7))
568 rd_byte(&m_ptr->fast);
569 rd_byte(&m_ptr->slow);
571 rd_byte(&m_ptr->stunned);
572 rd_byte(&m_ptr->confused);
573 rd_byte(&m_ptr->monfear);
575 if (z_older_than(10,0,10))
579 else if (z_older_than(10,0,11))
587 rd_s16b(&m_ptr->target_y);
588 rd_s16b(&m_ptr->target_x);
591 /* Monster invulnerability introduced from 2.3.2+ */
595 rd_byte(&m_ptr->invulner);
597 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
598 rd_u32b(&m_ptr->smart);
602 if (z_older_than(10, 4, 5))
605 rd_u32b(&m_ptr->exp);
607 if (z_older_than(10, 2, 2))
609 if (m_ptr->r_idx < 0)
611 m_ptr->r_idx = (0-m_ptr->r_idx);
612 m_ptr->mflag2 |= MFLAG_KAGE;
617 rd_byte(&m_ptr->mflag2);
620 if (z_older_than(11, 0, 12))
622 if (m_ptr->mflag2 & MFLAG_KAGE)
623 m_ptr->ap_r_idx = MON_KAGE;
626 if (z_older_than(10, 1, 3))
633 if (buf[0]) m_ptr->nickname = quark_add(buf);
644 * Read the monster lore
646 static void rd_lore(int r_idx)
650 monster_race *r_ptr = &r_info[r_idx];
652 /* Count sights/deaths/kills */
653 rd_s16b(&r_ptr->r_sights);
654 rd_s16b(&r_ptr->r_deaths);
655 rd_s16b(&r_ptr->r_pkills);
656 rd_s16b(&r_ptr->r_tkills);
658 /* Count wakes and ignores */
659 rd_byte(&r_ptr->r_wake);
660 rd_byte(&r_ptr->r_ignore);
663 rd_byte(&r_ptr->r_xtra1);
664 rd_byte(&r_ptr->r_xtra2);
667 rd_byte(&r_ptr->r_drop_gold);
668 rd_byte(&r_ptr->r_drop_item);
671 rd_byte(&r_ptr->r_cast_inate);
672 rd_byte(&r_ptr->r_cast_spell);
674 /* Count blows of each type */
675 rd_byte(&r_ptr->r_blows[0]);
676 rd_byte(&r_ptr->r_blows[1]);
677 rd_byte(&r_ptr->r_blows[2]);
678 rd_byte(&r_ptr->r_blows[3]);
681 rd_u32b(&r_ptr->r_flags1);
682 rd_u32b(&r_ptr->r_flags2);
683 rd_u32b(&r_ptr->r_flags3);
684 rd_u32b(&r_ptr->r_flags4);
685 rd_u32b(&r_ptr->r_flags5);
686 rd_u32b(&r_ptr->r_flags6);
688 /* Read the "Racial" monster limit per level */
689 rd_byte(&r_ptr->max_num);
696 /* Repair the lore flags */
697 r_ptr->r_flags1 &= r_ptr->flags1;
698 r_ptr->r_flags2 &= r_ptr->flags2;
699 r_ptr->r_flags3 &= r_ptr->flags3;
700 r_ptr->r_flags4 &= r_ptr->flags4;
701 r_ptr->r_flags5 &= r_ptr->flags5;
702 r_ptr->r_flags6 &= r_ptr->flags6;
709 * Add the item "o_ptr" to the inventory of the "Home"
711 * In all cases, return the slot (or -1) where the object was placed
713 * Note that this is a hacked up version of "inven_carry()".
715 * Also note that it may not correctly "adapt" to "knowledge" bacoming
716 * known, the player may have to pick stuff up and drop it again.
718 static void home_carry(store_type *st_ptr, object_type *o_ptr)
726 /* Check each existing item (try to combine) */
727 for (slot = 0; slot < st_ptr->stock_num; slot++)
729 /* Get the existing item */
730 j_ptr = &st_ptr->stock[slot];
732 /* The home acts just like the player */
733 if (object_similar(j_ptr, o_ptr))
735 /* Save the new number of items */
736 object_absorb(j_ptr, o_ptr);
744 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
748 /* Determine the "value" of the item */
749 value = object_value(o_ptr);
751 /* Check existing slots to see if we must "slide" */
752 for (slot = 0; slot < st_ptr->stock_num; slot++)
755 j_ptr = &st_ptr->stock[slot];
757 /* Hack -- readable books always come first */
758 if ((o_ptr->tval == mp_ptr->spell_book) &&
759 (j_ptr->tval != mp_ptr->spell_book)) break;
760 if ((j_ptr->tval == mp_ptr->spell_book) &&
761 (o_ptr->tval != mp_ptr->spell_book)) continue;
763 /* Objects sort by decreasing type */
764 if (o_ptr->tval > j_ptr->tval) break;
765 if (o_ptr->tval < j_ptr->tval) continue;
767 /* Can happen in the home */
768 if (!object_aware_p(o_ptr)) continue;
769 if (!object_aware_p(j_ptr)) break;
771 /* Objects sort by increasing sval */
772 if (o_ptr->sval < j_ptr->sval) break;
773 if (o_ptr->sval > j_ptr->sval) continue;
775 /* Objects in the home can be unknown */
776 if (!object_known_p(o_ptr)) continue;
777 if (!object_known_p(j_ptr)) break;
780 * Hack: otherwise identical rods sort by
781 * increasing recharge time --dsb
783 if (o_ptr->tval == TV_ROD)
785 if (o_ptr->pval < j_ptr->pval) break;
786 if (o_ptr->pval > j_ptr->pval) continue;
789 /* Objects sort by decreasing value */
790 j_value = object_value(j_ptr);
791 if (value > j_value) break;
792 if (value < j_value) continue;
795 /* Slide the others up */
796 for (i = st_ptr->stock_num; i > slot; i--)
798 st_ptr->stock[i] = st_ptr->stock[i-1];
804 /* Insert the new item */
805 st_ptr->stock[slot] = *o_ptr;
807 chg_virtue(V_SACRIFICE, -1);
809 /* Return the location */
817 static errr rd_store(int town_number, int store_number)
829 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
831 st_ptr = &town[1].store[store_number];
832 if (st_ptr->stock_num) sort = TRUE;
836 st_ptr = &town[town_number].store[store_number];
839 /* Read the basic info */
840 rd_s32b(&st_ptr->store_open);
841 rd_s16b(&st_ptr->insult_cur);
843 if (z_older_than(11, 0, 4))
852 rd_s16b(&st_ptr->good_buy);
853 rd_s16b(&st_ptr->bad_buy);
855 /* Read last visit */
856 rd_s32b(&st_ptr->last_visit);
858 /* Extract the owner (see above) */
862 for (j = 0; j < num; j++)
867 /* Get local object */
870 /* Wipe the object */
876 /* Acquire valid items */
877 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
882 home_carry(st_ptr, q_ptr);
886 k = st_ptr->stock_num++;
888 /* Acquire the item */
889 object_copy(&st_ptr->stock[k], q_ptr);
901 * Read RNG state (added in 2.8.0)
903 static void rd_randomizer(void)
913 rd_u16b(&Rand_place);
916 for (i = 0; i < RAND_DEG; i++)
918 rd_u32b(&Rand_state[i]);
928 * Read options (ignore most pre-2.8.0 options)
930 * Note that the normal options are now stored as a set of 256 bit flags,
931 * plus a set of 256 bit masks to indicate which bit flags were defined
932 * at the time the savefile was created. This will allow new options
933 * to be added, and old options to be removed, at any time, without
934 * hurting old savefiles.
936 * The window options are stored in the same way, but note that each
937 * window gets 32 options, and their order is fixed by certain defines.
939 static void rd_options(void)
953 /* Ignore old options */
959 /* Read "delay_factor" */
963 /* Read "hitpoint_warn" */
968 /*** Cheating options ***/
972 if (c & 0x0002) wizard = TRUE;
974 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
975 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
976 cheat_room = (c & 0x0400) ? TRUE : FALSE;
977 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
978 cheat_know = (c & 0x1000) ? TRUE : FALSE;
979 cheat_live = (c & 0x2000) ? TRUE : FALSE;
981 rd_byte((byte *)&autosave_l);
982 rd_byte((byte *)&autosave_t);
983 rd_s16b(&autosave_freq);
986 /*** Normal Options ***/
988 /* Read the option flags */
989 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
991 /* Read the option masks */
992 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
994 /* Analyze the options */
995 for (n = 0; n < 8; n++)
997 /* Analyze the options */
998 for (i = 0; i < 32; i++)
1000 /* Process valid flags */
1001 if (mask[n] & (1L << i))
1003 /* Process valid flags */
1004 if (option_mask[n] & (1L << i))
1007 if (flag[n] & (1L << i))
1010 option_flag[n] |= (1L << i);
1017 option_flag[n] &= ~(1L << i);
1024 if (z_older_than(10, 4, 5))
1026 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1027 else option_flag[5] |= (0x00000001 << 4);
1028 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1029 else option_flag[2] |= (0x00000001 << 5);
1030 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1031 else option_flag[4] |= (0x00000001 << 5);
1032 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1033 else option_flag[5] |= (0x00000001 << 0);
1034 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1035 else option_flag[5] |= (0x00000001 << 12);
1036 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1037 else option_flag[1] |= (0x00000001 << 0);
1038 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1039 else option_flag[1] |= (0x00000001 << 18);
1040 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1041 else option_flag[1] |= (0x00000001 << 19);
1042 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1043 else option_flag[5] |= (0x00000001 << 3);
1047 /*** Window Options ***/
1049 /* Read the window flags */
1050 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1052 /* Read the window masks */
1053 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1055 /* Analyze the options */
1056 for (n = 0; n < 8; n++)
1058 /* Analyze the options */
1059 for (i = 0; i < 32; i++)
1061 /* Process valid flags */
1062 if (mask[n] & (1L << i))
1064 /* Process valid flags */
1065 if (window_mask[n] & (1L << i))
1068 if (flag[n] & (1L << i))
1071 window_flag[n] |= (1L << i);
1078 window_flag[n] &= ~(1L << i);
1091 * Hack -- strip the "ghost" info
1093 * XXX XXX XXX This is such a nasty hack it hurts.
1095 static void rd_ghost(void)
1102 /* Strip old data */
1108 * Save quick start data
1110 void load_quick_start()
1115 if (z_older_than(11, 0, 13))
1117 previous_char.quick_ok = FALSE;
1121 rd_byte(&previous_char.psex);
1122 rd_byte(&previous_char.prace);
1123 rd_byte(&previous_char.pclass);
1124 rd_byte(&previous_char.pseikaku);
1125 rd_byte(&previous_char.realm1);
1126 rd_byte(&previous_char.realm2);
1128 rd_s16b(&previous_char.age);
1129 rd_s16b(&previous_char.ht);
1130 rd_s16b(&previous_char.wt);
1131 rd_s16b(&previous_char.sc);
1132 rd_s32b(&previous_char.au);
1134 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1135 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1137 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1139 rd_s16b(&previous_char.chaos_patron);
1141 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1143 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], 60);
1145 rd_byte(&previous_char.quests);
1148 previous_char.quick_ok = (bool)tmp8u;
1152 * Read the "extra" information
1154 static void rd_extra(void)
1161 rd_string(player_name, 32);
1163 rd_string(died_from, 80);
1167 for (i = 0; i < 4; i++)
1169 rd_string(history[i], 60);
1172 /* Class/Race/Seikaku/Gender/Spells */
1173 rd_byte(&p_ptr->prace);
1174 rd_byte(&p_ptr->pclass);
1175 rd_byte(&p_ptr->pseikaku);
1176 rd_byte(&p_ptr->psex);
1177 rd_byte(&p_ptr->realm1);
1178 rd_byte(&p_ptr->realm2);
1179 rd_byte(&tmp8u); /* oops */
1181 if (z_older_than(10, 4, 4))
1183 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1184 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1185 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1186 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1189 /* Special Race/Class info */
1190 rd_byte(&p_ptr->hitdie);
1191 rd_u16b(&p_ptr->expfact);
1193 /* Age/Height/Weight */
1194 rd_s16b(&p_ptr->age);
1195 rd_s16b(&p_ptr->ht);
1196 rd_s16b(&p_ptr->wt);
1198 /* Read the stat info */
1199 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1200 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1201 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1203 strip_bytes(24); /* oops */
1205 rd_s32b(&p_ptr->au);
1207 rd_s32b(&p_ptr->max_exp);
1208 rd_s32b(&p_ptr->exp);
1209 rd_u16b(&p_ptr->exp_frac);
1211 rd_s16b(&p_ptr->lev);
1213 for (i = 0; i < 64; i++) rd_s16b(&spell_exp[i]);
1214 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1216 for (i = 0; i < 64; i++) spell_exp[i] = 1600;
1218 if (z_older_than(10, 3, 6))
1219 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&weapon_exp[i][j]);
1221 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&weapon_exp[i][j]);
1222 for (i = 0; i < 10; i++) rd_s16b(&skill_exp[i]);
1223 if (z_older_than(10, 4, 1))
1225 if (p_ptr->pclass != CLASS_BEASTMASTER) skill_exp[GINOU_RIDING] /= 2;
1226 skill_exp[GINOU_RIDING] = MIN(skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1228 if (z_older_than(10, 3, 14))
1230 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1231 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1235 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1236 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1238 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1240 if (z_older_than(11, 0, 7))
1242 p_ptr->start_race = p_ptr->prace;
1243 p_ptr->old_race1 = 0L;
1244 p_ptr->old_race2 = 0L;
1245 p_ptr->old_realm = 0;
1249 rd_byte(&p_ptr->start_race);
1250 rd_s32b(&p_ptr->old_race1);
1251 rd_s32b(&p_ptr->old_race2);
1252 rd_s16b(&p_ptr->old_realm);
1255 if (z_older_than(10, 0, 1))
1257 for (i = 0; i < OLD_MAX_MANE; i++)
1264 else if (z_older_than(10, 2, 3))
1266 for (i = 0; i < OLD_MAX_MANE; i++)
1271 for (i = 0; i < MAX_MANE; i++)
1281 for (i = 0; i < MAX_MANE; i++)
1283 rd_s16b(&mane_spell[i]);
1284 rd_s16b(&mane_dam[i]);
1289 if (z_older_than(10, 0, 3))
1291 get_mon_num_prep(NULL, NULL);
1292 for (i = 0; i < MAX_KUBI; i++)
1294 monster_race *r_ptr;
1299 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1300 r_ptr = &r_info[kubi_r_idx[i]];
1302 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1304 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1306 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1308 for (j = 0; j < i; j++)
1309 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1314 for (i = 0; i < MAX_KUBI -1; i++)
1317 for (j = i; j < MAX_KUBI; j++)
1319 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1321 tmp = kubi_r_idx[i];
1322 kubi_r_idx[i] = kubi_r_idx[j];
1323 kubi_r_idx[j] = tmp;
1327 for (i = 0; i < MAX_KUBI; i++)
1329 if(!r_info[kubi_r_idx[i]].max_num)
1330 kubi_r_idx[i] += 10000;
1335 for (i = 0; i < MAX_KUBI; i++)
1337 rd_s16b(&kubi_r_idx[i]);
1341 if (z_older_than(10, 0, 3))
1347 for (i = 0; i < 4; i++)
1349 rd_s16b(&battle_mon[i]);
1350 if (z_older_than(10, 3, 4))
1353 mon_odds[i] = tmp16s;
1355 else rd_u32b(&mon_odds[i]);
1359 rd_s16b(&p_ptr->town_num);
1361 /* Read arena and rewards information */
1362 rd_s16b(&p_ptr->arena_number);
1364 p_ptr->inside_arena = (bool)tmp16s;
1365 rd_s16b(&p_ptr->inside_quest);
1366 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1370 p_ptr->inside_battle = (bool)tmp16s;
1372 rd_byte(&p_ptr->exit_bldg);
1373 rd_byte(&p_ptr->leftbldg);
1375 rd_s16b(&p_ptr->oldpx);
1376 rd_s16b(&p_ptr->oldpy);
1377 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1381 if (tmp16s > MAX_BACT)
1384 note(format("¤ÎÃæ", tmp16s));
1386 note(format("Too many (%d) building rewards!", tmp16s));
1391 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1393 rd_s16b(&p_ptr->mhp);
1394 rd_s16b(&p_ptr->chp);
1395 rd_u16b(&p_ptr->chp_frac);
1397 rd_s16b(&p_ptr->msp);
1398 rd_s16b(&p_ptr->csp);
1399 rd_u16b(&p_ptr->csp_frac);
1401 rd_s16b(&p_ptr->max_plv);
1402 if (z_older_than(10, 3, 8))
1404 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1408 byte max = (byte)max_d_idx;
1412 for(i = 0; i < max; i++)
1414 rd_s16b(&max_dlv[i]);
1415 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1419 /* Repair maximum player level XXX XXX XXX */
1420 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1424 rd_s16b(&p_ptr->sc);
1427 /* Read the flags */
1428 strip_bytes(2); /* Old "rest" */
1429 rd_s16b(&p_ptr->blind);
1430 rd_s16b(&p_ptr->paralyzed);
1431 rd_s16b(&p_ptr->confused);
1432 rd_s16b(&p_ptr->food);
1433 strip_bytes(4); /* Old "food_digested" / "protection" */
1435 rd_s16b(&p_ptr->energy_need);
1436 if (z_older_than(11, 0, 13))
1437 p_ptr->energy_need = 100 - p_ptr->energy_need;
1439 rd_s16b(&p_ptr->fast);
1440 rd_s16b(&p_ptr->slow);
1441 rd_s16b(&p_ptr->afraid);
1442 rd_s16b(&p_ptr->cut);
1443 rd_s16b(&p_ptr->stun);
1444 rd_s16b(&p_ptr->poisoned);
1445 rd_s16b(&p_ptr->image);
1446 rd_s16b(&p_ptr->protevil);
1447 rd_s16b(&p_ptr->invuln);
1448 if(z_older_than(10, 0, 0))
1451 rd_s16b(&p_ptr->ult_res);
1452 rd_s16b(&p_ptr->hero);
1453 rd_s16b(&p_ptr->shero);
1454 rd_s16b(&p_ptr->shield);
1455 rd_s16b(&p_ptr->blessed);
1456 rd_s16b(&p_ptr->tim_invis);
1457 rd_s16b(&p_ptr->word_recall);
1458 if (z_older_than(10, 3, 8))
1459 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1463 p_ptr->recall_dungeon = (byte)tmp16s;
1465 rd_s16b(&p_ptr->see_infra);
1466 rd_s16b(&p_ptr->tim_infra);
1467 rd_s16b(&p_ptr->oppose_fire);
1468 rd_s16b(&p_ptr->oppose_cold);
1469 rd_s16b(&p_ptr->oppose_acid);
1470 rd_s16b(&p_ptr->oppose_elec);
1471 rd_s16b(&p_ptr->oppose_pois);
1472 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1473 else rd_s16b(&p_ptr->tsuyoshi);
1475 /* Old savefiles do not have the following fields... */
1476 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1479 p_ptr->wraith_form = 0;
1480 p_ptr->resist_magic = 0;
1481 p_ptr->tim_regen = 0;
1482 p_ptr->kabenuke = 0;
1483 p_ptr->tim_stealth = 0;
1484 p_ptr->tim_ffall = 0;
1485 p_ptr->tim_sh_touki = 0;
1486 p_ptr->lightspeed = 0;
1487 p_ptr->tsubureru = 0;
1488 p_ptr->tim_res_nether = 0;
1489 p_ptr->tim_res_time = 0;
1490 p_ptr->mimic_form = 0;
1491 p_ptr->tim_mimic = 0;
1492 p_ptr->tim_sh_fire = 0;
1495 p_ptr->tim_reflect = 0;
1496 p_ptr->multishadow = 0;
1497 p_ptr->dustrobe = 0;
1499 p_ptr->chaos_patron = get_chaos_patron();
1507 rd_s16b(&p_ptr->tim_esp);
1508 rd_s16b(&p_ptr->wraith_form);
1509 rd_s16b(&p_ptr->resist_magic);
1510 rd_s16b(&p_ptr->tim_regen);
1511 rd_s16b(&p_ptr->kabenuke);
1512 rd_s16b(&p_ptr->tim_stealth);
1513 rd_s16b(&p_ptr->tim_ffall);
1514 rd_s16b(&p_ptr->tim_sh_touki);
1515 rd_s16b(&p_ptr->lightspeed);
1516 rd_s16b(&p_ptr->tsubureru);
1517 if (z_older_than(10, 4, 7))
1518 p_ptr->magicdef = 0;
1520 rd_s16b(&p_ptr->magicdef);
1521 rd_s16b(&p_ptr->tim_res_nether);
1522 if (z_older_than(10, 4, 11))
1524 p_ptr->tim_res_time = 0;
1525 p_ptr->mimic_form = 0;
1526 p_ptr->tim_mimic = 0;
1527 p_ptr->tim_sh_fire = 0;
1531 rd_s16b(&p_ptr->tim_res_time);
1532 rd_byte(&p_ptr->mimic_form);
1533 rd_s16b(&p_ptr->tim_mimic);
1534 rd_s16b(&p_ptr->tim_sh_fire);
1538 if ( z_older_than(11,0,3) ){
1539 p_ptr->tim_reflect=0;
1540 p_ptr->multishadow=0;
1544 rd_s16b(&p_ptr->tim_reflect);
1545 rd_s16b(&p_ptr->multishadow);
1546 rd_s16b(&p_ptr->dustrobe);
1549 rd_s16b(&p_ptr->chaos_patron);
1550 rd_u32b(&p_ptr->muta1);
1551 rd_u32b(&p_ptr->muta2);
1552 rd_u32b(&p_ptr->muta3);
1554 for (i = 0; i < 8; i++)
1555 rd_s16b(&p_ptr->virtues[i]);
1556 for (i = 0; i < 8; i++)
1557 rd_s16b(&p_ptr->vir_types[i]);
1560 /* Calc the regeneration modifier for mutations */
1561 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1563 if (z_older_than(10,0,9))
1566 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1567 p_ptr->ele_attack = 0;
1571 rd_s16b(&p_ptr->ele_attack);
1572 rd_u32b(&p_ptr->special_attack);
1574 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1575 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1576 if (z_older_than(10,0,12))
1578 p_ptr->ele_immune = 0;
1579 p_ptr->special_defense = 0;
1583 rd_s16b(&p_ptr->ele_immune);
1584 rd_u32b(&p_ptr->special_defense);
1586 rd_byte(&p_ptr->knowledge);
1587 rd_byte(&tmp8u); /* oops */
1588 rd_byte(&tmp8u); /* oops */
1589 rd_byte(&p_ptr->action);
1590 if (!z_older_than(10, 4, 3))
1593 if (tmp8u) p_ptr->action = ACTION_LEARN;
1595 rd_byte((byte *)&preserve_mode);
1596 rd_byte((byte *)&wait_report_score);
1599 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1601 /* Skip the flags */
1605 /* Hack -- the two "special seeds" */
1606 rd_u32b(&seed_flavor);
1607 rd_u32b(&seed_town);
1611 rd_u16b(&panic_save);
1612 rd_u16b(&total_winner);
1620 /* Read "feeling" */
1624 /* Turn of last "feeling" */
1630 if (z_older_than(10, 3, 12))
1632 dungeon_turn = turn;
1634 else rd_s32b(&dungeon_turn);
1636 if (z_older_than(11, 0, 13))
1643 if (z_older_than(10, 3, 13))
1647 else rd_s32b(&old_battle);
1649 if (z_older_than(10,0,3))
1651 monster_race *r_ptr;
1655 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1656 r_ptr = &r_info[today_mon];
1658 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1659 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1660 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1661 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1662 if (r_ptr->rarity > 10) continue;
1663 if (r_ptr->level == 0) continue;
1667 p_ptr->today_mon = 0;
1671 rd_s16b(&today_mon);
1672 rd_s16b(&p_ptr->today_mon);
1675 if (z_older_than(10,0,7))
1681 rd_s16b(&p_ptr->riding);
1684 if (z_older_than(10,1,2))
1693 if (z_older_than(10,3,9))
1697 else if (z_older_than(10, 3, 10))
1705 rd_s32b(&p_ptr->visit);
1707 if (!z_older_than(11, 0, 5))
1709 rd_u32b(&p_ptr->count);
1717 * Read the player inventory
1719 * Note that the inventory changed in Angband 2.7.4. Two extra
1720 * pack slots were added and the equipment was rearranged. Note
1721 * that these two features combine when parsing old save-files, in
1722 * which items from the old "aux" slot are "carried", perhaps into
1723 * one of the two new "inventory" slots.
1725 * Note that the inventory is "re-sorted" later by "dungeon()".
1727 static errr rd_inventory(void)
1735 p_ptr->total_weight = 0;
1741 /* Read until done */
1746 /* Get the next item index */
1749 /* Nope, we reached the end */
1750 if (n == 0xFFFF) break;
1752 /* Get local object */
1755 /* Wipe the object */
1761 /* Hack -- verify item */
1762 if (!q_ptr->k_idx) return (53);
1764 /* Wield equipment */
1765 if (n >= INVEN_RARM)
1768 object_copy(&inventory[n], q_ptr);
1770 /* Add the weight */
1771 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1777 /* Warning -- backpack is full */
1778 else if (inven_cnt == INVEN_PACK)
1782 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1784 note("Too many items in the inventory!");
1792 /* Carry inventory */
1799 object_copy(&inventory[n], q_ptr);
1801 /* Add the weight */
1802 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1816 * Read the saved messages
1818 static void rd_messages(void)
1828 /* Read the messages */
1829 for (i = 0; i < num; i++)
1831 /* Read the message */
1832 rd_string(buf, 128);
1834 /* Save the message */
1844 * The monsters/objects must be loaded in the same order
1845 * that they were stored, since the actual indexes matter.
1847 static errr rd_dungeon(void)
1858 /*** Basic info ***/
1861 rd_s16b(&dun_level);
1862 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1863 else rd_byte(&dungeon_type);
1865 /* Set the base level for old versions */
1866 base_level = dun_level;
1868 rd_s16b(&base_level);
1870 rd_s16b(&num_repro);
1875 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1878 rd_s16b(&tmp16s); /* max_panel_rows */
1879 rd_s16b(&tmp16s); /* max_panel_cols */
1882 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1890 /*** Run length decoding ***/
1892 /* Load the dungeon data */
1893 for (x = y = 0; y < ymax; )
1897 if (z_older_than(10,3,6))
1902 /* Apply the RLE info */
1903 for (i = count; i > 0; i--)
1905 /* Access the cave */
1906 c_ptr = &cave[y][x];
1908 /* Extract "info" */
1909 if (z_older_than(10,3,6))
1910 c_ptr->info = tmp8u;
1911 else c_ptr->info = tmp16s;
1920 if (++y >= ymax) break;
1926 /*** Run length decoding ***/
1928 /* Load the dungeon data */
1929 for (x = y = 0; y < ymax; )
1935 /* Apply the RLE info */
1936 for (i = count; i > 0; i--)
1938 /* Access the cave */
1939 c_ptr = &cave[y][x];
1941 if (c_ptr->feat == FEAT_INVIS)
1943 c_ptr->feat = FEAT_FLOOR;
1944 c_ptr->info |= CAVE_TRAP;
1947 /* Extract "feat" */
1948 c_ptr->feat = tmp8u;
1957 if (++y >= ymax) break;
1962 /*** Run length decoding ***/
1964 /* Load the dungeon data */
1965 for (x = y = 0; y < ymax; )
1971 /* Apply the RLE info */
1972 for (i = count; i > 0; i--)
1974 /* Access the cave */
1975 c_ptr = &cave[y][x];
1977 /* Extract "feat" */
1978 c_ptr->mimic = tmp8u;
1987 if (++y >= ymax) break;
1992 /*** Run length decoding ***/
1994 /* Load the dungeon data */
1995 for (x = y = 0; y < ymax; )
2001 /* Apply the RLE info */
2002 for (i = count; i > 0; i--)
2004 /* Access the cave */
2005 c_ptr = &cave[y][x];
2007 /* Extract "feat" */
2008 c_ptr->special = tmp16s;
2017 if (++y >= ymax) break;
2024 /* Read the item count */
2027 /* Verify maximum */
2028 if (limit >= max_o_idx)
2031 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2033 note(format("Too many (%d) object entries!", limit));
2039 /* Read the dungeon items */
2040 for (i = 1; i < limit; i++)
2047 /* Get a new record */
2054 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2056 note(format("Object allocation error (%d <> %d)", i, o_idx));
2064 o_ptr = &o_list[o_idx];
2070 /* XXX XXX XXX XXX XXX */
2073 if (o_ptr->held_m_idx)
2075 monster_type *m_ptr;
2078 m_ptr = &m_list[o_ptr->held_m_idx];
2081 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2083 /* Place the object */
2084 m_ptr->hold_o_idx = o_idx;
2090 /* Access the item location */
2091 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2094 o_ptr->next_o_idx = c_ptr->o_idx;
2096 /* Place the object */
2097 c_ptr->o_idx = o_idx;
2104 /* Read the monster count */
2107 /* Hack -- verify */
2108 if (limit >= max_m_idx)
2111 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2113 note(format("Too many (%d) monster entries!", limit));
2119 /* Read the monsters */
2120 for (i = 1; i < limit; i++)
2124 monster_type *m_ptr;
2126 monster_race *r_ptr;
2129 /* Get a new record */
2136 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2138 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2145 /* Acquire monster */
2146 m_ptr = &m_list[m_idx];
2148 /* Read the monster */
2153 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2155 /* Mark the location */
2156 c_ptr->m_idx = m_idx;
2160 r_ptr = &r_info[m_ptr->r_idx];
2162 /* Count XXX XXX XXX */
2168 /* The dungeon is ready */
2169 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2170 character_dungeon = FALSE;
2172 character_dungeon = TRUE;
2181 * Actually read the savefile
2183 static errr rd_savefile_new_aux(void)
2195 #ifdef VERIFY_CHECKSUMS
2196 u32b n_x_check, n_v_check;
2197 u32b o_x_check, o_v_check;
2201 /* Mention the savefile version */
2203 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2205 note(format("Loading a %d.%d.%d savefile...",
2208 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2211 /* Strip the version bytes */
2214 /* Hack -- decrypt */
2215 xor_byte = sf_extra;
2218 /* Clear the checksums */
2222 #if SAVEFILE_VERSION
2223 /* Read the version number of the savefile */
2224 rd_u32b(&sf_version);
2225 #endif /* SAVEFILE_VERSION */
2227 /* Operating system info */
2230 /* Time of savefile creation */
2233 /* Number of resurrections */
2236 /* Number of times played */
2240 /* Later use (always zero) */
2243 /* Later use (always zero) */
2247 /* Read RNG state */
2250 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2252 if (arg_fiddle) note("Loaded Randomizer Info");
2257 /* Then the options */
2260 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2262 if (arg_fiddle) note("Loaded Option Flags");
2266 * Munchkin players are marked
2268 * XXX - should be replaced with a better method,
2269 * after the new scorefile-handling is implemented.
2277 /* Then the "messages" */
2280 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2282 if (arg_fiddle) note("Loaded Messages");
2287 for (i = 0; i < max_r_idx; i++)
2289 monster_race *r_ptr;
2290 /* Access that monster */
2293 /* Hack -- Reset the death counter */
2294 r_ptr->max_num = 100;
2295 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2296 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2299 /* Monster Memory */
2302 /* Incompatible save files */
2303 if (tmp16u > max_r_idx)
2306 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2308 note(format("Too many (%u) monster races!", tmp16u));
2314 /* Read the available records */
2315 for (i = 0; i < tmp16u; i++)
2317 monster_race *r_ptr;
2322 /* Access that monster */
2327 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2329 if (arg_fiddle) note("Loaded Monster Memory");
2337 /* Incompatible save files */
2338 if (tmp16u > max_k_idx)
2341 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2343 note(format("Too many (%u) object kinds!", tmp16u));
2349 /* Read the object memory */
2350 for (i = 0; i < tmp16u; i++)
2353 object_kind *k_ptr = &k_info[i];
2357 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2358 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2361 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2363 if (arg_fiddle) note("Loaded Object Memory");
2369 * Initialize arena and rewards information
2371 p_ptr->arena_number = 0;
2372 p_ptr->inside_arena = 0;
2373 p_ptr->inside_quest = 0;
2374 p_ptr->leftbldg = FALSE;
2375 p_ptr->exit_bldg = TRUE;
2377 /* Start in town 1 */
2378 p_ptr->town_num = 1;
2380 p_ptr->wilderness_x = 4;
2381 p_ptr->wilderness_y = 4;
2385 /* Init the wilderness seeds */
2386 for (i = 0; i < max_wild_x; i++)
2388 for (j = 0; j < max_wild_y; j++)
2390 wilderness[j][i].seed = randint0(0x10000000);
2394 /* 2.1.3 or newer version */
2396 u16b max_towns_load;
2397 u16b max_quests_load;
2398 byte max_rquests_load;
2399 s16b old_inside_quest = p_ptr->inside_quest;
2401 /* Number of towns */
2402 rd_u16b(&max_towns_load);
2404 /* Incompatible save files */
2405 if (max_towns_load > max_towns)
2408 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2410 note(format("Too many (%u) towns!", max_towns_load));
2416 /* Number of quests */
2417 rd_u16b(&max_quests_load);
2419 if (z_older_than(11, 0, 7))
2421 max_rquests_load = 10;
2425 rd_byte(&max_rquests_load);
2428 /* Incompatible save files */
2429 if (max_quests_load > max_quests)
2432 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2434 note(format("Too many (%u) quests!", max_quests_load));
2440 for (i = 0; i < max_quests_load; i++)
2444 rd_s16b(&quest[i].status);
2445 rd_s16b(&quest[i].level);
2447 if (z_older_than(11, 0, 6))
2449 quest[i].complev = 0;
2453 rd_byte(&quest[i].complev);
2456 /* Load quest status if quest is running */
2457 if (quest[i].status == QUEST_STATUS_TAKEN || (!z_older_than(10, 3, 14) && (quest[i].status == QUEST_STATUS_COMPLETED)) || (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST+max_rquests_load))))
2459 rd_s16b(&quest[i].cur_num);
2460 rd_s16b(&quest[i].max_num);
2461 rd_s16b(&quest[i].type);
2463 /* Load quest monster index */
2464 rd_s16b(&quest[i].r_idx);
2466 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2471 monster_race *r_ptr;
2474 * Random monster 5 - 10 levels out of depth
2475 * (depending on level)
2477 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
2478 r_ptr = &r_info[r_idx];
2480 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2482 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2484 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2486 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2488 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2491 * Accept monsters that are 2 - 6 levels
2492 * out of depth depending on the quest level
2494 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2497 quest[i].r_idx = r_idx;
2500 /* Load quest item index */
2501 rd_s16b(&quest[i].k_idx);
2504 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
2506 rd_byte(&quest[i].flags);
2508 if (z_older_than(10, 3, 11))
2510 if (quest[i].flags & QUEST_FLAG_PRESET)
2512 quest[i].dungeon = 0;
2516 init_flags = INIT_ASSIGN;
2517 p_ptr->inside_quest = i;
2519 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2520 p_ptr->inside_quest = old_inside_quest;
2525 rd_byte(&quest[i].dungeon);
2528 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2529 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2530 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2533 /* Ignore the empty quests from old versions */
2536 /* Ignore quest status */
2539 /* Ignore quest level */
2543 * We don't have to care about the other info,
2544 * since status should be 0 for these quests anyway
2549 /* Position in the wilderness */
2550 rd_s32b(&p_ptr->wilderness_x);
2551 rd_s32b(&p_ptr->wilderness_y);
2552 if (z_older_than(10, 3, 13))
2554 p_ptr->wilderness_x = 5;
2555 p_ptr->wilderness_y = 48;
2558 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2559 else rd_byte((byte *)&p_ptr->wild_mode);
2560 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2561 else rd_byte((byte *)&ambush_flag);
2563 /* Size of the wilderness */
2564 rd_s32b(&wild_x_size);
2565 rd_s32b(&wild_y_size);
2567 /* Incompatible save files */
2568 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2571 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2573 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2579 /* Load the wilderness seeds */
2580 for (i = 0; i < wild_x_size; i++)
2582 for (j = 0; j < wild_y_size; j++)
2584 rd_u32b(&wilderness[j][i].seed);
2590 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2592 if (arg_fiddle) note("Loaded Quests");
2595 /* Load the Artifacts */
2598 /* Incompatible save files */
2599 if (tmp16u > max_a_idx)
2602 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2604 note(format("Too many (%u) artifacts!", tmp16u));
2610 /* Read the artifact flags */
2611 for (i = 0; i < tmp16u; i++)
2614 a_info[i].cur_num = tmp8u;
2620 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2622 if (arg_fiddle) note("Loaded Artifacts");
2627 /* Read the extra stuff */
2629 if (p_ptr->energy_need < -999) world_player = TRUE;
2632 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2634 if (arg_fiddle) note("Loaded extra information");
2638 /* Read the player_hp array */
2641 /* Incompatible save files */
2642 if (tmp16u > PY_MAX_LEVEL)
2645 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2647 note(format("Too many (%u) hitpoint entries!", tmp16u));
2653 /* Read the player_hp array */
2654 for (i = 0; i < tmp16u; i++)
2656 rd_s16b(&player_hp[i]);
2659 /* Important -- Initialize the sex */
2660 sp_ptr = &sex_info[p_ptr->psex];
2662 /* Important -- Initialize the race/class */
2663 rp_ptr = &race_info[p_ptr->prace];
2664 cp_ptr = &class_info[p_ptr->pclass];
2665 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2667 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !death)
2669 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2670 do_cmd_rerate(FALSE);
2672 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !death)
2674 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2675 do_cmd_rerate(FALSE);
2677 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !death)
2679 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2680 do_cmd_rerate(FALSE);
2682 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !death)
2684 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2685 do_cmd_rerate(FALSE);
2688 /* Important -- Initialize the magic */
2689 mp_ptr = &m_info[p_ptr->pclass];
2692 /* Read spell info */
2693 rd_u32b(&spell_learned1);
2694 rd_u32b(&spell_learned2);
2695 rd_u32b(&spell_worked1);
2696 rd_u32b(&spell_worked2);
2697 rd_u32b(&spell_forgotten1);
2698 rd_u32b(&spell_forgotten2);
2700 if (z_older_than(10,0,5))
2702 p_ptr->learned_spells = 0;
2703 for (i = 0; i < 64; i++)
2705 /* Count known spells */
2707 (spell_learned1 & (1L << i)) :
2708 (spell_learned2 & (1L << (i - 32))))
2710 p_ptr->learned_spells++;
2714 else rd_s16b(&p_ptr->learned_spells);
2716 if (z_older_than(10,0,6))
2718 p_ptr->add_spells = 0;
2720 else rd_s16b(&p_ptr->add_spells);
2721 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2723 for (i = 0; i < 64; i++)
2725 rd_byte(&spell_order[i]);
2729 /* Read the inventory */
2733 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2735 note("Unable to read inventory");
2741 /* Read number of towns */
2743 town_count = tmp16u;
2745 /* Read the stores */
2747 for (i = 1; i < town_count; i++)
2749 for (j = 0; j < tmp16u; j++)
2751 if (rd_store(i, j)) return (22);
2755 rd_s16b(&p_ptr->pet_follow_distance);
2756 if (z_older_than(10, 4, 10))
2758 p_ptr->pet_extra_flags = 0;
2760 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2762 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2764 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2768 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2771 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2775 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2778 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2782 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2785 if (!z_older_than(10,0,8))
2788 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2793 rd_s16b(&p_ptr->pet_extra_flags);
2796 if (!z_older_than(11, 0, 9))
2798 char buf[SCREEN_BUF_SIZE];
2799 rd_string(buf, SCREEN_BUF_SIZE);
2800 if (buf[0]) screen_dump = string_make(buf);
2805 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2807 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2812 /* I'm not dead yet... */
2815 /* Dead players have no dungeon */
2817 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2819 note("Restoring Dungeon...");
2825 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2827 note("Error reading dungeon data");
2833 /* Read the ghost info */
2840 strip_bytes(tmp32s);
2845 #ifdef VERIFY_CHECKSUMS
2847 /* Save the checksum */
2848 n_v_check = v_check;
2850 /* Read the old checksum */
2851 rd_u32b(&o_v_check);
2854 if (o_v_check != n_v_check)
2857 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2859 note("Invalid checksum");
2866 /* Save the encoded checksum */
2867 n_x_check = x_check;
2869 /* Read the checksum */
2870 rd_u32b(&o_x_check);
2874 if (o_x_check != n_x_check)
2877 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2879 note("Invalid encoded checksum");
2893 * Actually read the savefile
2895 errr rd_savefile_new(void)
2899 /* The savefile is a binary file */
2900 fff = my_fopen(savefile, "rb");
2903 if (!fff) return (-1);
2905 /* Call the sub-function */
2906 err = rd_savefile_new_aux();
2908 /* Check for errors */
2909 if (ferror(fff)) err = -1;
2911 /* Close the file */