/*! * @brief セーブデータの書き込み / * Actually write a save-file * @return 成功すればtrue */ static bool wr_savefile_new(void) { int i, j; u32b now; byte tmp8u; u16b tmp16u; /* Compact the objects */ compact_objects(0); /* Compact the monsters */ compact_monsters(0); /* Guess at the current time */ now = time((time_t *)0); /* Note the operating system */ sf_system = 0L; /* Note when the file was saved */ sf_when = now; /* Note the number of saves */ sf_saves++; /*** Actually write the file ***/ /* Dump the file header */ xor_byte = 0; wr_byte(FAKE_VER_MAJOR); xor_byte = 0; wr_byte(FAKE_VER_MINOR); xor_byte = 0; wr_byte(FAKE_VER_PATCH); xor_byte = 0; /* Initial value of xor_byte */ tmp8u = (byte)Rand_external(256); wr_byte(tmp8u); /* Reset the checksum */ v_stamp = 0L; x_stamp = 0L; /* Write the savefile version for Hengband 1.1.1 and later */ wr_byte(H_VER_EXTRA); wr_byte(H_VER_PATCH); wr_byte(H_VER_MINOR); wr_byte(H_VER_MAJOR); /* Operating system */ wr_u32b(sf_system); /* Time file last saved */ wr_u32b(sf_when); /* Number of past lives */ wr_u16b(sf_lives); /* Number of times saved */ wr_u16b(sf_saves); /* Space */ wr_u32b(0L); wr_u16b(0); wr_byte(0); #ifdef JP # ifdef EUC /* EUC kanji code */ wr_byte(2); # endif # ifdef SJIS /* SJIS kanji code */ wr_byte(3); # endif #else /* ASCII */ wr_byte(1); #endif /* Write the RNG state */ wr_randomizer(); /* Write the boolean "options" */ wr_options(); /* Dump the number of "messages" */ tmp16u = message_num(); if (compress_savefile && (tmp16u > 40)) tmp16u = 40; wr_u16b(tmp16u); /* Dump the messages (oldest first!) */ for (i = tmp16u - 1; i >= 0; i--) { wr_string(message_str((s16b)i)); } /* Dump the monster lore */ tmp16u = max_r_idx; wr_u16b(tmp16u); for (i = 0; i < tmp16u; i++) wr_lore(i); /* Dump the object memory */ tmp16u = max_k_idx; wr_u16b(tmp16u); for (i = 0; i < tmp16u; i++) wr_xtra(i); /* Dump the towns */ tmp16u = max_towns; wr_u16b(tmp16u); /* Dump the quests */ tmp16u = max_quests; wr_u16b(tmp16u); /* Dump the quests */ tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST; wr_byte(tmp8u); for (i = 0; i < max_quests; i++) { quest_type* const q_ptr = &quest[i]; /* Save status for every quest */ wr_s16b(q_ptr->status); /* And the dungeon level too */ /* (prevents problems with multi-level quests) */ wr_s16b(q_ptr->level); wr_byte(q_ptr->complev); wr_u32b(q_ptr->comptime); /* Save quest status if quest is running */ if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i)) { wr_s16b(q_ptr->cur_num); wr_s16b(q_ptr->max_num); wr_s16b(q_ptr->type); wr_s16b(q_ptr->r_idx); wr_s16b(q_ptr->k_idx); wr_byte(q_ptr->flags); wr_byte(q_ptr->dungeon); } } /* Dump the position in the wilderness */ wr_s32b(p_ptr->wilderness_x); wr_s32b(p_ptr->wilderness_y); wr_byte(p_ptr->wild_mode); wr_byte(ambush_flag); wr_s32b(max_wild_x); wr_s32b(max_wild_y); /* Dump the wilderness seeds */ for (i = 0; i < max_wild_x; i++) { for (j = 0; j < max_wild_y; j++) { wr_u32b(wilderness[j][i].seed); } } /* Hack -- Dump the artifacts */ tmp16u = max_a_idx; wr_u16b(tmp16u); for (i = 0; i < tmp16u; i++) { artifact_type *a_ptr = &a_info[i]; wr_byte(a_ptr->cur_num); wr_s16b(a_ptr->floor_id); } /* Write the "extra" information */ wr_extra(); /* Dump the "player hp" entries */ tmp16u = PY_MAX_LEVEL; wr_u16b(tmp16u); for (i = 0; i < tmp16u; i++) { wr_s16b(p_ptr->player_hp[i]); } /* Write spell data */ wr_u32b(p_ptr->spell_learned1); wr_u32b(p_ptr->spell_learned2); wr_u32b(p_ptr->spell_worked1); wr_u32b(p_ptr->spell_worked2); wr_u32b(p_ptr->spell_forgotten1); wr_u32b(p_ptr->spell_forgotten2); wr_s16b(p_ptr->learned_spells); wr_s16b(p_ptr->add_spells); /* Dump the ordered spells */ for (i = 0; i < 64; i++) { wr_byte(p_ptr->spell_order[i]); } /* Write the inventory */ for (i = 0; i < INVEN_TOTAL; i++) { object_type *o_ptr = &inventory[i]; /* Skip non-objects */ if (!o_ptr->k_idx) continue; /* Dump index */ wr_u16b((u16b)i); /* Dump object */ wr_item(o_ptr); } /* Add a sentinel */ wr_u16b(0xFFFF); /* Note the towns */ tmp16u = max_towns; wr_u16b(tmp16u); /* Note the stores */ tmp16u = MAX_STORES; wr_u16b(tmp16u); /* Dump the stores of all towns */ for (i = 1; i < max_towns; i++) { for (j = 0; j < MAX_STORES; j++) { wr_store(&town[i].store[j]); } } /* Write the pet command settings */ wr_s16b(p_ptr->pet_follow_distance); wr_s16b(p_ptr->pet_extra_flags); /* Write screen dump for sending score */ if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead)) { wr_string(screen_dump); } else { wr_string(""); } /* Player is not dead, write the dungeon */ if (!p_ptr->is_dead) { /* Dump the dungeon */ if (!wr_dungeon()) return FALSE; /* Dump the ghost */ wr_ghost(); /* No scripts */ wr_s32b(0); } /* Write the "value check-sum" */ wr_u32b(v_stamp); /* Write the "encoded checksum" */ wr_u32b(x_stamp); /* Error in save */ if (ferror(fff) || (fflush(fff) == EOF)) return FALSE; /* Successful save */ return TRUE; }
/* * Actually write a save-file */ static bool wr_savefile(void) { int i; u32b now; u16b tmp16u; /* Guess at the current time */ now = time((time_t *)0); /* Note the operating system */ sf_xtra = 0L; /* Note when the file was saved */ sf_when = now; /* Note the number of saves */ sf_saves++; /*** Actually write the file ***/ /* Dump the file header */ xor_byte = 0; wr_byte(VERSION_MAJOR); xor_byte = 0; wr_byte(VERSION_MINOR); xor_byte = 0; wr_byte(VERSION_PATCH); xor_byte = 0; wr_byte(VERSION_EXTRA); /* Reset the checksum */ v_stamp = 0L; x_stamp = 0L; /* Operating system */ wr_u32b(sf_xtra); /* Time file last saved */ wr_u32b(sf_when); /* Number of past lives */ wr_u16b(sf_lives); /* Number of times saved */ wr_u16b(sf_saves); // 8 spare bytes wr_u32b(0L); wr_u32b(0L); /* Write the RNG state */ wr_randomizer(); /* Write the boolean "options" */ wr_options(); /* Dump the number of "messages" */ tmp16u = message_num(); wr_u16b(tmp16u); /* Dump the messages (oldest first!) */ for (i = tmp16u - 1; i >= 0; i--) { wr_string(message_str((s16b)i)); wr_u16b(message_type((s16b)i)); } /* Dump the monster lore */ tmp16u = z_info->r_max; wr_u16b(tmp16u); for (i = 0; i < tmp16u; i++) wr_lore(i); /* Dump the object memory */ tmp16u = z_info->k_max; wr_u16b(tmp16u); for (i = 0; i < tmp16u; i++) wr_xtra(i); /* Hack -- Dump the artefacts */ tmp16u = z_info->art_max; wr_u16b(tmp16u); for (i = 0; i < tmp16u; i++) { artefact_type *a_ptr = &a_info[i]; wr_byte(a_ptr->cur_num); wr_byte(a_ptr->found_num); } /* Write the "extra" information */ wr_extra(); /*Write the randarts*/ wr_randarts(); /*Copy the notes file into the savefile*/ wr_notes(); // Write the smithing item wr_item(smith_o_ptr); /* Write the inventory */ for (i = 0; i < INVEN_TOTAL; i++) { object_type *o_ptr = &inventory[i]; /* Skip non-objects */ if (!o_ptr->k_idx) continue; /* Dump index */ wr_u16b((u16b)i); /* Dump object */ wr_item(o_ptr); } /* Add a sentinel */ wr_u16b(0xFFFF); /* Player is not dead, write the dungeon */ if (!p_ptr->is_dead) { /* Dump the dungeon */ wr_dungeon(); } /* Write the "value check-sum" */ wr_u32b(v_stamp); /* Write the "encoded checksum" */ wr_u32b(x_stamp); /* Error in save */ if (ferror(fff) || (fflush(fff) == EOF)) return FALSE; /* Successful save */ return TRUE; }