3 * @brief セーブファイル書き込み処理 / Purpose: interact with savefiles
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
15 #include "birth/quick-start.h"
16 #include "cmd-building/cmd-building.h"
17 #include "util/sort.h"
18 #include "dungeon/dungeon.h"
19 #include "dungeon/quest.h"
20 #include "floor/floor-events.h"
21 #include "floor/floor-town.h"
22 #include "floor/floor.h"
23 #include "floor/wild.h"
24 #include "game-option/birth-options.h"
25 #include "game-option/cheat-options.h"
26 #include "game-option/option-flags.h"
27 #include "game-option/option-types-table.h"
28 #include "game-option/runtime-arguments.h"
29 #include "game-option/special-options.h"
30 #include "game-option/text-display-options.h"
31 #include "grid/grid.h"
32 #include "io/files-util.h"
34 #include "io/report.h"
35 #include "io/uid-checker.h"
36 #include "monster-race/monster-race.h"
37 #include "monster/monster-compaction.h"
38 #include "monster/monster-info.h"
39 #include "monster/monster-status.h"
40 #include "object-enchant/artifact.h"
41 #include "object/object-kind.h"
42 #include "store/store-util.h"
43 #include "store/store.h"
44 #include "system/angband-version.h"
45 #include "util/angband-files.h"
46 #include "util/quarks.h"
47 #include "view/display-main-window.h"
48 #include "view/display-messages.h"
49 #include "world/world.h"
52 * Some "local" parameters, used to help write savefiles
55 static FILE *fff; /* Current save "file" */
56 static byte xor_byte; /* Simple encryption */
57 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
58 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
61 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
65 static void sf_put(byte v)
67 /* Encode the value, write a character */
69 (void)putc((int)xor_byte, fff);
71 /* Maintain the checksum info */
78 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
82 static void wr_byte(byte v)
89 * @brief 符号なし16ビットをファイルに書き込む
90 * @param v 書き込む符号なし16bit値
93 static void wr_u16b(u16b v)
95 sf_put((byte)(v & 0xFF));
96 sf_put((byte)((v >> 8) & 0xFF));
101 * @brief 符号あり16ビットをファイルに書き込む
102 * @param v 書き込む符号あり16bit値
105 static void wr_s16b(s16b v)
112 * @brief 符号なし32ビットをファイルに書き込む
113 * @param v 書き込む符号なし32bit値
116 static void wr_u32b(u32b v)
118 sf_put((byte)(v & 0xFF));
119 sf_put((byte)((v >> 8) & 0xFF));
120 sf_put((byte)((v >> 16) & 0xFF));
121 sf_put((byte)((v >> 24) & 0xFF));
126 * @brief 符号あり32ビットをファイルに書き込む
127 * @param v 書き込む符号あり32bit値
130 static void wr_s32b(s32b v)
137 * @brief 文字列をファイルに書き込む
141 static void wr_string(concptr str)
153 * These functions write info in larger logical records
158 * @brief アイテムオブジェクトを書き込む / Write an "item" record
159 * @param o_ptr アイテムオブジェクト保存元ポインタ
162 static void wr_item(object_type *o_ptr)
164 BIT_FLAGS flags = 0x00000000;
166 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
167 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
168 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
169 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
170 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
171 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
172 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
173 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
174 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
175 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
176 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
177 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
178 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
179 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
180 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
181 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
182 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
183 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
184 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
185 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
186 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
187 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
188 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
189 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
190 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
191 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
192 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
193 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
194 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
196 /*** Item save flags ***/
199 /*** Write only un-obvious elements ***/
200 wr_s16b(o_ptr->k_idx);
202 wr_byte((byte)o_ptr->iy);
203 wr_byte((byte)o_ptr->ix);
205 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
207 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
208 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte)o_ptr->number);
210 wr_s16b((s16b)o_ptr->weight);
212 if (flags & SAVE_ITEM_NAME1) wr_byte((byte)o_ptr->name1);
213 if (flags & SAVE_ITEM_NAME2) wr_byte((byte)o_ptr->name2);
214 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
216 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
217 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
218 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
219 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
220 if (flags & SAVE_ITEM_DD) wr_byte((byte)o_ptr->dd);
221 if (flags & SAVE_ITEM_DS) wr_byte((byte)o_ptr->ds);
223 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
225 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
227 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
228 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
229 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
230 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
231 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
233 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
235 /* Held by monster index */
236 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
238 /* Extra information */
239 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
240 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
241 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
242 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
243 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
246 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
248 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
249 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
254 * @brief モンスター情報を書き込む / Write a "monster" record
255 * @param m_ptr モンスター情報保存元ポインタ
258 static void wr_monster(monster_type *m_ptr)
260 BIT_FLAGS flags = 0x00000000;
261 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
262 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
263 if (monster_csleep_remaining(m_ptr)) flags |= SAVE_MON_CSLEEP;
264 if (monster_fast_remaining(m_ptr)) flags |= SAVE_MON_FAST;
265 if (monster_slow_remaining(m_ptr)) flags |= SAVE_MON_SLOW;
266 if (monster_stunned_remaining(m_ptr)) flags |= SAVE_MON_STUNNED;
267 if (monster_confused_remaining(m_ptr)) flags |= SAVE_MON_CONFUSED;
268 if (monster_fear_remaining(m_ptr)) flags |= SAVE_MON_MONFEAR;
269 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
270 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
271 if (monster_invulner_remaining(m_ptr)) flags |= SAVE_MON_INVULNER;
272 if (m_ptr->smart) flags |= SAVE_MON_SMART;
273 if (m_ptr->exp) flags |= SAVE_MON_EXP;
274 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
275 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
276 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
278 /*** Monster save flags ***/
281 /*** Write only un-obvious elements ***/
282 wr_s16b(m_ptr->r_idx);
283 wr_byte((byte)m_ptr->fy);
284 wr_byte((byte)m_ptr->fx);
285 wr_s16b((s16b)m_ptr->hp);
286 wr_s16b((s16b)m_ptr->maxhp);
287 wr_s16b((s16b)m_ptr->max_maxhp);
288 wr_u32b(m_ptr->dealt_damage);
290 /* Monster race index of its appearance */
291 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
293 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
294 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
296 wr_byte((byte)m_ptr->mspeed);
297 wr_s16b(m_ptr->energy_need);
300 if (flags & SAVE_MON_FAST)
302 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
305 if (flags & SAVE_MON_SLOW)
307 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
310 if (flags & SAVE_MON_STUNNED)
312 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
315 if (flags & SAVE_MON_CONFUSED)
317 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
320 if (flags & SAVE_MON_MONFEAR)
322 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
325 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
326 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
327 if (flags & SAVE_MON_INVULNER)
329 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
332 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
333 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
334 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
335 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
336 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
341 * @brief モンスターの思い出を書き込む / Write a "lore" record
342 * @param r_idx モンスター種族ID
345 static void wr_lore(MONRACE_IDX r_idx)
347 /* Count sights/deaths/kills */
348 monster_race *r_ptr = &r_info[r_idx];
349 wr_s16b((s16b)r_ptr->r_sights);
350 wr_s16b((s16b)r_ptr->r_deaths);
351 wr_s16b((s16b)r_ptr->r_pkills);
352 wr_s16b((s16b)r_ptr->r_akills);
353 wr_s16b((s16b)r_ptr->r_tkills);
355 /* Count wakes and ignores */
356 wr_byte(r_ptr->r_wake);
357 wr_byte(r_ptr->r_ignore);
360 wr_byte(r_ptr->r_xtra1);
361 wr_byte(r_ptr->r_xtra2);
364 wr_byte((byte)r_ptr->r_drop_gold);
365 wr_byte((byte)r_ptr->r_drop_item);
368 wr_byte(0); /* unused now */
369 wr_byte(r_ptr->r_cast_spell);
371 /* Count blows of each type */
372 wr_byte(r_ptr->r_blows[0]);
373 wr_byte(r_ptr->r_blows[1]);
374 wr_byte(r_ptr->r_blows[2]);
375 wr_byte(r_ptr->r_blows[3]);
378 wr_u32b(r_ptr->r_flags1);
379 wr_u32b(r_ptr->r_flags2);
380 wr_u32b(r_ptr->r_flags3);
381 wr_u32b(r_ptr->r_flags4);
382 wr_u32b(r_ptr->r_flags5);
383 wr_u32b(r_ptr->r_flags6);
384 wr_u32b(r_ptr->r_flagsr);
386 /* Monster limit per level */
387 wr_byte((byte)r_ptr->max_num);
389 /* Location in saved floor */
390 wr_s16b(r_ptr->floor_id);
397 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
398 * @param k_idx ベースアイテムのID
401 static void wr_xtra(KIND_OBJECT_IDX k_idx)
405 object_kind *k_ptr = &k_info[k_idx];
407 if (k_ptr->aware) tmp8u |= 0x01;
408 if (k_ptr->tried) tmp8u |= 0x02;
415 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
416 * @param store_ptr 店舗情報の参照ポインタ
419 static void wr_store(store_type *store_ptr)
421 /* Save the "open" counter */
422 wr_u32b(store_ptr->store_open);
424 /* Save the "insults" */
425 wr_s16b(store_ptr->insult_cur);
427 /* Save the current owner */
428 wr_byte(store_ptr->owner);
430 /* Save the stock size */
431 wr_s16b(store_ptr->stock_num);
433 /* Save the "haggle" info */
434 wr_s16b(store_ptr->good_buy);
435 wr_s16b(store_ptr->bad_buy);
437 wr_s32b(store_ptr->last_visit);
440 for (int j = 0; j < store_ptr->stock_num; j++)
442 /* Save each item in stock */
443 wr_item(&store_ptr->stock[j]);
449 * @brief セーブデータに乱数情報を書き込む / Write RNG state
452 static errr wr_randomizer(void)
457 for (int i = 0; i < RAND_DEG; i++)
459 wr_u32b(Rand_state[i]);
467 * @brief ゲームオプション情報を書き込む / Write the "options"
470 static void wr_options(void)
472 for (int i = 0; i < 4; i++) wr_u32b(0L);
474 /*** Special options ***/
475 /* Write "delay_factor" */
476 wr_byte(delay_factor);
478 /* Write "hitpoint_warn" */
479 wr_byte(hitpoint_warn);
481 /* Write "mana_warn" */
484 /*** Cheating options ***/
487 if (current_world_ptr->wizard) c |= 0x0002;
489 if (cheat_sight) c |= 0x0040;
490 if (cheat_turn) c |= 0x0080;
492 if (cheat_peek) c |= 0x0100;
493 if (cheat_hear) c |= 0x0200;
494 if (cheat_room) c |= 0x0400;
495 if (cheat_xtra) c |= 0x0800;
496 if (cheat_know) c |= 0x1000;
497 if (cheat_live) c |= 0x2000;
498 if (cheat_save) c |= 0x4000;
499 if (cheat_diary_output) c |= 0x8000;
506 wr_s16b(autosave_freq);
508 /*** Extract options ***/
509 /* Analyze the options */
510 for (int i = 0; option_info[i].o_desc; i++)
512 int os = option_info[i].o_set;
513 int ob = option_info[i].o_bit;
515 /* Process real entries */
516 if (!option_info[i].o_var) continue;
518 if (*option_info[i].o_var)
520 option_flag[os] |= (1L << ob);
524 option_flag[os] &= ~(1L << ob);
528 /*** Normal options ***/
530 for (int i = 0; i < 8; i++) wr_u32b(option_flag[i]);
533 for (int i = 0; i < 8; i++) wr_u32b(option_mask[i]);
535 /*** Window options ***/
537 for (int i = 0; i < 8; i++) wr_u32b(window_flag[i]);
540 for (int i = 0; i < 8; i++) wr_u32b(window_mask[i]);
545 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
548 static void wr_ghost(void)
550 wr_string(_("不正なゴースト", "Broken Ghost"));
552 /* Hack -- stupid data */
553 for (int i = 0; i < 60; i++) wr_byte(0);
558 * @brief クイック・スタート情報を書き込む / Save quick start data
561 static void save_quick_start(void)
563 wr_byte(previous_char.psex);
564 wr_byte((byte)previous_char.prace);
565 wr_byte((byte)previous_char.pclass);
566 wr_byte((byte)previous_char.pseikaku);
567 wr_byte((byte)previous_char.realm1);
568 wr_byte((byte)previous_char.realm2);
570 wr_s16b(previous_char.age);
571 wr_s16b(previous_char.ht);
572 wr_s16b(previous_char.wt);
573 wr_s16b(previous_char.sc);
574 wr_s32b(previous_char.au);
576 for (int i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
577 for (int i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
579 for (int i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
581 wr_s16b(previous_char.chaos_patron);
583 for (int i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
585 for (int i = 0; i < 4; i++) wr_string(previous_char.history[i]);
587 /* UNUSED : Was number of random quests */
590 /* No quick start after using debug mode or cheat options */
591 if (current_world_ptr->noscore) previous_char.quick_ok = FALSE;
593 wr_byte((byte)previous_char.quick_ok);
598 * @brief その他の情報を書き込む / Write some "extra" info
601 static void wr_extra(player_type *creature_ptr)
603 wr_string(creature_ptr->name);
604 wr_string(creature_ptr->died_from);
605 wr_string(creature_ptr->last_message ? creature_ptr->last_message : "");
609 for (int i = 0; i < 4; i++)
611 wr_string(creature_ptr->history[i]);
614 /* Race/Class/Gender/Spells */
615 wr_byte((byte)creature_ptr->prace);
616 wr_byte((byte)creature_ptr->pclass);
617 wr_byte((byte)creature_ptr->pseikaku);
618 wr_byte((byte)creature_ptr->psex);
619 wr_byte((byte)creature_ptr->realm1);
620 wr_byte((byte)creature_ptr->realm2);
623 wr_byte((byte)creature_ptr->hitdie);
624 wr_u16b(creature_ptr->expfact);
626 wr_s16b(creature_ptr->age);
627 wr_s16b(creature_ptr->ht);
628 wr_s16b(creature_ptr->wt);
630 /* Dump the stats (maximum and current) */
631 for (int i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max[i]);
632 for (int i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max_max[i]);
633 for (int i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_cur[i]);
635 /* Ignore the transient stats */
636 for (int i = 0; i < 12; ++i) wr_s16b(0);
638 wr_u32b(creature_ptr->au);
640 wr_u32b(creature_ptr->max_exp);
641 wr_u32b(creature_ptr->max_max_exp);
642 wr_u32b(creature_ptr->exp);
643 wr_u32b(creature_ptr->exp_frac);
644 wr_s16b(creature_ptr->lev);
646 for (int i = 0; i < 64; i++) wr_s16b(creature_ptr->spell_exp[i]);
647 for (int i = 0; i < 5; i++)
648 for (int j = 0; j < 64; j++)
649 wr_s16b(creature_ptr->weapon_exp[i][j]);
651 for (int i = 0; i < GINOU_MAX; i++) wr_s16b(creature_ptr->skill_exp[i]);
652 for (int i = 0; i < 108; i++) wr_s32b(creature_ptr->magic_num1[i]);
653 for (int i = 0; i < 108; i++) wr_byte(creature_ptr->magic_num2[i]);
655 wr_byte((byte)creature_ptr->start_race);
656 wr_s32b(creature_ptr->old_race1);
657 wr_s32b(creature_ptr->old_race2);
658 wr_s16b(creature_ptr->old_realm);
660 for (int i = 0; i < MAX_MANE; i++)
662 wr_s16b((s16b)creature_ptr->mane_spell[i]);
663 wr_s16b((s16b)creature_ptr->mane_dam[i]);
666 wr_s16b(creature_ptr->mane_num);
668 for (int i = 0; i < MAX_BOUNTY; i++)
670 wr_s16b(current_world_ptr->bounty_r_idx[i]);
673 for (int i = 0; i < 4; i++)
675 wr_s16b(battle_mon[i]);
676 wr_u32b(mon_odds[i]);
679 wr_s16b(creature_ptr->town_num); /* -KMW- */
681 /* Write arena and rewards information -KMW- */
682 wr_s16b(creature_ptr->arena_number);
683 wr_s16b(creature_ptr->current_floor_ptr->inside_arena);
684 wr_s16b(creature_ptr->current_floor_ptr->inside_quest);
685 wr_s16b(creature_ptr->phase_out);
686 wr_byte(creature_ptr->exit_bldg);
687 wr_byte(0); /* Unused */
689 wr_s16b((s16b)creature_ptr->oldpx);
690 wr_s16b((s16b)creature_ptr->oldpy);
692 /* Was number of creature_ptr->rewards[] */
695 wr_s32b(creature_ptr->mhp);
696 wr_s32b(creature_ptr->chp);
697 wr_u32b(creature_ptr->chp_frac);
699 wr_s32b(creature_ptr->msp);
700 wr_s32b(creature_ptr->csp);
701 wr_u32b(creature_ptr->csp_frac);
703 /* Max Player and Dungeon Levels */
704 wr_s16b(creature_ptr->max_plv);
705 byte tmp8u = (byte)current_world_ptr->max_d_idx;
707 for (int i = 0; i < tmp8u; i++)
708 wr_s16b((s16b)max_dlv[i]);
715 wr_s16b(creature_ptr->sc);
716 wr_s16b(creature_ptr->concent);
718 wr_s16b(0); /* old "rest" */
719 wr_s16b(creature_ptr->blind);
720 wr_s16b(creature_ptr->paralyzed);
721 wr_s16b(creature_ptr->confused);
722 wr_s16b(creature_ptr->food);
723 wr_s16b(0); /* old "food_digested" */
724 wr_s16b(0); /* old "protection" */
725 wr_s16b(creature_ptr->energy_need);
726 wr_s16b(creature_ptr->enchant_energy_need);
727 wr_s16b(creature_ptr->fast);
728 wr_s16b(creature_ptr->slow);
729 wr_s16b(creature_ptr->afraid);
730 wr_s16b(creature_ptr->cut);
731 wr_s16b(creature_ptr->stun);
732 wr_s16b(creature_ptr->poisoned);
733 wr_s16b(creature_ptr->image);
734 wr_s16b(creature_ptr->protevil);
735 wr_s16b(creature_ptr->invuln);
736 wr_s16b(creature_ptr->ult_res);
737 wr_s16b(creature_ptr->hero);
738 wr_s16b(creature_ptr->shero);
739 wr_s16b(creature_ptr->shield);
740 wr_s16b(creature_ptr->blessed);
741 wr_s16b(creature_ptr->tim_invis);
742 wr_s16b(creature_ptr->word_recall);
743 wr_s16b(creature_ptr->recall_dungeon);
744 wr_s16b(creature_ptr->alter_reality);
745 wr_s16b(creature_ptr->see_infra);
746 wr_s16b(creature_ptr->tim_infra);
747 wr_s16b(creature_ptr->oppose_fire);
748 wr_s16b(creature_ptr->oppose_cold);
749 wr_s16b(creature_ptr->oppose_acid);
750 wr_s16b(creature_ptr->oppose_elec);
751 wr_s16b(creature_ptr->oppose_pois);
752 wr_s16b(creature_ptr->tsuyoshi);
753 wr_s16b(creature_ptr->tim_esp);
754 wr_s16b(creature_ptr->wraith_form);
755 wr_s16b(creature_ptr->resist_magic);
756 wr_s16b(creature_ptr->tim_regen);
757 wr_s16b(creature_ptr->kabenuke);
758 wr_s16b(creature_ptr->tim_stealth);
759 wr_s16b(creature_ptr->tim_levitation);
760 wr_s16b(creature_ptr->tim_sh_touki);
761 wr_s16b(creature_ptr->lightspeed);
762 wr_s16b(creature_ptr->tsubureru);
763 wr_s16b(creature_ptr->magicdef);
764 wr_s16b(creature_ptr->tim_res_nether);
765 wr_s16b(creature_ptr->tim_res_time);
766 wr_byte((byte)creature_ptr->mimic_form);
767 wr_s16b(creature_ptr->tim_mimic);
768 wr_s16b(creature_ptr->tim_sh_fire);
769 wr_s16b(creature_ptr->tim_sh_holy);
770 wr_s16b(creature_ptr->tim_eyeeye);
773 wr_s16b(creature_ptr->tim_reflect);
774 wr_s16b(creature_ptr->multishadow);
775 wr_s16b(creature_ptr->dustrobe);
777 wr_s16b(creature_ptr->chaos_patron);
778 wr_u32b(creature_ptr->muta1);
779 wr_u32b(creature_ptr->muta2);
780 wr_u32b(creature_ptr->muta3);
782 for (int i = 0; i < 8; i++)
783 wr_s16b(creature_ptr->virtues[i]);
784 for (int i = 0; i < 8; i++)
785 wr_s16b(creature_ptr->vir_types[i]);
787 wr_s16b(creature_ptr->ele_attack);
788 wr_u32b(creature_ptr->special_attack);
789 wr_s16b(creature_ptr->ele_immune);
790 wr_u32b(creature_ptr->special_defense);
791 wr_byte(creature_ptr->knowledge);
792 wr_byte(creature_ptr->autopick_autoregister);
794 wr_byte((byte)creature_ptr->action);
796 wr_byte(preserve_mode);
797 wr_byte(creature_ptr->wait_report_score);
800 for (int i = 0; i < 12; i++) wr_u32b(0L);
802 /* Ignore some flags */
807 /* Write the "object seeds" */
808 wr_u32b(current_world_ptr->seed_flavor);
809 wr_u32b(current_world_ptr->seed_town);
812 wr_u16b(creature_ptr->panic_save);
813 wr_u16b(current_world_ptr->total_winner);
814 wr_u16b(current_world_ptr->noscore);
817 wr_byte(creature_ptr->is_dead);
820 wr_byte(creature_ptr->feeling);
822 /* Turn when level began */
823 wr_s32b(creature_ptr->current_floor_ptr->generated_turn);
825 /* Turn of last "feeling" */
826 wr_s32b(creature_ptr->feeling_turn);
829 wr_s32b(current_world_ptr->game_turn);
831 wr_s32b(current_world_ptr->dungeon_turn);
833 wr_s32b(current_world_ptr->arena_start_turn);
836 wr_s16b(creature_ptr->today_mon);
837 wr_s16b(creature_ptr->riding);
839 /* Current floor_id */
840 wr_s16b(creature_ptr->floor_id);
842 /* Save temporary preserved pets (obsolated) */
845 wr_u32b(current_world_ptr->play_time);
846 wr_s32b(creature_ptr->visit);
847 wr_u32b(creature_ptr->count);
852 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
853 * @param sf_ptr 保存したいフロアの参照ポインタ
856 static void wr_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
859 /* Dungeon floor specific info follows */
860 floor_type *floor_ptr = player_ptr->current_floor_ptr;
863 /*** Not a saved floor ***/
865 wr_s16b((s16b)floor_ptr->dun_level);
869 /*** The saved floor ***/
871 wr_s16b(sf_ptr->floor_id);
872 wr_byte((byte)sf_ptr->savefile_id);
873 wr_s16b((s16b)sf_ptr->dun_level);
874 wr_s32b(sf_ptr->last_visit);
875 wr_u32b(sf_ptr->visit_mark);
876 wr_s16b(sf_ptr->upper_floor_id);
877 wr_s16b(sf_ptr->lower_floor_id);
880 wr_u16b((u16b)floor_ptr->base_level);
881 wr_u16b((s16b)player_ptr->current_floor_ptr->num_repro);
882 wr_u16b((u16b)player_ptr->y);
883 wr_u16b((u16b)player_ptr->x);
884 wr_u16b((u16b)floor_ptr->height);
885 wr_u16b((u16b)floor_ptr->width);
886 wr_byte(player_ptr->feeling);
888 /*********** Make template for grid_type **********/
891 * Usually number of templates are fewer than 255. Even if
892 * more than 254 are exist, the occurrence of each template
893 * with larger ID is very small when we sort templates by
894 * occurrence. So we will use two (or more) bytes for
895 * templete ID larger than 254.
897 * Ex: 256 will be "0xff" "0x01".
898 * 515 will be "0xff" "0xff" "0x03"
901 /* Fake max number */
902 u16b max_num_temp = 255;
904 /* Allocate the "template" array */
905 grid_template_type *templates;
906 C_MAKE(templates, max_num_temp, grid_template_type);
908 /* Extract template array */
910 for (int y = 0; y < floor_ptr->height; y++)
912 for (int x = 0; x < floor_ptr->width; x++)
914 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
917 for (i = 0; i < num_temp; i++)
919 if (templates[i].info == g_ptr->info &&
920 templates[i].feat == g_ptr->feat &&
921 templates[i].mimic == g_ptr->mimic &&
922 templates[i].special == g_ptr->special)
924 /* Same terrain is exist */
925 templates[i].occurrence++;
930 /* Are there same one? */
931 if (i < num_temp) continue;
933 /* If the max_num_temp is too small, increase it. */
934 if (num_temp >= max_num_temp)
936 grid_template_type *old_template = templates;
938 /* Re-allocate the "template" array */
939 C_MAKE(templates, max_num_temp + 255, grid_template_type);
940 (void)C_COPY(templates, old_template, max_num_temp, grid_template_type);
941 C_KILL(old_template, max_num_temp, grid_template_type);
945 /* Add new template */
946 templates[num_temp].info = g_ptr->info;
947 templates[num_temp].feat = g_ptr->feat;
948 templates[num_temp].mimic = g_ptr->mimic;
949 templates[num_temp].special = g_ptr->special;
950 templates[num_temp].occurrence = 1;
952 /* Increase number of template */
957 /* Sort by occurrence */
959 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
961 /*** Dump templates ***/
963 /* Total templates */
966 /* Dump the templates */
967 for (int i = 0; i < num_temp; i++)
969 grid_template_type *ct_ptr = &templates[i];
970 wr_u16b((u16b)ct_ptr->info);
971 wr_s16b(ct_ptr->feat);
972 wr_s16b(ct_ptr->mimic);
973 wr_s16b(ct_ptr->special);
976 /*** "Run-Length-Encoding" of floor ***/
977 /* Note that this will induce two wasted bytes */
981 for (int y = 0; y < floor_ptr->height; y++)
983 for (int x = 0; x < floor_ptr->width; x++)
985 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
987 for (i = 0; i < num_temp; i++)
989 if (templates[i].info == g_ptr->info &&
990 templates[i].feat == g_ptr->feat &&
991 templates[i].mimic == g_ptr->mimic &&
992 templates[i].special == g_ptr->special)
997 u16b tmp16u = (u16b)i;
999 /* If the run is broken, or too full, flush it */
1000 if ((tmp16u == prev_u16b) && (count != MAX_UCHAR))
1006 wr_byte((byte)count);
1008 while (prev_u16b >= MAX_UCHAR)
1010 /* Mark as actual data is larger than 254 */
1012 prev_u16b -= MAX_UCHAR;
1015 wr_byte((byte)prev_u16b);
1021 /* Flush the data (if any) */
1024 wr_byte((byte)count);
1026 while (prev_u16b >= MAX_UCHAR)
1028 /* Mark as actual data is larger than 254 */
1030 prev_u16b -= MAX_UCHAR;
1033 wr_byte((byte)prev_u16b);
1036 /* Free the "template" array */
1037 C_KILL(templates, max_num_temp, grid_template_type);
1039 /*** Dump objects ***/
1042 wr_u16b(floor_ptr->o_max);
1044 /* Dump the objects */
1045 for (int i = 1; i < floor_ptr->o_max; i++)
1047 object_type *o_ptr = &floor_ptr->o_list[i];
1051 /*** Dump the monsters ***/
1053 /* Total monsters */
1054 wr_u16b(floor_ptr->m_max);
1056 /* Dump the monsters */
1057 for (int i = 1; i < floor_ptr->m_max; i++)
1059 monster_type *m_ptr = &floor_ptr->m_list[i];
1066 * @brief 現在フロアの書き込み /
1067 * Write the current dungeon (new method)
1068 * @player_ptr プレーヤーへの参照ポインタ
1069 * @return 保存に成功したらTRUE
1071 static bool wr_dungeon(player_type *player_ptr)
1073 forget_lite(player_ptr->current_floor_ptr);
1074 forget_view(player_ptr->current_floor_ptr);
1075 clear_mon_lite(player_ptr->current_floor_ptr);
1077 /* Update lite/view */
1078 player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1079 player_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1083 /* Number of floor_id used from birth */
1084 wr_s16b(max_floor_id);
1086 /* Current dungeon type */
1087 wr_byte((byte)player_ptr->dungeon_idx);
1090 /*** No saved floor (On the surface etc.) ***/
1091 if (!player_ptr->floor_id)
1093 /* No array elements */
1096 /* Write the current floor data */
1097 wr_saved_floor(player_ptr, NULL);
1104 /*** In the dungeon ***/
1106 /* Number of array elements */
1107 wr_byte(MAX_SAVED_FLOORS);
1109 /* Write the saved_floors array */
1110 for (int i = 0; i < MAX_SAVED_FLOORS; i++)
1112 saved_floor_type *sf_ptr = &saved_floors[i];
1114 wr_s16b(sf_ptr->floor_id);
1115 wr_byte((byte)sf_ptr->savefile_id);
1116 wr_s16b((s16b)sf_ptr->dun_level);
1117 wr_s32b(sf_ptr->last_visit);
1118 wr_u32b(sf_ptr->visit_mark);
1119 wr_s16b(sf_ptr->upper_floor_id);
1120 wr_s16b(sf_ptr->lower_floor_id);
1123 /* Extract pointer to current floor */
1124 saved_floor_type *cur_sf_ptr;
1125 cur_sf_ptr = get_sf_ptr(player_ptr->floor_id);
1127 /* Save current floor to temporary file */
1128 if (!save_floor(player_ptr, cur_sf_ptr, (SLF_SECOND))) return FALSE;
1130 /* Move data in temporary files to the savefile */
1131 for (int i = 0; i < MAX_SAVED_FLOORS; i++)
1133 saved_floor_type *sf_ptr = &saved_floors[i];
1134 if (!sf_ptr->floor_id) continue;
1135 if (!load_floor(player_ptr, sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1142 wr_saved_floor(player_ptr, sf_ptr);
1145 if (!load_floor(player_ptr, cur_sf_ptr, (SLF_SECOND))) return FALSE;
1151 * @brief セーブデータの書き込み /
1152 * Actually write a save-file
1153 * @param player_ptr プレーヤーへの参照ポインタ
1156 static bool wr_savefile_new(player_type *player_ptr)
1158 /* Compact the objects */
1159 compact_objects(player_ptr, 0);
1161 /* Compact the monsters */
1162 compact_monsters(player_ptr, 0);
1164 /* Guess at the current time */
1165 u32b now = (u32b)time((time_t *)0);
1167 /* Note the operating system */
1168 current_world_ptr->sf_system = 0L;
1170 /* Note when the file was saved */
1171 current_world_ptr->sf_when = now;
1173 /* Note the number of saves */
1174 current_world_ptr->sf_saves++;
1176 /*** Actually write the file ***/
1177 /* Dump the file header */
1179 wr_byte(FAKE_VER_MAJOR);
1181 wr_byte(FAKE_VER_MINOR);
1183 wr_byte(FAKE_VER_PATCH);
1186 /* Initial value of xor_byte */
1187 byte tmp8u = (byte)Rand_external(256);
1190 /* Reset the checksum */
1194 /* Write the savefile version for Hengband 1.1.1 and later */
1195 wr_byte(H_VER_EXTRA);
1196 wr_byte(H_VER_PATCH);
1197 wr_byte(H_VER_MINOR);
1198 wr_byte(H_VER_MAJOR);
1200 /* Operating system */
1201 wr_u32b(current_world_ptr->sf_system);
1203 /* Time file last saved */
1204 wr_u32b(current_world_ptr->sf_when);
1206 /* Number of past lives */
1207 wr_u16b(current_world_ptr->sf_lives);
1209 /* Number of times saved */
1210 wr_u16b(current_world_ptr->sf_saves);
1218 /* EUC kanji code */
1222 /* SJIS kanji code */
1230 /* Write the RNG state */
1233 /* Write the boolean "options" */
1236 /* Dump the number of "messages" */
1237 u32b tmp32u = message_num();
1238 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1241 /* Dump the messages (oldest first!) */
1242 for (int i = tmp32u - 1; i >= 0; i--)
1244 wr_string(message_str((s16b)i));
1247 /* Dump the monster lore */
1248 u16b tmp16u = max_r_idx;
1250 for (MONRACE_IDX r_idx = 0; r_idx < tmp16u; r_idx++)
1255 /* Dump the object memory */
1258 for (KIND_OBJECT_IDX k_idx = 0; k_idx < tmp16u; k_idx++)
1263 /* Dump the towns */
1267 /* Dump the quests */
1271 /* Dump the quests */
1272 tmp8u = MAX_RANDOM_QUEST - MIN_RANDOM_QUEST;
1275 for (int i = 0; i < max_q_idx; i++)
1277 quest_type* const q_ptr = &quest[i];
1279 /* Save status for every quest */
1280 wr_s16b(q_ptr->status);
1282 /* And the dungeon level too */
1283 /* (prevents problems with multi-level quests) */
1284 wr_s16b((s16b)q_ptr->level);
1286 wr_byte((byte)q_ptr->complev);
1287 wr_u32b(q_ptr->comptime);
1289 bool is_quest_running = q_ptr->status == QUEST_STATUS_TAKEN;
1290 is_quest_running |= q_ptr->status == QUEST_STATUS_COMPLETED;
1291 is_quest_running |= !is_fixed_quest_idx(i);
1292 if (!is_quest_running) continue;
1294 wr_s16b((s16b)q_ptr->cur_num);
1295 wr_s16b((s16b)q_ptr->max_num);
1296 wr_s16b(q_ptr->type);
1297 wr_s16b(q_ptr->r_idx);
1298 wr_s16b(q_ptr->k_idx);
1299 wr_byte((byte)q_ptr->flags);
1300 wr_byte((byte)q_ptr->dungeon);
1303 /* Dump the position in the wilderness */
1304 wr_s32b(player_ptr->wilderness_x);
1305 wr_s32b(player_ptr->wilderness_y);
1307 wr_byte(player_ptr->wild_mode);
1308 wr_byte(player_ptr->ambush_flag);
1310 wr_s32b(current_world_ptr->max_wild_x);
1311 wr_s32b(current_world_ptr->max_wild_y);
1313 /* Dump the wilderness seeds */
1314 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
1316 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
1318 wr_u32b(wilderness[j][i].seed);
1322 /* Hack -- Dump the artifacts */
1325 for (int i = 0; i < tmp16u; i++)
1327 artifact_type *a_ptr = &a_info[i];
1328 wr_byte(a_ptr->cur_num);
1329 wr_s16b(a_ptr->floor_id);
1332 /* Write the "extra" information */
1333 wr_extra(player_ptr);
1335 /* Dump the "player hp" entries */
1336 tmp16u = PY_MAX_LEVEL;
1338 for (int i = 0; i < tmp16u; i++)
1340 wr_s16b((s16b)player_ptr->player_hp[i]);
1343 /* Write spell data */
1344 wr_u32b(player_ptr->spell_learned1);
1345 wr_u32b(player_ptr->spell_learned2);
1346 wr_u32b(player_ptr->spell_worked1);
1347 wr_u32b(player_ptr->spell_worked2);
1348 wr_u32b(player_ptr->spell_forgotten1);
1349 wr_u32b(player_ptr->spell_forgotten2);
1351 wr_s16b(player_ptr->learned_spells);
1352 wr_s16b(player_ptr->add_spells);
1354 /* Dump the ordered spells */
1355 for (int i = 0; i < 64; i++)
1357 wr_byte((byte)player_ptr->spell_order[i]);
1360 for (int i = 0; i < INVEN_TOTAL; i++)
1362 object_type *o_ptr = &player_ptr->inventory_list[i];
1363 if (!o_ptr->k_idx) continue;
1372 /* Add a sentinel */
1375 /* Note the towns */
1379 /* Note the stores */
1380 tmp16u = MAX_STORES;
1383 /* Dump the stores of all towns */
1384 for (int i = 1; i < max_towns; i++)
1386 for (int j = 0; j < MAX_STORES; j++)
1388 wr_store(&town_info[i].store[j]);
1392 /* Write the pet command settings */
1393 wr_s16b(player_ptr->pet_follow_distance);
1394 wr_s16b(player_ptr->pet_extra_flags);
1396 /* Write screen dump for sending score */
1397 if (screen_dump && (player_ptr->wait_report_score || !player_ptr->is_dead))
1399 wr_string(screen_dump);
1406 /* Player is not dead, write the dungeon */
1407 if (!player_ptr->is_dead)
1409 /* Dump the dungeon */
1410 if (!wr_dungeon(player_ptr)) return FALSE;
1412 /* Dump the ghost */
1419 /* Write the "value check-sum" */
1422 /* Write the "encoded checksum" */
1425 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1431 * @brief セーブデータ書き込みのサブルーチン /
1432 * Medium level player saver
1433 * @param player_ptr プレーヤーへの参照ポインタ
1436 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1438 static bool save_player_aux(player_type *player_ptr, char *name)
1440 /* Grab permissions */
1443 /* Create the savefile */
1444 int file_permission = 0644;
1445 int fd = fd_make(name, file_permission);
1447 /* Drop permissions */
1450 bool is_save_successful = FALSE;
1454 /* Close the "fd" */
1457 /* Grab permissions */
1460 /* Open the savefile */
1461 fff = angband_fopen(name, "wb");
1463 /* Drop permissions */
1466 /* Successful open */
1469 /* Write the savefile */
1470 if (wr_savefile_new(player_ptr)) is_save_successful = TRUE;
1472 /* Attempt to close it */
1473 if (angband_fclose(fff)) is_save_successful = FALSE;
1476 /* Grab permissions */
1479 /* Remove "broken" files */
1480 if (!is_save_successful) (void)fd_kill(name);
1482 /* Drop permissions */
1486 if (!is_save_successful) return FALSE;
1488 counts_write(player_ptr, 0, current_world_ptr->play_time);
1489 current_world_ptr->character_saved = TRUE;
1495 * @brief セーブデータ書き込みのメインルーチン /
1496 * Attempt to save the player in a savefile
1497 * @param player_ptr プレーヤーへの参照ポインタ
1500 bool save_player(player_type *player_ptr)
1503 strcpy(safe, savefile);
1504 strcat(safe, ".new");
1506 /* Grab permissions */
1511 /* Drop permissions */
1515 /* Attempt to save the player */
1516 bool result = FALSE;
1517 if (save_player_aux(player_ptr, safe))
1522 strcpy(temp, savefile);
1523 strcat(temp, ".old");
1525 /* Grab permissions */
1531 /* Preserve old savefile */
1532 fd_move(savefile, temp);
1534 /* Activate new savefile */
1535 fd_move(safe, savefile);
1537 /* Remove preserved savefile */
1540 /* Drop permissions */
1543 /* Hack -- Pretend the character was loaded */
1544 current_world_ptr->character_loaded = TRUE;
1549 /* Return the result */
1555 * @brief セーブデータ読み込みのメインルーチン /
1556 * Attempt to Load a "savefile"
1557 * @param creature_ptr プレーヤーへの参照ポインタ
1561 * Version 2.7.0 introduced a slightly different "savefile" format from
1562 * older versions, requiring a completely different parsing method.
1564 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1566 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1568 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1570 * On multi-user systems, you may only "read" a savefile if you will be
1571 * allowed to "write" it later, this prevents painful situations in which
1572 * the player loads a savefile belonging to someone else, and then is not
1573 * allowed to save his game when he quits.
1575 * We return "TRUE" if the savefile was usable, and we set the global
1576 * flag "current_world_ptr->character_loaded" if a real, living, character was loaded.
1578 * Note that we always try to load the "current" savefile, even if
1579 * there is no such file, so we must check for "empty" savefile names.
1582 bool load_player(player_type *player_ptr)
1584 concptr what = "generic";
1586 current_world_ptr->game_turn = 0;
1587 player_ptr->is_dead = FALSE;
1590 /* Allow empty savefile name */
1591 if (!savefile[0]) return TRUE;
1594 #if !defined(WINDOWS)
1598 /* Verify the existance of the savefile */
1599 if (access(savefile, 0) < 0)
1601 /* Give a message */
1602 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1617 /* Open the savefile */
1618 fd = fd_open(savefile, O_RDONLY);
1621 if (fd < 0) err = -1;
1623 /* Message (below) */
1624 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1630 /* Read the first four bytes */
1631 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1634 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1641 /* Extract version */
1642 current_world_ptr->z_major = vvv[0];
1643 current_world_ptr->z_minor = vvv[1];
1644 current_world_ptr->z_patch = vvv[2];
1645 current_world_ptr->sf_extra = vvv[3];
1649 /* Attempt to load */
1650 err = rd_savefile_new(player_ptr);
1652 /* Message (below) */
1653 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1659 if (!current_world_ptr->game_turn) err = -1;
1661 /* Message (below) */
1662 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1667 /* Give a conversion warning */
1668 if ((FAKE_VER_MAJOR != current_world_ptr->z_major) ||
1669 (FAKE_VER_MINOR != current_world_ptr->z_minor) ||
1670 (FAKE_VER_PATCH != current_world_ptr->z_patch))
1672 if (current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6)
1674 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1678 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1679 (current_world_ptr->z_major > 9) ? current_world_ptr->z_major - 10 : current_world_ptr->z_major, current_world_ptr->z_minor, current_world_ptr->z_patch);
1684 /* Player is dead */
1685 if (player_ptr->is_dead)
1690 /* A character was loaded */
1691 current_world_ptr->character_loaded = TRUE;
1695 /* Player is no longer "dead" */
1696 player_ptr->is_dead = FALSE;
1699 current_world_ptr->sf_lives++;
1704 /* A character was loaded */
1705 current_world_ptr->character_loaded = TRUE;
1708 u32b tmp = counts_read(player_ptr, 2);
1709 if (tmp > player_ptr->count)
1710 player_ptr->count = tmp;
1711 if (counts_read(player_ptr, 0) > current_world_ptr->play_time || counts_read(player_ptr, 1) == current_world_ptr->play_time)
1712 counts_write(player_ptr, 2, ++player_ptr->count);
1713 counts_write(player_ptr, 1, current_world_ptr->play_time);
1720 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1721 what, (current_world_ptr->z_major > 9) ? current_world_ptr->z_major - 10 : current_world_ptr->z_major, current_world_ptr->z_minor, current_world_ptr->z_patch);
1728 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporary saved floor file
1729 * @param player_ptr プレーヤーへの参照ポインタ
1730 * @param sf_ptr 保存フロア参照ポインタ
1733 static bool save_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
1735 /* Compact the objects */
1736 compact_objects(player_ptr, 0);
1737 /* Compact the monsters */
1738 compact_monsters(player_ptr, 0);
1740 /*** Actually write the file ***/
1741 /* Initial value of xor_byte */
1742 byte tmp8u = (byte)randint0(256);
1746 /* Reset the checksum */
1750 /* Write the sign of this process */
1751 wr_u32b(saved_floor_file_sign);
1753 /* Dump the dungeon floor */
1754 wr_saved_floor(player_ptr, sf_ptr);
1756 /* Write the "value check-sum" */
1759 /* Write the "encoded checksum" */
1762 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1768 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporarily saved-floor data
1769 * @param player_ptr プレーヤーへの参照ポインタ
1770 * @param sf_ptr 保存フロア参照ポインタ
1771 * @param mode 保存オプション
1774 bool save_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
1776 FILE *old_fff = NULL;
1777 byte old_xor_byte = 0;
1778 u32b old_v_stamp = 0;
1779 u32b old_x_stamp = 0;
1781 char floor_savefile[1024];
1782 if (!(mode & SLF_SECOND))
1786 /* We have one file already opened */
1789 /* Backup original values */
1791 old_xor_byte = xor_byte;
1792 old_v_stamp = v_stamp;
1793 old_x_stamp = x_stamp;
1797 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
1799 /* Grab permissions */
1803 fd_kill(floor_savefile);
1805 /* Drop permissions */
1808 /* Attempt to save the player */
1813 /* Grab permissions */
1816 /* Create the savefile */
1817 int fd = fd_make(floor_savefile, 0644);
1819 /* Drop permissions */
1822 bool is_save_successful = FALSE;
1825 /* Close the "fd" */
1828 /* Grab permissions */
1831 /* Open the savefile */
1832 fff = angband_fopen(floor_savefile, "wb");
1834 /* Drop permissions */
1837 /* Successful open */
1840 /* Write the savefile */
1841 if (save_floor_aux(player_ptr, sf_ptr)) is_save_successful = TRUE;
1843 /* Attempt to close it */
1844 if (angband_fclose(fff)) is_save_successful = FALSE;
1847 /* Remove "broken" files */
1848 if (!is_save_successful)
1850 /* Grab permissions */
1853 (void)fd_kill(floor_savefile);
1855 /* Drop permissions */
1860 if (!(mode & SLF_SECOND))
1864 /* We have one file already opened */
1867 /* Restore original values */
1869 xor_byte = old_xor_byte;
1870 v_stamp = old_v_stamp;
1871 x_stamp = old_x_stamp;
1874 return is_save_successful;