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)
239 /* Read the string */
240 for (i = 0; TRUE; i++)
247 /* Collect string while legal */
248 if (i < max) str[i] = tmp8u;
260 for (i = 0; i < l; i++) {
262 if (c1 & 0x80) kanji = 1;
263 if ( c1>=0x80 && (c1 < 0xa1 || c1 > 0xfe)) iseuc = 0;
266 if (kanji && !iseuc) {
267 unsigned char tmp[256];
268 for (i = 0; i < l; i++) {
274 c1 = c1 * 2 - (c1 >= 0xe0 ? 0xe0 : 0x60);
277 c1 = c1 * 2 - (c1 >= 0xe0 ? 0xe1 : 0x61);
278 c2 += 0x60 + (c2 < 0x7f);
286 strcpy(str, (char *)tmp);
291 if (kanji && iseuc) {
292 unsigned char tmp[256];
293 for (i = 0; i < l; i++) {
299 c1 = (c1 >> 1) + (c1 < 0xdf ? 0x31 : 0x71);
300 c2 -= 0x60 + (c2 < 0xe0);
302 c1 = (c1 >> 1) + (c1 < 0xdf ? 0x30 : 0x70);
320 * Hack -- strip some bytes
322 static void strip_bytes(int n)
326 /* Strip the bytes */
327 while (n--) rd_byte(&tmp8u);
330 #define OLD_MAX_MANE 22
335 * This function attempts to "repair" old savefiles, and to extract
336 * the most up to date values for various object fields.
338 * Note that Angband 2.7.9 introduced a new method for object "flags"
339 * in which the "flags" on an object are actually extracted when they
340 * are needed from the object kind, artifact index, ego-item index,
341 * and two special "xtra" fields which are used to encode any "extra"
342 * power of certain ego-items. This had the side effect that items
343 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
344 * may have had, and also, all "uncursed" items will become "cursed"
345 * again, including Calris, even if it is being worn at the time. As
346 * a complete hack, items which are inscribed with "uncursed" will be
347 * "uncursed" when imported from pre-2.7.9 savefiles.
349 static void rd_item(object_type *o_ptr)
362 rd_s16b(&o_ptr->k_idx);
369 rd_byte(&o_ptr->tval);
370 rd_byte(&o_ptr->sval);
372 if (z_older_than(10, 4, 4))
374 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
375 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
376 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
380 rd_s16b(&o_ptr->pval);
382 rd_byte(&o_ptr->discount);
383 rd_byte(&o_ptr->number);
384 rd_s16b(&o_ptr->weight);
386 rd_byte(&o_ptr->name1);
387 rd_byte(&o_ptr->name2);
388 rd_s16b(&o_ptr->timeout);
390 rd_s16b(&o_ptr->to_h);
391 rd_s16b(&o_ptr->to_d);
392 rd_s16b(&o_ptr->to_a);
399 rd_byte(&o_ptr->ident);
401 rd_byte(&o_ptr->marked);
404 rd_u32b(&o_ptr->art_flags1);
405 rd_u32b(&o_ptr->art_flags2);
406 rd_u32b(&o_ptr->art_flags3);
408 /* Monster holding object */
409 rd_s16b(&o_ptr->held_m_idx);
412 rd_byte(&o_ptr->xtra1);
413 rd_byte(&o_ptr->xtra2);
414 if (z_older_than(10, 2, 3))
419 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
421 o_ptr->xtra3 = o_ptr->xtra1;
424 if (o_ptr->tval == TV_CAPTURE)
426 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
427 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
429 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
430 if (ironman_nightmare)
432 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
434 o_ptr->xtra4 = o_ptr->xtra5;
439 rd_byte(&o_ptr->xtra3);
440 rd_s16b(&o_ptr->xtra4);
441 rd_s16b(&o_ptr->xtra5);
444 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)))
446 o_ptr->xtra4 = o_ptr->pval;
450 /* Feeling - from 2.3.1, "savefile version 1" */
453 rd_byte(&o_ptr->feeling);
459 /* If this savefile is old, maybe we need to translate the feeling */
464 for (i = 0; i <= FEEL_MAX; i++)
466 if (game_inscriptions[i] == NULL)
471 if (streq(buf, game_inscriptions[i]))
480 /* Save the inscription */
481 if (buf[0]) o_ptr->inscription = quark_add(buf);
484 if (buf[0]) o_ptr->art_name = quark_add(buf);
486 /* The Python object */
494 char *python_object = (char*) malloc(tmp32s + 1);
495 rd_string(python_object, tmp32s + 1);
496 o_ptr->python = object_load_callback(python_object);
499 #else /* USE_SCRIPT */
501 #endif /* USE_SCRIPT */
504 /* Mega-Hack -- handle "dungeon objects" later */
505 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
507 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
509 /* Obtain the "kind" template */
510 k_ptr = &k_info[o_ptr->k_idx];
512 /* Obtain tval/sval from k_info */
513 o_ptr->tval = k_ptr->tval;
514 o_ptr->sval = k_ptr->sval;
516 /* Hack -- notice "broken" items */
517 if (k_ptr->cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
520 /* Repair non "wearable" items */
521 if (!wearable_p(o_ptr))
523 /* Acquire correct fields */
524 o_ptr->to_h = k_ptr->to_h;
525 o_ptr->to_d = k_ptr->to_d;
526 o_ptr->to_a = k_ptr->to_a;
528 /* Acquire correct fields */
529 o_ptr->ac = k_ptr->ac;
530 o_ptr->dd = k_ptr->dd;
531 o_ptr->ds = k_ptr->ds;
533 /* Acquire correct weight */
534 o_ptr->weight = k_ptr->weight;
537 o_ptr->name1 = o_ptr->name2 = 0;
544 /* Extract the flags */
545 object_flags(o_ptr, &f1, &f2, &f3);
547 if (z_older_than(10, 4, 9))
549 if (o_ptr->art_flags1 & TR1_MAGIC_MASTERY)
551 o_ptr->art_flags1 &= ~(TR1_MAGIC_MASTERY);
552 o_ptr->art_flags3 |= (TR3_DEC_MANA);
559 artifact_type *a_ptr;
561 /* Obtain the artifact info */
562 a_ptr = &a_info[o_ptr->name1];
564 /* Verify that artifact */
565 if (!a_ptr->name) o_ptr->name1 = 0;
571 ego_item_type *e_ptr;
573 /* Obtain the ego-item info */
574 e_ptr = &e_info[o_ptr->name2];
576 /* Verify that ego-item */
577 if (!e_ptr->name) o_ptr->name2 = 0;
581 /* Acquire standard fields */
582 o_ptr->ac = k_ptr->ac;
583 o_ptr->dd = k_ptr->dd;
584 o_ptr->ds = k_ptr->ds;
586 /* Acquire standard weight */
587 o_ptr->weight = k_ptr->weight;
589 /* Hack -- extract the "broken" flag */
590 if (!o_ptr->pval < 0) o_ptr->ident |= (IDENT_BROKEN);
595 artifact_type *a_ptr;
597 /* Obtain the artifact info */
598 a_ptr = &a_info[o_ptr->name1];
600 /* Acquire new artifact "pval" */
601 o_ptr->pval = a_ptr->pval;
603 /* Acquire new artifact fields */
604 o_ptr->ac = a_ptr->ac;
605 o_ptr->dd = a_ptr->dd;
606 o_ptr->ds = a_ptr->ds;
608 /* Acquire new artifact weight */
609 o_ptr->weight = a_ptr->weight;
611 /* Hack -- extract the "broken" flag */
612 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
618 ego_item_type *e_ptr;
620 /* Obtain the ego-item info */
621 e_ptr = &e_info[o_ptr->name2];
626 if (o_ptr->name2 == EGO_DWARVEN)
629 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
632 /* Hack -- extract the "broken" flag */
633 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
636 if (o_ptr->art_name) /* A random artifact */
649 static void rd_monster(monster_type *m_ptr)
654 /* Read the monster race */
655 rd_s16b(&m_ptr->r_idx);
657 /* Read the other information */
661 rd_s16b(&m_ptr->maxhp);
662 if (z_older_than(11, 0, 5))
664 m_ptr->max_maxhp = m_ptr->maxhp;
668 rd_s16b(&m_ptr->max_maxhp);
670 rd_s16b(&m_ptr->csleep);
671 rd_byte(&m_ptr->mspeed);
672 if (z_older_than(10, 4, 2))
675 m_ptr->energy = (s16b)tmp8u;
677 else rd_s16b(&m_ptr->energy);
678 if (z_older_than(10,0,7))
685 rd_byte(&m_ptr->fast);
686 rd_byte(&m_ptr->slow);
688 rd_byte(&m_ptr->stunned);
689 rd_byte(&m_ptr->confused);
690 rd_byte(&m_ptr->monfear);
692 if (z_older_than(10,0,10))
697 else if (z_older_than(10,0,11))
706 rd_s16b(&m_ptr->target_y);
707 rd_s16b(&m_ptr->target_x);
710 /* Monster invulnerability introduced from 2.3.2+ */
714 rd_byte(&m_ptr->invulner);
716 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
717 rd_u32b(&m_ptr->smart);
721 if (z_older_than(10, 4, 5))
724 rd_u32b(&m_ptr->exp);
726 if (z_older_than(10, 2, 2))
728 if (m_ptr->r_idx < 0)
730 m_ptr->r_idx = (0-m_ptr->r_idx);
731 m_ptr->mflag2 |= MFLAG_KAGE;
736 rd_byte(&m_ptr->mflag2);
739 if (z_older_than(10, 1, 3))
746 if (buf[0]) m_ptr->nickname = quark_add(buf);
757 * Read the monster lore
759 static void rd_lore(int r_idx)
763 monster_race *r_ptr = &r_info[r_idx];
765 /* Count sights/deaths/kills */
766 rd_s16b(&r_ptr->r_sights);
767 rd_s16b(&r_ptr->r_deaths);
768 rd_s16b(&r_ptr->r_pkills);
769 rd_s16b(&r_ptr->r_tkills);
771 /* Count wakes and ignores */
772 rd_byte(&r_ptr->r_wake);
773 rd_byte(&r_ptr->r_ignore);
776 rd_byte(&r_ptr->r_xtra1);
777 rd_byte(&r_ptr->r_xtra2);
780 rd_byte(&r_ptr->r_drop_gold);
781 rd_byte(&r_ptr->r_drop_item);
784 rd_byte(&r_ptr->r_cast_inate);
785 rd_byte(&r_ptr->r_cast_spell);
787 /* Count blows of each type */
788 rd_byte(&r_ptr->r_blows[0]);
789 rd_byte(&r_ptr->r_blows[1]);
790 rd_byte(&r_ptr->r_blows[2]);
791 rd_byte(&r_ptr->r_blows[3]);
794 rd_u32b(&r_ptr->r_flags1);
795 rd_u32b(&r_ptr->r_flags2);
796 rd_u32b(&r_ptr->r_flags3);
797 rd_u32b(&r_ptr->r_flags4);
798 rd_u32b(&r_ptr->r_flags5);
799 rd_u32b(&r_ptr->r_flags6);
801 /* Read the "Racial" monster limit per level */
802 rd_byte(&r_ptr->max_num);
809 /* Repair the lore flags */
810 r_ptr->r_flags1 &= r_ptr->flags1;
811 r_ptr->r_flags2 &= r_ptr->flags2;
812 r_ptr->r_flags3 &= r_ptr->flags3;
813 r_ptr->r_flags4 &= r_ptr->flags4;
814 r_ptr->r_flags5 &= r_ptr->flags5;
815 r_ptr->r_flags6 &= r_ptr->flags6;
822 * Add the item "o_ptr" to the inventory of the "Home"
824 * In all cases, return the slot (or -1) where the object was placed
826 * Note that this is a hacked up version of "inven_carry()".
828 * Also note that it may not correctly "adapt" to "knowledge" bacoming
829 * known, the player may have to pick stuff up and drop it again.
831 static void home_carry(store_type *st_ptr, object_type *o_ptr)
839 /* Check each existing item (try to combine) */
840 for (slot = 0; slot < st_ptr->stock_num; slot++)
842 /* Get the existing item */
843 j_ptr = &st_ptr->stock[slot];
845 /* The home acts just like the player */
846 if (object_similar(j_ptr, o_ptr))
848 /* Save the new number of items */
849 object_absorb(j_ptr, o_ptr);
857 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
861 /* Determine the "value" of the item */
862 value = object_value(o_ptr);
864 /* Check existing slots to see if we must "slide" */
865 for (slot = 0; slot < st_ptr->stock_num; slot++)
868 j_ptr = &st_ptr->stock[slot];
870 /* Hack -- readable books always come first */
871 if ((o_ptr->tval == mp_ptr->spell_book) &&
872 (j_ptr->tval != mp_ptr->spell_book)) break;
873 if ((j_ptr->tval == mp_ptr->spell_book) &&
874 (o_ptr->tval != mp_ptr->spell_book)) continue;
876 /* Objects sort by decreasing type */
877 if (o_ptr->tval > j_ptr->tval) break;
878 if (o_ptr->tval < j_ptr->tval) continue;
880 /* Can happen in the home */
881 if (!object_aware_p(o_ptr)) continue;
882 if (!object_aware_p(j_ptr)) break;
884 /* Objects sort by increasing sval */
885 if (o_ptr->sval < j_ptr->sval) break;
886 if (o_ptr->sval > j_ptr->sval) continue;
888 /* Objects in the home can be unknown */
889 if (!object_known_p(o_ptr)) continue;
890 if (!object_known_p(j_ptr)) break;
893 * Hack: otherwise identical rods sort by
894 * increasing recharge time --dsb
896 if (o_ptr->tval == TV_ROD)
898 if (o_ptr->pval < j_ptr->pval) break;
899 if (o_ptr->pval > j_ptr->pval) continue;
902 /* Objects sort by decreasing value */
903 j_value = object_value(j_ptr);
904 if (value > j_value) break;
905 if (value < j_value) continue;
908 /* Slide the others up */
909 for (i = st_ptr->stock_num; i > slot; i--)
911 st_ptr->stock[i] = st_ptr->stock[i-1];
917 /* Insert the new item */
918 st_ptr->stock[slot] = *o_ptr;
920 chg_virtue(V_SACRIFICE, -1);
922 /* Return the location */
930 static errr rd_store(int town_number, int store_number)
942 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
944 st_ptr = &town[1].store[store_number];
945 if (st_ptr->stock_num) sort = TRUE;
949 st_ptr = &town[town_number].store[store_number];
952 /* Read the basic info */
953 rd_s32b(&st_ptr->store_open);
954 rd_s16b(&st_ptr->insult_cur);
956 if (z_older_than(11, 0, 4))
965 rd_s16b(&st_ptr->good_buy);
966 rd_s16b(&st_ptr->bad_buy);
968 /* Read last visit */
969 rd_s32b(&st_ptr->last_visit);
971 /* Extract the owner (see above) */
975 for (j = 0; j < num; j++)
980 /* Get local object */
983 /* Wipe the object */
989 /* Acquire valid items */
990 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
995 home_carry(st_ptr, q_ptr);
999 k = st_ptr->stock_num++;
1001 /* Acquire the item */
1002 object_copy(&st_ptr->stock[k], q_ptr);
1014 * Read RNG state (added in 2.8.0)
1016 static void rd_randomizer(void)
1026 rd_u16b(&Rand_place);
1029 for (i = 0; i < RAND_DEG; i++)
1031 rd_u32b(&Rand_state[i]);
1041 * Read options (ignore most pre-2.8.0 options)
1043 * Note that the normal options are now stored as a set of 256 bit flags,
1044 * plus a set of 256 bit masks to indicate which bit flags were defined
1045 * at the time the savefile was created. This will allow new options
1046 * to be added, and old options to be removed, at any time, without
1047 * hurting old savefiles.
1049 * The window options are stored in the same way, but note that each
1050 * window gets 32 options, and their order is fixed by certain defines.
1052 static void rd_options(void)
1066 /* Ignore old options */
1070 /*** Special info */
1072 /* Read "delay_factor" */
1076 /* Read "hitpoint_warn" */
1081 /*** Cheating options ***/
1085 if (c & 0x0002) wizard = TRUE;
1087 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1088 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1089 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1090 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1091 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1092 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1094 rd_byte((byte *)&autosave_l);
1095 rd_byte((byte *)&autosave_t);
1096 rd_s16b(&autosave_freq);
1099 /*** Normal Options ***/
1101 /* Read the option flags */
1102 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1104 /* Read the option masks */
1105 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1107 /* Analyze the options */
1108 for (n = 0; n < 8; n++)
1110 /* Analyze the options */
1111 for (i = 0; i < 32; i++)
1113 /* Process valid flags */
1114 if (mask[n] & (1L << i))
1116 /* Process valid flags */
1117 if (option_mask[n] & (1L << i))
1120 if (flag[n] & (1L << i))
1123 option_flag[n] |= (1L << i);
1130 option_flag[n] &= ~(1L << i);
1137 if (z_older_than(10, 4, 5))
1139 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1140 else option_flag[5] |= (0x00000001 << 4);
1141 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1142 else option_flag[2] |= (0x00000001 << 5);
1143 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1144 else option_flag[4] |= (0x00000001 << 5);
1145 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1146 else option_flag[5] |= (0x00000001 << 0);
1147 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1148 else option_flag[5] |= (0x00000001 << 12);
1149 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1150 else option_flag[1] |= (0x00000001 << 0);
1151 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1152 else option_flag[1] |= (0x00000001 << 18);
1153 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1154 else option_flag[1] |= (0x00000001 << 19);
1155 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1156 else option_flag[5] |= (0x00000001 << 3);
1160 /*** Window Options ***/
1162 /* Read the window flags */
1163 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1165 /* Read the window masks */
1166 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1168 /* Analyze the options */
1169 for (n = 0; n < 8; n++)
1171 /* Analyze the options */
1172 for (i = 0; i < 32; i++)
1174 /* Process valid flags */
1175 if (mask[n] & (1L << i))
1177 /* Process valid flags */
1178 if (window_mask[n] & (1L << i))
1181 if (flag[n] & (1L << i))
1184 window_flag[n] |= (1L << i);
1191 window_flag[n] &= ~(1L << i);
1204 * Hack -- strip the "ghost" info
1206 * XXX XXX XXX This is such a nasty hack it hurts.
1208 static void rd_ghost(void)
1215 /* Strip old data */
1223 * Read the "extra" information
1225 static void rd_extra(void)
1232 rd_string(player_name, 32);
1234 rd_string(died_from, 80);
1236 for (i = 0; i < 4; i++)
1238 rd_string(history[i], 60);
1241 /* Class/Race/Seikaku/Gender/Spells */
1242 rd_byte(&p_ptr->prace);
1243 rd_byte(&p_ptr->pclass);
1244 rd_byte(&p_ptr->pseikaku);
1245 rd_byte(&p_ptr->psex);
1246 rd_byte(&p_ptr->realm1);
1247 rd_byte(&p_ptr->realm2);
1248 rd_byte(&tmp8u); /* oops */
1250 if (z_older_than(10, 4, 4))
1252 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1253 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1254 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1255 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1258 /* Special Race/Class info */
1259 rd_byte(&p_ptr->hitdie);
1260 rd_u16b(&p_ptr->expfact);
1262 /* Age/Height/Weight */
1263 rd_s16b(&p_ptr->age);
1264 rd_s16b(&p_ptr->ht);
1265 rd_s16b(&p_ptr->wt);
1267 /* Read the stat info */
1268 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1269 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1270 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1272 strip_bytes(24); /* oops */
1274 rd_s32b(&p_ptr->au);
1276 rd_s32b(&p_ptr->max_exp);
1277 rd_s32b(&p_ptr->exp);
1278 rd_u16b(&p_ptr->exp_frac);
1280 rd_s16b(&p_ptr->lev);
1282 for (i = 0; i < 64; i++) rd_s16b(&spell_exp[i]);
1283 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1285 for (i = 0; i < 64; i++) spell_exp[i] = 1600;
1287 if (z_older_than(10, 3, 6))
1288 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&weapon_exp[i][j]);
1290 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&weapon_exp[i][j]);
1291 for (i = 0; i < 10; i++) rd_s16b(&skill_exp[i]);
1292 if (z_older_than(10, 4, 1))
1294 if (p_ptr->pclass != CLASS_BEASTMASTER) skill_exp[GINOU_RIDING] /= 2;
1295 skill_exp[GINOU_RIDING] = MIN(skill_exp[GINOU_RIDING], skill_exp_settei[p_ptr->pclass][GINOU_RIDING][1]);
1297 if (z_older_than(10, 3, 14))
1299 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1300 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1304 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1305 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1307 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1309 if (z_older_than(11, 0, 7))
1311 p_ptr->start_race = p_ptr->prace;
1312 p_ptr->old_race1 = 0L;
1313 p_ptr->old_race2 = 0L;
1314 p_ptr->old_realm = 0;
1318 rd_byte(&p_ptr->start_race);
1319 rd_s32b(&p_ptr->old_race1);
1320 rd_s32b(&p_ptr->old_race2);
1321 rd_s16b(&p_ptr->old_realm);
1324 if (z_older_than(10, 0, 1))
1326 for (i = 0; i < OLD_MAX_MANE; i++)
1333 else if (z_older_than(10, 2, 3))
1335 for (i = 0; i < OLD_MAX_MANE; i++)
1340 for (i = 0; i < MAX_MANE; i++)
1350 for (i = 0; i < MAX_MANE; i++)
1352 rd_s16b(&mane_spell[i]);
1353 rd_s16b(&mane_dam[i]);
1358 if (z_older_than(10, 0, 3))
1360 get_mon_num_prep(NULL, NULL);
1361 for (i = 0; i < MAX_KUBI; i++)
1363 monster_race *r_ptr;
1368 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1369 r_ptr = &r_info[kubi_r_idx[i]];
1371 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1373 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1375 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1377 for (j = 0; j < i; j++)
1378 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1383 for (i = 0; i < MAX_KUBI -1; i++)
1386 for (j = i; j < MAX_KUBI; j++)
1388 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1390 tmp = kubi_r_idx[i];
1391 kubi_r_idx[i] = kubi_r_idx[j];
1392 kubi_r_idx[j] = tmp;
1396 for (i = 0; i < MAX_KUBI; i++)
1398 if(!r_info[kubi_r_idx[i]].max_num)
1399 kubi_r_idx[i] += 10000;
1404 for (i = 0; i < MAX_KUBI; i++)
1406 rd_s16b(&kubi_r_idx[i]);
1410 if (z_older_than(10, 0, 3))
1416 for (i = 0; i < 4; i++)
1418 rd_s16b(&battle_mon[i]);
1419 if (z_older_than(10, 3, 4))
1422 mon_odds[i] = tmp16s;
1424 else rd_u32b(&mon_odds[i]);
1428 rd_s16b(&p_ptr->town_num);
1430 /* Read arena and rewards information */
1431 rd_s16b(&p_ptr->arena_number);
1432 rd_s16b(&p_ptr->inside_arena);
1433 rd_s16b(&p_ptr->inside_quest);
1434 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1435 else rd_s16b(&p_ptr->inside_battle);
1436 rd_byte(&p_ptr->exit_bldg);
1437 rd_byte(&p_ptr->leftbldg);
1439 rd_s16b(&p_ptr->oldpx);
1440 rd_s16b(&p_ptr->oldpy);
1441 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1445 if (tmp16s > MAX_BACT)
1448 note(format("¤ÎÃæ", tmp16s));
1450 note(format("Too many (%d) building rewards!", tmp16s));
1455 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1457 rd_s16b(&p_ptr->mhp);
1458 rd_s16b(&p_ptr->chp);
1459 rd_u16b(&p_ptr->chp_frac);
1461 rd_s16b(&p_ptr->msp);
1462 rd_s16b(&p_ptr->csp);
1463 rd_u16b(&p_ptr->csp_frac);
1465 rd_s16b(&p_ptr->max_plv);
1466 if (z_older_than(10, 3, 8))
1468 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1472 byte max = max_d_idx;
1476 for(i = 0; i < max; i++)
1478 rd_s16b(&max_dlv[i]);
1479 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1483 /* Repair maximum player level XXX XXX XXX */
1484 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1488 rd_s16b(&p_ptr->sc);
1491 /* Read the flags */
1492 strip_bytes(2); /* Old "rest" */
1493 rd_s16b(&p_ptr->blind);
1494 rd_s16b(&p_ptr->paralyzed);
1495 rd_s16b(&p_ptr->confused);
1496 rd_s16b(&p_ptr->food);
1497 strip_bytes(4); /* Old "food_digested" / "protection" */
1498 rd_s16b(&p_ptr->energy);
1499 rd_s16b(&p_ptr->fast);
1500 rd_s16b(&p_ptr->slow);
1501 rd_s16b(&p_ptr->afraid);
1502 rd_s16b(&p_ptr->cut);
1503 rd_s16b(&p_ptr->stun);
1504 rd_s16b(&p_ptr->poisoned);
1505 rd_s16b(&p_ptr->image);
1506 rd_s16b(&p_ptr->protevil);
1507 rd_s16b(&p_ptr->invuln);
1508 if(z_older_than(10, 0, 0))
1511 rd_s16b(&p_ptr->ult_res);
1512 rd_s16b(&p_ptr->hero);
1513 rd_s16b(&p_ptr->shero);
1514 rd_s16b(&p_ptr->shield);
1515 rd_s16b(&p_ptr->blessed);
1516 rd_s16b(&p_ptr->tim_invis);
1517 rd_s16b(&p_ptr->word_recall);
1518 if (z_older_than(10, 3, 8))
1519 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1521 rd_s16b(&p_ptr->recall_dungeon);
1522 rd_s16b(&p_ptr->see_infra);
1523 rd_s16b(&p_ptr->tim_infra);
1524 rd_s16b(&p_ptr->oppose_fire);
1525 rd_s16b(&p_ptr->oppose_cold);
1526 rd_s16b(&p_ptr->oppose_acid);
1527 rd_s16b(&p_ptr->oppose_elec);
1528 rd_s16b(&p_ptr->oppose_pois);
1529 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1530 else rd_s16b(&p_ptr->tsuyoshi);
1532 /* Old savefiles do not have the following fields... */
1533 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1536 p_ptr->wraith_form = 0;
1537 p_ptr->resist_magic = 0;
1538 p_ptr->tim_regen = 0;
1539 p_ptr->kabenuke = 0;
1540 p_ptr->tim_stealth = 0;
1541 p_ptr->tim_ffall = 0;
1542 p_ptr->tim_sh_touki = 0;
1543 p_ptr->lightspeed = 0;
1544 p_ptr->tsubureru = 0;
1545 p_ptr->tim_res_nether = 0;
1546 p_ptr->tim_res_time = 0;
1547 p_ptr->mimic_form = 0;
1548 p_ptr->tim_mimic = 0;
1549 p_ptr->tim_sh_fire = 0;
1552 p_ptr->tim_reflect = 0;
1553 p_ptr->multishadow = 0;
1554 p_ptr->dustrobe = 0;
1556 p_ptr->chaos_patron = get_chaos_patron();
1564 rd_s16b(&p_ptr->tim_esp);
1565 rd_s16b(&p_ptr->wraith_form);
1566 rd_s16b(&p_ptr->resist_magic);
1567 rd_s16b(&p_ptr->tim_regen);
1568 rd_s16b(&p_ptr->kabenuke);
1569 rd_s16b(&p_ptr->tim_stealth);
1570 rd_s16b(&p_ptr->tim_ffall);
1571 rd_s16b(&p_ptr->tim_sh_touki);
1572 rd_s16b(&p_ptr->lightspeed);
1573 rd_s16b(&p_ptr->tsubureru);
1574 if (z_older_than(10, 4, 7))
1575 p_ptr->magicdef = 0;
1577 rd_s16b(&p_ptr->magicdef);
1578 rd_s16b(&p_ptr->tim_res_nether);
1579 if (z_older_than(10, 4, 11))
1581 p_ptr->tim_res_time = 0;
1582 p_ptr->mimic_form = 0;
1583 p_ptr->tim_mimic = 0;
1584 p_ptr->tim_sh_fire = 0;
1588 rd_s16b(&p_ptr->tim_res_time);
1589 rd_byte(&p_ptr->mimic_form);
1590 rd_s16b(&p_ptr->tim_mimic);
1591 rd_s16b(&p_ptr->tim_sh_fire);
1595 if ( z_older_than(11,0,3) ){
1596 p_ptr->tim_reflect=0;
1597 p_ptr->multishadow=0;
1601 rd_s16b(&p_ptr->tim_reflect);
1602 rd_s16b(&p_ptr->multishadow);
1603 rd_s16b(&p_ptr->dustrobe);
1606 rd_s16b(&p_ptr->chaos_patron);
1607 rd_u32b(&p_ptr->muta1);
1608 rd_u32b(&p_ptr->muta2);
1609 rd_u32b(&p_ptr->muta3);
1611 for (i = 0; i < 8; i++)
1612 rd_s16b(&p_ptr->virtues[i]);
1613 for (i = 0; i < 8; i++)
1614 rd_s16b(&p_ptr->vir_types[i]);
1617 /* Calc the regeneration modifier for mutations */
1618 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1620 if (z_older_than(10,0,9))
1623 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1624 p_ptr->ele_attack = 0;
1628 rd_s16b(&p_ptr->ele_attack);
1629 rd_u32b(&p_ptr->special_attack);
1631 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1632 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1633 if (z_older_than(10,0,12))
1635 p_ptr->ele_immune = 0;
1636 p_ptr->special_defense = 0;
1640 rd_s16b(&p_ptr->ele_immune);
1641 rd_u32b(&p_ptr->special_defense);
1643 rd_byte(&p_ptr->knowledge);
1644 rd_byte(&tmp8u); /* oops */
1645 rd_byte(&tmp8u); /* oops */
1646 rd_byte(&p_ptr->action);
1647 if (!z_older_than(10, 4, 3))
1650 if (tmp8u) p_ptr->action = ACTION_LEARN;
1652 rd_byte((byte *)&preserve_mode);
1653 rd_byte((byte *)&wait_report_score);
1656 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1658 /* Skip the flags */
1662 /* Hack -- the two "special seeds" */
1663 rd_u32b(&seed_flavor);
1664 rd_u32b(&seed_town);
1668 rd_u16b(&panic_save);
1669 rd_u16b(&total_winner);
1677 /* Read "feeling" */
1681 /* Turn of last "feeling" */
1687 if (z_older_than(10, 3, 12))
1689 dungeon_turn = turn;
1691 else rd_s32b(&dungeon_turn);
1693 if (z_older_than(10, 3, 13))
1697 else rd_s32b(&old_battle);
1699 if (z_older_than(10,0,3))
1701 monster_race *r_ptr;
1705 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1706 r_ptr = &r_info[today_mon];
1708 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1709 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1710 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1711 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1712 if (r_ptr->rarity > 10) continue;
1713 if (r_ptr->level == 0) continue;
1717 p_ptr->today_mon = 0;
1721 rd_s16b(&today_mon);
1722 rd_s16b(&p_ptr->today_mon);
1725 if (z_older_than(10,0,7))
1731 rd_s16b(&p_ptr->riding);
1734 if (z_older_than(10,1,2))
1743 if (z_older_than(10,3,9))
1747 else if (z_older_than(10, 3, 10))
1755 rd_s32b(&p_ptr->visit);
1757 if (!z_older_than(11, 0, 5))
1759 rd_s32b(&p_ptr->count);
1767 * Read the player inventory
1769 * Note that the inventory changed in Angband 2.7.4. Two extra
1770 * pack slots were added and the equipment was rearranged. Note
1771 * that these two features combine when parsing old save-files, in
1772 * which items from the old "aux" slot are "carried", perhaps into
1773 * one of the two new "inventory" slots.
1775 * Note that the inventory is "re-sorted" later by "dungeon()".
1777 static errr rd_inventory(void)
1785 p_ptr->total_weight = 0;
1791 /* Read until done */
1796 /* Get the next item index */
1799 /* Nope, we reached the end */
1800 if (n == 0xFFFF) break;
1802 /* Get local object */
1805 /* Wipe the object */
1811 /* Hack -- verify item */
1812 if (!q_ptr->k_idx) return (53);
1814 /* Wield equipment */
1815 if (n >= INVEN_RARM)
1818 object_copy(&inventory[n], q_ptr);
1820 /* Add the weight */
1821 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1827 /* Warning -- backpack is full */
1828 else if (inven_cnt == INVEN_PACK)
1832 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1834 note("Too many items in the inventory!");
1842 /* Carry inventory */
1849 object_copy(&inventory[n], q_ptr);
1851 /* Add the weight */
1852 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1866 * Read the saved messages
1868 static void rd_messages(void)
1878 /* Read the messages */
1879 for (i = 0; i < num; i++)
1881 /* Read the message */
1882 rd_string(buf, 128);
1884 /* Save the message */
1894 * The monsters/objects must be loaded in the same order
1895 * that they were stored, since the actual indexes matter.
1897 static errr rd_dungeon(void)
1908 /*** Basic info ***/
1911 rd_s16b(&dun_level);
1912 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1913 else rd_byte(&dungeon_type);
1915 /* Set the base level for old versions */
1916 base_level = dun_level;
1918 rd_s16b(&base_level);
1920 rd_s16b(&num_repro);
1923 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1926 rd_s16b(&max_panel_rows);
1927 rd_s16b(&max_panel_cols);
1930 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1938 /*** Run length decoding ***/
1940 /* Load the dungeon data */
1941 for (x = y = 0; y < ymax; )
1945 if (z_older_than(10,3,6))
1950 /* Apply the RLE info */
1951 for (i = count; i > 0; i--)
1953 /* Access the cave */
1954 c_ptr = &cave[y][x];
1956 /* Extract "info" */
1957 if (z_older_than(10,3,6))
1958 c_ptr->info = tmp8u;
1959 else c_ptr->info = tmp16s;
1968 if (++y >= ymax) break;
1974 /*** Run length decoding ***/
1976 /* Load the dungeon data */
1977 for (x = y = 0; y < ymax; )
1983 /* Apply the RLE info */
1984 for (i = count; i > 0; i--)
1986 /* Access the cave */
1987 c_ptr = &cave[y][x];
1989 if (c_ptr->feat == FEAT_INVIS)
1991 c_ptr->feat = FEAT_FLOOR;
1992 c_ptr->info |= CAVE_TRAP;
1995 /* Extract "feat" */
1996 c_ptr->feat = tmp8u;
2005 if (++y >= ymax) break;
2010 /*** Run length decoding ***/
2012 /* Load the dungeon data */
2013 for (x = y = 0; y < ymax; )
2019 /* Apply the RLE info */
2020 for (i = count; i > 0; i--)
2022 /* Access the cave */
2023 c_ptr = &cave[y][x];
2025 /* Extract "feat" */
2026 c_ptr->mimic = tmp8u;
2035 if (++y >= ymax) break;
2040 /*** Run length decoding ***/
2042 /* Load the dungeon data */
2043 for (x = y = 0; y < ymax; )
2049 /* Apply the RLE info */
2050 for (i = count; i > 0; i--)
2052 /* Access the cave */
2053 c_ptr = &cave[y][x];
2055 /* Extract "feat" */
2056 c_ptr->special = tmp16s;
2065 if (++y >= ymax) break;
2072 /* Read the item count */
2075 /* Verify maximum */
2076 if (limit >= max_o_idx)
2079 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2081 note(format("Too many (%d) object entries!", limit));
2087 /* Read the dungeon items */
2088 for (i = 1; i < limit; i++)
2095 /* Get a new record */
2102 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2104 note(format("Object allocation error (%d <> %d)", i, o_idx));
2112 o_ptr = &o_list[o_idx];
2118 /* XXX XXX XXX XXX XXX */
2121 if (o_ptr->held_m_idx)
2123 monster_type *m_ptr;
2126 m_ptr = &m_list[o_ptr->held_m_idx];
2129 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2131 /* Place the object */
2132 m_ptr->hold_o_idx = o_idx;
2138 /* Access the item location */
2139 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2142 o_ptr->next_o_idx = c_ptr->o_idx;
2144 /* Place the object */
2145 c_ptr->o_idx = o_idx;
2152 /* Read the monster count */
2155 /* Hack -- verify */
2156 if (limit >= max_m_idx)
2159 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2161 note(format("Too many (%d) monster entries!", limit));
2167 /* Read the monsters */
2168 for (i = 1; i < limit; i++)
2172 monster_type *m_ptr;
2174 monster_race *r_ptr;
2177 /* Get a new record */
2184 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2186 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2193 /* Acquire monster */
2194 m_ptr = &m_list[m_idx];
2196 /* Read the monster */
2201 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2203 /* Mark the location */
2204 c_ptr->m_idx = m_idx;
2208 r_ptr = &r_info[m_ptr->r_idx];
2210 /* Count XXX XXX XXX */
2216 /* The dungeon is ready */
2217 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2218 character_dungeon = FALSE;
2220 character_dungeon = TRUE;
2229 * Actually read the savefile
2231 static errr rd_savefile_new_aux(void)
2243 #ifdef VERIFY_CHECKSUMS
2244 u32b n_x_check, n_v_check;
2245 u32b o_x_check, o_v_check;
2249 /* Mention the savefile version */
2251 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2253 note(format("Loading a %d.%d.%d savefile...",
2256 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2259 /* Strip the version bytes */
2262 /* Hack -- decrypt */
2263 xor_byte = sf_extra;
2266 /* Clear the checksums */
2270 #if SAVEFILE_VERSION
2271 /* Read the version number of the savefile */
2272 rd_u32b(&sf_version);
2273 #endif /* SAVEFILE_VERSION */
2275 /* Operating system info */
2278 /* Time of savefile creation */
2281 /* Number of resurrections */
2284 /* Number of times played */
2288 /* Later use (always zero) */
2291 /* Later use (always zero) */
2295 /* Read RNG state */
2298 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2300 if (arg_fiddle) note("Loaded Randomizer Info");
2305 /* Then the options */
2308 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2310 if (arg_fiddle) note("Loaded Option Flags");
2314 * Munchkin players are marked
2316 * XXX - should be replaced with a better method,
2317 * after the new scorefile-handling is implemented.
2325 /* Then the "messages" */
2328 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2330 if (arg_fiddle) note("Loaded Messages");
2335 for (i = 0; i < max_r_idx; i++)
2337 monster_race *r_ptr;
2338 /* Access that monster */
2341 /* Hack -- Reset the death counter */
2342 r_ptr->max_num = 100;
2343 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2344 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2347 /* Monster Memory */
2350 /* Incompatible save files */
2351 if (tmp16u > max_r_idx)
2354 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2356 note(format("Too many (%u) monster races!", tmp16u));
2362 /* Read the available records */
2363 for (i = 0; i < tmp16u; i++)
2365 monster_race *r_ptr;
2370 /* Access that monster */
2375 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2377 if (arg_fiddle) note("Loaded Monster Memory");
2385 /* Incompatible save files */
2386 if (tmp16u > max_k_idx)
2389 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2391 note(format("Too many (%u) object kinds!", tmp16u));
2397 /* Read the object memory */
2398 for (i = 0; i < tmp16u; i++)
2401 object_kind *k_ptr = &k_info[i];
2405 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2406 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2409 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2411 if (arg_fiddle) note("Loaded Object Memory");
2417 * Initialize arena and rewards information
2419 p_ptr->arena_number = 0;
2420 p_ptr->inside_arena = 0;
2421 p_ptr->inside_quest = 0;
2422 p_ptr->leftbldg = FALSE;
2423 p_ptr->exit_bldg = TRUE;
2425 /* Start in town 1 */
2426 p_ptr->town_num = 1;
2428 p_ptr->wilderness_x = 4;
2429 p_ptr->wilderness_y = 4;
2433 /* Init the wilderness seeds */
2434 for (i = 0; i < max_wild_x; i++)
2436 for (j = 0; j < max_wild_y; j++)
2438 wilderness[j][i].seed = rand_int(0x10000000);
2442 /* 2.1.3 or newer version */
2444 u16b max_towns_load;
2445 u16b max_quests_load;
2446 byte max_rquests_load;
2447 s16b old_inside_quest = p_ptr->inside_quest;
2449 /* Number of towns */
2450 rd_u16b(&max_towns_load);
2452 /* Incompatible save files */
2453 if (max_towns_load > max_towns)
2456 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2458 note(format("Too many (%u) towns!", max_towns_load));
2464 /* Number of quests */
2465 rd_u16b(&max_quests_load);
2467 if (z_older_than(11, 0, 7))
2469 max_rquests_load = 10;
2473 rd_byte(&max_rquests_load);
2476 /* Incompatible save files */
2477 if (max_quests_load > max_quests)
2480 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2482 note(format("Too many (%u) quests!", max_quests_load));
2488 for (i = 0; i < max_quests_load; i++)
2492 rd_s16b(&quest[i].status);
2493 rd_s16b(&quest[i].level);
2495 if (z_older_than(11, 0, 6))
2497 quest[i].complev = 0;
2501 rd_byte(&quest[i].complev);
2504 /* Load quest status if quest is running */
2505 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))))
2507 rd_s16b(&quest[i].cur_num);
2508 rd_s16b(&quest[i].max_num);
2509 rd_s16b(&quest[i].type);
2511 /* Load quest monster index */
2512 rd_s16b(&quest[i].r_idx);
2514 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2519 monster_race *r_ptr;
2522 * Random monster 5 - 10 levels out of depth
2523 * (depending on level)
2525 r_idx = get_mon_num(quest[i].level + 5 + randint(quest[i].level / 10));
2526 r_ptr = &r_info[r_idx];
2528 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2530 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2532 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2534 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2536 if(!(r_ptr->flags8 & RF8_DUNGEON)) continue;
2539 * Accept monsters that are 2 - 6 levels
2540 * out of depth depending on the quest level
2542 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2545 quest[i].r_idx = r_idx;
2548 /* Load quest item index */
2549 rd_s16b(&quest[i].k_idx);
2552 a_info[quest[i].k_idx].flags3 |= TR3_QUESTITEM;
2554 rd_byte(&quest[i].flags);
2556 if (z_older_than(10, 3, 11))
2558 if (quest[i].flags & QUEST_FLAG_PRESET)
2560 quest[i].dungeon = 0;
2564 init_flags = INIT_ASSIGN;
2565 p_ptr->inside_quest = i;
2567 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2568 p_ptr->inside_quest = old_inside_quest;
2573 rd_byte(&quest[i].dungeon);
2576 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2577 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2578 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2581 /* Ignore the empty quests from old versions */
2584 /* Ignore quest status */
2587 /* Ignore quest level */
2591 * We don't have to care about the other info,
2592 * since status should be 0 for these quests anyway
2597 /* Position in the wilderness */
2598 rd_s32b(&p_ptr->wilderness_x);
2599 rd_s32b(&p_ptr->wilderness_y);
2600 if (z_older_than(10, 3, 13))
2602 p_ptr->wilderness_x = 5;
2603 p_ptr->wilderness_y = 48;
2606 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2607 else rd_byte((byte *)&p_ptr->wild_mode);
2608 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2609 else rd_byte((byte *)&ambush_flag);
2611 /* Size of the wilderness */
2612 rd_s32b(&wild_x_size);
2613 rd_s32b(&wild_y_size);
2615 /* Incompatible save files */
2616 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2619 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2621 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2627 /* Load the wilderness seeds */
2628 for (i = 0; i < wild_x_size; i++)
2630 for (j = 0; j < wild_y_size; j++)
2632 rd_u32b(&wilderness[j][i].seed);
2638 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2640 if (arg_fiddle) note("Loaded Quests");
2643 /* Load the Artifacts */
2646 /* Incompatible save files */
2647 if (tmp16u > max_a_idx)
2650 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2652 note(format("Too many (%u) artifacts!", tmp16u));
2658 /* Read the artifact flags */
2659 for (i = 0; i < tmp16u; i++)
2662 a_info[i].cur_num = tmp8u;
2668 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2670 if (arg_fiddle) note("Loaded Artifacts");
2675 /* Read the extra stuff */
2677 if (p_ptr->energy > 999) world_player = TRUE;
2679 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2681 if (arg_fiddle) note("Loaded extra information");
2685 /* Read the player_hp array */
2688 /* Incompatible save files */
2689 if (tmp16u > PY_MAX_LEVEL)
2692 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2694 note(format("Too many (%u) hitpoint entries!", tmp16u));
2700 /* Read the player_hp array */
2701 for (i = 0; i < tmp16u; i++)
2703 rd_s16b(&player_hp[i]);
2706 if(p_ptr->pseikaku == SEIKAKU_SEXY)
2707 weapon_exp_settei[p_ptr->pclass][TV_HAFTED-TV_BOW][SV_WHIP][1] = 8000;
2708 /* Important -- Initialize the sex */
2709 sp_ptr = &sex_info[p_ptr->psex];
2711 /* Important -- Initialize the race/class */
2712 rp_ptr = &race_info[p_ptr->prace];
2713 cp_ptr = &class_info[p_ptr->pclass];
2714 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2716 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !death)
2718 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2719 do_cmd_rerate(FALSE);
2721 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !death)
2723 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2724 do_cmd_rerate(FALSE);
2726 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !death)
2728 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2729 do_cmd_rerate(FALSE);
2731 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !death)
2733 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2734 do_cmd_rerate(FALSE);
2737 /* Important -- Initialize the magic */
2738 mp_ptr = &magic_info[p_ptr->pclass];
2741 /* Read spell info */
2742 rd_u32b(&spell_learned1);
2743 rd_u32b(&spell_learned2);
2744 rd_u32b(&spell_worked1);
2745 rd_u32b(&spell_worked2);
2746 rd_u32b(&spell_forgotten1);
2747 rd_u32b(&spell_forgotten2);
2749 if (z_older_than(10,0,5))
2751 p_ptr->learned_spells = 0;
2752 for (i = 0; i < 64; i++)
2754 /* Count known spells */
2756 (spell_learned1 & (1L << i)) :
2757 (spell_learned2 & (1L << (i - 32))))
2759 p_ptr->learned_spells++;
2763 else rd_s16b(&p_ptr->learned_spells);
2765 if (z_older_than(10,0,6))
2767 p_ptr->add_spells = 0;
2769 else rd_s16b(&p_ptr->add_spells);
2770 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2772 for (i = 0; i < 64; i++)
2774 rd_byte(&spell_order[i]);
2778 /* Read the inventory */
2782 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2784 note("Unable to read inventory");
2790 /* Read number of towns */
2792 town_count = tmp16u;
2794 /* Read the stores */
2796 for (i = 1; i < town_count; i++)
2798 for (j = 0; j < tmp16u; j++)
2800 if (rd_store(i, j)) return (22);
2804 rd_s16b(&p_ptr->pet_follow_distance);
2805 if (z_older_than(10, 4, 10))
2807 p_ptr->pet_extra_flags = 0;
2809 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2811 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2813 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2817 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2820 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2824 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2827 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2831 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2834 if (!z_older_than(10,0,8))
2837 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2842 rd_s16b(&p_ptr->pet_extra_flags);
2847 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2849 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2854 /* I'm not dead yet... */
2857 /* Dead players have no dungeon */
2859 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2861 note("Restoring Dungeon...");
2867 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2869 note("Error reading dungeon data");
2875 /* Read the ghost info */
2885 char *callbacks = (char*) malloc(tmp32s + 1);
2886 rd_string(callbacks, tmp32s + 1);
2887 callbacks_load_callback(callbacks);
2890 #else /* USE_SCRIPT */
2891 strip_bytes(tmp32s);
2892 #endif /* USE_SCRIPT */
2897 #ifdef VERIFY_CHECKSUMS
2899 /* Save the checksum */
2900 n_v_check = v_check;
2902 /* Read the old checksum */
2903 rd_u32b(&o_v_check);
2906 if (o_v_check != n_v_check)
2909 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2911 note("Invalid checksum");
2918 /* Save the encoded checksum */
2919 n_x_check = x_check;
2921 /* Read the checksum */
2922 rd_u32b(&o_x_check);
2926 if (o_x_check != n_x_check)
2929 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2931 note("Invalid encoded checksum");
2945 * Actually read the savefile
2947 errr rd_savefile_new(void)
2951 /* The savefile is a binary file */
2952 fff = my_fopen(savefile, "rb");
2955 if (!fff) return (-1);
2957 /* Call the sub-function */
2958 err = rd_savefile_new_aux();
2960 /* Check for errors */
2961 if (ferror(fff)) err = -1;
2963 /* Close the file */