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 (z_older_than(11, 0, 10))
356 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
358 switch (o_ptr->xtra2 % 6)
360 case 0: o_ptr->art_flags2 |= (TR2_SUST_STR); break;
361 case 1: o_ptr->art_flags2 |= (TR2_SUST_INT); break;
362 case 2: o_ptr->art_flags2 |= (TR2_SUST_WIS); break;
363 case 3: o_ptr->art_flags2 |= (TR2_SUST_DEX); break;
364 case 4: o_ptr->art_flags2 |= (TR2_SUST_CON); break;
365 case 5: o_ptr->art_flags2 |= (TR2_SUST_CHR); break;
369 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
371 switch (o_ptr->xtra2 % 11)
373 case 0: o_ptr->art_flags2 |= (TR2_RES_BLIND); break;
374 case 1: o_ptr->art_flags2 |= (TR2_RES_CONF); break;
375 case 2: o_ptr->art_flags2 |= (TR2_RES_SOUND); break;
376 case 3: o_ptr->art_flags2 |= (TR2_RES_SHARDS); break;
377 case 4: o_ptr->art_flags2 |= (TR2_RES_NETHER); break;
378 case 5: o_ptr->art_flags2 |= (TR2_RES_NEXUS); break;
379 case 6: o_ptr->art_flags2 |= (TR2_RES_CHAOS); break;
380 case 7: o_ptr->art_flags2 |= (TR2_RES_DISEN); break;
381 case 8: o_ptr->art_flags2 |= (TR2_RES_POIS); break;
382 case 9: o_ptr->art_flags2 |= (TR2_RES_DARK); break;
383 case 10: o_ptr->art_flags2 |= (TR2_RES_LITE); break;
387 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
389 switch (o_ptr->xtra2 % 8)
391 case 0: o_ptr->art_flags3 |= (TR3_FEATHER); break;
392 case 1: o_ptr->art_flags3 |= (TR3_LITE); break;
393 case 2: o_ptr->art_flags3 |= (TR3_SEE_INVIS); break;
394 case 3: o_ptr->art_flags3 |= (TR3_WARNING); break;
395 case 4: o_ptr->art_flags3 |= (TR3_SLOW_DIGEST); break;
396 case 5: o_ptr->art_flags3 |= (TR3_REGEN); break;
397 case 6: o_ptr->art_flags2 |= (TR2_FREE_ACT); break;
398 case 7: o_ptr->art_flags2 |= (TR2_HOLD_LIFE); break;
405 if (z_older_than(10, 2, 3))
410 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
412 o_ptr->xtra3 = o_ptr->xtra1;
415 if (o_ptr->tval == TV_CAPTURE)
417 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
418 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
420 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
421 if (ironman_nightmare)
423 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
425 o_ptr->xtra4 = o_ptr->xtra5;
430 rd_byte(&o_ptr->xtra3);
431 rd_s16b(&o_ptr->xtra4);
432 rd_s16b(&o_ptr->xtra5);
435 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)))
437 o_ptr->xtra4 = o_ptr->pval;
441 /* Feeling - from 2.3.1, "savefile version 1" */
444 rd_byte(&o_ptr->feeling);
450 /* If this savefile is old, maybe we need to translate the feeling */
455 for (i = 0; i <= FEEL_MAX; i++)
457 if (game_inscriptions[i] == NULL)
462 if (streq(buf, game_inscriptions[i]))
471 /* Save the inscription */
472 if (buf[0]) o_ptr->inscription = quark_add(buf);
475 if (buf[0]) o_ptr->art_name = quark_add(buf);
477 /* The Python object */
485 /* Mega-Hack -- handle "dungeon objects" later */
486 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
488 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
490 /* Obtain the "kind" template */
491 k_ptr = &k_info[o_ptr->k_idx];
493 /* Obtain tval/sval from k_info */
494 o_ptr->tval = k_ptr->tval;
495 o_ptr->sval = k_ptr->sval;
497 /* Hack -- notice "broken" items */
498 if (k_ptr->cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
501 /* Repair non "wearable" items */
502 if (!wearable_p(o_ptr))
504 /* Acquire correct fields */
505 o_ptr->to_h = k_ptr->to_h;
506 o_ptr->to_d = k_ptr->to_d;
507 o_ptr->to_a = k_ptr->to_a;
509 /* Acquire correct fields */
510 o_ptr->ac = k_ptr->ac;
511 o_ptr->dd = k_ptr->dd;
512 o_ptr->ds = k_ptr->ds;
514 /* Acquire correct weight */
515 o_ptr->weight = k_ptr->weight;
518 o_ptr->name1 = o_ptr->name2 = 0;
525 /* Extract the flags */
526 object_flags(o_ptr, &f1, &f2, &f3);
528 if (z_older_than(10, 4, 9))
530 if (o_ptr->art_flags1 & TR1_MAGIC_MASTERY)
532 o_ptr->art_flags1 &= ~(TR1_MAGIC_MASTERY);
533 o_ptr->art_flags3 |= (TR3_DEC_MANA);
540 artifact_type *a_ptr;
542 /* Obtain the artifact info */
543 a_ptr = &a_info[o_ptr->name1];
545 /* Verify that artifact */
546 if (!a_ptr->name) o_ptr->name1 = 0;
552 ego_item_type *e_ptr;
554 /* Obtain the ego-item info */
555 e_ptr = &e_info[o_ptr->name2];
557 /* Verify that ego-item */
558 if (!e_ptr->name) o_ptr->name2 = 0;
562 /* Acquire standard fields */
563 o_ptr->ac = k_ptr->ac;
564 o_ptr->dd = k_ptr->dd;
565 o_ptr->ds = k_ptr->ds;
567 /* Acquire standard weight */
568 o_ptr->weight = k_ptr->weight;
570 /* Hack -- extract the "broken" flag */
571 if (!o_ptr->pval < 0) o_ptr->ident |= (IDENT_BROKEN);
576 artifact_type *a_ptr;
578 /* Obtain the artifact info */
579 a_ptr = &a_info[o_ptr->name1];
581 /* Acquire new artifact "pval" */
582 o_ptr->pval = a_ptr->pval;
584 /* Acquire new artifact fields */
585 o_ptr->ac = a_ptr->ac;
586 o_ptr->dd = a_ptr->dd;
587 o_ptr->ds = a_ptr->ds;
589 /* Acquire new artifact weight */
590 o_ptr->weight = a_ptr->weight;
592 /* Hack -- extract the "broken" flag */
593 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
599 ego_item_type *e_ptr;
601 /* Obtain the ego-item info */
602 e_ptr = &e_info[o_ptr->name2];
607 if (o_ptr->name2 == EGO_DWARVEN)
610 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
613 /* Hack -- extract the "broken" flag */
614 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
617 if (o_ptr->art_name) /* A random artifact */
630 static void rd_monster(monster_type *m_ptr)
635 /* Read the monster race */
636 rd_s16b(&m_ptr->r_idx);
638 /* Read the other information */
642 rd_s16b(&m_ptr->maxhp);
643 if (z_older_than(11, 0, 5))
645 m_ptr->max_maxhp = m_ptr->maxhp;
649 rd_s16b(&m_ptr->max_maxhp);
651 rd_s16b(&m_ptr->csleep);
652 rd_byte(&m_ptr->mspeed);
653 if (z_older_than(10, 4, 2))
656 m_ptr->energy = (s16b)tmp8u;
658 else rd_s16b(&m_ptr->energy);
659 if (z_older_than(10,0,7))
666 rd_byte(&m_ptr->fast);
667 rd_byte(&m_ptr->slow);
669 rd_byte(&m_ptr->stunned);
670 rd_byte(&m_ptr->confused);
671 rd_byte(&m_ptr->monfear);
673 if (z_older_than(10,0,10))
677 else if (z_older_than(10,0,11))
685 rd_s16b(&m_ptr->target_y);
686 rd_s16b(&m_ptr->target_x);
689 /* Monster invulnerability introduced from 2.3.2+ */
693 rd_byte(&m_ptr->invulner);
695 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
696 rd_u32b(&m_ptr->smart);
700 if (z_older_than(10, 4, 5))
703 rd_u32b(&m_ptr->exp);
705 if (z_older_than(10, 2, 2))
707 if (m_ptr->r_idx < 0)
709 m_ptr->r_idx = (0-m_ptr->r_idx);
710 m_ptr->mflag2 |= MFLAG_KAGE;
715 rd_byte(&m_ptr->mflag2);
718 if (z_older_than(10, 1, 3))
725 if (buf[0]) m_ptr->nickname = quark_add(buf);
736 * Read the monster lore
738 static void rd_lore(int r_idx)
742 monster_race *r_ptr = &r_info[r_idx];
744 /* Count sights/deaths/kills */
745 rd_s16b(&r_ptr->r_sights);
746 rd_s16b(&r_ptr->r_deaths);
747 rd_s16b(&r_ptr->r_pkills);
748 rd_s16b(&r_ptr->r_tkills);
750 /* Count wakes and ignores */
751 rd_byte(&r_ptr->r_wake);
752 rd_byte(&r_ptr->r_ignore);
755 rd_byte(&r_ptr->r_xtra1);
756 rd_byte(&r_ptr->r_xtra2);
759 rd_byte(&r_ptr->r_drop_gold);
760 rd_byte(&r_ptr->r_drop_item);
763 rd_byte(&r_ptr->r_cast_inate);
764 rd_byte(&r_ptr->r_cast_spell);
766 /* Count blows of each type */
767 rd_byte(&r_ptr->r_blows[0]);
768 rd_byte(&r_ptr->r_blows[1]);
769 rd_byte(&r_ptr->r_blows[2]);
770 rd_byte(&r_ptr->r_blows[3]);
773 rd_u32b(&r_ptr->r_flags1);
774 rd_u32b(&r_ptr->r_flags2);
775 rd_u32b(&r_ptr->r_flags3);
776 rd_u32b(&r_ptr->r_flags4);
777 rd_u32b(&r_ptr->r_flags5);
778 rd_u32b(&r_ptr->r_flags6);
780 /* Read the "Racial" monster limit per level */
781 rd_byte(&r_ptr->max_num);
788 /* Repair the lore flags */
789 r_ptr->r_flags1 &= r_ptr->flags1;
790 r_ptr->r_flags2 &= r_ptr->flags2;
791 r_ptr->r_flags3 &= r_ptr->flags3;
792 r_ptr->r_flags4 &= r_ptr->flags4;
793 r_ptr->r_flags5 &= r_ptr->flags5;
794 r_ptr->r_flags6 &= r_ptr->flags6;
801 * Add the item "o_ptr" to the inventory of the "Home"
803 * In all cases, return the slot (or -1) where the object was placed
805 * Note that this is a hacked up version of "inven_carry()".
807 * Also note that it may not correctly "adapt" to "knowledge" bacoming
808 * known, the player may have to pick stuff up and drop it again.
810 static void home_carry(store_type *st_ptr, object_type *o_ptr)
818 /* Check each existing item (try to combine) */
819 for (slot = 0; slot < st_ptr->stock_num; slot++)
821 /* Get the existing item */
822 j_ptr = &st_ptr->stock[slot];
824 /* The home acts just like the player */
825 if (object_similar(j_ptr, o_ptr))
827 /* Save the new number of items */
828 object_absorb(j_ptr, o_ptr);
836 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
840 /* Determine the "value" of the item */
841 value = object_value(o_ptr);
843 /* Check existing slots to see if we must "slide" */
844 for (slot = 0; slot < st_ptr->stock_num; slot++)
847 j_ptr = &st_ptr->stock[slot];
849 /* Hack -- readable books always come first */
850 if ((o_ptr->tval == mp_ptr->spell_book) &&
851 (j_ptr->tval != mp_ptr->spell_book)) break;
852 if ((j_ptr->tval == mp_ptr->spell_book) &&
853 (o_ptr->tval != mp_ptr->spell_book)) continue;
855 /* Objects sort by decreasing type */
856 if (o_ptr->tval > j_ptr->tval) break;
857 if (o_ptr->tval < j_ptr->tval) continue;
859 /* Can happen in the home */
860 if (!object_aware_p(o_ptr)) continue;
861 if (!object_aware_p(j_ptr)) break;
863 /* Objects sort by increasing sval */
864 if (o_ptr->sval < j_ptr->sval) break;
865 if (o_ptr->sval > j_ptr->sval) continue;
867 /* Objects in the home can be unknown */
868 if (!object_known_p(o_ptr)) continue;
869 if (!object_known_p(j_ptr)) break;
872 * Hack: otherwise identical rods sort by
873 * increasing recharge time --dsb
875 if (o_ptr->tval == TV_ROD)
877 if (o_ptr->pval < j_ptr->pval) break;
878 if (o_ptr->pval > j_ptr->pval) continue;
881 /* Objects sort by decreasing value */
882 j_value = object_value(j_ptr);
883 if (value > j_value) break;
884 if (value < j_value) continue;
887 /* Slide the others up */
888 for (i = st_ptr->stock_num; i > slot; i--)
890 st_ptr->stock[i] = st_ptr->stock[i-1];
896 /* Insert the new item */
897 st_ptr->stock[slot] = *o_ptr;
899 chg_virtue(V_SACRIFICE, -1);
901 /* Return the location */
909 static errr rd_store(int town_number, int store_number)
921 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
923 st_ptr = &town[1].store[store_number];
924 if (st_ptr->stock_num) sort = TRUE;
928 st_ptr = &town[town_number].store[store_number];
931 /* Read the basic info */
932 rd_s32b(&st_ptr->store_open);
933 rd_s16b(&st_ptr->insult_cur);
935 if (z_older_than(11, 0, 4))
944 rd_s16b(&st_ptr->good_buy);
945 rd_s16b(&st_ptr->bad_buy);
947 /* Read last visit */
948 rd_s32b(&st_ptr->last_visit);
950 /* Extract the owner (see above) */
954 for (j = 0; j < num; j++)
959 /* Get local object */
962 /* Wipe the object */
968 /* Acquire valid items */
969 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
974 home_carry(st_ptr, q_ptr);
978 k = st_ptr->stock_num++;
980 /* Acquire the item */
981 object_copy(&st_ptr->stock[k], q_ptr);
993 * Read RNG state (added in 2.8.0)
995 static void rd_randomizer(void)
1005 rd_u16b(&Rand_place);
1008 for (i = 0; i < RAND_DEG; i++)
1010 rd_u32b(&Rand_state[i]);
1020 * Read options (ignore most pre-2.8.0 options)
1022 * Note that the normal options are now stored as a set of 256 bit flags,
1023 * plus a set of 256 bit masks to indicate which bit flags were defined
1024 * at the time the savefile was created. This will allow new options
1025 * to be added, and old options to be removed, at any time, without
1026 * hurting old savefiles.
1028 * The window options are stored in the same way, but note that each
1029 * window gets 32 options, and their order is fixed by certain defines.
1031 static void rd_options(void)
1045 /* Ignore old options */
1049 /*** Special info */
1051 /* Read "delay_factor" */
1055 /* Read "hitpoint_warn" */
1060 /*** Cheating options ***/
1064 if (c & 0x0002) wizard = TRUE;
1066 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1067 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1068 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1069 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1070 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1071 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1073 rd_byte((byte *)&autosave_l);
1074 rd_byte((byte *)&autosave_t);
1075 rd_s16b(&autosave_freq);
1078 /*** Normal Options ***/
1080 /* Read the option flags */
1081 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1083 /* Read the option masks */
1084 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1086 /* Analyze the options */
1087 for (n = 0; n < 8; n++)
1089 /* Analyze the options */
1090 for (i = 0; i < 32; i++)
1092 /* Process valid flags */
1093 if (mask[n] & (1L << i))
1095 /* Process valid flags */
1096 if (option_mask[n] & (1L << i))
1099 if (flag[n] & (1L << i))
1102 option_flag[n] |= (1L << i);
1109 option_flag[n] &= ~(1L << i);
1116 if (z_older_than(10, 4, 5))
1118 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1119 else option_flag[5] |= (0x00000001 << 4);
1120 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1121 else option_flag[2] |= (0x00000001 << 5);
1122 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1123 else option_flag[4] |= (0x00000001 << 5);
1124 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1125 else option_flag[5] |= (0x00000001 << 0);
1126 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1127 else option_flag[5] |= (0x00000001 << 12);
1128 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1129 else option_flag[1] |= (0x00000001 << 0);
1130 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1131 else option_flag[1] |= (0x00000001 << 18);
1132 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1133 else option_flag[1] |= (0x00000001 << 19);
1134 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1135 else option_flag[5] |= (0x00000001 << 3);
1139 /*** Window Options ***/
1141 /* Read the window flags */
1142 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1144 /* Read the window masks */
1145 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1147 /* Analyze the options */
1148 for (n = 0; n < 8; n++)
1150 /* Analyze the options */
1151 for (i = 0; i < 32; i++)
1153 /* Process valid flags */
1154 if (mask[n] & (1L << i))
1156 /* Process valid flags */
1157 if (window_mask[n] & (1L << i))
1160 if (flag[n] & (1L << i))
1163 window_flag[n] |= (1L << i);
1170 window_flag[n] &= ~(1L << i);
1183 * Hack -- strip the "ghost" info
1185 * XXX XXX XXX This is such a nasty hack it hurts.
1187 static void rd_ghost(void)
1194 /* Strip old data */
1202 * Read the "extra" information
1204 static void rd_extra(void)
1211 rd_string(player_name, 32);
1213 rd_string(died_from, 80);
1215 for (i = 0; i < 4; i++)
1217 rd_string(history[i], 60);
1220 /* Class/Race/Seikaku/Gender/Spells */
1221 rd_byte(&p_ptr->prace);
1222 rd_byte(&p_ptr->pclass);
1223 rd_byte(&p_ptr->pseikaku);
1224 rd_byte(&p_ptr->psex);
1225 rd_byte(&p_ptr->realm1);
1226 rd_byte(&p_ptr->realm2);
1227 rd_byte(&tmp8u); /* oops */
1229 if (z_older_than(10, 4, 4))
1231 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1232 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1233 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1234 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1237 /* Special Race/Class info */
1238 rd_byte(&p_ptr->hitdie);
1239 rd_u16b(&p_ptr->expfact);
1241 /* Age/Height/Weight */
1242 rd_s16b(&p_ptr->age);
1243 rd_s16b(&p_ptr->ht);
1244 rd_s16b(&p_ptr->wt);
1246 /* Read the stat info */
1247 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1248 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1249 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1251 strip_bytes(24); /* oops */
1253 rd_s32b(&p_ptr->au);
1255 rd_s32b(&p_ptr->max_exp);
1256 rd_s32b(&p_ptr->exp);
1257 rd_u16b(&p_ptr->exp_frac);
1259 rd_s16b(&p_ptr->lev);
1261 for (i = 0; i < 64; i++) rd_s16b(&spell_exp[i]);
1262 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1264 for (i = 0; i < 64; i++) spell_exp[i] = 1600;
1266 if (z_older_than(10, 3, 6))
1267 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&weapon_exp[i][j]);
1269 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&weapon_exp[i][j]);
1270 for (i = 0; i < 10; i++) rd_s16b(&skill_exp[i]);
1271 if (z_older_than(10, 4, 1))
1273 if (p_ptr->pclass != CLASS_BEASTMASTER) skill_exp[GINOU_RIDING] /= 2;
1274 skill_exp[GINOU_RIDING] = MIN(skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1276 if (z_older_than(10, 3, 14))
1278 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1279 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1283 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1284 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1286 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1288 if (z_older_than(11, 0, 7))
1290 p_ptr->start_race = p_ptr->prace;
1291 p_ptr->old_race1 = 0L;
1292 p_ptr->old_race2 = 0L;
1293 p_ptr->old_realm = 0;
1297 rd_byte(&p_ptr->start_race);
1298 rd_s32b(&p_ptr->old_race1);
1299 rd_s32b(&p_ptr->old_race2);
1300 rd_s16b(&p_ptr->old_realm);
1303 if (z_older_than(10, 0, 1))
1305 for (i = 0; i < OLD_MAX_MANE; i++)
1312 else if (z_older_than(10, 2, 3))
1314 for (i = 0; i < OLD_MAX_MANE; i++)
1319 for (i = 0; i < MAX_MANE; i++)
1329 for (i = 0; i < MAX_MANE; i++)
1331 rd_s16b(&mane_spell[i]);
1332 rd_s16b(&mane_dam[i]);
1337 if (z_older_than(10, 0, 3))
1339 get_mon_num_prep(NULL, NULL);
1340 for (i = 0; i < MAX_KUBI; i++)
1342 monster_race *r_ptr;
1347 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1348 r_ptr = &r_info[kubi_r_idx[i]];
1350 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1352 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1354 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1356 for (j = 0; j < i; j++)
1357 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1362 for (i = 0; i < MAX_KUBI -1; i++)
1365 for (j = i; j < MAX_KUBI; j++)
1367 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1369 tmp = kubi_r_idx[i];
1370 kubi_r_idx[i] = kubi_r_idx[j];
1371 kubi_r_idx[j] = tmp;
1375 for (i = 0; i < MAX_KUBI; i++)
1377 if(!r_info[kubi_r_idx[i]].max_num)
1378 kubi_r_idx[i] += 10000;
1383 for (i = 0; i < MAX_KUBI; i++)
1385 rd_s16b(&kubi_r_idx[i]);
1389 if (z_older_than(10, 0, 3))
1395 for (i = 0; i < 4; i++)
1397 rd_s16b(&battle_mon[i]);
1398 if (z_older_than(10, 3, 4))
1401 mon_odds[i] = tmp16s;
1403 else rd_u32b(&mon_odds[i]);
1407 rd_s16b(&p_ptr->town_num);
1409 /* Read arena and rewards information */
1410 rd_s16b(&p_ptr->arena_number);
1412 p_ptr->inside_arena = (bool)tmp16s;
1413 rd_s16b(&p_ptr->inside_quest);
1414 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1418 p_ptr->inside_battle = (bool)tmp16s;
1420 rd_byte(&p_ptr->exit_bldg);
1421 rd_byte(&p_ptr->leftbldg);
1423 rd_s16b(&p_ptr->oldpx);
1424 rd_s16b(&p_ptr->oldpy);
1425 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1429 if (tmp16s > MAX_BACT)
1432 note(format("¤ÎÃæ", tmp16s));
1434 note(format("Too many (%d) building rewards!", tmp16s));
1439 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1441 rd_s16b(&p_ptr->mhp);
1442 rd_s16b(&p_ptr->chp);
1443 rd_u16b(&p_ptr->chp_frac);
1445 rd_s16b(&p_ptr->msp);
1446 rd_s16b(&p_ptr->csp);
1447 rd_u16b(&p_ptr->csp_frac);
1449 rd_s16b(&p_ptr->max_plv);
1450 if (z_older_than(10, 3, 8))
1452 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1456 byte max = (byte)max_d_idx;
1460 for(i = 0; i < max; i++)
1462 rd_s16b(&max_dlv[i]);
1463 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1467 /* Repair maximum player level XXX XXX XXX */
1468 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1472 rd_s16b(&p_ptr->sc);
1475 /* Read the flags */
1476 strip_bytes(2); /* Old "rest" */
1477 rd_s16b(&p_ptr->blind);
1478 rd_s16b(&p_ptr->paralyzed);
1479 rd_s16b(&p_ptr->confused);
1480 rd_s16b(&p_ptr->food);
1481 strip_bytes(4); /* Old "food_digested" / "protection" */
1482 rd_s16b(&p_ptr->energy);
1483 rd_s16b(&p_ptr->fast);
1484 rd_s16b(&p_ptr->slow);
1485 rd_s16b(&p_ptr->afraid);
1486 rd_s16b(&p_ptr->cut);
1487 rd_s16b(&p_ptr->stun);
1488 rd_s16b(&p_ptr->poisoned);
1489 rd_s16b(&p_ptr->image);
1490 rd_s16b(&p_ptr->protevil);
1491 rd_s16b(&p_ptr->invuln);
1492 if(z_older_than(10, 0, 0))
1495 rd_s16b(&p_ptr->ult_res);
1496 rd_s16b(&p_ptr->hero);
1497 rd_s16b(&p_ptr->shero);
1498 rd_s16b(&p_ptr->shield);
1499 rd_s16b(&p_ptr->blessed);
1500 rd_s16b(&p_ptr->tim_invis);
1501 rd_s16b(&p_ptr->word_recall);
1502 if (z_older_than(10, 3, 8))
1503 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1507 p_ptr->recall_dungeon = (byte)tmp16s;
1509 rd_s16b(&p_ptr->see_infra);
1510 rd_s16b(&p_ptr->tim_infra);
1511 rd_s16b(&p_ptr->oppose_fire);
1512 rd_s16b(&p_ptr->oppose_cold);
1513 rd_s16b(&p_ptr->oppose_acid);
1514 rd_s16b(&p_ptr->oppose_elec);
1515 rd_s16b(&p_ptr->oppose_pois);
1516 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1517 else rd_s16b(&p_ptr->tsuyoshi);
1519 /* Old savefiles do not have the following fields... */
1520 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1523 p_ptr->wraith_form = 0;
1524 p_ptr->resist_magic = 0;
1525 p_ptr->tim_regen = 0;
1526 p_ptr->kabenuke = 0;
1527 p_ptr->tim_stealth = 0;
1528 p_ptr->tim_ffall = 0;
1529 p_ptr->tim_sh_touki = 0;
1530 p_ptr->lightspeed = 0;
1531 p_ptr->tsubureru = 0;
1532 p_ptr->tim_res_nether = 0;
1533 p_ptr->tim_res_time = 0;
1534 p_ptr->mimic_form = 0;
1535 p_ptr->tim_mimic = 0;
1536 p_ptr->tim_sh_fire = 0;
1539 p_ptr->tim_reflect = 0;
1540 p_ptr->multishadow = 0;
1541 p_ptr->dustrobe = 0;
1543 p_ptr->chaos_patron = get_chaos_patron();
1551 rd_s16b(&p_ptr->tim_esp);
1552 rd_s16b(&p_ptr->wraith_form);
1553 rd_s16b(&p_ptr->resist_magic);
1554 rd_s16b(&p_ptr->tim_regen);
1555 rd_s16b(&p_ptr->kabenuke);
1556 rd_s16b(&p_ptr->tim_stealth);
1557 rd_s16b(&p_ptr->tim_ffall);
1558 rd_s16b(&p_ptr->tim_sh_touki);
1559 rd_s16b(&p_ptr->lightspeed);
1560 rd_s16b(&p_ptr->tsubureru);
1561 if (z_older_than(10, 4, 7))
1562 p_ptr->magicdef = 0;
1564 rd_s16b(&p_ptr->magicdef);
1565 rd_s16b(&p_ptr->tim_res_nether);
1566 if (z_older_than(10, 4, 11))
1568 p_ptr->tim_res_time = 0;
1569 p_ptr->mimic_form = 0;
1570 p_ptr->tim_mimic = 0;
1571 p_ptr->tim_sh_fire = 0;
1575 rd_s16b(&p_ptr->tim_res_time);
1576 rd_byte(&p_ptr->mimic_form);
1577 rd_s16b(&p_ptr->tim_mimic);
1578 rd_s16b(&p_ptr->tim_sh_fire);
1582 if ( z_older_than(11,0,3) ){
1583 p_ptr->tim_reflect=0;
1584 p_ptr->multishadow=0;
1588 rd_s16b(&p_ptr->tim_reflect);
1589 rd_s16b(&p_ptr->multishadow);
1590 rd_s16b(&p_ptr->dustrobe);
1593 rd_s16b(&p_ptr->chaos_patron);
1594 rd_u32b(&p_ptr->muta1);
1595 rd_u32b(&p_ptr->muta2);
1596 rd_u32b(&p_ptr->muta3);
1598 for (i = 0; i < 8; i++)
1599 rd_s16b(&p_ptr->virtues[i]);
1600 for (i = 0; i < 8; i++)
1601 rd_s16b(&p_ptr->vir_types[i]);
1604 /* Calc the regeneration modifier for mutations */
1605 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1607 if (z_older_than(10,0,9))
1610 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1611 p_ptr->ele_attack = 0;
1615 rd_s16b(&p_ptr->ele_attack);
1616 rd_u32b(&p_ptr->special_attack);
1618 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1619 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1620 if (z_older_than(10,0,12))
1622 p_ptr->ele_immune = 0;
1623 p_ptr->special_defense = 0;
1627 rd_s16b(&p_ptr->ele_immune);
1628 rd_u32b(&p_ptr->special_defense);
1630 rd_byte(&p_ptr->knowledge);
1631 rd_byte(&tmp8u); /* oops */
1632 rd_byte(&tmp8u); /* oops */
1633 rd_byte(&p_ptr->action);
1634 if (!z_older_than(10, 4, 3))
1637 if (tmp8u) p_ptr->action = ACTION_LEARN;
1639 rd_byte((byte *)&preserve_mode);
1640 rd_byte((byte *)&wait_report_score);
1643 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1645 /* Skip the flags */
1649 /* Hack -- the two "special seeds" */
1650 rd_u32b(&seed_flavor);
1651 rd_u32b(&seed_town);
1655 rd_u16b(&panic_save);
1656 rd_u16b(&total_winner);
1664 /* Read "feeling" */
1668 /* Turn of last "feeling" */
1674 if (z_older_than(10, 3, 12))
1676 dungeon_turn = turn;
1678 else rd_s32b(&dungeon_turn);
1680 if (z_older_than(10, 3, 13))
1684 else rd_s32b(&old_battle);
1686 if (z_older_than(10,0,3))
1688 monster_race *r_ptr;
1692 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1693 r_ptr = &r_info[today_mon];
1695 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1696 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1697 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1698 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1699 if (r_ptr->rarity > 10) continue;
1700 if (r_ptr->level == 0) continue;
1704 p_ptr->today_mon = 0;
1708 rd_s16b(&today_mon);
1709 rd_s16b(&p_ptr->today_mon);
1712 if (z_older_than(10,0,7))
1718 rd_s16b(&p_ptr->riding);
1721 if (z_older_than(10,1,2))
1730 if (z_older_than(10,3,9))
1734 else if (z_older_than(10, 3, 10))
1742 rd_s32b(&p_ptr->visit);
1744 if (!z_older_than(11, 0, 5))
1746 rd_u32b(&p_ptr->count);
1754 * Read the player inventory
1756 * Note that the inventory changed in Angband 2.7.4. Two extra
1757 * pack slots were added and the equipment was rearranged. Note
1758 * that these two features combine when parsing old save-files, in
1759 * which items from the old "aux" slot are "carried", perhaps into
1760 * one of the two new "inventory" slots.
1762 * Note that the inventory is "re-sorted" later by "dungeon()".
1764 static errr rd_inventory(void)
1772 p_ptr->total_weight = 0;
1778 /* Read until done */
1783 /* Get the next item index */
1786 /* Nope, we reached the end */
1787 if (n == 0xFFFF) break;
1789 /* Get local object */
1792 /* Wipe the object */
1798 /* Hack -- verify item */
1799 if (!q_ptr->k_idx) return (53);
1801 /* Wield equipment */
1802 if (n >= INVEN_RARM)
1805 object_copy(&inventory[n], q_ptr);
1807 /* Add the weight */
1808 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1814 /* Warning -- backpack is full */
1815 else if (inven_cnt == INVEN_PACK)
1819 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1821 note("Too many items in the inventory!");
1829 /* Carry inventory */
1836 object_copy(&inventory[n], q_ptr);
1838 /* Add the weight */
1839 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1853 * Read the saved messages
1855 static void rd_messages(void)
1865 /* Read the messages */
1866 for (i = 0; i < num; i++)
1868 /* Read the message */
1869 rd_string(buf, 128);
1871 /* Save the message */
1881 * The monsters/objects must be loaded in the same order
1882 * that they were stored, since the actual indexes matter.
1884 static errr rd_dungeon(void)
1895 /*** Basic info ***/
1898 rd_s16b(&dun_level);
1899 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1900 else rd_byte(&dungeon_type);
1902 /* Set the base level for old versions */
1903 base_level = dun_level;
1905 rd_s16b(&base_level);
1907 rd_s16b(&num_repro);
1912 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1915 rd_s16b(&tmp16s); /* max_panel_rows */
1916 rd_s16b(&tmp16s); /* max_panel_cols */
1919 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1927 /*** Run length decoding ***/
1929 /* Load the dungeon data */
1930 for (x = y = 0; y < ymax; )
1934 if (z_older_than(10,3,6))
1939 /* Apply the RLE info */
1940 for (i = count; i > 0; i--)
1942 /* Access the cave */
1943 c_ptr = &cave[y][x];
1945 /* Extract "info" */
1946 if (z_older_than(10,3,6))
1947 c_ptr->info = tmp8u;
1948 else c_ptr->info = tmp16s;
1957 if (++y >= ymax) break;
1963 /*** Run length decoding ***/
1965 /* Load the dungeon data */
1966 for (x = y = 0; y < ymax; )
1972 /* Apply the RLE info */
1973 for (i = count; i > 0; i--)
1975 /* Access the cave */
1976 c_ptr = &cave[y][x];
1978 if (c_ptr->feat == FEAT_INVIS)
1980 c_ptr->feat = FEAT_FLOOR;
1981 c_ptr->info |= CAVE_TRAP;
1984 /* Extract "feat" */
1985 c_ptr->feat = tmp8u;
1994 if (++y >= ymax) break;
1999 /*** Run length decoding ***/
2001 /* Load the dungeon data */
2002 for (x = y = 0; y < ymax; )
2008 /* Apply the RLE info */
2009 for (i = count; i > 0; i--)
2011 /* Access the cave */
2012 c_ptr = &cave[y][x];
2014 /* Extract "feat" */
2015 c_ptr->mimic = tmp8u;
2024 if (++y >= ymax) break;
2029 /*** Run length decoding ***/
2031 /* Load the dungeon data */
2032 for (x = y = 0; y < ymax; )
2038 /* Apply the RLE info */
2039 for (i = count; i > 0; i--)
2041 /* Access the cave */
2042 c_ptr = &cave[y][x];
2044 /* Extract "feat" */
2045 c_ptr->special = tmp16s;
2054 if (++y >= ymax) break;
2061 /* Read the item count */
2064 /* Verify maximum */
2065 if (limit >= max_o_idx)
2068 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2070 note(format("Too many (%d) object entries!", limit));
2076 /* Read the dungeon items */
2077 for (i = 1; i < limit; i++)
2084 /* Get a new record */
2091 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2093 note(format("Object allocation error (%d <> %d)", i, o_idx));
2101 o_ptr = &o_list[o_idx];
2107 /* XXX XXX XXX XXX XXX */
2110 if (o_ptr->held_m_idx)
2112 monster_type *m_ptr;
2115 m_ptr = &m_list[o_ptr->held_m_idx];
2118 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2120 /* Place the object */
2121 m_ptr->hold_o_idx = o_idx;
2127 /* Access the item location */
2128 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2131 o_ptr->next_o_idx = c_ptr->o_idx;
2133 /* Place the object */
2134 c_ptr->o_idx = o_idx;
2141 /* Read the monster count */
2144 /* Hack -- verify */
2145 if (limit >= max_m_idx)
2148 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2150 note(format("Too many (%d) monster entries!", limit));
2156 /* Read the monsters */
2157 for (i = 1; i < limit; i++)
2161 monster_type *m_ptr;
2163 monster_race *r_ptr;
2166 /* Get a new record */
2173 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2175 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2182 /* Acquire monster */
2183 m_ptr = &m_list[m_idx];
2185 /* Read the monster */
2190 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2192 /* Mark the location */
2193 c_ptr->m_idx = m_idx;
2197 r_ptr = &r_info[m_ptr->r_idx];
2199 /* Count XXX XXX XXX */
2205 /* The dungeon is ready */
2206 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2207 character_dungeon = FALSE;
2209 character_dungeon = TRUE;
2218 * Actually read the savefile
2220 static errr rd_savefile_new_aux(void)
2232 #ifdef VERIFY_CHECKSUMS
2233 u32b n_x_check, n_v_check;
2234 u32b o_x_check, o_v_check;
2238 /* Mention the savefile version */
2240 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2242 note(format("Loading a %d.%d.%d savefile...",
2245 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2248 /* Strip the version bytes */
2251 /* Hack -- decrypt */
2252 xor_byte = sf_extra;
2255 /* Clear the checksums */
2259 #if SAVEFILE_VERSION
2260 /* Read the version number of the savefile */
2261 rd_u32b(&sf_version);
2262 #endif /* SAVEFILE_VERSION */
2264 /* Operating system info */
2267 /* Time of savefile creation */
2270 /* Number of resurrections */
2273 /* Number of times played */
2277 /* Later use (always zero) */
2280 /* Later use (always zero) */
2284 /* Read RNG state */
2287 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2289 if (arg_fiddle) note("Loaded Randomizer Info");
2294 /* Then the options */
2297 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2299 if (arg_fiddle) note("Loaded Option Flags");
2303 * Munchkin players are marked
2305 * XXX - should be replaced with a better method,
2306 * after the new scorefile-handling is implemented.
2314 /* Then the "messages" */
2317 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2319 if (arg_fiddle) note("Loaded Messages");
2324 for (i = 0; i < max_r_idx; i++)
2326 monster_race *r_ptr;
2327 /* Access that monster */
2330 /* Hack -- Reset the death counter */
2331 r_ptr->max_num = 100;
2332 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2333 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2336 /* Monster Memory */
2339 /* Incompatible save files */
2340 if (tmp16u > max_r_idx)
2343 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2345 note(format("Too many (%u) monster races!", tmp16u));
2351 /* Read the available records */
2352 for (i = 0; i < tmp16u; i++)
2354 monster_race *r_ptr;
2359 /* Access that monster */
2364 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2366 if (arg_fiddle) note("Loaded Monster Memory");
2374 /* Incompatible save files */
2375 if (tmp16u > max_k_idx)
2378 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2380 note(format("Too many (%u) object kinds!", tmp16u));
2386 /* Read the object memory */
2387 for (i = 0; i < tmp16u; i++)
2390 object_kind *k_ptr = &k_info[i];
2394 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2395 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2398 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2400 if (arg_fiddle) note("Loaded Object Memory");
2406 * Initialize arena and rewards information
2408 p_ptr->arena_number = 0;
2409 p_ptr->inside_arena = 0;
2410 p_ptr->inside_quest = 0;
2411 p_ptr->leftbldg = FALSE;
2412 p_ptr->exit_bldg = TRUE;
2414 /* Start in town 1 */
2415 p_ptr->town_num = 1;
2417 p_ptr->wilderness_x = 4;
2418 p_ptr->wilderness_y = 4;
2422 /* Init the wilderness seeds */
2423 for (i = 0; i < max_wild_x; i++)
2425 for (j = 0; j < max_wild_y; j++)
2427 wilderness[j][i].seed = randint0(0x10000000);
2431 /* 2.1.3 or newer version */
2433 u16b max_towns_load;
2434 u16b max_quests_load;
2435 byte max_rquests_load;
2436 s16b old_inside_quest = p_ptr->inside_quest;
2438 /* Number of towns */
2439 rd_u16b(&max_towns_load);
2441 /* Incompatible save files */
2442 if (max_towns_load > max_towns)
2445 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2447 note(format("Too many (%u) towns!", max_towns_load));
2453 /* Number of quests */
2454 rd_u16b(&max_quests_load);
2456 if (z_older_than(11, 0, 7))
2458 max_rquests_load = 10;
2462 rd_byte(&max_rquests_load);
2465 /* Incompatible save files */
2466 if (max_quests_load > max_quests)
2469 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2471 note(format("Too many (%u) quests!", max_quests_load));
2477 for (i = 0; i < max_quests_load; i++)
2481 rd_s16b(&quest[i].status);
2482 rd_s16b(&quest[i].level);
2484 if (z_older_than(11, 0, 6))
2486 quest[i].complev = 0;
2490 rd_byte(&quest[i].complev);
2493 /* Load quest status if quest is running */
2494 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))))
2496 rd_s16b(&quest[i].cur_num);
2497 rd_s16b(&quest[i].max_num);
2498 rd_s16b(&quest[i].type);
2500 /* Load quest monster index */
2501 rd_s16b(&quest[i].r_idx);
2503 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2508 monster_race *r_ptr;
2511 * Random monster 5 - 10 levels out of depth
2512 * (depending on level)
2514 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
2515 r_ptr = &r_info[r_idx];
2517 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2519 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2521 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2523 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2525 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2528 * Accept monsters that are 2 - 6 levels
2529 * out of depth depending on the quest level
2531 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2534 quest[i].r_idx = r_idx;
2537 /* Load quest item index */
2538 rd_s16b(&quest[i].k_idx);
2541 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
2543 rd_byte(&quest[i].flags);
2545 if (z_older_than(10, 3, 11))
2547 if (quest[i].flags & QUEST_FLAG_PRESET)
2549 quest[i].dungeon = 0;
2553 init_flags = INIT_ASSIGN;
2554 p_ptr->inside_quest = i;
2556 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2557 p_ptr->inside_quest = old_inside_quest;
2562 rd_byte(&quest[i].dungeon);
2565 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2566 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2567 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2570 /* Ignore the empty quests from old versions */
2573 /* Ignore quest status */
2576 /* Ignore quest level */
2580 * We don't have to care about the other info,
2581 * since status should be 0 for these quests anyway
2586 /* Position in the wilderness */
2587 rd_s32b(&p_ptr->wilderness_x);
2588 rd_s32b(&p_ptr->wilderness_y);
2589 if (z_older_than(10, 3, 13))
2591 p_ptr->wilderness_x = 5;
2592 p_ptr->wilderness_y = 48;
2595 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2596 else rd_byte((byte *)&p_ptr->wild_mode);
2597 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2598 else rd_byte((byte *)&ambush_flag);
2600 /* Size of the wilderness */
2601 rd_s32b(&wild_x_size);
2602 rd_s32b(&wild_y_size);
2604 /* Incompatible save files */
2605 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2608 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2610 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2616 /* Load the wilderness seeds */
2617 for (i = 0; i < wild_x_size; i++)
2619 for (j = 0; j < wild_y_size; j++)
2621 rd_u32b(&wilderness[j][i].seed);
2627 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2629 if (arg_fiddle) note("Loaded Quests");
2632 /* Load the Artifacts */
2635 /* Incompatible save files */
2636 if (tmp16u > max_a_idx)
2639 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2641 note(format("Too many (%u) artifacts!", tmp16u));
2647 /* Read the artifact flags */
2648 for (i = 0; i < tmp16u; i++)
2651 a_info[i].cur_num = tmp8u;
2657 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2659 if (arg_fiddle) note("Loaded Artifacts");
2664 /* Read the extra stuff */
2666 if (p_ptr->energy > 999) world_player = TRUE;
2668 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2670 if (arg_fiddle) note("Loaded extra information");
2674 /* Read the player_hp array */
2677 /* Incompatible save files */
2678 if (tmp16u > PY_MAX_LEVEL)
2681 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2683 note(format("Too many (%u) hitpoint entries!", tmp16u));
2689 /* Read the player_hp array */
2690 for (i = 0; i < tmp16u; i++)
2692 rd_s16b(&player_hp[i]);
2695 /* Important -- Initialize the sex */
2696 sp_ptr = &sex_info[p_ptr->psex];
2698 /* Important -- Initialize the race/class */
2699 rp_ptr = &race_info[p_ptr->prace];
2700 cp_ptr = &class_info[p_ptr->pclass];
2701 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2703 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !death)
2705 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2706 do_cmd_rerate(FALSE);
2708 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !death)
2710 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2711 do_cmd_rerate(FALSE);
2713 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !death)
2715 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2716 do_cmd_rerate(FALSE);
2718 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !death)
2720 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2721 do_cmd_rerate(FALSE);
2724 /* Important -- Initialize the magic */
2725 mp_ptr = &m_info[p_ptr->pclass];
2728 /* Read spell info */
2729 rd_u32b(&spell_learned1);
2730 rd_u32b(&spell_learned2);
2731 rd_u32b(&spell_worked1);
2732 rd_u32b(&spell_worked2);
2733 rd_u32b(&spell_forgotten1);
2734 rd_u32b(&spell_forgotten2);
2736 if (z_older_than(10,0,5))
2738 p_ptr->learned_spells = 0;
2739 for (i = 0; i < 64; i++)
2741 /* Count known spells */
2743 (spell_learned1 & (1L << i)) :
2744 (spell_learned2 & (1L << (i - 32))))
2746 p_ptr->learned_spells++;
2750 else rd_s16b(&p_ptr->learned_spells);
2752 if (z_older_than(10,0,6))
2754 p_ptr->add_spells = 0;
2756 else rd_s16b(&p_ptr->add_spells);
2757 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2759 for (i = 0; i < 64; i++)
2761 rd_byte(&spell_order[i]);
2765 /* Read the inventory */
2769 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2771 note("Unable to read inventory");
2777 /* Read number of towns */
2779 town_count = tmp16u;
2781 /* Read the stores */
2783 for (i = 1; i < town_count; i++)
2785 for (j = 0; j < tmp16u; j++)
2787 if (rd_store(i, j)) return (22);
2791 rd_s16b(&p_ptr->pet_follow_distance);
2792 if (z_older_than(10, 4, 10))
2794 p_ptr->pet_extra_flags = 0;
2796 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2798 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2800 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2804 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2807 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2811 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2814 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2818 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2821 if (!z_older_than(10,0,8))
2824 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2829 rd_s16b(&p_ptr->pet_extra_flags);
2832 if (!z_older_than(11, 0, 9))
2834 char buf[SCREEN_BUF_SIZE];
2835 rd_string(buf, SCREEN_BUF_SIZE);
2836 if (buf[0]) screen_dump = string_make(buf);
2841 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2843 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2848 /* I'm not dead yet... */
2851 /* Dead players have no dungeon */
2853 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2855 note("Restoring Dungeon...");
2861 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2863 note("Error reading dungeon data");
2869 /* Read the ghost info */
2876 strip_bytes(tmp32s);
2881 #ifdef VERIFY_CHECKSUMS
2883 /* Save the checksum */
2884 n_v_check = v_check;
2886 /* Read the old checksum */
2887 rd_u32b(&o_v_check);
2890 if (o_v_check != n_v_check)
2893 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2895 note("Invalid checksum");
2902 /* Save the encoded checksum */
2903 n_x_check = x_check;
2905 /* Read the checksum */
2906 rd_u32b(&o_x_check);
2910 if (o_x_check != n_x_check)
2913 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2915 note("Invalid encoded checksum");
2929 * Actually read the savefile
2931 errr rd_savefile_new(void)
2935 /* The savefile is a binary file */
2936 fff = my_fopen(savefile, "rb");
2939 if (!fff) return (-1);
2941 /* Call the sub-function */
2942 err = rd_savefile_new_aux();
2944 /* Check for errors */
2945 if (ferror(fff)) err = -1;
2947 /* Close the file */