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 * Hack -- determine if an item is "wearable" (or a missile)
139 static bool wearable_p(object_type *o_ptr)
141 /* Valid "tval" codes */
177 * The following functions are used to load the basic building blocks
178 * of savefiles. They also maintain the "checksum" info for 2.7.0+
181 static byte sf_get(void)
185 /* Get a character, decode the value */
186 c = getc(fff) & 0xFF;
190 /* Maintain the checksum info */
194 /* Return the value */
198 static void rd_byte(byte *ip)
203 static void rd_u16b(u16b *ip)
206 (*ip) |= ((u16b)(sf_get()) << 8);
209 static void rd_s16b(s16b *ip)
214 static void rd_u32b(u32b *ip)
217 (*ip) |= ((u32b)(sf_get()) << 8);
218 (*ip) |= ((u32b)(sf_get()) << 16);
219 (*ip) |= ((u32b)(sf_get()) << 24);
222 static void rd_s32b(s32b *ip)
229 * Hack -- read a string
231 static void rd_string(char *str, int max)
235 /* Read the string */
236 for (i = 0; TRUE; i++)
243 /* Collect string while legal */
244 if (i < max) str[i] = tmp8u;
259 * Hack -- strip some bytes
261 static void strip_bytes(int n)
265 /* Strip the bytes */
266 while (n--) rd_byte(&tmp8u);
269 #define OLD_MAX_MANE 22
274 * This function attempts to "repair" old savefiles, and to extract
275 * the most up to date values for various object fields.
277 * Note that Angband 2.7.9 introduced a new method for object "flags"
278 * in which the "flags" on an object are actually extracted when they
279 * are needed from the object kind, artifact index, ego-item index,
280 * and two special "xtra" fields which are used to encode any "extra"
281 * power of certain ego-items. This had the side effect that items
282 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
283 * may have had, and also, all "uncursed" items will become "cursed"
284 * again, including Calris, even if it is being worn at the time. As
285 * a complete hack, items which are inscribed with "uncursed" will be
286 * "uncursed" when imported from pre-2.7.9 savefiles.
288 static void rd_item(object_type *o_ptr)
296 rd_s16b(&o_ptr->k_idx);
303 rd_byte(&o_ptr->tval);
304 rd_byte(&o_ptr->sval);
306 if (z_older_than(10, 4, 4))
308 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
309 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
310 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
314 rd_s16b(&o_ptr->pval);
316 rd_byte(&o_ptr->discount);
317 rd_byte(&o_ptr->number);
318 rd_s16b(&o_ptr->weight);
320 rd_byte(&o_ptr->name1);
321 rd_byte(&o_ptr->name2);
322 rd_s16b(&o_ptr->timeout);
324 rd_s16b(&o_ptr->to_h);
325 rd_s16b(&o_ptr->to_d);
326 rd_s16b(&o_ptr->to_a);
333 rd_byte(&o_ptr->ident);
335 rd_byte(&o_ptr->marked);
338 rd_u32b(&o_ptr->art_flags1);
339 rd_u32b(&o_ptr->art_flags2);
340 rd_u32b(&o_ptr->art_flags3);
342 if (z_older_than(11, 0, 11))
344 o_ptr->curse_flags = 0L;
345 if (o_ptr->ident & 0x40)
347 o_ptr->curse_flags |= TRC_CURSED;
348 if (o_ptr->art_flags3 & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
349 if (o_ptr->art_flags3 & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
352 artifact_type *a_ptr = &a_info[o_ptr->name1];
353 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
354 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
356 else if (o_ptr->name2)
358 ego_item_type *e_ptr = &e_info[o_ptr->name2];
359 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
360 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
363 o_ptr->art_flags3 &= (0x1FFFFFFFL);
367 rd_u32b(&o_ptr->curse_flags);
370 /* Monster holding object */
371 rd_s16b(&o_ptr->held_m_idx);
374 rd_byte(&o_ptr->xtra1);
375 rd_byte(&o_ptr->xtra2);
377 if (z_older_than(11, 0, 10))
379 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
381 switch (o_ptr->xtra2 % 6)
383 case 0: o_ptr->art_flags2 |= (TR2_SUST_STR); break;
384 case 1: o_ptr->art_flags2 |= (TR2_SUST_INT); break;
385 case 2: o_ptr->art_flags2 |= (TR2_SUST_WIS); break;
386 case 3: o_ptr->art_flags2 |= (TR2_SUST_DEX); break;
387 case 4: o_ptr->art_flags2 |= (TR2_SUST_CON); break;
388 case 5: o_ptr->art_flags2 |= (TR2_SUST_CHR); break;
392 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
394 switch (o_ptr->xtra2 % 11)
396 case 0: o_ptr->art_flags2 |= (TR2_RES_BLIND); break;
397 case 1: o_ptr->art_flags2 |= (TR2_RES_CONF); break;
398 case 2: o_ptr->art_flags2 |= (TR2_RES_SOUND); break;
399 case 3: o_ptr->art_flags2 |= (TR2_RES_SHARDS); break;
400 case 4: o_ptr->art_flags2 |= (TR2_RES_NETHER); break;
401 case 5: o_ptr->art_flags2 |= (TR2_RES_NEXUS); break;
402 case 6: o_ptr->art_flags2 |= (TR2_RES_CHAOS); break;
403 case 7: o_ptr->art_flags2 |= (TR2_RES_DISEN); break;
404 case 8: o_ptr->art_flags2 |= (TR2_RES_POIS); break;
405 case 9: o_ptr->art_flags2 |= (TR2_RES_DARK); break;
406 case 10: o_ptr->art_flags2 |= (TR2_RES_LITE); break;
410 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
412 switch (o_ptr->xtra2 % 8)
414 case 0: o_ptr->art_flags3 |= (TR3_FEATHER); break;
415 case 1: o_ptr->art_flags3 |= (TR3_LITE); break;
416 case 2: o_ptr->art_flags3 |= (TR3_SEE_INVIS); break;
417 case 3: o_ptr->art_flags3 |= (TR3_WARNING); break;
418 case 4: o_ptr->art_flags3 |= (TR3_SLOW_DIGEST); break;
419 case 5: o_ptr->art_flags3 |= (TR3_REGEN); break;
420 case 6: o_ptr->art_flags2 |= (TR2_FREE_ACT); break;
421 case 7: o_ptr->art_flags2 |= (TR2_HOLD_LIFE); break;
428 if (z_older_than(10, 2, 3))
433 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
435 o_ptr->xtra3 = o_ptr->xtra1;
438 if (o_ptr->tval == TV_CAPTURE)
440 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
441 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
443 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
444 if (ironman_nightmare)
446 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
448 o_ptr->xtra4 = o_ptr->xtra5;
453 rd_byte(&o_ptr->xtra3);
454 rd_s16b(&o_ptr->xtra4);
455 rd_s16b(&o_ptr->xtra5);
458 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)))
460 o_ptr->xtra4 = o_ptr->pval;
464 /* Feeling - from 2.3.1, "savefile version 1" */
467 rd_byte(&o_ptr->feeling);
473 /* If this savefile is old, maybe we need to translate the feeling */
478 for (i = 0; i <= FEEL_MAX; i++)
480 if (game_inscriptions[i] == NULL)
485 if (streq(buf, game_inscriptions[i]))
494 /* Save the inscription */
495 if (buf[0]) o_ptr->inscription = quark_add(buf);
498 if (buf[0]) o_ptr->art_name = quark_add(buf);
500 /* The Python object */
508 /* Mega-Hack -- handle "dungeon objects" later */
509 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
511 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
513 if (z_older_than(10, 4, 9))
515 if (o_ptr->art_flags1 & TR1_MAGIC_MASTERY)
517 o_ptr->art_flags1 &= ~(TR1_MAGIC_MASTERY);
518 o_ptr->art_flags3 |= (TR3_DEC_MANA);
525 artifact_type *a_ptr;
527 /* Obtain the artifact info */
528 a_ptr = &a_info[o_ptr->name1];
530 /* Verify that artifact */
531 if (!a_ptr->name) o_ptr->name1 = 0;
537 ego_item_type *e_ptr;
539 /* Obtain the ego-item info */
540 e_ptr = &e_info[o_ptr->name2];
542 /* Verify that ego-item */
543 if (!e_ptr->name) o_ptr->name2 = 0;
554 static void rd_monster(monster_type *m_ptr)
559 /* Read the monster race */
560 rd_s16b(&m_ptr->r_idx);
562 /* Read the other information */
566 rd_s16b(&m_ptr->maxhp);
567 if (z_older_than(11, 0, 5))
569 m_ptr->max_maxhp = m_ptr->maxhp;
573 rd_s16b(&m_ptr->max_maxhp);
575 rd_s16b(&m_ptr->csleep);
576 rd_byte(&m_ptr->mspeed);
577 if (z_older_than(10, 4, 2))
580 m_ptr->energy = (s16b)tmp8u;
582 else rd_s16b(&m_ptr->energy);
583 if (z_older_than(10,0,7))
590 rd_byte(&m_ptr->fast);
591 rd_byte(&m_ptr->slow);
593 rd_byte(&m_ptr->stunned);
594 rd_byte(&m_ptr->confused);
595 rd_byte(&m_ptr->monfear);
597 if (z_older_than(10,0,10))
601 else if (z_older_than(10,0,11))
609 rd_s16b(&m_ptr->target_y);
610 rd_s16b(&m_ptr->target_x);
613 /* Monster invulnerability introduced from 2.3.2+ */
617 rd_byte(&m_ptr->invulner);
619 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
620 rd_u32b(&m_ptr->smart);
624 if (z_older_than(10, 4, 5))
627 rd_u32b(&m_ptr->exp);
629 if (z_older_than(10, 2, 2))
631 if (m_ptr->r_idx < 0)
633 m_ptr->r_idx = (0-m_ptr->r_idx);
634 m_ptr->mflag2 |= MFLAG_KAGE;
639 rd_byte(&m_ptr->mflag2);
642 if (z_older_than(10, 1, 3))
649 if (buf[0]) m_ptr->nickname = quark_add(buf);
660 * Read the monster lore
662 static void rd_lore(int r_idx)
666 monster_race *r_ptr = &r_info[r_idx];
668 /* Count sights/deaths/kills */
669 rd_s16b(&r_ptr->r_sights);
670 rd_s16b(&r_ptr->r_deaths);
671 rd_s16b(&r_ptr->r_pkills);
672 rd_s16b(&r_ptr->r_tkills);
674 /* Count wakes and ignores */
675 rd_byte(&r_ptr->r_wake);
676 rd_byte(&r_ptr->r_ignore);
679 rd_byte(&r_ptr->r_xtra1);
680 rd_byte(&r_ptr->r_xtra2);
683 rd_byte(&r_ptr->r_drop_gold);
684 rd_byte(&r_ptr->r_drop_item);
687 rd_byte(&r_ptr->r_cast_inate);
688 rd_byte(&r_ptr->r_cast_spell);
690 /* Count blows of each type */
691 rd_byte(&r_ptr->r_blows[0]);
692 rd_byte(&r_ptr->r_blows[1]);
693 rd_byte(&r_ptr->r_blows[2]);
694 rd_byte(&r_ptr->r_blows[3]);
697 rd_u32b(&r_ptr->r_flags1);
698 rd_u32b(&r_ptr->r_flags2);
699 rd_u32b(&r_ptr->r_flags3);
700 rd_u32b(&r_ptr->r_flags4);
701 rd_u32b(&r_ptr->r_flags5);
702 rd_u32b(&r_ptr->r_flags6);
704 /* Read the "Racial" monster limit per level */
705 rd_byte(&r_ptr->max_num);
712 /* Repair the lore flags */
713 r_ptr->r_flags1 &= r_ptr->flags1;
714 r_ptr->r_flags2 &= r_ptr->flags2;
715 r_ptr->r_flags3 &= r_ptr->flags3;
716 r_ptr->r_flags4 &= r_ptr->flags4;
717 r_ptr->r_flags5 &= r_ptr->flags5;
718 r_ptr->r_flags6 &= r_ptr->flags6;
725 * Add the item "o_ptr" to the inventory of the "Home"
727 * In all cases, return the slot (or -1) where the object was placed
729 * Note that this is a hacked up version of "inven_carry()".
731 * Also note that it may not correctly "adapt" to "knowledge" bacoming
732 * known, the player may have to pick stuff up and drop it again.
734 static void home_carry(store_type *st_ptr, object_type *o_ptr)
742 /* Check each existing item (try to combine) */
743 for (slot = 0; slot < st_ptr->stock_num; slot++)
745 /* Get the existing item */
746 j_ptr = &st_ptr->stock[slot];
748 /* The home acts just like the player */
749 if (object_similar(j_ptr, o_ptr))
751 /* Save the new number of items */
752 object_absorb(j_ptr, o_ptr);
760 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
764 /* Determine the "value" of the item */
765 value = object_value(o_ptr);
767 /* Check existing slots to see if we must "slide" */
768 for (slot = 0; slot < st_ptr->stock_num; slot++)
771 j_ptr = &st_ptr->stock[slot];
773 /* Hack -- readable books always come first */
774 if ((o_ptr->tval == mp_ptr->spell_book) &&
775 (j_ptr->tval != mp_ptr->spell_book)) break;
776 if ((j_ptr->tval == mp_ptr->spell_book) &&
777 (o_ptr->tval != mp_ptr->spell_book)) continue;
779 /* Objects sort by decreasing type */
780 if (o_ptr->tval > j_ptr->tval) break;
781 if (o_ptr->tval < j_ptr->tval) continue;
783 /* Can happen in the home */
784 if (!object_aware_p(o_ptr)) continue;
785 if (!object_aware_p(j_ptr)) break;
787 /* Objects sort by increasing sval */
788 if (o_ptr->sval < j_ptr->sval) break;
789 if (o_ptr->sval > j_ptr->sval) continue;
791 /* Objects in the home can be unknown */
792 if (!object_known_p(o_ptr)) continue;
793 if (!object_known_p(j_ptr)) break;
796 * Hack: otherwise identical rods sort by
797 * increasing recharge time --dsb
799 if (o_ptr->tval == TV_ROD)
801 if (o_ptr->pval < j_ptr->pval) break;
802 if (o_ptr->pval > j_ptr->pval) continue;
805 /* Objects sort by decreasing value */
806 j_value = object_value(j_ptr);
807 if (value > j_value) break;
808 if (value < j_value) continue;
811 /* Slide the others up */
812 for (i = st_ptr->stock_num; i > slot; i--)
814 st_ptr->stock[i] = st_ptr->stock[i-1];
820 /* Insert the new item */
821 st_ptr->stock[slot] = *o_ptr;
823 chg_virtue(V_SACRIFICE, -1);
825 /* Return the location */
833 static errr rd_store(int town_number, int store_number)
845 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
847 st_ptr = &town[1].store[store_number];
848 if (st_ptr->stock_num) sort = TRUE;
852 st_ptr = &town[town_number].store[store_number];
855 /* Read the basic info */
856 rd_s32b(&st_ptr->store_open);
857 rd_s16b(&st_ptr->insult_cur);
859 if (z_older_than(11, 0, 4))
868 rd_s16b(&st_ptr->good_buy);
869 rd_s16b(&st_ptr->bad_buy);
871 /* Read last visit */
872 rd_s32b(&st_ptr->last_visit);
874 /* Extract the owner (see above) */
878 for (j = 0; j < num; j++)
883 /* Get local object */
886 /* Wipe the object */
892 /* Acquire valid items */
893 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
898 home_carry(st_ptr, q_ptr);
902 k = st_ptr->stock_num++;
904 /* Acquire the item */
905 object_copy(&st_ptr->stock[k], q_ptr);
917 * Read RNG state (added in 2.8.0)
919 static void rd_randomizer(void)
929 rd_u16b(&Rand_place);
932 for (i = 0; i < RAND_DEG; i++)
934 rd_u32b(&Rand_state[i]);
944 * Read options (ignore most pre-2.8.0 options)
946 * Note that the normal options are now stored as a set of 256 bit flags,
947 * plus a set of 256 bit masks to indicate which bit flags were defined
948 * at the time the savefile was created. This will allow new options
949 * to be added, and old options to be removed, at any time, without
950 * hurting old savefiles.
952 * The window options are stored in the same way, but note that each
953 * window gets 32 options, and their order is fixed by certain defines.
955 static void rd_options(void)
969 /* Ignore old options */
975 /* Read "delay_factor" */
979 /* Read "hitpoint_warn" */
984 /*** Cheating options ***/
988 if (c & 0x0002) wizard = TRUE;
990 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
991 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
992 cheat_room = (c & 0x0400) ? TRUE : FALSE;
993 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
994 cheat_know = (c & 0x1000) ? TRUE : FALSE;
995 cheat_live = (c & 0x2000) ? TRUE : FALSE;
997 rd_byte((byte *)&autosave_l);
998 rd_byte((byte *)&autosave_t);
999 rd_s16b(&autosave_freq);
1002 /*** Normal Options ***/
1004 /* Read the option flags */
1005 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1007 /* Read the option masks */
1008 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1010 /* Analyze the options */
1011 for (n = 0; n < 8; n++)
1013 /* Analyze the options */
1014 for (i = 0; i < 32; i++)
1016 /* Process valid flags */
1017 if (mask[n] & (1L << i))
1019 /* Process valid flags */
1020 if (option_mask[n] & (1L << i))
1023 if (flag[n] & (1L << i))
1026 option_flag[n] |= (1L << i);
1033 option_flag[n] &= ~(1L << i);
1040 if (z_older_than(10, 4, 5))
1042 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1043 else option_flag[5] |= (0x00000001 << 4);
1044 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1045 else option_flag[2] |= (0x00000001 << 5);
1046 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1047 else option_flag[4] |= (0x00000001 << 5);
1048 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1049 else option_flag[5] |= (0x00000001 << 0);
1050 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1051 else option_flag[5] |= (0x00000001 << 12);
1052 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1053 else option_flag[1] |= (0x00000001 << 0);
1054 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1055 else option_flag[1] |= (0x00000001 << 18);
1056 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1057 else option_flag[1] |= (0x00000001 << 19);
1058 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1059 else option_flag[5] |= (0x00000001 << 3);
1063 /*** Window Options ***/
1065 /* Read the window flags */
1066 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1068 /* Read the window masks */
1069 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1071 /* Analyze the options */
1072 for (n = 0; n < 8; n++)
1074 /* Analyze the options */
1075 for (i = 0; i < 32; i++)
1077 /* Process valid flags */
1078 if (mask[n] & (1L << i))
1080 /* Process valid flags */
1081 if (window_mask[n] & (1L << i))
1084 if (flag[n] & (1L << i))
1087 window_flag[n] |= (1L << i);
1094 window_flag[n] &= ~(1L << i);
1107 * Hack -- strip the "ghost" info
1109 * XXX XXX XXX This is such a nasty hack it hurts.
1111 static void rd_ghost(void)
1118 /* Strip old data */
1126 * Read the "extra" information
1128 static void rd_extra(void)
1135 rd_string(player_name, 32);
1137 rd_string(died_from, 80);
1139 for (i = 0; i < 4; i++)
1141 rd_string(history[i], 60);
1144 /* Class/Race/Seikaku/Gender/Spells */
1145 rd_byte(&p_ptr->prace);
1146 rd_byte(&p_ptr->pclass);
1147 rd_byte(&p_ptr->pseikaku);
1148 rd_byte(&p_ptr->psex);
1149 rd_byte(&p_ptr->realm1);
1150 rd_byte(&p_ptr->realm2);
1151 rd_byte(&tmp8u); /* oops */
1153 if (z_older_than(10, 4, 4))
1155 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1156 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1157 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1158 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1161 /* Special Race/Class info */
1162 rd_byte(&p_ptr->hitdie);
1163 rd_u16b(&p_ptr->expfact);
1165 /* Age/Height/Weight */
1166 rd_s16b(&p_ptr->age);
1167 rd_s16b(&p_ptr->ht);
1168 rd_s16b(&p_ptr->wt);
1170 /* Read the stat info */
1171 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1172 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1173 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1175 strip_bytes(24); /* oops */
1177 rd_s32b(&p_ptr->au);
1179 rd_s32b(&p_ptr->max_exp);
1180 rd_s32b(&p_ptr->exp);
1181 rd_u16b(&p_ptr->exp_frac);
1183 rd_s16b(&p_ptr->lev);
1185 for (i = 0; i < 64; i++) rd_s16b(&spell_exp[i]);
1186 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1188 for (i = 0; i < 64; i++) spell_exp[i] = 1600;
1190 if (z_older_than(10, 3, 6))
1191 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&weapon_exp[i][j]);
1193 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&weapon_exp[i][j]);
1194 for (i = 0; i < 10; i++) rd_s16b(&skill_exp[i]);
1195 if (z_older_than(10, 4, 1))
1197 if (p_ptr->pclass != CLASS_BEASTMASTER) skill_exp[GINOU_RIDING] /= 2;
1198 skill_exp[GINOU_RIDING] = MIN(skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1200 if (z_older_than(10, 3, 14))
1202 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1203 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1207 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1208 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1210 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1212 if (z_older_than(11, 0, 7))
1214 p_ptr->start_race = p_ptr->prace;
1215 p_ptr->old_race1 = 0L;
1216 p_ptr->old_race2 = 0L;
1217 p_ptr->old_realm = 0;
1221 rd_byte(&p_ptr->start_race);
1222 rd_s32b(&p_ptr->old_race1);
1223 rd_s32b(&p_ptr->old_race2);
1224 rd_s16b(&p_ptr->old_realm);
1227 if (z_older_than(10, 0, 1))
1229 for (i = 0; i < OLD_MAX_MANE; i++)
1236 else if (z_older_than(10, 2, 3))
1238 for (i = 0; i < OLD_MAX_MANE; i++)
1243 for (i = 0; i < MAX_MANE; i++)
1253 for (i = 0; i < MAX_MANE; i++)
1255 rd_s16b(&mane_spell[i]);
1256 rd_s16b(&mane_dam[i]);
1261 if (z_older_than(10, 0, 3))
1263 get_mon_num_prep(NULL, NULL);
1264 for (i = 0; i < MAX_KUBI; i++)
1266 monster_race *r_ptr;
1271 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1272 r_ptr = &r_info[kubi_r_idx[i]];
1274 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1276 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1278 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1280 for (j = 0; j < i; j++)
1281 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1286 for (i = 0; i < MAX_KUBI -1; i++)
1289 for (j = i; j < MAX_KUBI; j++)
1291 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1293 tmp = kubi_r_idx[i];
1294 kubi_r_idx[i] = kubi_r_idx[j];
1295 kubi_r_idx[j] = tmp;
1299 for (i = 0; i < MAX_KUBI; i++)
1301 if(!r_info[kubi_r_idx[i]].max_num)
1302 kubi_r_idx[i] += 10000;
1307 for (i = 0; i < MAX_KUBI; i++)
1309 rd_s16b(&kubi_r_idx[i]);
1313 if (z_older_than(10, 0, 3))
1319 for (i = 0; i < 4; i++)
1321 rd_s16b(&battle_mon[i]);
1322 if (z_older_than(10, 3, 4))
1325 mon_odds[i] = tmp16s;
1327 else rd_u32b(&mon_odds[i]);
1331 rd_s16b(&p_ptr->town_num);
1333 /* Read arena and rewards information */
1334 rd_s16b(&p_ptr->arena_number);
1336 p_ptr->inside_arena = (bool)tmp16s;
1337 rd_s16b(&p_ptr->inside_quest);
1338 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1342 p_ptr->inside_battle = (bool)tmp16s;
1344 rd_byte(&p_ptr->exit_bldg);
1345 rd_byte(&p_ptr->leftbldg);
1347 rd_s16b(&p_ptr->oldpx);
1348 rd_s16b(&p_ptr->oldpy);
1349 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1353 if (tmp16s > MAX_BACT)
1356 note(format("¤ÎÃæ", tmp16s));
1358 note(format("Too many (%d) building rewards!", tmp16s));
1363 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1365 rd_s16b(&p_ptr->mhp);
1366 rd_s16b(&p_ptr->chp);
1367 rd_u16b(&p_ptr->chp_frac);
1369 rd_s16b(&p_ptr->msp);
1370 rd_s16b(&p_ptr->csp);
1371 rd_u16b(&p_ptr->csp_frac);
1373 rd_s16b(&p_ptr->max_plv);
1374 if (z_older_than(10, 3, 8))
1376 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1380 byte max = (byte)max_d_idx;
1384 for(i = 0; i < max; i++)
1386 rd_s16b(&max_dlv[i]);
1387 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1391 /* Repair maximum player level XXX XXX XXX */
1392 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1396 rd_s16b(&p_ptr->sc);
1399 /* Read the flags */
1400 strip_bytes(2); /* Old "rest" */
1401 rd_s16b(&p_ptr->blind);
1402 rd_s16b(&p_ptr->paralyzed);
1403 rd_s16b(&p_ptr->confused);
1404 rd_s16b(&p_ptr->food);
1405 strip_bytes(4); /* Old "food_digested" / "protection" */
1406 rd_s16b(&p_ptr->energy);
1407 rd_s16b(&p_ptr->fast);
1408 rd_s16b(&p_ptr->slow);
1409 rd_s16b(&p_ptr->afraid);
1410 rd_s16b(&p_ptr->cut);
1411 rd_s16b(&p_ptr->stun);
1412 rd_s16b(&p_ptr->poisoned);
1413 rd_s16b(&p_ptr->image);
1414 rd_s16b(&p_ptr->protevil);
1415 rd_s16b(&p_ptr->invuln);
1416 if(z_older_than(10, 0, 0))
1419 rd_s16b(&p_ptr->ult_res);
1420 rd_s16b(&p_ptr->hero);
1421 rd_s16b(&p_ptr->shero);
1422 rd_s16b(&p_ptr->shield);
1423 rd_s16b(&p_ptr->blessed);
1424 rd_s16b(&p_ptr->tim_invis);
1425 rd_s16b(&p_ptr->word_recall);
1426 if (z_older_than(10, 3, 8))
1427 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1431 p_ptr->recall_dungeon = (byte)tmp16s;
1433 rd_s16b(&p_ptr->see_infra);
1434 rd_s16b(&p_ptr->tim_infra);
1435 rd_s16b(&p_ptr->oppose_fire);
1436 rd_s16b(&p_ptr->oppose_cold);
1437 rd_s16b(&p_ptr->oppose_acid);
1438 rd_s16b(&p_ptr->oppose_elec);
1439 rd_s16b(&p_ptr->oppose_pois);
1440 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1441 else rd_s16b(&p_ptr->tsuyoshi);
1443 /* Old savefiles do not have the following fields... */
1444 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1447 p_ptr->wraith_form = 0;
1448 p_ptr->resist_magic = 0;
1449 p_ptr->tim_regen = 0;
1450 p_ptr->kabenuke = 0;
1451 p_ptr->tim_stealth = 0;
1452 p_ptr->tim_ffall = 0;
1453 p_ptr->tim_sh_touki = 0;
1454 p_ptr->lightspeed = 0;
1455 p_ptr->tsubureru = 0;
1456 p_ptr->tim_res_nether = 0;
1457 p_ptr->tim_res_time = 0;
1458 p_ptr->mimic_form = 0;
1459 p_ptr->tim_mimic = 0;
1460 p_ptr->tim_sh_fire = 0;
1463 p_ptr->tim_reflect = 0;
1464 p_ptr->multishadow = 0;
1465 p_ptr->dustrobe = 0;
1467 p_ptr->chaos_patron = get_chaos_patron();
1475 rd_s16b(&p_ptr->tim_esp);
1476 rd_s16b(&p_ptr->wraith_form);
1477 rd_s16b(&p_ptr->resist_magic);
1478 rd_s16b(&p_ptr->tim_regen);
1479 rd_s16b(&p_ptr->kabenuke);
1480 rd_s16b(&p_ptr->tim_stealth);
1481 rd_s16b(&p_ptr->tim_ffall);
1482 rd_s16b(&p_ptr->tim_sh_touki);
1483 rd_s16b(&p_ptr->lightspeed);
1484 rd_s16b(&p_ptr->tsubureru);
1485 if (z_older_than(10, 4, 7))
1486 p_ptr->magicdef = 0;
1488 rd_s16b(&p_ptr->magicdef);
1489 rd_s16b(&p_ptr->tim_res_nether);
1490 if (z_older_than(10, 4, 11))
1492 p_ptr->tim_res_time = 0;
1493 p_ptr->mimic_form = 0;
1494 p_ptr->tim_mimic = 0;
1495 p_ptr->tim_sh_fire = 0;
1499 rd_s16b(&p_ptr->tim_res_time);
1500 rd_byte(&p_ptr->mimic_form);
1501 rd_s16b(&p_ptr->tim_mimic);
1502 rd_s16b(&p_ptr->tim_sh_fire);
1506 if ( z_older_than(11,0,3) ){
1507 p_ptr->tim_reflect=0;
1508 p_ptr->multishadow=0;
1512 rd_s16b(&p_ptr->tim_reflect);
1513 rd_s16b(&p_ptr->multishadow);
1514 rd_s16b(&p_ptr->dustrobe);
1517 rd_s16b(&p_ptr->chaos_patron);
1518 rd_u32b(&p_ptr->muta1);
1519 rd_u32b(&p_ptr->muta2);
1520 rd_u32b(&p_ptr->muta3);
1522 for (i = 0; i < 8; i++)
1523 rd_s16b(&p_ptr->virtues[i]);
1524 for (i = 0; i < 8; i++)
1525 rd_s16b(&p_ptr->vir_types[i]);
1528 /* Calc the regeneration modifier for mutations */
1529 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1531 if (z_older_than(10,0,9))
1534 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1535 p_ptr->ele_attack = 0;
1539 rd_s16b(&p_ptr->ele_attack);
1540 rd_u32b(&p_ptr->special_attack);
1542 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1543 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1544 if (z_older_than(10,0,12))
1546 p_ptr->ele_immune = 0;
1547 p_ptr->special_defense = 0;
1551 rd_s16b(&p_ptr->ele_immune);
1552 rd_u32b(&p_ptr->special_defense);
1554 rd_byte(&p_ptr->knowledge);
1555 rd_byte(&tmp8u); /* oops */
1556 rd_byte(&tmp8u); /* oops */
1557 rd_byte(&p_ptr->action);
1558 if (!z_older_than(10, 4, 3))
1561 if (tmp8u) p_ptr->action = ACTION_LEARN;
1563 rd_byte((byte *)&preserve_mode);
1564 rd_byte((byte *)&wait_report_score);
1567 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1569 /* Skip the flags */
1573 /* Hack -- the two "special seeds" */
1574 rd_u32b(&seed_flavor);
1575 rd_u32b(&seed_town);
1579 rd_u16b(&panic_save);
1580 rd_u16b(&total_winner);
1588 /* Read "feeling" */
1592 /* Turn of last "feeling" */
1598 if (z_older_than(10, 3, 12))
1600 dungeon_turn = turn;
1602 else rd_s32b(&dungeon_turn);
1604 if (z_older_than(10, 3, 13))
1608 else rd_s32b(&old_battle);
1610 if (z_older_than(10,0,3))
1612 monster_race *r_ptr;
1616 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1617 r_ptr = &r_info[today_mon];
1619 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1620 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1621 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1622 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1623 if (r_ptr->rarity > 10) continue;
1624 if (r_ptr->level == 0) continue;
1628 p_ptr->today_mon = 0;
1632 rd_s16b(&today_mon);
1633 rd_s16b(&p_ptr->today_mon);
1636 if (z_older_than(10,0,7))
1642 rd_s16b(&p_ptr->riding);
1645 if (z_older_than(10,1,2))
1654 if (z_older_than(10,3,9))
1658 else if (z_older_than(10, 3, 10))
1666 rd_s32b(&p_ptr->visit);
1668 if (!z_older_than(11, 0, 5))
1670 rd_u32b(&p_ptr->count);
1678 * Read the player inventory
1680 * Note that the inventory changed in Angband 2.7.4. Two extra
1681 * pack slots were added and the equipment was rearranged. Note
1682 * that these two features combine when parsing old save-files, in
1683 * which items from the old "aux" slot are "carried", perhaps into
1684 * one of the two new "inventory" slots.
1686 * Note that the inventory is "re-sorted" later by "dungeon()".
1688 static errr rd_inventory(void)
1696 p_ptr->total_weight = 0;
1702 /* Read until done */
1707 /* Get the next item index */
1710 /* Nope, we reached the end */
1711 if (n == 0xFFFF) break;
1713 /* Get local object */
1716 /* Wipe the object */
1722 /* Hack -- verify item */
1723 if (!q_ptr->k_idx) return (53);
1725 /* Wield equipment */
1726 if (n >= INVEN_RARM)
1729 object_copy(&inventory[n], q_ptr);
1731 /* Add the weight */
1732 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1738 /* Warning -- backpack is full */
1739 else if (inven_cnt == INVEN_PACK)
1743 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1745 note("Too many items in the inventory!");
1753 /* Carry inventory */
1760 object_copy(&inventory[n], q_ptr);
1762 /* Add the weight */
1763 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1777 * Read the saved messages
1779 static void rd_messages(void)
1789 /* Read the messages */
1790 for (i = 0; i < num; i++)
1792 /* Read the message */
1793 rd_string(buf, 128);
1795 /* Save the message */
1805 * The monsters/objects must be loaded in the same order
1806 * that they were stored, since the actual indexes matter.
1808 static errr rd_dungeon(void)
1819 /*** Basic info ***/
1822 rd_s16b(&dun_level);
1823 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1824 else rd_byte(&dungeon_type);
1826 /* Set the base level for old versions */
1827 base_level = dun_level;
1829 rd_s16b(&base_level);
1831 rd_s16b(&num_repro);
1836 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1839 rd_s16b(&tmp16s); /* max_panel_rows */
1840 rd_s16b(&tmp16s); /* max_panel_cols */
1843 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1851 /*** Run length decoding ***/
1853 /* Load the dungeon data */
1854 for (x = y = 0; y < ymax; )
1858 if (z_older_than(10,3,6))
1863 /* Apply the RLE info */
1864 for (i = count; i > 0; i--)
1866 /* Access the cave */
1867 c_ptr = &cave[y][x];
1869 /* Extract "info" */
1870 if (z_older_than(10,3,6))
1871 c_ptr->info = tmp8u;
1872 else c_ptr->info = tmp16s;
1881 if (++y >= ymax) break;
1887 /*** Run length decoding ***/
1889 /* Load the dungeon data */
1890 for (x = y = 0; y < ymax; )
1896 /* Apply the RLE info */
1897 for (i = count; i > 0; i--)
1899 /* Access the cave */
1900 c_ptr = &cave[y][x];
1902 if (c_ptr->feat == FEAT_INVIS)
1904 c_ptr->feat = FEAT_FLOOR;
1905 c_ptr->info |= CAVE_TRAP;
1908 /* Extract "feat" */
1909 c_ptr->feat = tmp8u;
1918 if (++y >= ymax) break;
1923 /*** Run length decoding ***/
1925 /* Load the dungeon data */
1926 for (x = y = 0; y < ymax; )
1932 /* Apply the RLE info */
1933 for (i = count; i > 0; i--)
1935 /* Access the cave */
1936 c_ptr = &cave[y][x];
1938 /* Extract "feat" */
1939 c_ptr->mimic = tmp8u;
1948 if (++y >= ymax) break;
1953 /*** Run length decoding ***/
1955 /* Load the dungeon data */
1956 for (x = y = 0; y < ymax; )
1962 /* Apply the RLE info */
1963 for (i = count; i > 0; i--)
1965 /* Access the cave */
1966 c_ptr = &cave[y][x];
1968 /* Extract "feat" */
1969 c_ptr->special = tmp16s;
1978 if (++y >= ymax) break;
1985 /* Read the item count */
1988 /* Verify maximum */
1989 if (limit >= max_o_idx)
1992 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
1994 note(format("Too many (%d) object entries!", limit));
2000 /* Read the dungeon items */
2001 for (i = 1; i < limit; i++)
2008 /* Get a new record */
2015 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2017 note(format("Object allocation error (%d <> %d)", i, o_idx));
2025 o_ptr = &o_list[o_idx];
2031 /* XXX XXX XXX XXX XXX */
2034 if (o_ptr->held_m_idx)
2036 monster_type *m_ptr;
2039 m_ptr = &m_list[o_ptr->held_m_idx];
2042 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2044 /* Place the object */
2045 m_ptr->hold_o_idx = o_idx;
2051 /* Access the item location */
2052 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2055 o_ptr->next_o_idx = c_ptr->o_idx;
2057 /* Place the object */
2058 c_ptr->o_idx = o_idx;
2065 /* Read the monster count */
2068 /* Hack -- verify */
2069 if (limit >= max_m_idx)
2072 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2074 note(format("Too many (%d) monster entries!", limit));
2080 /* Read the monsters */
2081 for (i = 1; i < limit; i++)
2085 monster_type *m_ptr;
2087 monster_race *r_ptr;
2090 /* Get a new record */
2097 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2099 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2106 /* Acquire monster */
2107 m_ptr = &m_list[m_idx];
2109 /* Read the monster */
2114 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2116 /* Mark the location */
2117 c_ptr->m_idx = m_idx;
2121 r_ptr = &r_info[m_ptr->r_idx];
2123 /* Count XXX XXX XXX */
2129 /* The dungeon is ready */
2130 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2131 character_dungeon = FALSE;
2133 character_dungeon = TRUE;
2142 * Actually read the savefile
2144 static errr rd_savefile_new_aux(void)
2156 #ifdef VERIFY_CHECKSUMS
2157 u32b n_x_check, n_v_check;
2158 u32b o_x_check, o_v_check;
2162 /* Mention the savefile version */
2164 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2166 note(format("Loading a %d.%d.%d savefile...",
2169 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2172 /* Strip the version bytes */
2175 /* Hack -- decrypt */
2176 xor_byte = sf_extra;
2179 /* Clear the checksums */
2183 #if SAVEFILE_VERSION
2184 /* Read the version number of the savefile */
2185 rd_u32b(&sf_version);
2186 #endif /* SAVEFILE_VERSION */
2188 /* Operating system info */
2191 /* Time of savefile creation */
2194 /* Number of resurrections */
2197 /* Number of times played */
2201 /* Later use (always zero) */
2204 /* Later use (always zero) */
2208 /* Read RNG state */
2211 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2213 if (arg_fiddle) note("Loaded Randomizer Info");
2218 /* Then the options */
2221 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2223 if (arg_fiddle) note("Loaded Option Flags");
2227 * Munchkin players are marked
2229 * XXX - should be replaced with a better method,
2230 * after the new scorefile-handling is implemented.
2238 /* Then the "messages" */
2241 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2243 if (arg_fiddle) note("Loaded Messages");
2248 for (i = 0; i < max_r_idx; i++)
2250 monster_race *r_ptr;
2251 /* Access that monster */
2254 /* Hack -- Reset the death counter */
2255 r_ptr->max_num = 100;
2256 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2257 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2260 /* Monster Memory */
2263 /* Incompatible save files */
2264 if (tmp16u > max_r_idx)
2267 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2269 note(format("Too many (%u) monster races!", tmp16u));
2275 /* Read the available records */
2276 for (i = 0; i < tmp16u; i++)
2278 monster_race *r_ptr;
2283 /* Access that monster */
2288 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2290 if (arg_fiddle) note("Loaded Monster Memory");
2298 /* Incompatible save files */
2299 if (tmp16u > max_k_idx)
2302 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2304 note(format("Too many (%u) object kinds!", tmp16u));
2310 /* Read the object memory */
2311 for (i = 0; i < tmp16u; i++)
2314 object_kind *k_ptr = &k_info[i];
2318 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2319 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2322 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2324 if (arg_fiddle) note("Loaded Object Memory");
2330 * Initialize arena and rewards information
2332 p_ptr->arena_number = 0;
2333 p_ptr->inside_arena = 0;
2334 p_ptr->inside_quest = 0;
2335 p_ptr->leftbldg = FALSE;
2336 p_ptr->exit_bldg = TRUE;
2338 /* Start in town 1 */
2339 p_ptr->town_num = 1;
2341 p_ptr->wilderness_x = 4;
2342 p_ptr->wilderness_y = 4;
2346 /* Init the wilderness seeds */
2347 for (i = 0; i < max_wild_x; i++)
2349 for (j = 0; j < max_wild_y; j++)
2351 wilderness[j][i].seed = randint0(0x10000000);
2355 /* 2.1.3 or newer version */
2357 u16b max_towns_load;
2358 u16b max_quests_load;
2359 byte max_rquests_load;
2360 s16b old_inside_quest = p_ptr->inside_quest;
2362 /* Number of towns */
2363 rd_u16b(&max_towns_load);
2365 /* Incompatible save files */
2366 if (max_towns_load > max_towns)
2369 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2371 note(format("Too many (%u) towns!", max_towns_load));
2377 /* Number of quests */
2378 rd_u16b(&max_quests_load);
2380 if (z_older_than(11, 0, 7))
2382 max_rquests_load = 10;
2386 rd_byte(&max_rquests_load);
2389 /* Incompatible save files */
2390 if (max_quests_load > max_quests)
2393 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2395 note(format("Too many (%u) quests!", max_quests_load));
2401 for (i = 0; i < max_quests_load; i++)
2405 rd_s16b(&quest[i].status);
2406 rd_s16b(&quest[i].level);
2408 if (z_older_than(11, 0, 6))
2410 quest[i].complev = 0;
2414 rd_byte(&quest[i].complev);
2417 /* Load quest status if quest is running */
2418 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))))
2420 rd_s16b(&quest[i].cur_num);
2421 rd_s16b(&quest[i].max_num);
2422 rd_s16b(&quest[i].type);
2424 /* Load quest monster index */
2425 rd_s16b(&quest[i].r_idx);
2427 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2432 monster_race *r_ptr;
2435 * Random monster 5 - 10 levels out of depth
2436 * (depending on level)
2438 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
2439 r_ptr = &r_info[r_idx];
2441 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2443 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2445 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2447 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2449 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2452 * Accept monsters that are 2 - 6 levels
2453 * out of depth depending on the quest level
2455 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2458 quest[i].r_idx = r_idx;
2461 /* Load quest item index */
2462 rd_s16b(&quest[i].k_idx);
2465 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
2467 rd_byte(&quest[i].flags);
2469 if (z_older_than(10, 3, 11))
2471 if (quest[i].flags & QUEST_FLAG_PRESET)
2473 quest[i].dungeon = 0;
2477 init_flags = INIT_ASSIGN;
2478 p_ptr->inside_quest = i;
2480 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2481 p_ptr->inside_quest = old_inside_quest;
2486 rd_byte(&quest[i].dungeon);
2489 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2490 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2491 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2494 /* Ignore the empty quests from old versions */
2497 /* Ignore quest status */
2500 /* Ignore quest level */
2504 * We don't have to care about the other info,
2505 * since status should be 0 for these quests anyway
2510 /* Position in the wilderness */
2511 rd_s32b(&p_ptr->wilderness_x);
2512 rd_s32b(&p_ptr->wilderness_y);
2513 if (z_older_than(10, 3, 13))
2515 p_ptr->wilderness_x = 5;
2516 p_ptr->wilderness_y = 48;
2519 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2520 else rd_byte((byte *)&p_ptr->wild_mode);
2521 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2522 else rd_byte((byte *)&ambush_flag);
2524 /* Size of the wilderness */
2525 rd_s32b(&wild_x_size);
2526 rd_s32b(&wild_y_size);
2528 /* Incompatible save files */
2529 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2532 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2534 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2540 /* Load the wilderness seeds */
2541 for (i = 0; i < wild_x_size; i++)
2543 for (j = 0; j < wild_y_size; j++)
2545 rd_u32b(&wilderness[j][i].seed);
2551 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2553 if (arg_fiddle) note("Loaded Quests");
2556 /* Load the Artifacts */
2559 /* Incompatible save files */
2560 if (tmp16u > max_a_idx)
2563 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2565 note(format("Too many (%u) artifacts!", tmp16u));
2571 /* Read the artifact flags */
2572 for (i = 0; i < tmp16u; i++)
2575 a_info[i].cur_num = tmp8u;
2581 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2583 if (arg_fiddle) note("Loaded Artifacts");
2588 /* Read the extra stuff */
2590 if (p_ptr->energy > 999) world_player = TRUE;
2592 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2594 if (arg_fiddle) note("Loaded extra information");
2598 /* Read the player_hp array */
2601 /* Incompatible save files */
2602 if (tmp16u > PY_MAX_LEVEL)
2605 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2607 note(format("Too many (%u) hitpoint entries!", tmp16u));
2613 /* Read the player_hp array */
2614 for (i = 0; i < tmp16u; i++)
2616 rd_s16b(&player_hp[i]);
2619 /* Important -- Initialize the sex */
2620 sp_ptr = &sex_info[p_ptr->psex];
2622 /* Important -- Initialize the race/class */
2623 rp_ptr = &race_info[p_ptr->prace];
2624 cp_ptr = &class_info[p_ptr->pclass];
2625 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2627 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !death)
2629 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2630 do_cmd_rerate(FALSE);
2632 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !death)
2634 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2635 do_cmd_rerate(FALSE);
2637 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !death)
2639 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2640 do_cmd_rerate(FALSE);
2642 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !death)
2644 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2645 do_cmd_rerate(FALSE);
2648 /* Important -- Initialize the magic */
2649 mp_ptr = &m_info[p_ptr->pclass];
2652 /* Read spell info */
2653 rd_u32b(&spell_learned1);
2654 rd_u32b(&spell_learned2);
2655 rd_u32b(&spell_worked1);
2656 rd_u32b(&spell_worked2);
2657 rd_u32b(&spell_forgotten1);
2658 rd_u32b(&spell_forgotten2);
2660 if (z_older_than(10,0,5))
2662 p_ptr->learned_spells = 0;
2663 for (i = 0; i < 64; i++)
2665 /* Count known spells */
2667 (spell_learned1 & (1L << i)) :
2668 (spell_learned2 & (1L << (i - 32))))
2670 p_ptr->learned_spells++;
2674 else rd_s16b(&p_ptr->learned_spells);
2676 if (z_older_than(10,0,6))
2678 p_ptr->add_spells = 0;
2680 else rd_s16b(&p_ptr->add_spells);
2681 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2683 for (i = 0; i < 64; i++)
2685 rd_byte(&spell_order[i]);
2689 /* Read the inventory */
2693 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2695 note("Unable to read inventory");
2701 /* Read number of towns */
2703 town_count = tmp16u;
2705 /* Read the stores */
2707 for (i = 1; i < town_count; i++)
2709 for (j = 0; j < tmp16u; j++)
2711 if (rd_store(i, j)) return (22);
2715 rd_s16b(&p_ptr->pet_follow_distance);
2716 if (z_older_than(10, 4, 10))
2718 p_ptr->pet_extra_flags = 0;
2720 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2722 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2724 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2728 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2731 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2735 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2738 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2742 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2745 if (!z_older_than(10,0,8))
2748 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2753 rd_s16b(&p_ptr->pet_extra_flags);
2756 if (!z_older_than(11, 0, 9))
2758 char buf[SCREEN_BUF_SIZE];
2759 rd_string(buf, SCREEN_BUF_SIZE);
2760 if (buf[0]) screen_dump = string_make(buf);
2765 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2767 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2772 /* I'm not dead yet... */
2775 /* Dead players have no dungeon */
2777 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2779 note("Restoring Dungeon...");
2785 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2787 note("Error reading dungeon data");
2793 /* Read the ghost info */
2800 strip_bytes(tmp32s);
2805 #ifdef VERIFY_CHECKSUMS
2807 /* Save the checksum */
2808 n_v_check = v_check;
2810 /* Read the old checksum */
2811 rd_u32b(&o_v_check);
2814 if (o_v_check != n_v_check)
2817 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2819 note("Invalid checksum");
2826 /* Save the encoded checksum */
2827 n_x_check = x_check;
2829 /* Read the checksum */
2830 rd_u32b(&o_x_check);
2834 if (o_x_check != n_x_check)
2837 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2839 note("Invalid encoded checksum");
2853 * Actually read the savefile
2855 errr rd_savefile_new(void)
2859 /* The savefile is a binary file */
2860 fff = my_fopen(savefile, "rb");
2863 if (!fff) return (-1);
2865 /* Call the sub-function */
2866 err = rd_savefile_new_aux();
2868 /* Check for errors */
2869 if (ferror(fff)) err = -1;
2871 /* Close the file */