4 * Copyright (c) 1997 Ben Harrison, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: support for loading savefiles -BEN- */
17 * This file loads savefiles from Angband 2.7.X and 2.8.X
19 * Ancient savefiles (pre-2.7.0) are loaded by another file.
21 * Note that Angband 2.7.0 through 2.7.3 are now officially obsolete,
22 * and savefiles from those versions may not be successfully converted.
24 * We attempt to prevent corrupt savefiles from inducing memory errors.
26 * Note that this file should not use the random number generator, the
27 * object flavors, the visual attr/char mappings, or anything else which
28 * is initialized *after* or *during* the "load character" function.
30 * This file assumes that the monster/object records are initialized
31 * to zero, and the race/kind tables have been loaded correctly. The
32 * order of object stacks is currently not saved in the savefiles, but
33 * the "next" pointers are saved, so all necessary knowledge is present.
35 * We should implement simple "savefile extenders" using some form of
36 * "sized" chunks of bytes, with a {size,type,data} format, so everyone
37 * can know the size, interested people can know the type, and the actual
38 * data is available to the parsing routines that acknowledge the type.
40 * Consider changing the "globe of invulnerability" code so that it
41 * takes some form of "maximum damage to protect from" in addition to
42 * the existing "number of turns to protect for", and where each hit
43 * by a monster will reduce the shield by that amount.
51 * Maximum number of tries for selection of a proper quest monster
57 * Local "savefile" pointer
62 * Hack -- old "encryption" byte
67 * Hack -- simple "checksum" on the actual values
69 static u32b v_check = 0L;
72 * Hack -- simple "checksum" on the encoded bytes
74 static u32b x_check = 0L;
79 * This function determines if the version of the savefile
80 * currently being read is older than version "major.minor.patch.extra".
82 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
84 /* Much older, or much more recent */
85 if (h_ver_major < major) return (TRUE);
86 if (h_ver_major > major) return (FALSE);
88 /* Distinctly older, or distinctly more recent */
89 if (h_ver_minor < minor) return (TRUE);
90 if (h_ver_minor > minor) return (FALSE);
92 /* Barely older, or barely more recent */
93 if (h_ver_patch < patch) return (TRUE);
94 if (h_ver_patch > patch) return (FALSE);
96 /* Barely older, or barely more recent */
97 if (h_ver_extra < extra) return (TRUE);
98 if (h_ver_extra > extra) return (FALSE);
100 /* Identical versions */
106 * The above function, adapted for Zangband
108 static bool z_older_than(byte x, byte y, byte z)
110 /* Much older, or much more recent */
111 if (z_major < x) return (TRUE);
112 if (z_major > x) return (FALSE);
114 /* Distinctly older, or distinctly more recent */
115 if (z_minor < y) return (TRUE);
116 if (z_minor > y) return (FALSE);
118 /* Barely older, or barely more recent */
119 if (z_patch < z) return (TRUE);
120 if (z_patch > z) return (FALSE);
122 /* Identical versions */
128 * Hack -- Show information on the screen, one line at a time.
130 * Avoid the top two lines, to avoid interference with "msg_print()".
132 static void note(cptr msg)
136 /* Draw the message */
139 /* Advance one line (wrap if needed) */
140 if (++y >= 24) y = 2;
148 * The following functions are used to load the basic building blocks
149 * of savefiles. They also maintain the "checksum" info for 2.7.0+
152 static byte sf_get(void)
156 /* Get a character, decode the value */
157 c = getc(fff) & 0xFF;
161 /* Maintain the checksum info */
165 /* Return the value */
169 static void rd_byte(byte *ip)
174 static void rd_u16b(u16b *ip)
177 (*ip) |= ((u16b)(sf_get()) << 8);
180 static void rd_s16b(s16b *ip)
185 static void rd_u32b(u32b *ip)
188 (*ip) |= ((u32b)(sf_get()) << 8);
189 (*ip) |= ((u32b)(sf_get()) << 16);
190 (*ip) |= ((u32b)(sf_get()) << 24);
193 static void rd_s32b(s32b *ip)
200 * Hack -- read a string
202 static void rd_string(char *str, int max)
206 /* Read the string */
207 for (i = 0; TRUE; i++)
214 /* Collect string while legal */
215 if (i < max) str[i] = tmp8u;
230 * Hack -- strip some bytes
232 static void strip_bytes(int n)
236 /* Strip the bytes */
237 while (n--) rd_byte(&tmp8u);
240 #define OLD_MAX_MANE 22
243 * Read an object (Old method)
245 * This function attempts to "repair" old savefiles, and to extract
246 * the most up to date values for various object fields.
248 * Note that Angband 2.7.9 introduced a new method for object "flags"
249 * in which the "flags" on an object are actually extracted when they
250 * are needed from the object kind, artifact index, ego-item index,
251 * and two special "xtra" fields which are used to encode any "extra"
252 * power of certain ego-items. This had the side effect that items
253 * imported from pre-2.7.9 savefiles will lose any "extra" powers they
254 * may have had, and also, all "uncursed" items will become "cursed"
255 * again, including Calris, even if it is being worn at the time. As
256 * a complete hack, items which are inscribed with "uncursed" will be
257 * "uncursed" when imported from pre-2.7.9 savefiles.
259 static void rd_item_old(object_type *o_ptr)
265 rd_s16b(&o_ptr->k_idx);
272 rd_byte(&o_ptr->tval);
273 rd_byte(&o_ptr->sval);
275 if (z_older_than(10, 4, 4))
277 if (o_ptr->tval == 100) o_ptr->tval = TV_GOLD;
278 if (o_ptr->tval == 98) o_ptr->tval = TV_MUSIC_BOOK;
279 if (o_ptr->tval == 110) o_ptr->tval = TV_HISSATSU_BOOK;
283 rd_s16b(&o_ptr->pval);
285 rd_byte(&o_ptr->discount);
286 rd_byte(&o_ptr->number);
287 rd_s16b(&o_ptr->weight);
289 rd_byte(&o_ptr->name1);
290 rd_byte(&o_ptr->name2);
291 rd_s16b(&o_ptr->timeout);
293 rd_s16b(&o_ptr->to_h);
294 rd_s16b(&o_ptr->to_d);
295 rd_s16b(&o_ptr->to_a);
302 rd_byte(&o_ptr->ident);
304 rd_byte(&o_ptr->marked);
307 rd_u32b(&o_ptr->art_flags[0]);
308 rd_u32b(&o_ptr->art_flags[1]);
309 rd_u32b(&o_ptr->art_flags[2]);
310 if (h_older_than(1, 3, 0, 0)) o_ptr->art_flags[3] = 0L;
311 else rd_u32b(&o_ptr->art_flags[3]);
313 if (h_older_than(1, 3, 0, 0))
315 if (o_ptr->name2 == EGO_TELEPATHY)
316 add_flag(o_ptr->art_flags, TR_TELEPATHY);
319 if (z_older_than(11, 0, 11))
321 o_ptr->curse_flags = 0L;
322 if (o_ptr->ident & 0x40)
324 o_ptr->curse_flags |= TRC_CURSED;
325 if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
326 if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
329 artifact_type *a_ptr = &a_info[o_ptr->name1];
330 if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
331 if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
333 else if (o_ptr->name2)
335 ego_item_type *e_ptr = &e_info[o_ptr->name2];
336 if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
337 if (e_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
340 o_ptr->art_flags[2] &= (0x1FFFFFFFL);
344 rd_u32b(&o_ptr->curse_flags);
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: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
361 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
362 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
363 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
364 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
365 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
369 else if (o_ptr->xtra1 == EGO_XTRA_POWER)
371 switch (o_ptr->xtra2 % 11)
373 case 0: add_flag(o_ptr->art_flags, TR_RES_BLIND); break;
374 case 1: add_flag(o_ptr->art_flags, TR_RES_CONF); break;
375 case 2: add_flag(o_ptr->art_flags, TR_RES_SOUND); break;
376 case 3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
377 case 4: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
378 case 5: add_flag(o_ptr->art_flags, TR_RES_NEXUS); break;
379 case 6: add_flag(o_ptr->art_flags, TR_RES_CHAOS); break;
380 case 7: add_flag(o_ptr->art_flags, TR_RES_DISEN); break;
381 case 8: add_flag(o_ptr->art_flags, TR_RES_POIS); break;
382 case 9: add_flag(o_ptr->art_flags, TR_RES_DARK); break;
383 case 10: add_flag(o_ptr->art_flags, TR_RES_LITE); break;
387 else if (o_ptr->xtra1 == EGO_XTRA_ABILITY)
389 switch (o_ptr->xtra2 % 8)
391 case 0: add_flag(o_ptr->art_flags, TR_FEATHER); break;
392 case 1: add_flag(o_ptr->art_flags, TR_LITE); break;
393 case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS); break;
394 case 3: add_flag(o_ptr->art_flags, TR_WARNING); break;
395 case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
396 case 5: add_flag(o_ptr->art_flags, TR_REGEN); break;
397 case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT); break;
398 case 7: add_flag(o_ptr->art_flags, TR_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 if (h_older_than(1, 3, 0, 1))
433 if (item_tester_hook_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
434 o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
437 rd_s16b(&o_ptr->xtra4);
438 rd_s16b(&o_ptr->xtra5);
441 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)))
443 o_ptr->xtra4 = o_ptr->pval;
447 rd_byte(&o_ptr->feeling);
450 rd_string(buf, sizeof(buf));
452 /* Save the inscription */
453 if (buf[0]) o_ptr->inscription = quark_add(buf);
455 rd_string(buf, sizeof(buf));
456 if (buf[0]) o_ptr->art_name = quark_add(buf);
458 /* The Python object */
466 /* Mega-Hack -- handle "dungeon objects" later */
467 if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;
469 if (z_older_than(10, 4, 10) && (o_ptr->name2 == EGO_YOIYAMI)) o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
471 if (z_older_than(10, 4, 9))
473 if (have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY))
475 remove_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
476 add_flag(o_ptr->art_flags, TR_DEC_MANA);
483 artifact_type *a_ptr;
485 /* Obtain the artifact info */
486 a_ptr = &a_info[o_ptr->name1];
488 /* Verify that artifact */
489 if (!a_ptr->name) o_ptr->name1 = 0;
495 ego_item_type *e_ptr;
497 /* Obtain the ego-item info */
498 e_ptr = &e_info[o_ptr->name2];
500 /* Verify that ego-item */
501 if (!e_ptr->name) o_ptr->name2 = 0;
508 * Read an object (New method)
510 static void rd_item(object_type *o_ptr)
516 if (h_older_than(1, 5, 0, 0))
522 /*** Item save flags ***/
525 /*** Read un-obvious elements ***/
527 rd_s16b(&o_ptr->k_idx);
534 k_ptr = &k_info[o_ptr->k_idx];
535 o_ptr->tval = k_ptr->tval;
536 o_ptr->sval = k_ptr->sval;
539 if (flags & SAVE_ITEM_PVAL) rd_s16b(&o_ptr->pval);
540 else o_ptr->pval = 0;
542 if (flags & SAVE_ITEM_DISCOUNT) rd_byte(&o_ptr->discount);
543 else o_ptr->discount = 0;
544 if (flags & SAVE_ITEM_NUMBER) rd_byte(&o_ptr->number);
545 else o_ptr->number = 1;
547 rd_s16b(&o_ptr->weight);
549 if (flags & SAVE_ITEM_NAME1) rd_byte(&o_ptr->name1);
550 else o_ptr->name1 = 0;
551 if (flags & SAVE_ITEM_NAME2) rd_byte(&o_ptr->name2);
552 else o_ptr->name2 = 0;
553 if (flags & SAVE_ITEM_TIMEOUT) rd_s16b(&o_ptr->timeout);
554 else o_ptr->timeout = 0;
556 if (flags & SAVE_ITEM_TO_H) rd_s16b(&o_ptr->to_h);
557 else o_ptr->to_h = 0;
558 if (flags & SAVE_ITEM_TO_D) rd_s16b(&o_ptr->to_d);
559 else o_ptr->to_d = 0;
560 if (flags & SAVE_ITEM_TO_A) rd_s16b(&o_ptr->to_a);
561 else o_ptr->to_a = 0;
563 if (flags & SAVE_ITEM_AC) rd_s16b(&o_ptr->ac);
566 if (flags & SAVE_ITEM_DD) rd_byte(&o_ptr->dd);
568 if (flags & SAVE_ITEM_DS) rd_byte(&o_ptr->ds);
571 if (flags & SAVE_ITEM_IDENT) rd_byte(&o_ptr->ident);
572 else o_ptr->ident = 0;
574 if (flags & SAVE_ITEM_MARKED) rd_byte(&o_ptr->marked);
575 else o_ptr->marked = 0;
578 if (flags & SAVE_ITEM_ART_FLAGS0) rd_u32b(&o_ptr->art_flags[0]);
579 else o_ptr->art_flags[0] = 0;
580 if (flags & SAVE_ITEM_ART_FLAGS1) rd_u32b(&o_ptr->art_flags[1]);
581 else o_ptr->art_flags[1] = 0;
582 if (flags & SAVE_ITEM_ART_FLAGS2) rd_u32b(&o_ptr->art_flags[2]);
583 else o_ptr->art_flags[2] = 0;
584 if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
585 else o_ptr->art_flags[3] = 0;
587 if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
588 else o_ptr->curse_flags = 0;
590 /* Monster holding object */
591 if (flags & SAVE_ITEM_HELD_M_IDX) rd_s16b(&o_ptr->held_m_idx);
592 else o_ptr->held_m_idx = 0;
595 if (flags & SAVE_ITEM_XTRA1) rd_byte(&o_ptr->xtra1);
596 else o_ptr->xtra1 = 0;
597 if (flags & SAVE_ITEM_XTRA2) rd_byte(&o_ptr->xtra2);
598 else o_ptr->xtra2 = 0;
600 if (flags & SAVE_ITEM_XTRA3) rd_byte(&o_ptr->xtra3);
601 else o_ptr->xtra3 = 0;
603 if (flags & SAVE_ITEM_XTRA4) rd_s16b(&o_ptr->xtra4);
604 else o_ptr->xtra4 = 0;
605 if (flags & SAVE_ITEM_XTRA5) rd_s16b(&o_ptr->xtra5);
606 else o_ptr->xtra5 = 0;
608 if (flags & SAVE_ITEM_FEELING) rd_byte(&o_ptr->feeling);
609 else o_ptr->feeling = 0;
611 if (flags & SAVE_ITEM_INSCRIPTION)
613 rd_string(buf, sizeof(buf));
614 if (buf[0]) o_ptr->inscription = quark_add(buf);
615 else o_ptr->inscription = 0;
617 else o_ptr->inscription = 0;
619 if (flags & SAVE_ITEM_ART_NAME)
621 rd_string(buf, sizeof(buf));
622 if (buf[0]) o_ptr->art_name = quark_add(buf);
623 else o_ptr->art_name = 0;
625 else o_ptr->art_name = 0;
630 * Read a monster (Old method)
632 static void rd_monster_old(monster_type *m_ptr)
637 /* Read the monster race */
638 rd_s16b(&m_ptr->r_idx);
640 if (z_older_than(11, 0, 12))
641 m_ptr->ap_r_idx = m_ptr->r_idx;
643 rd_s16b(&m_ptr->ap_r_idx);
645 if (z_older_than(11, 0, 14))
647 monster_race *r_ptr = &r_info[m_ptr->r_idx];
649 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
650 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
651 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
654 rd_byte(&m_ptr->sub_align);
656 /* Read the other information */
660 rd_s16b(&m_ptr->maxhp);
661 if (z_older_than(11, 0, 5))
663 m_ptr->max_maxhp = m_ptr->maxhp;
667 rd_s16b(&m_ptr->max_maxhp);
669 rd_s16b(&m_ptr->csleep);
670 rd_byte(&m_ptr->mspeed);
671 if (z_older_than(10, 4, 2))
674 m_ptr->energy_need = (s16b)tmp8u;
676 else rd_s16b(&m_ptr->energy_need);
678 if (z_older_than(11, 0, 13))
679 m_ptr->energy_need = 100 - m_ptr->energy_need;
681 if (z_older_than(10,0,7))
688 rd_byte(&m_ptr->fast);
689 rd_byte(&m_ptr->slow);
691 rd_byte(&m_ptr->stunned);
692 rd_byte(&m_ptr->confused);
693 rd_byte(&m_ptr->monfear);
695 if (z_older_than(10,0,10))
699 else if (z_older_than(10,0,11))
707 rd_s16b(&m_ptr->target_y);
708 rd_s16b(&m_ptr->target_x);
711 rd_byte(&m_ptr->invulner);
713 if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
714 rd_u32b(&m_ptr->smart);
718 if (z_older_than(10, 4, 5))
721 rd_u32b(&m_ptr->exp);
723 if (z_older_than(10, 2, 2))
725 if (m_ptr->r_idx < 0)
727 m_ptr->r_idx = (0-m_ptr->r_idx);
728 m_ptr->mflag2 |= MFLAG2_KAGE;
733 rd_byte(&m_ptr->mflag2);
736 if (z_older_than(11, 0, 12))
738 if (m_ptr->mflag2 & MFLAG2_KAGE)
739 m_ptr->ap_r_idx = MON_KAGE;
742 if (z_older_than(10, 1, 3))
748 rd_string(buf, sizeof(buf));
749 if (buf[0]) m_ptr->nickname = quark_add(buf);
757 * Read a monster (New method)
759 static void rd_monster(monster_type *m_ptr)
764 if (h_older_than(1, 5, 0, 0))
766 rd_monster_old(m_ptr);
770 /*** Monster save flags ***/
773 /*** Read un-obvious elements ***/
775 /* Read the monster race */
776 rd_s16b(&m_ptr->r_idx);
778 /* Read the other information */
782 rd_s16b(&m_ptr->maxhp);
783 rd_s16b(&m_ptr->max_maxhp);
785 /* Monster race index of its appearance */
786 if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
787 else m_ptr->ap_r_idx = m_ptr->r_idx;
789 if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
790 else m_ptr->sub_align = 0;
792 if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->csleep);
793 else m_ptr->csleep = 0;
795 rd_byte(&m_ptr->mspeed);
797 rd_s16b(&m_ptr->energy_need);
799 if (flags & SAVE_MON_FAST) rd_byte(&m_ptr->fast);
800 else m_ptr->fast = 0;
801 if (flags & SAVE_MON_SLOW) rd_byte(&m_ptr->slow);
802 else m_ptr->slow = 0;
803 if (flags & SAVE_MON_STUNNED) rd_byte(&m_ptr->stunned);
804 else m_ptr->stunned = 0;
805 if (flags & SAVE_MON_CONFUSED) rd_byte(&m_ptr->confused);
806 else m_ptr->confused = 0;
807 if (flags & SAVE_MON_MONFEAR) rd_byte(&m_ptr->monfear);
808 else m_ptr->monfear = 0;
810 if (flags & SAVE_MON_TARGET_Y) rd_s16b(&m_ptr->target_y);
811 else m_ptr->target_y = 0;
812 if (flags & SAVE_MON_TARGET_X) rd_s16b(&m_ptr->target_x);
813 else m_ptr->target_x = 0;
815 if (flags & SAVE_MON_INVULNER) rd_byte(&m_ptr->invulner);
816 else m_ptr->invulner = 0;
818 if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
819 else m_ptr->smart = 0;
821 if (flags & SAVE_MON_EXP) rd_u32b(&m_ptr->exp);
824 m_ptr->mflag = 0; /* Not saved */
826 if (flags & SAVE_MON_MFLAG2) rd_byte(&m_ptr->mflag2);
827 else m_ptr->mflag2 = 0;
829 if (flags & SAVE_MON_NICKNAME)
831 rd_string(buf, sizeof(buf));
832 if (buf[0]) m_ptr->nickname = quark_add(buf);
833 else m_ptr->nickname = 0;
835 else m_ptr->nickname = 0;
840 * Old monster bit flags of racial resistances
842 #define RF3_IM_ACID 0x00010000 /* Resist acid a lot */
843 #define RF3_IM_ELEC 0x00020000 /* Resist elec a lot */
844 #define RF3_IM_FIRE 0x00040000 /* Resist fire a lot */
845 #define RF3_IM_COLD 0x00080000 /* Resist cold a lot */
846 #define RF3_IM_POIS 0x00100000 /* Resist poison a lot */
847 #define RF3_RES_TELE 0x00200000 /* Resist teleportation */
848 #define RF3_RES_NETH 0x00400000 /* Resist nether a lot */
849 #define RF3_RES_WATE 0x00800000 /* Resist water */
850 #define RF3_RES_PLAS 0x01000000 /* Resist plasma */
851 #define RF3_RES_NEXU 0x02000000 /* Resist nexus */
852 #define RF3_RES_DISE 0x04000000 /* Resist disenchantment */
853 #define RF3_RES_ALL 0x08000000 /* Resist all */
855 #define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
857 if ((R_PTR)->r_flags3 & (RF3)) \
859 (R_PTR)->r_flags3 &= ~(RF3); \
860 (R_PTR)->r_flagsr |= (RFR); \
864 #define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
866 if ((R_PTR)->r_flags4 & (RF4_BR)) \
868 (R_PTR)->r_flagsr |= (RFR); \
872 #define RF4_BR_LITE 0x00004000 /* Breathe Lite */
873 #define RF4_BR_DARK 0x00008000 /* Breathe Dark */
874 #define RF4_BR_CONF 0x00010000 /* Breathe Confusion */
875 #define RF4_BR_SOUN 0x00020000 /* Breathe Sound */
876 #define RF4_BR_CHAO 0x00040000 /* Breathe Chaos */
877 #define RF4_BR_TIME 0x00200000 /* Breathe Time */
878 #define RF4_BR_INER 0x00400000 /* Breathe Inertia */
879 #define RF4_BR_GRAV 0x00800000 /* Breathe Gravity */
880 #define RF4_BR_SHAR 0x01000000 /* Breathe Shards */
881 #define RF4_BR_WALL 0x04000000 /* Breathe Force */
883 * Read the monster lore
885 static void rd_lore(int r_idx)
889 monster_race *r_ptr = &r_info[r_idx];
891 /* Count sights/deaths/kills */
892 rd_s16b(&r_ptr->r_sights);
893 rd_s16b(&r_ptr->r_deaths);
894 rd_s16b(&r_ptr->r_pkills);
895 rd_s16b(&r_ptr->r_tkills);
897 /* Count wakes and ignores */
898 rd_byte(&r_ptr->r_wake);
899 rd_byte(&r_ptr->r_ignore);
902 rd_byte(&r_ptr->r_xtra1);
903 rd_byte(&r_ptr->r_xtra2);
906 rd_byte(&r_ptr->r_drop_gold);
907 rd_byte(&r_ptr->r_drop_item);
911 rd_byte(&r_ptr->r_cast_spell);
913 /* Count blows of each type */
914 rd_byte(&r_ptr->r_blows[0]);
915 rd_byte(&r_ptr->r_blows[1]);
916 rd_byte(&r_ptr->r_blows[2]);
917 rd_byte(&r_ptr->r_blows[3]);
920 rd_u32b(&r_ptr->r_flags1);
921 rd_u32b(&r_ptr->r_flags2);
922 rd_u32b(&r_ptr->r_flags3);
923 rd_u32b(&r_ptr->r_flags4);
924 rd_u32b(&r_ptr->r_flags5);
925 rd_u32b(&r_ptr->r_flags6);
926 if (h_older_than(1, 5, 0, 3))
928 r_ptr->r_flagsr = 0L;
930 /* Move RF3 resistance flags to RFR */
931 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID, RFR_IM_ACID);
932 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC, RFR_IM_ELEC);
933 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE, RFR_IM_FIRE);
934 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD, RFR_IM_COLD);
935 MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS, RFR_IM_POIS);
936 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
937 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
938 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
939 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
940 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
941 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
942 MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL, RFR_RES_ALL);
944 /* Separate breathers resistance from RF4 to RFR */
945 RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
946 RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
947 RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
948 RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
949 RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
950 RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
951 RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
952 RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
953 RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
955 /* Resist confusion is merged to RF3_NO_CONF */
956 if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
958 /* Misc resistance hack to RFR */
959 if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
960 if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
964 rd_u32b(&r_ptr->r_flagsr);
967 /* Read the "Racial" monster limit per level */
968 rd_byte(&r_ptr->max_num);
970 /* Location in saved floor */
971 rd_s16b(&r_ptr->floor_id);
976 /* Repair the lore flags */
977 r_ptr->r_flags1 &= r_ptr->flags1;
978 r_ptr->r_flags2 &= r_ptr->flags2;
979 r_ptr->r_flags3 &= r_ptr->flags3;
980 r_ptr->r_flags4 &= r_ptr->flags4;
981 r_ptr->r_flags5 &= r_ptr->flags5;
982 r_ptr->r_flags6 &= r_ptr->flags6;
983 r_ptr->r_flagsr &= r_ptr->flagsr;
990 * Add the item "o_ptr" to the inventory of the "Home"
992 * In all cases, return the slot (or -1) where the object was placed
994 * Note that this is a hacked up version of "inven_carry()".
996 * Also note that it may not correctly "adapt" to "knowledge" bacoming
997 * known, the player may have to pick stuff up and drop it again.
999 static void home_carry(store_type *st_ptr, object_type *o_ptr)
1002 s32b value, j_value;
1007 /* Check each existing item (try to combine) */
1008 for (slot = 0; slot < st_ptr->stock_num; slot++)
1010 /* Get the existing item */
1011 j_ptr = &st_ptr->stock[slot];
1013 /* The home acts just like the player */
1014 if (object_similar(j_ptr, o_ptr))
1016 /* Save the new number of items */
1017 object_absorb(j_ptr, o_ptr);
1025 if (st_ptr->stock_num >= STORE_INVEN_MAX * 10) {
1029 /* Determine the "value" of the item */
1030 value = object_value(o_ptr);
1032 /* Check existing slots to see if we must "slide" */
1033 for (slot = 0; slot < st_ptr->stock_num; slot++)
1036 j_ptr = &st_ptr->stock[slot];
1038 /* Hack -- readable books always come first */
1039 if ((o_ptr->tval == mp_ptr->spell_book) &&
1040 (j_ptr->tval != mp_ptr->spell_book)) break;
1041 if ((j_ptr->tval == mp_ptr->spell_book) &&
1042 (o_ptr->tval != mp_ptr->spell_book)) continue;
1044 /* Objects sort by decreasing type */
1045 if (o_ptr->tval > j_ptr->tval) break;
1046 if (o_ptr->tval < j_ptr->tval) continue;
1048 /* Can happen in the home */
1049 if (!object_aware_p(o_ptr)) continue;
1050 if (!object_aware_p(j_ptr)) break;
1052 /* Objects sort by increasing sval */
1053 if (o_ptr->sval < j_ptr->sval) break;
1054 if (o_ptr->sval > j_ptr->sval) continue;
1056 /* Objects in the home can be unknown */
1057 if (!object_known_p(o_ptr)) continue;
1058 if (!object_known_p(j_ptr)) break;
1061 * Hack: otherwise identical rods sort by
1062 * increasing recharge time --dsb
1064 if (o_ptr->tval == TV_ROD)
1066 if (o_ptr->pval < j_ptr->pval) break;
1067 if (o_ptr->pval > j_ptr->pval) continue;
1070 /* Objects sort by decreasing value */
1071 j_value = object_value(j_ptr);
1072 if (value > j_value) break;
1073 if (value < j_value) continue;
1076 /* Slide the others up */
1077 for (i = st_ptr->stock_num; i > slot; i--)
1079 st_ptr->stock[i] = st_ptr->stock[i-1];
1082 /* More stuff now */
1083 st_ptr->stock_num++;
1085 /* Insert the new item */
1086 st_ptr->stock[slot] = *o_ptr;
1088 chg_virtue(V_SACRIFICE, -1);
1090 /* Return the location */
1098 static errr rd_store(int town_number, int store_number)
1110 if (z_older_than(10, 3, 3) && (store_number == STORE_HOME))
1112 st_ptr = &town[1].store[store_number];
1113 if (st_ptr->stock_num) sort = TRUE;
1117 st_ptr = &town[town_number].store[store_number];
1120 /* Read the basic info */
1121 rd_s32b(&st_ptr->store_open);
1122 rd_s16b(&st_ptr->insult_cur);
1124 if (z_older_than(11, 0, 4))
1133 rd_s16b(&st_ptr->good_buy);
1134 rd_s16b(&st_ptr->bad_buy);
1136 /* Read last visit */
1137 rd_s32b(&st_ptr->last_visit);
1139 /* Extract the owner (see above) */
1140 st_ptr->owner = own;
1142 /* Read the items */
1143 for (j = 0; j < num; j++)
1148 /* Get local object */
1151 /* Wipe the object */
1157 /* Acquire valid items */
1158 if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : (store_number == STORE_MUSEUM ? (STORE_INVEN_MAX) * 50 : STORE_INVEN_MAX)))
1163 home_carry(st_ptr, q_ptr);
1167 k = st_ptr->stock_num++;
1169 /* Acquire the item */
1170 object_copy(&st_ptr->stock[k], q_ptr);
1182 * Read RNG state (added in 2.8.0)
1184 static void rd_randomizer(void)
1194 rd_u16b(&Rand_place);
1197 for (i = 0; i < RAND_DEG; i++)
1199 rd_u32b(&Rand_state[i]);
1209 * Read options (ignore most pre-2.8.0 options)
1211 * Note that the normal options are now stored as a set of 256 bit flags,
1212 * plus a set of 256 bit masks to indicate which bit flags were defined
1213 * at the time the savefile was created. This will allow new options
1214 * to be added, and old options to be removed, at any time, without
1215 * hurting old savefiles.
1217 * The window options are stored in the same way, but note that each
1218 * window gets 32 options, and their order is fixed by certain defines.
1220 static void rd_options(void)
1234 /* Ignore old options */
1238 /*** Special info */
1240 /* Read "delay_factor" */
1244 /* Read "hitpoint_warn" */
1248 /* Read "mana_warn" */
1249 if(h_older_than(1, 7, 0, 0))
1260 /*** Cheating options ***/
1264 if (c & 0x0002) p_ptr->wizard = TRUE;
1266 cheat_peek = (c & 0x0100) ? TRUE : FALSE;
1267 cheat_hear = (c & 0x0200) ? TRUE : FALSE;
1268 cheat_room = (c & 0x0400) ? TRUE : FALSE;
1269 cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
1270 cheat_know = (c & 0x1000) ? TRUE : FALSE;
1271 cheat_live = (c & 0x2000) ? TRUE : FALSE;
1272 cheat_save = (c & 0x4000) ? TRUE : FALSE;
1274 rd_byte((byte *)&autosave_l);
1275 rd_byte((byte *)&autosave_t);
1276 rd_s16b(&autosave_freq);
1279 /*** Normal Options ***/
1281 /* Read the option flags */
1282 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1284 /* Read the option masks */
1285 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1287 /* Analyze the options */
1288 for (n = 0; n < 8; n++)
1290 /* Analyze the options */
1291 for (i = 0; i < 32; i++)
1293 /* Process valid flags */
1294 if (mask[n] & (1L << i))
1296 /* Process valid flags */
1297 if (option_mask[n] & (1L << i))
1300 if (flag[n] & (1L << i))
1303 option_flag[n] |= (1L << i);
1310 option_flag[n] &= ~(1L << i);
1317 if (z_older_than(10, 4, 5))
1319 if (option_flag[5] & (0x00000001 << 4)) option_flag[5] &= ~(0x00000001 << 4);
1320 else option_flag[5] |= (0x00000001 << 4);
1321 if (option_flag[2] & (0x00000001 << 5)) option_flag[2] &= ~(0x00000001 << 5);
1322 else option_flag[2] |= (0x00000001 << 5);
1323 if (option_flag[4] & (0x00000001 << 5)) option_flag[4] &= ~(0x00000001 << 5);
1324 else option_flag[4] |= (0x00000001 << 5);
1325 if (option_flag[5] & (0x00000001 << 0)) option_flag[5] &= ~(0x00000001 << 0);
1326 else option_flag[5] |= (0x00000001 << 0);
1327 if (option_flag[5] & (0x00000001 << 12)) option_flag[5] &= ~(0x00000001 << 12);
1328 else option_flag[5] |= (0x00000001 << 12);
1329 if (option_flag[1] & (0x00000001 << 0)) option_flag[1] &= ~(0x00000001 << 0);
1330 else option_flag[1] |= (0x00000001 << 0);
1331 if (option_flag[1] & (0x00000001 << 18)) option_flag[1] &= ~(0x00000001 << 18);
1332 else option_flag[1] |= (0x00000001 << 18);
1333 if (option_flag[1] & (0x00000001 << 19)) option_flag[1] &= ~(0x00000001 << 19);
1334 else option_flag[1] |= (0x00000001 << 19);
1335 if (option_flag[5] & (0x00000001 << 3)) option_flag[1] &= ~(0x00000001 << 3);
1336 else option_flag[5] |= (0x00000001 << 3);
1339 /* Extract the options */
1340 extract_option_vars();
1343 /*** Window Options ***/
1345 /* Read the window flags */
1346 for (n = 0; n < 8; n++) rd_u32b(&flag[n]);
1348 /* Read the window masks */
1349 for (n = 0; n < 8; n++) rd_u32b(&mask[n]);
1351 /* Analyze the options */
1352 for (n = 0; n < 8; n++)
1354 /* Analyze the options */
1355 for (i = 0; i < 32; i++)
1357 /* Process valid flags */
1358 if (mask[n] & (1L << i))
1360 /* Process valid flags */
1361 if (window_mask[n] & (1L << i))
1364 if (flag[n] & (1L << i))
1367 window_flag[n] |= (1L << i);
1374 window_flag[n] &= ~(1L << i);
1387 * Hack -- strip the "ghost" info
1389 * XXX XXX XXX This is such a nasty hack it hurts.
1391 static void rd_ghost(void)
1396 rd_string(buf, sizeof(buf));
1398 /* Strip old data */
1404 * Save quick start data
1406 static void load_quick_start(void)
1411 if (z_older_than(11, 0, 13))
1413 previous_char.quick_ok = FALSE;
1417 rd_byte(&previous_char.psex);
1418 rd_byte(&previous_char.prace);
1419 rd_byte(&previous_char.pclass);
1420 rd_byte(&previous_char.pseikaku);
1421 rd_byte(&previous_char.realm1);
1422 rd_byte(&previous_char.realm2);
1424 rd_s16b(&previous_char.age);
1425 rd_s16b(&previous_char.ht);
1426 rd_s16b(&previous_char.wt);
1427 rd_s16b(&previous_char.sc);
1428 rd_s32b(&previous_char.au);
1430 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max[i]);
1431 for (i = 0; i < 6; i++) rd_s16b(&previous_char.stat_max_max[i]);
1433 for (i = 0; i < PY_MAX_LEVEL; i++) rd_s16b(&previous_char.player_hp[i]);
1435 rd_s16b(&previous_char.chaos_patron);
1437 for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
1439 for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
1441 rd_byte(&previous_char.quests);
1444 previous_char.quick_ok = (bool)tmp8u;
1448 * Read the "extra" information
1450 static void rd_extra(void)
1457 rd_string(player_name, sizeof(player_name));
1459 rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
1463 for (i = 0; i < 4; i++)
1465 rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
1468 /* Class/Race/Seikaku/Gender/Spells */
1469 rd_byte(&p_ptr->prace);
1470 rd_byte(&p_ptr->pclass);
1471 rd_byte(&p_ptr->pseikaku);
1472 rd_byte(&p_ptr->psex);
1473 rd_byte(&p_ptr->realm1);
1474 rd_byte(&p_ptr->realm2);
1475 rd_byte(&tmp8u); /* oops */
1477 if (z_older_than(10, 4, 4))
1479 if (p_ptr->realm1 == 9) p_ptr->realm1 = REALM_MUSIC;
1480 if (p_ptr->realm2 == 9) p_ptr->realm2 = REALM_MUSIC;
1481 if (p_ptr->realm1 == 10) p_ptr->realm1 = REALM_HISSATSU;
1482 if (p_ptr->realm2 == 10) p_ptr->realm2 = REALM_HISSATSU;
1485 /* Special Race/Class info */
1486 rd_byte(&p_ptr->hitdie);
1487 rd_u16b(&p_ptr->expfact);
1489 /* Age/Height/Weight */
1490 rd_s16b(&p_ptr->age);
1491 rd_s16b(&p_ptr->ht);
1492 rd_s16b(&p_ptr->wt);
1494 /* Read the stat info */
1495 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max[i]);
1496 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
1497 for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
1499 strip_bytes(24); /* oops */
1501 rd_s32b(&p_ptr->au);
1503 rd_s32b(&p_ptr->max_exp);
1504 if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
1505 else rd_s32b(&p_ptr->max_max_exp);
1506 rd_s32b(&p_ptr->exp);
1507 rd_u16b(&p_ptr->exp_frac);
1509 rd_s16b(&p_ptr->lev);
1511 for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
1512 if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
1514 for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
1516 if (z_older_than(10, 3, 6))
1517 for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1519 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
1520 for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
1521 if (z_older_than(10, 4, 1))
1523 if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
1524 p_ptr->skill_exp[GINOU_RIDING] = MIN(p_ptr->skill_exp[GINOU_RIDING], s_info[p_ptr->pclass].s_max[GINOU_RIDING]);
1526 if (z_older_than(10, 3, 14))
1528 for (i = 0; i < 108; i++) p_ptr->magic_num1[i] = 0;
1529 for (i = 0; i < 108; i++) p_ptr->magic_num2[i] = 0;
1533 for (i = 0; i < 108; i++) rd_s32b(&p_ptr->magic_num1[i]);
1534 for (i = 0; i < 108; i++) rd_byte(&p_ptr->magic_num2[i]);
1535 if (h_older_than(1, 3, 0, 1))
1537 if (p_ptr->pclass == CLASS_SMITH)
1539 p_ptr->magic_num1[TR_ES_ATTACK] = p_ptr->magic_num1[96];
1540 p_ptr->magic_num1[96] = 0;
1541 p_ptr->magic_num1[TR_ES_AC] = p_ptr->magic_num1[97];
1542 p_ptr->magic_num1[97] = 0;
1546 if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
1548 if (z_older_than(11, 0, 7))
1550 p_ptr->start_race = p_ptr->prace;
1551 p_ptr->old_race1 = 0L;
1552 p_ptr->old_race2 = 0L;
1553 p_ptr->old_realm = 0;
1557 rd_byte(&p_ptr->start_race);
1558 rd_s32b(&p_ptr->old_race1);
1559 rd_s32b(&p_ptr->old_race2);
1560 rd_s16b(&p_ptr->old_realm);
1563 if (z_older_than(10, 0, 1))
1565 for (i = 0; i < OLD_MAX_MANE; i++)
1567 p_ptr->mane_spell[i] = -1;
1568 p_ptr->mane_dam[i] = 0;
1570 p_ptr->mane_num = 0;
1572 else if (z_older_than(10, 2, 3))
1574 for (i = 0; i < OLD_MAX_MANE; i++)
1579 for (i = 0; i < MAX_MANE; i++)
1581 p_ptr->mane_spell[i] = -1;
1582 p_ptr->mane_dam[i] = 0;
1585 p_ptr->mane_num = 0;
1589 for (i = 0; i < MAX_MANE; i++)
1591 rd_s16b(&p_ptr->mane_spell[i]);
1592 rd_s16b(&p_ptr->mane_dam[i]);
1594 rd_s16b(&p_ptr->mane_num);
1597 if (z_older_than(10, 0, 3))
1599 determine_bounty_uniques();
1601 for (i = 0; i < MAX_KUBI; i++)
1603 /* Is this bounty unique already dead? */
1604 if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
1609 for (i = 0; i < MAX_KUBI; i++)
1611 rd_s16b(&kubi_r_idx[i]);
1615 if (z_older_than(10, 0, 3))
1621 for (i = 0; i < 4; i++)
1623 rd_s16b(&battle_mon[i]);
1624 if (z_older_than(10, 3, 4))
1627 mon_odds[i] = tmp16s;
1629 else rd_u32b(&mon_odds[i]);
1633 rd_s16b(&p_ptr->town_num);
1635 /* Read arena and rewards information */
1636 rd_s16b(&p_ptr->arena_number);
1637 if (h_older_than(1, 5, 0, 1))
1639 /* Arena loser of previous version was marked number 99 */
1640 if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
1643 p_ptr->inside_arena = (bool)tmp16s;
1644 rd_s16b(&p_ptr->inside_quest);
1645 if (z_older_than(10, 3, 5)) p_ptr->inside_battle = FALSE;
1649 p_ptr->inside_battle = (bool)tmp16s;
1651 rd_byte(&p_ptr->exit_bldg);
1652 rd_byte(&p_ptr->leftbldg);
1654 rd_s16b(&p_ptr->oldpx);
1655 rd_s16b(&p_ptr->oldpy);
1656 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
1660 if (tmp16s > MAX_BACT)
1663 note(format("¤ÎÃæ", tmp16s));
1665 note(format("Too many (%d) building rewards!", tmp16s));
1670 for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
1672 rd_s16b(&p_ptr->mhp);
1673 rd_s16b(&p_ptr->chp);
1674 rd_u16b(&p_ptr->chp_frac);
1676 rd_s16b(&p_ptr->msp);
1677 rd_s16b(&p_ptr->csp);
1678 rd_u16b(&p_ptr->csp_frac);
1680 rd_s16b(&p_ptr->max_plv);
1681 if (z_older_than(10, 3, 8))
1683 rd_s16b(&max_dlv[DUNGEON_ANGBAND]);
1687 byte max = (byte)max_d_idx;
1691 for(i = 0; i < max; i++)
1693 rd_s16b(&max_dlv[i]);
1694 if (max_dlv[i] > d_info[i].maxdepth) max_dlv[i] = d_info[i].maxdepth;
1698 /* Repair maximum player level XXX XXX XXX */
1699 if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
1703 rd_s16b(&p_ptr->sc);
1706 /* Read the flags */
1707 strip_bytes(2); /* Old "rest" */
1708 rd_s16b(&p_ptr->blind);
1709 rd_s16b(&p_ptr->paralyzed);
1710 rd_s16b(&p_ptr->confused);
1711 rd_s16b(&p_ptr->food);
1712 strip_bytes(4); /* Old "food_digested" / "protection" */
1714 rd_s16b(&p_ptr->energy_need);
1715 if (z_older_than(11, 0, 13))
1716 p_ptr->energy_need = 100 - p_ptr->energy_need;
1718 rd_s16b(&p_ptr->fast);
1719 rd_s16b(&p_ptr->slow);
1720 rd_s16b(&p_ptr->afraid);
1721 rd_s16b(&p_ptr->cut);
1722 rd_s16b(&p_ptr->stun);
1723 rd_s16b(&p_ptr->poisoned);
1724 rd_s16b(&p_ptr->image);
1725 rd_s16b(&p_ptr->protevil);
1726 rd_s16b(&p_ptr->invuln);
1727 if(z_older_than(10, 0, 0))
1730 rd_s16b(&p_ptr->ult_res);
1731 rd_s16b(&p_ptr->hero);
1732 rd_s16b(&p_ptr->shero);
1733 rd_s16b(&p_ptr->shield);
1734 rd_s16b(&p_ptr->blessed);
1735 rd_s16b(&p_ptr->tim_invis);
1736 rd_s16b(&p_ptr->word_recall);
1737 if (z_older_than(10, 3, 8))
1738 p_ptr->recall_dungeon = DUNGEON_ANGBAND;
1742 p_ptr->recall_dungeon = (byte)tmp16s;
1745 if (h_older_than(1, 5, 0, 0))
1746 p_ptr->alter_reality = 0;
1748 rd_s16b(&p_ptr->alter_reality);
1750 rd_s16b(&p_ptr->see_infra);
1751 rd_s16b(&p_ptr->tim_infra);
1752 rd_s16b(&p_ptr->oppose_fire);
1753 rd_s16b(&p_ptr->oppose_cold);
1754 rd_s16b(&p_ptr->oppose_acid);
1755 rd_s16b(&p_ptr->oppose_elec);
1756 rd_s16b(&p_ptr->oppose_pois);
1757 if (z_older_than(10,0,2)) p_ptr->tsuyoshi = 0;
1758 else rd_s16b(&p_ptr->tsuyoshi);
1760 /* Old savefiles do not have the following fields... */
1761 if ((z_major == 2) && (z_minor == 0) && (z_patch == 6))
1764 p_ptr->wraith_form = 0;
1765 p_ptr->resist_magic = 0;
1766 p_ptr->tim_regen = 0;
1767 p_ptr->kabenuke = 0;
1768 p_ptr->tim_stealth = 0;
1769 p_ptr->tim_ffall = 0;
1770 p_ptr->tim_sh_touki = 0;
1771 p_ptr->lightspeed = 0;
1772 p_ptr->tsubureru = 0;
1773 p_ptr->tim_res_nether = 0;
1774 p_ptr->tim_res_time = 0;
1775 p_ptr->mimic_form = 0;
1776 p_ptr->tim_mimic = 0;
1777 p_ptr->tim_sh_fire = 0;
1780 p_ptr->tim_reflect = 0;
1781 p_ptr->multishadow = 0;
1782 p_ptr->dustrobe = 0;
1784 p_ptr->chaos_patron = get_chaos_patron();
1792 rd_s16b(&p_ptr->tim_esp);
1793 rd_s16b(&p_ptr->wraith_form);
1794 rd_s16b(&p_ptr->resist_magic);
1795 rd_s16b(&p_ptr->tim_regen);
1796 rd_s16b(&p_ptr->kabenuke);
1797 rd_s16b(&p_ptr->tim_stealth);
1798 rd_s16b(&p_ptr->tim_ffall);
1799 rd_s16b(&p_ptr->tim_sh_touki);
1800 rd_s16b(&p_ptr->lightspeed);
1801 rd_s16b(&p_ptr->tsubureru);
1802 if (z_older_than(10, 4, 7))
1803 p_ptr->magicdef = 0;
1805 rd_s16b(&p_ptr->magicdef);
1806 rd_s16b(&p_ptr->tim_res_nether);
1807 if (z_older_than(10, 4, 11))
1809 p_ptr->tim_res_time = 0;
1810 p_ptr->mimic_form = 0;
1811 p_ptr->tim_mimic = 0;
1812 p_ptr->tim_sh_fire = 0;
1816 rd_s16b(&p_ptr->tim_res_time);
1817 rd_byte(&p_ptr->mimic_form);
1818 rd_s16b(&p_ptr->tim_mimic);
1819 rd_s16b(&p_ptr->tim_sh_fire);
1822 if (z_older_than(11, 0, 99))
1824 p_ptr->tim_sh_holy = 0;
1825 p_ptr->tim_eyeeye = 0;
1829 rd_s16b(&p_ptr->tim_sh_holy);
1830 rd_s16b(&p_ptr->tim_eyeeye);
1834 if ( z_older_than(11,0,3) ){
1835 p_ptr->tim_reflect=0;
1836 p_ptr->multishadow=0;
1840 rd_s16b(&p_ptr->tim_reflect);
1841 rd_s16b(&p_ptr->multishadow);
1842 rd_s16b(&p_ptr->dustrobe);
1845 rd_s16b(&p_ptr->chaos_patron);
1846 rd_u32b(&p_ptr->muta1);
1847 rd_u32b(&p_ptr->muta2);
1848 rd_u32b(&p_ptr->muta3);
1850 for (i = 0; i < 8; i++)
1851 rd_s16b(&p_ptr->virtues[i]);
1852 for (i = 0; i < 8; i++)
1853 rd_s16b(&p_ptr->vir_types[i]);
1856 /* Calc the regeneration modifier for mutations */
1857 mutant_regenerate_mod = calc_mutant_regenerate_mod();
1859 if (z_older_than(10,0,9))
1862 if (tmp8u) p_ptr->special_attack = ATTACK_CONFUSE;
1863 p_ptr->ele_attack = 0;
1867 rd_s16b(&p_ptr->ele_attack);
1868 rd_u32b(&p_ptr->special_attack);
1870 if (p_ptr->special_attack & KAMAE_MASK) p_ptr->action = ACTION_KAMAE;
1871 else if (p_ptr->special_attack & KATA_MASK) p_ptr->action = ACTION_KATA;
1872 if (z_older_than(10,0,12))
1874 p_ptr->ele_immune = 0;
1875 p_ptr->special_defense = 0;
1879 rd_s16b(&p_ptr->ele_immune);
1880 rd_u32b(&p_ptr->special_defense);
1882 rd_byte(&p_ptr->knowledge);
1883 rd_byte(&tmp8u); /* oops */
1884 rd_byte(&tmp8u); /* oops */
1885 rd_byte(&p_ptr->action);
1886 if (!z_older_than(10, 4, 3))
1889 if (tmp8u) p_ptr->action = ACTION_LEARN;
1891 rd_byte((byte *)&preserve_mode);
1892 rd_byte((byte *)&p_ptr->wait_report_score);
1895 for (i = 0; i < 48; i++) rd_byte(&tmp8u);
1897 /* Skip the flags */
1901 /* Hack -- the two "special seeds" */
1902 rd_u32b(&seed_flavor);
1903 rd_u32b(&seed_town);
1907 rd_u16b(&p_ptr->panic_save);
1908 rd_u16b(&p_ptr->total_winner);
1909 rd_u16b(&p_ptr->noscore);
1914 p_ptr->is_dead = tmp8u;
1916 /* Read "feeling" */
1920 /* Turn of last "feeling" */
1926 if (z_older_than(10, 3, 12))
1928 dungeon_turn = turn;
1930 else rd_s32b(&dungeon_turn);
1932 if (z_older_than(11, 0, 13))
1939 if (z_older_than(10, 3, 13))
1943 else rd_s32b(&old_battle);
1945 if (z_older_than(10,0,3))
1947 determine_today_mon(TRUE);
1951 rd_s16b(&today_mon);
1952 rd_s16b(&p_ptr->today_mon);
1955 if (z_older_than(10,0,7))
1961 rd_s16b(&p_ptr->riding);
1964 /* Current floor_id */
1965 if (h_older_than(1, 5, 0, 0))
1967 p_ptr->floor_id = 0;
1971 rd_s16b(&p_ptr->floor_id);
1974 if (h_older_than(1, 5, 0, 2))
1980 /* Get number of party_mon array */
1983 /* Strip old temporary preserved pets */
1984 for (i = 0; i < tmp16s; i++)
1986 monster_type dummy_mon;
1988 rd_monster(&dummy_mon);
1992 if (z_older_than(10,1,2))
2001 if (z_older_than(10,3,9))
2005 else if (z_older_than(10, 3, 10))
2013 rd_s32b(&p_ptr->visit);
2015 if (!z_older_than(11, 0, 5))
2017 rd_u32b(&p_ptr->count);
2025 * Read the player inventory
2027 * Note that the inventory changed in Angband 2.7.4. Two extra
2028 * pack slots were added and the equipment was rearranged. Note
2029 * that these two features combine when parsing old save-files, in
2030 * which items from the old "aux" slot are "carried", perhaps into
2031 * one of the two new "inventory" slots.
2033 * Note that the inventory is "re-sorted" later by "dungeon()".
2035 static errr rd_inventory(void)
2043 p_ptr->total_weight = 0;
2049 /* Read until done */
2054 /* Get the next item index */
2057 /* Nope, we reached the end */
2058 if (n == 0xFFFF) break;
2060 /* Get local object */
2063 /* Wipe the object */
2069 /* Hack -- verify item */
2070 if (!q_ptr->k_idx) return (53);
2072 /* Wield equipment */
2073 if (n >= INVEN_RARM)
2076 object_copy(&inventory[n], q_ptr);
2078 /* Add the weight */
2079 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2085 /* Warning -- backpack is full */
2086 else if (inven_cnt == INVEN_PACK)
2090 note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
2092 note("Too many items in the inventory!");
2100 /* Carry inventory */
2107 object_copy(&inventory[n], q_ptr);
2109 /* Add the weight */
2110 p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
2124 * Read the saved messages
2126 static void rd_messages(void)
2136 /* Read the messages */
2137 for (i = 0; i < num; i++)
2139 /* Read the message */
2140 rd_string(buf, sizeof(buf));
2142 /* Save the message */
2149 /* Old hidden trap flag */
2150 #define CAVE_TRAP 0x8000
2153 * Read the dungeon (old method)
2155 * The monsters/objects must be loaded in the same order
2156 * that they were stored, since the actual indexes matter.
2158 static errr rd_dungeon_old(void)
2169 /*** Basic info ***/
2172 rd_s16b(&dun_level);
2173 if (z_older_than(10, 3, 8)) dungeon_type = DUNGEON_ANGBAND;
2174 else rd_byte(&dungeon_type);
2176 /* Set the base level for old versions */
2177 base_level = dun_level;
2179 rd_s16b(&base_level);
2181 rd_s16b(&num_repro);
2186 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
2189 rd_s16b(&tmp16s); /* max_panel_rows */
2190 rd_s16b(&tmp16s); /* max_panel_cols */
2193 if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤¤ÎÉüµìÍÑ */
2201 /*** Run length decoding ***/
2203 /* Load the dungeon data */
2204 for (x = y = 0; y < ymax; )
2210 if (z_older_than(10,3,6))
2219 /* Decline invalid flags */
2220 info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
2223 /* Apply the RLE info */
2224 for (i = count; i > 0; i--)
2226 /* Access the cave */
2227 c_ptr = &cave[y][x];
2229 /* Extract "info" */
2239 if (++y >= ymax) break;
2245 /*** Run length decoding ***/
2247 /* Load the dungeon data */
2248 for (x = y = 0; y < ymax; )
2254 /* Apply the RLE info */
2255 for (i = count; i > 0; i--)
2257 /* Access the cave */
2258 c_ptr = &cave[y][x];
2260 /* Extract "feat" */
2261 c_ptr->feat = tmp8u;
2270 if (++y >= ymax) break;
2275 /*** Run length decoding ***/
2277 /* Load the dungeon data */
2278 for (x = y = 0; y < ymax; )
2284 /* Apply the RLE info */
2285 for (i = count; i > 0; i--)
2287 /* Access the cave */
2288 c_ptr = &cave[y][x];
2290 /* Extract "feat" */
2291 c_ptr->mimic = tmp8u;
2300 if (++y >= ymax) break;
2305 /*** Run length decoding ***/
2307 /* Load the dungeon data */
2308 for (x = y = 0; y < ymax; )
2314 /* Apply the RLE info */
2315 for (i = count; i > 0; i--)
2317 /* Access the cave */
2318 c_ptr = &cave[y][x];
2320 /* Extract "feat" */
2321 c_ptr->special = tmp16s;
2330 if (++y >= ymax) break;
2335 /* Convert cave data */
2336 if (z_older_than(11, 0, 99))
2338 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2340 /* Wipe old unused flags */
2341 cave[y][x].info &= ~(CAVE_MASK);
2345 if (h_older_than(1, 1, 1, 0))
2347 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2349 /* Access the cave */
2350 c_ptr = &cave[y][x];
2353 if (c_ptr->feat == FEAT_INVIS)
2355 c_ptr->feat = FEAT_FLOOR;
2356 c_ptr->info |= CAVE_TRAP;
2359 /* Older than 1.1.1 */
2360 if (c_ptr->feat == FEAT_MIRROR)
2362 c_ptr->feat = FEAT_FLOOR;
2363 c_ptr->info |= CAVE_OBJECT;
2368 if (h_older_than(1, 3, 1, 0))
2370 for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
2372 /* Access the cave */
2373 c_ptr = &cave[y][x];
2375 /* Old CAVE_IN_MIRROR flag */
2376 if (c_ptr->info & CAVE_OBJECT)
2378 c_ptr->mimic = FEAT_MIRROR;
2381 /* Runes will be mimics and flags */
2382 else if (c_ptr->feat == FEAT_MINOR_GLYPH ||
2383 c_ptr->feat == FEAT_GLYPH)
2385 c_ptr->info |= CAVE_OBJECT;
2386 c_ptr->mimic = c_ptr->feat;
2387 c_ptr->feat = FEAT_FLOOR;
2390 /* Hidden traps will be trap terrains mimicing floor */
2391 else if (c_ptr->info & CAVE_TRAP)
2393 c_ptr->info &= ~CAVE_TRAP;
2394 c_ptr->mimic = c_ptr->feat;
2395 c_ptr->feat = choose_random_trap();
2398 /* Another hidden trap */
2399 else if (c_ptr->feat == FEAT_INVIS)
2401 c_ptr->mimic = FEAT_FLOOR;
2402 c_ptr->feat = FEAT_TRAP_OPEN;
2405 /* Hidden doors will be closed doors mimicing wall */
2406 else if (c_ptr->feat == FEAT_SECRET)
2408 place_closed_door(y, x);
2409 c_ptr->mimic = FEAT_WALL_EXTRA;
2416 /* Read the item count */
2419 /* Verify maximum */
2420 if (limit > max_o_idx)
2423 note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2425 note(format("Too many (%d) object entries!", limit));
2431 /* Read the dungeon items */
2432 for (i = 1; i < limit; i++)
2439 /* Get a new record */
2446 note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
2448 note(format("Object allocation error (%d <> %d)", i, o_idx));
2456 o_ptr = &o_list[o_idx];
2462 /* XXX XXX XXX XXX XXX */
2465 if (o_ptr->held_m_idx)
2467 monster_type *m_ptr;
2470 m_ptr = &m_list[o_ptr->held_m_idx];
2473 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2475 /* Place the object */
2476 m_ptr->hold_o_idx = o_idx;
2482 /* Access the item location */
2483 c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2486 o_ptr->next_o_idx = c_ptr->o_idx;
2488 /* Place the object */
2489 c_ptr->o_idx = o_idx;
2496 /* Read the monster count */
2499 /* Hack -- verify */
2500 if (limit > max_m_idx)
2503 note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
2505 note(format("Too many (%d) monster entries!", limit));
2511 /* Read the monsters */
2512 for (i = 1; i < limit; i++)
2515 monster_type *m_ptr;
2517 /* Get a new record */
2524 note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
2526 note(format("Monster allocation error (%d <> %d)", i, m_idx));
2533 /* Acquire monster */
2534 m_ptr = &m_list[m_idx];
2536 /* Read the monster */
2541 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2543 /* Mark the location */
2544 c_ptr->m_idx = m_idx;
2547 real_r_ptr(m_ptr)->cur_num++;
2552 /* The dungeon is ready */
2553 if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
2554 character_dungeon = FALSE;
2556 character_dungeon = TRUE;
2565 * Read the saved floor
2567 * The monsters/objects must be loaded in the same order
2568 * that they were stored, since the actual indexes matter.
2570 static errr rd_saved_floor(saved_floor_type *sf_ptr)
2582 cave_template_type *template;
2585 /*** Wipe all cave ***/
2589 /*** Basic info ***/
2591 /* Dungeon floor specific info follows */
2595 /*** Not a saved floor ***/
2597 rd_s16b(&dun_level);
2598 base_level = dun_level;
2602 /*** The saved floor ***/
2605 if (tmp16s != sf_ptr->floor_id) return 171;
2608 if (tmp8u != sf_ptr->savefile_id) return 171;
2611 if (tmp16s != sf_ptr->dun_level) return 171;
2612 dun_level = sf_ptr->dun_level;
2615 if (tmp32s != sf_ptr->last_visit) return 171;
2618 if (tmp32u != sf_ptr->visit_mark) return 171;
2621 if (tmp16s != sf_ptr->upper_floor_id) return 171;
2624 if (tmp16s != sf_ptr->lower_floor_id) return 171;
2627 rd_s16b(&base_level);
2628 rd_s16b(&num_repro);
2643 /*** Read template for cave_type ***/
2645 /* Read the template count */
2648 /* Allocate the "template" array */
2649 C_MAKE(template, limit, cave_template_type);
2651 /* Read the templates */
2652 for (i = 0; i < limit; i++)
2654 cave_template_type *ct_ptr = &template[i];
2657 rd_u16b(&ct_ptr->info);
2658 rd_byte(&ct_ptr->feat);
2659 rd_byte(&ct_ptr->mimic);
2660 rd_s16b(&ct_ptr->special);
2668 /*** Run length decoding ***/
2670 /* Load the dungeon data */
2671 for (x = y = 0; y < ymax; )
2683 } while (tmp8u == MAX_UCHAR);
2685 /* Apply the RLE info */
2686 for (i = count; i > 0; i--)
2688 /* Access the cave */
2689 cave_type *c_ptr = &cave[y][x];
2691 /* Extract cave data */
2692 c_ptr->info = template[id].info;
2693 c_ptr->feat = template[id].feat;
2694 c_ptr->mimic = template[id].mimic;
2695 c_ptr->special = template[id].special;
2704 if (++y >= ymax) break;
2709 /* Free the "template" array */
2710 C_FREE(template, limit, cave_template_type);
2715 /* Read the item count */
2718 /* Verify maximum */
2719 if (limit > max_o_idx) return 151;
2722 /* Read the dungeon items */
2723 for (i = 1; i < limit; i++)
2729 /* Get a new record */
2733 if (i != o_idx) return 152;
2736 o_ptr = &o_list[o_idx];
2743 if (o_ptr->held_m_idx)
2745 monster_type *m_ptr;
2748 m_ptr = &m_list[o_ptr->held_m_idx];
2751 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2753 /* Place the object */
2754 m_ptr->hold_o_idx = o_idx;
2760 /* Access the item location */
2761 cave_type *c_ptr = &cave[o_ptr->iy][o_ptr->ix];
2764 o_ptr->next_o_idx = c_ptr->o_idx;
2766 /* Place the object */
2767 c_ptr->o_idx = o_idx;
2774 /* Read the monster count */
2777 /* Hack -- verify */
2778 if (limit > max_m_idx) return 161;
2780 /* Read the monsters */
2781 for (i = 1; i < limit; i++)
2785 monster_type *m_ptr;
2787 /* Get a new record */
2791 if (i != m_idx) return 162;
2794 /* Acquire monster */
2795 m_ptr = &m_list[m_idx];
2797 /* Read the monster */
2802 c_ptr = &cave[m_ptr->fy][m_ptr->fx];
2804 /* Mark the location */
2805 c_ptr->m_idx = m_idx;
2808 real_r_ptr(m_ptr)->cur_num++;
2817 * Read the dungeon (new method)
2819 * The monsters/objects must be loaded in the same order
2820 * that they were stored, since the actual indexes matter.
2822 static errr rd_dungeon(void)
2828 /* Initialize saved_floors array and temporal files */
2829 init_saved_floors();
2832 if (h_older_than(1, 5, 0, 0))
2834 err = rd_dungeon_old();
2836 /* Prepare floor_id of current floor */
2839 p_ptr->floor_id = get_new_floor_id();
2840 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
2849 /* Number of floor_id used from birth */
2850 rd_s16b(&max_floor_id);
2852 /* Current dungeon type */
2853 rd_byte(&dungeon_type);
2856 /* Number of the saved_floors array elements */
2859 /*** On the surface ***/
2862 /* It should be 0 */
2865 /* Read the current floor data */
2866 err = rd_saved_floor(NULL);
2869 /*** In the dungeon ***/
2873 /* Read the saved_floors array */
2874 for (i = 0; i < num; i++)
2876 saved_floor_type *sf_ptr = &saved_floors[i];
2878 rd_s16b(&sf_ptr->floor_id);
2879 rd_byte(&sf_ptr->savefile_id);
2880 rd_s16b(&sf_ptr->dun_level);
2881 rd_s32b(&sf_ptr->last_visit);
2882 rd_u32b(&sf_ptr->visit_mark);
2883 rd_s16b(&sf_ptr->upper_floor_id);
2884 rd_s16b(&sf_ptr->lower_floor_id);
2888 /* Move saved floors data to temporal files */
2889 for (i = 0; i < num; i++)
2891 saved_floor_type *sf_ptr = &saved_floors[i];
2894 /* Unused element */
2895 if (!sf_ptr->floor_id) continue;
2897 /* Read the failure mark */
2899 if (tmp8u) continue;
2901 /* Read from the save file */
2902 err = rd_saved_floor(sf_ptr);
2907 /* Re-save as temporal saved floor file */
2908 if (!save_floor(sf_ptr, SLF_SECOND)) err = 182;
2914 /* Finally load current floor data from temporal file */
2917 if (!load_floor(get_sf_ptr(p_ptr->floor_id), SLF_SECOND)) err = 183;
2922 /*** Error messages ***/
2927 note("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
2929 note("Too many object entries!");
2935 note("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼");
2937 note("Object allocation error");
2943 note("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë¡ª");
2945 note("Too many monster entries!");
2951 note("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼");
2953 note("Monster allocation error");
2959 note("Êݸ¤µ¤ì¤¿¥Õ¥í¥¢¤Î¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡ª");
2961 note("Dungeon data of saved floors are broken!");
2975 note("¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
2977 note("Failed to make temporal files!");
2990 /* The dungeon is ready */
2991 character_dungeon = TRUE;
2993 /* Success or Error */
2999 * Actually read the savefile
3001 static errr rd_savefile_new_aux(void)
3013 #ifdef VERIFY_CHECKSUMS
3014 u32b n_x_check, n_v_check;
3015 u32b o_x_check, o_v_check;
3019 /* Mention the savefile version */
3022 "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
3024 "Loading a %d.%d.%d savefile...",
3026 (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
3029 /* Strip the version bytes */
3032 /* Hack -- decrypt */
3033 xor_byte = sf_extra;
3036 /* Clear the checksums */
3040 /* Read the version number of the savefile */
3041 /* Old savefile will be version 0.0.0.3 */
3042 rd_byte(&h_ver_extra);
3043 rd_byte(&h_ver_patch);
3044 rd_byte(&h_ver_minor);
3045 rd_byte(&h_ver_major);
3047 /* Operating system info */
3048 rd_u32b(&sf_system);
3050 /* Time of savefile creation */
3053 /* Number of resurrections */
3056 /* Number of times played */
3060 /* Later use (always zero) */
3063 /* Later use (always zero) */
3067 /* Read RNG state */
3070 if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3072 if (arg_fiddle) note("Loaded Randomizer Info");
3077 /* Then the options */
3080 if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3082 if (arg_fiddle) note("Loaded Option Flags");
3085 /* Then the "messages" */
3088 if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3090 if (arg_fiddle) note("Loaded Messages");
3095 for (i = 0; i < max_r_idx; i++)
3097 /* Access that monster */
3098 monster_race *r_ptr = &r_info[i];
3100 /* Hack -- Reset the death counter */
3101 r_ptr->max_num = 100;
3103 if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
3105 /* Hack -- Non-unique Nazguls are semi-unique */
3106 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
3109 /* Monster Memory */
3112 /* Incompatible save files */
3113 if (tmp16u > max_r_idx)
3116 note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3118 note(format("Too many (%u) monster races!", tmp16u));
3124 /* Read the available records */
3125 for (i = 0; i < tmp16u; i++)
3132 if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3134 if (arg_fiddle) note("Loaded Monster Memory");
3142 /* Incompatible save files */
3143 if (tmp16u > max_k_idx)
3146 note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3148 note(format("Too many (%u) object kinds!", tmp16u));
3154 /* Read the object memory */
3155 for (i = 0; i < tmp16u; i++)
3158 object_kind *k_ptr = &k_info[i];
3162 k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
3163 k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
3166 if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤ÎµÏ¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3168 if (arg_fiddle) note("Loaded Object Memory");
3174 * Initialize arena and rewards information
3176 p_ptr->arena_number = 0;
3177 p_ptr->inside_arena = 0;
3178 p_ptr->inside_quest = 0;
3179 p_ptr->leftbldg = FALSE;
3180 p_ptr->exit_bldg = TRUE;
3182 /* Start in town 1 */
3183 p_ptr->town_num = 1;
3185 p_ptr->wilderness_x = 4;
3186 p_ptr->wilderness_y = 4;
3190 /* Init the wilderness seeds */
3191 for (i = 0; i < max_wild_x; i++)
3193 for (j = 0; j < max_wild_y; j++)
3195 wilderness[j][i].seed = randint0(0x10000000);
3199 /* 2.1.3 or newer version */
3201 u16b max_towns_load;
3202 u16b max_quests_load;
3203 byte max_rquests_load;
3204 s16b old_inside_quest = p_ptr->inside_quest;
3206 /* Number of towns */
3207 rd_u16b(&max_towns_load);
3209 /* Incompatible save files */
3210 if (max_towns_load > max_towns)
3213 note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
3215 note(format("Too many (%u) towns!", max_towns_load));
3221 /* Number of quests */
3222 rd_u16b(&max_quests_load);
3224 if (z_older_than(11, 0, 7))
3226 max_rquests_load = 10;
3230 rd_byte(&max_rquests_load);
3233 /* Incompatible save files */
3234 if (max_quests_load > max_quests)
3237 note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
3239 note(format("Too many (%u) quests!", max_quests_load));
3245 for (i = 0; i < max_quests_load; i++)
3249 rd_s16b(&quest[i].status);
3250 rd_s16b(&quest[i].level);
3252 if (z_older_than(11, 0, 6))
3254 quest[i].complev = 0;
3258 rd_byte(&quest[i].complev);
3261 /* Load quest status if quest is running */
3262 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))))
3264 rd_s16b(&quest[i].cur_num);
3265 rd_s16b(&quest[i].max_num);
3266 rd_s16b(&quest[i].type);
3268 /* Load quest monster index */
3269 rd_s16b(&quest[i].r_idx);
3271 if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
3273 determine_random_questor(&quest[i]);
3276 /* Load quest item index */
3277 rd_s16b(&quest[i].k_idx);
3280 a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
3282 rd_byte(&quest[i].flags);
3284 if (z_older_than(10, 3, 11))
3286 if (quest[i].flags & QUEST_FLAG_PRESET)
3288 quest[i].dungeon = 0;
3292 init_flags = INIT_ASSIGN;
3293 p_ptr->inside_quest = i;
3295 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3296 p_ptr->inside_quest = old_inside_quest;
3301 rd_byte(&quest[i].dungeon);
3304 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
3305 if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
3306 r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
3309 /* Ignore the empty quests from old versions */
3312 /* Ignore quest status */
3315 /* Ignore quest level */
3319 * We don't have to care about the other info,
3320 * since status should be 0 for these quests anyway
3325 /* Position in the wilderness */
3326 rd_s32b(&p_ptr->wilderness_x);
3327 rd_s32b(&p_ptr->wilderness_y);
3328 if (z_older_than(10, 3, 13))
3330 p_ptr->wilderness_x = 5;
3331 p_ptr->wilderness_y = 48;
3334 if (z_older_than(10, 3, 7)) p_ptr->wild_mode = FALSE;
3335 else rd_byte((byte *)&p_ptr->wild_mode);
3336 if (z_older_than(10, 3, 7)) ambush_flag = FALSE;
3337 else rd_byte((byte *)&ambush_flag);
3339 /* Size of the wilderness */
3340 rd_s32b(&wild_x_size);
3341 rd_s32b(&wild_y_size);
3343 /* Incompatible save files */
3344 if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
3347 note(format("¹ÓÌÂ礤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
3349 note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
3355 /* Load the wilderness seeds */
3356 for (i = 0; i < wild_x_size; i++)
3358 for (j = 0; j < wild_y_size; j++)
3360 rd_u32b(&wilderness[j][i].seed);
3366 if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3368 if (arg_fiddle) note("Loaded Quests");
3371 /* Load the Artifacts */
3374 /* Incompatible save files */
3375 if (tmp16u > max_a_idx)
3378 note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
3380 note(format("Too many (%u) artifacts!", tmp16u));
3386 /* Read the artifact flags */
3387 for (i = 0; i < tmp16u; i++)
3389 artifact_type *a_ptr = &a_info[i];
3392 a_ptr->cur_num = tmp8u;
3394 if (h_older_than(1, 5, 0, 0))
3396 a_ptr->floor_id = 0;
3404 rd_s16b(&a_ptr->floor_id);
3408 if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3410 if (arg_fiddle) note("Loaded Artifacts");
3415 /* Read the extra stuff */
3417 if (p_ptr->energy_need < -999) world_player = TRUE;
3420 if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
3422 if (arg_fiddle) note("Loaded extra information");
3426 /* Read the player_hp array */
3429 /* Incompatible save files */
3430 if (tmp16u > PY_MAX_LEVEL)
3433 note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礤¹¤®¤ë(%u)¡ª", tmp16u));
3435 note(format("Too many (%u) hitpoint entries!", tmp16u));
3441 /* Read the player_hp array */
3442 for (i = 0; i < tmp16u; i++)
3444 rd_s16b(&p_ptr->player_hp[i]);
3447 /* Important -- Initialize the sex */
3448 sp_ptr = &sex_info[p_ptr->psex];
3450 /* Important -- Initialize the race/class */
3451 rp_ptr = &race_info[p_ptr->prace];
3452 cp_ptr = &class_info[p_ptr->pclass];
3453 ap_ptr = &seikaku_info[p_ptr->pseikaku];
3455 if(z_older_than(10, 2, 2) && (p_ptr->pclass == CLASS_BEASTMASTER) && !p_ptr->is_dead)
3457 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3458 do_cmd_rerate(FALSE);
3460 if(z_older_than(10, 3, 2) && (p_ptr->pclass == CLASS_ARCHER) && !p_ptr->is_dead)
3462 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3463 do_cmd_rerate(FALSE);
3465 if(z_older_than(10, 2, 6) && (p_ptr->pclass == CLASS_SORCERER) && !p_ptr->is_dead)
3467 p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3468 do_cmd_rerate(FALSE);
3470 if(z_older_than(10, 4, 7) && (p_ptr->pclass == CLASS_BLUE_MAGE) && !p_ptr->is_dead)
3472 p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3473 do_cmd_rerate(FALSE);
3476 /* Important -- Initialize the magic */
3477 mp_ptr = &m_info[p_ptr->pclass];
3480 /* Read spell info */
3481 rd_u32b(&p_ptr->spell_learned1);
3482 rd_u32b(&p_ptr->spell_learned2);
3483 rd_u32b(&p_ptr->spell_worked1);
3484 rd_u32b(&p_ptr->spell_worked2);
3485 rd_u32b(&p_ptr->spell_forgotten1);
3486 rd_u32b(&p_ptr->spell_forgotten2);
3488 if (z_older_than(10,0,5))
3490 p_ptr->learned_spells = 0;
3491 for (i = 0; i < 64; i++)
3493 /* Count known spells */
3495 (p_ptr->spell_learned1 & (1L << i)) :
3496 (p_ptr->spell_learned2 & (1L << (i - 32))))
3498 p_ptr->learned_spells++;
3502 else rd_s16b(&p_ptr->learned_spells);
3504 if (z_older_than(10,0,6))
3506 p_ptr->add_spells = 0;
3508 else rd_s16b(&p_ptr->add_spells);
3509 if (p_ptr->pclass == CLASS_MINDCRAFTER) p_ptr->add_spells = 0;
3511 for (i = 0; i < 64; i++)
3513 rd_byte(&p_ptr->spell_order[i]);
3517 /* Read the inventory */
3521 note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó");
3523 note("Unable to read inventory");
3529 /* Read number of towns */
3531 town_count = tmp16u;
3533 /* Read the stores */
3535 for (i = 1; i < town_count; i++)
3537 for (j = 0; j < tmp16u; j++)
3539 if (rd_store(i, j)) return (22);
3543 rd_s16b(&p_ptr->pet_follow_distance);
3544 if (z_older_than(10, 4, 10))
3546 p_ptr->pet_extra_flags = 0;
3548 if (tmp8u) p_ptr->pet_extra_flags |= PF_OPEN_DOORS;
3550 if (tmp8u) p_ptr->pet_extra_flags |= PF_PICKUP_ITEMS;
3552 if (z_older_than(10,0,4)) p_ptr->pet_extra_flags |= PF_TELEPORT;
3556 if (tmp8u) p_ptr->pet_extra_flags |= PF_TELEPORT;
3559 if (z_older_than(10,0,7)) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3563 if (tmp8u) p_ptr->pet_extra_flags |= PF_ATTACK_SPELL;
3566 if (z_older_than(10,0,8)) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3570 if (tmp8u) p_ptr->pet_extra_flags |= PF_SUMMON_SPELL;
3573 if (!z_older_than(10,0,8))
3576 if (tmp8u) p_ptr->pet_extra_flags |= PF_BALL_SPELL;
3581 rd_s16b(&p_ptr->pet_extra_flags);
3584 if (!z_older_than(11, 0, 9))
3586 char buf[SCREEN_BUF_SIZE];
3587 rd_string(buf, sizeof(buf));
3588 if (buf[0]) screen_dump = string_make(buf);
3593 for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3595 r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3600 /* I'm not dead yet... */
3601 if (!p_ptr->is_dead)
3603 /* Dead players have no dungeon */
3605 note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
3607 note("Restoring Dungeon...");
3613 note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
3615 note("Error reading dungeon data");
3621 /* Read the ghost info */
3628 strip_bytes(tmp32s);
3633 #ifdef VERIFY_CHECKSUMS
3635 /* Save the checksum */
3636 n_v_check = v_check;
3638 /* Read the old checksum */
3639 rd_u32b(&o_v_check);
3642 if (o_v_check != n_v_check)
3645 note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3647 note("Invalid checksum");
3654 /* Save the encoded checksum */
3655 n_x_check = x_check;
3657 /* Read the checksum */
3658 rd_u32b(&o_x_check);
3662 if (o_x_check != n_x_check)
3665 note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
3667 note("Invalid encoded checksum");
3681 * Actually read the savefile
3683 errr rd_savefile_new(void)
3687 /* Grab permissions */
3690 /* The savefile is a binary file */
3691 fff = my_fopen(savefile, "rb");
3693 /* Drop permissions */
3697 if (!fff) return (-1);
3699 /* Call the sub-function */
3700 err = rd_savefile_new_aux();
3702 /* Check for errors */
3703 if (ferror(fff)) err = -1;
3705 /* Close the file */
3714 * Actually load and verify a floor save data
3716 static bool load_floor_aux(saved_floor_type *sf_ptr)
3721 #ifdef VERIFY_CHECKSUMS
3722 u32b n_x_check, n_v_check;
3723 u32b o_x_check, o_v_check;
3726 /* Hack -- decrypt (read xor_byte) */
3730 /* Clear the checksums */
3734 /* Set the version number to current version */
3735 /* Never load old temporal files */
3736 h_ver_extra = H_VER_EXTRA;
3737 h_ver_patch = H_VER_PATCH;
3738 h_ver_minor = H_VER_MINOR;
3739 h_ver_major = H_VER_MAJOR;
3741 /* Verify the sign */
3743 if (saved_floor_file_sign != tmp32u) return FALSE;
3745 /* Read -- have error? */
3746 if (rd_saved_floor(sf_ptr)) return FALSE;
3749 #ifdef VERIFY_CHECKSUMS
3750 /* Save the checksum */
3751 n_v_check = v_check;
3753 /* Read the old checksum */
3754 rd_u32b(&o_v_check);
3757 if (o_v_check != n_v_check) return FALSE;
3759 /* Save the encoded checksum */
3760 n_x_check = x_check;
3762 /* Read the checksum */
3763 rd_u32b(&o_x_check);
3766 if (o_x_check != n_x_check) return FALSE;
3775 * Attempt to load the temporally saved-floor data
3777 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
3779 FILE *old_fff = NULL;
3780 byte old_xor_byte = 0;
3781 u32b old_v_check = 0;
3782 u32b old_x_check = 0;
3783 byte old_h_ver_major = 0;
3784 byte old_h_ver_minor = 0;
3785 byte old_h_ver_patch = 0;
3786 byte old_h_ver_extra = 0;
3789 char floor_savefile[1024];
3791 /* We have one file already opened */
3792 if (mode & SLF_SECOND)
3794 /* Backup original values */
3796 old_xor_byte = xor_byte;
3797 old_v_check = v_check;
3798 old_x_check = x_check;
3799 old_h_ver_major = h_ver_major;
3800 old_h_ver_minor = h_ver_minor;
3801 old_h_ver_patch = h_ver_patch;
3802 old_h_ver_extra = h_ver_extra;
3805 /* floor savefile */
3806 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
3808 /* Grab permissions */
3811 /* The savefile is a binary file */
3812 fff = my_fopen(floor_savefile, "rb");
3814 /* Drop permissions */
3818 if (!fff) ok = FALSE;
3820 /* Attempt to load */
3823 /* Load saved floor data from file */
3824 ok = load_floor_aux(sf_ptr);
3826 /* Check for errors */
3827 if (ferror(fff)) ok = FALSE;
3829 /* Close the file */
3832 /* Grab permissions */
3835 /* Delete the file */
3836 if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
3838 /* Drop permissions */
3842 /* We have one file already opened */
3843 if (mode & SLF_SECOND)
3845 /* Restore original values */
3847 xor_byte = old_xor_byte;
3848 v_check = old_v_check;
3849 x_check = old_x_check;
3850 h_ver_major = old_h_ver_major;
3851 h_ver_minor = old_h_ver_minor;
3852 h_ver_patch = old_h_ver_patch;
3853 h_ver_extra = old_h_ver_extra;