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);
354 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
356 switch (o_ptr->xtra2 % 6)
358 case 0: o_ptr->art_flags2 |= (TR2_SUST_STR); break;
359 case 1: o_ptr->art_flags2 |= (TR2_SUST_INT); break;
360 case 2: o_ptr->art_flags2 |= (TR2_SUST_WIS); break;
361 case 3: o_ptr->art_flags2 |= (TR2_SUST_DEX); break;
362 case 4: o_ptr->art_flags2 |= (TR2_SUST_CON); break;
363 case 5: o_ptr->art_flags2 |= (TR2_SUST_CHR); break;
365 o_ptr->xtra1 = o_ptr->xtra2 = 0;
367 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
369 switch (o_ptr->xtra2 % 11)
371 case 0: o_ptr->art_flags2 |= (TR2_RES_BLIND); break;
372 case 1: o_ptr->art_flags2 |= (TR2_RES_CONF); break;
373 case 2: o_ptr->art_flags2 |= (TR2_RES_SOUND); break;
374 case 3: o_ptr->art_flags2 |= (TR2_RES_SHARDS); break;
375 case 4: o_ptr->art_flags2 |= (TR2_RES_NETHER); break;
376 case 5: o_ptr->art_flags2 |= (TR2_RES_NEXUS); break;
377 case 6: o_ptr->art_flags2 |= (TR2_RES_CHAOS); break;
378 case 7: o_ptr->art_flags2 |= (TR2_RES_DISEN); break;
379 case 8: o_ptr->art_flags2 |= (TR2_RES_POIS); break;
380 case 9: o_ptr->art_flags2 |= (TR2_RES_DARK); break;
381 case 10: o_ptr->art_flags2 |= (TR2_RES_LITE); break;
383 o_ptr->xtra1 = o_ptr->xtra2 = 0;
385 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
387 switch (o_ptr->xtra2 % 8)
389 case 0: o_ptr->art_flags3 |= (TR3_FEATHER); break;
390 case 1: o_ptr->art_flags3 |= (TR3_LITE); break;
391 case 2: o_ptr->art_flags3 |= (TR3_SEE_INVIS); break;
392 case 3: o_ptr->art_flags3 |= (TR3_WARNING); break;
393 case 4: o_ptr->art_flags3 |= (TR3_SLOW_DIGEST); break;
394 case 5: o_ptr->art_flags3 |= (TR3_REGEN); break;
395 case 6: o_ptr->art_flags2 |= (TR2_FREE_ACT); break;
396 case 7: o_ptr->art_flags2 |= (TR2_HOLD_LIFE); break;
398 o_ptr->xtra1 = o_ptr->xtra2 = 0;
401 if (z_older_than(10, 2, 3))
406 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
408 o_ptr->xtra3 = o_ptr->xtra1;
411 if (o_ptr->tval == TV_CAPTURE)
413 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
414 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
416 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
417 if (ironman_nightmare)
419 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
421 o_ptr->xtra4 = o_ptr->xtra5;
426 rd_byte(&o_ptr->xtra3);
427 rd_s16b(&o_ptr->xtra4);
428 rd_s16b(&o_ptr->xtra5);
431 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)))
433 o_ptr->xtra4 = o_ptr->pval;
437 /* Feeling - from 2.3.1, "savefile version 1" */
440 rd_byte(&o_ptr->feeling);
446 /* If this savefile is old, maybe we need to translate the feeling */
451 for (i = 0; i <= FEEL_MAX; i++)
453 if (game_inscriptions[i] == NULL)
458 if (streq(buf, game_inscriptions[i]))
467 /* Save the inscription */
468 if (buf[0]) o_ptr->inscription = quark_add(buf);
471 if (buf[0]) o_ptr->art_name = quark_add(buf);
473 /* The Python object */
481 /* Mega-Hack -- handle "dungeon objects" later */
482 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
484 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
486 /* Obtain the "kind" template */
487 k_ptr = &k_info[o_ptr->k_idx];
489 /* Obtain tval/sval from k_info */
490 o_ptr->tval = k_ptr->tval;
491 o_ptr->sval = k_ptr->sval;
493 /* Hack -- notice "broken" items */
494 if (k_ptr->cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
497 /* Repair non "wearable" items */
498 if (!wearable_p(o_ptr))
500 /* Acquire correct fields */
501 o_ptr->to_h = k_ptr->to_h;
502 o_ptr->to_d = k_ptr->to_d;
503 o_ptr->to_a = k_ptr->to_a;
505 /* Acquire correct fields */
506 o_ptr->ac = k_ptr->ac;
507 o_ptr->dd = k_ptr->dd;
508 o_ptr->ds = k_ptr->ds;
510 /* Acquire correct weight */
511 o_ptr->weight = k_ptr->weight;
514 o_ptr->name1 = o_ptr->name2 = 0;
521 /* Extract the flags */
522 object_flags(o_ptr, &f1, &f2, &f3);
524 if (z_older_than(10, 4, 9))
526 if (o_ptr->art_flags1 & TR1_MAGIC_MASTERY)
528 o_ptr->art_flags1 &= ~(TR1_MAGIC_MASTERY);
529 o_ptr->art_flags3 |= (TR3_DEC_MANA);
536 artifact_type *a_ptr;
538 /* Obtain the artifact info */
539 a_ptr = &a_info[o_ptr->name1];
541 /* Verify that artifact */
542 if (!a_ptr->name) o_ptr->name1 = 0;
548 ego_item_type *e_ptr;
550 /* Obtain the ego-item info */
551 e_ptr = &e_info[o_ptr->name2];
553 /* Verify that ego-item */
554 if (!e_ptr->name) o_ptr->name2 = 0;
558 /* Acquire standard fields */
559 o_ptr->ac = k_ptr->ac;
560 o_ptr->dd = k_ptr->dd;
561 o_ptr->ds = k_ptr->ds;
563 /* Acquire standard weight */
564 o_ptr->weight = k_ptr->weight;
566 /* Hack -- extract the "broken" flag */
567 if (!o_ptr->pval < 0) o_ptr->ident |= (IDENT_BROKEN);
572 artifact_type *a_ptr;
574 /* Obtain the artifact info */
575 a_ptr = &a_info[o_ptr->name1];
577 /* Acquire new artifact "pval" */
578 o_ptr->pval = a_ptr->pval;
580 /* Acquire new artifact fields */
581 o_ptr->ac = a_ptr->ac;
582 o_ptr->dd = a_ptr->dd;
583 o_ptr->ds = a_ptr->ds;
585 /* Acquire new artifact weight */
586 o_ptr->weight = a_ptr->weight;
588 /* Hack -- extract the "broken" flag */
589 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
595 ego_item_type *e_ptr;
597 /* Obtain the ego-item info */
598 e_ptr = &e_info[o_ptr->name2];
603 if (o_ptr->name2 == EGO_DWARVEN)
606 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
609 /* Hack -- extract the "broken" flag */
610 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
613 if (o_ptr->art_name) /* A random artifact */
626 static void rd_monster(monster_type *m_ptr)
631 /* Read the monster race */
632 rd_s16b(&m_ptr->r_idx);
634 /* Read the other information */
638 rd_s16b(&m_ptr->maxhp);
639 if (z_older_than(11, 0, 5))
641 m_ptr->max_maxhp = m_ptr->maxhp;
645 rd_s16b(&m_ptr->max_maxhp);
647 rd_s16b(&m_ptr->csleep);
648 rd_byte(&m_ptr->mspeed);
649 if (z_older_than(10, 4, 2))
652 m_ptr->energy = (s16b)tmp8u;
654 else rd_s16b(&m_ptr->energy);
655 if (z_older_than(10,0,7))
662 rd_byte(&m_ptr->fast);
663 rd_byte(&m_ptr->slow);
665 rd_byte(&m_ptr->stunned);
666 rd_byte(&m_ptr->confused);
667 rd_byte(&m_ptr->monfear);
669 if (z_older_than(10,0,10))
673 else if (z_older_than(10,0,11))
681 rd_s16b(&m_ptr->target_y);
682 rd_s16b(&m_ptr->target_x);
685 /* Monster invulnerability introduced from 2.3.2+ */
689 rd_byte(&m_ptr->invulner);
691 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
692 rd_u32b(&m_ptr->smart);
696 if (z_older_than(10, 4, 5))
699 rd_u32b(&m_ptr->exp);
701 if (z_older_than(10, 2, 2))
703 if (m_ptr->r_idx < 0)
705 m_ptr->r_idx = (0-m_ptr->r_idx);
706 m_ptr->mflag2 |= MFLAG_KAGE;
711 rd_byte(&m_ptr->mflag2);
714 if (z_older_than(10, 1, 3))
721 if (buf[0]) m_ptr->nickname = quark_add(buf);
732 * Read the monster lore
734 static void rd_lore(int r_idx)
738 monster_race *r_ptr = &r_info[r_idx];
740 /* Count sights/deaths/kills */
741 rd_s16b(&r_ptr->r_sights);
742 rd_s16b(&r_ptr->r_deaths);
743 rd_s16b(&r_ptr->r_pkills);
744 rd_s16b(&r_ptr->r_tkills);
746 /* Count wakes and ignores */
747 rd_byte(&r_ptr->r_wake);
748 rd_byte(&r_ptr->r_ignore);
751 rd_byte(&r_ptr->r_xtra1);
752 rd_byte(&r_ptr->r_xtra2);
755 rd_byte(&r_ptr->r_drop_gold);
756 rd_byte(&r_ptr->r_drop_item);
759 rd_byte(&r_ptr->r_cast_inate);
760 rd_byte(&r_ptr->r_cast_spell);
762 /* Count blows of each type */
763 rd_byte(&r_ptr->r_blows[0]);
764 rd_byte(&r_ptr->r_blows[1]);
765 rd_byte(&r_ptr->r_blows[2]);
766 rd_byte(&r_ptr->r_blows[3]);
769 rd_u32b(&r_ptr->r_flags1);
770 rd_u32b(&r_ptr->r_flags2);
771 rd_u32b(&r_ptr->r_flags3);
772 rd_u32b(&r_ptr->r_flags4);
773 rd_u32b(&r_ptr->r_flags5);
774 rd_u32b(&r_ptr->r_flags6);
776 /* Read the "Racial" monster limit per level */
777 rd_byte(&r_ptr->max_num);
784 /* Repair the lore flags */
785 r_ptr->r_flags1 &= r_ptr->flags1;
786 r_ptr->r_flags2 &= r_ptr->flags2;
787 r_ptr->r_flags3 &= r_ptr->flags3;
788 r_ptr->r_flags4 &= r_ptr->flags4;
789 r_ptr->r_flags5 &= r_ptr->flags5;
790 r_ptr->r_flags6 &= r_ptr->flags6;
797 * Add the item "o_ptr" to the inventory of the "Home"
799 * In all cases, return the slot (or -1) where the object was placed
801 * Note that this is a hacked up version of "inven_carry()".
803 * Also note that it may not correctly "adapt" to "knowledge" bacoming
804 * known, the player may have to pick stuff up and drop it again.
806 static void home_carry(store_type *st_ptr, object_type *o_ptr)
814 /* Check each existing item (try to combine) */
815 for (slot = 0; slot < st_ptr->stock_num; slot++)
817 /* Get the existing item */
818 j_ptr = &st_ptr->stock[slot];
820 /* The home acts just like the player */
821 if (object_similar(j_ptr, o_ptr))
823 /* Save the new number of items */
824 object_absorb(j_ptr, o_ptr);
832 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
836 /* Determine the "value" of the item */
837 value = object_value(o_ptr);
839 /* Check existing slots to see if we must "slide" */
840 for (slot = 0; slot < st_ptr->stock_num; slot++)
843 j_ptr = &st_ptr->stock[slot];
845 /* Hack -- readable books always come first */
846 if ((o_ptr->tval == mp_ptr->spell_book) &&
847 (j_ptr->tval != mp_ptr->spell_book)) break;
848 if ((j_ptr->tval == mp_ptr->spell_book) &&
849 (o_ptr->tval != mp_ptr->spell_book)) continue;
851 /* Objects sort by decreasing type */
852 if (o_ptr->tval > j_ptr->tval) break;
853 if (o_ptr->tval < j_ptr->tval) continue;
855 /* Can happen in the home */
856 if (!object_aware_p(o_ptr)) continue;
857 if (!object_aware_p(j_ptr)) break;
859 /* Objects sort by increasing sval */
860 if (o_ptr->sval < j_ptr->sval) break;
861 if (o_ptr->sval > j_ptr->sval) continue;
863 /* Objects in the home can be unknown */
864 if (!object_known_p(o_ptr)) continue;
865 if (!object_known_p(j_ptr)) break;
868 * Hack: otherwise identical rods sort by
869 * increasing recharge time --dsb
871 if (o_ptr->tval == TV_ROD)
873 if (o_ptr->pval < j_ptr->pval) break;
874 if (o_ptr->pval > j_ptr->pval) continue;
877 /* Objects sort by decreasing value */
878 j_value = object_value(j_ptr);
879 if (value > j_value) break;
880 if (value < j_value) continue;
883 /* Slide the others up */
884 for (i = st_ptr->stock_num; i > slot; i--)
886 st_ptr->stock[i] = st_ptr->stock[i-1];
892 /* Insert the new item */
893 st_ptr->stock[slot] = *o_ptr;
895 chg_virtue(V_SACRIFICE, -1);
897 /* Return the location */
905 static errr rd_store(int town_number, int store_number)
917 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
919 st_ptr = &town[1].store[store_number];
920 if (st_ptr->stock_num) sort = TRUE;
924 st_ptr = &town[town_number].store[store_number];
927 /* Read the basic info */
928 rd_s32b(&st_ptr->store_open);
929 rd_s16b(&st_ptr->insult_cur);
931 if (z_older_than(11, 0, 4))
940 rd_s16b(&st_ptr->good_buy);
941 rd_s16b(&st_ptr->bad_buy);
943 /* Read last visit */
944 rd_s32b(&st_ptr->last_visit);
946 /* Extract the owner (see above) */
950 for (j = 0; j < num; j++)
955 /* Get local object */
958 /* Wipe the object */
964 /* Acquire valid items */
965 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
970 home_carry(st_ptr, q_ptr);
974 k = st_ptr->stock_num++;
976 /* Acquire the item */
977 object_copy(&st_ptr->stock[k], q_ptr);
989 * Read RNG state (added in 2.8.0)
991 static void rd_randomizer(void)
1001 rd_u16b(&Rand_place);
1004 for (i = 0; i < RAND_DEG; i++)
1006 rd_u32b(&Rand_state[i]);
1016 * Read options (ignore most pre-2.8.0 options)
1018 * Note that the normal options are now stored as a set of 256 bit flags,
1019 * plus a set of 256 bit masks to indicate which bit flags were defined
1020 * at the time the savefile was created. This will allow new options
1021 * to be added, and old options to be removed, at any time, without
1022 * hurting old savefiles.
1024 * The window options are stored in the same way, but note that each
1025 * window gets 32 options, and their order is fixed by certain defines.
1027 static void rd_options(void)
1041 /* Ignore old options */
1045 /*** Special info */
1047 /* Read "delay_factor" */
1051 /* Read "hitpoint_warn" */
1056 /*** Cheating options ***/
1060 if (c & 0x0002) wizard = TRUE;
1062 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1063 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1064 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1065 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1066 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1067 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1069 rd_byte((byte *)&autosave_l);
1070 rd_byte((byte *)&autosave_t);
1071 rd_s16b(&autosave_freq);
1074 /*** Normal Options ***/
1076 /* Read the option flags */
1077 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1079 /* Read the option masks */
1080 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1082 /* Analyze the options */
1083 for (n = 0; n < 8; n++)
1085 /* Analyze the options */
1086 for (i = 0; i < 32; i++)
1088 /* Process valid flags */
1089 if (mask[n] & (1L << i))
1091 /* Process valid flags */
1092 if (option_mask[n] & (1L << i))
1095 if (flag[n] & (1L << i))
1098 option_flag[n] |= (1L << i);
1105 option_flag[n] &= ~(1L << i);
1112 if (z_older_than(10, 4, 5))
1114 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1115 else option_flag[5] |= (0x00000001 << 4);
1116 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1117 else option_flag[2] |= (0x00000001 << 5);
1118 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1119 else option_flag[4] |= (0x00000001 << 5);
1120 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1121 else option_flag[5] |= (0x00000001 << 0);
1122 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1123 else option_flag[5] |= (0x00000001 << 12);
1124 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1125 else option_flag[1] |= (0x00000001 << 0);
1126 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1127 else option_flag[1] |= (0x00000001 << 18);
1128 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1129 else option_flag[1] |= (0x00000001 << 19);
1130 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1131 else option_flag[5] |= (0x00000001 << 3);
1135 /*** Window Options ***/
1137 /* Read the window flags */
1138 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1140 /* Read the window masks */
1141 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1143 /* Analyze the options */
1144 for (n = 0; n < 8; n++)
1146 /* Analyze the options */
1147 for (i = 0; i < 32; i++)
1149 /* Process valid flags */
1150 if (mask[n] & (1L << i))
1152 /* Process valid flags */
1153 if (window_mask[n] & (1L << i))
1156 if (flag[n] & (1L << i))
1159 window_flag[n] |= (1L << i);
1166 window_flag[n] &= ~(1L << i);
1179 * Hack -- strip the "ghost" info
1181 * XXX XXX XXX This is such a nasty hack it hurts.
1183 static void rd_ghost(void)
1190 /* Strip old data */
1198 * Read the "extra" information
1200 static void rd_extra(void)
1207 rd_string(player_name, 32);
1209 rd_string(died_from, 80);
1211 for (i = 0; i < 4; i++)
1213 rd_string(history[i], 60);
1216 /* Class/Race/Seikaku/Gender/Spells */
1217 rd_byte(&p_ptr->prace);
1218 rd_byte(&p_ptr->pclass);
1219 rd_byte(&p_ptr->pseikaku);
1220 rd_byte(&p_ptr->psex);
1221 rd_byte(&p_ptr->realm1);
1222 rd_byte(&p_ptr->realm2);
1223 rd_byte(&tmp8u); /* oops */
1225 if (z_older_than(10, 4, 4))
1227 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1228 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1229 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1230 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1233 /* Special Race/Class info */
1234 rd_byte(&p_ptr->hitdie);
1235 rd_u16b(&p_ptr->expfact);
1237 /* Age/Height/Weight */
1238 rd_s16b(&p_ptr->age);
1239 rd_s16b(&p_ptr->ht);
1240 rd_s16b(&p_ptr->wt);
1242 /* Read the stat info */
1243 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1244 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1245 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1247 strip_bytes(24); /* oops */
1249 rd_s32b(&p_ptr->au);
1251 rd_s32b(&p_ptr->max_exp);
1252 rd_s32b(&p_ptr->exp);
1253 rd_u16b(&p_ptr->exp_frac);
1255 rd_s16b(&p_ptr->lev);
1257 for (i = 0; i < 64; i++) rd_s16b(&spell_exp[i]);
1258 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1260 for (i = 0; i < 64; i++) spell_exp[i] = 1600;
1262 if (z_older_than(10, 3, 6))
1263 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&weapon_exp[i][j]);
1265 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&weapon_exp[i][j]);
1266 for (i = 0; i < 10; i++) rd_s16b(&skill_exp[i]);
1267 if (z_older_than(10, 4, 1))
1269 if (p_ptr->pclass != CLASS_BEASTMASTER) skill_exp[GINOU_RIDING] /= 2;
1270 skill_exp[GINOU_RIDING] = MIN(skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1272 if (z_older_than(10, 3, 14))
1274 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1275 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1279 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1280 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1282 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1284 if (z_older_than(11, 0, 7))
1286 p_ptr->start_race = p_ptr->prace;
1287 p_ptr->old_race1 = 0L;
1288 p_ptr->old_race2 = 0L;
1289 p_ptr->old_realm = 0;
1293 rd_byte(&p_ptr->start_race);
1294 rd_s32b(&p_ptr->old_race1);
1295 rd_s32b(&p_ptr->old_race2);
1296 rd_s16b(&p_ptr->old_realm);
1299 if (z_older_than(10, 0, 1))
1301 for (i = 0; i < OLD_MAX_MANE; i++)
1308 else if (z_older_than(10, 2, 3))
1310 for (i = 0; i < OLD_MAX_MANE; i++)
1315 for (i = 0; i < MAX_MANE; i++)
1325 for (i = 0; i < MAX_MANE; i++)
1327 rd_s16b(&mane_spell[i]);
1328 rd_s16b(&mane_dam[i]);
1333 if (z_older_than(10, 0, 3))
1335 get_mon_num_prep(NULL, NULL);
1336 for (i = 0; i < MAX_KUBI; i++)
1338 monster_race *r_ptr;
1343 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1344 r_ptr = &r_info[kubi_r_idx[i]];
1346 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1348 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1350 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1352 for (j = 0; j < i; j++)
1353 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1358 for (i = 0; i < MAX_KUBI -1; i++)
1361 for (j = i; j < MAX_KUBI; j++)
1363 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1365 tmp = kubi_r_idx[i];
1366 kubi_r_idx[i] = kubi_r_idx[j];
1367 kubi_r_idx[j] = tmp;
1371 for (i = 0; i < MAX_KUBI; i++)
1373 if(!r_info[kubi_r_idx[i]].max_num)
1374 kubi_r_idx[i] += 10000;
1379 for (i = 0; i < MAX_KUBI; i++)
1381 rd_s16b(&kubi_r_idx[i]);
1385 if (z_older_than(10, 0, 3))
1391 for (i = 0; i < 4; i++)
1393 rd_s16b(&battle_mon[i]);
1394 if (z_older_than(10, 3, 4))
1397 mon_odds[i] = tmp16s;
1399 else rd_u32b(&mon_odds[i]);
1403 rd_s16b(&p_ptr->town_num);
1405 /* Read arena and rewards information */
1406 rd_s16b(&p_ptr->arena_number);
1408 p_ptr->inside_arena = (bool)tmp16s;
1409 rd_s16b(&p_ptr->inside_quest);
1410 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1414 p_ptr->inside_battle = (bool)tmp16s;
1416 rd_byte(&p_ptr->exit_bldg);
1417 rd_byte(&p_ptr->leftbldg);
1419 rd_s16b(&p_ptr->oldpx);
1420 rd_s16b(&p_ptr->oldpy);
1421 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1425 if (tmp16s > MAX_BACT)
1428 note(format("¤ÎÃæ", tmp16s));
1430 note(format("Too many (%d) building rewards!", tmp16s));
1435 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1437 rd_s16b(&p_ptr->mhp);
1438 rd_s16b(&p_ptr->chp);
1439 rd_u16b(&p_ptr->chp_frac);
1441 rd_s16b(&p_ptr->msp);
1442 rd_s16b(&p_ptr->csp);
1443 rd_u16b(&p_ptr->csp_frac);
1445 rd_s16b(&p_ptr->max_plv);
1446 if (z_older_than(10, 3, 8))
1448 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1452 byte max = (byte)max_d_idx;
1456 for(i = 0; i < max; i++)
1458 rd_s16b(&max_dlv[i]);
1459 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1463 /* Repair maximum player level XXX XXX XXX */
1464 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1468 rd_s16b(&p_ptr->sc);
1471 /* Read the flags */
1472 strip_bytes(2); /* Old "rest" */
1473 rd_s16b(&p_ptr->blind);
1474 rd_s16b(&p_ptr->paralyzed);
1475 rd_s16b(&p_ptr->confused);
1476 rd_s16b(&p_ptr->food);
1477 strip_bytes(4); /* Old "food_digested" / "protection" */
1478 rd_s16b(&p_ptr->energy);
1479 rd_s16b(&p_ptr->fast);
1480 rd_s16b(&p_ptr->slow);
1481 rd_s16b(&p_ptr->afraid);
1482 rd_s16b(&p_ptr->cut);
1483 rd_s16b(&p_ptr->stun);
1484 rd_s16b(&p_ptr->poisoned);
1485 rd_s16b(&p_ptr->image);
1486 rd_s16b(&p_ptr->protevil);
1487 rd_s16b(&p_ptr->invuln);
1488 if(z_older_than(10, 0, 0))
1491 rd_s16b(&p_ptr->ult_res);
1492 rd_s16b(&p_ptr->hero);
1493 rd_s16b(&p_ptr->shero);
1494 rd_s16b(&p_ptr->shield);
1495 rd_s16b(&p_ptr->blessed);
1496 rd_s16b(&p_ptr->tim_invis);
1497 rd_s16b(&p_ptr->word_recall);
1498 if (z_older_than(10, 3, 8))
1499 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1503 p_ptr->recall_dungeon = (byte)tmp16s;
1505 rd_s16b(&p_ptr->see_infra);
1506 rd_s16b(&p_ptr->tim_infra);
1507 rd_s16b(&p_ptr->oppose_fire);
1508 rd_s16b(&p_ptr->oppose_cold);
1509 rd_s16b(&p_ptr->oppose_acid);
1510 rd_s16b(&p_ptr->oppose_elec);
1511 rd_s16b(&p_ptr->oppose_pois);
1512 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1513 else rd_s16b(&p_ptr->tsuyoshi);
1515 /* Old savefiles do not have the following fields... */
1516 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1519 p_ptr->wraith_form = 0;
1520 p_ptr->resist_magic = 0;
1521 p_ptr->tim_regen = 0;
1522 p_ptr->kabenuke = 0;
1523 p_ptr->tim_stealth = 0;
1524 p_ptr->tim_ffall = 0;
1525 p_ptr->tim_sh_touki = 0;
1526 p_ptr->lightspeed = 0;
1527 p_ptr->tsubureru = 0;
1528 p_ptr->tim_res_nether = 0;
1529 p_ptr->tim_res_time = 0;
1530 p_ptr->mimic_form = 0;
1531 p_ptr->tim_mimic = 0;
1532 p_ptr->tim_sh_fire = 0;
1535 p_ptr->tim_reflect = 0;
1536 p_ptr->multishadow = 0;
1537 p_ptr->dustrobe = 0;
1539 p_ptr->chaos_patron = get_chaos_patron();
1547 rd_s16b(&p_ptr->tim_esp);
1548 rd_s16b(&p_ptr->wraith_form);
1549 rd_s16b(&p_ptr->resist_magic);
1550 rd_s16b(&p_ptr->tim_regen);
1551 rd_s16b(&p_ptr->kabenuke);
1552 rd_s16b(&p_ptr->tim_stealth);
1553 rd_s16b(&p_ptr->tim_ffall);
1554 rd_s16b(&p_ptr->tim_sh_touki);
1555 rd_s16b(&p_ptr->lightspeed);
1556 rd_s16b(&p_ptr->tsubureru);
1557 if (z_older_than(10, 4, 7))
1558 p_ptr->magicdef = 0;
1560 rd_s16b(&p_ptr->magicdef);
1561 rd_s16b(&p_ptr->tim_res_nether);
1562 if (z_older_than(10, 4, 11))
1564 p_ptr->tim_res_time = 0;
1565 p_ptr->mimic_form = 0;
1566 p_ptr->tim_mimic = 0;
1567 p_ptr->tim_sh_fire = 0;
1571 rd_s16b(&p_ptr->tim_res_time);
1572 rd_byte(&p_ptr->mimic_form);
1573 rd_s16b(&p_ptr->tim_mimic);
1574 rd_s16b(&p_ptr->tim_sh_fire);
1578 if ( z_older_than(11,0,3) ){
1579 p_ptr->tim_reflect=0;
1580 p_ptr->multishadow=0;
1584 rd_s16b(&p_ptr->tim_reflect);
1585 rd_s16b(&p_ptr->multishadow);
1586 rd_s16b(&p_ptr->dustrobe);
1589 rd_s16b(&p_ptr->chaos_patron);
1590 rd_u32b(&p_ptr->muta1);
1591 rd_u32b(&p_ptr->muta2);
1592 rd_u32b(&p_ptr->muta3);
1594 for (i = 0; i < 8; i++)
1595 rd_s16b(&p_ptr->virtues[i]);
1596 for (i = 0; i < 8; i++)
1597 rd_s16b(&p_ptr->vir_types[i]);
1600 /* Calc the regeneration modifier for mutations */
1601 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1603 if (z_older_than(10,0,9))
1606 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1607 p_ptr->ele_attack = 0;
1611 rd_s16b(&p_ptr->ele_attack);
1612 rd_u32b(&p_ptr->special_attack);
1614 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1615 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1616 if (z_older_than(10,0,12))
1618 p_ptr->ele_immune = 0;
1619 p_ptr->special_defense = 0;
1623 rd_s16b(&p_ptr->ele_immune);
1624 rd_u32b(&p_ptr->special_defense);
1626 rd_byte(&p_ptr->knowledge);
1627 rd_byte(&tmp8u); /* oops */
1628 rd_byte(&tmp8u); /* oops */
1629 rd_byte(&p_ptr->action);
1630 if (!z_older_than(10, 4, 3))
1633 if (tmp8u) p_ptr->action = ACTION_LEARN;
1635 rd_byte((byte *)&preserve_mode);
1636 rd_byte((byte *)&wait_report_score);
1639 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1641 /* Skip the flags */
1645 /* Hack -- the two "special seeds" */
1646 rd_u32b(&seed_flavor);
1647 rd_u32b(&seed_town);
1651 rd_u16b(&panic_save);
1652 rd_u16b(&total_winner);
1660 /* Read "feeling" */
1664 /* Turn of last "feeling" */
1670 if (z_older_than(10, 3, 12))
1672 dungeon_turn = turn;
1674 else rd_s32b(&dungeon_turn);
1676 if (z_older_than(10, 3, 13))
1680 else rd_s32b(&old_battle);
1682 if (z_older_than(10,0,3))
1684 monster_race *r_ptr;
1688 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1689 r_ptr = &r_info[today_mon];
1691 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1692 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1693 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1694 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1695 if (r_ptr->rarity > 10) continue;
1696 if (r_ptr->level == 0) continue;
1700 p_ptr->today_mon = 0;
1704 rd_s16b(&today_mon);
1705 rd_s16b(&p_ptr->today_mon);
1708 if (z_older_than(10,0,7))
1714 rd_s16b(&p_ptr->riding);
1717 if (z_older_than(10,1,2))
1726 if (z_older_than(10,3,9))
1730 else if (z_older_than(10, 3, 10))
1738 rd_s32b(&p_ptr->visit);
1740 if (!z_older_than(11, 0, 5))
1742 rd_u32b(&p_ptr->count);
1750 * Read the player inventory
1752 * Note that the inventory changed in Angband 2.7.4. Two extra
1753 * pack slots were added and the equipment was rearranged. Note
1754 * that these two features combine when parsing old save-files, in
1755 * which items from the old "aux" slot are "carried", perhaps into
1756 * one of the two new "inventory" slots.
1758 * Note that the inventory is "re-sorted" later by "dungeon()".
1760 static errr rd_inventory(void)
1768 p_ptr->total_weight = 0;
1774 /* Read until done */
1779 /* Get the next item index */
1782 /* Nope, we reached the end */
1783 if (n == 0xFFFF) break;
1785 /* Get local object */
1788 /* Wipe the object */
1794 /* Hack -- verify item */
1795 if (!q_ptr->k_idx) return (53);
1797 /* Wield equipment */
1798 if (n >= INVEN_RARM)
1801 object_copy(&inventory[n], q_ptr);
1803 /* Add the weight */
1804 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1810 /* Warning -- backpack is full */
1811 else if (inven_cnt == INVEN_PACK)
1815 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1817 note("Too many items in the inventory!");
1825 /* Carry inventory */
1832 object_copy(&inventory[n], q_ptr);
1834 /* Add the weight */
1835 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1849 * Read the saved messages
1851 static void rd_messages(void)
1861 /* Read the messages */
1862 for (i = 0; i < num; i++)
1864 /* Read the message */
1865 rd_string(buf, 128);
1867 /* Save the message */
1877 * The monsters/objects must be loaded in the same order
1878 * that they were stored, since the actual indexes matter.
1880 static errr rd_dungeon(void)
1891 /*** Basic info ***/
1894 rd_s16b(&dun_level);
1895 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1896 else rd_byte(&dungeon_type);
1898 /* Set the base level for old versions */
1899 base_level = dun_level;
1901 rd_s16b(&base_level);
1903 rd_s16b(&num_repro);
1908 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1911 rd_s16b(&max_panel_rows);
1912 rd_s16b(&max_panel_cols);
1915 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1923 /*** Run length decoding ***/
1925 /* Load the dungeon data */
1926 for (x = y = 0; y < ymax; )
1930 if (z_older_than(10,3,6))
1935 /* Apply the RLE info */
1936 for (i = count; i > 0; i--)
1938 /* Access the cave */
1939 c_ptr = &cave[y][x];
1941 /* Extract "info" */
1942 if (z_older_than(10,3,6))
1943 c_ptr->info = tmp8u;
1944 else c_ptr->info = tmp16s;
1953 if (++y >= ymax) break;
1959 /*** Run length decoding ***/
1961 /* Load the dungeon data */
1962 for (x = y = 0; y < ymax; )
1968 /* Apply the RLE info */
1969 for (i = count; i > 0; i--)
1971 /* Access the cave */
1972 c_ptr = &cave[y][x];
1974 if (c_ptr->feat == FEAT_INVIS)
1976 c_ptr->feat = FEAT_FLOOR;
1977 c_ptr->info |= CAVE_TRAP;
1980 /* Extract "feat" */
1981 c_ptr->feat = tmp8u;
1990 if (++y >= ymax) break;
1995 /*** Run length decoding ***/
1997 /* Load the dungeon data */
1998 for (x = y = 0; y < ymax; )
2004 /* Apply the RLE info */
2005 for (i = count; i > 0; i--)
2007 /* Access the cave */
2008 c_ptr = &cave[y][x];
2010 /* Extract "feat" */
2011 c_ptr->mimic = tmp8u;
2020 if (++y >= ymax) break;
2025 /*** Run length decoding ***/
2027 /* Load the dungeon data */
2028 for (x = y = 0; y < ymax; )
2034 /* Apply the RLE info */
2035 for (i = count; i > 0; i--)
2037 /* Access the cave */
2038 c_ptr = &cave[y][x];
2040 /* Extract "feat" */
2041 c_ptr->special = tmp16s;
2050 if (++y >= ymax) break;
2057 /* Read the item count */
2060 /* Verify maximum */
2061 if (limit >= max_o_idx)
2064 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2066 note(format("Too many (%d) object entries!", limit));
2072 /* Read the dungeon items */
2073 for (i = 1; i < limit; i++)
2080 /* Get a new record */
2087 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2089 note(format("Object allocation error (%d <> %d)", i, o_idx));
2097 o_ptr = &o_list[o_idx];
2103 /* XXX XXX XXX XXX XXX */
2106 if (o_ptr->held_m_idx)
2108 monster_type *m_ptr;
2111 m_ptr = &m_list[o_ptr->held_m_idx];
2114 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2116 /* Place the object */
2117 m_ptr->hold_o_idx = o_idx;
2123 /* Access the item location */
2124 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2127 o_ptr->next_o_idx = c_ptr->o_idx;
2129 /* Place the object */
2130 c_ptr->o_idx = o_idx;
2137 /* Read the monster count */
2140 /* Hack -- verify */
2141 if (limit >= max_m_idx)
2144 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2146 note(format("Too many (%d) monster entries!", limit));
2152 /* Read the monsters */
2153 for (i = 1; i < limit; i++)
2157 monster_type *m_ptr;
2159 monster_race *r_ptr;
2162 /* Get a new record */
2169 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2171 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2178 /* Acquire monster */
2179 m_ptr = &m_list[m_idx];
2181 /* Read the monster */
2186 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2188 /* Mark the location */
2189 c_ptr->m_idx = m_idx;
2193 r_ptr = &r_info[m_ptr->r_idx];
2195 /* Count XXX XXX XXX */
2201 /* The dungeon is ready */
2202 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2203 character_dungeon = FALSE;
2205 character_dungeon = TRUE;
2214 * Actually read the savefile
2216 static errr rd_savefile_new_aux(void)
2228 #ifdef VERIFY_CHECKSUMS
2229 u32b n_x_check, n_v_check;
2230 u32b o_x_check, o_v_check;
2234 /* Mention the savefile version */
2236 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2238 note(format("Loading a %d.%d.%d savefile...",
2241 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2244 /* Strip the version bytes */
2247 /* Hack -- decrypt */
2248 xor_byte = sf_extra;
2251 /* Clear the checksums */
2255 #if SAVEFILE_VERSION
2256 /* Read the version number of the savefile */
2257 rd_u32b(&sf_version);
2258 #endif /* SAVEFILE_VERSION */
2260 /* Operating system info */
2263 /* Time of savefile creation */
2266 /* Number of resurrections */
2269 /* Number of times played */
2273 /* Later use (always zero) */
2276 /* Later use (always zero) */
2280 /* Read RNG state */
2283 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2285 if (arg_fiddle) note("Loaded Randomizer Info");
2290 /* Then the options */
2293 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2295 if (arg_fiddle) note("Loaded Option Flags");
2299 * Munchkin players are marked
2301 * XXX - should be replaced with a better method,
2302 * after the new scorefile-handling is implemented.
2310 /* Then the "messages" */
2313 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2315 if (arg_fiddle) note("Loaded Messages");
2320 for (i = 0; i < max_r_idx; i++)
2322 monster_race *r_ptr;
2323 /* Access that monster */
2326 /* Hack -- Reset the death counter */
2327 r_ptr->max_num = 100;
2328 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2329 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2332 /* Monster Memory */
2335 /* Incompatible save files */
2336 if (tmp16u > max_r_idx)
2339 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2341 note(format("Too many (%u) monster races!", tmp16u));
2347 /* Read the available records */
2348 for (i = 0; i < tmp16u; i++)
2350 monster_race *r_ptr;
2355 /* Access that monster */
2360 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2362 if (arg_fiddle) note("Loaded Monster Memory");
2370 /* Incompatible save files */
2371 if (tmp16u > max_k_idx)
2374 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2376 note(format("Too many (%u) object kinds!", tmp16u));
2382 /* Read the object memory */
2383 for (i = 0; i < tmp16u; i++)
2386 object_kind *k_ptr = &k_info[i];
2390 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2391 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2394 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2396 if (arg_fiddle) note("Loaded Object Memory");
2402 * Initialize arena and rewards information
2404 p_ptr->arena_number = 0;
2405 p_ptr->inside_arena = 0;
2406 p_ptr->inside_quest = 0;
2407 p_ptr->leftbldg = FALSE;
2408 p_ptr->exit_bldg = TRUE;
2410 /* Start in town 1 */
2411 p_ptr->town_num = 1;
2413 p_ptr->wilderness_x = 4;
2414 p_ptr->wilderness_y = 4;
2418 /* Init the wilderness seeds */
2419 for (i = 0; i < max_wild_x; i++)
2421 for (j = 0; j < max_wild_y; j++)
2423 wilderness[j][i].seed = randint0(0x10000000);
2427 /* 2.1.3 or newer version */
2429 u16b max_towns_load;
2430 u16b max_quests_load;
2431 byte max_rquests_load;
2432 s16b old_inside_quest = p_ptr->inside_quest;
2434 /* Number of towns */
2435 rd_u16b(&max_towns_load);
2437 /* Incompatible save files */
2438 if (max_towns_load > max_towns)
2441 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2443 note(format("Too many (%u) towns!", max_towns_load));
2449 /* Number of quests */
2450 rd_u16b(&max_quests_load);
2452 if (z_older_than(11, 0, 7))
2454 max_rquests_load = 10;
2458 rd_byte(&max_rquests_load);
2461 /* Incompatible save files */
2462 if (max_quests_load > max_quests)
2465 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2467 note(format("Too many (%u) quests!", max_quests_load));
2473 for (i = 0; i < max_quests_load; i++)
2477 rd_s16b(&quest[i].status);
2478 rd_s16b(&quest[i].level);
2480 if (z_older_than(11, 0, 6))
2482 quest[i].complev = 0;
2486 rd_byte(&quest[i].complev);
2489 /* Load quest status if quest is running */
2490 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))))
2492 rd_s16b(&quest[i].cur_num);
2493 rd_s16b(&quest[i].max_num);
2494 rd_s16b(&quest[i].type);
2496 /* Load quest monster index */
2497 rd_s16b(&quest[i].r_idx);
2499 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2504 monster_race *r_ptr;
2507 * Random monster 5 - 10 levels out of depth
2508 * (depending on level)
2510 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
2511 r_ptr = &r_info[r_idx];
2513 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2515 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2517 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2519 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2521 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2524 * Accept monsters that are 2 - 6 levels
2525 * out of depth depending on the quest level
2527 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2530 quest[i].r_idx = r_idx;
2533 /* Load quest item index */
2534 rd_s16b(&quest[i].k_idx);
2537 a_info[quest[i].k_idx].flags3 |= TR3_QUESTITEM;
2539 rd_byte(&quest[i].flags);
2541 if (z_older_than(10, 3, 11))
2543 if (quest[i].flags & QUEST_FLAG_PRESET)
2545 quest[i].dungeon = 0;
2549 init_flags = INIT_ASSIGN;
2550 p_ptr->inside_quest = i;
2552 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2553 p_ptr->inside_quest = old_inside_quest;
2558 rd_byte(&quest[i].dungeon);
2561 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2562 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2563 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2566 /* Ignore the empty quests from old versions */
2569 /* Ignore quest status */
2572 /* Ignore quest level */
2576 * We don't have to care about the other info,
2577 * since status should be 0 for these quests anyway
2582 /* Position in the wilderness */
2583 rd_s32b(&p_ptr->wilderness_x);
2584 rd_s32b(&p_ptr->wilderness_y);
2585 if (z_older_than(10, 3, 13))
2587 p_ptr->wilderness_x = 5;
2588 p_ptr->wilderness_y = 48;
2591 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2592 else rd_byte((byte *)&p_ptr->wild_mode);
2593 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2594 else rd_byte((byte *)&ambush_flag);
2596 /* Size of the wilderness */
2597 rd_s32b(&wild_x_size);
2598 rd_s32b(&wild_y_size);
2600 /* Incompatible save files */
2601 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2604 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2606 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2612 /* Load the wilderness seeds */
2613 for (i = 0; i < wild_x_size; i++)
2615 for (j = 0; j < wild_y_size; j++)
2617 rd_u32b(&wilderness[j][i].seed);
2623 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2625 if (arg_fiddle) note("Loaded Quests");
2628 /* Load the Artifacts */
2631 /* Incompatible save files */
2632 if (tmp16u > max_a_idx)
2635 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2637 note(format("Too many (%u) artifacts!", tmp16u));
2643 /* Read the artifact flags */
2644 for (i = 0; i < tmp16u; i++)
2647 a_info[i].cur_num = tmp8u;
2653 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2655 if (arg_fiddle) note("Loaded Artifacts");
2660 /* Read the extra stuff */
2662 if (p_ptr->energy > 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(&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) && !death)
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) && !death)
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) && !death)
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) && !death)
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(&spell_learned1);
2726 rd_u32b(&spell_learned2);
2727 rd_u32b(&spell_worked1);
2728 rd_u32b(&spell_worked2);
2729 rd_u32b(&spell_forgotten1);
2730 rd_u32b(&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 (spell_learned1 & (1L << i)) :
2740 (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(&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... */
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 */