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 if (z_older_than(11, 0, 11))
349 o_ptr->curse_flags = 0L;
350 if (o_ptr->ident & 0x40)
352 o_ptr->curse_flags |= TRC_CURSED;
353 if (o_ptr->art_flags3 & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
354 if (o_ptr->art_flags3 & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
357 artifact_type *a_ptr = &a_info[o_ptr->name1];
358 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
359 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
361 else if (o_ptr->name2)
363 ego_item_type *e_ptr = &e_info[o_ptr->name2];
364 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
365 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
368 o_ptr->art_flags3 &= (0x1FFFFFFFL);
372 rd_u32b(&o_ptr->curse_flags);
375 /* Monster holding object */
376 rd_s16b(&o_ptr->held_m_idx);
379 rd_byte(&o_ptr->xtra1);
380 rd_byte(&o_ptr->xtra2);
382 if (z_older_than(11, 0, 10))
384 if (o_ptr->xtra1 == EGO_XTRA_SUSTAIN)
386 switch (o_ptr->xtra2 % 6)
388 case 0: o_ptr->art_flags2 |= (TR2_SUST_STR); break;
389 case 1: o_ptr->art_flags2 |= (TR2_SUST_INT); break;
390 case 2: o_ptr->art_flags2 |= (TR2_SUST_WIS); break;
391 case 3: o_ptr->art_flags2 |= (TR2_SUST_DEX); break;
392 case 4: o_ptr->art_flags2 |= (TR2_SUST_CON); break;
393 case 5: o_ptr->art_flags2 |= (TR2_SUST_CHR); break;
397 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
399 switch (o_ptr->xtra2 % 11)
401 case 0: o_ptr->art_flags2 |= (TR2_RES_BLIND); break;
402 case 1: o_ptr->art_flags2 |= (TR2_RES_CONF); break;
403 case 2: o_ptr->art_flags2 |= (TR2_RES_SOUND); break;
404 case 3: o_ptr->art_flags2 |= (TR2_RES_SHARDS); break;
405 case 4: o_ptr->art_flags2 |= (TR2_RES_NETHER); break;
406 case 5: o_ptr->art_flags2 |= (TR2_RES_NEXUS); break;
407 case 6: o_ptr->art_flags2 |= (TR2_RES_CHAOS); break;
408 case 7: o_ptr->art_flags2 |= (TR2_RES_DISEN); break;
409 case 8: o_ptr->art_flags2 |= (TR2_RES_POIS); break;
410 case 9: o_ptr->art_flags2 |= (TR2_RES_DARK); break;
411 case 10: o_ptr->art_flags2 |= (TR2_RES_LITE); break;
415 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
417 switch (o_ptr->xtra2 % 8)
419 case 0: o_ptr->art_flags3 |= (TR3_FEATHER); break;
420 case 1: o_ptr->art_flags3 |= (TR3_LITE); break;
421 case 2: o_ptr->art_flags3 |= (TR3_SEE_INVIS); break;
422 case 3: o_ptr->art_flags3 |= (TR3_WARNING); break;
423 case 4: o_ptr->art_flags3 |= (TR3_SLOW_DIGEST); break;
424 case 5: o_ptr->art_flags3 |= (TR3_REGEN); break;
425 case 6: o_ptr->art_flags2 |= (TR2_FREE_ACT); break;
426 case 7: o_ptr->art_flags2 |= (TR2_HOLD_LIFE); break;
433 if (z_older_than(10, 2, 3))
438 if ((o_ptr->tval == TV_CHEST) || (o_ptr->tval == TV_CAPTURE))
440 o_ptr->xtra3 = o_ptr->xtra1;
443 if (o_ptr->tval == TV_CAPTURE)
445 if (r_info[o_ptr->pval].flags1 & RF1_FORCE_MAXHP)
446 o_ptr->xtra5 = maxroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
448 o_ptr->xtra5 = damroll(r_info[o_ptr->pval].hdice, r_info[o_ptr->pval].hside);
449 if (ironman_nightmare)
451 o_ptr->xtra5 = (s16b)MIN(30000, o_ptr->xtra5*2L);
453 o_ptr->xtra4 = o_ptr->xtra5;
458 rd_byte(&o_ptr->xtra3);
459 rd_s16b(&o_ptr->xtra4);
460 rd_s16b(&o_ptr->xtra5);
463 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)))
465 o_ptr->xtra4 = o_ptr->pval;
469 /* Feeling - from 2.3.1, "savefile version 1" */
472 rd_byte(&o_ptr->feeling);
478 /* If this savefile is old, maybe we need to translate the feeling */
483 for (i = 0; i <= FEEL_MAX; i++)
485 if (game_inscriptions[i] == NULL)
490 if (streq(buf, game_inscriptions[i]))
499 /* Save the inscription */
500 if (buf[0]) o_ptr->inscription = quark_add(buf);
503 if (buf[0]) o_ptr->art_name = quark_add(buf);
505 /* The Python object */
513 /* Mega-Hack -- handle "dungeon objects" later */
514 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
516 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
518 /* Obtain the "kind" template */
519 k_ptr = &k_info[o_ptr->k_idx];
521 /* Obtain tval/sval from k_info */
522 o_ptr->tval = k_ptr->tval;
523 o_ptr->sval = k_ptr->sval;
525 /* Hack -- notice "broken" items */
526 if (k_ptr->cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
529 /* Repair non "wearable" items */
530 if (!wearable_p(o_ptr))
532 /* Acquire correct fields */
533 o_ptr->to_h = k_ptr->to_h;
534 o_ptr->to_d = k_ptr->to_d;
535 o_ptr->to_a = k_ptr->to_a;
537 /* Acquire correct fields */
538 o_ptr->ac = k_ptr->ac;
539 o_ptr->dd = k_ptr->dd;
540 o_ptr->ds = k_ptr->ds;
542 /* Acquire correct weight */
543 o_ptr->weight = k_ptr->weight;
546 o_ptr->name1 = o_ptr->name2 = 0;
553 /* Extract the flags */
554 object_flags(o_ptr, &f1, &f2, &f3);
556 if (z_older_than(10, 4, 9))
558 if (o_ptr->art_flags1 & TR1_MAGIC_MASTERY)
560 o_ptr->art_flags1 &= ~(TR1_MAGIC_MASTERY);
561 o_ptr->art_flags3 |= (TR3_DEC_MANA);
568 artifact_type *a_ptr;
570 /* Obtain the artifact info */
571 a_ptr = &a_info[o_ptr->name1];
573 /* Verify that artifact */
574 if (!a_ptr->name) o_ptr->name1 = 0;
580 ego_item_type *e_ptr;
582 /* Obtain the ego-item info */
583 e_ptr = &e_info[o_ptr->name2];
585 /* Verify that ego-item */
586 if (!e_ptr->name) o_ptr->name2 = 0;
590 /* Acquire standard fields */
591 o_ptr->ac = k_ptr->ac;
592 o_ptr->dd = k_ptr->dd;
593 o_ptr->ds = k_ptr->ds;
595 /* Acquire standard weight */
596 o_ptr->weight = k_ptr->weight;
598 /* Hack -- extract the "broken" flag */
599 if (!o_ptr->pval < 0) o_ptr->ident |= (IDENT_BROKEN);
604 artifact_type *a_ptr;
606 /* Obtain the artifact info */
607 a_ptr = &a_info[o_ptr->name1];
609 /* Acquire new artifact "pval" */
610 o_ptr->pval = a_ptr->pval;
612 /* Acquire new artifact fields */
613 o_ptr->ac = a_ptr->ac;
614 o_ptr->dd = a_ptr->dd;
615 o_ptr->ds = a_ptr->ds;
617 /* Acquire new artifact weight */
618 o_ptr->weight = a_ptr->weight;
620 /* Hack -- extract the "broken" flag */
621 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
627 ego_item_type *e_ptr;
629 /* Obtain the ego-item info */
630 e_ptr = &e_info[o_ptr->name2];
635 if (o_ptr->name2 == EGO_DWARVEN)
638 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
641 /* Hack -- extract the "broken" flag */
642 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
645 if (o_ptr->art_name) /* A random artifact */
658 static void rd_monster(monster_type *m_ptr)
663 /* Read the monster race */
664 rd_s16b(&m_ptr->r_idx);
666 /* Read the other information */
670 rd_s16b(&m_ptr->maxhp);
671 if (z_older_than(11, 0, 5))
673 m_ptr->max_maxhp = m_ptr->maxhp;
677 rd_s16b(&m_ptr->max_maxhp);
679 rd_s16b(&m_ptr->csleep);
680 rd_byte(&m_ptr->mspeed);
681 if (z_older_than(10, 4, 2))
684 m_ptr->energy = (s16b)tmp8u;
686 else rd_s16b(&m_ptr->energy);
687 if (z_older_than(10,0,7))
694 rd_byte(&m_ptr->fast);
695 rd_byte(&m_ptr->slow);
697 rd_byte(&m_ptr->stunned);
698 rd_byte(&m_ptr->confused);
699 rd_byte(&m_ptr->monfear);
701 if (z_older_than(10,0,10))
705 else if (z_older_than(10,0,11))
713 rd_s16b(&m_ptr->target_y);
714 rd_s16b(&m_ptr->target_x);
717 /* Monster invulnerability introduced from 2.3.2+ */
721 rd_byte(&m_ptr->invulner);
723 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
724 rd_u32b(&m_ptr->smart);
728 if (z_older_than(10, 4, 5))
731 rd_u32b(&m_ptr->exp);
733 if (z_older_than(10, 2, 2))
735 if (m_ptr->r_idx < 0)
737 m_ptr->r_idx = (0-m_ptr->r_idx);
738 m_ptr->mflag2 |= MFLAG_KAGE;
743 rd_byte(&m_ptr->mflag2);
746 if (z_older_than(10, 1, 3))
753 if (buf[0]) m_ptr->nickname = quark_add(buf);
764 * Read the monster lore
766 static void rd_lore(int r_idx)
770 monster_race *r_ptr = &r_info[r_idx];
772 /* Count sights/deaths/kills */
773 rd_s16b(&r_ptr->r_sights);
774 rd_s16b(&r_ptr->r_deaths);
775 rd_s16b(&r_ptr->r_pkills);
776 rd_s16b(&r_ptr->r_tkills);
778 /* Count wakes and ignores */
779 rd_byte(&r_ptr->r_wake);
780 rd_byte(&r_ptr->r_ignore);
783 rd_byte(&r_ptr->r_xtra1);
784 rd_byte(&r_ptr->r_xtra2);
787 rd_byte(&r_ptr->r_drop_gold);
788 rd_byte(&r_ptr->r_drop_item);
791 rd_byte(&r_ptr->r_cast_inate);
792 rd_byte(&r_ptr->r_cast_spell);
794 /* Count blows of each type */
795 rd_byte(&r_ptr->r_blows[0]);
796 rd_byte(&r_ptr->r_blows[1]);
797 rd_byte(&r_ptr->r_blows[2]);
798 rd_byte(&r_ptr->r_blows[3]);
801 rd_u32b(&r_ptr->r_flags1);
802 rd_u32b(&r_ptr->r_flags2);
803 rd_u32b(&r_ptr->r_flags3);
804 rd_u32b(&r_ptr->r_flags4);
805 rd_u32b(&r_ptr->r_flags5);
806 rd_u32b(&r_ptr->r_flags6);
808 /* Read the "Racial" monster limit per level */
809 rd_byte(&r_ptr->max_num);
816 /* Repair the lore flags */
817 r_ptr->r_flags1 &= r_ptr->flags1;
818 r_ptr->r_flags2 &= r_ptr->flags2;
819 r_ptr->r_flags3 &= r_ptr->flags3;
820 r_ptr->r_flags4 &= r_ptr->flags4;
821 r_ptr->r_flags5 &= r_ptr->flags5;
822 r_ptr->r_flags6 &= r_ptr->flags6;
829 * Add the item "o_ptr" to the inventory of the "Home"
831 * In all cases, return the slot (or -1) where the object was placed
833 * Note that this is a hacked up version of "inven_carry()".
835 * Also note that it may not correctly "adapt" to "knowledge" bacoming
836 * known, the player may have to pick stuff up and drop it again.
838 static void home_carry(store_type *st_ptr, object_type *o_ptr)
846 /* Check each existing item (try to combine) */
847 for (slot = 0; slot < st_ptr->stock_num; slot++)
849 /* Get the existing item */
850 j_ptr = &st_ptr->stock[slot];
852 /* The home acts just like the player */
853 if (object_similar(j_ptr, o_ptr))
855 /* Save the new number of items */
856 object_absorb(j_ptr, o_ptr);
864 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
868 /* Determine the "value" of the item */
869 value = object_value(o_ptr);
871 /* Check existing slots to see if we must "slide" */
872 for (slot = 0; slot < st_ptr->stock_num; slot++)
875 j_ptr = &st_ptr->stock[slot];
877 /* Hack -- readable books always come first */
878 if ((o_ptr->tval == mp_ptr->spell_book) &&
879 (j_ptr->tval != mp_ptr->spell_book)) break;
880 if ((j_ptr->tval == mp_ptr->spell_book) &&
881 (o_ptr->tval != mp_ptr->spell_book)) continue;
883 /* Objects sort by decreasing type */
884 if (o_ptr->tval > j_ptr->tval) break;
885 if (o_ptr->tval < j_ptr->tval) continue;
887 /* Can happen in the home */
888 if (!object_aware_p(o_ptr)) continue;
889 if (!object_aware_p(j_ptr)) break;
891 /* Objects sort by increasing sval */
892 if (o_ptr->sval < j_ptr->sval) break;
893 if (o_ptr->sval > j_ptr->sval) continue;
895 /* Objects in the home can be unknown */
896 if (!object_known_p(o_ptr)) continue;
897 if (!object_known_p(j_ptr)) break;
900 * Hack: otherwise identical rods sort by
901 * increasing recharge time --dsb
903 if (o_ptr->tval == TV_ROD)
905 if (o_ptr->pval < j_ptr->pval) break;
906 if (o_ptr->pval > j_ptr->pval) continue;
909 /* Objects sort by decreasing value */
910 j_value = object_value(j_ptr);
911 if (value > j_value) break;
912 if (value < j_value) continue;
915 /* Slide the others up */
916 for (i = st_ptr->stock_num; i > slot; i--)
918 st_ptr->stock[i] = st_ptr->stock[i-1];
924 /* Insert the new item */
925 st_ptr->stock[slot] = *o_ptr;
927 chg_virtue(V_SACRIFICE, -1);
929 /* Return the location */
937 static errr rd_store(int town_number, int store_number)
949 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
951 st_ptr = &town[1].store[store_number];
952 if (st_ptr->stock_num) sort = TRUE;
956 st_ptr = &town[town_number].store[store_number];
959 /* Read the basic info */
960 rd_s32b(&st_ptr->store_open);
961 rd_s16b(&st_ptr->insult_cur);
963 if (z_older_than(11, 0, 4))
972 rd_s16b(&st_ptr->good_buy);
973 rd_s16b(&st_ptr->bad_buy);
975 /* Read last visit */
976 rd_s32b(&st_ptr->last_visit);
978 /* Extract the owner (see above) */
982 for (j = 0; j < num; j++)
987 /* Get local object */
990 /* Wipe the object */
996 /* Acquire valid items */
997 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1002 home_carry(st_ptr, q_ptr);
1006 k = st_ptr->stock_num++;
1008 /* Acquire the item */
1009 object_copy(&st_ptr->stock[k], q_ptr);
1021 * Read RNG state (added in 2.8.0)
1023 static void rd_randomizer(void)
1033 rd_u16b(&Rand_place);
1036 for (i = 0; i < RAND_DEG; i++)
1038 rd_u32b(&Rand_state[i]);
1048 * Read options (ignore most pre-2.8.0 options)
1050 * Note that the normal options are now stored as a set of 256 bit flags,
1051 * plus a set of 256 bit masks to indicate which bit flags were defined
1052 * at the time the savefile was created. This will allow new options
1053 * to be added, and old options to be removed, at any time, without
1054 * hurting old savefiles.
1056 * The window options are stored in the same way, but note that each
1057 * window gets 32 options, and their order is fixed by certain defines.
1059 static void rd_options(void)
1073 /* Ignore old options */
1077 /*** Special info */
1079 /* Read "delay_factor" */
1083 /* Read "hitpoint_warn" */
1088 /*** Cheating options ***/
1092 if (c & 0x0002) wizard = TRUE;
1094 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1095 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1096 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1097 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1098 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1099 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1101 rd_byte((byte *)&autosave_l);
1102 rd_byte((byte *)&autosave_t);
1103 rd_s16b(&autosave_freq);
1106 /*** Normal Options ***/
1108 /* Read the option flags */
1109 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1111 /* Read the option masks */
1112 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1114 /* Analyze the options */
1115 for (n = 0; n < 8; n++)
1117 /* Analyze the options */
1118 for (i = 0; i < 32; i++)
1120 /* Process valid flags */
1121 if (mask[n] & (1L << i))
1123 /* Process valid flags */
1124 if (option_mask[n] & (1L << i))
1127 if (flag[n] & (1L << i))
1130 option_flag[n] |= (1L << i);
1137 option_flag[n] &= ~(1L << i);
1144 if (z_older_than(10, 4, 5))
1146 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1147 else option_flag[5] |= (0x00000001 << 4);
1148 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1149 else option_flag[2] |= (0x00000001 << 5);
1150 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1151 else option_flag[4] |= (0x00000001 << 5);
1152 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1153 else option_flag[5] |= (0x00000001 << 0);
1154 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1155 else option_flag[5] |= (0x00000001 << 12);
1156 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1157 else option_flag[1] |= (0x00000001 << 0);
1158 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1159 else option_flag[1] |= (0x00000001 << 18);
1160 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1161 else option_flag[1] |= (0x00000001 << 19);
1162 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1163 else option_flag[5] |= (0x00000001 << 3);
1167 /*** Window Options ***/
1169 /* Read the window flags */
1170 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1172 /* Read the window masks */
1173 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1175 /* Analyze the options */
1176 for (n = 0; n < 8; n++)
1178 /* Analyze the options */
1179 for (i = 0; i < 32; i++)
1181 /* Process valid flags */
1182 if (mask[n] & (1L << i))
1184 /* Process valid flags */
1185 if (window_mask[n] & (1L << i))
1188 if (flag[n] & (1L << i))
1191 window_flag[n] |= (1L << i);
1198 window_flag[n] &= ~(1L << i);
1211 * Hack -- strip the "ghost" info
1213 * XXX XXX XXX This is such a nasty hack it hurts.
1215 static void rd_ghost(void)
1222 /* Strip old data */
1230 * Read the "extra" information
1232 static void rd_extra(void)
1239 rd_string(player_name, 32);
1241 rd_string(died_from, 80);
1243 for (i = 0; i < 4; i++)
1245 rd_string(history[i], 60);
1248 /* Class/Race/Seikaku/Gender/Spells */
1249 rd_byte(&p_ptr->prace);
1250 rd_byte(&p_ptr->pclass);
1251 rd_byte(&p_ptr->pseikaku);
1252 rd_byte(&p_ptr->psex);
1253 rd_byte(&p_ptr->realm1);
1254 rd_byte(&p_ptr->realm2);
1255 rd_byte(&tmp8u); /* oops */
1257 if (z_older_than(10, 4, 4))
1259 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1260 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1261 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1262 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1265 /* Special Race/Class info */
1266 rd_byte(&p_ptr->hitdie);
1267 rd_u16b(&p_ptr->expfact);
1269 /* Age/Height/Weight */
1270 rd_s16b(&p_ptr->age);
1271 rd_s16b(&p_ptr->ht);
1272 rd_s16b(&p_ptr->wt);
1274 /* Read the stat info */
1275 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1276 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1277 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1279 strip_bytes(24); /* oops */
1281 rd_s32b(&p_ptr->au);
1283 rd_s32b(&p_ptr->max_exp);
1284 rd_s32b(&p_ptr->exp);
1285 rd_u16b(&p_ptr->exp_frac);
1287 rd_s16b(&p_ptr->lev);
1289 for (i = 0; i < 64; i++) rd_s16b(&spell_exp[i]);
1290 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1292 for (i = 0; i < 64; i++) spell_exp[i] = 1600;
1294 if (z_older_than(10, 3, 6))
1295 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&weapon_exp[i][j]);
1297 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&weapon_exp[i][j]);
1298 for (i = 0; i < 10; i++) rd_s16b(&skill_exp[i]);
1299 if (z_older_than(10, 4, 1))
1301 if (p_ptr->pclass != CLASS_BEASTMASTER) skill_exp[GINOU_RIDING] /= 2;
1302 skill_exp[GINOU_RIDING] = MIN(skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1304 if (z_older_than(10, 3, 14))
1306 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1307 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1311 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1312 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1314 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1316 if (z_older_than(11, 0, 7))
1318 p_ptr->start_race = p_ptr->prace;
1319 p_ptr->old_race1 = 0L;
1320 p_ptr->old_race2 = 0L;
1321 p_ptr->old_realm = 0;
1325 rd_byte(&p_ptr->start_race);
1326 rd_s32b(&p_ptr->old_race1);
1327 rd_s32b(&p_ptr->old_race2);
1328 rd_s16b(&p_ptr->old_realm);
1331 if (z_older_than(10, 0, 1))
1333 for (i = 0; i < OLD_MAX_MANE; i++)
1340 else if (z_older_than(10, 2, 3))
1342 for (i = 0; i < OLD_MAX_MANE; i++)
1347 for (i = 0; i < MAX_MANE; i++)
1357 for (i = 0; i < MAX_MANE; i++)
1359 rd_s16b(&mane_spell[i]);
1360 rd_s16b(&mane_dam[i]);
1365 if (z_older_than(10, 0, 3))
1367 get_mon_num_prep(NULL, NULL);
1368 for (i = 0; i < MAX_KUBI; i++)
1370 monster_race *r_ptr;
1375 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
1376 r_ptr = &r_info[kubi_r_idx[i]];
1378 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
1380 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
1382 if(r_ptr->flags6 & RF6_SPECIAL) continue;
1384 for (j = 0; j < i; j++)
1385 if (kubi_r_idx[i] == kubi_r_idx[j])break;
1390 for (i = 0; i < MAX_KUBI -1; i++)
1393 for (j = i; j < MAX_KUBI; j++)
1395 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
1397 tmp = kubi_r_idx[i];
1398 kubi_r_idx[i] = kubi_r_idx[j];
1399 kubi_r_idx[j] = tmp;
1403 for (i = 0; i < MAX_KUBI; i++)
1405 if(!r_info[kubi_r_idx[i]].max_num)
1406 kubi_r_idx[i] += 10000;
1411 for (i = 0; i < MAX_KUBI; i++)
1413 rd_s16b(&kubi_r_idx[i]);
1417 if (z_older_than(10, 0, 3))
1423 for (i = 0; i < 4; i++)
1425 rd_s16b(&battle_mon[i]);
1426 if (z_older_than(10, 3, 4))
1429 mon_odds[i] = tmp16s;
1431 else rd_u32b(&mon_odds[i]);
1435 rd_s16b(&p_ptr->town_num);
1437 /* Read arena and rewards information */
1438 rd_s16b(&p_ptr->arena_number);
1440 p_ptr->inside_arena = (bool)tmp16s;
1441 rd_s16b(&p_ptr->inside_quest);
1442 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1446 p_ptr->inside_battle = (bool)tmp16s;
1448 rd_byte(&p_ptr->exit_bldg);
1449 rd_byte(&p_ptr->leftbldg);
1451 rd_s16b(&p_ptr->oldpx);
1452 rd_s16b(&p_ptr->oldpy);
1453 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1457 if (tmp16s > MAX_BACT)
1460 note(format("¤ÎÃæ", tmp16s));
1462 note(format("Too many (%d) building rewards!", tmp16s));
1467 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1469 rd_s16b(&p_ptr->mhp);
1470 rd_s16b(&p_ptr->chp);
1471 rd_u16b(&p_ptr->chp_frac);
1473 rd_s16b(&p_ptr->msp);
1474 rd_s16b(&p_ptr->csp);
1475 rd_u16b(&p_ptr->csp_frac);
1477 rd_s16b(&p_ptr->max_plv);
1478 if (z_older_than(10, 3, 8))
1480 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1484 byte max = (byte)max_d_idx;
1488 for(i = 0; i < max; i++)
1490 rd_s16b(&max_dlv[i]);
1491 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1495 /* Repair maximum player level XXX XXX XXX */
1496 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1500 rd_s16b(&p_ptr->sc);
1503 /* Read the flags */
1504 strip_bytes(2); /* Old "rest" */
1505 rd_s16b(&p_ptr->blind);
1506 rd_s16b(&p_ptr->paralyzed);
1507 rd_s16b(&p_ptr->confused);
1508 rd_s16b(&p_ptr->food);
1509 strip_bytes(4); /* Old "food_digested" / "protection" */
1510 rd_s16b(&p_ptr->energy);
1511 rd_s16b(&p_ptr->fast);
1512 rd_s16b(&p_ptr->slow);
1513 rd_s16b(&p_ptr->afraid);
1514 rd_s16b(&p_ptr->cut);
1515 rd_s16b(&p_ptr->stun);
1516 rd_s16b(&p_ptr->poisoned);
1517 rd_s16b(&p_ptr->image);
1518 rd_s16b(&p_ptr->protevil);
1519 rd_s16b(&p_ptr->invuln);
1520 if(z_older_than(10, 0, 0))
1523 rd_s16b(&p_ptr->ult_res);
1524 rd_s16b(&p_ptr->hero);
1525 rd_s16b(&p_ptr->shero);
1526 rd_s16b(&p_ptr->shield);
1527 rd_s16b(&p_ptr->blessed);
1528 rd_s16b(&p_ptr->tim_invis);
1529 rd_s16b(&p_ptr->word_recall);
1530 if (z_older_than(10, 3, 8))
1531 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1535 p_ptr->recall_dungeon = (byte)tmp16s;
1537 rd_s16b(&p_ptr->see_infra);
1538 rd_s16b(&p_ptr->tim_infra);
1539 rd_s16b(&p_ptr->oppose_fire);
1540 rd_s16b(&p_ptr->oppose_cold);
1541 rd_s16b(&p_ptr->oppose_acid);
1542 rd_s16b(&p_ptr->oppose_elec);
1543 rd_s16b(&p_ptr->oppose_pois);
1544 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1545 else rd_s16b(&p_ptr->tsuyoshi);
1547 /* Old savefiles do not have the following fields... */
1548 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1551 p_ptr->wraith_form = 0;
1552 p_ptr->resist_magic = 0;
1553 p_ptr->tim_regen = 0;
1554 p_ptr->kabenuke = 0;
1555 p_ptr->tim_stealth = 0;
1556 p_ptr->tim_ffall = 0;
1557 p_ptr->tim_sh_touki = 0;
1558 p_ptr->lightspeed = 0;
1559 p_ptr->tsubureru = 0;
1560 p_ptr->tim_res_nether = 0;
1561 p_ptr->tim_res_time = 0;
1562 p_ptr->mimic_form = 0;
1563 p_ptr->tim_mimic = 0;
1564 p_ptr->tim_sh_fire = 0;
1567 p_ptr->tim_reflect = 0;
1568 p_ptr->multishadow = 0;
1569 p_ptr->dustrobe = 0;
1571 p_ptr->chaos_patron = get_chaos_patron();
1579 rd_s16b(&p_ptr->tim_esp);
1580 rd_s16b(&p_ptr->wraith_form);
1581 rd_s16b(&p_ptr->resist_magic);
1582 rd_s16b(&p_ptr->tim_regen);
1583 rd_s16b(&p_ptr->kabenuke);
1584 rd_s16b(&p_ptr->tim_stealth);
1585 rd_s16b(&p_ptr->tim_ffall);
1586 rd_s16b(&p_ptr->tim_sh_touki);
1587 rd_s16b(&p_ptr->lightspeed);
1588 rd_s16b(&p_ptr->tsubureru);
1589 if (z_older_than(10, 4, 7))
1590 p_ptr->magicdef = 0;
1592 rd_s16b(&p_ptr->magicdef);
1593 rd_s16b(&p_ptr->tim_res_nether);
1594 if (z_older_than(10, 4, 11))
1596 p_ptr->tim_res_time = 0;
1597 p_ptr->mimic_form = 0;
1598 p_ptr->tim_mimic = 0;
1599 p_ptr->tim_sh_fire = 0;
1603 rd_s16b(&p_ptr->tim_res_time);
1604 rd_byte(&p_ptr->mimic_form);
1605 rd_s16b(&p_ptr->tim_mimic);
1606 rd_s16b(&p_ptr->tim_sh_fire);
1610 if ( z_older_than(11,0,3) ){
1611 p_ptr->tim_reflect=0;
1612 p_ptr->multishadow=0;
1616 rd_s16b(&p_ptr->tim_reflect);
1617 rd_s16b(&p_ptr->multishadow);
1618 rd_s16b(&p_ptr->dustrobe);
1621 rd_s16b(&p_ptr->chaos_patron);
1622 rd_u32b(&p_ptr->muta1);
1623 rd_u32b(&p_ptr->muta2);
1624 rd_u32b(&p_ptr->muta3);
1626 for (i = 0; i < 8; i++)
1627 rd_s16b(&p_ptr->virtues[i]);
1628 for (i = 0; i < 8; i++)
1629 rd_s16b(&p_ptr->vir_types[i]);
1632 /* Calc the regeneration modifier for mutations */
1633 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1635 if (z_older_than(10,0,9))
1638 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1639 p_ptr->ele_attack = 0;
1643 rd_s16b(&p_ptr->ele_attack);
1644 rd_u32b(&p_ptr->special_attack);
1646 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1647 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1648 if (z_older_than(10,0,12))
1650 p_ptr->ele_immune = 0;
1651 p_ptr->special_defense = 0;
1655 rd_s16b(&p_ptr->ele_immune);
1656 rd_u32b(&p_ptr->special_defense);
1658 rd_byte(&p_ptr->knowledge);
1659 rd_byte(&tmp8u); /* oops */
1660 rd_byte(&tmp8u); /* oops */
1661 rd_byte(&p_ptr->action);
1662 if (!z_older_than(10, 4, 3))
1665 if (tmp8u) p_ptr->action = ACTION_LEARN;
1667 rd_byte((byte *)&preserve_mode);
1668 rd_byte((byte *)&wait_report_score);
1671 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1673 /* Skip the flags */
1677 /* Hack -- the two "special seeds" */
1678 rd_u32b(&seed_flavor);
1679 rd_u32b(&seed_town);
1683 rd_u16b(&panic_save);
1684 rd_u16b(&total_winner);
1692 /* Read "feeling" */
1696 /* Turn of last "feeling" */
1702 if (z_older_than(10, 3, 12))
1704 dungeon_turn = turn;
1706 else rd_s32b(&dungeon_turn);
1708 if (z_older_than(10, 3, 13))
1712 else rd_s32b(&old_battle);
1714 if (z_older_than(10,0,3))
1716 monster_race *r_ptr;
1720 today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
1721 r_ptr = &r_info[today_mon];
1723 if (r_ptr->flags1 & RF1_UNIQUE) continue;
1724 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
1725 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
1726 if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
1727 if (r_ptr->rarity > 10) continue;
1728 if (r_ptr->level == 0) continue;
1732 p_ptr->today_mon = 0;
1736 rd_s16b(&today_mon);
1737 rd_s16b(&p_ptr->today_mon);
1740 if (z_older_than(10,0,7))
1746 rd_s16b(&p_ptr->riding);
1749 if (z_older_than(10,1,2))
1758 if (z_older_than(10,3,9))
1762 else if (z_older_than(10, 3, 10))
1770 rd_s32b(&p_ptr->visit);
1772 if (!z_older_than(11, 0, 5))
1774 rd_u32b(&p_ptr->count);
1782 * Read the player inventory
1784 * Note that the inventory changed in Angband 2.7.4. Two extra
1785 * pack slots were added and the equipment was rearranged. Note
1786 * that these two features combine when parsing old save-files, in
1787 * which items from the old "aux" slot are "carried", perhaps into
1788 * one of the two new "inventory" slots.
1790 * Note that the inventory is "re-sorted" later by "dungeon()".
1792 static errr rd_inventory(void)
1800 p_ptr->total_weight = 0;
1806 /* Read until done */
1811 /* Get the next item index */
1814 /* Nope, we reached the end */
1815 if (n == 0xFFFF) break;
1817 /* Get local object */
1820 /* Wipe the object */
1826 /* Hack -- verify item */
1827 if (!q_ptr->k_idx) return (53);
1829 /* Wield equipment */
1830 if (n >= INVEN_RARM)
1833 object_copy(&inventory[n], q_ptr);
1835 /* Add the weight */
1836 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1842 /* Warning -- backpack is full */
1843 else if (inven_cnt == INVEN_PACK)
1847 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
1849 note("Too many items in the inventory!");
1857 /* Carry inventory */
1864 object_copy(&inventory[n], q_ptr);
1866 /* Add the weight */
1867 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
1881 * Read the saved messages
1883 static void rd_messages(void)
1893 /* Read the messages */
1894 for (i = 0; i < num; i++)
1896 /* Read the message */
1897 rd_string(buf, 128);
1899 /* Save the message */
1909 * The monsters/objects must be loaded in the same order
1910 * that they were stored, since the actual indexes matter.
1912 static errr rd_dungeon(void)
1923 /*** Basic info ***/
1926 rd_s16b(&dun_level);
1927 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
1928 else rd_byte(&dungeon_type);
1930 /* Set the base level for old versions */
1931 base_level = dun_level;
1933 rd_s16b(&base_level);
1935 rd_s16b(&num_repro);
1940 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
1943 rd_s16b(&tmp16s); /* max_panel_rows */
1944 rd_s16b(&tmp16s); /* max_panel_cols */
1947 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
1955 /*** Run length decoding ***/
1957 /* Load the dungeon data */
1958 for (x = y = 0; y < ymax; )
1962 if (z_older_than(10,3,6))
1967 /* Apply the RLE info */
1968 for (i = count; i > 0; i--)
1970 /* Access the cave */
1971 c_ptr = &cave[y][x];
1973 /* Extract "info" */
1974 if (z_older_than(10,3,6))
1975 c_ptr->info = tmp8u;
1976 else c_ptr->info = tmp16s;
1985 if (++y >= ymax) break;
1991 /*** Run length decoding ***/
1993 /* Load the dungeon data */
1994 for (x = y = 0; y < ymax; )
2000 /* Apply the RLE info */
2001 for (i = count; i > 0; i--)
2003 /* Access the cave */
2004 c_ptr = &cave[y][x];
2006 if (c_ptr->feat == FEAT_INVIS)
2008 c_ptr->feat = FEAT_FLOOR;
2009 c_ptr->info |= CAVE_TRAP;
2012 /* Extract "feat" */
2013 c_ptr->feat = tmp8u;
2022 if (++y >= ymax) break;
2027 /*** Run length decoding ***/
2029 /* Load the dungeon data */
2030 for (x = y = 0; y < ymax; )
2036 /* Apply the RLE info */
2037 for (i = count; i > 0; i--)
2039 /* Access the cave */
2040 c_ptr = &cave[y][x];
2042 /* Extract "feat" */
2043 c_ptr->mimic = tmp8u;
2052 if (++y >= ymax) break;
2057 /*** Run length decoding ***/
2059 /* Load the dungeon data */
2060 for (x = y = 0; y < ymax; )
2066 /* Apply the RLE info */
2067 for (i = count; i > 0; i--)
2069 /* Access the cave */
2070 c_ptr = &cave[y][x];
2072 /* Extract "feat" */
2073 c_ptr->special = tmp16s;
2082 if (++y >= ymax) break;
2089 /* Read the item count */
2092 /* Verify maximum */
2093 if (limit >= max_o_idx)
2096 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2098 note(format("Too many (%d) object entries!", limit));
2104 /* Read the dungeon items */
2105 for (i = 1; i < limit; i++)
2112 /* Get a new record */
2119 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2121 note(format("Object allocation error (%d <> %d)", i, o_idx));
2129 o_ptr = &o_list[o_idx];
2135 /* XXX XXX XXX XXX XXX */
2138 if (o_ptr->held_m_idx)
2140 monster_type *m_ptr;
2143 m_ptr = &m_list[o_ptr->held_m_idx];
2146 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2148 /* Place the object */
2149 m_ptr->hold_o_idx = o_idx;
2155 /* Access the item location */
2156 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2159 o_ptr->next_o_idx = c_ptr->o_idx;
2161 /* Place the object */
2162 c_ptr->o_idx = o_idx;
2169 /* Read the monster count */
2172 /* Hack -- verify */
2173 if (limit >= max_m_idx)
2176 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2178 note(format("Too many (%d) monster entries!", limit));
2184 /* Read the monsters */
2185 for (i = 1; i < limit; i++)
2189 monster_type *m_ptr;
2191 monster_race *r_ptr;
2194 /* Get a new record */
2201 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2203 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2210 /* Acquire monster */
2211 m_ptr = &m_list[m_idx];
2213 /* Read the monster */
2218 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2220 /* Mark the location */
2221 c_ptr->m_idx = m_idx;
2225 r_ptr = &r_info[m_ptr->r_idx];
2227 /* Count XXX XXX XXX */
2233 /* The dungeon is ready */
2234 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2235 character_dungeon = FALSE;
2237 character_dungeon = TRUE;
2246 * Actually read the savefile
2248 static errr rd_savefile_new_aux(void)
2260 #ifdef VERIFY_CHECKSUMS
2261 u32b n_x_check, n_v_check;
2262 u32b o_x_check, o_v_check;
2266 /* Mention the savefile version */
2268 note(format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
2270 note(format("Loading a %d.%d.%d savefile...",
2273 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
2276 /* Strip the version bytes */
2279 /* Hack -- decrypt */
2280 xor_byte = sf_extra;
2283 /* Clear the checksums */
2287 #if SAVEFILE_VERSION
2288 /* Read the version number of the savefile */
2289 rd_u32b(&sf_version);
2290 #endif /* SAVEFILE_VERSION */
2292 /* Operating system info */
2295 /* Time of savefile creation */
2298 /* Number of resurrections */
2301 /* Number of times played */
2305 /* Later use (always zero) */
2308 /* Later use (always zero) */
2312 /* Read RNG state */
2315 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2317 if (arg_fiddle) note("Loaded Randomizer Info");
2322 /* Then the options */
2325 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2327 if (arg_fiddle) note("Loaded Option Flags");
2331 * Munchkin players are marked
2333 * XXX - should be replaced with a better method,
2334 * after the new scorefile-handling is implemented.
2342 /* Then the "messages" */
2345 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2347 if (arg_fiddle) note("Loaded Messages");
2352 for (i = 0; i < max_r_idx; i++)
2354 monster_race *r_ptr;
2355 /* Access that monster */
2358 /* Hack -- Reset the death counter */
2359 r_ptr->max_num = 100;
2360 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
2361 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
2364 /* Monster Memory */
2367 /* Incompatible save files */
2368 if (tmp16u > max_r_idx)
2371 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2373 note(format("Too many (%u) monster races!", tmp16u));
2379 /* Read the available records */
2380 for (i = 0; i < tmp16u; i++)
2382 monster_race *r_ptr;
2387 /* Access that monster */
2392 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2394 if (arg_fiddle) note("Loaded Monster Memory");
2402 /* Incompatible save files */
2403 if (tmp16u > max_k_idx)
2406 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2408 note(format("Too many (%u) object kinds!", tmp16u));
2414 /* Read the object memory */
2415 for (i = 0; i < tmp16u; i++)
2418 object_kind *k_ptr = &k_info[i];
2422 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
2423 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
2426 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2428 if (arg_fiddle) note("Loaded Object Memory");
2434 * Initialize arena and rewards information
2436 p_ptr->arena_number = 0;
2437 p_ptr->inside_arena = 0;
2438 p_ptr->inside_quest = 0;
2439 p_ptr->leftbldg = FALSE;
2440 p_ptr->exit_bldg = TRUE;
2442 /* Start in town 1 */
2443 p_ptr->town_num = 1;
2445 p_ptr->wilderness_x = 4;
2446 p_ptr->wilderness_y = 4;
2450 /* Init the wilderness seeds */
2451 for (i = 0; i < max_wild_x; i++)
2453 for (j = 0; j < max_wild_y; j++)
2455 wilderness[j][i].seed = randint0(0x10000000);
2459 /* 2.1.3 or newer version */
2461 u16b max_towns_load;
2462 u16b max_quests_load;
2463 byte max_rquests_load;
2464 s16b old_inside_quest = p_ptr->inside_quest;
2466 /* Number of towns */
2467 rd_u16b(&max_towns_load);
2469 /* Incompatible save files */
2470 if (max_towns_load > max_towns)
2473 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
2475 note(format("Too many (%u) towns!", max_towns_load));
2481 /* Number of quests */
2482 rd_u16b(&max_quests_load);
2484 if (z_older_than(11, 0, 7))
2486 max_rquests_load = 10;
2490 rd_byte(&max_rquests_load);
2493 /* Incompatible save files */
2494 if (max_quests_load > max_quests)
2497 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
2499 note(format("Too many (%u) quests!", max_quests_load));
2505 for (i = 0; i < max_quests_load; i++)
2509 rd_s16b(&quest[i].status);
2510 rd_s16b(&quest[i].level);
2512 if (z_older_than(11, 0, 6))
2514 quest[i].complev = 0;
2518 rd_byte(&quest[i].complev);
2521 /* Load quest status if quest is running */
2522 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))))
2524 rd_s16b(&quest[i].cur_num);
2525 rd_s16b(&quest[i].max_num);
2526 rd_s16b(&quest[i].type);
2528 /* Load quest monster index */
2529 rd_s16b(&quest[i].r_idx);
2531 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
2536 monster_race *r_ptr;
2539 * Random monster 5 - 10 levels out of depth
2540 * (depending on level)
2542 r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
2543 r_ptr = &r_info[r_idx];
2545 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
2547 if(r_ptr->flags6 & RF6_SPECIAL) continue;
2549 if(r_ptr->flags7 & RF7_FRIENDLY) continue;
2551 if(r_ptr->flags7 & RF7_AQUATIC) continue;
2553 if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
2556 * Accept monsters that are 2 - 6 levels
2557 * out of depth depending on the quest level
2559 if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
2562 quest[i].r_idx = r_idx;
2565 /* Load quest item index */
2566 rd_s16b(&quest[i].k_idx);
2569 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
2571 rd_byte(&quest[i].flags);
2573 if (z_older_than(10, 3, 11))
2575 if (quest[i].flags & QUEST_FLAG_PRESET)
2577 quest[i].dungeon = 0;
2581 init_flags = INIT_ASSIGN;
2582 p_ptr->inside_quest = i;
2584 process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
2585 p_ptr->inside_quest = old_inside_quest;
2590 rd_byte(&quest[i].dungeon);
2593 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
2594 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
2595 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
2598 /* Ignore the empty quests from old versions */
2601 /* Ignore quest status */
2604 /* Ignore quest level */
2608 * We don't have to care about the other info,
2609 * since status should be 0 for these quests anyway
2614 /* Position in the wilderness */
2615 rd_s32b(&p_ptr->wilderness_x);
2616 rd_s32b(&p_ptr->wilderness_y);
2617 if (z_older_than(10, 3, 13))
2619 p_ptr->wilderness_x = 5;
2620 p_ptr->wilderness_y = 48;
2623 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
2624 else rd_byte((byte *)&p_ptr->wild_mode);
2625 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
2626 else rd_byte((byte *)&ambush_flag);
2628 /* Size of the wilderness */
2629 rd_s32b(&wild_x_size);
2630 rd_s32b(&wild_y_size);
2632 /* Incompatible save files */
2633 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
2636 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
2638 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
2644 /* Load the wilderness seeds */
2645 for (i = 0; i < wild_x_size; i++)
2647 for (j = 0; j < wild_y_size; j++)
2649 rd_u32b(&wilderness[j][i].seed);
2655 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2657 if (arg_fiddle) note("Loaded Quests");
2660 /* Load the Artifacts */
2663 /* Incompatible save files */
2664 if (tmp16u > max_a_idx)
2667 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
2669 note(format("Too many (%u) artifacts!", tmp16u));
2675 /* Read the artifact flags */
2676 for (i = 0; i < tmp16u; i++)
2679 a_info[i].cur_num = tmp8u;
2685 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2687 if (arg_fiddle) note("Loaded Artifacts");
2692 /* Read the extra stuff */
2694 if (p_ptr->energy > 999) world_player = TRUE;
2696 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
2698 if (arg_fiddle) note("Loaded extra information");
2702 /* Read the player_hp array */
2705 /* Incompatible save files */
2706 if (tmp16u > PY_MAX_LEVEL)
2709 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
2711 note(format("Too many (%u) hitpoint entries!", tmp16u));
2717 /* Read the player_hp array */
2718 for (i = 0; i < tmp16u; i++)
2720 rd_s16b(&player_hp[i]);
2723 /* Important -- Initialize the sex */
2724 sp_ptr = &sex_info[p_ptr->psex];
2726 /* Important -- Initialize the race/class */
2727 rp_ptr = &race_info[p_ptr->prace];
2728 cp_ptr = &class_info[p_ptr->pclass];
2729 ap_ptr = &seikaku_info[p_ptr->pseikaku];
2731 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !death)
2733 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2734 do_cmd_rerate(FALSE);
2736 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !death)
2738 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2739 do_cmd_rerate(FALSE);
2741 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !death)
2743 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2744 do_cmd_rerate(FALSE);
2746 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !death)
2748 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2749 do_cmd_rerate(FALSE);
2752 /* Important -- Initialize the magic */
2753 mp_ptr = &m_info[p_ptr->pclass];
2756 /* Read spell info */
2757 rd_u32b(&spell_learned1);
2758 rd_u32b(&spell_learned2);
2759 rd_u32b(&spell_worked1);
2760 rd_u32b(&spell_worked2);
2761 rd_u32b(&spell_forgotten1);
2762 rd_u32b(&spell_forgotten2);
2764 if (z_older_than(10,0,5))
2766 p_ptr->learned_spells = 0;
2767 for (i = 0; i < 64; i++)
2769 /* Count known spells */
2771 (spell_learned1 & (1L << i)) :
2772 (spell_learned2 & (1L << (i - 32))))
2774 p_ptr->learned_spells++;
2778 else rd_s16b(&p_ptr->learned_spells);
2780 if (z_older_than(10,0,6))
2782 p_ptr->add_spells = 0;
2784 else rd_s16b(&p_ptr->add_spells);
2785 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
2787 for (i = 0; i < 64; i++)
2789 rd_byte(&spell_order[i]);
2793 /* Read the inventory */
2797 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
2799 note("Unable to read inventory");
2805 /* Read number of towns */
2807 town_count = tmp16u;
2809 /* Read the stores */
2811 for (i = 1; i < town_count; i++)
2813 for (j = 0; j < tmp16u; j++)
2815 if (rd_store(i, j)) return (22);
2819 rd_s16b(&p_ptr->pet_follow_distance);
2820 if (z_older_than(10, 4, 10))
2822 p_ptr->pet_extra_flags = 0;
2824 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
2826 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
2828 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
2832 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
2835 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2839 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
2842 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2846 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
2849 if (!z_older_than(10,0,8))
2852 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
2857 rd_s16b(&p_ptr->pet_extra_flags);
2860 if (!z_older_than(11, 0, 9))
2862 char buf[SCREEN_BUF_SIZE];
2863 rd_string(buf, SCREEN_BUF_SIZE);
2864 if (buf[0]) screen_dump = string_make(buf);
2869 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
2871 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
2876 /* I'm not dead yet... */
2879 /* Dead players have no dungeon */
2881 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
2883 note("Restoring Dungeon...");
2889 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
2891 note("Error reading dungeon data");
2897 /* Read the ghost info */
2904 strip_bytes(tmp32s);
2909 #ifdef VERIFY_CHECKSUMS
2911 /* Save the checksum */
2912 n_v_check = v_check;
2914 /* Read the old checksum */
2915 rd_u32b(&o_v_check);
2918 if (o_v_check != n_v_check)
2921 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2923 note("Invalid checksum");
2930 /* Save the encoded checksum */
2931 n_x_check = x_check;
2933 /* Read the checksum */
2934 rd_u32b(&o_x_check);
2938 if (o_x_check != n_x_check)
2941 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
2943 note("Invalid encoded checksum");
2957 * Actually read the savefile
2959 errr rd_savefile_new(void)
2963 /* The savefile is a binary file */
2964 fff = my_fopen(savefile, "rb");
2967 if (!fff) return (-1);
2969 /* Call the sub-function */
2970 err = rd_savefile_new_aux();
2972 /* Check for errors */
2973 if (ferror(fff)) err = -1;
2975 /* Close the file */