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.
26 #include "market/store-util.h"
29 #include "floor-events.h"
30 #include "floor-save.h"
31 #include "floor-town.h"
32 #include "uid-checker.h"
35 #include "objectkind.h"
36 #include "monsterrace.h"
38 #include "market/building.h"
39 #include "view-mainwindow.h"
42 * Some "local" parameters, used to help write savefiles
45 static FILE *fff; /* Current save "file" */
46 static byte xor_byte; /* Simple encryption */
47 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
48 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
51 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
55 static void sf_put(byte v)
57 /* Encode the value, write a character */
59 (void)putc((int)xor_byte, fff);
61 /* Maintain the checksum info */
68 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
72 static void wr_byte(byte v)
79 * @brief 符号なし16ビットをファイルに書き込む
80 * @param v 書き込む符号なし16bit値
83 static void wr_u16b(u16b v)
85 sf_put((byte)(v & 0xFF));
86 sf_put((byte)((v >> 8) & 0xFF));
91 * @brief 符号あり16ビットをファイルに書き込む
92 * @param v 書き込む符号あり16bit値
95 static void wr_s16b(s16b v)
102 * @brief 符号なし32ビットをファイルに書き込む
103 * @param v 書き込む符号なし32bit値
106 static void wr_u32b(u32b v)
108 sf_put((byte)(v & 0xFF));
109 sf_put((byte)((v >> 8) & 0xFF));
110 sf_put((byte)((v >> 16) & 0xFF));
111 sf_put((byte)((v >> 24) & 0xFF));
116 * @brief 符号あり32ビットをファイルに書き込む
117 * @param v 書き込む符号あり32bit値
120 static void wr_s32b(s32b v)
127 * @brief 文字列をファイルに書き込む
131 static void wr_string(concptr str)
143 * These functions write info in larger logical records
148 * @brief アイテムオブジェクトを書き込む / Write an "item" record
149 * @param o_ptr アイテムオブジェクト保存元ポインタ
152 static void wr_item(object_type *o_ptr)
154 BIT_FLAGS flags = 0x00000000;
156 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
157 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
158 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
159 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
160 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
161 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
162 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
163 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
164 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
165 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
166 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
167 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
168 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
169 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
170 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
171 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
172 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
173 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
174 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
175 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
176 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
177 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
178 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
179 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
180 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
181 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
182 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
183 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
184 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
186 /*** Item save flags ***/
189 /*** Write only un-obvious elements ***/
190 wr_s16b(o_ptr->k_idx);
192 wr_byte((byte)o_ptr->iy);
193 wr_byte((byte)o_ptr->ix);
195 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
197 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
198 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte)o_ptr->number);
200 wr_s16b((s16b)o_ptr->weight);
202 if (flags & SAVE_ITEM_NAME1) wr_byte((byte)o_ptr->name1);
203 if (flags & SAVE_ITEM_NAME2) wr_byte((byte)o_ptr->name2);
204 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
206 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
207 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
208 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
209 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
210 if (flags & SAVE_ITEM_DD) wr_byte((byte)o_ptr->dd);
211 if (flags & SAVE_ITEM_DS) wr_byte((byte)o_ptr->ds);
213 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
215 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
217 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
218 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
219 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
220 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
221 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
223 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
225 /* Held by monster index */
226 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
228 /* Extra information */
229 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
230 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
231 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
232 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
233 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
236 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
238 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
239 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
244 * @brief モンスター情報を書き込む / Write a "monster" record
245 * @param m_ptr モンスター情報保存元ポインタ
248 static void wr_monster(monster_type *m_ptr)
250 BIT_FLAGS flags = 0x00000000;
251 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
252 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
253 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
254 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
255 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
256 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
257 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
258 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
259 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
260 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
261 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
262 if (m_ptr->smart) flags |= SAVE_MON_SMART;
263 if (m_ptr->exp) flags |= SAVE_MON_EXP;
264 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
265 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
266 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
268 /*** Monster save flags ***/
271 /*** Write only un-obvious elements ***/
272 wr_s16b(m_ptr->r_idx);
273 wr_byte((byte)m_ptr->fy);
274 wr_byte((byte)m_ptr->fx);
275 wr_s16b((s16b)m_ptr->hp);
276 wr_s16b((s16b)m_ptr->maxhp);
277 wr_s16b((s16b)m_ptr->max_maxhp);
278 wr_u32b(m_ptr->dealt_damage);
280 /* Monster race index of its appearance */
281 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
283 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
284 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
286 wr_byte((byte)m_ptr->mspeed);
287 wr_s16b(m_ptr->energy_need);
290 if (flags & SAVE_MON_FAST)
292 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
295 if (flags & SAVE_MON_SLOW)
297 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
300 if (flags & SAVE_MON_STUNNED)
302 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
305 if (flags & SAVE_MON_CONFUSED)
307 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
310 if (flags & SAVE_MON_MONFEAR)
312 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
315 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
316 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
317 if (flags & SAVE_MON_INVULNER)
319 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
322 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
323 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
324 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
325 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
326 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
331 * @brief モンスターの思い出を書き込む / Write a "lore" record
332 * @param r_idx モンスター種族ID
335 static void wr_lore(MONRACE_IDX r_idx)
337 /* Count sights/deaths/kills */
338 monster_race *r_ptr = &r_info[r_idx];
339 wr_s16b((s16b)r_ptr->r_sights);
340 wr_s16b((s16b)r_ptr->r_deaths);
341 wr_s16b((s16b)r_ptr->r_pkills);
342 wr_s16b((s16b)r_ptr->r_akills);
343 wr_s16b((s16b)r_ptr->r_tkills);
345 /* Count wakes and ignores */
346 wr_byte(r_ptr->r_wake);
347 wr_byte(r_ptr->r_ignore);
350 wr_byte(r_ptr->r_xtra1);
351 wr_byte(r_ptr->r_xtra2);
354 wr_byte((byte)r_ptr->r_drop_gold);
355 wr_byte((byte)r_ptr->r_drop_item);
358 wr_byte(0); /* unused now */
359 wr_byte(r_ptr->r_cast_spell);
361 /* Count blows of each type */
362 wr_byte(r_ptr->r_blows[0]);
363 wr_byte(r_ptr->r_blows[1]);
364 wr_byte(r_ptr->r_blows[2]);
365 wr_byte(r_ptr->r_blows[3]);
368 wr_u32b(r_ptr->r_flags1);
369 wr_u32b(r_ptr->r_flags2);
370 wr_u32b(r_ptr->r_flags3);
371 wr_u32b(r_ptr->r_flags4);
372 wr_u32b(r_ptr->r_flags5);
373 wr_u32b(r_ptr->r_flags6);
374 wr_u32b(r_ptr->r_flagsr);
376 /* Monster limit per level */
377 wr_byte((byte)r_ptr->max_num);
379 /* Location in saved floor */
380 wr_s16b(r_ptr->floor_id);
387 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
388 * @param k_idx ベースアイテムのID
391 static void wr_xtra(KIND_OBJECT_IDX k_idx)
395 object_kind *k_ptr = &k_info[k_idx];
397 if (k_ptr->aware) tmp8u |= 0x01;
398 if (k_ptr->tried) tmp8u |= 0x02;
405 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
406 * @param store_ptr 店舗情報の参照ポインタ
409 static void wr_store(store_type *store_ptr)
411 /* Save the "open" counter */
412 wr_u32b(store_ptr->store_open);
414 /* Save the "insults" */
415 wr_s16b(store_ptr->insult_cur);
417 /* Save the current owner */
418 wr_byte(store_ptr->owner);
420 /* Save the stock size */
421 wr_s16b(store_ptr->stock_num);
423 /* Save the "haggle" info */
424 wr_s16b(store_ptr->good_buy);
425 wr_s16b(store_ptr->bad_buy);
427 wr_s32b(store_ptr->last_visit);
430 for (int j = 0; j < store_ptr->stock_num; j++)
432 /* Save each item in stock */
433 wr_item(&store_ptr->stock[j]);
439 * @brief セーブデータに乱数情報を書き込む / Write RNG state
442 static errr wr_randomizer(void)
447 for (int i = 0; i < RAND_DEG; i++)
449 wr_u32b(Rand_state[i]);
457 * @brief ゲームオプション情報を書き込む / Write the "options"
460 static void wr_options(void)
462 for (int i = 0; i < 4; i++) wr_u32b(0L);
464 /*** Special options ***/
465 /* Write "delay_factor" */
466 wr_byte(delay_factor);
468 /* Write "hitpoint_warn" */
469 wr_byte(hitpoint_warn);
471 /* Write "mana_warn" */
474 /*** Cheating options ***/
477 if (current_world_ptr->wizard) c |= 0x0002;
479 if (cheat_sight) c |= 0x0040;
480 if (cheat_turn) c |= 0x0080;
482 if (cheat_peek) c |= 0x0100;
483 if (cheat_hear) c |= 0x0200;
484 if (cheat_room) c |= 0x0400;
485 if (cheat_xtra) c |= 0x0800;
486 if (cheat_know) c |= 0x1000;
487 if (cheat_live) c |= 0x2000;
488 if (cheat_save) c |= 0x4000;
489 if (cheat_diary_output) c |= 0x8000;
496 wr_s16b(autosave_freq);
498 /*** Extract options ***/
499 /* Analyze the options */
500 for (int i = 0; option_info[i].o_desc; i++)
502 int os = option_info[i].o_set;
503 int ob = option_info[i].o_bit;
505 /* Process real entries */
506 if (!option_info[i].o_var) continue;
508 if (*option_info[i].o_var)
510 option_flag[os] |= (1L << ob);
514 option_flag[os] &= ~(1L << ob);
518 /*** Normal options ***/
520 for (int i = 0; i < 8; i++) wr_u32b(option_flag[i]);
523 for (int i = 0; i < 8; i++) wr_u32b(option_mask[i]);
525 /*** Window options ***/
527 for (int i = 0; i < 8; i++) wr_u32b(window_flag[i]);
530 for (int i = 0; i < 8; i++) wr_u32b(window_mask[i]);
535 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
538 static void wr_ghost(void)
540 wr_string(_("不正なゴースト", "Broken Ghost"));
542 /* Hack -- stupid data */
543 for (int i = 0; i < 60; i++) wr_byte(0);
548 * @brief クイック・スタート情報を書き込む / Save quick start data
551 static void save_quick_start(void)
553 wr_byte(previous_char.psex);
554 wr_byte((byte)previous_char.prace);
555 wr_byte((byte)previous_char.pclass);
556 wr_byte((byte)previous_char.pseikaku);
557 wr_byte((byte)previous_char.realm1);
558 wr_byte((byte)previous_char.realm2);
560 wr_s16b(previous_char.age);
561 wr_s16b(previous_char.ht);
562 wr_s16b(previous_char.wt);
563 wr_s16b(previous_char.sc);
564 wr_s32b(previous_char.au);
566 for (int i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
567 for (int i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
569 for (int i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
571 wr_s16b(previous_char.chaos_patron);
573 for (int i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
575 for (int i = 0; i < 4; i++) wr_string(previous_char.history[i]);
577 /* UNUSED : Was number of random quests */
580 /* No quick start after using debug mode or cheat options */
581 if (current_world_ptr->noscore) previous_char.quick_ok = FALSE;
583 wr_byte((byte)previous_char.quick_ok);
588 * @brief その他の情報を書き込む / Write some "extra" info
591 static void wr_extra(player_type *creature_ptr)
593 wr_string(creature_ptr->name);
594 wr_string(creature_ptr->died_from);
595 wr_string(creature_ptr->last_message ? creature_ptr->last_message : "");
599 for (int i = 0; i < 4; i++)
601 wr_string(creature_ptr->history[i]);
604 /* Race/Class/Gender/Spells */
605 wr_byte((byte)creature_ptr->prace);
606 wr_byte((byte)creature_ptr->pclass);
607 wr_byte((byte)creature_ptr->pseikaku);
608 wr_byte((byte)creature_ptr->psex);
609 wr_byte((byte)creature_ptr->realm1);
610 wr_byte((byte)creature_ptr->realm2);
613 wr_byte((byte)creature_ptr->hitdie);
614 wr_u16b(creature_ptr->expfact);
616 wr_s16b(creature_ptr->age);
617 wr_s16b(creature_ptr->ht);
618 wr_s16b(creature_ptr->wt);
620 /* Dump the stats (maximum and current) */
621 for (int i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max[i]);
622 for (int i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max_max[i]);
623 for (int i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_cur[i]);
625 /* Ignore the transient stats */
626 for (int i = 0; i < 12; ++i) wr_s16b(0);
628 wr_u32b(creature_ptr->au);
630 wr_u32b(creature_ptr->max_exp);
631 wr_u32b(creature_ptr->max_max_exp);
632 wr_u32b(creature_ptr->exp);
633 wr_u32b(creature_ptr->exp_frac);
634 wr_s16b(creature_ptr->lev);
636 for (int i = 0; i < 64; i++) wr_s16b(creature_ptr->spell_exp[i]);
637 for (int i = 0; i < 5; i++)
638 for (int j = 0; j < 64; j++)
639 wr_s16b(creature_ptr->weapon_exp[i][j]);
641 for (int i = 0; i < GINOU_MAX; i++) wr_s16b(creature_ptr->skill_exp[i]);
642 for (int i = 0; i < 108; i++) wr_s32b(creature_ptr->magic_num1[i]);
643 for (int i = 0; i < 108; i++) wr_byte(creature_ptr->magic_num2[i]);
645 wr_byte((byte)creature_ptr->start_race);
646 wr_s32b(creature_ptr->old_race1);
647 wr_s32b(creature_ptr->old_race2);
648 wr_s16b(creature_ptr->old_realm);
650 for (int i = 0; i < MAX_MANE; i++)
652 wr_s16b((s16b)creature_ptr->mane_spell[i]);
653 wr_s16b((s16b)creature_ptr->mane_dam[i]);
656 wr_s16b(creature_ptr->mane_num);
658 for (int i = 0; i < MAX_BOUNTY; i++)
660 wr_s16b(current_world_ptr->bounty_r_idx[i]);
663 for (int i = 0; i < 4; i++)
665 wr_s16b(battle_mon[i]);
666 wr_u32b(mon_odds[i]);
669 wr_s16b(creature_ptr->town_num); /* -KMW- */
671 /* Write arena and rewards information -KMW- */
672 wr_s16b(creature_ptr->arena_number);
673 wr_s16b(creature_ptr->current_floor_ptr->inside_arena);
674 wr_s16b(creature_ptr->current_floor_ptr->inside_quest);
675 wr_s16b(creature_ptr->phase_out);
676 wr_byte(creature_ptr->exit_bldg);
677 wr_byte(0); /* Unused */
679 wr_s16b((s16b)creature_ptr->oldpx);
680 wr_s16b((s16b)creature_ptr->oldpy);
682 /* Was number of creature_ptr->rewards[] */
685 wr_s32b(creature_ptr->mhp);
686 wr_s32b(creature_ptr->chp);
687 wr_u32b(creature_ptr->chp_frac);
689 wr_s32b(creature_ptr->msp);
690 wr_s32b(creature_ptr->csp);
691 wr_u32b(creature_ptr->csp_frac);
693 /* Max Player and Dungeon Levels */
694 wr_s16b(creature_ptr->max_plv);
695 byte tmp8u = (byte)current_world_ptr->max_d_idx;
697 for (int i = 0; i < tmp8u; i++)
698 wr_s16b((s16b)max_dlv[i]);
705 wr_s16b(creature_ptr->sc);
706 wr_s16b(creature_ptr->concent);
708 wr_s16b(0); /* old "rest" */
709 wr_s16b(creature_ptr->blind);
710 wr_s16b(creature_ptr->paralyzed);
711 wr_s16b(creature_ptr->confused);
712 wr_s16b(creature_ptr->food);
713 wr_s16b(0); /* old "food_digested" */
714 wr_s16b(0); /* old "protection" */
715 wr_s16b(creature_ptr->energy_need);
716 wr_s16b(creature_ptr->enchant_energy_need);
717 wr_s16b(creature_ptr->fast);
718 wr_s16b(creature_ptr->slow);
719 wr_s16b(creature_ptr->afraid);
720 wr_s16b(creature_ptr->cut);
721 wr_s16b(creature_ptr->stun);
722 wr_s16b(creature_ptr->poisoned);
723 wr_s16b(creature_ptr->image);
724 wr_s16b(creature_ptr->protevil);
725 wr_s16b(creature_ptr->invuln);
726 wr_s16b(creature_ptr->ult_res);
727 wr_s16b(creature_ptr->hero);
728 wr_s16b(creature_ptr->shero);
729 wr_s16b(creature_ptr->shield);
730 wr_s16b(creature_ptr->blessed);
731 wr_s16b(creature_ptr->tim_invis);
732 wr_s16b(creature_ptr->word_recall);
733 wr_s16b(creature_ptr->recall_dungeon);
734 wr_s16b(creature_ptr->alter_reality);
735 wr_s16b(creature_ptr->see_infra);
736 wr_s16b(creature_ptr->tim_infra);
737 wr_s16b(creature_ptr->oppose_fire);
738 wr_s16b(creature_ptr->oppose_cold);
739 wr_s16b(creature_ptr->oppose_acid);
740 wr_s16b(creature_ptr->oppose_elec);
741 wr_s16b(creature_ptr->oppose_pois);
742 wr_s16b(creature_ptr->tsuyoshi);
743 wr_s16b(creature_ptr->tim_esp);
744 wr_s16b(creature_ptr->wraith_form);
745 wr_s16b(creature_ptr->resist_magic);
746 wr_s16b(creature_ptr->tim_regen);
747 wr_s16b(creature_ptr->kabenuke);
748 wr_s16b(creature_ptr->tim_stealth);
749 wr_s16b(creature_ptr->tim_levitation);
750 wr_s16b(creature_ptr->tim_sh_touki);
751 wr_s16b(creature_ptr->lightspeed);
752 wr_s16b(creature_ptr->tsubureru);
753 wr_s16b(creature_ptr->magicdef);
754 wr_s16b(creature_ptr->tim_res_nether);
755 wr_s16b(creature_ptr->tim_res_time);
756 wr_byte((byte)creature_ptr->mimic_form);
757 wr_s16b(creature_ptr->tim_mimic);
758 wr_s16b(creature_ptr->tim_sh_fire);
759 wr_s16b(creature_ptr->tim_sh_holy);
760 wr_s16b(creature_ptr->tim_eyeeye);
763 wr_s16b(creature_ptr->tim_reflect);
764 wr_s16b(creature_ptr->multishadow);
765 wr_s16b(creature_ptr->dustrobe);
767 wr_s16b(creature_ptr->chaos_patron);
768 wr_u32b(creature_ptr->muta1);
769 wr_u32b(creature_ptr->muta2);
770 wr_u32b(creature_ptr->muta3);
772 for (int i = 0; i < 8; i++)
773 wr_s16b(creature_ptr->virtues[i]);
774 for (int i = 0; i < 8; i++)
775 wr_s16b(creature_ptr->vir_types[i]);
777 wr_s16b(creature_ptr->ele_attack);
778 wr_u32b(creature_ptr->special_attack);
779 wr_s16b(creature_ptr->ele_immune);
780 wr_u32b(creature_ptr->special_defense);
781 wr_byte(creature_ptr->knowledge);
782 wr_byte(creature_ptr->autopick_autoregister);
784 wr_byte((byte)creature_ptr->action);
786 wr_byte(preserve_mode);
787 wr_byte(creature_ptr->wait_report_score);
790 for (int i = 0; i < 12; i++) wr_u32b(0L);
792 /* Ignore some flags */
797 /* Write the "object seeds" */
798 wr_u32b(current_world_ptr->seed_flavor);
799 wr_u32b(current_world_ptr->seed_town);
802 wr_u16b(creature_ptr->panic_save);
803 wr_u16b(current_world_ptr->total_winner);
804 wr_u16b(current_world_ptr->noscore);
807 wr_byte(creature_ptr->is_dead);
810 wr_byte(creature_ptr->feeling);
812 /* Turn when level began */
813 wr_s32b(creature_ptr->current_floor_ptr->generated_turn);
815 /* Turn of last "feeling" */
816 wr_s32b(creature_ptr->feeling_turn);
819 wr_s32b(current_world_ptr->game_turn);
821 wr_s32b(current_world_ptr->dungeon_turn);
823 wr_s32b(current_world_ptr->arena_start_turn);
826 wr_s16b(creature_ptr->today_mon);
827 wr_s16b(creature_ptr->riding);
829 /* Current floor_id */
830 wr_s16b(creature_ptr->floor_id);
832 /* Save temporary preserved pets (obsolated) */
835 wr_u32b(current_world_ptr->play_time);
836 wr_s32b(creature_ptr->visit);
837 wr_u32b(creature_ptr->count);
842 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
843 * @param sf_ptr 保存したいフロアの参照ポインタ
846 static void wr_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
849 /* Dungeon floor specific info follows */
850 floor_type *floor_ptr = player_ptr->current_floor_ptr;
853 /*** Not a saved floor ***/
855 wr_s16b((s16b)floor_ptr->dun_level);
859 /*** The saved floor ***/
861 wr_s16b(sf_ptr->floor_id);
862 wr_byte((byte)sf_ptr->savefile_id);
863 wr_s16b((s16b)sf_ptr->dun_level);
864 wr_s32b(sf_ptr->last_visit);
865 wr_u32b(sf_ptr->visit_mark);
866 wr_s16b(sf_ptr->upper_floor_id);
867 wr_s16b(sf_ptr->lower_floor_id);
870 wr_u16b((u16b)floor_ptr->base_level);
871 wr_u16b((s16b)player_ptr->current_floor_ptr->num_repro);
872 wr_u16b((u16b)player_ptr->y);
873 wr_u16b((u16b)player_ptr->x);
874 wr_u16b((u16b)floor_ptr->height);
875 wr_u16b((u16b)floor_ptr->width);
876 wr_byte(player_ptr->feeling);
878 /*********** Make template for grid_type **********/
881 * Usually number of templates are fewer than 255. Even if
882 * more than 254 are exist, the occurrence of each template
883 * with larger ID is very small when we sort templates by
884 * occurrence. So we will use two (or more) bytes for
885 * templete ID larger than 254.
887 * Ex: 256 will be "0xff" "0x01".
888 * 515 will be "0xff" "0xff" "0x03"
891 /* Fake max number */
892 u16b max_num_temp = 255;
894 /* Allocate the "template" array */
895 grid_template_type *templates;
896 C_MAKE(templates, max_num_temp, grid_template_type);
898 /* Extract template array */
900 for (int y = 0; y < floor_ptr->height; y++)
902 for (int x = 0; x < floor_ptr->width; x++)
904 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
907 for (i = 0; i < num_temp; i++)
909 if (templates[i].info == g_ptr->info &&
910 templates[i].feat == g_ptr->feat &&
911 templates[i].mimic == g_ptr->mimic &&
912 templates[i].special == g_ptr->special)
914 /* Same terrain is exist */
915 templates[i].occurrence++;
920 /* Are there same one? */
921 if (i < num_temp) continue;
923 /* If the max_num_temp is too small, increase it. */
924 if (num_temp >= max_num_temp)
926 grid_template_type *old_template = templates;
928 /* Re-allocate the "template" array */
929 C_MAKE(templates, max_num_temp + 255, grid_template_type);
930 (void)C_COPY(templates, old_template, max_num_temp, grid_template_type);
931 C_KILL(old_template, max_num_temp, grid_template_type);
935 /* Add new template */
936 templates[num_temp].info = g_ptr->info;
937 templates[num_temp].feat = g_ptr->feat;
938 templates[num_temp].mimic = g_ptr->mimic;
939 templates[num_temp].special = g_ptr->special;
940 templates[num_temp].occurrence = 1;
942 /* Increase number of template */
947 /* Sort by occurrence */
949 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
951 /*** Dump templates ***/
953 /* Total templates */
956 /* Dump the templates */
957 for (int i = 0; i < num_temp; i++)
959 grid_template_type *ct_ptr = &templates[i];
960 wr_u16b((u16b)ct_ptr->info);
961 wr_s16b(ct_ptr->feat);
962 wr_s16b(ct_ptr->mimic);
963 wr_s16b(ct_ptr->special);
966 /*** "Run-Length-Encoding" of floor ***/
967 /* Note that this will induce two wasted bytes */
971 for (int y = 0; y < floor_ptr->height; y++)
973 for (int x = 0; x < floor_ptr->width; x++)
975 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
977 for (i = 0; i < num_temp; i++)
979 if (templates[i].info == g_ptr->info &&
980 templates[i].feat == g_ptr->feat &&
981 templates[i].mimic == g_ptr->mimic &&
982 templates[i].special == g_ptr->special)
987 u16b tmp16u = (u16b)i;
989 /* If the run is broken, or too full, flush it */
990 if ((tmp16u == prev_u16b) && (count != MAX_UCHAR))
996 wr_byte((byte)count);
998 while (prev_u16b >= MAX_UCHAR)
1000 /* Mark as actual data is larger than 254 */
1002 prev_u16b -= MAX_UCHAR;
1005 wr_byte((byte)prev_u16b);
1011 /* Flush the data (if any) */
1014 wr_byte((byte)count);
1016 while (prev_u16b >= MAX_UCHAR)
1018 /* Mark as actual data is larger than 254 */
1020 prev_u16b -= MAX_UCHAR;
1023 wr_byte((byte)prev_u16b);
1026 /* Free the "template" array */
1027 C_KILL(templates, max_num_temp, grid_template_type);
1029 /*** Dump objects ***/
1032 wr_u16b(floor_ptr->o_max);
1034 /* Dump the objects */
1035 for (int i = 1; i < floor_ptr->o_max; i++)
1037 object_type *o_ptr = &floor_ptr->o_list[i];
1041 /*** Dump the monsters ***/
1043 /* Total monsters */
1044 wr_u16b(floor_ptr->m_max);
1046 /* Dump the monsters */
1047 for (int i = 1; i < floor_ptr->m_max; i++)
1049 monster_type *m_ptr = &floor_ptr->m_list[i];
1056 * @brief 現在フロアの書き込み /
1057 * Write the current dungeon (new method)
1058 * @player_ptr プレーヤーへの参照ポインタ
1059 * @return 保存に成功したらTRUE
1061 static bool wr_dungeon(player_type *player_ptr)
1063 forget_lite(player_ptr->current_floor_ptr);
1064 forget_view(player_ptr->current_floor_ptr);
1065 clear_mon_lite(player_ptr->current_floor_ptr);
1067 /* Update lite/view */
1068 player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1069 player_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1073 /* Number of floor_id used from birth */
1074 wr_s16b(max_floor_id);
1076 /* Current dungeon type */
1077 wr_byte((byte)player_ptr->dungeon_idx);
1080 /*** No saved floor (On the surface etc.) ***/
1081 if (!player_ptr->floor_id)
1083 /* No array elements */
1086 /* Write the current floor data */
1087 wr_saved_floor(player_ptr, NULL);
1094 /*** In the dungeon ***/
1096 /* Number of array elements */
1097 wr_byte(MAX_SAVED_FLOORS);
1099 /* Write the saved_floors array */
1100 for (int i = 0; i < MAX_SAVED_FLOORS; i++)
1102 saved_floor_type *sf_ptr = &saved_floors[i];
1104 wr_s16b(sf_ptr->floor_id);
1105 wr_byte((byte)sf_ptr->savefile_id);
1106 wr_s16b((s16b)sf_ptr->dun_level);
1107 wr_s32b(sf_ptr->last_visit);
1108 wr_u32b(sf_ptr->visit_mark);
1109 wr_s16b(sf_ptr->upper_floor_id);
1110 wr_s16b(sf_ptr->lower_floor_id);
1113 /* Extract pointer to current floor */
1114 saved_floor_type *cur_sf_ptr;
1115 cur_sf_ptr = get_sf_ptr(player_ptr->floor_id);
1117 /* Save current floor to temporary file */
1118 if (!save_floor(player_ptr, cur_sf_ptr, (SLF_SECOND))) return FALSE;
1120 /* Move data in temporary files to the savefile */
1121 for (int i = 0; i < MAX_SAVED_FLOORS; i++)
1123 saved_floor_type *sf_ptr = &saved_floors[i];
1124 if (!sf_ptr->floor_id) continue;
1125 if (!load_floor(player_ptr, sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1132 wr_saved_floor(player_ptr, sf_ptr);
1135 if (!load_floor(player_ptr, cur_sf_ptr, (SLF_SECOND))) return FALSE;
1141 * @brief セーブデータの書き込み /
1142 * Actually write a save-file
1143 * @param player_ptr プレーヤーへの参照ポインタ
1146 static bool wr_savefile_new(player_type *player_ptr)
1148 /* Compact the objects */
1149 compact_objects(player_ptr, 0);
1151 /* Compact the monsters */
1152 compact_monsters(player_ptr, 0);
1154 /* Guess at the current time */
1155 u32b now = (u32b)time((time_t *)0);
1157 /* Note the operating system */
1158 current_world_ptr->sf_system = 0L;
1160 /* Note when the file was saved */
1161 current_world_ptr->sf_when = now;
1163 /* Note the number of saves */
1164 current_world_ptr->sf_saves++;
1166 /*** Actually write the file ***/
1167 /* Dump the file header */
1169 wr_byte(FAKE_VER_MAJOR);
1171 wr_byte(FAKE_VER_MINOR);
1173 wr_byte(FAKE_VER_PATCH);
1176 /* Initial value of xor_byte */
1177 byte tmp8u = (byte)Rand_external(256);
1180 /* Reset the checksum */
1184 /* Write the savefile version for Hengband 1.1.1 and later */
1185 wr_byte(H_VER_EXTRA);
1186 wr_byte(H_VER_PATCH);
1187 wr_byte(H_VER_MINOR);
1188 wr_byte(H_VER_MAJOR);
1190 /* Operating system */
1191 wr_u32b(current_world_ptr->sf_system);
1193 /* Time file last saved */
1194 wr_u32b(current_world_ptr->sf_when);
1196 /* Number of past lives */
1197 wr_u16b(current_world_ptr->sf_lives);
1199 /* Number of times saved */
1200 wr_u16b(current_world_ptr->sf_saves);
1208 /* EUC kanji code */
1212 /* SJIS kanji code */
1220 /* Write the RNG state */
1223 /* Write the boolean "options" */
1226 /* Dump the number of "messages" */
1227 u32b tmp32u = message_num();
1228 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1231 /* Dump the messages (oldest first!) */
1232 for (int i = tmp32u - 1; i >= 0; i--)
1234 wr_string(message_str((s16b)i));
1237 /* Dump the monster lore */
1238 u16b tmp16u = max_r_idx;
1240 for (MONRACE_IDX r_idx = 0; r_idx < tmp16u; r_idx++)
1245 /* Dump the object memory */
1248 for (KIND_OBJECT_IDX k_idx = 0; k_idx < tmp16u; k_idx++)
1253 /* Dump the towns */
1257 /* Dump the quests */
1261 /* Dump the quests */
1262 tmp8u = MAX_RANDOM_QUEST - MIN_RANDOM_QUEST;
1265 for (int i = 0; i < max_q_idx; i++)
1267 quest_type* const q_ptr = &quest[i];
1269 /* Save status for every quest */
1270 wr_s16b(q_ptr->status);
1272 /* And the dungeon level too */
1273 /* (prevents problems with multi-level quests) */
1274 wr_s16b((s16b)q_ptr->level);
1276 wr_byte((byte)q_ptr->complev);
1277 wr_u32b(q_ptr->comptime);
1279 bool is_quest_running = q_ptr->status == QUEST_STATUS_TAKEN;
1280 is_quest_running |= q_ptr->status == QUEST_STATUS_COMPLETED;
1281 is_quest_running |= !is_fixed_quest_idx(i);
1282 if (!is_quest_running) continue;
1284 wr_s16b((s16b)q_ptr->cur_num);
1285 wr_s16b((s16b)q_ptr->max_num);
1286 wr_s16b(q_ptr->type);
1287 wr_s16b(q_ptr->r_idx);
1288 wr_s16b(q_ptr->k_idx);
1289 wr_byte((byte)q_ptr->flags);
1290 wr_byte((byte)q_ptr->dungeon);
1293 /* Dump the position in the wilderness */
1294 wr_s32b(player_ptr->wilderness_x);
1295 wr_s32b(player_ptr->wilderness_y);
1297 wr_byte(player_ptr->wild_mode);
1298 wr_byte(player_ptr->ambush_flag);
1300 wr_s32b(current_world_ptr->max_wild_x);
1301 wr_s32b(current_world_ptr->max_wild_y);
1303 /* Dump the wilderness seeds */
1304 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
1306 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
1308 wr_u32b(wilderness[j][i].seed);
1312 /* Hack -- Dump the artifacts */
1315 for (int i = 0; i < tmp16u; i++)
1317 artifact_type *a_ptr = &a_info[i];
1318 wr_byte(a_ptr->cur_num);
1319 wr_s16b(a_ptr->floor_id);
1322 /* Write the "extra" information */
1323 wr_extra(player_ptr);
1325 /* Dump the "player hp" entries */
1326 tmp16u = PY_MAX_LEVEL;
1328 for (int i = 0; i < tmp16u; i++)
1330 wr_s16b((s16b)player_ptr->player_hp[i]);
1333 /* Write spell data */
1334 wr_u32b(player_ptr->spell_learned1);
1335 wr_u32b(player_ptr->spell_learned2);
1336 wr_u32b(player_ptr->spell_worked1);
1337 wr_u32b(player_ptr->spell_worked2);
1338 wr_u32b(player_ptr->spell_forgotten1);
1339 wr_u32b(player_ptr->spell_forgotten2);
1341 wr_s16b(player_ptr->learned_spells);
1342 wr_s16b(player_ptr->add_spells);
1344 /* Dump the ordered spells */
1345 for (int i = 0; i < 64; i++)
1347 wr_byte((byte)player_ptr->spell_order[i]);
1350 for (int i = 0; i < INVEN_TOTAL; i++)
1352 object_type *o_ptr = &player_ptr->inventory_list[i];
1353 if (!o_ptr->k_idx) continue;
1362 /* Add a sentinel */
1365 /* Note the towns */
1369 /* Note the stores */
1370 tmp16u = MAX_STORES;
1373 /* Dump the stores of all towns */
1374 for (int i = 1; i < max_towns; i++)
1376 for (int j = 0; j < MAX_STORES; j++)
1378 wr_store(&town_info[i].store[j]);
1382 /* Write the pet command settings */
1383 wr_s16b(player_ptr->pet_follow_distance);
1384 wr_s16b(player_ptr->pet_extra_flags);
1386 /* Write screen dump for sending score */
1387 if (screen_dump && (player_ptr->wait_report_score || !player_ptr->is_dead))
1389 wr_string(screen_dump);
1396 /* Player is not dead, write the dungeon */
1397 if (!player_ptr->is_dead)
1399 /* Dump the dungeon */
1400 if (!wr_dungeon(player_ptr)) return FALSE;
1402 /* Dump the ghost */
1409 /* Write the "value check-sum" */
1412 /* Write the "encoded checksum" */
1415 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1421 * @brief セーブデータ書き込みのサブルーチン /
1422 * Medium level player saver
1423 * @param player_ptr プレーヤーへの参照ポインタ
1426 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1428 static bool save_player_aux(player_type *player_ptr, char *name)
1430 FILE_TYPE(FILE_TYPE_SAVE);
1432 /* Grab permissions */
1435 /* Create the savefile */
1436 int file_permission = 0644;
1437 int fd = fd_make(name, file_permission);
1439 /* Drop permissions */
1442 bool is_save_successful = FALSE;
1446 /* Close the "fd" */
1449 /* Grab permissions */
1452 /* Open the savefile */
1453 fff = my_fopen(name, "wb");
1455 /* Drop permissions */
1458 /* Successful open */
1461 /* Write the savefile */
1462 if (wr_savefile_new(player_ptr)) is_save_successful = TRUE;
1464 /* Attempt to close it */
1465 if (my_fclose(fff)) is_save_successful = FALSE;
1468 /* Grab permissions */
1471 /* Remove "broken" files */
1472 if (!is_save_successful) (void)fd_kill(name);
1474 /* Drop permissions */
1478 if (!is_save_successful) return FALSE;
1480 counts_write(player_ptr, 0, current_world_ptr->play_time);
1481 current_world_ptr->character_saved = TRUE;
1487 * @brief セーブデータ書き込みのメインルーチン /
1488 * Attempt to save the player in a savefile
1489 * @param player_ptr プレーヤーへの参照ポインタ
1492 bool save_player(player_type *player_ptr)
1495 strcpy(safe, savefile);
1496 strcat(safe, ".new");
1498 /* Grab permissions */
1503 /* Drop permissions */
1507 /* Attempt to save the player */
1508 bool result = FALSE;
1509 if (save_player_aux(player_ptr, safe))
1514 strcpy(temp, savefile);
1515 strcat(temp, ".old");
1517 /* Grab permissions */
1523 /* Preserve old savefile */
1524 fd_move(savefile, temp);
1526 /* Activate new savefile */
1527 fd_move(safe, savefile);
1529 /* Remove preserved savefile */
1532 /* Drop permissions */
1535 /* Hack -- Pretend the character was loaded */
1536 current_world_ptr->character_loaded = TRUE;
1541 /* Return the result */
1547 * @brief セーブデータ読み込みのメインルーチン /
1548 * Attempt to Load a "savefile"
1549 * @param creature_ptr プレーヤーへの参照ポインタ
1553 * Version 2.7.0 introduced a slightly different "savefile" format from
1554 * older versions, requiring a completely different parsing method.
1556 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1558 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1560 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1562 * On multi-user systems, you may only "read" a savefile if you will be
1563 * allowed to "write" it later, this prevents painful situations in which
1564 * the player loads a savefile belonging to someone else, and then is not
1565 * allowed to save his game when he quits.
1567 * We return "TRUE" if the savefile was usable, and we set the global
1568 * flag "current_world_ptr->character_loaded" if a real, living, character was loaded.
1570 * Note that we always try to load the "current" savefile, even if
1571 * there is no such file, so we must check for "empty" savefile names.
1574 bool load_player(player_type *player_ptr)
1576 concptr what = "generic";
1578 current_world_ptr->game_turn = 0;
1579 player_ptr->is_dead = FALSE;
1582 /* Allow empty savefile name */
1583 if (!savefile[0]) return TRUE;
1586 #if !defined(WINDOWS)
1590 /* Verify the existance of the savefile */
1591 if (access(savefile, 0) < 0)
1593 /* Give a message */
1594 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1609 /* Open the savefile */
1610 fd = fd_open(savefile, O_RDONLY);
1613 if (fd < 0) err = -1;
1615 /* Message (below) */
1616 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1622 /* Read the first four bytes */
1623 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1626 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1633 /* Extract version */
1634 current_world_ptr->z_major = vvv[0];
1635 current_world_ptr->z_minor = vvv[1];
1636 current_world_ptr->z_patch = vvv[2];
1637 current_world_ptr->sf_extra = vvv[3];
1641 /* Attempt to load */
1642 err = rd_savefile_new(player_ptr);
1644 /* Message (below) */
1645 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1651 if (!current_world_ptr->game_turn) err = -1;
1653 /* Message (below) */
1654 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1659 /* Give a conversion warning */
1660 if ((FAKE_VER_MAJOR != current_world_ptr->z_major) ||
1661 (FAKE_VER_MINOR != current_world_ptr->z_minor) ||
1662 (FAKE_VER_PATCH != current_world_ptr->z_patch))
1664 if (current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6)
1666 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1670 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1671 (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);
1676 /* Player is dead */
1677 if (player_ptr->is_dead)
1682 /* A character was loaded */
1683 current_world_ptr->character_loaded = TRUE;
1687 /* Player is no longer "dead" */
1688 player_ptr->is_dead = FALSE;
1691 current_world_ptr->sf_lives++;
1696 /* A character was loaded */
1697 current_world_ptr->character_loaded = TRUE;
1700 u32b tmp = counts_read(player_ptr, 2);
1701 if (tmp > player_ptr->count)
1702 player_ptr->count = tmp;
1703 if (counts_read(player_ptr, 0) > current_world_ptr->play_time || counts_read(player_ptr, 1) == current_world_ptr->play_time)
1704 counts_write(player_ptr, 2, ++player_ptr->count);
1705 counts_write(player_ptr, 1, current_world_ptr->play_time);
1712 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1713 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);
1720 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporary saved floor file
1721 * @param player_ptr プレーヤーへの参照ポインタ
1722 * @param sf_ptr 保存フロア参照ポインタ
1725 static bool save_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
1727 /* Compact the objects */
1728 compact_objects(player_ptr, 0);
1729 /* Compact the monsters */
1730 compact_monsters(player_ptr, 0);
1732 /*** Actually write the file ***/
1733 /* Initial value of xor_byte */
1734 byte tmp8u = (byte)randint0(256);
1738 /* Reset the checksum */
1742 /* Write the sign of this process */
1743 wr_u32b(saved_floor_file_sign);
1745 /* Dump the dungeon floor */
1746 wr_saved_floor(player_ptr, sf_ptr);
1748 /* Write the "value check-sum" */
1751 /* Write the "encoded checksum" */
1754 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1760 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporarily saved-floor data
1761 * @param player_ptr プレーヤーへの参照ポインタ
1762 * @param sf_ptr 保存フロア参照ポインタ
1763 * @param mode 保存オプション
1766 bool save_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
1768 FILE *old_fff = NULL;
1769 byte old_xor_byte = 0;
1770 u32b old_v_stamp = 0;
1771 u32b old_x_stamp = 0;
1773 char floor_savefile[1024];
1774 if (!(mode & SLF_SECOND))
1778 /* We have one file already opened */
1781 /* Backup original values */
1783 old_xor_byte = xor_byte;
1784 old_v_stamp = v_stamp;
1785 old_x_stamp = x_stamp;
1789 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
1791 /* Grab permissions */
1795 fd_kill(floor_savefile);
1797 /* Drop permissions */
1800 /* Attempt to save the player */
1805 /* File type is "SAVE" */
1806 FILE_TYPE(FILE_TYPE_SAVE);
1808 /* Grab permissions */
1811 /* Create the savefile */
1812 int fd = fd_make(floor_savefile, 0644);
1814 /* Drop permissions */
1817 bool is_save_successful = FALSE;
1820 /* Close the "fd" */
1823 /* Grab permissions */
1826 /* Open the savefile */
1827 fff = my_fopen(floor_savefile, "wb");
1829 /* Drop permissions */
1832 /* Successful open */
1835 /* Write the savefile */
1836 if (save_floor_aux(player_ptr, sf_ptr)) is_save_successful = TRUE;
1838 /* Attempt to close it */
1839 if (my_fclose(fff)) is_save_successful = FALSE;
1842 /* Remove "broken" files */
1843 if (!is_save_successful)
1845 /* Grab permissions */
1848 (void)fd_kill(floor_savefile);
1850 /* Drop permissions */
1855 if (!(mode & SLF_SECOND))
1859 /* We have one file already opened */
1862 /* Restore original values */
1864 xor_byte = old_xor_byte;
1865 v_stamp = old_v_stamp;
1866 x_stamp = old_x_stamp;
1869 return is_save_successful;