3 /* Purpose: support for loading savefiles -BEN- */
9 * This file loads savefiles from Angband 2.7.X and 2.8.X
11 * Ancient savefiles (pre-2.7.0) are loaded by another file.
13 * Note that Angband 2.7.0 through 2.7.3 are now officially obsolete,
14 * and savefiles from those versions may not be successfully converted.
16 * We attempt to prevent corrupt savefiles from inducing memory errors.
18 * Note that this file should not use the random number generator, the
19 * object flavors, the visual attr/char mappings, or anything else which
20 * is initialized *after* or *during* the "load character" function.
22 * This file assumes that the monster/object records are initialized
23 * to zero, and the race/kind tables have been loaded correctly. The
24 * order of object stacks is currently not saved in the savefiles, but
25 * the "next" pointers are saved, so all necessary knowledge is present.
27 * We should implement simple "savefile extenders" using some form of
28 * "sized" chunks of bytes, with a {size,type,data} format, so everyone
29 * can know the size, interested people can know the type, and the actual
30 * data is available to the parsing routines that acknowledge the type.
32 * Consider changing the "globe of invulnerability" code so that it
33 * takes some form of "maximum damage to protect from" in addition to
34 * the existing "number of turns to protect for", and where each hit
35 * by a monster will reduce the shield by that amount.
43 * Maximum number of tries for selection of a proper quest monster
49 * Local "savefile" pointer
54 * Hack -- old "encryption" byte
59 * Hack -- simple "checksum" on the actual values
61 static u32b v_check = 0L;
64 * Hack -- simple "checksum" on the encoded bytes
66 static u32b x_check = 0L;
72 * This function determines if the version of the savefile
73 * currently being read is older than version "x.y.z".
75 static bool older_than(byte x, byte y, byte z)
77 /* Much older, or much more recent */
78 if (sf_major < x) return (TRUE);
79 if (sf_major > x) return (FALSE);
81 /* Distinctly older, or distinctly more recent */
82 if (sf_minor < y) return (TRUE);
83 if (sf_minor > y) return (FALSE);
85 /* Barely older, or barely more recent */
86 if (sf_patch < z) return (TRUE);
87 if (sf_patch > z) return (FALSE);
89 /* Identical versions */
95 * The above function, adapted for Zangband
97 static bool z_older_than(byte x, byte y, byte z)
99 /* Much older, or much more recent */
100 if (z_major < x) return (TRUE);
101 if (z_major > x) return (FALSE);
103 /* Distinctly older, or distinctly more recent */
104 if (z_minor < y) return (TRUE);
105 if (z_minor > y) return (FALSE);
107 /* Barely older, or barely more recent */
108 if (z_patch < z) return (TRUE);
109 if (z_patch > z) return (FALSE);
111 /* Identical versions */
117 * Hack -- Show information on the screen, one line at a time.
119 * Avoid the top two lines, to avoid interference with "msg_print()".
121 static void note(cptr msg)
125 /* Draw the message */
128 /* Advance one line (wrap if needed) */
129 if (++y >= 24) y = 2;
137 * Hack -- determine if an item is "wearable" (or a missile)
139 static bool wearable_p(object_type *o_ptr)
141 /* Valid "tval" codes */
177 * The following functions are used to load the basic building blocks
178 * of savefiles. They also maintain the "checksum" info for 2.7.0+
181 static byte sf_get(void)
185 /* Get a character, decode the value */
186 c = getc(fff) & 0xFF;
190 /* Maintain the checksum info */
194 /* Return the value */
198 static void rd_byte(byte *ip)
203 static void rd_u16b(u16b *ip)
206 (*ip) |= ((u16b)(sf_get()) << 8);
209 static void rd_s16b(s16b *ip)
214 static void rd_u32b(u32b *ip)
217 (*ip) |= ((u32b)(sf_get()) << 8);
218 (*ip) |= ((u32b)(sf_get()) << 16);
219 (*ip) |= ((u32b)(sf_get()) << 24);
222 static void rd_s32b(s32b *ip)
229 * Hack -- read a string
231 static void rd_string(char *str, int max)
235 /* Read the string */
236 for (i = 0; TRUE; i++)
243 /* Collect string while legal */
244 if (i < max) str[i] = tmp8u;
259 * Hack -- strip some bytes
261 static void strip_bytes(int n)
265 /* Strip the bytes */
266 while (n--) rd_byte(&tmp8u);
269 #define OLD_MAX_MANE 22
274 * This function attempts to "repair" old savefiles, and to extract
275 * the most up to date values for various object fields.
277 * Note that Angband 2.7.9 introduced a new method for object "flags"
278 * in which the "flags" on an object are actually extracted when they
279 * are needed from the object kind, artifact index, ego-item index,
280 * and two special "xtra" fields which are used to encode any "extra"
281 * power of certain ego-items. This had the side effect that items
282 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
283 * may have had, and also, all "uncursed" items will become "cursed"
284 * again, including Calris, even if it is being worn at the time. As
285 * a complete hack, items which are inscribed with "uncursed" will be
286 * "uncursed" when imported from pre-2.7.9 savefiles.
288 static void rd_item(object_type *o_ptr)
301 rd_s16b(&o_ptr->k_idx);
308 rd_byte(&o_ptr->tval);
309 rd_byte(&o_ptr->sval);
311 if (z_older_than(10, 4, 4))
313 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
314 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
315 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
319 rd_s16b(&o_ptr->pval);
321 rd_byte(&o_ptr->discount);
322 rd_byte(&o_ptr->number);
323 rd_s16b(&o_ptr->weight);
325 rd_byte(&o_ptr->name1);
326 rd_byte(&o_ptr->name2);
327 rd_s16b(&o_ptr->timeout);
329 rd_s16b(&o_ptr->to_h);
330 rd_s16b(&o_ptr->to_d);
331 rd_s16b(&o_ptr->to_a);
338 rd_byte(&o_ptr->ident);
340 rd_byte(&o_ptr->marked);
343 rd_u32b(&o_ptr->art_flags1);
344 rd_u32b(&o_ptr->art_flags2);
345 rd_u32b(&o_ptr->art_flags3);
347 /* Monster holding object */
348 rd_s16b(&o_ptr->held_m_idx);
351 rd_byte(&o_ptr->xtra1);
352 rd_byte(&o_ptr->xtra2);
353 if (z_older_than(10, 2, 3))
358 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
360 o_ptr->xtra3 = o_ptr->xtra1;
363 if (o_ptr->tval == TV_CAPTURE)
365 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
366 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
368 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
369 if (ironman_nightmare)
371 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
373 o_ptr->xtra4 = o_ptr->xtra5;
378 rd_byte(&o_ptr->xtra3);
379 rd_s16b(&o_ptr->xtra4);
380 rd_s16b(&o_ptr->xtra5);
383 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)))
385 o_ptr->xtra4 = o_ptr->pval;
389 /* Feeling - from 2.3.1, "savefile version 1" */
392 rd_byte(&o_ptr->feeling);
398 /* If this savefile is old, maybe we need to translate the feeling */
403 for (i = 0; i <= FEEL_MAX; i++)
405 if (game_inscriptions[i] == NULL)
410 if (streq(buf, game_inscriptions[i]))
419 /* Save the inscription */
420 if (buf[0]) o_ptr->inscription = quark_add(buf);
423 if (buf[0]) o_ptr->art_name = quark_add(buf);
425 /* The Python object */
433 /* Mega-Hack -- handle "dungeon objects" later */
434 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
436 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
438 /* Obtain the "kind" template */
439 k_ptr = &k_info[o_ptr->k_idx];
441 /* Obtain tval/sval from k_info */
442 o_ptr->tval = k_ptr->tval;
443 o_ptr->sval = k_ptr->sval;
445 /* Hack -- notice "broken" items */
446 if (k_ptr->cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
449 /* Repair non "wearable" items */
450 if (!wearable_p(o_ptr))
452 /* Acquire correct fields */
453 o_ptr->to_h = k_ptr->to_h;
454 o_ptr->to_d = k_ptr->to_d;
455 o_ptr->to_a = k_ptr->to_a;
457 /* Acquire correct fields */
458 o_ptr->ac = k_ptr->ac;
459 o_ptr->dd = k_ptr->dd;
460 o_ptr->ds = k_ptr->ds;
462 /* Acquire correct weight */
463 o_ptr->weight = k_ptr->weight;
466 o_ptr->name1 = o_ptr->name2 = 0;
473 /* Extract the flags */
474 object_flags(o_ptr, &f1, &f2, &f3);
476 if (z_older_than(10, 4, 9))
478 if (o_ptr->art_flags1 & TR1_MAGIC_MASTERY)
480 o_ptr->art_flags1 &= ~(TR1_MAGIC_MASTERY);
481 o_ptr->art_flags3 |= (TR3_DEC_MANA);
488 artifact_type *a_ptr;
490 /* Obtain the artifact info */
491 a_ptr = &a_info[o_ptr->name1];
493 /* Verify that artifact */
494 if (!a_ptr->name) o_ptr->name1 = 0;
500 ego_item_type *e_ptr;
502 /* Obtain the ego-item info */
503 e_ptr = &e_info[o_ptr->name2];
505 /* Verify that ego-item */
506 if (!e_ptr->name) o_ptr->name2 = 0;
510 /* Acquire standard fields */
511 o_ptr->ac = k_ptr->ac;
512 o_ptr->dd = k_ptr->dd;
513 o_ptr->ds = k_ptr->ds;
515 /* Acquire standard weight */
516 o_ptr->weight = k_ptr->weight;
518 /* Hack -- extract the "broken" flag */
519 if (!o_ptr->pval < 0) o_ptr->ident |= (IDENT_BROKEN);
524 artifact_type *a_ptr;
526 /* Obtain the artifact info */
527 a_ptr = &a_info[o_ptr->name1];
529 /* Acquire new artifact "pval" */
530 o_ptr->pval = a_ptr->pval;
532 /* Acquire new artifact fields */
533 o_ptr->ac = a_ptr->ac;
534 o_ptr->dd = a_ptr->dd;
535 o_ptr->ds = a_ptr->ds;
537 /* Acquire new artifact weight */
538 o_ptr->weight = a_ptr->weight;
540 /* Hack -- extract the "broken" flag */
541 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
547 ego_item_type *e_ptr;
549 /* Obtain the ego-item info */
550 e_ptr = &e_info[o_ptr->name2];
555 if (o_ptr->name2 == EGO_DWARVEN)
558 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
561 /* Hack -- extract the "broken" flag */
562 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
565 if (o_ptr->art_name) /* A random artifact */
578 static void rd_monster(monster_type *m_ptr)
583 /* Read the monster race */
584 rd_s16b(&m_ptr->r_idx);
586 /* Read the other information */
590 rd_s16b(&m_ptr->maxhp);
591 if (z_older_than(11, 0, 5))
593 m_ptr->max_maxhp = m_ptr->maxhp;
597 rd_s16b(&m_ptr->max_maxhp);
599 rd_s16b(&m_ptr->csleep);
600 rd_byte(&m_ptr->mspeed);
601 if (z_older_than(10, 4, 2))
604 m_ptr->energy = (s16b)tmp8u;
606 else rd_s16b(&m_ptr->energy);
607 if (z_older_than(10,0,7))
614 rd_byte(&m_ptr->fast);
615 rd_byte(&m_ptr->slow);
617 rd_byte(&m_ptr->stunned);
618 rd_byte(&m_ptr->confused);
619 rd_byte(&m_ptr->monfear);
621 if (z_older_than(10,0,10))
626 else if (z_older_than(10,0,11))
635 rd_s16b(&m_ptr->target_y);
636 rd_s16b(&m_ptr->target_x);
639 /* Monster invulnerability introduced from 2.3.2+ */
643 rd_byte(&m_ptr->invulner);
645 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
646 rd_u32b(&m_ptr->smart);
650 if (z_older_than(10, 4, 5))
653 rd_u32b(&m_ptr->exp);
655 if (z_older_than(10, 2, 2))
657 if (m_ptr->r_idx < 0)
659 m_ptr->r_idx = (0-m_ptr->r_idx);
660 m_ptr->mflag2 |= MFLAG_KAGE;
665 rd_byte(&m_ptr->mflag2);
668 if (z_older_than(10, 1, 3))
675 if (buf[0]) m_ptr->nickname = quark_add(buf);
686 * Read the monster lore
688 static void rd_lore(int r_idx)
692 monster_race *r_ptr = &r_info[r_idx];
694 /* Count sights/deaths/kills */
695 rd_s16b(&r_ptr->r_sights);
696 rd_s16b(&r_ptr->r_deaths);
697 rd_s16b(&r_ptr->r_pkills);
698 rd_s16b(&r_ptr->r_tkills);
700 /* Count wakes and ignores */
701 rd_byte(&r_ptr->r_wake);
702 rd_byte(&r_ptr->r_ignore);
705 rd_byte(&r_ptr->r_xtra1);
706 rd_byte(&r_ptr->r_xtra2);
709 rd_byte(&r_ptr->r_drop_gold);
710 rd_byte(&r_ptr->r_drop_item);
713 rd_byte(&r_ptr->r_cast_inate);
714 rd_byte(&r_ptr->r_cast_spell);
716 /* Count blows of each type */
717 rd_byte(&r_ptr->r_blows[0]);
718 rd_byte(&r_ptr->r_blows[1]);
719 rd_byte(&r_ptr->r_blows[2]);
720 rd_byte(&r_ptr->r_blows[3]);
723 rd_u32b(&r_ptr->r_flags1);
724 rd_u32b(&r_ptr->r_flags2);
725 rd_u32b(&r_ptr->r_flags3);
726 rd_u32b(&r_ptr->r_flags4);
727 rd_u32b(&r_ptr->r_flags5);
728 rd_u32b(&r_ptr->r_flags6);
730 /* Read the "Racial" monster limit per level */
731 rd_byte(&r_ptr->max_num);
738 /* Repair the lore flags */
739 r_ptr->r_flags1 &= r_ptr->flags1;
740 r_ptr->r_flags2 &= r_ptr->flags2;
741 r_ptr->r_flags3 &= r_ptr->flags3;
742 r_ptr->r_flags4 &= r_ptr->flags4;
743 r_ptr->r_flags5 &= r_ptr->flags5;
744 r_ptr->r_flags6 &= r_ptr->flags6;
751 * Add the item "o_ptr" to the inventory of the "Home"
753 * In all cases, return the slot (or -1) where the object was placed
755 * Note that this is a hacked up version of "inven_carry()".
757 * Also note that it may not correctly "adapt" to "knowledge" bacoming
758 * known, the player may have to pick stuff up and drop it again.
760 static void home_carry(store_type *st_ptr, object_type *o_ptr)
768 /* Check each existing item (try to combine) */
769 for (slot = 0; slot < st_ptr->stock_num; slot++)
771 /* Get the existing item */
772 j_ptr = &st_ptr->stock[slot];
774 /* The home acts just like the player */
775 if (object_similar(j_ptr, o_ptr))
777 /* Save the new number of items */
778 object_absorb(j_ptr, o_ptr);
786 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
790 /* Determine the "value" of the item */
791 value = object_value(o_ptr);
793 /* Check existing slots to see if we must "slide" */
794 for (slot = 0; slot < st_ptr->stock_num; slot++)
797 j_ptr = &st_ptr->stock[slot];
799 /* Hack -- readable books always come first */
800 if ((o_ptr->tval == mp_ptr->spell_book) &&
801 (j_ptr->tval != mp_ptr->spell_book)) break;
802 if ((j_ptr->tval == mp_ptr->spell_book) &&
803 (o_ptr->tval != mp_ptr->spell_book)) continue;
805 /* Objects sort by decreasing type */
806 if (o_ptr->tval > j_ptr->tval) break;
807 if (o_ptr->tval < j_ptr->tval) continue;
809 /* Can happen in the home */
810 if (!object_aware_p(o_ptr)) continue;
811 if (!object_aware_p(j_ptr)) break;
813 /* Objects sort by increasing sval */
814 if (o_ptr->sval < j_ptr->sval) break;
815 if (o_ptr->sval > j_ptr->sval) continue;
817 /* Objects in the home can be unknown */
818 if (!object_known_p(o_ptr)) continue;
819 if (!object_known_p(j_ptr)) break;
822 * Hack: otherwise identical rods sort by
823 * increasing recharge time --dsb
825 if (o_ptr->tval == TV_ROD)
827 if (o_ptr->pval < j_ptr->pval) break;
828 if (o_ptr->pval > j_ptr->pval) continue;
831 /* Objects sort by decreasing value */
832 j_value = object_value(j_ptr);
833 if (value > j_value) break;
834 if (value < j_value) continue;
837 /* Slide the others up */
838 for (i = st_ptr->stock_num; i > slot; i--)
840 st_ptr->stock[i] = st_ptr->stock[i-1];
846 /* Insert the new item */
847 st_ptr->stock[slot] = *o_ptr;
849 chg_virtue(V_SACRIFICE, -1);
851 /* Return the location */
859 static errr rd_store(int town_number, int store_number)
871 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
873 st_ptr = &town[1].store[store_number];
874 if (st_ptr->stock_num) sort = TRUE;
878 st_ptr = &town[town_number].store[store_number];
881 /* Read the basic info */
882 rd_s32b(&st_ptr->store_open);
883 rd_s16b(&st_ptr->insult_cur);
885 if (z_older_than(11, 0, 4))
894 rd_s16b(&st_ptr->good_buy);
895 rd_s16b(&st_ptr->bad_buy);
897 /* Read last visit */
898 rd_s32b(&st_ptr->last_visit);
900 /* Extract the owner (see above) */
904 for (j = 0; j < num; j++)
909 /* Get local object */
912 /* Wipe the object */
918 /* Acquire valid items */
919 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
924 home_carry(st_ptr, q_ptr);
928 k = st_ptr->stock_num++;
930 /* Acquire the item */
931 object_copy(&st_ptr->stock[k], q_ptr);
943 * Read RNG state (added in 2.8.0)
945 static void rd_randomizer(void)
955 rd_u16b(&Rand_place);
958 for (i = 0; i < RAND_DEG; i++)
960 rd_u32b(&Rand_state[i]);
970 * Read options (ignore most pre-2.8.0 options)
972 * Note that the normal options are now stored as a set of 256 bit flags,
973 * plus a set of 256 bit masks to indicate which bit flags were defined
974 * at the time the savefile was created. This will allow new options
975 * to be added, and old options to be removed, at any time, without
976 * hurting old savefiles.
978 * The window options are stored in the same way, but note that each
979 * window gets 32 options, and their order is fixed by certain defines.
981 static void rd_options(void)
995 /* Ignore old options */
1001 /* Read "delay_factor" */
1005 /* Read "hitpoint_warn" */
1010 /*** Cheating options ***/
1014 if (c & 0x0002) wizard = TRUE;
1016 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1017 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1018 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1019 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1020 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1021 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1023 rd_byte((byte *)&autosave_l);
1024 rd_byte((byte *)&autosave_t);
1025 rd_s16b(&autosave_freq);
1028 /*** Normal Options ***/
1030 /* Read the option flags */
1031 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1033 /* Read the option masks */
1034 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1036 /* Analyze the options */
1037 for (n = 0; n < 8; n++)
1039 /* Analyze the options */
1040 for (i = 0; i < 32; i++)
1042 /* Process valid flags */
1043 if (mask[n] & (1L << i))
1045 /* Process valid flags */
1046 if (option_mask[n] & (1L << i))
1049 if (flag[n] & (1L << i))
1052 option_flag[n] |= (1L << i);
1059 option_flag[n] &= ~(1L << i);
1066 if (z_older_than(10, 4, 5))
1068 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1069 else option_flag[5] |= (0x00000001 << 4);
1070 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1071 else option_flag[2] |= (0x00000001 << 5);
1072 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1073 else option_flag[4] |= (0x00000001 << 5);
1074 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1075 else option_flag[5] |= (0x00000001 << 0);
1076 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1077 else option_flag[5] |= (0x00000001 << 12);
1078 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1079 else option_flag[1] |= (0x00000001 << 0);
1080 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1081 else option_flag[1] |= (0x00000001 << 18);
1082 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1083 else option_flag[1] |= (0x00000001 << 19);
1084 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1085 else option_flag[5] |= (0x00000001 << 3);
1089 /*** Window Options ***/
1091 /* Read the window flags */
1092 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1094 /* Read the window masks */
1095 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1097 /* Analyze the options */
1098 for (n = 0; n < 8; n++)
1100 /* Analyze the options */
1101 for (i = 0; i < 32; i++)
1103 /* Process valid flags */
1104 if (mask[n] & (1L << i))
1106 /* Process valid flags */
1107 if (window_mask[n] & (1L << i))
1110 if (flag[n] & (1L << i))
1113 window_flag[n] |= (1L << i);
1120 window_flag[n] &= ~(1L << i);
1133 * Hack -- strip the "ghost" info
1135 * XXX XXX XXX This is such a nasty hack it hurts.
1137 static void rd_ghost(void)
1144 /* Strip old data */
1152 * Read the "extra" information
1154 static void rd_extra(void)
1161 rd_string(player_name, 32);
1163 rd_string(died_from, 80);
1165 for (i = 0; i < 4; i++)
1167 rd_string(history[i], 60);
1170 /* Class/Race/Seikaku/Gender/Spells */
1171 rd_byte(&p_ptr->prace);
1172 rd_byte(&p_ptr->pclass);
1173 rd_byte(&p_ptr->pseikaku);
1174 rd_byte(&p_ptr->psex);
1175 rd_byte(&p_ptr->realm1);
1176 rd_byte(&p_ptr->realm2);
1177 rd_byte(&tmp8u); /* oops */
1179 if (z_older_than(10, 4, 4))
1181 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1182 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1183 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1184 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1187 /* Special Race/Class info */
1188 rd_byte(&p_ptr->hitdie);
1189 rd_u16b(&p_ptr->expfact);
1191 /* Age/Height/Weight */
1192 rd_s16b(&p_ptr->age);
1193 rd_s16b(&p_ptr->ht);
1194 rd_s16b(&p_ptr->wt);
1196 /* Read the stat info */
1197 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1198 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1199 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1201 strip_bytes(24); /* oops */
1203 rd_s32b(&p_ptr->au);
1205 rd_s32b(&p_ptr->max_exp);
1206 rd_s32b(&p_ptr->exp);
1207 rd_u16b(&p_ptr->exp_frac);
1209 rd_s16b(&p_ptr->lev);
1211 for (i = 0; i < 64; i++) rd_s16b(&spell_exp[i]);
1212 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1214 for (i = 0; i < 64; i++) spell_exp[i] = 1600;
1216 if (z_older_than(10, 3, 6))
1217 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&weapon_exp[i][j]);
1219 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&weapon_exp[i][j]);
1220 for (i = 0; i < 10; i++) rd_s16b(&skill_exp[i]);
1221 if (z_older_than(10, 4, 1))
1223 if (p_ptr->pclass != CLASS_BEASTMASTER) skill_exp[GINOU_RIDING] /= 2;
1224 skill_exp[GINOU_RIDING] = MIN(skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1226 if (z_older_than(10, 3, 14))
1228 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1229 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1233 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1234 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1236 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1238 if (z_older_than(11, 0, 7))
1240 p_ptr->start_race = p_ptr->prace;
1241 p_ptr->old_race1 = 0L;
1242 p_ptr->old_race2 = 0L;
1243 p_ptr->old_realm = 0;
1247 rd_byte(&p_ptr->start_race);
1248 rd_s32b(&p_ptr->old_race1);
1249 rd_s32b(&p_ptr->old_race2);
1250 rd_s16b(&p_ptr->old_realm);
1253 if (z_older_than(10, 0, 1))
1255 for (i = 0; i < OLD_MAX_MANE; i++)
1262 else if (z_older_than(10, 2, 3))
1264 for (i = 0; i < OLD_MAX_MANE; i++)
1269 for (i = 0; i < MAX_MANE; i++)
1279 for (i = 0; i < MAX_MANE; i++)
1281 rd_s16b(&mane_spell[i]);
1282 rd_s16b(&mane_dam[i]);
1287 if (z_older_than(10, 0, 3))
1289 get_mon_num_prep(NULL, NULL);
1290 for (i = 0; i < MAX_KUBI; i++)
1292 monster_race *r_ptr;
1297 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1298 r_ptr = &r_info[kubi_r_idx[i]];
1300 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1302 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1304 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1306 for (j = 0; j < i; j++)
1307 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1312 for (i = 0; i < MAX_KUBI -1; i++)
1315 for (j = i; j < MAX_KUBI; j++)
1317 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1319 tmp = kubi_r_idx[i];
1320 kubi_r_idx[i] = kubi_r_idx[j];
1321 kubi_r_idx[j] = tmp;
1325 for (i = 0; i < MAX_KUBI; i++)
1327 if(!r_info[kubi_r_idx[i]].max_num)
1328 kubi_r_idx[i] += 10000;
1333 for (i = 0; i < MAX_KUBI; i++)
1335 rd_s16b(&kubi_r_idx[i]);
1339 if (z_older_than(10, 0, 3))
1345 for (i = 0; i < 4; i++)
1347 rd_s16b(&battle_mon[i]);
1348 if (z_older_than(10, 3, 4))
1351 mon_odds[i] = tmp16s;
1353 else rd_u32b(&mon_odds[i]);
1357 rd_s16b(&p_ptr->town_num);
1359 /* Read arena and rewards information */
1360 rd_s16b(&p_ptr->arena_number);
1362 p_ptr->inside_arena = (bool)tmp16s;
1363 rd_s16b(&p_ptr->inside_quest);
1364 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1368 p_ptr->inside_battle = (bool)tmp16s;
1370 rd_byte(&p_ptr->exit_bldg);
1371 rd_byte(&p_ptr->leftbldg);
1373 rd_s16b(&p_ptr->oldpx);
1374 rd_s16b(&p_ptr->oldpy);
1375 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1379 if (tmp16s > MAX_BACT)
1382 note(format("¤ÎÃæ", tmp16s));
1384 note(format("Too many (%d) building rewards!", tmp16s));
1389 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1391 rd_s16b(&p_ptr->mhp);
1392 rd_s16b(&p_ptr->chp);
1393 rd_u16b(&p_ptr->chp_frac);
1395 rd_s16b(&p_ptr->msp);
1396 rd_s16b(&p_ptr->csp);
1397 rd_u16b(&p_ptr->csp_frac);
1399 rd_s16b(&p_ptr->max_plv);
1400 if (z_older_than(10, 3, 8))
1402 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1406 byte max = (byte)max_d_idx;
1410 for(i = 0; i < max; i++)
1412 rd_s16b(&max_dlv[i]);
1413 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1417 /* Repair maximum player level XXX XXX XXX */
1418 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1422 rd_s16b(&p_ptr->sc);
1425 /* Read the flags */
1426 strip_bytes(2); /* Old "rest" */
1427 rd_s16b(&p_ptr->blind);
1428 rd_s16b(&p_ptr->paralyzed);
1429 rd_s16b(&p_ptr->confused);
1430 rd_s16b(&p_ptr->food);
1431 strip_bytes(4); /* Old "food_digested" / "protection" */
1432 rd_s16b(&p_ptr->energy);
1433 rd_s16b(&p_ptr->fast);
1434 rd_s16b(&p_ptr->slow);
1435 rd_s16b(&p_ptr->afraid);
1436 rd_s16b(&p_ptr->cut);
1437 rd_s16b(&p_ptr->stun);
1438 rd_s16b(&p_ptr->poisoned);
1439 rd_s16b(&p_ptr->image);
1440 rd_s16b(&p_ptr->protevil);
1441 rd_s16b(&p_ptr->invuln);
1442 if(z_older_than(10, 0, 0))
1445 rd_s16b(&p_ptr->ult_res);
1446 rd_s16b(&p_ptr->hero);
1447 rd_s16b(&p_ptr->shero);
1448 rd_s16b(&p_ptr->shield);
1449 rd_s16b(&p_ptr->blessed);
1450 rd_s16b(&p_ptr->tim_invis);
1451 rd_s16b(&p_ptr->word_recall);
1452 if (z_older_than(10, 3, 8))
1453 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1457 p_ptr->recall_dungeon = (byte)tmp16s;
1459 rd_s16b(&p_ptr->see_infra);
1460 rd_s16b(&p_ptr->tim_infra);
1461 rd_s16b(&p_ptr->oppose_fire);
1462 rd_s16b(&p_ptr->oppose_cold);
1463 rd_s16b(&p_ptr->oppose_acid);
1464 rd_s16b(&p_ptr->oppose_elec);
1465 rd_s16b(&p_ptr->oppose_pois);
1466 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1467 else rd_s16b(&p_ptr->tsuyoshi);
1469 /* Old savefiles do not have the following fields... */
1470 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1473 p_ptr->wraith_form = 0;
1474 p_ptr->resist_magic = 0;
1475 p_ptr->tim_regen = 0;
1476 p_ptr->kabenuke = 0;
1477 p_ptr->tim_stealth = 0;
1478 p_ptr->tim_ffall = 0;
1479 p_ptr->tim_sh_touki = 0;
1480 p_ptr->lightspeed = 0;
1481 p_ptr->tsubureru = 0;
1482 p_ptr->tim_res_nether = 0;
1483 p_ptr->tim_res_time = 0;
1484 p_ptr->mimic_form = 0;
1485 p_ptr->tim_mimic = 0;
1486 p_ptr->tim_sh_fire = 0;
1489 p_ptr->tim_reflect = 0;
1490 p_ptr->multishadow = 0;
1491 p_ptr->dustrobe = 0;
1493 p_ptr->chaos_patron = get_chaos_patron();
1501 rd_s16b(&p_ptr->tim_esp);
1502 rd_s16b(&p_ptr->wraith_form);
1503 rd_s16b(&p_ptr->resist_magic);
1504 rd_s16b(&p_ptr->tim_regen);
1505 rd_s16b(&p_ptr->kabenuke);
1506 rd_s16b(&p_ptr->tim_stealth);
1507 rd_s16b(&p_ptr->tim_ffall);
1508 rd_s16b(&p_ptr->tim_sh_touki);
1509 rd_s16b(&p_ptr->lightspeed);
1510 rd_s16b(&p_ptr->tsubureru);
1511 if (z_older_than(10, 4, 7))
1512 p_ptr->magicdef = 0;
1514 rd_s16b(&p_ptr->magicdef);
1515 rd_s16b(&p_ptr->tim_res_nether);
1516 if (z_older_than(10, 4, 11))
1518 p_ptr->tim_res_time = 0;
1519 p_ptr->mimic_form = 0;
1520 p_ptr->tim_mimic = 0;
1521 p_ptr->tim_sh_fire = 0;
1525 rd_s16b(&p_ptr->tim_res_time);
1526 rd_byte(&p_ptr->mimic_form);
1527 rd_s16b(&p_ptr->tim_mimic);
1528 rd_s16b(&p_ptr->tim_sh_fire);
1532 if ( z_older_than(11,0,3) ){
1533 p_ptr->tim_reflect=0;
1534 p_ptr->multishadow=0;
1538 rd_s16b(&p_ptr->tim_reflect);
1539 rd_s16b(&p_ptr->multishadow);
1540 rd_s16b(&p_ptr->dustrobe);
1543 rd_s16b(&p_ptr->chaos_patron);
1544 rd_u32b(&p_ptr->muta1);
1545 rd_u32b(&p_ptr->muta2);
1546 rd_u32b(&p_ptr->muta3);
1548 for (i = 0; i < 8; i++)
1549 rd_s16b(&p_ptr->virtues[i]);
1550 for (i = 0; i < 8; i++)
1551 rd_s16b(&p_ptr->vir_types[i]);
1554 /* Calc the regeneration modifier for mutations */
1555 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1557 if (z_older_than(10,0,9))
1560 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1561 p_ptr->ele_attack = 0;
1565 rd_s16b(&p_ptr->ele_attack);
1566 rd_u32b(&p_ptr->special_attack);
1568 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1569 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1570 if (z_older_than(10,0,12))
1572 p_ptr->ele_immune = 0;
1573 p_ptr->special_defense = 0;
1577 rd_s16b(&p_ptr->ele_immune);
1578 rd_u32b(&p_ptr->special_defense);
1580 rd_byte(&p_ptr->knowledge);
1581 rd_byte(&tmp8u); /* oops */
1582 rd_byte(&tmp8u); /* oops */
1583 rd_byte(&p_ptr->action);
1584 if (!z_older_than(10, 4, 3))
1587 if (tmp8u) p_ptr->action = ACTION_LEARN;
1589 rd_byte((byte *)&preserve_mode);
1590 rd_byte((byte *)&wait_report_score);
1593 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1595 /* Skip the flags */
1599 /* Hack -- the two "special seeds" */
1600 rd_u32b(&seed_flavor);
1601 rd_u32b(&seed_town);
1605 rd_u16b(&panic_save);
1606 rd_u16b(&total_winner);
1614 /* Read "feeling" */
1618 /* Turn of last "feeling" */
1624 if (z_older_than(10, 3, 12))
1626 dungeon_turn = turn;
1628 else rd_s32b(&dungeon_turn);
1630 if (z_older_than(10, 3, 13))
1634 else rd_s32b(&old_battle);
1636 if (z_older_than(10,0,3))
1638 monster_race *r_ptr;
1642 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1643 r_ptr = &r_info[today_mon];
1645 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1646 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1647 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1648 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1649 if (r_ptr->rarity > 10) continue;
1650 if (r_ptr->level == 0) continue;
1654 p_ptr->today_mon = 0;
1658 rd_s16b(&today_mon);
1659 rd_s16b(&p_ptr->today_mon);
1662 if (z_older_than(10,0,7))
1668 rd_s16b(&p_ptr->riding);
1671 if (z_older_than(10,1,2))
1680 if (z_older_than(10,3,9))
1684 else if (z_older_than(10, 3, 10))
1692 rd_s32b(&p_ptr->visit);
1694 if (!z_older_than(11, 0, 5))
1696 rd_u32b(&p_ptr->count);
1704 * Read the player inventory
1706 * Note that the inventory changed in Angband 2.7.4. Two extra
1707 * pack slots were added and the equipment was rearranged. Note
1708 * that these two features combine when parsing old save-files, in
1709 * which items from the old "aux" slot are "carried", perhaps into
1710 * one of the two new "inventory" slots.
1712 * Note that the inventory is "re-sorted" later by "dungeon()".
1714 static errr rd_inventory(void)
1722 p_ptr->total_weight = 0;
1728 /* Read until done */
1733 /* Get the next item index */
1736 /* Nope, we reached the end */
1737 if (n == 0xFFFF) break;
1739 /* Get local object */
1742 /* Wipe the object */
1748 /* Hack -- verify item */
1749 if (!q_ptr->k_idx) return (53);
1751 /* Wield equipment */
1752 if (n >= INVEN_RARM)
1755 object_copy(&inventory[n], q_ptr);
1757 /* Add the weight */
1758 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1764 /* Warning -- backpack is full */
1765 else if (inven_cnt == INVEN_PACK)
1769 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1771 note("Too many items in the inventory!");
1779 /* Carry inventory */
1786 object_copy(&inventory[n], q_ptr);
1788 /* Add the weight */
1789 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1803 * Read the saved messages
1805 static void rd_messages(void)
1815 /* Read the messages */
1816 for (i = 0; i < num; i++)
1818 /* Read the message */
1819 rd_string(buf, 128);
1821 /* Save the message */
1831 * The monsters/objects must be loaded in the same order
1832 * that they were stored, since the actual indexes matter.
1834 static errr rd_dungeon(void)
1845 /*** Basic info ***/
1848 rd_s16b(&dun_level);
1849 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1850 else rd_byte(&dungeon_type);
1852 /* Set the base level for old versions */
1853 base_level = dun_level;
1855 rd_s16b(&base_level);
1857 rd_s16b(&num_repro);
1862 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1865 rd_s16b(&max_panel_rows);
1866 rd_s16b(&max_panel_cols);
1869 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1877 /*** Run length decoding ***/
1879 /* Load the dungeon data */
1880 for (x = y = 0; y < ymax; )
1884 if (z_older_than(10,3,6))
1889 /* Apply the RLE info */
1890 for (i = count; i > 0; i--)
1892 /* Access the cave */
1893 c_ptr = &cave[y][x];
1895 /* Extract "info" */
1896 if (z_older_than(10,3,6))
1897 c_ptr->info = tmp8u;
1898 else c_ptr->info = tmp16s;
1907 if (++y >= ymax) break;
1913 /*** Run length decoding ***/
1915 /* Load the dungeon data */
1916 for (x = y = 0; y < ymax; )
1922 /* Apply the RLE info */
1923 for (i = count; i > 0; i--)
1925 /* Access the cave */
1926 c_ptr = &cave[y][x];
1928 if (c_ptr->feat == FEAT_INVIS)
1930 c_ptr->feat = FEAT_FLOOR;
1931 c_ptr->info |= CAVE_TRAP;
1934 /* Extract "feat" */
1935 c_ptr->feat = tmp8u;
1944 if (++y >= ymax) break;
1949 /*** Run length decoding ***/
1951 /* Load the dungeon data */
1952 for (x = y = 0; y < ymax; )
1958 /* Apply the RLE info */
1959 for (i = count; i > 0; i--)
1961 /* Access the cave */
1962 c_ptr = &cave[y][x];
1964 /* Extract "feat" */
1965 c_ptr->mimic = tmp8u;
1974 if (++y >= ymax) break;
1979 /*** Run length decoding ***/
1981 /* Load the dungeon data */
1982 for (x = y = 0; y < ymax; )
1988 /* Apply the RLE info */
1989 for (i = count; i > 0; i--)
1991 /* Access the cave */
1992 c_ptr = &cave[y][x];
1994 /* Extract "feat" */
1995 c_ptr->special = tmp16s;
2004 if (++y >= ymax) break;
2011 /* Read the item count */
2014 /* Verify maximum */
2015 if (limit >= max_o_idx)
2018 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2020 note(format("Too many (%d) object entries!", limit));
2026 /* Read the dungeon items */
2027 for (i = 1; i < limit; i++)
2034 /* Get a new record */
2041 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2043 note(format("Object allocation error (%d <> %d)", i, o_idx));
2051 o_ptr = &o_list[o_idx];
2057 /* XXX XXX XXX XXX XXX */
2060 if (o_ptr->held_m_idx)
2062 monster_type *m_ptr;
2065 m_ptr = &m_list[o_ptr->held_m_idx];
2068 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2070 /* Place the object */
2071 m_ptr->hold_o_idx = o_idx;
2077 /* Access the item location */
2078 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2081 o_ptr->next_o_idx = c_ptr->o_idx;
2083 /* Place the object */
2084 c_ptr->o_idx = o_idx;
2091 /* Read the monster count */
2094 /* Hack -- verify */
2095 if (limit >= max_m_idx)
2098 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2100 note(format("Too many (%d) monster entries!", limit));
2106 /* Read the monsters */
2107 for (i = 1; i < limit; i++)
2111 monster_type *m_ptr;
2113 monster_race *r_ptr;
2116 /* Get a new record */
2123 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2125 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2132 /* Acquire monster */
2133 m_ptr = &m_list[m_idx];
2135 /* Read the monster */
2140 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2142 /* Mark the location */
2143 c_ptr->m_idx = m_idx;
2147 r_ptr = &r_info[m_ptr->r_idx];
2149 /* Count XXX XXX XXX */
2155 /* The dungeon is ready */
2156 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2157 character_dungeon = FALSE;
2159 character_dungeon = TRUE;
2168 * Actually read the savefile
2170 static errr rd_savefile_new_aux(void)
2182 #ifdef VERIFY_CHECKSUMS
2183 u32b n_x_check, n_v_check;
2184 u32b o_x_check, o_v_check;
2188 /* Mention the savefile version */
2190 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2192 note(format("Loading a %d.%d.%d savefile...",
2195 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2198 /* Strip the version bytes */
2201 /* Hack -- decrypt */
2202 xor_byte = sf_extra;
2205 /* Clear the checksums */
2209 #if SAVEFILE_VERSION
2210 /* Read the version number of the savefile */
2211 rd_u32b(&sf_version);
2212 #endif /* SAVEFILE_VERSION */
2214 /* Operating system info */
2217 /* Time of savefile creation */
2220 /* Number of resurrections */
2223 /* Number of times played */
2227 /* Later use (always zero) */
2230 /* Later use (always zero) */
2234 /* Read RNG state */
2237 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2239 if (arg_fiddle) note("Loaded Randomizer Info");
2244 /* Then the options */
2247 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2249 if (arg_fiddle) note("Loaded Option Flags");
2253 * Munchkin players are marked
2255 * XXX - should be replaced with a better method,
2256 * after the new scorefile-handling is implemented.
2264 /* Then the "messages" */
2267 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2269 if (arg_fiddle) note("Loaded Messages");
2274 for (i = 0; i < max_r_idx; i++)
2276 monster_race *r_ptr;
2277 /* Access that monster */
2280 /* Hack -- Reset the death counter */
2281 r_ptr->max_num = 100;
2282 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2283 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2286 /* Monster Memory */
2289 /* Incompatible save files */
2290 if (tmp16u > max_r_idx)
2293 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2295 note(format("Too many (%u) monster races!", tmp16u));
2301 /* Read the available records */
2302 for (i = 0; i < tmp16u; i++)
2304 monster_race *r_ptr;
2309 /* Access that monster */
2314 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2316 if (arg_fiddle) note("Loaded Monster Memory");
2324 /* Incompatible save files */
2325 if (tmp16u > max_k_idx)
2328 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2330 note(format("Too many (%u) object kinds!", tmp16u));
2336 /* Read the object memory */
2337 for (i = 0; i < tmp16u; i++)
2340 object_kind *k_ptr = &k_info[i];
2344 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2345 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2348 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2350 if (arg_fiddle) note("Loaded Object Memory");
2356 * Initialize arena and rewards information
2358 p_ptr->arena_number = 0;
2359 p_ptr->inside_arena = 0;
2360 p_ptr->inside_quest = 0;
2361 p_ptr->leftbldg = FALSE;
2362 p_ptr->exit_bldg = TRUE;
2364 /* Start in town 1 */
2365 p_ptr->town_num = 1;
2367 p_ptr->wilderness_x = 4;
2368 p_ptr->wilderness_y = 4;
2372 /* Init the wilderness seeds */
2373 for (i = 0; i < max_wild_x; i++)
2375 for (j = 0; j < max_wild_y; j++)
2377 wilderness[j][i].seed = rand_int(0x10000000);
2381 /* 2.1.3 or newer version */
2383 u16b max_towns_load;
2384 u16b max_quests_load;
2385 byte max_rquests_load;
2386 s16b old_inside_quest = p_ptr->inside_quest;
2388 /* Number of towns */
2389 rd_u16b(&max_towns_load);
2391 /* Incompatible save files */
2392 if (max_towns_load > max_towns)
2395 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2397 note(format("Too many (%u) towns!", max_towns_load));
2403 /* Number of quests */
2404 rd_u16b(&max_quests_load);
2406 if (z_older_than(11, 0, 7))
2408 max_rquests_load = 10;
2412 rd_byte(&max_rquests_load);
2415 /* Incompatible save files */
2416 if (max_quests_load > max_quests)
2419 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2421 note(format("Too many (%u) quests!", max_quests_load));
2427 for (i = 0; i < max_quests_load; i++)
2431 rd_s16b(&quest[i].status);
2432 rd_s16b(&quest[i].level);
2434 if (z_older_than(11, 0, 6))
2436 quest[i].complev = 0;
2440 rd_byte(&quest[i].complev);
2443 /* Load quest status if quest is running */
2444 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))))
2446 rd_s16b(&quest[i].cur_num);
2447 rd_s16b(&quest[i].max_num);
2448 rd_s16b(&quest[i].type);
2450 /* Load quest monster index */
2451 rd_s16b(&quest[i].r_idx);
2453 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2458 monster_race *r_ptr;
2461 * Random monster 5 - 10 levels out of depth
2462 * (depending on level)
2464 r_idx = get_mon_num(quest[i].level + 5 + randint(quest[i].level / 10));
2465 r_ptr = &r_info[r_idx];
2467 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2469 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2471 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2473 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2475 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2478 * Accept monsters that are 2 - 6 levels
2479 * out of depth depending on the quest level
2481 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2484 quest[i].r_idx = r_idx;
2487 /* Load quest item index */
2488 rd_s16b(&quest[i].k_idx);
2491 a_info[quest[i].k_idx].flags3 |= TR3_QUESTITEM;
2493 rd_byte(&quest[i].flags);
2495 if (z_older_than(10, 3, 11))
2497 if (quest[i].flags & QUEST_FLAG_PRESET)
2499 quest[i].dungeon = 0;
2503 init_flags = INIT_ASSIGN;
2504 p_ptr->inside_quest = i;
2506 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2507 p_ptr->inside_quest = old_inside_quest;
2512 rd_byte(&quest[i].dungeon);
2515 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2516 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2517 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2520 /* Ignore the empty quests from old versions */
2523 /* Ignore quest status */
2526 /* Ignore quest level */
2530 * We don't have to care about the other info,
2531 * since status should be 0 for these quests anyway
2536 /* Position in the wilderness */
2537 rd_s32b(&p_ptr->wilderness_x);
2538 rd_s32b(&p_ptr->wilderness_y);
2539 if (z_older_than(10, 3, 13))
2541 p_ptr->wilderness_x = 5;
2542 p_ptr->wilderness_y = 48;
2545 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2546 else rd_byte((byte *)&p_ptr->wild_mode);
2547 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2548 else rd_byte((byte *)&ambush_flag);
2550 /* Size of the wilderness */
2551 rd_s32b(&wild_x_size);
2552 rd_s32b(&wild_y_size);
2554 /* Incompatible save files */
2555 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2558 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2560 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2566 /* Load the wilderness seeds */
2567 for (i = 0; i < wild_x_size; i++)
2569 for (j = 0; j < wild_y_size; j++)
2571 rd_u32b(&wilderness[j][i].seed);
2577 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2579 if (arg_fiddle) note("Loaded Quests");
2582 /* Load the Artifacts */
2585 /* Incompatible save files */
2586 if (tmp16u > max_a_idx)
2589 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2591 note(format("Too many (%u) artifacts!", tmp16u));
2597 /* Read the artifact flags */
2598 for (i = 0; i < tmp16u; i++)
2601 a_info[i].cur_num = tmp8u;
2607 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2609 if (arg_fiddle) note("Loaded Artifacts");
2614 /* Read the extra stuff */
2616 if (p_ptr->energy > 999) world_player = TRUE;
2618 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2620 if (arg_fiddle) note("Loaded extra information");
2624 /* Read the player_hp array */
2627 /* Incompatible save files */
2628 if (tmp16u > PY_MAX_LEVEL)
2631 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2633 note(format("Too many (%u) hitpoint entries!", tmp16u));
2639 /* Read the player_hp array */
2640 for (i = 0; i < tmp16u; i++)
2642 rd_s16b(&player_hp[i]);
2645 /* Important -- Initialize the sex */
2646 sp_ptr = &sex_info[p_ptr->psex];
2648 /* Important -- Initialize the race/class */
2649 rp_ptr = &race_info[p_ptr->prace];
2650 cp_ptr = &class_info[p_ptr->pclass];
2651 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2653 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !death)
2655 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2656 do_cmd_rerate(FALSE);
2658 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !death)
2660 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2661 do_cmd_rerate(FALSE);
2663 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !death)
2665 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2666 do_cmd_rerate(FALSE);
2668 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !death)
2670 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2671 do_cmd_rerate(FALSE);
2674 /* Important -- Initialize the magic */
2675 mp_ptr = &m_info[p_ptr->pclass];
2678 /* Read spell info */
2679 rd_u32b(&spell_learned1);
2680 rd_u32b(&spell_learned2);
2681 rd_u32b(&spell_worked1);
2682 rd_u32b(&spell_worked2);
2683 rd_u32b(&spell_forgotten1);
2684 rd_u32b(&spell_forgotten2);
2686 if (z_older_than(10,0,5))
2688 p_ptr->learned_spells = 0;
2689 for (i = 0; i < 64; i++)
2691 /* Count known spells */
2693 (spell_learned1 & (1L << i)) :
2694 (spell_learned2 & (1L << (i - 32))))
2696 p_ptr->learned_spells++;
2700 else rd_s16b(&p_ptr->learned_spells);
2702 if (z_older_than(10,0,6))
2704 p_ptr->add_spells = 0;
2706 else rd_s16b(&p_ptr->add_spells);
2707 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2709 for (i = 0; i < 64; i++)
2711 rd_byte(&spell_order[i]);
2715 /* Read the inventory */
2719 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2721 note("Unable to read inventory");
2727 /* Read number of towns */
2729 town_count = tmp16u;
2731 /* Read the stores */
2733 for (i = 1; i < town_count; i++)
2735 for (j = 0; j < tmp16u; j++)
2737 if (rd_store(i, j)) return (22);
2741 rd_s16b(&p_ptr->pet_follow_distance);
2742 if (z_older_than(10, 4, 10))
2744 p_ptr->pet_extra_flags = 0;
2746 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2748 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2750 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2754 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2757 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2761 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2764 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2768 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2771 if (!z_older_than(10,0,8))
2774 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2779 rd_s16b(&p_ptr->pet_extra_flags);
2782 if (!z_older_than(11, 0, 9))
2784 char buf[SCREEN_BUF_SIZE];
2785 rd_string(buf, SCREEN_BUF_SIZE);
2786 if (buf[0]) screen_dump = string_make(buf);
2791 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2793 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2798 /* I'm not dead yet... */
2801 /* Dead players have no dungeon */
2803 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2805 note("Restoring Dungeon...");
2811 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2813 note("Error reading dungeon data");
2819 /* Read the ghost info */
2826 strip_bytes(tmp32s);
2831 #ifdef VERIFY_CHECKSUMS
2833 /* Save the checksum */
2834 n_v_check = v_check;
2836 /* Read the old checksum */
2837 rd_u32b(&o_v_check);
2840 if (o_v_check != n_v_check)
2843 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2845 note("Invalid checksum");
2852 /* Save the encoded checksum */
2853 n_x_check = x_check;
2855 /* Read the checksum */
2856 rd_u32b(&o_x_check);
2860 if (o_x_check != n_x_check)
2863 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2865 note("Invalid encoded checksum");
2879 * Actually read the savefile
2881 errr rd_savefile_new(void)
2885 /* The savefile is a binary file */
2886 fff = my_fopen(savefile, "rb");
2889 if (!fff) return (-1);
2891 /* Call the sub-function */
2892 err = rd_savefile_new_aux();
2894 /* Check for errors */
2895 if (ferror(fff)) err = -1;
2897 /* Close the file */