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.
28 #include "floor-events.h"
29 #include "floor-save.h"
30 #include "floor-town.h"
33 #include "objectkind.h"
34 #include "monsterrace.h"
37 #include "view-mainwindow.h"
41 * Some "local" parameters, used to help write savefiles
44 static FILE *fff; /* Current save "file" */
45 static byte xor_byte; /* Simple encryption */
46 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
47 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
52 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
56 static void sf_put(byte v)
58 /* Encode the value, write a character */
60 (void)putc((int)xor_byte, fff);
62 /* Maintain the checksum info */
68 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
72 static void wr_byte(byte v)
78 * @brief 符号なし16ビットをファイルに書き込む
79 * @param v 書き込む符号なし16bit値
82 static void wr_u16b(u16b v)
84 sf_put((byte)(v & 0xFF));
85 sf_put((byte)((v >> 8) & 0xFF));
89 * @brief 符号あり16ビットをファイルに書き込む
90 * @param v 書き込む符号あり16bit値
93 static void wr_s16b(s16b v)
99 * @brief 符号なし32ビットをファイルに書き込む
100 * @param v 書き込む符号なし32bit値
103 static void wr_u32b(u32b v)
105 sf_put((byte)(v & 0xFF));
106 sf_put((byte)((v >> 8) & 0xFF));
107 sf_put((byte)((v >> 16) & 0xFF));
108 sf_put((byte)((v >> 24) & 0xFF));
112 * @brief 符号あり32ビットをファイルに書き込む
113 * @param v 書き込む符号あり32bit値
116 static void wr_s32b(s32b v)
122 * @brief 文字列をファイルに書き込む
126 static void wr_string(concptr str)
138 * These functions write info in larger logical records
143 * @brief アイテムオブジェクトを書き込む / Write an "item" record
144 * @param o_ptr アイテムオブジェクト保存元ポインタ
147 static void wr_item(object_type *o_ptr)
149 BIT_FLAGS flags = 0x00000000;
151 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
152 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
153 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
154 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
155 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
156 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
157 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
158 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
159 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
160 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
161 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
162 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
163 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
164 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
165 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
166 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
167 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
168 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
169 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
170 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
171 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
172 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
173 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
174 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
175 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
176 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
177 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
178 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
179 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
181 /*** Item save flags ***/
184 /*** Write only un-obvious elements ***/
185 wr_s16b(o_ptr->k_idx);
187 wr_byte((byte_hack)o_ptr->iy);
188 wr_byte((byte_hack)o_ptr->ix);
190 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
192 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
193 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
195 wr_s16b((s16b)o_ptr->weight);
197 if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
198 if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
199 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
201 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
202 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
203 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
204 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
205 if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
206 if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
208 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
210 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
212 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
213 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
214 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
215 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
216 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
218 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
220 /* Held by monster index */
221 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
223 /* Extra information */
224 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
225 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
226 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
227 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
228 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
231 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
233 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
234 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
239 * @brief モンスター情報を書き込む / Write a "monster" record
240 * @param m_ptr モンスター情報保存元ポインタ
243 static void wr_monster(monster_type *m_ptr)
245 BIT_FLAGS flags = 0x00000000;
248 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
249 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
250 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
251 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
252 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
253 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
254 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
255 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
256 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
257 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
258 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
259 if (m_ptr->smart) flags |= SAVE_MON_SMART;
260 if (m_ptr->exp) flags |= SAVE_MON_EXP;
261 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
262 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
263 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
265 /*** Monster save flags ***/
268 /*** Write only un-obvious elements ***/
269 wr_s16b(m_ptr->r_idx);
270 wr_byte((byte_hack)m_ptr->fy);
271 wr_byte((byte_hack)m_ptr->fx);
272 wr_s16b((s16b)m_ptr->hp);
273 wr_s16b((s16b)m_ptr->maxhp);
274 wr_s16b((s16b)m_ptr->max_maxhp);
275 wr_u32b(m_ptr->dealt_damage);
278 /* Monster race index of its appearance */
279 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
281 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
282 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
284 wr_byte((byte)m_ptr->mspeed);
285 wr_s16b(m_ptr->energy_need);
287 if (flags & SAVE_MON_FAST)
289 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
292 if (flags & SAVE_MON_SLOW)
294 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
297 if (flags & SAVE_MON_STUNNED)
299 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
302 if (flags & SAVE_MON_CONFUSED)
304 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
307 if (flags & SAVE_MON_MONFEAR)
309 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
312 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
313 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
314 if (flags & SAVE_MON_INVULNER)
316 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
319 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
320 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
321 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
322 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
323 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
328 * @brief モンスターの思い出を書き込む / Write a "lore" record
329 * @param r_idx モンスター種族ID
332 static void wr_lore(MONRACE_IDX r_idx)
334 monster_race *r_ptr = &r_info[r_idx];
336 /* Count sights/deaths/kills */
337 wr_s16b((s16b)r_ptr->r_sights);
338 wr_s16b((s16b)r_ptr->r_deaths);
339 wr_s16b((s16b)r_ptr->r_pkills);
340 wr_s16b((s16b)r_ptr->r_akills);
341 wr_s16b((s16b)r_ptr->r_tkills);
343 /* Count wakes and ignores */
344 wr_byte(r_ptr->r_wake);
345 wr_byte(r_ptr->r_ignore);
348 wr_byte(r_ptr->r_xtra1);
349 wr_byte(r_ptr->r_xtra2);
352 wr_byte((byte_hack)r_ptr->r_drop_gold);
353 wr_byte((byte_hack)r_ptr->r_drop_item);
356 wr_byte(0); /* unused now */
357 wr_byte(r_ptr->r_cast_spell);
359 /* Count blows of each type */
360 wr_byte(r_ptr->r_blows[0]);
361 wr_byte(r_ptr->r_blows[1]);
362 wr_byte(r_ptr->r_blows[2]);
363 wr_byte(r_ptr->r_blows[3]);
366 wr_u32b(r_ptr->r_flags1);
367 wr_u32b(r_ptr->r_flags2);
368 wr_u32b(r_ptr->r_flags3);
369 wr_u32b(r_ptr->r_flags4);
370 wr_u32b(r_ptr->r_flags5);
371 wr_u32b(r_ptr->r_flags6);
372 wr_u32b(r_ptr->r_flagsr);
374 /* Monster limit per level */
375 wr_byte((byte_hack)r_ptr->max_num);
377 /* Location in saved floor */
378 wr_s16b(r_ptr->floor_id);
385 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
386 * @param k_idx ベースアイテムのID
389 static void wr_xtra(KIND_OBJECT_IDX k_idx)
393 object_kind *k_ptr = &k_info[k_idx];
395 if (k_ptr->aware) tmp8u |= 0x01;
396 if (k_ptr->tried) tmp8u |= 0x02;
403 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
404 * @param st_ptr 店舗情報の参照ポインタ
407 static void wr_store(store_type *st_ptr)
411 /* Save the "open" counter */
412 wr_u32b(st_ptr->store_open);
414 /* Save the "insults" */
415 wr_s16b(st_ptr->insult_cur);
417 /* Save the current owner */
418 wr_byte(st_ptr->owner);
420 /* Save the stock size */
421 wr_s16b(st_ptr->stock_num);
423 /* Save the "haggle" info */
424 wr_s16b(st_ptr->good_buy);
425 wr_s16b(st_ptr->bad_buy);
427 wr_s32b(st_ptr->last_visit);
430 for (j = 0; j < st_ptr->stock_num; j++)
432 /* Save each item in stock */
433 wr_item(&st_ptr->stock[j]);
439 * @brief セーブデータに乱数情報を書き込む / Write RNG state
442 static errr wr_randomizer(void)
448 for (i = 0; i < RAND_DEG; i++)
450 wr_u32b(Rand_state[i]);
458 * @brief ゲームオプション情報を書き込む / Write the "options"
461 static void wr_options(void)
470 for (i = 0; i < 4; i++) wr_u32b(0L);
473 /*** 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 ***/
488 if (current_world_ptr->wizard) c |= 0x0002;
490 if (cheat_sight) c |= 0x0040;
491 if (cheat_turn) c |= 0x0080;
493 if (cheat_peek) c |= 0x0100;
494 if (cheat_hear) c |= 0x0200;
495 if (cheat_room) c |= 0x0400;
496 if (cheat_xtra) c |= 0x0800;
497 if (cheat_know) c |= 0x1000;
498 if (cheat_live) c |= 0x2000;
499 if (cheat_save) c |= 0x4000;
500 if (cheat_diary_output) c |= 0x8000;
507 wr_s16b(autosave_freq);
509 /*** Extract options ***/
511 /* Analyze the options */
512 for (i = 0; option_info[i].o_desc; i++)
514 int os = option_info[i].o_set;
515 int ob = option_info[i].o_bit;
517 /* Process real entries */
518 if (option_info[i].o_var)
521 if (*option_info[i].o_var)
524 option_flag[os] |= (1L << ob);
528 option_flag[os] &= ~(1L << ob);
534 /*** Normal options ***/
537 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
540 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
543 /*** Window options ***/
546 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
549 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
554 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
557 static void wr_ghost(void)
562 wr_string(_("不正なゴースト", "Broken Ghost"));
564 /* Hack -- stupid data */
565 for (i = 0; i < 60; i++) wr_byte(0);
570 * @brief クイック・スタート情報を書き込む / Save quick start data
573 static void save_quick_start(void)
577 wr_byte(previous_char.psex);
578 wr_byte((byte_hack)previous_char.prace);
579 wr_byte((byte_hack)previous_char.pclass);
580 wr_byte((byte_hack)previous_char.pseikaku);
581 wr_byte((byte_hack)previous_char.realm1);
582 wr_byte((byte_hack)previous_char.realm2);
584 wr_s16b(previous_char.age);
585 wr_s16b(previous_char.ht);
586 wr_s16b(previous_char.wt);
587 wr_s16b(previous_char.sc);
588 wr_s32b(previous_char.au);
590 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
591 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
593 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
595 wr_s16b(previous_char.chaos_patron);
597 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
599 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
601 /* UNUSED : Was number of random quests */
604 /* No quick start after using debug mode or cheat options */
605 if (current_world_ptr->noscore) previous_char.quick_ok = FALSE;
607 wr_byte((byte)previous_char.quick_ok);
612 * @brief その他の情報を書き込む / Write some "extra" info
615 static void wr_extra(player_type *creature_ptr)
620 wr_string(creature_ptr->name);
621 wr_string(creature_ptr->died_from);
622 wr_string(creature_ptr->last_message ? creature_ptr->last_message : "");
626 for (i = 0; i < 4; i++)
628 wr_string(creature_ptr->history[i]);
631 /* Race/Class/Gender/Spells */
632 wr_byte((byte_hack)creature_ptr->prace);
633 wr_byte((byte_hack)creature_ptr->pclass);
634 wr_byte((byte_hack)creature_ptr->pseikaku);
635 wr_byte((byte_hack)creature_ptr->psex);
636 wr_byte((byte_hack)creature_ptr->realm1);
637 wr_byte((byte_hack)creature_ptr->realm2);
640 wr_byte((byte)creature_ptr->hitdie);
641 wr_u16b(creature_ptr->expfact);
643 wr_s16b(creature_ptr->age);
644 wr_s16b(creature_ptr->ht);
645 wr_s16b(creature_ptr->wt);
647 /* Dump the stats (maximum and current) */
648 for (i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max[i]);
649 for (i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max_max[i]);
650 for (i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_cur[i]);
652 /* Ignore the transient stats */
653 for (i = 0; i < 12; ++i) wr_s16b(0);
655 wr_u32b(creature_ptr->au);
657 wr_u32b(creature_ptr->max_exp);
658 wr_u32b(creature_ptr->max_max_exp);
659 wr_u32b(creature_ptr->exp);
660 wr_u32b(creature_ptr->exp_frac);
661 wr_s16b(creature_ptr->lev);
663 for (i = 0; i < 64; i++) wr_s16b(creature_ptr->spell_exp[i]);
664 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(creature_ptr->weapon_exp[i][j]);
665 for (i = 0; i < GINOU_MAX; i++) wr_s16b(creature_ptr->skill_exp[i]);
666 for (i = 0; i < 108; i++) wr_s32b(creature_ptr->magic_num1[i]);
667 for (i = 0; i < 108; i++) wr_byte(creature_ptr->magic_num2[i]);
669 wr_byte((byte_hack)creature_ptr->start_race);
670 wr_s32b(creature_ptr->old_race1);
671 wr_s32b(creature_ptr->old_race2);
672 wr_s16b(creature_ptr->old_realm);
674 for (i = 0; i < MAX_MANE; i++)
676 wr_s16b((s16b)creature_ptr->mane_spell[i]);
677 wr_s16b((s16b)creature_ptr->mane_dam[i]);
679 wr_s16b(creature_ptr->mane_num);
681 for (i = 0; i < MAX_BOUNTY; i++)
683 wr_s16b(current_world_ptr->bounty_r_idx[i]);
686 for (i = 0; i < 4; i++)
688 wr_s16b(battle_mon[i]);
689 wr_u32b(mon_odds[i]);
692 wr_s16b(creature_ptr->town_num); /* -KMW- */
694 /* Write arena and rewards information -KMW- */
695 wr_s16b(creature_ptr->arena_number);
696 wr_s16b(creature_ptr->current_floor_ptr->inside_arena);
697 wr_s16b(creature_ptr->current_floor_ptr->inside_quest);
698 wr_s16b(creature_ptr->phase_out);
699 wr_byte(creature_ptr->exit_bldg);
700 wr_byte(0); /* Unused */
702 wr_s16b((s16b)creature_ptr->oldpx);
703 wr_s16b((s16b)creature_ptr->oldpy);
705 /* Was number of creature_ptr->rewards[] */
708 wr_s32b(creature_ptr->mhp);
709 wr_s32b(creature_ptr->chp);
710 wr_u32b(creature_ptr->chp_frac);
712 wr_s32b(creature_ptr->msp);
713 wr_s32b(creature_ptr->csp);
714 wr_u32b(creature_ptr->csp_frac);
716 /* Max Player and Dungeon Levels */
717 wr_s16b(creature_ptr->max_plv);
718 tmp8u = (byte)current_world_ptr->max_d_idx;
720 for (i = 0; i < tmp8u; i++)
721 wr_s16b((s16b)max_dlv[i]);
728 wr_s16b(creature_ptr->sc);
729 wr_s16b(creature_ptr->concent);
731 wr_s16b(0); /* old "rest" */
732 wr_s16b(creature_ptr->blind);
733 wr_s16b(creature_ptr->paralyzed);
734 wr_s16b(creature_ptr->confused);
735 wr_s16b(creature_ptr->food);
736 wr_s16b(0); /* old "food_digested" */
737 wr_s16b(0); /* old "protection" */
738 wr_s16b(creature_ptr->energy_need);
739 wr_s16b(creature_ptr->enchant_energy_need);
740 wr_s16b(creature_ptr->fast);
741 wr_s16b(creature_ptr->slow);
742 wr_s16b(creature_ptr->afraid);
743 wr_s16b(creature_ptr->cut);
744 wr_s16b(creature_ptr->stun);
745 wr_s16b(creature_ptr->poisoned);
746 wr_s16b(creature_ptr->image);
747 wr_s16b(creature_ptr->protevil);
748 wr_s16b(creature_ptr->invuln);
749 wr_s16b(creature_ptr->ult_res);
750 wr_s16b(creature_ptr->hero);
751 wr_s16b(creature_ptr->shero);
752 wr_s16b(creature_ptr->shield);
753 wr_s16b(creature_ptr->blessed);
754 wr_s16b(creature_ptr->tim_invis);
755 wr_s16b(creature_ptr->word_recall);
756 wr_s16b(creature_ptr->recall_dungeon);
757 wr_s16b(creature_ptr->alter_reality);
758 wr_s16b(creature_ptr->see_infra);
759 wr_s16b(creature_ptr->tim_infra);
760 wr_s16b(creature_ptr->oppose_fire);
761 wr_s16b(creature_ptr->oppose_cold);
762 wr_s16b(creature_ptr->oppose_acid);
763 wr_s16b(creature_ptr->oppose_elec);
764 wr_s16b(creature_ptr->oppose_pois);
765 wr_s16b(creature_ptr->tsuyoshi);
766 wr_s16b(creature_ptr->tim_esp);
767 wr_s16b(creature_ptr->wraith_form);
768 wr_s16b(creature_ptr->resist_magic);
769 wr_s16b(creature_ptr->tim_regen);
770 wr_s16b(creature_ptr->kabenuke);
771 wr_s16b(creature_ptr->tim_stealth);
772 wr_s16b(creature_ptr->tim_levitation);
773 wr_s16b(creature_ptr->tim_sh_touki);
774 wr_s16b(creature_ptr->lightspeed);
775 wr_s16b(creature_ptr->tsubureru);
776 wr_s16b(creature_ptr->magicdef);
777 wr_s16b(creature_ptr->tim_res_nether);
778 wr_s16b(creature_ptr->tim_res_time);
779 wr_byte((byte)creature_ptr->mimic_form);
780 wr_s16b(creature_ptr->tim_mimic);
781 wr_s16b(creature_ptr->tim_sh_fire);
782 wr_s16b(creature_ptr->tim_sh_holy);
783 wr_s16b(creature_ptr->tim_eyeeye);
786 wr_s16b(creature_ptr->tim_reflect);
787 wr_s16b(creature_ptr->multishadow);
788 wr_s16b(creature_ptr->dustrobe);
790 wr_s16b(creature_ptr->chaos_patron);
791 wr_u32b(creature_ptr->muta1);
792 wr_u32b(creature_ptr->muta2);
793 wr_u32b(creature_ptr->muta3);
795 for (i = 0; i<8; i++)
796 wr_s16b(creature_ptr->virtues[i]);
797 for (i = 0; i<8; i++)
798 wr_s16b(creature_ptr->vir_types[i]);
800 wr_s16b(creature_ptr->ele_attack);
801 wr_u32b(creature_ptr->special_attack);
802 wr_s16b(creature_ptr->ele_immune);
803 wr_u32b(creature_ptr->special_defense);
804 wr_byte(creature_ptr->knowledge);
805 wr_byte(creature_ptr->autopick_autoregister);
807 wr_byte((byte_hack)creature_ptr->action);
809 wr_byte(preserve_mode);
810 wr_byte(creature_ptr->wait_report_score);
813 for (i = 0; i < 12; i++) wr_u32b(0L);
815 /* Ignore some flags */
821 /* Write the "object seeds" */
822 wr_u32b(current_world_ptr->seed_flavor);
823 wr_u32b(current_world_ptr->seed_town);
827 wr_u16b(creature_ptr->panic_save);
828 wr_u16b(current_world_ptr->total_winner);
829 wr_u16b(current_world_ptr->noscore);
833 wr_byte(creature_ptr->is_dead);
836 wr_byte(creature_ptr->feeling);
838 /* Turn when level began */
839 wr_s32b(creature_ptr->current_floor_ptr->generated_turn);
841 /* Turn of last "feeling" */
842 wr_s32b(creature_ptr->feeling_turn);
845 wr_s32b(current_world_ptr->game_turn);
847 wr_s32b(current_world_ptr->dungeon_turn);
849 wr_s32b(current_world_ptr->arena_start_turn);
852 wr_s16b(creature_ptr->today_mon);
853 wr_s16b(creature_ptr->riding);
855 /* Current floor_id */
856 wr_s16b(creature_ptr->floor_id);
858 /* Save temporary preserved pets (obsolated) */
861 wr_u32b(current_world_ptr->play_time);
863 wr_s32b(creature_ptr->visit);
865 wr_u32b(creature_ptr->count);
870 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
871 * @param sf_ptr 保存したいフロアの参照ポインタ
874 static void wr_saved_floor(saved_floor_type *sf_ptr)
876 grid_template_type *templates;
891 /* Dungeon floor specific info follows */
895 /*** Not a saved floor ***/
897 wr_s16b((s16b)p_ptr->current_floor_ptr->dun_level);
901 /*** The saved floor ***/
903 wr_s16b(sf_ptr->floor_id);
904 wr_byte((byte_hack)sf_ptr->savefile_id);
905 wr_s16b((s16b)sf_ptr->dun_level);
906 wr_s32b(sf_ptr->last_visit);
907 wr_u32b(sf_ptr->visit_mark);
908 wr_s16b(sf_ptr->upper_floor_id);
909 wr_s16b(sf_ptr->lower_floor_id);
912 wr_u16b((u16b)p_ptr->current_floor_ptr->base_level);
913 wr_u16b((s16b)p_ptr->current_floor_ptr->num_repro);
914 wr_u16b((u16b)p_ptr->y);
915 wr_u16b((u16b)p_ptr->x);
916 wr_u16b((u16b)p_ptr->current_floor_ptr->height);
917 wr_u16b((u16b)p_ptr->current_floor_ptr->width);
918 wr_byte(p_ptr->feeling);
922 /*********** Make template for grid_type **********/
925 * Usually number of templates are fewer than 255. Even if
926 * more than 254 are exist, the occurrence of each template
927 * with larger ID is very small when we sort templates by
928 * occurrence. So we will use two (or more) bytes for
929 * templete ID larger than 254.
931 * Ex: 256 will be "0xff" "0x01".
932 * 515 will be "0xff" "0xff" "0x03"
935 /* Fake max number */
938 /* Allocate the "template" array */
939 C_MAKE(templates, max_num_temp, grid_template_type);
941 /* Extract template array */
942 for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
944 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
946 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
948 for (i = 0; i < num_temp; i++)
950 if (templates[i].info == g_ptr->info &&
951 templates[i].feat == g_ptr->feat &&
952 templates[i].mimic == g_ptr->mimic &&
953 templates[i].special == g_ptr->special)
955 /* Same terrain is exist */
956 templates[i].occurrence++;
961 /* Are there same one? */
962 if (i < num_temp) continue;
964 /* If the max_num_temp is too small, increase it. */
965 if (num_temp >= max_num_temp)
967 grid_template_type *old_template = templates;
969 /* Re-allocate the "template" array */
970 C_MAKE(templates, max_num_temp + 255, grid_template_type);
971 (void)C_COPY(templates, old_template, max_num_temp, grid_template_type);
972 C_KILL(old_template, max_num_temp, grid_template_type);
976 /* Add new template */
977 templates[num_temp].info = g_ptr->info;
978 templates[num_temp].feat = g_ptr->feat;
979 templates[num_temp].mimic = g_ptr->mimic;
980 templates[num_temp].special = g_ptr->special;
981 templates[num_temp].occurrence = 1;
983 /* Increase number of template */
988 /* Sort by occurrence */
989 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
991 /*** Dump templates ***/
993 /* Total templates */
996 /* Dump the templates */
997 for (i = 0; i < num_temp; i++)
999 grid_template_type *ct_ptr = &templates[i];
1002 wr_u16b((u16b)ct_ptr->info);
1003 wr_s16b(ct_ptr->feat);
1004 wr_s16b(ct_ptr->mimic);
1005 wr_s16b(ct_ptr->special);
1010 /*** "Run-Length-Encoding" of floor ***/
1012 /* Note that this will induce two wasted bytes */
1016 for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
1018 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
1020 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1022 for (i = 0; i < num_temp; i++)
1024 if (templates[i].info == g_ptr->info &&
1025 templates[i].feat == g_ptr->feat &&
1026 templates[i].mimic == g_ptr->mimic &&
1027 templates[i].special == g_ptr->special)
1034 /* If the run is broken, or too full, flush it */
1035 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
1037 wr_byte((byte)count);
1039 while (prev_u16b >= MAX_UCHAR)
1041 /* Mark as actual data is larger than 254 */
1043 prev_u16b -= MAX_UCHAR;
1046 wr_byte((byte)prev_u16b);
1051 /* Continue the run */
1059 /* Flush the data (if any) */
1062 wr_byte((byte)count);
1064 while (prev_u16b >= MAX_UCHAR)
1066 /* Mark as actual data is larger than 254 */
1068 prev_u16b -= MAX_UCHAR;
1070 wr_byte((byte)prev_u16b);
1074 /* Free the "template" array */
1075 C_KILL(templates, max_num_temp, grid_template_type);
1078 /*** Dump objects ***/
1081 wr_u16b(p_ptr->current_floor_ptr->o_max);
1083 /* Dump the objects */
1084 for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
1086 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[i];
1093 /*** Dump the monsters ***/
1095 /* Total monsters */
1096 wr_u16b(p_ptr->current_floor_ptr->m_max);
1098 /* Dump the monsters */
1099 for (i = 1; i < p_ptr->current_floor_ptr->m_max; i++)
1101 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i];
1110 * @brief 現在フロアの書き込み /
1111 * Write the current dungeon (new method)
1112 * @player_ptr プレーヤーへの参照ポインタ
1113 * @return 保存に成功したらTRUE
1115 static bool wr_dungeon(player_type *player_ptr)
1117 saved_floor_type *cur_sf_ptr;
1120 forget_lite(p_ptr->current_floor_ptr);
1121 forget_view(p_ptr->current_floor_ptr);
1122 clear_mon_lite(p_ptr->current_floor_ptr);
1124 /* Update lite/view */
1125 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1126 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1130 /* Number of floor_id used from birth */
1131 wr_s16b(max_floor_id);
1133 /* Current dungeon type */
1134 wr_byte((byte_hack)p_ptr->dungeon_idx);
1137 /*** No saved floor (On the surface etc.) ***/
1138 if (!p_ptr->floor_id)
1140 /* No array elements */
1143 /* Write the current floor data */
1144 wr_saved_floor(NULL);
1151 /*** In the dungeon ***/
1153 /* Number of array elements */
1154 wr_byte(MAX_SAVED_FLOORS);
1156 /* Write the saved_floors array */
1157 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1159 saved_floor_type *sf_ptr = &saved_floors[i];
1161 wr_s16b(sf_ptr->floor_id);
1162 wr_byte((byte_hack)sf_ptr->savefile_id);
1163 wr_s16b((s16b)sf_ptr->dun_level);
1164 wr_s32b(sf_ptr->last_visit);
1165 wr_u32b(sf_ptr->visit_mark);
1166 wr_s16b(sf_ptr->upper_floor_id);
1167 wr_s16b(sf_ptr->lower_floor_id);
1170 /* Extract pointer to current floor */
1171 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1173 /* Save current floor to temporary file */
1174 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1176 /* Move data in temporary files to the savefile */
1177 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1179 saved_floor_type *sf_ptr = &saved_floors[i];
1181 /* Unused element */
1182 if (!sf_ptr->floor_id) continue;
1184 /* Load temporary saved floor file */
1185 if (load_floor(player_ptr, sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1190 /* Write saved floor data to the save file */
1191 wr_saved_floor(sf_ptr);
1200 /* Restore current floor */
1201 if (!load_floor(player_ptr, cur_sf_ptr, (SLF_SECOND))) return FALSE;
1209 * @brief セーブデータの書き込み /
1210 * Actually write a save-file
1211 * @param player_ptr プレーヤーへの参照ポインタ
1214 static bool wr_savefile_new(player_type *player_ptr)
1225 KIND_OBJECT_IDX k_idx;
1227 /* Compact the objects */
1228 compact_objects(player_ptr->current_floor_ptr, 0);
1229 /* Compact the monsters */
1230 compact_monsters(0);
1232 /* Guess at the current time */
1233 now = (u32b)time((time_t *)0);
1236 /* Note the operating system */
1237 current_world_ptr->sf_system = 0L;
1239 /* Note when the file was saved */
1240 current_world_ptr->sf_when = now;
1242 /* Note the number of saves */
1243 current_world_ptr->sf_saves++;
1246 /*** Actually write the file ***/
1248 /* Dump the file header */
1250 wr_byte(FAKE_VER_MAJOR);
1252 wr_byte(FAKE_VER_MINOR);
1254 wr_byte(FAKE_VER_PATCH);
1257 /* Initial value of xor_byte */
1258 tmp8u = (byte)Rand_external(256);
1262 /* Reset the checksum */
1266 /* Write the savefile version for Hengband 1.1.1 and later */
1267 wr_byte(H_VER_EXTRA);
1268 wr_byte(H_VER_PATCH);
1269 wr_byte(H_VER_MINOR);
1270 wr_byte(H_VER_MAJOR);
1272 /* Operating system */
1273 wr_u32b(current_world_ptr->sf_system);
1276 /* Time file last saved */
1277 wr_u32b(current_world_ptr->sf_when);
1279 /* Number of past lives */
1280 wr_u16b(current_world_ptr->sf_lives);
1282 /* Number of times saved */
1283 wr_u16b(current_world_ptr->sf_saves);
1293 /* EUC kanji code */
1297 /* SJIS kanji code */
1305 /* Write the RNG state */
1309 /* Write the boolean "options" */
1313 /* Dump the number of "messages" */
1314 tmp32u = message_num();
1315 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1318 /* Dump the messages (oldest first!) */
1319 for (i = tmp32u - 1; i >= 0; i--)
1321 wr_string(message_str((s16b)i));
1324 /* Dump the monster lore */
1327 for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
1329 /* Dump the object memory */
1332 for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
1334 /* Dump the towns */
1338 /* Dump the quests */
1342 /* Dump the quests */
1343 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1346 for (i = 0; i < max_q_idx; i++)
1348 quest_type* const q_ptr = &quest[i];
1350 /* Save status for every quest */
1351 wr_s16b(q_ptr->status);
1353 /* And the dungeon level too */
1354 /* (prevents problems with multi-level quests) */
1355 wr_s16b((s16b)q_ptr->level);
1357 wr_byte((byte_hack)q_ptr->complev);
1358 wr_u32b(q_ptr->comptime);
1360 /* Save quest status if quest is running */
1361 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1363 wr_s16b((s16b)q_ptr->cur_num);
1364 wr_s16b((s16b)q_ptr->max_num);
1365 wr_s16b(q_ptr->type);
1366 wr_s16b(q_ptr->r_idx);
1367 wr_s16b(q_ptr->k_idx);
1368 wr_byte((byte_hack)q_ptr->flags);
1369 wr_byte((byte_hack)q_ptr->dungeon);
1373 /* Dump the position in the wilderness */
1374 wr_s32b(player_ptr->wilderness_x);
1375 wr_s32b(player_ptr->wilderness_y);
1377 wr_byte(player_ptr->wild_mode);
1378 wr_byte(player_ptr->ambush_flag);
1380 wr_s32b(current_world_ptr->max_wild_x);
1381 wr_s32b(current_world_ptr->max_wild_y);
1383 /* Dump the wilderness seeds */
1384 for (i = 0; i < current_world_ptr->max_wild_x; i++)
1386 for (j = 0; j < current_world_ptr->max_wild_y; j++)
1388 wr_u32b(wilderness[j][i].seed);
1392 /* Hack -- Dump the artifacts */
1395 for (i = 0; i < tmp16u; i++)
1397 artifact_type *a_ptr = &a_info[i];
1398 wr_byte(a_ptr->cur_num);
1399 wr_s16b(a_ptr->floor_id);
1404 /* Write the "extra" information */
1405 wr_extra(player_ptr);
1407 /* Dump the "player hp" entries */
1408 tmp16u = PY_MAX_LEVEL;
1410 for (i = 0; i < tmp16u; i++)
1412 wr_s16b((s16b)player_ptr->player_hp[i]);
1416 /* Write spell data */
1417 wr_u32b(player_ptr->spell_learned1);
1418 wr_u32b(player_ptr->spell_learned2);
1419 wr_u32b(player_ptr->spell_worked1);
1420 wr_u32b(player_ptr->spell_worked2);
1421 wr_u32b(player_ptr->spell_forgotten1);
1422 wr_u32b(player_ptr->spell_forgotten2);
1424 wr_s16b(player_ptr->learned_spells);
1425 wr_s16b(player_ptr->add_spells);
1427 /* Dump the ordered spells */
1428 for (i = 0; i < 64; i++)
1430 wr_byte((byte_hack)player_ptr->spell_order[i]);
1433 for (i = 0; i < INVEN_TOTAL; i++)
1435 object_type *o_ptr = &player_ptr->inventory_list[i];
1436 if (!o_ptr->k_idx) continue;
1445 /* Add a sentinel */
1448 /* Note the towns */
1452 /* Note the stores */
1453 tmp16u = MAX_STORES;
1456 /* Dump the stores of all towns */
1457 for (i = 1; i < max_towns; i++)
1459 for (j = 0; j < MAX_STORES; j++)
1461 wr_store(&town_info[i].store[j]);
1465 /* Write the pet command settings */
1466 wr_s16b(player_ptr->pet_follow_distance);
1467 wr_s16b(player_ptr->pet_extra_flags);
1469 /* Write screen dump for sending score */
1470 if (screen_dump && (player_ptr->wait_report_score || !player_ptr->is_dead))
1472 wr_string(screen_dump);
1479 /* Player is not dead, write the dungeon */
1480 if (!player_ptr->is_dead)
1482 /* Dump the dungeon */
1483 if (!wr_dungeon(player_ptr)) return FALSE;
1485 /* Dump the ghost */
1493 /* Write the "value check-sum" */
1496 /* Write the "encoded checksum" */
1501 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1503 /* Successful save */
1509 * @brief セーブデータ書き込みのサブルーチン /
1510 * Medium level player saver
1511 * @param player_ptr プレーヤーへの参照ポインタ
1514 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1516 static bool save_player_aux(player_type *player_ptr, char *name)
1525 /* File type is "SAVE" */
1526 FILE_TYPE(FILE_TYPE_SAVE);
1528 /* Grab permissions */
1531 /* Create the savefile */
1532 fd = fd_make(name, mode);
1534 /* Drop permissions */
1540 /* Close the "fd" */
1543 /* Grab permissions */
1546 /* Open the savefile */
1547 fff = my_fopen(name, "wb");
1549 /* Drop permissions */
1552 /* Successful open */
1555 /* Write the savefile */
1556 if (wr_savefile_new(player_ptr)) ok = TRUE;
1558 /* Attempt to close it */
1559 if (my_fclose(fff)) ok = FALSE;
1562 /* Grab permissions */
1565 /* Remove "broken" files */
1566 if (!ok) (void)fd_kill(name);
1568 /* Drop permissions */
1574 if (!ok) return FALSE;
1576 counts_write(player_ptr, 0, current_world_ptr->play_time);
1578 /* Successful save */
1579 current_world_ptr->character_saved = TRUE;
1588 * @brief セーブデータ書き込みのメインルーチン /
1589 * Attempt to save the player in a savefile
1590 * @param player_ptr プレーヤーへの参照ポインタ
1593 bool save_player(player_type *player_ptr)
1595 bool result = FALSE;
1604 /* Get "games" permissions */
1613 strcpy(safe, savefile);
1614 strcat(safe, ".new");
1616 /* Grab permissions */
1622 /* Drop permissions */
1627 /* Attempt to save the player */
1628 if (save_player_aux(player_ptr, safe))
1633 strcpy(temp, savefile);
1634 strcat(temp, ".old");
1636 /* Grab permissions */
1642 /* Preserve old savefile */
1643 fd_move(savefile, temp);
1645 /* Activate new savefile */
1646 fd_move(safe, savefile);
1648 /* Remove preserved savefile */
1651 /* Drop permissions */
1654 /* Hack -- Pretend the character was loaded */
1655 current_world_ptr->character_loaded = TRUE;
1657 #ifdef VERIFY_SAVEFILE
1659 /* Lock on savefile */
1660 strcpy(temp, savefile);
1661 strcat(temp, ".lok");
1663 /* Grab permissions */
1666 /* Remove lock file */
1669 /* Drop permissions */
1683 /* Drop "games" permissions */
1690 /* Return the result */
1696 * @brief セーブデータ読み込みのメインルーチン /
1697 * Attempt to Load a "savefile"
1698 * @param creature_ptr プレーヤーへの参照ポインタ
1702 * Version 2.7.0 introduced a slightly different "savefile" format from
1703 * older versions, requiring a completely different parsing method.
1705 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1707 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1709 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1711 * On multi-user systems, you may only "read" a savefile if you will be
1712 * allowed to "write" it later, this prevents painful situations in which
1713 * the player loads a savefile belonging to someone else, and then is not
1714 * allowed to save his game when he quits.
1716 * We return "TRUE" if the savefile was usable, and we set the global
1717 * flag "current_world_ptr->character_loaded" if a real, living, character was loaded.
1719 * Note that we always try to load the "current" savefile, even if
1720 * there is no such file, so we must check for "empty" savefile names.
1723 bool load_player(player_type *player_ptr)
1731 #ifdef VERIFY_TIMESTAMP
1732 struct stat statbuf;
1735 concptr what = "generic";
1737 current_world_ptr->game_turn = 0;
1738 p_ptr->is_dead = FALSE;
1741 /* Allow empty savefile name */
1742 if (!savefile[0]) return TRUE;
1745 #if !defined(MACINTOSH) && !defined(WINDOWS)
1749 /* Verify the existance of the savefile */
1750 if (access(savefile, 0) < 0)
1752 /* Give a message */
1753 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1764 #ifdef VERIFY_SAVEFILE
1766 /* Verify savefile usage */
1773 /* Extract name of lock file */
1774 strcpy(temp, savefile);
1775 strcat(temp, ".lok");
1777 /* Check for lock */
1778 fkk = my_fopen(temp, "r");
1780 /* Oops, lock exists */
1785 msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
1791 /* Create a lock file */
1792 fkk = my_fopen(temp, "w");
1794 /* Dump a line of info */
1795 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1797 /* Close the lock file */
1806 /* Open the savefile */
1807 fd = fd_open(savefile, O_RDONLY);
1810 if (fd < 0) err = -1;
1812 /* Message (below) */
1813 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1820 #ifdef VERIFY_TIMESTAMP
1821 /* Get the timestamp */
1822 (void)fstat(fd, &statbuf);
1825 /* Read the first four bytes */
1826 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1829 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1837 /* Extract version */
1838 current_world_ptr->z_major = vvv[0];
1839 current_world_ptr->z_minor = vvv[1];
1840 current_world_ptr->z_patch = vvv[2];
1841 current_world_ptr->sf_extra = vvv[3];
1845 /* Attempt to load */
1846 err = rd_savefile_new();
1848 /* Message (below) */
1849 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1854 if (!current_world_ptr->game_turn) err = -1;
1856 /* Message (below) */
1857 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1860 #ifdef VERIFY_TIMESTAMP
1861 /* Verify timestamp */
1862 if (!err && !arg_wizard)
1864 /* Hack -- Verify the timestamp */
1865 if (current_world_ptr->sf_when > (statbuf.st_ctime + 100) ||
1866 current_world_ptr->sf_when < (statbuf.st_ctime - 100))
1868 what = _("無効なタイム・スタンプです", "Invalid timestamp");
1878 /* Give a conversion warning */
1879 if ((FAKE_VER_MAJOR != current_world_ptr->z_major) ||
1880 (FAKE_VER_MINOR != current_world_ptr->z_minor) ||
1881 (FAKE_VER_PATCH != current_world_ptr->z_patch))
1883 if (current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6)
1885 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1889 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1890 (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);
1895 /* Player is dead */
1896 if (player_ptr->is_dead)
1901 /* A character was loaded */
1902 current_world_ptr->character_loaded = TRUE;
1906 /* Player is no longer "dead" */
1907 player_ptr->is_dead = FALSE;
1910 current_world_ptr->sf_lives++;
1915 /* A character was loaded */
1916 current_world_ptr->character_loaded = TRUE;
1919 u32b tmp = counts_read(player_ptr, 2);
1920 if (tmp > player_ptr->count)
1921 player_ptr->count = tmp;
1922 if (counts_read(player_ptr, 0) > current_world_ptr->play_time || counts_read(player_ptr, 1) == current_world_ptr->play_time)
1923 counts_write(player_ptr, 2, ++player_ptr->count);
1924 counts_write(player_ptr, 1, current_world_ptr->play_time);
1932 #ifdef VERIFY_SAVEFILE
1934 /* Verify savefile usage */
1939 /* Extract name of lock file */
1940 strcpy(temp, savefile);
1941 strcat(temp, ".lok");
1949 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1950 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);
1961 void remove_loc(void)
1963 #ifdef VERIFY_SAVEFILE
1965 #endif /* VERIFY_SAVEFILE */
1970 /* Get "games" permissions */
1973 # endif /* SECURE */
1974 #endif /* SET_UID */
1976 #ifdef VERIFY_SAVEFILE
1978 /* Lock on savefile */
1979 strcpy(temp, savefile);
1980 strcat(temp, ".lok");
1982 /* Remove lock file */
1985 #endif /* VERIFY_SAVEFILE */
1990 /* Drop "games" permissions */
1993 # endif /* SECURE */
1994 #endif /* SET_UID */
2000 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporary saved floor file
2001 * @param sf_ptr 保存フロア参照ポインタ
2004 static bool save_floor_aux(saved_floor_type *sf_ptr)
2008 /* Compact the objects */
2009 compact_objects(p_ptr->current_floor_ptr, 0);
2010 /* Compact the monsters */
2011 compact_monsters(0);
2014 /*** Actually write the file ***/
2016 /* Initial value of xor_byte */
2017 tmp8u = (byte)randint0(256);
2022 /* Reset the checksum */
2026 /* Write the sign of this process */
2027 wr_u32b(saved_floor_file_sign);
2029 /* Dump the dungeon floor */
2030 wr_saved_floor(sf_ptr);
2033 /* Write the "value check-sum" */
2036 /* Write the "encoded checksum" */
2041 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2043 /* Successful save */
2049 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporarily saved-floor data
2050 * @param sf_ptr 保存フロア参照ポインタ
2051 * @param mode 保存オプション
2054 bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
2056 FILE *old_fff = NULL;
2057 byte old_xor_byte = 0;
2058 u32b old_v_stamp = 0;
2059 u32b old_x_stamp = 0;
2061 char floor_savefile[1024];
2065 if (!(mode & SLF_SECOND))
2069 /* Get "games" permissions */
2075 /* We have one file already opened */
2078 /* Backup original values */
2080 old_xor_byte = xor_byte;
2081 old_v_stamp = v_stamp;
2082 old_x_stamp = x_stamp;
2086 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2088 /* Grab permissions */
2092 fd_kill(floor_savefile);
2094 /* Drop permissions */
2098 /* Attempt to save the player */
2103 /* File type is "SAVE" */
2104 FILE_TYPE(FILE_TYPE_SAVE);
2106 /* Grab permissions */
2109 /* Create the savefile */
2110 fd = fd_make(floor_savefile, 0644);
2112 /* Drop permissions */
2118 /* Close the "fd" */
2121 /* Grab permissions */
2124 /* Open the savefile */
2125 fff = my_fopen(floor_savefile, "wb");
2127 /* Drop permissions */
2130 /* Successful open */
2133 /* Write the savefile */
2134 if (save_floor_aux(sf_ptr)) ok = TRUE;
2136 /* Attempt to close it */
2137 if (my_fclose(fff)) ok = FALSE;
2140 /* Remove "broken" files */
2143 /* Grab permissions */
2146 (void)fd_kill(floor_savefile);
2148 /* Drop permissions */
2153 if (!(mode & SLF_SECOND))
2157 /* Drop "games" permissions */
2163 /* We have one file already opened */
2166 /* Restore original values */
2168 xor_byte = old_xor_byte;
2169 v_stamp = old_v_stamp;
2170 x_stamp = old_x_stamp;
2173 /* Return the result */