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], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
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);
1433 p_ptr->inside_arena = (bool)tmp16s;
1434 rd_s16b(&p_ptr->inside_quest);
1435 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1439 p_ptr->inside_battle = (bool)tmp16s;
1441 rd_byte(&p_ptr->exit_bldg);
1442 rd_byte(&p_ptr->leftbldg);
1444 rd_s16b(&p_ptr->oldpx);
1445 rd_s16b(&p_ptr->oldpy);
1446 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1450 if (tmp16s > MAX_BACT)
1453 note(format("¤ÎÃæ", tmp16s));
1455 note(format("Too many (%d) building rewards!", tmp16s));
1460 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1462 rd_s16b(&p_ptr->mhp);
1463 rd_s16b(&p_ptr->chp);
1464 rd_u16b(&p_ptr->chp_frac);
1466 rd_s16b(&p_ptr->msp);
1467 rd_s16b(&p_ptr->csp);
1468 rd_u16b(&p_ptr->csp_frac);
1470 rd_s16b(&p_ptr->max_plv);
1471 if (z_older_than(10, 3, 8))
1473 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1477 byte max = (byte)max_d_idx;
1481 for(i = 0; i < max; i++)
1483 rd_s16b(&max_dlv[i]);
1484 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1488 /* Repair maximum player level XXX XXX XXX */
1489 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1493 rd_s16b(&p_ptr->sc);
1496 /* Read the flags */
1497 strip_bytes(2); /* Old "rest" */
1498 rd_s16b(&p_ptr->blind);
1499 rd_s16b(&p_ptr->paralyzed);
1500 rd_s16b(&p_ptr->confused);
1501 rd_s16b(&p_ptr->food);
1502 strip_bytes(4); /* Old "food_digested" / "protection" */
1503 rd_s16b(&p_ptr->energy);
1504 rd_s16b(&p_ptr->fast);
1505 rd_s16b(&p_ptr->slow);
1506 rd_s16b(&p_ptr->afraid);
1507 rd_s16b(&p_ptr->cut);
1508 rd_s16b(&p_ptr->stun);
1509 rd_s16b(&p_ptr->poisoned);
1510 rd_s16b(&p_ptr->image);
1511 rd_s16b(&p_ptr->protevil);
1512 rd_s16b(&p_ptr->invuln);
1513 if(z_older_than(10, 0, 0))
1516 rd_s16b(&p_ptr->ult_res);
1517 rd_s16b(&p_ptr->hero);
1518 rd_s16b(&p_ptr->shero);
1519 rd_s16b(&p_ptr->shield);
1520 rd_s16b(&p_ptr->blessed);
1521 rd_s16b(&p_ptr->tim_invis);
1522 rd_s16b(&p_ptr->word_recall);
1523 if (z_older_than(10, 3, 8))
1524 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1528 p_ptr->recall_dungeon = (byte)tmp16s;
1530 rd_s16b(&p_ptr->see_infra);
1531 rd_s16b(&p_ptr->tim_infra);
1532 rd_s16b(&p_ptr->oppose_fire);
1533 rd_s16b(&p_ptr->oppose_cold);
1534 rd_s16b(&p_ptr->oppose_acid);
1535 rd_s16b(&p_ptr->oppose_elec);
1536 rd_s16b(&p_ptr->oppose_pois);
1537 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1538 else rd_s16b(&p_ptr->tsuyoshi);
1540 /* Old savefiles do not have the following fields... */
1541 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1544 p_ptr->wraith_form = 0;
1545 p_ptr->resist_magic = 0;
1546 p_ptr->tim_regen = 0;
1547 p_ptr->kabenuke = 0;
1548 p_ptr->tim_stealth = 0;
1549 p_ptr->tim_ffall = 0;
1550 p_ptr->tim_sh_touki = 0;
1551 p_ptr->lightspeed = 0;
1552 p_ptr->tsubureru = 0;
1553 p_ptr->tim_res_nether = 0;
1554 p_ptr->tim_res_time = 0;
1555 p_ptr->mimic_form = 0;
1556 p_ptr->tim_mimic = 0;
1557 p_ptr->tim_sh_fire = 0;
1560 p_ptr->tim_reflect = 0;
1561 p_ptr->multishadow = 0;
1562 p_ptr->dustrobe = 0;
1564 p_ptr->chaos_patron = get_chaos_patron();
1572 rd_s16b(&p_ptr->tim_esp);
1573 rd_s16b(&p_ptr->wraith_form);
1574 rd_s16b(&p_ptr->resist_magic);
1575 rd_s16b(&p_ptr->tim_regen);
1576 rd_s16b(&p_ptr->kabenuke);
1577 rd_s16b(&p_ptr->tim_stealth);
1578 rd_s16b(&p_ptr->tim_ffall);
1579 rd_s16b(&p_ptr->tim_sh_touki);
1580 rd_s16b(&p_ptr->lightspeed);
1581 rd_s16b(&p_ptr->tsubureru);
1582 if (z_older_than(10, 4, 7))
1583 p_ptr->magicdef = 0;
1585 rd_s16b(&p_ptr->magicdef);
1586 rd_s16b(&p_ptr->tim_res_nether);
1587 if (z_older_than(10, 4, 11))
1589 p_ptr->tim_res_time = 0;
1590 p_ptr->mimic_form = 0;
1591 p_ptr->tim_mimic = 0;
1592 p_ptr->tim_sh_fire = 0;
1596 rd_s16b(&p_ptr->tim_res_time);
1597 rd_byte(&p_ptr->mimic_form);
1598 rd_s16b(&p_ptr->tim_mimic);
1599 rd_s16b(&p_ptr->tim_sh_fire);
1603 if ( z_older_than(11,0,3) ){
1604 p_ptr->tim_reflect=0;
1605 p_ptr->multishadow=0;
1609 rd_s16b(&p_ptr->tim_reflect);
1610 rd_s16b(&p_ptr->multishadow);
1611 rd_s16b(&p_ptr->dustrobe);
1614 rd_s16b(&p_ptr->chaos_patron);
1615 rd_u32b(&p_ptr->muta1);
1616 rd_u32b(&p_ptr->muta2);
1617 rd_u32b(&p_ptr->muta3);
1619 for (i = 0; i < 8; i++)
1620 rd_s16b(&p_ptr->virtues[i]);
1621 for (i = 0; i < 8; i++)
1622 rd_s16b(&p_ptr->vir_types[i]);
1625 /* Calc the regeneration modifier for mutations */
1626 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1628 if (z_older_than(10,0,9))
1631 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1632 p_ptr->ele_attack = 0;
1636 rd_s16b(&p_ptr->ele_attack);
1637 rd_u32b(&p_ptr->special_attack);
1639 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1640 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1641 if (z_older_than(10,0,12))
1643 p_ptr->ele_immune = 0;
1644 p_ptr->special_defense = 0;
1648 rd_s16b(&p_ptr->ele_immune);
1649 rd_u32b(&p_ptr->special_defense);
1651 rd_byte(&p_ptr->knowledge);
1652 rd_byte(&tmp8u); /* oops */
1653 rd_byte(&tmp8u); /* oops */
1654 rd_byte(&p_ptr->action);
1655 if (!z_older_than(10, 4, 3))
1658 if (tmp8u) p_ptr->action = ACTION_LEARN;
1660 rd_byte((byte *)&preserve_mode);
1661 rd_byte((byte *)&wait_report_score);
1664 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1666 /* Skip the flags */
1670 /* Hack -- the two "special seeds" */
1671 rd_u32b(&seed_flavor);
1672 rd_u32b(&seed_town);
1676 rd_u16b(&panic_save);
1677 rd_u16b(&total_winner);
1685 /* Read "feeling" */
1689 /* Turn of last "feeling" */
1695 if (z_older_than(10, 3, 12))
1697 dungeon_turn = turn;
1699 else rd_s32b(&dungeon_turn);
1701 if (z_older_than(10, 3, 13))
1705 else rd_s32b(&old_battle);
1707 if (z_older_than(10,0,3))
1709 monster_race *r_ptr;
1713 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1714 r_ptr = &r_info[today_mon];
1716 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1717 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1718 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1719 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1720 if (r_ptr->rarity > 10) continue;
1721 if (r_ptr->level == 0) continue;
1725 p_ptr->today_mon = 0;
1729 rd_s16b(&today_mon);
1730 rd_s16b(&p_ptr->today_mon);
1733 if (z_older_than(10,0,7))
1739 rd_s16b(&p_ptr->riding);
1742 if (z_older_than(10,1,2))
1751 if (z_older_than(10,3,9))
1755 else if (z_older_than(10, 3, 10))
1763 rd_s32b(&p_ptr->visit);
1765 if (!z_older_than(11, 0, 5))
1767 rd_u32b(&p_ptr->count);
1775 * Read the player inventory
1777 * Note that the inventory changed in Angband 2.7.4. Two extra
1778 * pack slots were added and the equipment was rearranged. Note
1779 * that these two features combine when parsing old save-files, in
1780 * which items from the old "aux" slot are "carried", perhaps into
1781 * one of the two new "inventory" slots.
1783 * Note that the inventory is "re-sorted" later by "dungeon()".
1785 static errr rd_inventory(void)
1793 p_ptr->total_weight = 0;
1799 /* Read until done */
1804 /* Get the next item index */
1807 /* Nope, we reached the end */
1808 if (n == 0xFFFF) break;
1810 /* Get local object */
1813 /* Wipe the object */
1819 /* Hack -- verify item */
1820 if (!q_ptr->k_idx) return (53);
1822 /* Wield equipment */
1823 if (n >= INVEN_RARM)
1826 object_copy(&inventory[n], q_ptr);
1828 /* Add the weight */
1829 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1835 /* Warning -- backpack is full */
1836 else if (inven_cnt == INVEN_PACK)
1840 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1842 note("Too many items in the inventory!");
1850 /* Carry inventory */
1857 object_copy(&inventory[n], q_ptr);
1859 /* Add the weight */
1860 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1874 * Read the saved messages
1876 static void rd_messages(void)
1886 /* Read the messages */
1887 for (i = 0; i < num; i++)
1889 /* Read the message */
1890 rd_string(buf, 128);
1892 /* Save the message */
1902 * The monsters/objects must be loaded in the same order
1903 * that they were stored, since the actual indexes matter.
1905 static errr rd_dungeon(void)
1916 /*** Basic info ***/
1919 rd_s16b(&dun_level);
1920 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1921 else rd_byte(&dungeon_type);
1923 /* Set the base level for old versions */
1924 base_level = dun_level;
1926 rd_s16b(&base_level);
1928 rd_s16b(&num_repro);
1933 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1936 rd_s16b(&max_panel_rows);
1937 rd_s16b(&max_panel_cols);
1940 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1948 /*** Run length decoding ***/
1950 /* Load the dungeon data */
1951 for (x = y = 0; y < ymax; )
1955 if (z_older_than(10,3,6))
1960 /* Apply the RLE info */
1961 for (i = count; i > 0; i--)
1963 /* Access the cave */
1964 c_ptr = &cave[y][x];
1966 /* Extract "info" */
1967 if (z_older_than(10,3,6))
1968 c_ptr->info = tmp8u;
1969 else c_ptr->info = tmp16s;
1978 if (++y >= ymax) break;
1984 /*** Run length decoding ***/
1986 /* Load the dungeon data */
1987 for (x = y = 0; y < ymax; )
1993 /* Apply the RLE info */
1994 for (i = count; i > 0; i--)
1996 /* Access the cave */
1997 c_ptr = &cave[y][x];
1999 if (c_ptr->feat == FEAT_INVIS)
2001 c_ptr->feat = FEAT_FLOOR;
2002 c_ptr->info |= CAVE_TRAP;
2005 /* Extract "feat" */
2006 c_ptr->feat = tmp8u;
2015 if (++y >= ymax) break;
2020 /*** Run length decoding ***/
2022 /* Load the dungeon data */
2023 for (x = y = 0; y < ymax; )
2029 /* Apply the RLE info */
2030 for (i = count; i > 0; i--)
2032 /* Access the cave */
2033 c_ptr = &cave[y][x];
2035 /* Extract "feat" */
2036 c_ptr->mimic = tmp8u;
2045 if (++y >= ymax) break;
2050 /*** Run length decoding ***/
2052 /* Load the dungeon data */
2053 for (x = y = 0; y < ymax; )
2059 /* Apply the RLE info */
2060 for (i = count; i > 0; i--)
2062 /* Access the cave */
2063 c_ptr = &cave[y][x];
2065 /* Extract "feat" */
2066 c_ptr->special = tmp16s;
2075 if (++y >= ymax) break;
2082 /* Read the item count */
2085 /* Verify maximum */
2086 if (limit >= max_o_idx)
2089 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2091 note(format("Too many (%d) object entries!", limit));
2097 /* Read the dungeon items */
2098 for (i = 1; i < limit; i++)
2105 /* Get a new record */
2112 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2114 note(format("Object allocation error (%d <> %d)", i, o_idx));
2122 o_ptr = &o_list[o_idx];
2128 /* XXX XXX XXX XXX XXX */
2131 if (o_ptr->held_m_idx)
2133 monster_type *m_ptr;
2136 m_ptr = &m_list[o_ptr->held_m_idx];
2139 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2141 /* Place the object */
2142 m_ptr->hold_o_idx = o_idx;
2148 /* Access the item location */
2149 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2152 o_ptr->next_o_idx = c_ptr->o_idx;
2154 /* Place the object */
2155 c_ptr->o_idx = o_idx;
2162 /* Read the monster count */
2165 /* Hack -- verify */
2166 if (limit >= max_m_idx)
2169 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2171 note(format("Too many (%d) monster entries!", limit));
2177 /* Read the monsters */
2178 for (i = 1; i < limit; i++)
2182 monster_type *m_ptr;
2184 monster_race *r_ptr;
2187 /* Get a new record */
2194 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2196 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2203 /* Acquire monster */
2204 m_ptr = &m_list[m_idx];
2206 /* Read the monster */
2211 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2213 /* Mark the location */
2214 c_ptr->m_idx = m_idx;
2218 r_ptr = &r_info[m_ptr->r_idx];
2220 /* Count XXX XXX XXX */
2226 /* The dungeon is ready */
2227 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2228 character_dungeon = FALSE;
2230 character_dungeon = TRUE;
2239 * Actually read the savefile
2241 static errr rd_savefile_new_aux(void)
2253 #ifdef VERIFY_CHECKSUMS
2254 u32b n_x_check, n_v_check;
2255 u32b o_x_check, o_v_check;
2259 /* Mention the savefile version */
2261 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2263 note(format("Loading a %d.%d.%d savefile...",
2266 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2269 /* Strip the version bytes */
2272 /* Hack -- decrypt */
2273 xor_byte = sf_extra;
2276 /* Clear the checksums */
2280 #if SAVEFILE_VERSION
2281 /* Read the version number of the savefile */
2282 rd_u32b(&sf_version);
2283 #endif /* SAVEFILE_VERSION */
2285 /* Operating system info */
2288 /* Time of savefile creation */
2291 /* Number of resurrections */
2294 /* Number of times played */
2298 /* Later use (always zero) */
2301 /* Later use (always zero) */
2305 /* Read RNG state */
2308 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2310 if (arg_fiddle) note("Loaded Randomizer Info");
2315 /* Then the options */
2318 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2320 if (arg_fiddle) note("Loaded Option Flags");
2324 * Munchkin players are marked
2326 * XXX - should be replaced with a better method,
2327 * after the new scorefile-handling is implemented.
2335 /* Then the "messages" */
2338 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2340 if (arg_fiddle) note("Loaded Messages");
2345 for (i = 0; i < max_r_idx; i++)
2347 monster_race *r_ptr;
2348 /* Access that monster */
2351 /* Hack -- Reset the death counter */
2352 r_ptr->max_num = 100;
2353 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2354 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2357 /* Monster Memory */
2360 /* Incompatible save files */
2361 if (tmp16u > max_r_idx)
2364 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2366 note(format("Too many (%u) monster races!", tmp16u));
2372 /* Read the available records */
2373 for (i = 0; i < tmp16u; i++)
2375 monster_race *r_ptr;
2380 /* Access that monster */
2385 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2387 if (arg_fiddle) note("Loaded Monster Memory");
2395 /* Incompatible save files */
2396 if (tmp16u > max_k_idx)
2399 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2401 note(format("Too many (%u) object kinds!", tmp16u));
2407 /* Read the object memory */
2408 for (i = 0; i < tmp16u; i++)
2411 object_kind *k_ptr = &k_info[i];
2415 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2416 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2419 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2421 if (arg_fiddle) note("Loaded Object Memory");
2427 * Initialize arena and rewards information
2429 p_ptr->arena_number = 0;
2430 p_ptr->inside_arena = 0;
2431 p_ptr->inside_quest = 0;
2432 p_ptr->leftbldg = FALSE;
2433 p_ptr->exit_bldg = TRUE;
2435 /* Start in town 1 */
2436 p_ptr->town_num = 1;
2438 p_ptr->wilderness_x = 4;
2439 p_ptr->wilderness_y = 4;
2443 /* Init the wilderness seeds */
2444 for (i = 0; i < max_wild_x; i++)
2446 for (j = 0; j < max_wild_y; j++)
2448 wilderness[j][i].seed = rand_int(0x10000000);
2452 /* 2.1.3 or newer version */
2454 u16b max_towns_load;
2455 u16b max_quests_load;
2456 byte max_rquests_load;
2457 s16b old_inside_quest = p_ptr->inside_quest;
2459 /* Number of towns */
2460 rd_u16b(&max_towns_load);
2462 /* Incompatible save files */
2463 if (max_towns_load > max_towns)
2466 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2468 note(format("Too many (%u) towns!", max_towns_load));
2474 /* Number of quests */
2475 rd_u16b(&max_quests_load);
2477 if (z_older_than(11, 0, 7))
2479 max_rquests_load = 10;
2483 rd_byte(&max_rquests_load);
2486 /* Incompatible save files */
2487 if (max_quests_load > max_quests)
2490 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2492 note(format("Too many (%u) quests!", max_quests_load));
2498 for (i = 0; i < max_quests_load; i++)
2502 rd_s16b(&quest[i].status);
2503 rd_s16b(&quest[i].level);
2505 if (z_older_than(11, 0, 6))
2507 quest[i].complev = 0;
2511 rd_byte(&quest[i].complev);
2514 /* Load quest status if quest is running */
2515 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))))
2517 rd_s16b(&quest[i].cur_num);
2518 rd_s16b(&quest[i].max_num);
2519 rd_s16b(&quest[i].type);
2521 /* Load quest monster index */
2522 rd_s16b(&quest[i].r_idx);
2524 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2529 monster_race *r_ptr;
2532 * Random monster 5 - 10 levels out of depth
2533 * (depending on level)
2535 r_idx = get_mon_num(quest[i].level + 5 + randint(quest[i].level / 10));
2536 r_ptr = &r_info[r_idx];
2538 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2540 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2542 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2544 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2546 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2549 * Accept monsters that are 2 - 6 levels
2550 * out of depth depending on the quest level
2552 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2555 quest[i].r_idx = r_idx;
2558 /* Load quest item index */
2559 rd_s16b(&quest[i].k_idx);
2562 a_info[quest[i].k_idx].flags3 |= TR3_QUESTITEM;
2564 rd_byte(&quest[i].flags);
2566 if (z_older_than(10, 3, 11))
2568 if (quest[i].flags & QUEST_FLAG_PRESET)
2570 quest[i].dungeon = 0;
2574 init_flags = INIT_ASSIGN;
2575 p_ptr->inside_quest = i;
2577 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2578 p_ptr->inside_quest = old_inside_quest;
2583 rd_byte(&quest[i].dungeon);
2586 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2587 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2588 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2591 /* Ignore the empty quests from old versions */
2594 /* Ignore quest status */
2597 /* Ignore quest level */
2601 * We don't have to care about the other info,
2602 * since status should be 0 for these quests anyway
2607 /* Position in the wilderness */
2608 rd_s32b(&p_ptr->wilderness_x);
2609 rd_s32b(&p_ptr->wilderness_y);
2610 if (z_older_than(10, 3, 13))
2612 p_ptr->wilderness_x = 5;
2613 p_ptr->wilderness_y = 48;
2616 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2617 else rd_byte((byte *)&p_ptr->wild_mode);
2618 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2619 else rd_byte((byte *)&ambush_flag);
2621 /* Size of the wilderness */
2622 rd_s32b(&wild_x_size);
2623 rd_s32b(&wild_y_size);
2625 /* Incompatible save files */
2626 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2629 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2631 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2637 /* Load the wilderness seeds */
2638 for (i = 0; i < wild_x_size; i++)
2640 for (j = 0; j < wild_y_size; j++)
2642 rd_u32b(&wilderness[j][i].seed);
2648 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2650 if (arg_fiddle) note("Loaded Quests");
2653 /* Load the Artifacts */
2656 /* Incompatible save files */
2657 if (tmp16u > max_a_idx)
2660 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2662 note(format("Too many (%u) artifacts!", tmp16u));
2668 /* Read the artifact flags */
2669 for (i = 0; i < tmp16u; i++)
2672 a_info[i].cur_num = tmp8u;
2678 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2680 if (arg_fiddle) note("Loaded Artifacts");
2685 /* Read the extra stuff */
2687 if (p_ptr->energy > 999) world_player = TRUE;
2689 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2691 if (arg_fiddle) note("Loaded extra information");
2695 /* Read the player_hp array */
2698 /* Incompatible save files */
2699 if (tmp16u > PY_MAX_LEVEL)
2702 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2704 note(format("Too many (%u) hitpoint entries!", tmp16u));
2710 /* Read the player_hp array */
2711 for (i = 0; i < tmp16u; i++)
2713 rd_s16b(&player_hp[i]);
2716 /* Important -- Initialize the sex */
2717 sp_ptr = &sex_info[p_ptr->psex];
2719 /* Important -- Initialize the race/class */
2720 rp_ptr = &race_info[p_ptr->prace];
2721 cp_ptr = &class_info[p_ptr->pclass];
2722 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2724 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !death)
2726 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2727 do_cmd_rerate(FALSE);
2729 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !death)
2731 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2732 do_cmd_rerate(FALSE);
2734 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !death)
2736 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2737 do_cmd_rerate(FALSE);
2739 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !death)
2741 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2742 do_cmd_rerate(FALSE);
2745 /* Important -- Initialize the magic */
2746 mp_ptr = &m_info[p_ptr->pclass];
2749 /* Read spell info */
2750 rd_u32b(&spell_learned1);
2751 rd_u32b(&spell_learned2);
2752 rd_u32b(&spell_worked1);
2753 rd_u32b(&spell_worked2);
2754 rd_u32b(&spell_forgotten1);
2755 rd_u32b(&spell_forgotten2);
2757 if (z_older_than(10,0,5))
2759 p_ptr->learned_spells = 0;
2760 for (i = 0; i < 64; i++)
2762 /* Count known spells */
2764 (spell_learned1 & (1L << i)) :
2765 (spell_learned2 & (1L << (i - 32))))
2767 p_ptr->learned_spells++;
2771 else rd_s16b(&p_ptr->learned_spells);
2773 if (z_older_than(10,0,6))
2775 p_ptr->add_spells = 0;
2777 else rd_s16b(&p_ptr->add_spells);
2778 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2780 for (i = 0; i < 64; i++)
2782 rd_byte(&spell_order[i]);
2786 /* Read the inventory */
2790 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2792 note("Unable to read inventory");
2798 /* Read number of towns */
2800 town_count = tmp16u;
2802 /* Read the stores */
2804 for (i = 1; i < town_count; i++)
2806 for (j = 0; j < tmp16u; j++)
2808 if (rd_store(i, j)) return (22);
2812 rd_s16b(&p_ptr->pet_follow_distance);
2813 if (z_older_than(10, 4, 10))
2815 p_ptr->pet_extra_flags = 0;
2817 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2819 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2821 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2825 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2828 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2832 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2835 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2839 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2842 if (!z_older_than(10,0,8))
2845 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2850 rd_s16b(&p_ptr->pet_extra_flags);
2855 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2857 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2862 /* I'm not dead yet... */
2865 /* Dead players have no dungeon */
2867 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2869 note("Restoring Dungeon...");
2875 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2877 note("Error reading dungeon data");
2883 /* Read the ghost info */
2893 char *callbacks = (char*) malloc(tmp32s + 1);
2894 rd_string(callbacks, tmp32s + 1);
2895 callbacks_load_callback(callbacks);
2898 #else /* USE_SCRIPT */
2899 strip_bytes(tmp32s);
2900 #endif /* USE_SCRIPT */
2905 #ifdef VERIFY_CHECKSUMS
2907 /* Save the checksum */
2908 n_v_check = v_check;
2910 /* Read the old checksum */
2911 rd_u32b(&o_v_check);
2914 if (o_v_check != n_v_check)
2917 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2919 note("Invalid checksum");
2926 /* Save the encoded checksum */
2927 n_x_check = x_check;
2929 /* Read the checksum */
2930 rd_u32b(&o_x_check);
2934 if (o_x_check != n_x_check)
2937 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2939 note("Invalid encoded checksum");
2953 * Actually read the savefile
2955 errr rd_savefile_new(void)
2959 /* The savefile is a binary file */
2960 fff = my_fopen(savefile, "rb");
2963 if (!fff) return (-1);
2965 /* Call the sub-function */
2966 err = rd_savefile_new_aux();
2968 /* Check for errors */
2969 if (ferror(fff)) err = -1;
2971 /* Close the file */