3 /* Purpose: support for loading savefiles -BEN- */
9 * This file loads savefiles from Angband 2.7.X and 2.8.X
11 * Ancient savefiles (pre-2.7.0) are loaded by another file.
13 * Note that Angband 2.7.0 through 2.7.3 are now officially obsolete,
14 * and savefiles from those versions may not be successfully converted.
16 * We attempt to prevent corrupt savefiles from inducing memory errors.
18 * Note that this file should not use the random number generator, the
19 * object flavors, the visual attr/char mappings, or anything else which
20 * is initialized *after* or *during* the "load character" function.
22 * This file assumes that the monster/object records are initialized
23 * to zero, and the race/kind tables have been loaded correctly. The
24 * order of object stacks is currently not saved in the savefiles, but
25 * the "next" pointers are saved, so all necessary knowledge is present.
27 * We should implement simple "savefile extenders" using some form of
28 * "sized" chunks of bytes, with a {size,type,data} format, so everyone
29 * can know the size, interested people can know the type, and the actual
30 * data is available to the parsing routines that acknowledge the type.
32 * Consider changing the "globe of invulnerability" code so that it
33 * takes some form of "maximum damage to protect from" in addition to
34 * the existing "number of turns to protect for", and where each hit
35 * by a monster will reduce the shield by that amount.
43 * Maximum number of tries for selection of a proper quest monster
49 * Local "savefile" pointer
54 * Hack -- old "encryption" byte
59 * Hack -- simple "checksum" on the actual values
61 static u32b v_check = 0L;
64 * Hack -- simple "checksum" on the encoded bytes
66 static u32b x_check = 0L;
71 * This function determines if the version of the savefile
72 * currently being read is older than version "major.minor.patch.extra".
74 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
76 /* Much older, or much more recent */
77 if (h_ver_major < major) return (TRUE);
78 if (h_ver_major > major) return (FALSE);
80 /* Distinctly older, or distinctly more recent */
81 if (h_ver_minor < minor) return (TRUE);
82 if (h_ver_minor > minor) return (FALSE);
84 /* Barely older, or barely more recent */
85 if (h_ver_patch < patch) return (TRUE);
86 if (h_ver_patch > patch) return (FALSE);
88 /* Barely older, or barely more recent */
89 if (h_ver_extra < extra) return (TRUE);
90 if (h_ver_extra > extra) return (FALSE);
92 /* Identical versions */
98 * The above function, adapted for Zangband
100 static bool z_older_than(byte x, byte y, byte z)
102 /* Much older, or much more recent */
103 if (z_major < x) return (TRUE);
104 if (z_major > x) return (FALSE);
106 /* Distinctly older, or distinctly more recent */
107 if (z_minor < y) return (TRUE);
108 if (z_minor > y) return (FALSE);
110 /* Barely older, or barely more recent */
111 if (z_patch < z) return (TRUE);
112 if (z_patch > z) return (FALSE);
114 /* Identical versions */
120 * Hack -- Show information on the screen, one line at a time.
122 * Avoid the top two lines, to avoid interference with "msg_print()".
124 static void note(cptr msg)
128 /* Draw the message */
131 /* Advance one line (wrap if needed) */
132 if (++y >= 24) y = 2;
140 * The following functions are used to load the basic building blocks
141 * of savefiles. They also maintain the "checksum" info for 2.7.0+
144 static byte sf_get(void)
148 /* Get a character, decode the value */
149 c = getc(fff) & 0xFF;
153 /* Maintain the checksum info */
157 /* Return the value */
161 static void rd_byte(byte *ip)
166 static void rd_u16b(u16b *ip)
169 (*ip) |= ((u16b)(sf_get()) << 8);
172 static void rd_s16b(s16b *ip)
177 static void rd_u32b(u32b *ip)
180 (*ip) |= ((u32b)(sf_get()) << 8);
181 (*ip) |= ((u32b)(sf_get()) << 16);
182 (*ip) |= ((u32b)(sf_get()) << 24);
185 static void rd_s32b(s32b *ip)
192 * Hack -- read a string
194 static void rd_string(char *str, int max)
198 /* Read the string */
199 for (i = 0; TRUE; i++)
206 /* Collect string while legal */
207 if (i < max) str[i] = tmp8u;
222 * Hack -- strip some bytes
224 static void strip_bytes(int n)
228 /* Strip the bytes */
229 while (n--) rd_byte(&tmp8u);
232 #define OLD_MAX_MANE 22
237 * This function attempts to "repair" old savefiles, and to extract
238 * the most up to date values for various object fields.
240 * Note that Angband 2.7.9 introduced a new method for object "flags"
241 * in which the "flags" on an object are actually extracted when they
242 * are needed from the object kind, artifact index, ego-item index,
243 * and two special "xtra" fields which are used to encode any "extra"
244 * power of certain ego-items. This had the side effect that items
245 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
246 * may have had, and also, all "uncursed" items will become "cursed"
247 * again, including Calris, even if it is being worn at the time. As
248 * a complete hack, items which are inscribed with "uncursed" will be
249 * "uncursed" when imported from pre-2.7.9 savefiles.
251 static void rd_item(object_type *o_ptr)
257 rd_s16b(&o_ptr->k_idx);
264 rd_byte(&o_ptr->tval);
265 rd_byte(&o_ptr->sval);
267 if (z_older_than(10, 4, 4))
269 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
270 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
271 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
275 rd_s16b(&o_ptr->pval);
277 rd_byte(&o_ptr->discount);
278 rd_byte(&o_ptr->number);
279 rd_s16b(&o_ptr->weight);
281 rd_byte(&o_ptr->name1);
282 rd_byte(&o_ptr->name2);
283 rd_s16b(&o_ptr->timeout);
285 rd_s16b(&o_ptr->to_h);
286 rd_s16b(&o_ptr->to_d);
287 rd_s16b(&o_ptr->to_a);
294 rd_byte(&o_ptr->ident);
296 rd_byte(&o_ptr->marked);
299 rd_u32b(&o_ptr->art_flags[0]);
300 rd_u32b(&o_ptr->art_flags[1]);
301 rd_u32b(&o_ptr->art_flags[2]);
302 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
303 else rd_u32b(&o_ptr->art_flags[3]);
305 if (z_older_than(11, 0, 11))
307 o_ptr->curse_flags = 0L;
308 if (o_ptr->ident & 0x40)
310 o_ptr->curse_flags |= TRC_CURSED;
311 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
312 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
315 artifact_type *a_ptr = &a_info[o_ptr->name1];
316 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
317 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
319 else if (o_ptr->name2)
321 ego_item_type *e_ptr = &e_info[o_ptr->name2];
322 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
323 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
326 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
330 rd_u32b(&o_ptr->curse_flags);
333 /* Monster holding object */
334 rd_s16b(&o_ptr->held_m_idx);
337 rd_byte(&o_ptr->xtra1);
338 rd_byte(&o_ptr->xtra2);
340 if (z_older_than(11, 0, 10))
342 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
344 switch (o_ptr->xtra2 % 6)
346 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
347 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
348 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
349 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
350 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
351 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
355 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
357 switch (o_ptr->xtra2 % 11)
359 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
360 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
361 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
362 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
363 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
364 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
365 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
366 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
367 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
368 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
369 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
373 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
375 switch (o_ptr->xtra2 % 8)
377 case 0: add_flag(o_ptr->art_flags, TR_FEATHER); break;
378 case 1: add_flag(o_ptr->art_flags, TR_LITE); break;
379 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
380 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
381 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
382 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
383 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
384 case 7: add_flag(o_ptr->art_flags, TR_HOLD_LIFE); break;
391 if (z_older_than(10, 2, 3))
396 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
398 o_ptr->xtra3 = o_ptr->xtra1;
401 if (o_ptr->tval == TV_CAPTURE)
403 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
404 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
406 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
407 if (ironman_nightmare)
409 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
411 o_ptr->xtra4 = o_ptr->xtra5;
416 rd_byte(&o_ptr->xtra3);
417 if (h_older_than(1, 3, 0, 1))
419 if (o_ptr->tval > TV_CAPTURE && o_ptr->xtra3 >= 1+96)
420 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
423 rd_s16b(&o_ptr->xtra4);
424 rd_s16b(&o_ptr->xtra5);
427 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)))
429 o_ptr->xtra4 = o_ptr->pval;
433 rd_byte(&o_ptr->feeling);
438 /* Save the inscription */
439 if (buf[0]) o_ptr->inscription = quark_add(buf);
442 if (buf[0]) o_ptr->art_name = quark_add(buf);
444 /* The Python object */
452 /* Mega-Hack -- handle "dungeon objects" later */
453 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
455 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
457 if (z_older_than(10, 4, 9))
459 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
461 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
462 add_flag(o_ptr->art_flags, TR_DEC_MANA);
469 artifact_type *a_ptr;
471 /* Obtain the artifact info */
472 a_ptr = &a_info[o_ptr->name1];
474 /* Verify that artifact */
475 if (!a_ptr->name) o_ptr->name1 = 0;
481 ego_item_type *e_ptr;
483 /* Obtain the ego-item info */
484 e_ptr = &e_info[o_ptr->name2];
486 /* Verify that ego-item */
487 if (!e_ptr->name) o_ptr->name2 = 0;
498 static void rd_monster(monster_type *m_ptr)
503 /* Read the monster race */
504 rd_s16b(&m_ptr->r_idx);
506 if (z_older_than(11, 0, 12))
507 m_ptr->ap_r_idx = m_ptr->r_idx;
509 rd_s16b(&m_ptr->ap_r_idx);
511 if (z_older_than(11, 0, 14))
513 monster_race *r_ptr = &r_info[m_ptr->r_idx];
515 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
516 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
517 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
520 rd_byte(&m_ptr->sub_align);
522 /* Read the other information */
526 rd_s16b(&m_ptr->maxhp);
527 if (z_older_than(11, 0, 5))
529 m_ptr->max_maxhp = m_ptr->maxhp;
533 rd_s16b(&m_ptr->max_maxhp);
535 rd_s16b(&m_ptr->csleep);
536 rd_byte(&m_ptr->mspeed);
537 if (z_older_than(10, 4, 2))
540 m_ptr->energy_need = (s16b)tmp8u;
542 else rd_s16b(&m_ptr->energy_need);
544 if (z_older_than(11, 0, 13))
545 m_ptr->energy_need = 100 - m_ptr->energy_need;
547 if (z_older_than(10,0,7))
554 rd_byte(&m_ptr->fast);
555 rd_byte(&m_ptr->slow);
557 rd_byte(&m_ptr->stunned);
558 rd_byte(&m_ptr->confused);
559 rd_byte(&m_ptr->monfear);
561 if (z_older_than(10,0,10))
565 else if (z_older_than(10,0,11))
573 rd_s16b(&m_ptr->target_y);
574 rd_s16b(&m_ptr->target_x);
577 rd_byte(&m_ptr->invulner);
579 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
580 rd_u32b(&m_ptr->smart);
584 if (z_older_than(10, 4, 5))
587 rd_u32b(&m_ptr->exp);
589 if (z_older_than(10, 2, 2))
591 if (m_ptr->r_idx < 0)
593 m_ptr->r_idx = (0-m_ptr->r_idx);
594 m_ptr->mflag2 |= MFLAG_KAGE;
599 rd_byte(&m_ptr->mflag2);
602 if (z_older_than(11, 0, 12))
604 if (m_ptr->mflag2 & MFLAG_KAGE)
605 m_ptr->ap_r_idx = MON_KAGE;
608 if (z_older_than(10, 1, 3))
615 if (buf[0]) m_ptr->nickname = quark_add(buf);
626 * Read the monster lore
628 static void rd_lore(int r_idx)
632 monster_race *r_ptr = &r_info[r_idx];
634 /* Count sights/deaths/kills */
635 rd_s16b(&r_ptr->r_sights);
636 rd_s16b(&r_ptr->r_deaths);
637 rd_s16b(&r_ptr->r_pkills);
638 rd_s16b(&r_ptr->r_tkills);
640 /* Count wakes and ignores */
641 rd_byte(&r_ptr->r_wake);
642 rd_byte(&r_ptr->r_ignore);
645 rd_byte(&r_ptr->r_xtra1);
646 rd_byte(&r_ptr->r_xtra2);
649 rd_byte(&r_ptr->r_drop_gold);
650 rd_byte(&r_ptr->r_drop_item);
653 rd_byte(&r_ptr->r_cast_inate);
654 rd_byte(&r_ptr->r_cast_spell);
656 /* Count blows of each type */
657 rd_byte(&r_ptr->r_blows[0]);
658 rd_byte(&r_ptr->r_blows[1]);
659 rd_byte(&r_ptr->r_blows[2]);
660 rd_byte(&r_ptr->r_blows[3]);
663 rd_u32b(&r_ptr->r_flags1);
664 rd_u32b(&r_ptr->r_flags2);
665 rd_u32b(&r_ptr->r_flags3);
666 rd_u32b(&r_ptr->r_flags4);
667 rd_u32b(&r_ptr->r_flags5);
668 rd_u32b(&r_ptr->r_flags6);
670 /* Read the "Racial" monster limit per level */
671 rd_byte(&r_ptr->max_num);
678 /* Repair the lore flags */
679 r_ptr->r_flags1 &= r_ptr->flags1;
680 r_ptr->r_flags2 &= r_ptr->flags2;
681 r_ptr->r_flags3 &= r_ptr->flags3;
682 r_ptr->r_flags4 &= r_ptr->flags4;
683 r_ptr->r_flags5 &= r_ptr->flags5;
684 r_ptr->r_flags6 &= r_ptr->flags6;
691 * Add the item "o_ptr" to the inventory of the "Home"
693 * In all cases, return the slot (or -1) where the object was placed
695 * Note that this is a hacked up version of "inven_carry()".
697 * Also note that it may not correctly "adapt" to "knowledge" bacoming
698 * known, the player may have to pick stuff up and drop it again.
700 static void home_carry(store_type *st_ptr, object_type *o_ptr)
708 /* Check each existing item (try to combine) */
709 for (slot = 0; slot < st_ptr->stock_num; slot++)
711 /* Get the existing item */
712 j_ptr = &st_ptr->stock[slot];
714 /* The home acts just like the player */
715 if (object_similar(j_ptr, o_ptr))
717 /* Save the new number of items */
718 object_absorb(j_ptr, o_ptr);
726 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
730 /* Determine the "value" of the item */
731 value = object_value(o_ptr);
733 /* Check existing slots to see if we must "slide" */
734 for (slot = 0; slot < st_ptr->stock_num; slot++)
737 j_ptr = &st_ptr->stock[slot];
739 /* Hack -- readable books always come first */
740 if ((o_ptr->tval == mp_ptr->spell_book) &&
741 (j_ptr->tval != mp_ptr->spell_book)) break;
742 if ((j_ptr->tval == mp_ptr->spell_book) &&
743 (o_ptr->tval != mp_ptr->spell_book)) continue;
745 /* Objects sort by decreasing type */
746 if (o_ptr->tval > j_ptr->tval) break;
747 if (o_ptr->tval < j_ptr->tval) continue;
749 /* Can happen in the home */
750 if (!object_aware_p(o_ptr)) continue;
751 if (!object_aware_p(j_ptr)) break;
753 /* Objects sort by increasing sval */
754 if (o_ptr->sval < j_ptr->sval) break;
755 if (o_ptr->sval > j_ptr->sval) continue;
757 /* Objects in the home can be unknown */
758 if (!object_known_p(o_ptr)) continue;
759 if (!object_known_p(j_ptr)) break;
762 * Hack: otherwise identical rods sort by
763 * increasing recharge time --dsb
765 if (o_ptr->tval == TV_ROD)
767 if (o_ptr->pval < j_ptr->pval) break;
768 if (o_ptr->pval > j_ptr->pval) continue;
771 /* Objects sort by decreasing value */
772 j_value = object_value(j_ptr);
773 if (value > j_value) break;
774 if (value < j_value) continue;
777 /* Slide the others up */
778 for (i = st_ptr->stock_num; i > slot; i--)
780 st_ptr->stock[i] = st_ptr->stock[i-1];
786 /* Insert the new item */
787 st_ptr->stock[slot] = *o_ptr;
789 chg_virtue(V_SACRIFICE, -1);
791 /* Return the location */
799 static errr rd_store(int town_number, int store_number)
811 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
813 st_ptr = &town[1].store[store_number];
814 if (st_ptr->stock_num) sort = TRUE;
818 st_ptr = &town[town_number].store[store_number];
821 /* Read the basic info */
822 rd_s32b(&st_ptr->store_open);
823 rd_s16b(&st_ptr->insult_cur);
825 if (z_older_than(11, 0, 4))
834 rd_s16b(&st_ptr->good_buy);
835 rd_s16b(&st_ptr->bad_buy);
837 /* Read last visit */
838 rd_s32b(&st_ptr->last_visit);
840 /* Extract the owner (see above) */
844 for (j = 0; j < num; j++)
849 /* Get local object */
852 /* Wipe the object */
858 /* Acquire valid items */
859 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
864 home_carry(st_ptr, q_ptr);
868 k = st_ptr->stock_num++;
870 /* Acquire the item */
871 object_copy(&st_ptr->stock[k], q_ptr);
883 * Read RNG state (added in 2.8.0)
885 static void rd_randomizer(void)
895 rd_u16b(&Rand_place);
898 for (i = 0; i < RAND_DEG; i++)
900 rd_u32b(&Rand_state[i]);
910 * Read options (ignore most pre-2.8.0 options)
912 * Note that the normal options are now stored as a set of 256 bit flags,
913 * plus a set of 256 bit masks to indicate which bit flags were defined
914 * at the time the savefile was created. This will allow new options
915 * to be added, and old options to be removed, at any time, without
916 * hurting old savefiles.
918 * The window options are stored in the same way, but note that each
919 * window gets 32 options, and their order is fixed by certain defines.
921 static void rd_options(void)
935 /* Ignore old options */
941 /* Read "delay_factor" */
945 /* Read "hitpoint_warn" */
950 /*** Cheating options ***/
954 if (c & 0x0002) p_ptr->wizard = TRUE;
956 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
957 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
958 cheat_room = (c & 0x0400) ? TRUE : FALSE;
959 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
960 cheat_know = (c & 0x1000) ? TRUE : FALSE;
961 cheat_live = (c & 0x2000) ? TRUE : FALSE;
963 rd_byte((byte *)&autosave_l);
964 rd_byte((byte *)&autosave_t);
965 rd_s16b(&autosave_freq);
968 /*** Normal Options ***/
970 /* Read the option flags */
971 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
973 /* Read the option masks */
974 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
976 /* Analyze the options */
977 for (n = 0; n < 8; n++)
979 /* Analyze the options */
980 for (i = 0; i < 32; i++)
982 /* Process valid flags */
983 if (mask[n] & (1L << i))
985 /* Process valid flags */
986 if (option_mask[n] & (1L << i))
989 if (flag[n] & (1L << i))
992 option_flag[n] |= (1L << i);
999 option_flag[n] &= ~(1L << i);
1006 if (z_older_than(10, 4, 5))
1008 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1009 else option_flag[5] |= (0x00000001 << 4);
1010 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1011 else option_flag[2] |= (0x00000001 << 5);
1012 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1013 else option_flag[4] |= (0x00000001 << 5);
1014 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1015 else option_flag[5] |= (0x00000001 << 0);
1016 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1017 else option_flag[5] |= (0x00000001 << 12);
1018 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1019 else option_flag[1] |= (0x00000001 << 0);
1020 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1021 else option_flag[1] |= (0x00000001 << 18);
1022 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1023 else option_flag[1] |= (0x00000001 << 19);
1024 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1025 else option_flag[5] |= (0x00000001 << 3);
1029 /*** Window Options ***/
1031 /* Read the window flags */
1032 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1034 /* Read the window masks */
1035 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1037 /* Analyze the options */
1038 for (n = 0; n < 8; n++)
1040 /* Analyze the options */
1041 for (i = 0; i < 32; i++)
1043 /* Process valid flags */
1044 if (mask[n] & (1L << i))
1046 /* Process valid flags */
1047 if (window_mask[n] & (1L << i))
1050 if (flag[n] & (1L << i))
1053 window_flag[n] |= (1L << i);
1060 window_flag[n] &= ~(1L << i);
1073 * Hack -- strip the "ghost" info
1075 * XXX XXX XXX This is such a nasty hack it hurts.
1077 static void rd_ghost(void)
1084 /* Strip old data */
1090 * Save quick start data
1092 static void load_quick_start(void)
1097 if (z_older_than(11, 0, 13))
1099 previous_char.quick_ok = FALSE;
1103 rd_byte(&previous_char.psex);
1104 rd_byte(&previous_char.prace);
1105 rd_byte(&previous_char.pclass);
1106 rd_byte(&previous_char.pseikaku);
1107 rd_byte(&previous_char.realm1);
1108 rd_byte(&previous_char.realm2);
1110 rd_s16b(&previous_char.age);
1111 rd_s16b(&previous_char.ht);
1112 rd_s16b(&previous_char.wt);
1113 rd_s16b(&previous_char.sc);
1114 rd_s32b(&previous_char.au);
1116 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1117 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1119 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1121 rd_s16b(&previous_char.chaos_patron);
1123 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1125 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], 60);
1127 rd_byte(&previous_char.quests);
1130 previous_char.quick_ok = (bool)tmp8u;
1134 * Read the "extra" information
1136 static void rd_extra(void)
1143 rd_string(player_name, 32);
1145 rd_string(p_ptr->died_from, 80);
1149 for (i = 0; i < 4; i++)
1151 rd_string(p_ptr->history[i], 60);
1154 /* Class/Race/Seikaku/Gender/Spells */
1155 rd_byte(&p_ptr->prace);
1156 rd_byte(&p_ptr->pclass);
1157 rd_byte(&p_ptr->pseikaku);
1158 rd_byte(&p_ptr->psex);
1159 rd_byte(&p_ptr->realm1);
1160 rd_byte(&p_ptr->realm2);
1161 rd_byte(&tmp8u); /* oops */
1163 if (z_older_than(10, 4, 4))
1165 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1166 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1167 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1168 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1171 /* Special Race/Class info */
1172 rd_byte(&p_ptr->hitdie);
1173 rd_u16b(&p_ptr->expfact);
1175 /* Age/Height/Weight */
1176 rd_s16b(&p_ptr->age);
1177 rd_s16b(&p_ptr->ht);
1178 rd_s16b(&p_ptr->wt);
1180 /* Read the stat info */
1181 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1182 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1183 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1185 strip_bytes(24); /* oops */
1187 rd_s32b(&p_ptr->au);
1189 rd_s32b(&p_ptr->max_exp);
1190 rd_s32b(&p_ptr->exp);
1191 rd_u16b(&p_ptr->exp_frac);
1193 rd_s16b(&p_ptr->lev);
1195 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1196 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1198 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = 1600;
1200 if (z_older_than(10, 3, 6))
1201 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1203 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1204 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1205 if (z_older_than(10, 4, 1))
1207 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1208 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1210 if (z_older_than(10, 3, 14))
1212 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1213 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1217 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1218 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1219 if (h_older_than(1, 3, 0, 1))
1221 if (p_ptr->pclass == CLASS_SMITH)
1223 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1224 p_ptr->magic_num1[96] = 0;
1225 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1226 p_ptr->magic_num1[97] = 0;
1230 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1232 if (z_older_than(11, 0, 7))
1234 p_ptr->start_race = p_ptr->prace;
1235 p_ptr->old_race1 = 0L;
1236 p_ptr->old_race2 = 0L;
1237 p_ptr->old_realm = 0;
1241 rd_byte(&p_ptr->start_race);
1242 rd_s32b(&p_ptr->old_race1);
1243 rd_s32b(&p_ptr->old_race2);
1244 rd_s16b(&p_ptr->old_realm);
1247 if (z_older_than(10, 0, 1))
1249 for (i = 0; i < OLD_MAX_MANE; i++)
1251 p_ptr->mane_spell[i] = -1;
1252 p_ptr->mane_dam[i] = 0;
1254 p_ptr->mane_num = 0;
1256 else if (z_older_than(10, 2, 3))
1258 for (i = 0; i < OLD_MAX_MANE; i++)
1263 for (i = 0; i < MAX_MANE; i++)
1265 p_ptr->mane_spell[i] = -1;
1266 p_ptr->mane_dam[i] = 0;
1269 p_ptr->mane_num = 0;
1273 for (i = 0; i < MAX_MANE; i++)
1275 rd_s16b(&p_ptr->mane_spell[i]);
1276 rd_s16b(&p_ptr->mane_dam[i]);
1278 rd_s16b(&p_ptr->mane_num);
1281 if (z_older_than(10, 0, 3))
1283 get_mon_num_prep(NULL, NULL);
1284 for (i = 0; i < MAX_KUBI; i++)
1286 monster_race *r_ptr;
1291 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1292 r_ptr = &r_info[kubi_r_idx[i]];
1294 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1296 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1298 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1300 for (j = 0; j < i; j++)
1301 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1306 for (i = 0; i < MAX_KUBI -1; i++)
1309 for (j = i; j < MAX_KUBI; j++)
1311 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1313 tmp = kubi_r_idx[i];
1314 kubi_r_idx[i] = kubi_r_idx[j];
1315 kubi_r_idx[j] = tmp;
1319 for (i = 0; i < MAX_KUBI; i++)
1321 if(!r_info[kubi_r_idx[i]].max_num)
1322 kubi_r_idx[i] += 10000;
1327 for (i = 0; i < MAX_KUBI; i++)
1329 rd_s16b(&kubi_r_idx[i]);
1333 if (z_older_than(10, 0, 3))
1339 for (i = 0; i < 4; i++)
1341 rd_s16b(&battle_mon[i]);
1342 if (z_older_than(10, 3, 4))
1345 mon_odds[i] = tmp16s;
1347 else rd_u32b(&mon_odds[i]);
1351 rd_s16b(&p_ptr->town_num);
1353 /* Read arena and rewards information */
1354 rd_s16b(&p_ptr->arena_number);
1356 p_ptr->inside_arena = (bool)tmp16s;
1357 rd_s16b(&p_ptr->inside_quest);
1358 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1362 p_ptr->inside_battle = (bool)tmp16s;
1364 rd_byte(&p_ptr->exit_bldg);
1365 rd_byte(&p_ptr->leftbldg);
1367 rd_s16b(&p_ptr->oldpx);
1368 rd_s16b(&p_ptr->oldpy);
1369 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1373 if (tmp16s > MAX_BACT)
1376 note(format("¤ÎÃæ", tmp16s));
1378 note(format("Too many (%d) building rewards!", tmp16s));
1383 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1385 rd_s16b(&p_ptr->mhp);
1386 rd_s16b(&p_ptr->chp);
1387 rd_u16b(&p_ptr->chp_frac);
1389 rd_s16b(&p_ptr->msp);
1390 rd_s16b(&p_ptr->csp);
1391 rd_u16b(&p_ptr->csp_frac);
1393 rd_s16b(&p_ptr->max_plv);
1394 if (z_older_than(10, 3, 8))
1396 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1400 byte max = (byte)max_d_idx;
1404 for(i = 0; i < max; i++)
1406 rd_s16b(&max_dlv[i]);
1407 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1411 /* Repair maximum player level XXX XXX XXX */
1412 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1416 rd_s16b(&p_ptr->sc);
1419 /* Read the flags */
1420 strip_bytes(2); /* Old "rest" */
1421 rd_s16b(&p_ptr->blind);
1422 rd_s16b(&p_ptr->paralyzed);
1423 rd_s16b(&p_ptr->confused);
1424 rd_s16b(&p_ptr->food);
1425 strip_bytes(4); /* Old "food_digested" / "protection" */
1427 rd_s16b(&p_ptr->energy_need);
1428 if (z_older_than(11, 0, 13))
1429 p_ptr->energy_need = 100 - p_ptr->energy_need;
1431 rd_s16b(&p_ptr->fast);
1432 rd_s16b(&p_ptr->slow);
1433 rd_s16b(&p_ptr->afraid);
1434 rd_s16b(&p_ptr->cut);
1435 rd_s16b(&p_ptr->stun);
1436 rd_s16b(&p_ptr->poisoned);
1437 rd_s16b(&p_ptr->image);
1438 rd_s16b(&p_ptr->protevil);
1439 rd_s16b(&p_ptr->invuln);
1440 if(z_older_than(10, 0, 0))
1443 rd_s16b(&p_ptr->ult_res);
1444 rd_s16b(&p_ptr->hero);
1445 rd_s16b(&p_ptr->shero);
1446 rd_s16b(&p_ptr->shield);
1447 rd_s16b(&p_ptr->blessed);
1448 rd_s16b(&p_ptr->tim_invis);
1449 rd_s16b(&p_ptr->word_recall);
1450 if (z_older_than(10, 3, 8))
1451 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1455 p_ptr->recall_dungeon = (byte)tmp16s;
1457 rd_s16b(&p_ptr->see_infra);
1458 rd_s16b(&p_ptr->tim_infra);
1459 rd_s16b(&p_ptr->oppose_fire);
1460 rd_s16b(&p_ptr->oppose_cold);
1461 rd_s16b(&p_ptr->oppose_acid);
1462 rd_s16b(&p_ptr->oppose_elec);
1463 rd_s16b(&p_ptr->oppose_pois);
1464 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1465 else rd_s16b(&p_ptr->tsuyoshi);
1467 /* Old savefiles do not have the following fields... */
1468 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1471 p_ptr->wraith_form = 0;
1472 p_ptr->resist_magic = 0;
1473 p_ptr->tim_regen = 0;
1474 p_ptr->kabenuke = 0;
1475 p_ptr->tim_stealth = 0;
1476 p_ptr->tim_ffall = 0;
1477 p_ptr->tim_sh_touki = 0;
1478 p_ptr->lightspeed = 0;
1479 p_ptr->tsubureru = 0;
1480 p_ptr->tim_res_nether = 0;
1481 p_ptr->tim_res_time = 0;
1482 p_ptr->mimic_form = 0;
1483 p_ptr->tim_mimic = 0;
1484 p_ptr->tim_sh_fire = 0;
1487 p_ptr->tim_reflect = 0;
1488 p_ptr->multishadow = 0;
1489 p_ptr->dustrobe = 0;
1491 p_ptr->chaos_patron = get_chaos_patron();
1499 rd_s16b(&p_ptr->tim_esp);
1500 rd_s16b(&p_ptr->wraith_form);
1501 rd_s16b(&p_ptr->resist_magic);
1502 rd_s16b(&p_ptr->tim_regen);
1503 rd_s16b(&p_ptr->kabenuke);
1504 rd_s16b(&p_ptr->tim_stealth);
1505 rd_s16b(&p_ptr->tim_ffall);
1506 rd_s16b(&p_ptr->tim_sh_touki);
1507 rd_s16b(&p_ptr->lightspeed);
1508 rd_s16b(&p_ptr->tsubureru);
1509 if (z_older_than(10, 4, 7))
1510 p_ptr->magicdef = 0;
1512 rd_s16b(&p_ptr->magicdef);
1513 rd_s16b(&p_ptr->tim_res_nether);
1514 if (z_older_than(10, 4, 11))
1516 p_ptr->tim_res_time = 0;
1517 p_ptr->mimic_form = 0;
1518 p_ptr->tim_mimic = 0;
1519 p_ptr->tim_sh_fire = 0;
1523 rd_s16b(&p_ptr->tim_res_time);
1524 rd_byte(&p_ptr->mimic_form);
1525 rd_s16b(&p_ptr->tim_mimic);
1526 rd_s16b(&p_ptr->tim_sh_fire);
1529 if (z_older_than(11, 0, 99))
1531 p_ptr->tim_sh_holy = 0;
1532 p_ptr->tim_eyeeye = 0;
1536 rd_s16b(&p_ptr->tim_sh_holy);
1537 rd_s16b(&p_ptr->tim_eyeeye);
1541 if ( z_older_than(11,0,3) ){
1542 p_ptr->tim_reflect=0;
1543 p_ptr->multishadow=0;
1547 rd_s16b(&p_ptr->tim_reflect);
1548 rd_s16b(&p_ptr->multishadow);
1549 rd_s16b(&p_ptr->dustrobe);
1552 rd_s16b(&p_ptr->chaos_patron);
1553 rd_u32b(&p_ptr->muta1);
1554 rd_u32b(&p_ptr->muta2);
1555 rd_u32b(&p_ptr->muta3);
1557 for (i = 0; i < 8; i++)
1558 rd_s16b(&p_ptr->virtues[i]);
1559 for (i = 0; i < 8; i++)
1560 rd_s16b(&p_ptr->vir_types[i]);
1563 /* Calc the regeneration modifier for mutations */
1564 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1566 if (z_older_than(10,0,9))
1569 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1570 p_ptr->ele_attack = 0;
1574 rd_s16b(&p_ptr->ele_attack);
1575 rd_u32b(&p_ptr->special_attack);
1577 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1578 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1579 if (z_older_than(10,0,12))
1581 p_ptr->ele_immune = 0;
1582 p_ptr->special_defense = 0;
1586 rd_s16b(&p_ptr->ele_immune);
1587 rd_u32b(&p_ptr->special_defense);
1589 rd_byte(&p_ptr->knowledge);
1590 rd_byte(&tmp8u); /* oops */
1591 rd_byte(&tmp8u); /* oops */
1592 rd_byte(&p_ptr->action);
1593 if (!z_older_than(10, 4, 3))
1596 if (tmp8u) p_ptr->action = ACTION_LEARN;
1598 rd_byte((byte *)&preserve_mode);
1599 rd_byte((byte *)&p_ptr->wait_report_score);
1602 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1604 /* Skip the flags */
1608 /* Hack -- the two "special seeds" */
1609 rd_u32b(&seed_flavor);
1610 rd_u32b(&seed_town);
1614 rd_u16b(&p_ptr->panic_save);
1615 rd_u16b(&p_ptr->total_winner);
1616 rd_u16b(&p_ptr->noscore);
1621 p_ptr->is_dead = tmp8u;
1623 /* Read "feeling" */
1627 /* Turn of last "feeling" */
1633 if (z_older_than(10, 3, 12))
1635 dungeon_turn = turn;
1637 else rd_s32b(&dungeon_turn);
1639 if (z_older_than(11, 0, 13))
1646 if (z_older_than(10, 3, 13))
1650 else rd_s32b(&old_battle);
1652 if (z_older_than(10,0,3))
1654 monster_race *r_ptr;
1658 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1659 r_ptr = &r_info[today_mon];
1661 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1662 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1663 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1664 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1665 if (r_ptr->rarity > 10) continue;
1666 if (r_ptr->level == 0) continue;
1670 p_ptr->today_mon = 0;
1674 rd_s16b(&today_mon);
1675 rd_s16b(&p_ptr->today_mon);
1678 if (z_older_than(10,0,7))
1684 rd_s16b(&p_ptr->riding);
1687 if (z_older_than(10,1,2))
1696 if (z_older_than(10,3,9))
1700 else if (z_older_than(10, 3, 10))
1708 rd_s32b(&p_ptr->visit);
1710 if (!z_older_than(11, 0, 5))
1712 rd_u32b(&p_ptr->count);
1720 * Read the player inventory
1722 * Note that the inventory changed in Angband 2.7.4. Two extra
1723 * pack slots were added and the equipment was rearranged. Note
1724 * that these two features combine when parsing old save-files, in
1725 * which items from the old "aux" slot are "carried", perhaps into
1726 * one of the two new "inventory" slots.
1728 * Note that the inventory is "re-sorted" later by "dungeon()".
1730 static errr rd_inventory(void)
1738 p_ptr->total_weight = 0;
1744 /* Read until done */
1749 /* Get the next item index */
1752 /* Nope, we reached the end */
1753 if (n == 0xFFFF) break;
1755 /* Get local object */
1758 /* Wipe the object */
1764 /* Hack -- verify item */
1765 if (!q_ptr->k_idx) return (53);
1767 /* Wield equipment */
1768 if (n >= INVEN_RARM)
1771 object_copy(&inventory[n], q_ptr);
1773 /* Add the weight */
1774 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1780 /* Warning -- backpack is full */
1781 else if (inven_cnt == INVEN_PACK)
1785 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1787 note("Too many items in the inventory!");
1795 /* Carry inventory */
1802 object_copy(&inventory[n], q_ptr);
1804 /* Add the weight */
1805 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1819 * Read the saved messages
1821 static void rd_messages(void)
1831 /* Read the messages */
1832 for (i = 0; i < num; i++)
1834 /* Read the message */
1835 rd_string(buf, 128);
1837 /* Save the message */
1847 * The monsters/objects must be loaded in the same order
1848 * that they were stored, since the actual indexes matter.
1850 static errr rd_dungeon(void)
1861 /*** Basic info ***/
1864 rd_s16b(&dun_level);
1865 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1866 else rd_byte(&dungeon_type);
1868 /* Set the base level for old versions */
1869 base_level = dun_level;
1871 rd_s16b(&base_level);
1873 rd_s16b(&num_repro);
1878 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1881 rd_s16b(&tmp16s); /* max_panel_rows */
1882 rd_s16b(&tmp16s); /* max_panel_cols */
1885 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1893 /*** Run length decoding ***/
1895 /* Load the dungeon data */
1896 for (x = y = 0; y < ymax; )
1900 if (z_older_than(10,3,6))
1905 /* Apply the RLE info */
1906 for (i = count; i > 0; i--)
1908 /* Access the cave */
1909 c_ptr = &cave[y][x];
1911 /* Extract "info" */
1912 if (z_older_than(10,3,6))
1913 c_ptr->info = tmp8u;
1914 else c_ptr->info = tmp16s;
1923 if (++y >= ymax) break;
1929 /*** Run length decoding ***/
1931 /* Load the dungeon data */
1932 for (x = y = 0; y < ymax; )
1938 /* Apply the RLE info */
1939 for (i = count; i > 0; i--)
1941 /* Access the cave */
1942 c_ptr = &cave[y][x];
1944 /* Extract "feat" */
1945 c_ptr->feat = tmp8u;
1954 if (++y >= ymax) break;
1959 /* Convert cave data */
1960 if (z_older_than(11, 0, 99))
1962 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
1964 /* Wipe old unused flags */
1965 cave[y][x].info &= ~(CAVE_MASK);
1969 if (h_older_than(1, 1, 1, 0))
1971 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
1973 /* Access the cave */
1974 c_ptr = &cave[y][x];
1977 if (c_ptr->feat == FEAT_INVIS)
1979 c_ptr->feat = FEAT_FLOOR;
1980 c_ptr->info |= CAVE_TRAP;
1983 /* Older than 1.1.1 */
1984 if (c_ptr->feat == FEAT_MIRROR)
1986 c_ptr->feat = FEAT_FLOOR;
1987 c_ptr->info |= CAVE_IN_MIRROR;
1992 /*** Run length decoding ***/
1994 /* Load the dungeon data */
1995 for (x = y = 0; y < ymax; )
2001 /* Apply the RLE info */
2002 for (i = count; i > 0; i--)
2004 /* Access the cave */
2005 c_ptr = &cave[y][x];
2007 /* Extract "feat" */
2008 c_ptr->mimic = tmp8u;
2017 if (++y >= ymax) break;
2022 /*** Run length decoding ***/
2024 /* Load the dungeon data */
2025 for (x = y = 0; y < ymax; )
2031 /* Apply the RLE info */
2032 for (i = count; i > 0; i--)
2034 /* Access the cave */
2035 c_ptr = &cave[y][x];
2037 /* Extract "feat" */
2038 c_ptr->special = tmp16s;
2047 if (++y >= ymax) break;
2054 /* Read the item count */
2057 /* Verify maximum */
2058 if (limit >= max_o_idx)
2061 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2063 note(format("Too many (%d) object entries!", limit));
2069 /* Read the dungeon items */
2070 for (i = 1; i < limit; i++)
2077 /* Get a new record */
2084 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2086 note(format("Object allocation error (%d <> %d)", i, o_idx));
2094 o_ptr = &o_list[o_idx];
2100 /* XXX XXX XXX XXX XXX */
2103 if (o_ptr->held_m_idx)
2105 monster_type *m_ptr;
2108 m_ptr = &m_list[o_ptr->held_m_idx];
2111 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2113 /* Place the object */
2114 m_ptr->hold_o_idx = o_idx;
2120 /* Access the item location */
2121 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2124 o_ptr->next_o_idx = c_ptr->o_idx;
2126 /* Place the object */
2127 c_ptr->o_idx = o_idx;
2134 /* Read the monster count */
2137 /* Hack -- verify */
2138 if (limit >= max_m_idx)
2141 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2143 note(format("Too many (%d) monster entries!", limit));
2149 /* Read the monsters */
2150 for (i = 1; i < limit; i++)
2154 monster_type *m_ptr;
2156 monster_race *r_ptr;
2159 /* Get a new record */
2166 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2168 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2175 /* Acquire monster */
2176 m_ptr = &m_list[m_idx];
2178 /* Read the monster */
2183 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2185 /* Mark the location */
2186 c_ptr->m_idx = m_idx;
2190 r_ptr = &r_info[m_ptr->r_idx];
2192 /* Count XXX XXX XXX */
2198 /* The dungeon is ready */
2199 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2200 character_dungeon = FALSE;
2202 character_dungeon = TRUE;
2211 * Actually read the savefile
2213 static errr rd_savefile_new_aux(void)
2225 #ifdef VERIFY_CHECKSUMS
2226 u32b n_x_check, n_v_check;
2227 u32b o_x_check, o_v_check;
2231 /* Mention the savefile version */
2234 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2236 "Loading a %d.%d.%d savefile...",
2238 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2241 /* Strip the version bytes */
2244 /* Hack -- decrypt */
2245 xor_byte = sf_extra;
2248 /* Clear the checksums */
2252 /* Read the version number of the savefile */
2253 /* Old savefile will be version 0.0.0.3 */
2254 rd_byte(&h_ver_extra);
2255 rd_byte(&h_ver_patch);
2256 rd_byte(&h_ver_minor);
2257 rd_byte(&h_ver_major);
2259 /* Operating system info */
2260 rd_u32b(&sf_system);
2262 /* Time of savefile creation */
2265 /* Number of resurrections */
2268 /* Number of times played */
2272 /* Later use (always zero) */
2275 /* Later use (always zero) */
2279 /* Read RNG state */
2282 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2284 if (arg_fiddle) note("Loaded Randomizer Info");
2289 /* Then the options */
2292 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2294 if (arg_fiddle) note("Loaded Option Flags");
2298 * Munchkin players are marked
2300 * XXX - should be replaced with a better method,
2301 * after the new scorefile-handling is implemented.
2306 p_ptr->noscore |= 0x0001;
2309 /* Then the "messages" */
2312 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2314 if (arg_fiddle) note("Loaded Messages");
2319 for (i = 0; i < max_r_idx; i++)
2321 monster_race *r_ptr;
2322 /* Access that monster */
2325 /* Hack -- Reset the death counter */
2326 r_ptr->max_num = 100;
2327 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2328 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2331 /* Monster Memory */
2334 /* Incompatible save files */
2335 if (tmp16u > max_r_idx)
2338 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2340 note(format("Too many (%u) monster races!", tmp16u));
2346 /* Read the available records */
2347 for (i = 0; i < tmp16u; i++)
2349 monster_race *r_ptr;
2354 /* Access that monster */
2359 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2361 if (arg_fiddle) note("Loaded Monster Memory");
2369 /* Incompatible save files */
2370 if (tmp16u > max_k_idx)
2373 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2375 note(format("Too many (%u) object kinds!", tmp16u));
2381 /* Read the object memory */
2382 for (i = 0; i < tmp16u; i++)
2385 object_kind *k_ptr = &k_info[i];
2389 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2390 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2393 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2395 if (arg_fiddle) note("Loaded Object Memory");
2401 * Initialize arena and rewards information
2403 p_ptr->arena_number = 0;
2404 p_ptr->inside_arena = 0;
2405 p_ptr->inside_quest = 0;
2406 p_ptr->leftbldg = FALSE;
2407 p_ptr->exit_bldg = TRUE;
2409 /* Start in town 1 */
2410 p_ptr->town_num = 1;
2412 p_ptr->wilderness_x = 4;
2413 p_ptr->wilderness_y = 4;
2417 /* Init the wilderness seeds */
2418 for (i = 0; i < max_wild_x; i++)
2420 for (j = 0; j < max_wild_y; j++)
2422 wilderness[j][i].seed = randint0(0x10000000);
2426 /* 2.1.3 or newer version */
2428 u16b max_towns_load;
2429 u16b max_quests_load;
2430 byte max_rquests_load;
2431 s16b old_inside_quest = p_ptr->inside_quest;
2433 /* Number of towns */
2434 rd_u16b(&max_towns_load);
2436 /* Incompatible save files */
2437 if (max_towns_load > max_towns)
2440 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2442 note(format("Too many (%u) towns!", max_towns_load));
2448 /* Number of quests */
2449 rd_u16b(&max_quests_load);
2451 if (z_older_than(11, 0, 7))
2453 max_rquests_load = 10;
2457 rd_byte(&max_rquests_load);
2460 /* Incompatible save files */
2461 if (max_quests_load > max_quests)
2464 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2466 note(format("Too many (%u) quests!", max_quests_load));
2472 for (i = 0; i < max_quests_load; i++)
2476 rd_s16b(&quest[i].status);
2477 rd_s16b(&quest[i].level);
2479 if (z_older_than(11, 0, 6))
2481 quest[i].complev = 0;
2485 rd_byte(&quest[i].complev);
2488 /* Load quest status if quest is running */
2489 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))))
2491 rd_s16b(&quest[i].cur_num);
2492 rd_s16b(&quest[i].max_num);
2493 rd_s16b(&quest[i].type);
2495 /* Load quest monster index */
2496 rd_s16b(&quest[i].r_idx);
2498 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2503 monster_race *r_ptr;
2506 * Random monster 5 - 10 levels out of depth
2507 * (depending on level)
2509 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
2510 r_ptr = &r_info[r_idx];
2512 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2514 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2516 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2518 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2520 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2523 * Accept monsters that are 2 - 6 levels
2524 * out of depth depending on the quest level
2526 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2529 quest[i].r_idx = r_idx;
2532 /* Load quest item index */
2533 rd_s16b(&quest[i].k_idx);
2536 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
2538 rd_byte(&quest[i].flags);
2540 if (z_older_than(10, 3, 11))
2542 if (quest[i].flags & QUEST_FLAG_PRESET)
2544 quest[i].dungeon = 0;
2548 init_flags = INIT_ASSIGN;
2549 p_ptr->inside_quest = i;
2551 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2552 p_ptr->inside_quest = old_inside_quest;
2557 rd_byte(&quest[i].dungeon);
2560 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2561 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2562 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2565 /* Ignore the empty quests from old versions */
2568 /* Ignore quest status */
2571 /* Ignore quest level */
2575 * We don't have to care about the other info,
2576 * since status should be 0 for these quests anyway
2581 /* Position in the wilderness */
2582 rd_s32b(&p_ptr->wilderness_x);
2583 rd_s32b(&p_ptr->wilderness_y);
2584 if (z_older_than(10, 3, 13))
2586 p_ptr->wilderness_x = 5;
2587 p_ptr->wilderness_y = 48;
2590 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2591 else rd_byte((byte *)&p_ptr->wild_mode);
2592 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2593 else rd_byte((byte *)&ambush_flag);
2595 /* Size of the wilderness */
2596 rd_s32b(&wild_x_size);
2597 rd_s32b(&wild_y_size);
2599 /* Incompatible save files */
2600 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2603 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2605 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2611 /* Load the wilderness seeds */
2612 for (i = 0; i < wild_x_size; i++)
2614 for (j = 0; j < wild_y_size; j++)
2616 rd_u32b(&wilderness[j][i].seed);
2622 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2624 if (arg_fiddle) note("Loaded Quests");
2627 /* Load the Artifacts */
2630 /* Incompatible save files */
2631 if (tmp16u > max_a_idx)
2634 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2636 note(format("Too many (%u) artifacts!", tmp16u));
2642 /* Read the artifact flags */
2643 for (i = 0; i < tmp16u; i++)
2646 a_info[i].cur_num = tmp8u;
2652 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2654 if (arg_fiddle) note("Loaded Artifacts");
2659 /* Read the extra stuff */
2661 if (p_ptr->energy_need < -999) world_player = TRUE;
2664 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2666 if (arg_fiddle) note("Loaded extra information");
2670 /* Read the player_hp array */
2673 /* Incompatible save files */
2674 if (tmp16u > PY_MAX_LEVEL)
2677 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2679 note(format("Too many (%u) hitpoint entries!", tmp16u));
2685 /* Read the player_hp array */
2686 for (i = 0; i < tmp16u; i++)
2688 rd_s16b(&p_ptr->player_hp[i]);
2691 /* Important -- Initialize the sex */
2692 sp_ptr = &sex_info[p_ptr->psex];
2694 /* Important -- Initialize the race/class */
2695 rp_ptr = &race_info[p_ptr->prace];
2696 cp_ptr = &class_info[p_ptr->pclass];
2697 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2699 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
2701 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2702 do_cmd_rerate(FALSE);
2704 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
2706 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2707 do_cmd_rerate(FALSE);
2709 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
2711 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2712 do_cmd_rerate(FALSE);
2714 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
2716 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2717 do_cmd_rerate(FALSE);
2720 /* Important -- Initialize the magic */
2721 mp_ptr = &m_info[p_ptr->pclass];
2724 /* Read spell info */
2725 rd_u32b(&p_ptr->spell_learned1);
2726 rd_u32b(&p_ptr->spell_learned2);
2727 rd_u32b(&p_ptr->spell_worked1);
2728 rd_u32b(&p_ptr->spell_worked2);
2729 rd_u32b(&p_ptr->spell_forgotten1);
2730 rd_u32b(&p_ptr->spell_forgotten2);
2732 if (z_older_than(10,0,5))
2734 p_ptr->learned_spells = 0;
2735 for (i = 0; i < 64; i++)
2737 /* Count known spells */
2739 (p_ptr->spell_learned1 & (1L << i)) :
2740 (p_ptr->spell_learned2 & (1L << (i - 32))))
2742 p_ptr->learned_spells++;
2746 else rd_s16b(&p_ptr->learned_spells);
2748 if (z_older_than(10,0,6))
2750 p_ptr->add_spells = 0;
2752 else rd_s16b(&p_ptr->add_spells);
2753 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2755 for (i = 0; i < 64; i++)
2757 rd_byte(&p_ptr->spell_order[i]);
2761 /* Read the inventory */
2765 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2767 note("Unable to read inventory");
2773 /* Read number of towns */
2775 town_count = tmp16u;
2777 /* Read the stores */
2779 for (i = 1; i < town_count; i++)
2781 for (j = 0; j < tmp16u; j++)
2783 if (rd_store(i, j)) return (22);
2787 rd_s16b(&p_ptr->pet_follow_distance);
2788 if (z_older_than(10, 4, 10))
2790 p_ptr->pet_extra_flags = 0;
2792 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2794 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2796 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2800 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2803 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2807 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2810 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2814 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2817 if (!z_older_than(10,0,8))
2820 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2825 rd_s16b(&p_ptr->pet_extra_flags);
2828 if (!z_older_than(11, 0, 9))
2830 char buf[SCREEN_BUF_SIZE];
2831 rd_string(buf, SCREEN_BUF_SIZE);
2832 if (buf[0]) screen_dump = string_make(buf);
2837 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2839 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2844 /* I'm not dead yet... */
2845 if (!p_ptr->is_dead)
2847 /* Dead players have no dungeon */
2849 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2851 note("Restoring Dungeon...");
2857 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2859 note("Error reading dungeon data");
2865 /* Read the ghost info */
2872 strip_bytes(tmp32s);
2877 #ifdef VERIFY_CHECKSUMS
2879 /* Save the checksum */
2880 n_v_check = v_check;
2882 /* Read the old checksum */
2883 rd_u32b(&o_v_check);
2886 if (o_v_check != n_v_check)
2889 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2891 note("Invalid checksum");
2898 /* Save the encoded checksum */
2899 n_x_check = x_check;
2901 /* Read the checksum */
2902 rd_u32b(&o_x_check);
2906 if (o_x_check != n_x_check)
2909 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2911 note("Invalid encoded checksum");
2925 * Actually read the savefile
2927 errr rd_savefile_new(void)
2931 /* The savefile is a binary file */
2932 fff = my_fopen(savefile, "rb");
2935 if (!fff) return (-1);
2937 /* Call the sub-function */
2938 err = rd_savefile_new_aux();
2940 /* Check for errors */
2941 if (ferror(fff)) err = -1;
2943 /* Close the file */