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) p_ptr->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 static void load_quick_start(void)
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(p_ptr->died_from, 80);
1167 for (i = 0; i < 4; i++)
1169 rd_string(p_ptr->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(&p_ptr->spell_exp[i]);
1214 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1216 for (i = 0; i < 64; i++) p_ptr->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(&p_ptr->weapon_exp[i][j]);
1221 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1222 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1223 if (z_older_than(10, 4, 1))
1225 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1226 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->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++)
1259 p_ptr->mane_spell[i] = -1;
1260 p_ptr->mane_dam[i] = 0;
1262 p_ptr->mane_num = 0;
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++)
1273 p_ptr->mane_spell[i] = -1;
1274 p_ptr->mane_dam[i] = 0;
1277 p_ptr->mane_num = 0;
1281 for (i = 0; i < MAX_MANE; i++)
1283 rd_s16b(&p_ptr->mane_spell[i]);
1284 rd_s16b(&p_ptr->mane_dam[i]);
1286 rd_s16b(&p_ptr->mane_num);
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);
1537 if (z_older_than(11, 0, 99))
1539 p_ptr->tim_sh_holy = 0;
1540 p_ptr->tim_eyeeye = 0;
1544 rd_s16b(&p_ptr->tim_sh_holy);
1545 rd_s16b(&p_ptr->tim_eyeeye);
1549 if ( z_older_than(11,0,3) ){
1550 p_ptr->tim_reflect=0;
1551 p_ptr->multishadow=0;
1555 rd_s16b(&p_ptr->tim_reflect);
1556 rd_s16b(&p_ptr->multishadow);
1557 rd_s16b(&p_ptr->dustrobe);
1560 rd_s16b(&p_ptr->chaos_patron);
1561 rd_u32b(&p_ptr->muta1);
1562 rd_u32b(&p_ptr->muta2);
1563 rd_u32b(&p_ptr->muta3);
1565 for (i = 0; i < 8; i++)
1566 rd_s16b(&p_ptr->virtues[i]);
1567 for (i = 0; i < 8; i++)
1568 rd_s16b(&p_ptr->vir_types[i]);
1571 /* Calc the regeneration modifier for mutations */
1572 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1574 if (z_older_than(10,0,9))
1577 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1578 p_ptr->ele_attack = 0;
1582 rd_s16b(&p_ptr->ele_attack);
1583 rd_u32b(&p_ptr->special_attack);
1585 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1586 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1587 if (z_older_than(10,0,12))
1589 p_ptr->ele_immune = 0;
1590 p_ptr->special_defense = 0;
1594 rd_s16b(&p_ptr->ele_immune);
1595 rd_u32b(&p_ptr->special_defense);
1597 rd_byte(&p_ptr->knowledge);
1598 rd_byte(&tmp8u); /* oops */
1599 rd_byte(&tmp8u); /* oops */
1600 rd_byte(&p_ptr->action);
1601 if (!z_older_than(10, 4, 3))
1604 if (tmp8u) p_ptr->action = ACTION_LEARN;
1606 rd_byte((byte *)&preserve_mode);
1607 rd_byte((byte *)&p_ptr->wait_report_score);
1610 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1612 /* Skip the flags */
1616 /* Hack -- the two "special seeds" */
1617 rd_u32b(&seed_flavor);
1618 rd_u32b(&seed_town);
1622 rd_u16b(&p_ptr->panic_save);
1623 rd_u16b(&p_ptr->total_winner);
1624 rd_u16b(&p_ptr->noscore);
1629 p_ptr->is_dead = tmp8u;
1631 /* Read "feeling" */
1635 /* Turn of last "feeling" */
1641 if (z_older_than(10, 3, 12))
1643 dungeon_turn = turn;
1645 else rd_s32b(&dungeon_turn);
1647 if (z_older_than(11, 0, 13))
1654 if (z_older_than(10, 3, 13))
1658 else rd_s32b(&old_battle);
1660 if (z_older_than(10,0,3))
1662 monster_race *r_ptr;
1666 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1667 r_ptr = &r_info[today_mon];
1669 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1670 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1671 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1672 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1673 if (r_ptr->rarity > 10) continue;
1674 if (r_ptr->level == 0) continue;
1678 p_ptr->today_mon = 0;
1682 rd_s16b(&today_mon);
1683 rd_s16b(&p_ptr->today_mon);
1686 if (z_older_than(10,0,7))
1692 rd_s16b(&p_ptr->riding);
1695 if (z_older_than(10,1,2))
1704 if (z_older_than(10,3,9))
1708 else if (z_older_than(10, 3, 10))
1716 rd_s32b(&p_ptr->visit);
1718 if (!z_older_than(11, 0, 5))
1720 rd_u32b(&p_ptr->count);
1728 * Read the player inventory
1730 * Note that the inventory changed in Angband 2.7.4. Two extra
1731 * pack slots were added and the equipment was rearranged. Note
1732 * that these two features combine when parsing old save-files, in
1733 * which items from the old "aux" slot are "carried", perhaps into
1734 * one of the two new "inventory" slots.
1736 * Note that the inventory is "re-sorted" later by "dungeon()".
1738 static errr rd_inventory(void)
1746 p_ptr->total_weight = 0;
1752 /* Read until done */
1757 /* Get the next item index */
1760 /* Nope, we reached the end */
1761 if (n == 0xFFFF) break;
1763 /* Get local object */
1766 /* Wipe the object */
1772 /* Hack -- verify item */
1773 if (!q_ptr->k_idx) return (53);
1775 /* Wield equipment */
1776 if (n >= INVEN_RARM)
1779 object_copy(&inventory[n], q_ptr);
1781 /* Add the weight */
1782 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1788 /* Warning -- backpack is full */
1789 else if (inven_cnt == INVEN_PACK)
1793 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1795 note("Too many items in the inventory!");
1803 /* Carry inventory */
1810 object_copy(&inventory[n], q_ptr);
1812 /* Add the weight */
1813 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1827 * Read the saved messages
1829 static void rd_messages(void)
1839 /* Read the messages */
1840 for (i = 0; i < num; i++)
1842 /* Read the message */
1843 rd_string(buf, 128);
1845 /* Save the message */
1855 * The monsters/objects must be loaded in the same order
1856 * that they were stored, since the actual indexes matter.
1858 static errr rd_dungeon(void)
1869 /*** Basic info ***/
1872 rd_s16b(&dun_level);
1873 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1874 else rd_byte(&dungeon_type);
1876 /* Set the base level for old versions */
1877 base_level = dun_level;
1879 rd_s16b(&base_level);
1881 rd_s16b(&num_repro);
1886 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1889 rd_s16b(&tmp16s); /* max_panel_rows */
1890 rd_s16b(&tmp16s); /* max_panel_cols */
1893 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1901 /*** Run length decoding ***/
1903 /* Load the dungeon data */
1904 for (x = y = 0; y < ymax; )
1908 if (z_older_than(10,3,6))
1913 /* Apply the RLE info */
1914 for (i = count; i > 0; i--)
1916 /* Access the cave */
1917 c_ptr = &cave[y][x];
1919 /* Extract "info" */
1920 if (z_older_than(10,3,6))
1921 c_ptr->info = tmp8u;
1922 else c_ptr->info = tmp16s;
1931 if (++y >= ymax) break;
1937 /*** Run length decoding ***/
1939 /* Load the dungeon data */
1940 for (x = y = 0; y < ymax; )
1946 /* Apply the RLE info */
1947 for (i = count; i > 0; i--)
1949 /* Access the cave */
1950 c_ptr = &cave[y][x];
1952 /* Extract "feat" */
1953 c_ptr->feat = tmp8u;
1955 if (c_ptr->feat == FEAT_INVIS)
1957 c_ptr->feat = FEAT_FLOOR;
1958 c_ptr->info |= CAVE_TRAP;
1961 /* Older than 1.1.1 */
1962 if (c_ptr->feat == FEAT_MIRROR)
1964 c_ptr->feat = FEAT_FLOOR;
1965 c_ptr->info |= CAVE_IN_MIRROR;
1975 if (++y >= ymax) break;
1980 /*** Run length decoding ***/
1982 /* Load the dungeon data */
1983 for (x = y = 0; y < ymax; )
1989 /* Apply the RLE info */
1990 for (i = count; i > 0; i--)
1992 /* Access the cave */
1993 c_ptr = &cave[y][x];
1995 /* Extract "feat" */
1996 c_ptr->mimic = tmp8u;
2005 if (++y >= ymax) break;
2010 /*** Run length decoding ***/
2012 /* Load the dungeon data */
2013 for (x = y = 0; y < ymax; )
2019 /* Apply the RLE info */
2020 for (i = count; i > 0; i--)
2022 /* Access the cave */
2023 c_ptr = &cave[y][x];
2025 /* Extract "feat" */
2026 c_ptr->special = tmp16s;
2035 if (++y >= ymax) break;
2042 /* Read the item count */
2045 /* Verify maximum */
2046 if (limit >= max_o_idx)
2049 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2051 note(format("Too many (%d) object entries!", limit));
2057 /* Read the dungeon items */
2058 for (i = 1; i < limit; i++)
2065 /* Get a new record */
2072 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2074 note(format("Object allocation error (%d <> %d)", i, o_idx));
2082 o_ptr = &o_list[o_idx];
2088 /* XXX XXX XXX XXX XXX */
2091 if (o_ptr->held_m_idx)
2093 monster_type *m_ptr;
2096 m_ptr = &m_list[o_ptr->held_m_idx];
2099 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2101 /* Place the object */
2102 m_ptr->hold_o_idx = o_idx;
2108 /* Access the item location */
2109 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2112 o_ptr->next_o_idx = c_ptr->o_idx;
2114 /* Place the object */
2115 c_ptr->o_idx = o_idx;
2122 /* Read the monster count */
2125 /* Hack -- verify */
2126 if (limit >= max_m_idx)
2129 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2131 note(format("Too many (%d) monster entries!", limit));
2137 /* Read the monsters */
2138 for (i = 1; i < limit; i++)
2142 monster_type *m_ptr;
2144 monster_race *r_ptr;
2147 /* Get a new record */
2154 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2156 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2163 /* Acquire monster */
2164 m_ptr = &m_list[m_idx];
2166 /* Read the monster */
2171 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2173 /* Mark the location */
2174 c_ptr->m_idx = m_idx;
2178 r_ptr = &r_info[m_ptr->r_idx];
2180 /* Count XXX XXX XXX */
2186 /* The dungeon is ready */
2187 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2188 character_dungeon = FALSE;
2190 character_dungeon = TRUE;
2199 * Actually read the savefile
2201 static errr rd_savefile_new_aux(void)
2213 #ifdef VERIFY_CHECKSUMS
2214 u32b n_x_check, n_v_check;
2215 u32b o_x_check, o_v_check;
2219 /* Mention the savefile version */
2221 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2223 note(format("Loading a %d.%d.%d savefile...",
2226 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2229 /* Strip the version bytes */
2232 /* Hack -- decrypt */
2233 xor_byte = sf_extra;
2236 /* Clear the checksums */
2240 #if SAVEFILE_VERSION
2241 /* Read the version number of the savefile */
2242 rd_u32b(&sf_version);
2243 #endif /* SAVEFILE_VERSION */
2245 /* Operating system info */
2248 /* Time of savefile creation */
2251 /* Number of resurrections */
2254 /* Number of times played */
2258 /* Later use (always zero) */
2261 /* Later use (always zero) */
2265 /* Read RNG state */
2268 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2270 if (arg_fiddle) note("Loaded Randomizer Info");
2275 /* Then the options */
2278 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2280 if (arg_fiddle) note("Loaded Option Flags");
2284 * Munchkin players are marked
2286 * XXX - should be replaced with a better method,
2287 * after the new scorefile-handling is implemented.
2292 p_ptr->noscore |= 0x0001;
2295 /* Then the "messages" */
2298 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2300 if (arg_fiddle) note("Loaded Messages");
2305 for (i = 0; i < max_r_idx; i++)
2307 monster_race *r_ptr;
2308 /* Access that monster */
2311 /* Hack -- Reset the death counter */
2312 r_ptr->max_num = 100;
2313 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2314 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2317 /* Monster Memory */
2320 /* Incompatible save files */
2321 if (tmp16u > max_r_idx)
2324 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2326 note(format("Too many (%u) monster races!", tmp16u));
2332 /* Read the available records */
2333 for (i = 0; i < tmp16u; i++)
2335 monster_race *r_ptr;
2340 /* Access that monster */
2345 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2347 if (arg_fiddle) note("Loaded Monster Memory");
2355 /* Incompatible save files */
2356 if (tmp16u > max_k_idx)
2359 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2361 note(format("Too many (%u) object kinds!", tmp16u));
2367 /* Read the object memory */
2368 for (i = 0; i < tmp16u; i++)
2371 object_kind *k_ptr = &k_info[i];
2375 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2376 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2379 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2381 if (arg_fiddle) note("Loaded Object Memory");
2387 * Initialize arena and rewards information
2389 p_ptr->arena_number = 0;
2390 p_ptr->inside_arena = 0;
2391 p_ptr->inside_quest = 0;
2392 p_ptr->leftbldg = FALSE;
2393 p_ptr->exit_bldg = TRUE;
2395 /* Start in town 1 */
2396 p_ptr->town_num = 1;
2398 p_ptr->wilderness_x = 4;
2399 p_ptr->wilderness_y = 4;
2403 /* Init the wilderness seeds */
2404 for (i = 0; i < max_wild_x; i++)
2406 for (j = 0; j < max_wild_y; j++)
2408 wilderness[j][i].seed = randint0(0x10000000);
2412 /* 2.1.3 or newer version */
2414 u16b max_towns_load;
2415 u16b max_quests_load;
2416 byte max_rquests_load;
2417 s16b old_inside_quest = p_ptr->inside_quest;
2419 /* Number of towns */
2420 rd_u16b(&max_towns_load);
2422 /* Incompatible save files */
2423 if (max_towns_load > max_towns)
2426 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2428 note(format("Too many (%u) towns!", max_towns_load));
2434 /* Number of quests */
2435 rd_u16b(&max_quests_load);
2437 if (z_older_than(11, 0, 7))
2439 max_rquests_load = 10;
2443 rd_byte(&max_rquests_load);
2446 /* Incompatible save files */
2447 if (max_quests_load > max_quests)
2450 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2452 note(format("Too many (%u) quests!", max_quests_load));
2458 for (i = 0; i < max_quests_load; i++)
2462 rd_s16b(&quest[i].status);
2463 rd_s16b(&quest[i].level);
2465 if (z_older_than(11, 0, 6))
2467 quest[i].complev = 0;
2471 rd_byte(&quest[i].complev);
2474 /* Load quest status if quest is running */
2475 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))))
2477 rd_s16b(&quest[i].cur_num);
2478 rd_s16b(&quest[i].max_num);
2479 rd_s16b(&quest[i].type);
2481 /* Load quest monster index */
2482 rd_s16b(&quest[i].r_idx);
2484 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2489 monster_race *r_ptr;
2492 * Random monster 5 - 10 levels out of depth
2493 * (depending on level)
2495 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
2496 r_ptr = &r_info[r_idx];
2498 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2500 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2502 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2504 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2506 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2509 * Accept monsters that are 2 - 6 levels
2510 * out of depth depending on the quest level
2512 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2515 quest[i].r_idx = r_idx;
2518 /* Load quest item index */
2519 rd_s16b(&quest[i].k_idx);
2522 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
2524 rd_byte(&quest[i].flags);
2526 if (z_older_than(10, 3, 11))
2528 if (quest[i].flags & QUEST_FLAG_PRESET)
2530 quest[i].dungeon = 0;
2534 init_flags = INIT_ASSIGN;
2535 p_ptr->inside_quest = i;
2537 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2538 p_ptr->inside_quest = old_inside_quest;
2543 rd_byte(&quest[i].dungeon);
2546 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2547 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2548 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2551 /* Ignore the empty quests from old versions */
2554 /* Ignore quest status */
2557 /* Ignore quest level */
2561 * We don't have to care about the other info,
2562 * since status should be 0 for these quests anyway
2567 /* Position in the wilderness */
2568 rd_s32b(&p_ptr->wilderness_x);
2569 rd_s32b(&p_ptr->wilderness_y);
2570 if (z_older_than(10, 3, 13))
2572 p_ptr->wilderness_x = 5;
2573 p_ptr->wilderness_y = 48;
2576 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2577 else rd_byte((byte *)&p_ptr->wild_mode);
2578 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2579 else rd_byte((byte *)&ambush_flag);
2581 /* Size of the wilderness */
2582 rd_s32b(&wild_x_size);
2583 rd_s32b(&wild_y_size);
2585 /* Incompatible save files */
2586 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2589 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2591 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2597 /* Load the wilderness seeds */
2598 for (i = 0; i < wild_x_size; i++)
2600 for (j = 0; j < wild_y_size; j++)
2602 rd_u32b(&wilderness[j][i].seed);
2608 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2610 if (arg_fiddle) note("Loaded Quests");
2613 /* Load the Artifacts */
2616 /* Incompatible save files */
2617 if (tmp16u > max_a_idx)
2620 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2622 note(format("Too many (%u) artifacts!", tmp16u));
2628 /* Read the artifact flags */
2629 for (i = 0; i < tmp16u; i++)
2632 a_info[i].cur_num = tmp8u;
2638 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2640 if (arg_fiddle) note("Loaded Artifacts");
2645 /* Read the extra stuff */
2647 if (p_ptr->energy_need < -999) world_player = TRUE;
2650 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2652 if (arg_fiddle) note("Loaded extra information");
2656 /* Read the player_hp array */
2659 /* Incompatible save files */
2660 if (tmp16u > PY_MAX_LEVEL)
2663 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2665 note(format("Too many (%u) hitpoint entries!", tmp16u));
2671 /* Read the player_hp array */
2672 for (i = 0; i < tmp16u; i++)
2674 rd_s16b(&p_ptr->player_hp[i]);
2677 /* Important -- Initialize the sex */
2678 sp_ptr = &sex_info[p_ptr->psex];
2680 /* Important -- Initialize the race/class */
2681 rp_ptr = &race_info[p_ptr->prace];
2682 cp_ptr = &class_info[p_ptr->pclass];
2683 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2685 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
2687 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2688 do_cmd_rerate(FALSE);
2690 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
2692 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2693 do_cmd_rerate(FALSE);
2695 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
2697 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2698 do_cmd_rerate(FALSE);
2700 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
2702 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2703 do_cmd_rerate(FALSE);
2706 /* Important -- Initialize the magic */
2707 mp_ptr = &m_info[p_ptr->pclass];
2710 /* Read spell info */
2711 rd_u32b(&p_ptr->spell_learned1);
2712 rd_u32b(&p_ptr->spell_learned2);
2713 rd_u32b(&p_ptr->spell_worked1);
2714 rd_u32b(&p_ptr->spell_worked2);
2715 rd_u32b(&p_ptr->spell_forgotten1);
2716 rd_u32b(&p_ptr->spell_forgotten2);
2718 if (z_older_than(10,0,5))
2720 p_ptr->learned_spells = 0;
2721 for (i = 0; i < 64; i++)
2723 /* Count known spells */
2725 (p_ptr->spell_learned1 & (1L << i)) :
2726 (p_ptr->spell_learned2 & (1L << (i - 32))))
2728 p_ptr->learned_spells++;
2732 else rd_s16b(&p_ptr->learned_spells);
2734 if (z_older_than(10,0,6))
2736 p_ptr->add_spells = 0;
2738 else rd_s16b(&p_ptr->add_spells);
2739 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2741 for (i = 0; i < 64; i++)
2743 rd_byte(&p_ptr->spell_order[i]);
2747 /* Read the inventory */
2751 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2753 note("Unable to read inventory");
2759 /* Read number of towns */
2761 town_count = tmp16u;
2763 /* Read the stores */
2765 for (i = 1; i < town_count; i++)
2767 for (j = 0; j < tmp16u; j++)
2769 if (rd_store(i, j)) return (22);
2773 rd_s16b(&p_ptr->pet_follow_distance);
2774 if (z_older_than(10, 4, 10))
2776 p_ptr->pet_extra_flags = 0;
2778 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2780 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2782 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2786 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2789 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2793 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2796 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2800 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2803 if (!z_older_than(10,0,8))
2806 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2811 rd_s16b(&p_ptr->pet_extra_flags);
2814 if (!z_older_than(11, 0, 9))
2816 char buf[SCREEN_BUF_SIZE];
2817 rd_string(buf, SCREEN_BUF_SIZE);
2818 if (buf[0]) screen_dump = string_make(buf);
2823 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2825 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2830 /* I'm not dead yet... */
2831 if (!p_ptr->is_dead)
2833 /* Dead players have no dungeon */
2835 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2837 note("Restoring Dungeon...");
2843 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2845 note("Error reading dungeon data");
2851 /* Read the ghost info */
2858 strip_bytes(tmp32s);
2863 #ifdef VERIFY_CHECKSUMS
2865 /* Save the checksum */
2866 n_v_check = v_check;
2868 /* Read the old checksum */
2869 rd_u32b(&o_v_check);
2872 if (o_v_check != n_v_check)
2875 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2877 note("Invalid checksum");
2884 /* Save the encoded checksum */
2885 n_x_check = x_check;
2887 /* Read the checksum */
2888 rd_u32b(&o_x_check);
2892 if (o_x_check != n_x_check)
2895 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2897 note("Invalid encoded checksum");
2911 * Actually read the savefile
2913 errr rd_savefile_new(void)
2917 /* The savefile is a binary file */
2918 fff = my_fopen(savefile, "rb");
2921 if (!fff) return (-1);
2923 /* Call the sub-function */
2924 err = rd_savefile_new_aux();
2926 /* Check for errors */
2927 if (ferror(fff)) err = -1;
2929 /* Close the file */