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;
71 * This function determines if the version of the savefile
72 * currently being read is older than version "major.minor.patch.extra".
74 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
76 /* Much older, or much more recent */
77 if (h_ver_major < major) return (TRUE);
78 if (h_ver_major > major) return (FALSE);
80 /* Distinctly older, or distinctly more recent */
81 if (h_ver_minor < minor) return (TRUE);
82 if (h_ver_minor > minor) return (FALSE);
84 /* Barely older, or barely more recent */
85 if (h_ver_patch < patch) return (TRUE);
86 if (h_ver_patch > patch) return (FALSE);
88 /* Barely older, or barely more recent */
89 if (h_ver_extra < extra) return (TRUE);
90 if (h_ver_extra > extra) return (FALSE);
92 /* Identical versions */
98 * The above function, adapted for Zangband
100 static bool z_older_than(byte x, byte y, byte z)
102 /* Much older, or much more recent */
103 if (z_major < x) return (TRUE);
104 if (z_major > x) return (FALSE);
106 /* Distinctly older, or distinctly more recent */
107 if (z_minor < y) return (TRUE);
108 if (z_minor > y) return (FALSE);
110 /* Barely older, or barely more recent */
111 if (z_patch < z) return (TRUE);
112 if (z_patch > z) return (FALSE);
114 /* Identical versions */
120 * Hack -- Show information on the screen, one line at a time.
122 * Avoid the top two lines, to avoid interference with "msg_print()".
124 static void note(cptr msg)
128 /* Draw the message */
131 /* Advance one line (wrap if needed) */
132 if (++y >= 24) y = 2;
140 * The following functions are used to load the basic building blocks
141 * of savefiles. They also maintain the "checksum" info for 2.7.0+
144 static byte sf_get(void)
148 /* Get a character, decode the value */
149 c = getc(fff) & 0xFF;
153 /* Maintain the checksum info */
157 /* Return the value */
161 static void rd_byte(byte *ip)
166 static void rd_u16b(u16b *ip)
169 (*ip) |= ((u16b)(sf_get()) << 8);
172 static void rd_s16b(s16b *ip)
177 static void rd_u32b(u32b *ip)
180 (*ip) |= ((u32b)(sf_get()) << 8);
181 (*ip) |= ((u32b)(sf_get()) << 16);
182 (*ip) |= ((u32b)(sf_get()) << 24);
185 static void rd_s32b(s32b *ip)
192 * Hack -- read a string
194 static void rd_string(char *str, int max)
198 /* Read the string */
199 for (i = 0; TRUE; i++)
206 /* Collect string while legal */
207 if (i < max) str[i] = tmp8u;
222 * Hack -- strip some bytes
224 static void strip_bytes(int n)
228 /* Strip the bytes */
229 while (n--) rd_byte(&tmp8u);
232 #define OLD_MAX_MANE 22
237 * This function attempts to "repair" old savefiles, and to extract
238 * the most up to date values for various object fields.
240 * Note that Angband 2.7.9 introduced a new method for object "flags"
241 * in which the "flags" on an object are actually extracted when they
242 * are needed from the object kind, artifact index, ego-item index,
243 * and two special "xtra" fields which are used to encode any "extra"
244 * power of certain ego-items. This had the side effect that items
245 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
246 * may have had, and also, all "uncursed" items will become "cursed"
247 * again, including Calris, even if it is being worn at the time. As
248 * a complete hack, items which are inscribed with "uncursed" will be
249 * "uncursed" when imported from pre-2.7.9 savefiles.
251 static void rd_item(object_type *o_ptr)
257 rd_s16b(&o_ptr->k_idx);
264 rd_byte(&o_ptr->tval);
265 rd_byte(&o_ptr->sval);
267 if (z_older_than(10, 4, 4))
269 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
270 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
271 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
275 rd_s16b(&o_ptr->pval);
277 rd_byte(&o_ptr->discount);
278 rd_byte(&o_ptr->number);
279 rd_s16b(&o_ptr->weight);
281 rd_byte(&o_ptr->name1);
282 rd_byte(&o_ptr->name2);
283 rd_s16b(&o_ptr->timeout);
285 rd_s16b(&o_ptr->to_h);
286 rd_s16b(&o_ptr->to_d);
287 rd_s16b(&o_ptr->to_a);
294 rd_byte(&o_ptr->ident);
296 rd_byte(&o_ptr->marked);
299 rd_u32b(&o_ptr->art_flags[0]);
300 rd_u32b(&o_ptr->art_flags[1]);
301 rd_u32b(&o_ptr->art_flags[2]);
302 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
303 else rd_u32b(&o_ptr->art_flags[3]);
305 if (z_older_than(11, 0, 11))
307 o_ptr->curse_flags = 0L;
308 if (o_ptr->ident & 0x40)
310 o_ptr->curse_flags |= TRC_CURSED;
311 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
312 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
315 artifact_type *a_ptr = &a_info[o_ptr->name1];
316 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
317 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
319 else if (o_ptr->name2)
321 ego_item_type *e_ptr = &e_info[o_ptr->name2];
322 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
323 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
326 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
330 rd_u32b(&o_ptr->curse_flags);
333 /* Monster holding object */
334 rd_s16b(&o_ptr->held_m_idx);
337 rd_byte(&o_ptr->xtra1);
338 rd_byte(&o_ptr->xtra2);
340 if (z_older_than(11, 0, 10))
342 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
344 switch (o_ptr->xtra2 % 6)
346 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
347 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
348 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
349 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
350 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
351 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
355 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
357 switch (o_ptr->xtra2 % 11)
359 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
360 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
361 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
362 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
363 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
364 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
365 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
366 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
367 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
368 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
369 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
373 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
375 switch (o_ptr->xtra2 % 8)
377 case 0: add_flag(o_ptr->art_flags, TR_FEATHER); break;
378 case 1: add_flag(o_ptr->art_flags, TR_LITE); break;
379 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
380 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
381 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
382 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
383 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
384 case 7: add_flag(o_ptr->art_flags, TR_HOLD_LIFE); break;
391 if (z_older_than(10, 2, 3))
396 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
398 o_ptr->xtra3 = o_ptr->xtra1;
401 if (o_ptr->tval == TV_CAPTURE)
403 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
404 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
406 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
407 if (ironman_nightmare)
409 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
411 o_ptr->xtra4 = o_ptr->xtra5;
416 rd_byte(&o_ptr->xtra3);
417 rd_s16b(&o_ptr->xtra4);
418 rd_s16b(&o_ptr->xtra5);
421 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)))
423 o_ptr->xtra4 = o_ptr->pval;
427 rd_byte(&o_ptr->feeling);
432 /* Save the inscription */
433 if (buf[0]) o_ptr->inscription = quark_add(buf);
436 if (buf[0]) o_ptr->art_name = quark_add(buf);
438 /* The Python object */
446 /* Mega-Hack -- handle "dungeon objects" later */
447 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
449 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
451 if (z_older_than(10, 4, 9))
453 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
455 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
456 add_flag(o_ptr->art_flags, TR_DEC_MANA);
463 artifact_type *a_ptr;
465 /* Obtain the artifact info */
466 a_ptr = &a_info[o_ptr->name1];
468 /* Verify that artifact */
469 if (!a_ptr->name) o_ptr->name1 = 0;
475 ego_item_type *e_ptr;
477 /* Obtain the ego-item info */
478 e_ptr = &e_info[o_ptr->name2];
480 /* Verify that ego-item */
481 if (!e_ptr->name) o_ptr->name2 = 0;
492 static void rd_monster(monster_type *m_ptr)
497 /* Read the monster race */
498 rd_s16b(&m_ptr->r_idx);
500 if (z_older_than(11, 0, 12))
501 m_ptr->ap_r_idx = m_ptr->r_idx;
503 rd_s16b(&m_ptr->ap_r_idx);
505 if (z_older_than(11, 0, 14))
507 monster_race *r_ptr = &r_info[m_ptr->r_idx];
509 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
510 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
511 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
514 rd_byte(&m_ptr->sub_align);
516 /* Read the other information */
520 rd_s16b(&m_ptr->maxhp);
521 if (z_older_than(11, 0, 5))
523 m_ptr->max_maxhp = m_ptr->maxhp;
527 rd_s16b(&m_ptr->max_maxhp);
529 rd_s16b(&m_ptr->csleep);
530 rd_byte(&m_ptr->mspeed);
531 if (z_older_than(10, 4, 2))
534 m_ptr->energy_need = (s16b)tmp8u;
536 else rd_s16b(&m_ptr->energy_need);
538 if (z_older_than(11, 0, 13))
539 m_ptr->energy_need = 100 - m_ptr->energy_need;
541 if (z_older_than(10,0,7))
548 rd_byte(&m_ptr->fast);
549 rd_byte(&m_ptr->slow);
551 rd_byte(&m_ptr->stunned);
552 rd_byte(&m_ptr->confused);
553 rd_byte(&m_ptr->monfear);
555 if (z_older_than(10,0,10))
559 else if (z_older_than(10,0,11))
567 rd_s16b(&m_ptr->target_y);
568 rd_s16b(&m_ptr->target_x);
571 rd_byte(&m_ptr->invulner);
573 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
574 rd_u32b(&m_ptr->smart);
578 if (z_older_than(10, 4, 5))
581 rd_u32b(&m_ptr->exp);
583 if (z_older_than(10, 2, 2))
585 if (m_ptr->r_idx < 0)
587 m_ptr->r_idx = (0-m_ptr->r_idx);
588 m_ptr->mflag2 |= MFLAG_KAGE;
593 rd_byte(&m_ptr->mflag2);
596 if (z_older_than(11, 0, 12))
598 if (m_ptr->mflag2 & MFLAG_KAGE)
599 m_ptr->ap_r_idx = MON_KAGE;
602 if (z_older_than(10, 1, 3))
609 if (buf[0]) m_ptr->nickname = quark_add(buf);
620 * Read the monster lore
622 static void rd_lore(int r_idx)
626 monster_race *r_ptr = &r_info[r_idx];
628 /* Count sights/deaths/kills */
629 rd_s16b(&r_ptr->r_sights);
630 rd_s16b(&r_ptr->r_deaths);
631 rd_s16b(&r_ptr->r_pkills);
632 rd_s16b(&r_ptr->r_tkills);
634 /* Count wakes and ignores */
635 rd_byte(&r_ptr->r_wake);
636 rd_byte(&r_ptr->r_ignore);
639 rd_byte(&r_ptr->r_xtra1);
640 rd_byte(&r_ptr->r_xtra2);
643 rd_byte(&r_ptr->r_drop_gold);
644 rd_byte(&r_ptr->r_drop_item);
647 rd_byte(&r_ptr->r_cast_inate);
648 rd_byte(&r_ptr->r_cast_spell);
650 /* Count blows of each type */
651 rd_byte(&r_ptr->r_blows[0]);
652 rd_byte(&r_ptr->r_blows[1]);
653 rd_byte(&r_ptr->r_blows[2]);
654 rd_byte(&r_ptr->r_blows[3]);
657 rd_u32b(&r_ptr->r_flags1);
658 rd_u32b(&r_ptr->r_flags2);
659 rd_u32b(&r_ptr->r_flags3);
660 rd_u32b(&r_ptr->r_flags4);
661 rd_u32b(&r_ptr->r_flags5);
662 rd_u32b(&r_ptr->r_flags6);
664 /* Read the "Racial" monster limit per level */
665 rd_byte(&r_ptr->max_num);
672 /* Repair the lore flags */
673 r_ptr->r_flags1 &= r_ptr->flags1;
674 r_ptr->r_flags2 &= r_ptr->flags2;
675 r_ptr->r_flags3 &= r_ptr->flags3;
676 r_ptr->r_flags4 &= r_ptr->flags4;
677 r_ptr->r_flags5 &= r_ptr->flags5;
678 r_ptr->r_flags6 &= r_ptr->flags6;
685 * Add the item "o_ptr" to the inventory of the "Home"
687 * In all cases, return the slot (or -1) where the object was placed
689 * Note that this is a hacked up version of "inven_carry()".
691 * Also note that it may not correctly "adapt" to "knowledge" bacoming
692 * known, the player may have to pick stuff up and drop it again.
694 static void home_carry(store_type *st_ptr, object_type *o_ptr)
702 /* Check each existing item (try to combine) */
703 for (slot = 0; slot < st_ptr->stock_num; slot++)
705 /* Get the existing item */
706 j_ptr = &st_ptr->stock[slot];
708 /* The home acts just like the player */
709 if (object_similar(j_ptr, o_ptr))
711 /* Save the new number of items */
712 object_absorb(j_ptr, o_ptr);
720 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
724 /* Determine the "value" of the item */
725 value = object_value(o_ptr);
727 /* Check existing slots to see if we must "slide" */
728 for (slot = 0; slot < st_ptr->stock_num; slot++)
731 j_ptr = &st_ptr->stock[slot];
733 /* Hack -- readable books always come first */
734 if ((o_ptr->tval == mp_ptr->spell_book) &&
735 (j_ptr->tval != mp_ptr->spell_book)) break;
736 if ((j_ptr->tval == mp_ptr->spell_book) &&
737 (o_ptr->tval != mp_ptr->spell_book)) continue;
739 /* Objects sort by decreasing type */
740 if (o_ptr->tval > j_ptr->tval) break;
741 if (o_ptr->tval < j_ptr->tval) continue;
743 /* Can happen in the home */
744 if (!object_aware_p(o_ptr)) continue;
745 if (!object_aware_p(j_ptr)) break;
747 /* Objects sort by increasing sval */
748 if (o_ptr->sval < j_ptr->sval) break;
749 if (o_ptr->sval > j_ptr->sval) continue;
751 /* Objects in the home can be unknown */
752 if (!object_known_p(o_ptr)) continue;
753 if (!object_known_p(j_ptr)) break;
756 * Hack: otherwise identical rods sort by
757 * increasing recharge time --dsb
759 if (o_ptr->tval == TV_ROD)
761 if (o_ptr->pval < j_ptr->pval) break;
762 if (o_ptr->pval > j_ptr->pval) continue;
765 /* Objects sort by decreasing value */
766 j_value = object_value(j_ptr);
767 if (value > j_value) break;
768 if (value < j_value) continue;
771 /* Slide the others up */
772 for (i = st_ptr->stock_num; i > slot; i--)
774 st_ptr->stock[i] = st_ptr->stock[i-1];
780 /* Insert the new item */
781 st_ptr->stock[slot] = *o_ptr;
783 chg_virtue(V_SACRIFICE, -1);
785 /* Return the location */
793 static errr rd_store(int town_number, int store_number)
805 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
807 st_ptr = &town[1].store[store_number];
808 if (st_ptr->stock_num) sort = TRUE;
812 st_ptr = &town[town_number].store[store_number];
815 /* Read the basic info */
816 rd_s32b(&st_ptr->store_open);
817 rd_s16b(&st_ptr->insult_cur);
819 if (z_older_than(11, 0, 4))
828 rd_s16b(&st_ptr->good_buy);
829 rd_s16b(&st_ptr->bad_buy);
831 /* Read last visit */
832 rd_s32b(&st_ptr->last_visit);
834 /* Extract the owner (see above) */
838 for (j = 0; j < num; j++)
843 /* Get local object */
846 /* Wipe the object */
852 /* Acquire valid items */
853 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
858 home_carry(st_ptr, q_ptr);
862 k = st_ptr->stock_num++;
864 /* Acquire the item */
865 object_copy(&st_ptr->stock[k], q_ptr);
877 * Read RNG state (added in 2.8.0)
879 static void rd_randomizer(void)
889 rd_u16b(&Rand_place);
892 for (i = 0; i < RAND_DEG; i++)
894 rd_u32b(&Rand_state[i]);
904 * Read options (ignore most pre-2.8.0 options)
906 * Note that the normal options are now stored as a set of 256 bit flags,
907 * plus a set of 256 bit masks to indicate which bit flags were defined
908 * at the time the savefile was created. This will allow new options
909 * to be added, and old options to be removed, at any time, without
910 * hurting old savefiles.
912 * The window options are stored in the same way, but note that each
913 * window gets 32 options, and their order is fixed by certain defines.
915 static void rd_options(void)
929 /* Ignore old options */
935 /* Read "delay_factor" */
939 /* Read "hitpoint_warn" */
944 /*** Cheating options ***/
948 if (c & 0x0002) p_ptr->wizard = TRUE;
950 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
951 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
952 cheat_room = (c & 0x0400) ? TRUE : FALSE;
953 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
954 cheat_know = (c & 0x1000) ? TRUE : FALSE;
955 cheat_live = (c & 0x2000) ? TRUE : FALSE;
957 rd_byte((byte *)&autosave_l);
958 rd_byte((byte *)&autosave_t);
959 rd_s16b(&autosave_freq);
962 /*** Normal Options ***/
964 /* Read the option flags */
965 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
967 /* Read the option masks */
968 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
970 /* Analyze the options */
971 for (n = 0; n < 8; n++)
973 /* Analyze the options */
974 for (i = 0; i < 32; i++)
976 /* Process valid flags */
977 if (mask[n] & (1L << i))
979 /* Process valid flags */
980 if (option_mask[n] & (1L << i))
983 if (flag[n] & (1L << i))
986 option_flag[n] |= (1L << i);
993 option_flag[n] &= ~(1L << i);
1000 if (z_older_than(10, 4, 5))
1002 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1003 else option_flag[5] |= (0x00000001 << 4);
1004 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1005 else option_flag[2] |= (0x00000001 << 5);
1006 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1007 else option_flag[4] |= (0x00000001 << 5);
1008 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1009 else option_flag[5] |= (0x00000001 << 0);
1010 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1011 else option_flag[5] |= (0x00000001 << 12);
1012 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1013 else option_flag[1] |= (0x00000001 << 0);
1014 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1015 else option_flag[1] |= (0x00000001 << 18);
1016 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1017 else option_flag[1] |= (0x00000001 << 19);
1018 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1019 else option_flag[5] |= (0x00000001 << 3);
1023 /*** Window Options ***/
1025 /* Read the window flags */
1026 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1028 /* Read the window masks */
1029 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1031 /* Analyze the options */
1032 for (n = 0; n < 8; n++)
1034 /* Analyze the options */
1035 for (i = 0; i < 32; i++)
1037 /* Process valid flags */
1038 if (mask[n] & (1L << i))
1040 /* Process valid flags */
1041 if (window_mask[n] & (1L << i))
1044 if (flag[n] & (1L << i))
1047 window_flag[n] |= (1L << i);
1054 window_flag[n] &= ~(1L << i);
1067 * Hack -- strip the "ghost" info
1069 * XXX XXX XXX This is such a nasty hack it hurts.
1071 static void rd_ghost(void)
1078 /* Strip old data */
1084 * Save quick start data
1086 static void load_quick_start(void)
1091 if (z_older_than(11, 0, 13))
1093 previous_char.quick_ok = FALSE;
1097 rd_byte(&previous_char.psex);
1098 rd_byte(&previous_char.prace);
1099 rd_byte(&previous_char.pclass);
1100 rd_byte(&previous_char.pseikaku);
1101 rd_byte(&previous_char.realm1);
1102 rd_byte(&previous_char.realm2);
1104 rd_s16b(&previous_char.age);
1105 rd_s16b(&previous_char.ht);
1106 rd_s16b(&previous_char.wt);
1107 rd_s16b(&previous_char.sc);
1108 rd_s32b(&previous_char.au);
1110 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1111 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1113 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1115 rd_s16b(&previous_char.chaos_patron);
1117 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1119 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], 60);
1121 rd_byte(&previous_char.quests);
1124 previous_char.quick_ok = (bool)tmp8u;
1128 * Read the "extra" information
1130 static void rd_extra(void)
1137 rd_string(player_name, 32);
1139 rd_string(p_ptr->died_from, 80);
1143 for (i = 0; i < 4; i++)
1145 rd_string(p_ptr->history[i], 60);
1148 /* Class/Race/Seikaku/Gender/Spells */
1149 rd_byte(&p_ptr->prace);
1150 rd_byte(&p_ptr->pclass);
1151 rd_byte(&p_ptr->pseikaku);
1152 rd_byte(&p_ptr->psex);
1153 rd_byte(&p_ptr->realm1);
1154 rd_byte(&p_ptr->realm2);
1155 rd_byte(&tmp8u); /* oops */
1157 if (z_older_than(10, 4, 4))
1159 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1160 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1161 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1162 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1165 /* Special Race/Class info */
1166 rd_byte(&p_ptr->hitdie);
1167 rd_u16b(&p_ptr->expfact);
1169 /* Age/Height/Weight */
1170 rd_s16b(&p_ptr->age);
1171 rd_s16b(&p_ptr->ht);
1172 rd_s16b(&p_ptr->wt);
1174 /* Read the stat info */
1175 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1176 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1177 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1179 strip_bytes(24); /* oops */
1181 rd_s32b(&p_ptr->au);
1183 rd_s32b(&p_ptr->max_exp);
1184 rd_s32b(&p_ptr->exp);
1185 rd_u16b(&p_ptr->exp_frac);
1187 rd_s16b(&p_ptr->lev);
1189 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1190 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1192 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = 1600;
1194 if (z_older_than(10, 3, 6))
1195 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1197 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1198 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1199 if (z_older_than(10, 4, 1))
1201 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1202 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1204 if (z_older_than(10, 3, 14))
1206 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1207 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1211 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1212 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1214 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1216 if (z_older_than(11, 0, 7))
1218 p_ptr->start_race = p_ptr->prace;
1219 p_ptr->old_race1 = 0L;
1220 p_ptr->old_race2 = 0L;
1221 p_ptr->old_realm = 0;
1225 rd_byte(&p_ptr->start_race);
1226 rd_s32b(&p_ptr->old_race1);
1227 rd_s32b(&p_ptr->old_race2);
1228 rd_s16b(&p_ptr->old_realm);
1231 if (z_older_than(10, 0, 1))
1233 for (i = 0; i < OLD_MAX_MANE; i++)
1235 p_ptr->mane_spell[i] = -1;
1236 p_ptr->mane_dam[i] = 0;
1238 p_ptr->mane_num = 0;
1240 else if (z_older_than(10, 2, 3))
1242 for (i = 0; i < OLD_MAX_MANE; i++)
1247 for (i = 0; i < MAX_MANE; i++)
1249 p_ptr->mane_spell[i] = -1;
1250 p_ptr->mane_dam[i] = 0;
1253 p_ptr->mane_num = 0;
1257 for (i = 0; i < MAX_MANE; i++)
1259 rd_s16b(&p_ptr->mane_spell[i]);
1260 rd_s16b(&p_ptr->mane_dam[i]);
1262 rd_s16b(&p_ptr->mane_num);
1265 if (z_older_than(10, 0, 3))
1267 get_mon_num_prep(NULL, NULL);
1268 for (i = 0; i < MAX_KUBI; i++)
1270 monster_race *r_ptr;
1275 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1276 r_ptr = &r_info[kubi_r_idx[i]];
1278 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1280 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1282 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1284 for (j = 0; j < i; j++)
1285 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1290 for (i = 0; i < MAX_KUBI -1; i++)
1293 for (j = i; j < MAX_KUBI; j++)
1295 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1297 tmp = kubi_r_idx[i];
1298 kubi_r_idx[i] = kubi_r_idx[j];
1299 kubi_r_idx[j] = tmp;
1303 for (i = 0; i < MAX_KUBI; i++)
1305 if(!r_info[kubi_r_idx[i]].max_num)
1306 kubi_r_idx[i] += 10000;
1311 for (i = 0; i < MAX_KUBI; i++)
1313 rd_s16b(&kubi_r_idx[i]);
1317 if (z_older_than(10, 0, 3))
1323 for (i = 0; i < 4; i++)
1325 rd_s16b(&battle_mon[i]);
1326 if (z_older_than(10, 3, 4))
1329 mon_odds[i] = tmp16s;
1331 else rd_u32b(&mon_odds[i]);
1335 rd_s16b(&p_ptr->town_num);
1337 /* Read arena and rewards information */
1338 rd_s16b(&p_ptr->arena_number);
1340 p_ptr->inside_arena = (bool)tmp16s;
1341 rd_s16b(&p_ptr->inside_quest);
1342 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1346 p_ptr->inside_battle = (bool)tmp16s;
1348 rd_byte(&p_ptr->exit_bldg);
1349 rd_byte(&p_ptr->leftbldg);
1351 rd_s16b(&p_ptr->oldpx);
1352 rd_s16b(&p_ptr->oldpy);
1353 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1357 if (tmp16s > MAX_BACT)
1360 note(format("¤ÎÃæ", tmp16s));
1362 note(format("Too many (%d) building rewards!", tmp16s));
1367 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1369 rd_s16b(&p_ptr->mhp);
1370 rd_s16b(&p_ptr->chp);
1371 rd_u16b(&p_ptr->chp_frac);
1373 rd_s16b(&p_ptr->msp);
1374 rd_s16b(&p_ptr->csp);
1375 rd_u16b(&p_ptr->csp_frac);
1377 rd_s16b(&p_ptr->max_plv);
1378 if (z_older_than(10, 3, 8))
1380 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1384 byte max = (byte)max_d_idx;
1388 for(i = 0; i < max; i++)
1390 rd_s16b(&max_dlv[i]);
1391 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1395 /* Repair maximum player level XXX XXX XXX */
1396 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1400 rd_s16b(&p_ptr->sc);
1403 /* Read the flags */
1404 strip_bytes(2); /* Old "rest" */
1405 rd_s16b(&p_ptr->blind);
1406 rd_s16b(&p_ptr->paralyzed);
1407 rd_s16b(&p_ptr->confused);
1408 rd_s16b(&p_ptr->food);
1409 strip_bytes(4); /* Old "food_digested" / "protection" */
1411 rd_s16b(&p_ptr->energy_need);
1412 if (z_older_than(11, 0, 13))
1413 p_ptr->energy_need = 100 - p_ptr->energy_need;
1415 rd_s16b(&p_ptr->fast);
1416 rd_s16b(&p_ptr->slow);
1417 rd_s16b(&p_ptr->afraid);
1418 rd_s16b(&p_ptr->cut);
1419 rd_s16b(&p_ptr->stun);
1420 rd_s16b(&p_ptr->poisoned);
1421 rd_s16b(&p_ptr->image);
1422 rd_s16b(&p_ptr->protevil);
1423 rd_s16b(&p_ptr->invuln);
1424 if(z_older_than(10, 0, 0))
1427 rd_s16b(&p_ptr->ult_res);
1428 rd_s16b(&p_ptr->hero);
1429 rd_s16b(&p_ptr->shero);
1430 rd_s16b(&p_ptr->shield);
1431 rd_s16b(&p_ptr->blessed);
1432 rd_s16b(&p_ptr->tim_invis);
1433 rd_s16b(&p_ptr->word_recall);
1434 if (z_older_than(10, 3, 8))
1435 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1439 p_ptr->recall_dungeon = (byte)tmp16s;
1441 rd_s16b(&p_ptr->see_infra);
1442 rd_s16b(&p_ptr->tim_infra);
1443 rd_s16b(&p_ptr->oppose_fire);
1444 rd_s16b(&p_ptr->oppose_cold);
1445 rd_s16b(&p_ptr->oppose_acid);
1446 rd_s16b(&p_ptr->oppose_elec);
1447 rd_s16b(&p_ptr->oppose_pois);
1448 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1449 else rd_s16b(&p_ptr->tsuyoshi);
1451 /* Old savefiles do not have the following fields... */
1452 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1455 p_ptr->wraith_form = 0;
1456 p_ptr->resist_magic = 0;
1457 p_ptr->tim_regen = 0;
1458 p_ptr->kabenuke = 0;
1459 p_ptr->tim_stealth = 0;
1460 p_ptr->tim_ffall = 0;
1461 p_ptr->tim_sh_touki = 0;
1462 p_ptr->lightspeed = 0;
1463 p_ptr->tsubureru = 0;
1464 p_ptr->tim_res_nether = 0;
1465 p_ptr->tim_res_time = 0;
1466 p_ptr->mimic_form = 0;
1467 p_ptr->tim_mimic = 0;
1468 p_ptr->tim_sh_fire = 0;
1471 p_ptr->tim_reflect = 0;
1472 p_ptr->multishadow = 0;
1473 p_ptr->dustrobe = 0;
1475 p_ptr->chaos_patron = get_chaos_patron();
1483 rd_s16b(&p_ptr->tim_esp);
1484 rd_s16b(&p_ptr->wraith_form);
1485 rd_s16b(&p_ptr->resist_magic);
1486 rd_s16b(&p_ptr->tim_regen);
1487 rd_s16b(&p_ptr->kabenuke);
1488 rd_s16b(&p_ptr->tim_stealth);
1489 rd_s16b(&p_ptr->tim_ffall);
1490 rd_s16b(&p_ptr->tim_sh_touki);
1491 rd_s16b(&p_ptr->lightspeed);
1492 rd_s16b(&p_ptr->tsubureru);
1493 if (z_older_than(10, 4, 7))
1494 p_ptr->magicdef = 0;
1496 rd_s16b(&p_ptr->magicdef);
1497 rd_s16b(&p_ptr->tim_res_nether);
1498 if (z_older_than(10, 4, 11))
1500 p_ptr->tim_res_time = 0;
1501 p_ptr->mimic_form = 0;
1502 p_ptr->tim_mimic = 0;
1503 p_ptr->tim_sh_fire = 0;
1507 rd_s16b(&p_ptr->tim_res_time);
1508 rd_byte(&p_ptr->mimic_form);
1509 rd_s16b(&p_ptr->tim_mimic);
1510 rd_s16b(&p_ptr->tim_sh_fire);
1513 if (z_older_than(11, 0, 99))
1515 p_ptr->tim_sh_holy = 0;
1516 p_ptr->tim_eyeeye = 0;
1520 rd_s16b(&p_ptr->tim_sh_holy);
1521 rd_s16b(&p_ptr->tim_eyeeye);
1525 if ( z_older_than(11,0,3) ){
1526 p_ptr->tim_reflect=0;
1527 p_ptr->multishadow=0;
1531 rd_s16b(&p_ptr->tim_reflect);
1532 rd_s16b(&p_ptr->multishadow);
1533 rd_s16b(&p_ptr->dustrobe);
1536 rd_s16b(&p_ptr->chaos_patron);
1537 rd_u32b(&p_ptr->muta1);
1538 rd_u32b(&p_ptr->muta2);
1539 rd_u32b(&p_ptr->muta3);
1541 for (i = 0; i < 8; i++)
1542 rd_s16b(&p_ptr->virtues[i]);
1543 for (i = 0; i < 8; i++)
1544 rd_s16b(&p_ptr->vir_types[i]);
1547 /* Calc the regeneration modifier for mutations */
1548 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1550 if (z_older_than(10,0,9))
1553 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1554 p_ptr->ele_attack = 0;
1558 rd_s16b(&p_ptr->ele_attack);
1559 rd_u32b(&p_ptr->special_attack);
1561 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1562 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1563 if (z_older_than(10,0,12))
1565 p_ptr->ele_immune = 0;
1566 p_ptr->special_defense = 0;
1570 rd_s16b(&p_ptr->ele_immune);
1571 rd_u32b(&p_ptr->special_defense);
1573 rd_byte(&p_ptr->knowledge);
1574 rd_byte(&tmp8u); /* oops */
1575 rd_byte(&tmp8u); /* oops */
1576 rd_byte(&p_ptr->action);
1577 if (!z_older_than(10, 4, 3))
1580 if (tmp8u) p_ptr->action = ACTION_LEARN;
1582 rd_byte((byte *)&preserve_mode);
1583 rd_byte((byte *)&p_ptr->wait_report_score);
1586 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1588 /* Skip the flags */
1592 /* Hack -- the two "special seeds" */
1593 rd_u32b(&seed_flavor);
1594 rd_u32b(&seed_town);
1598 rd_u16b(&p_ptr->panic_save);
1599 rd_u16b(&p_ptr->total_winner);
1600 rd_u16b(&p_ptr->noscore);
1605 p_ptr->is_dead = tmp8u;
1607 /* Read "feeling" */
1611 /* Turn of last "feeling" */
1617 if (z_older_than(10, 3, 12))
1619 dungeon_turn = turn;
1621 else rd_s32b(&dungeon_turn);
1623 if (z_older_than(11, 0, 13))
1630 if (z_older_than(10, 3, 13))
1634 else rd_s32b(&old_battle);
1636 if (z_older_than(10,0,3))
1638 monster_race *r_ptr;
1642 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1643 r_ptr = &r_info[today_mon];
1645 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1646 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1647 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1648 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1649 if (r_ptr->rarity > 10) continue;
1650 if (r_ptr->level == 0) continue;
1654 p_ptr->today_mon = 0;
1658 rd_s16b(&today_mon);
1659 rd_s16b(&p_ptr->today_mon);
1662 if (z_older_than(10,0,7))
1668 rd_s16b(&p_ptr->riding);
1671 if (z_older_than(10,1,2))
1680 if (z_older_than(10,3,9))
1684 else if (z_older_than(10, 3, 10))
1692 rd_s32b(&p_ptr->visit);
1694 if (!z_older_than(11, 0, 5))
1696 rd_u32b(&p_ptr->count);
1704 * Read the player inventory
1706 * Note that the inventory changed in Angband 2.7.4. Two extra
1707 * pack slots were added and the equipment was rearranged. Note
1708 * that these two features combine when parsing old save-files, in
1709 * which items from the old "aux" slot are "carried", perhaps into
1710 * one of the two new "inventory" slots.
1712 * Note that the inventory is "re-sorted" later by "dungeon()".
1714 static errr rd_inventory(void)
1722 p_ptr->total_weight = 0;
1728 /* Read until done */
1733 /* Get the next item index */
1736 /* Nope, we reached the end */
1737 if (n == 0xFFFF) break;
1739 /* Get local object */
1742 /* Wipe the object */
1748 /* Hack -- verify item */
1749 if (!q_ptr->k_idx) return (53);
1751 /* Wield equipment */
1752 if (n >= INVEN_RARM)
1755 object_copy(&inventory[n], q_ptr);
1757 /* Add the weight */
1758 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1764 /* Warning -- backpack is full */
1765 else if (inven_cnt == INVEN_PACK)
1769 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1771 note("Too many items in the inventory!");
1779 /* Carry inventory */
1786 object_copy(&inventory[n], q_ptr);
1788 /* Add the weight */
1789 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1803 * Read the saved messages
1805 static void rd_messages(void)
1815 /* Read the messages */
1816 for (i = 0; i < num; i++)
1818 /* Read the message */
1819 rd_string(buf, 128);
1821 /* Save the message */
1831 * The monsters/objects must be loaded in the same order
1832 * that they were stored, since the actual indexes matter.
1834 static errr rd_dungeon(void)
1845 /*** Basic info ***/
1848 rd_s16b(&dun_level);
1849 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1850 else rd_byte(&dungeon_type);
1852 /* Set the base level for old versions */
1853 base_level = dun_level;
1855 rd_s16b(&base_level);
1857 rd_s16b(&num_repro);
1862 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1865 rd_s16b(&tmp16s); /* max_panel_rows */
1866 rd_s16b(&tmp16s); /* max_panel_cols */
1869 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1877 /*** Run length decoding ***/
1879 /* Load the dungeon data */
1880 for (x = y = 0; y < ymax; )
1884 if (z_older_than(10,3,6))
1889 /* Apply the RLE info */
1890 for (i = count; i > 0; i--)
1892 /* Access the cave */
1893 c_ptr = &cave[y][x];
1895 /* Extract "info" */
1896 if (z_older_than(10,3,6))
1897 c_ptr->info = tmp8u;
1898 else c_ptr->info = tmp16s;
1907 if (++y >= ymax) break;
1913 /*** Run length decoding ***/
1915 /* Load the dungeon data */
1916 for (x = y = 0; y < ymax; )
1922 /* Apply the RLE info */
1923 for (i = count; i > 0; i--)
1925 /* Access the cave */
1926 c_ptr = &cave[y][x];
1928 /* Extract "feat" */
1929 c_ptr->feat = tmp8u;
1938 if (++y >= ymax) break;
1943 /* Convert cave data */
1944 if (z_older_than(11, 0, 99))
1946 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
1948 /* Wipe old unused flags */
1949 cave[y][x].info &= ~(CAVE_MASK);
1953 if (h_older_than(1, 1, 1, 0))
1955 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
1957 /* Access the cave */
1958 c_ptr = &cave[y][x];
1961 if (c_ptr->feat == FEAT_INVIS)
1963 c_ptr->feat = FEAT_FLOOR;
1964 c_ptr->info |= CAVE_TRAP;
1967 /* Older than 1.1.1 */
1968 if (c_ptr->feat == FEAT_MIRROR)
1970 c_ptr->feat = FEAT_FLOOR;
1971 c_ptr->info |= CAVE_IN_MIRROR;
1976 /*** Run length decoding ***/
1978 /* Load the dungeon data */
1979 for (x = y = 0; y < ymax; )
1985 /* Apply the RLE info */
1986 for (i = count; i > 0; i--)
1988 /* Access the cave */
1989 c_ptr = &cave[y][x];
1991 /* Extract "feat" */
1992 c_ptr->mimic = tmp8u;
2001 if (++y >= ymax) break;
2006 /*** Run length decoding ***/
2008 /* Load the dungeon data */
2009 for (x = y = 0; y < ymax; )
2015 /* Apply the RLE info */
2016 for (i = count; i > 0; i--)
2018 /* Access the cave */
2019 c_ptr = &cave[y][x];
2021 /* Extract "feat" */
2022 c_ptr->special = tmp16s;
2031 if (++y >= ymax) break;
2038 /* Read the item count */
2041 /* Verify maximum */
2042 if (limit >= max_o_idx)
2045 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2047 note(format("Too many (%d) object entries!", limit));
2053 /* Read the dungeon items */
2054 for (i = 1; i < limit; i++)
2061 /* Get a new record */
2068 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2070 note(format("Object allocation error (%d <> %d)", i, o_idx));
2078 o_ptr = &o_list[o_idx];
2084 /* XXX XXX XXX XXX XXX */
2087 if (o_ptr->held_m_idx)
2089 monster_type *m_ptr;
2092 m_ptr = &m_list[o_ptr->held_m_idx];
2095 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2097 /* Place the object */
2098 m_ptr->hold_o_idx = o_idx;
2104 /* Access the item location */
2105 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2108 o_ptr->next_o_idx = c_ptr->o_idx;
2110 /* Place the object */
2111 c_ptr->o_idx = o_idx;
2118 /* Read the monster count */
2121 /* Hack -- verify */
2122 if (limit >= max_m_idx)
2125 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2127 note(format("Too many (%d) monster entries!", limit));
2133 /* Read the monsters */
2134 for (i = 1; i < limit; i++)
2138 monster_type *m_ptr;
2140 monster_race *r_ptr;
2143 /* Get a new record */
2150 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2152 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2159 /* Acquire monster */
2160 m_ptr = &m_list[m_idx];
2162 /* Read the monster */
2167 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2169 /* Mark the location */
2170 c_ptr->m_idx = m_idx;
2174 r_ptr = &r_info[m_ptr->r_idx];
2176 /* Count XXX XXX XXX */
2182 /* The dungeon is ready */
2183 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2184 character_dungeon = FALSE;
2186 character_dungeon = TRUE;
2195 * Actually read the savefile
2197 static errr rd_savefile_new_aux(void)
2209 #ifdef VERIFY_CHECKSUMS
2210 u32b n_x_check, n_v_check;
2211 u32b o_x_check, o_v_check;
2215 /* Mention the savefile version */
2218 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2220 "Loading a %d.%d.%d savefile...",
2222 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2225 /* Strip the version bytes */
2228 /* Hack -- decrypt */
2229 xor_byte = sf_extra;
2232 /* Clear the checksums */
2236 /* Read the version number of the savefile */
2237 /* Old savefile will be version 0.0.0.3 */
2238 rd_byte(&h_ver_extra);
2239 rd_byte(&h_ver_patch);
2240 rd_byte(&h_ver_minor);
2241 rd_byte(&h_ver_major);
2243 /* Operating system info */
2244 rd_u32b(&sf_system);
2246 /* Time of savefile creation */
2249 /* Number of resurrections */
2252 /* Number of times played */
2256 /* Later use (always zero) */
2259 /* Later use (always zero) */
2263 /* Read RNG state */
2266 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2268 if (arg_fiddle) note("Loaded Randomizer Info");
2273 /* Then the options */
2276 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2278 if (arg_fiddle) note("Loaded Option Flags");
2282 * Munchkin players are marked
2284 * XXX - should be replaced with a better method,
2285 * after the new scorefile-handling is implemented.
2290 p_ptr->noscore |= 0x0001;
2293 /* Then the "messages" */
2296 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2298 if (arg_fiddle) note("Loaded Messages");
2303 for (i = 0; i < max_r_idx; i++)
2305 monster_race *r_ptr;
2306 /* Access that monster */
2309 /* Hack -- Reset the death counter */
2310 r_ptr->max_num = 100;
2311 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2312 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2315 /* Monster Memory */
2318 /* Incompatible save files */
2319 if (tmp16u > max_r_idx)
2322 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2324 note(format("Too many (%u) monster races!", tmp16u));
2330 /* Read the available records */
2331 for (i = 0; i < tmp16u; i++)
2333 monster_race *r_ptr;
2338 /* Access that monster */
2343 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2345 if (arg_fiddle) note("Loaded Monster Memory");
2353 /* Incompatible save files */
2354 if (tmp16u > max_k_idx)
2357 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2359 note(format("Too many (%u) object kinds!", tmp16u));
2365 /* Read the object memory */
2366 for (i = 0; i < tmp16u; i++)
2369 object_kind *k_ptr = &k_info[i];
2373 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2374 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2377 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2379 if (arg_fiddle) note("Loaded Object Memory");
2385 * Initialize arena and rewards information
2387 p_ptr->arena_number = 0;
2388 p_ptr->inside_arena = 0;
2389 p_ptr->inside_quest = 0;
2390 p_ptr->leftbldg = FALSE;
2391 p_ptr->exit_bldg = TRUE;
2393 /* Start in town 1 */
2394 p_ptr->town_num = 1;
2396 p_ptr->wilderness_x = 4;
2397 p_ptr->wilderness_y = 4;
2401 /* Init the wilderness seeds */
2402 for (i = 0; i < max_wild_x; i++)
2404 for (j = 0; j < max_wild_y; j++)
2406 wilderness[j][i].seed = randint0(0x10000000);
2410 /* 2.1.3 or newer version */
2412 u16b max_towns_load;
2413 u16b max_quests_load;
2414 byte max_rquests_load;
2415 s16b old_inside_quest = p_ptr->inside_quest;
2417 /* Number of towns */
2418 rd_u16b(&max_towns_load);
2420 /* Incompatible save files */
2421 if (max_towns_load > max_towns)
2424 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2426 note(format("Too many (%u) towns!", max_towns_load));
2432 /* Number of quests */
2433 rd_u16b(&max_quests_load);
2435 if (z_older_than(11, 0, 7))
2437 max_rquests_load = 10;
2441 rd_byte(&max_rquests_load);
2444 /* Incompatible save files */
2445 if (max_quests_load > max_quests)
2448 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2450 note(format("Too many (%u) quests!", max_quests_load));
2456 for (i = 0; i < max_quests_load; i++)
2460 rd_s16b(&quest[i].status);
2461 rd_s16b(&quest[i].level);
2463 if (z_older_than(11, 0, 6))
2465 quest[i].complev = 0;
2469 rd_byte(&quest[i].complev);
2472 /* Load quest status if quest is running */
2473 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))))
2475 rd_s16b(&quest[i].cur_num);
2476 rd_s16b(&quest[i].max_num);
2477 rd_s16b(&quest[i].type);
2479 /* Load quest monster index */
2480 rd_s16b(&quest[i].r_idx);
2482 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2487 monster_race *r_ptr;
2490 * Random monster 5 - 10 levels out of depth
2491 * (depending on level)
2493 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
2494 r_ptr = &r_info[r_idx];
2496 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2498 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2500 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2502 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2504 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2507 * Accept monsters that are 2 - 6 levels
2508 * out of depth depending on the quest level
2510 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2513 quest[i].r_idx = r_idx;
2516 /* Load quest item index */
2517 rd_s16b(&quest[i].k_idx);
2520 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
2522 rd_byte(&quest[i].flags);
2524 if (z_older_than(10, 3, 11))
2526 if (quest[i].flags & QUEST_FLAG_PRESET)
2528 quest[i].dungeon = 0;
2532 init_flags = INIT_ASSIGN;
2533 p_ptr->inside_quest = i;
2535 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2536 p_ptr->inside_quest = old_inside_quest;
2541 rd_byte(&quest[i].dungeon);
2544 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2545 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2546 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2549 /* Ignore the empty quests from old versions */
2552 /* Ignore quest status */
2555 /* Ignore quest level */
2559 * We don't have to care about the other info,
2560 * since status should be 0 for these quests anyway
2565 /* Position in the wilderness */
2566 rd_s32b(&p_ptr->wilderness_x);
2567 rd_s32b(&p_ptr->wilderness_y);
2568 if (z_older_than(10, 3, 13))
2570 p_ptr->wilderness_x = 5;
2571 p_ptr->wilderness_y = 48;
2574 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2575 else rd_byte((byte *)&p_ptr->wild_mode);
2576 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2577 else rd_byte((byte *)&ambush_flag);
2579 /* Size of the wilderness */
2580 rd_s32b(&wild_x_size);
2581 rd_s32b(&wild_y_size);
2583 /* Incompatible save files */
2584 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2587 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2589 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2595 /* Load the wilderness seeds */
2596 for (i = 0; i < wild_x_size; i++)
2598 for (j = 0; j < wild_y_size; j++)
2600 rd_u32b(&wilderness[j][i].seed);
2606 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2608 if (arg_fiddle) note("Loaded Quests");
2611 /* Load the Artifacts */
2614 /* Incompatible save files */
2615 if (tmp16u > max_a_idx)
2618 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2620 note(format("Too many (%u) artifacts!", tmp16u));
2626 /* Read the artifact flags */
2627 for (i = 0; i < tmp16u; i++)
2630 a_info[i].cur_num = tmp8u;
2636 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2638 if (arg_fiddle) note("Loaded Artifacts");
2643 /* Read the extra stuff */
2645 if (p_ptr->energy_need < -999) world_player = TRUE;
2648 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2650 if (arg_fiddle) note("Loaded extra information");
2654 /* Read the player_hp array */
2657 /* Incompatible save files */
2658 if (tmp16u > PY_MAX_LEVEL)
2661 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2663 note(format("Too many (%u) hitpoint entries!", tmp16u));
2669 /* Read the player_hp array */
2670 for (i = 0; i < tmp16u; i++)
2672 rd_s16b(&p_ptr->player_hp[i]);
2675 /* Important -- Initialize the sex */
2676 sp_ptr = &sex_info[p_ptr->psex];
2678 /* Important -- Initialize the race/class */
2679 rp_ptr = &race_info[p_ptr->prace];
2680 cp_ptr = &class_info[p_ptr->pclass];
2681 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2683 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
2685 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2686 do_cmd_rerate(FALSE);
2688 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
2690 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2691 do_cmd_rerate(FALSE);
2693 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
2695 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2696 do_cmd_rerate(FALSE);
2698 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
2700 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2701 do_cmd_rerate(FALSE);
2704 /* Important -- Initialize the magic */
2705 mp_ptr = &m_info[p_ptr->pclass];
2708 /* Read spell info */
2709 rd_u32b(&p_ptr->spell_learned1);
2710 rd_u32b(&p_ptr->spell_learned2);
2711 rd_u32b(&p_ptr->spell_worked1);
2712 rd_u32b(&p_ptr->spell_worked2);
2713 rd_u32b(&p_ptr->spell_forgotten1);
2714 rd_u32b(&p_ptr->spell_forgotten2);
2716 if (z_older_than(10,0,5))
2718 p_ptr->learned_spells = 0;
2719 for (i = 0; i < 64; i++)
2721 /* Count known spells */
2723 (p_ptr->spell_learned1 & (1L << i)) :
2724 (p_ptr->spell_learned2 & (1L << (i - 32))))
2726 p_ptr->learned_spells++;
2730 else rd_s16b(&p_ptr->learned_spells);
2732 if (z_older_than(10,0,6))
2734 p_ptr->add_spells = 0;
2736 else rd_s16b(&p_ptr->add_spells);
2737 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2739 for (i = 0; i < 64; i++)
2741 rd_byte(&p_ptr->spell_order[i]);
2745 /* Read the inventory */
2749 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2751 note("Unable to read inventory");
2757 /* Read number of towns */
2759 town_count = tmp16u;
2761 /* Read the stores */
2763 for (i = 1; i < town_count; i++)
2765 for (j = 0; j < tmp16u; j++)
2767 if (rd_store(i, j)) return (22);
2771 rd_s16b(&p_ptr->pet_follow_distance);
2772 if (z_older_than(10, 4, 10))
2774 p_ptr->pet_extra_flags = 0;
2776 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2778 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2780 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2784 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2787 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2791 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2794 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2798 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2801 if (!z_older_than(10,0,8))
2804 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2809 rd_s16b(&p_ptr->pet_extra_flags);
2812 if (!z_older_than(11, 0, 9))
2814 char buf[SCREEN_BUF_SIZE];
2815 rd_string(buf, SCREEN_BUF_SIZE);
2816 if (buf[0]) screen_dump = string_make(buf);
2821 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2823 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2828 /* I'm not dead yet... */
2829 if (!p_ptr->is_dead)
2831 /* Dead players have no dungeon */
2833 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2835 note("Restoring Dungeon...");
2841 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2843 note("Error reading dungeon data");
2849 /* Read the ghost info */
2856 strip_bytes(tmp32s);
2861 #ifdef VERIFY_CHECKSUMS
2863 /* Save the checksum */
2864 n_v_check = v_check;
2866 /* Read the old checksum */
2867 rd_u32b(&o_v_check);
2870 if (o_v_check != n_v_check)
2873 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2875 note("Invalid checksum");
2882 /* Save the encoded checksum */
2883 n_x_check = x_check;
2885 /* Read the checksum */
2886 rd_u32b(&o_x_check);
2890 if (o_x_check != n_x_check)
2893 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2895 note("Invalid encoded checksum");
2909 * Actually read the savefile
2911 errr rd_savefile_new(void)
2915 /* The savefile is a binary file */
2916 fff = my_fopen(savefile, "rb");
2919 if (!fff) return (-1);
2921 /* Call the sub-function */
2922 err = rd_savefile_new_aux();
2924 /* Check for errors */
2925 if (ferror(fff)) err = -1;
2927 /* Close the file */