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.
23 #include "floor-events.h"
24 #include "floor-save.h"
30 * Some "local" parameters, used to help write savefiles
33 static FILE *fff; /* Current save "file" */
34 static byte xor_byte; /* Simple encryption */
35 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
36 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
41 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
45 static void sf_put(byte v)
47 /* Encode the value, write a character */
49 (void)putc((int)xor_byte, fff);
51 /* Maintain the checksum info */
57 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
61 static void wr_byte(byte v)
67 * @brief 符号なし16ビットをファイルに書き込む
68 * @param v 書き込む符号なし16bit値
71 static void wr_u16b(u16b v)
73 sf_put((byte)(v & 0xFF));
74 sf_put((byte)((v >> 8) & 0xFF));
78 * @brief 符号あり16ビットをファイルに書き込む
79 * @param v 書き込む符号あり16bit値
82 static void wr_s16b(s16b v)
88 * @brief 符号なし32ビットをファイルに書き込む
89 * @param v 書き込む符号なし32bit値
92 static void wr_u32b(u32b v)
94 sf_put((byte)(v & 0xFF));
95 sf_put((byte)((v >> 8) & 0xFF));
96 sf_put((byte)((v >> 16) & 0xFF));
97 sf_put((byte)((v >> 24) & 0xFF));
101 * @brief 符号あり32ビットをファイルに書き込む
102 * @param v 書き込む符号あり32bit値
105 static void wr_s32b(s32b v)
111 * @brief 文字列をファイルに書き込む
115 static void wr_string(concptr str)
127 * These functions write info in larger logical records
132 * @brief アイテムオブジェクトを書き込む / Write an "item" record
133 * @param o_ptr アイテムオブジェクト保存元ポインタ
136 static void wr_item(object_type *o_ptr)
138 BIT_FLAGS flags = 0x00000000;
140 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
141 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
142 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
143 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
144 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
145 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
146 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
147 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
148 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
149 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
150 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
151 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
152 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
153 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
154 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
155 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
156 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
157 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
158 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
159 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
160 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
161 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
162 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
163 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
164 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
165 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
166 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
167 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
168 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
170 /*** Item save flags ***/
173 /*** Write only un-obvious elements ***/
174 wr_s16b(o_ptr->k_idx);
176 wr_byte((byte_hack)o_ptr->iy);
177 wr_byte((byte_hack)o_ptr->ix);
179 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
181 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
182 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
184 wr_s16b((s16b)o_ptr->weight);
186 if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
187 if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
188 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
190 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
191 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
192 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
193 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
194 if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
195 if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
197 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
199 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
201 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
202 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
203 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
204 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
205 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
207 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
209 /* Held by monster index */
210 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
212 /* Extra information */
213 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
214 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
215 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
216 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
217 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
220 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
222 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
223 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
228 * @brief モンスター情報を書き込む / Write a "monster" record
229 * @param m_ptr モンスター情報保存元ポインタ
232 static void wr_monster(monster_type *m_ptr)
234 BIT_FLAGS flags = 0x00000000;
237 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
238 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
239 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
240 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
241 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
242 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
243 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
244 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
245 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
246 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
247 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
248 if (m_ptr->smart) flags |= SAVE_MON_SMART;
249 if (m_ptr->exp) flags |= SAVE_MON_EXP;
250 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
251 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
252 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
254 /*** Monster save flags ***/
257 /*** Write only un-obvious elements ***/
258 wr_s16b(m_ptr->r_idx);
259 wr_byte((byte_hack)m_ptr->fy);
260 wr_byte((byte_hack)m_ptr->fx);
261 wr_s16b((s16b)m_ptr->hp);
262 wr_s16b((s16b)m_ptr->maxhp);
263 wr_s16b((s16b)m_ptr->max_maxhp);
264 wr_u32b(m_ptr->dealt_damage);
267 /* Monster race index of its appearance */
268 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
270 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
271 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
273 wr_byte((byte)m_ptr->mspeed);
274 wr_s16b(m_ptr->energy_need);
276 if (flags & SAVE_MON_FAST)
278 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
281 if (flags & SAVE_MON_SLOW)
283 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
286 if (flags & SAVE_MON_STUNNED)
288 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
291 if (flags & SAVE_MON_CONFUSED)
293 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
296 if (flags & SAVE_MON_MONFEAR)
298 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
301 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
302 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
303 if (flags & SAVE_MON_INVULNER)
305 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
308 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
309 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
310 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
311 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
312 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
317 * @brief モンスターの思い出を書き込む / Write a "lore" record
318 * @param r_idx モンスター種族ID
321 static void wr_lore(MONRACE_IDX r_idx)
323 monster_race *r_ptr = &r_info[r_idx];
325 /* Count sights/deaths/kills */
326 wr_s16b((s16b)r_ptr->r_sights);
327 wr_s16b((s16b)r_ptr->r_deaths);
328 wr_s16b((s16b)r_ptr->r_pkills);
329 wr_s16b((s16b)r_ptr->r_akills);
330 wr_s16b((s16b)r_ptr->r_tkills);
332 /* Count wakes and ignores */
333 wr_byte(r_ptr->r_wake);
334 wr_byte(r_ptr->r_ignore);
337 wr_byte(r_ptr->r_xtra1);
338 wr_byte(r_ptr->r_xtra2);
341 wr_byte((byte_hack)r_ptr->r_drop_gold);
342 wr_byte((byte_hack)r_ptr->r_drop_item);
345 wr_byte(0); /* unused now */
346 wr_byte(r_ptr->r_cast_spell);
348 /* Count blows of each type */
349 wr_byte(r_ptr->r_blows[0]);
350 wr_byte(r_ptr->r_blows[1]);
351 wr_byte(r_ptr->r_blows[2]);
352 wr_byte(r_ptr->r_blows[3]);
355 wr_u32b(r_ptr->r_flags1);
356 wr_u32b(r_ptr->r_flags2);
357 wr_u32b(r_ptr->r_flags3);
358 wr_u32b(r_ptr->r_flags4);
359 wr_u32b(r_ptr->r_flags5);
360 wr_u32b(r_ptr->r_flags6);
361 wr_u32b(r_ptr->r_flagsr);
363 /* Monster limit per level */
364 wr_byte((byte_hack)r_ptr->max_num);
366 /* Location in saved floor */
367 wr_s16b(r_ptr->floor_id);
374 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
375 * @param k_idx ベースアイテムのID
378 static void wr_xtra(KIND_OBJECT_IDX k_idx)
382 object_kind *k_ptr = &k_info[k_idx];
384 if (k_ptr->aware) tmp8u |= 0x01;
385 if (k_ptr->tried) tmp8u |= 0x02;
392 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
393 * @param st_ptr 店舗情報の参照ポインタ
396 static void wr_store(store_type *st_ptr)
400 /* Save the "open" counter */
401 wr_u32b(st_ptr->store_open);
403 /* Save the "insults" */
404 wr_s16b(st_ptr->insult_cur);
406 /* Save the current owner */
407 wr_byte(st_ptr->owner);
409 /* Save the stock size */
410 wr_s16b(st_ptr->stock_num);
412 /* Save the "haggle" info */
413 wr_s16b(st_ptr->good_buy);
414 wr_s16b(st_ptr->bad_buy);
416 wr_s32b(st_ptr->last_visit);
419 for (j = 0; j < st_ptr->stock_num; j++)
421 /* Save each item in stock */
422 wr_item(&st_ptr->stock[j]);
428 * @brief セーブデータに乱数情報を書き込む / Write RNG state
431 static errr wr_randomizer(void)
437 for (i = 0; i < RAND_DEG; i++)
439 wr_u32b(Rand_state[i]);
447 * @brief ゲームオプション情報を書き込む / Write the "options"
450 static void wr_options(void)
459 for (i = 0; i < 4; i++) wr_u32b(0L);
462 /*** Special Options ***/
464 /* Write "delay_factor" */
465 wr_byte(delay_factor);
467 /* Write "hitpoint_warn" */
468 wr_byte(hitpoint_warn);
470 /* Write "mana_warn" */
473 /*** Cheating options ***/
477 if (p_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 ***/
500 /* Analyze the options */
501 for (i = 0; option_info[i].o_desc; i++)
503 int os = option_info[i].o_set;
504 int ob = option_info[i].o_bit;
506 /* Process real entries */
507 if (option_info[i].o_var)
510 if (*option_info[i].o_var)
513 option_flag[os] |= (1L << ob);
520 option_flag[os] &= ~(1L << ob);
526 /*** Normal options ***/
529 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
532 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
535 /*** Window options ***/
538 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
541 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
546 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
549 static void wr_ghost(void)
554 wr_string(_("不正なゴースト", "Broken Ghost"));
556 /* Hack -- stupid data */
557 for (i = 0; i < 60; i++) wr_byte(0);
562 * @brief クイック・スタート情報を書き込む / Save quick start data
565 static void save_quick_start(void)
569 wr_byte(previous_char.psex);
570 wr_byte((byte_hack)previous_char.prace);
571 wr_byte((byte_hack)previous_char.pclass);
572 wr_byte((byte_hack)previous_char.pseikaku);
573 wr_byte((byte_hack)previous_char.realm1);
574 wr_byte((byte_hack)previous_char.realm2);
576 wr_s16b(previous_char.age);
577 wr_s16b(previous_char.ht);
578 wr_s16b(previous_char.wt);
579 wr_s16b(previous_char.sc);
580 wr_s32b(previous_char.au);
582 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
583 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
585 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
587 wr_s16b(previous_char.chaos_patron);
589 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
591 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
593 /* UNUSED : Was number of random quests */
596 /* No quick start after using debug mode or cheat options */
597 if (p_ptr->noscore) previous_char.quick_ok = FALSE;
599 wr_byte((byte)previous_char.quick_ok);
604 * @brief その他の情報を書き込む / Write some "extra" info
607 static void wr_extra(void)
612 wr_string(p_ptr->name);
613 wr_string(p_ptr->died_from);
614 wr_string(p_ptr->last_message ? p_ptr->last_message : "");
618 for (i = 0; i < 4; i++)
620 wr_string(p_ptr->history[i]);
623 /* Race/Class/Gender/Spells */
624 wr_byte((byte_hack)p_ptr->prace);
625 wr_byte((byte_hack)p_ptr->pclass);
626 wr_byte((byte_hack)p_ptr->pseikaku);
627 wr_byte((byte_hack)p_ptr->psex);
628 wr_byte((byte_hack)p_ptr->realm1);
629 wr_byte((byte_hack)p_ptr->realm2);
632 wr_byte((byte)p_ptr->hitdie);
633 wr_u16b(p_ptr->expfact);
639 /* Dump the stats (maximum and current) */
640 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max[i]);
641 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max_max[i]);
642 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_cur[i]);
644 /* Ignore the transient stats */
645 for (i = 0; i < 12; ++i) wr_s16b(0);
649 wr_u32b(p_ptr->max_exp);
650 wr_u32b(p_ptr->max_max_exp);
652 wr_u32b(p_ptr->exp_frac);
655 for (i = 0; i < 64; i++) wr_s16b(p_ptr->spell_exp[i]);
656 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(p_ptr->weapon_exp[i][j]);
657 for (i = 0; i < GINOU_MAX; i++) wr_s16b(p_ptr->skill_exp[i]);
658 for (i = 0; i < 108; i++) wr_s32b(p_ptr->magic_num1[i]);
659 for (i = 0; i < 108; i++) wr_byte(p_ptr->magic_num2[i]);
661 wr_byte((byte_hack)p_ptr->start_race);
662 wr_s32b(p_ptr->old_race1);
663 wr_s32b(p_ptr->old_race2);
664 wr_s16b(p_ptr->old_realm);
666 for (i = 0; i < MAX_MANE; i++)
668 wr_s16b((s16b)p_ptr->mane_spell[i]);
669 wr_s16b((s16b)p_ptr->mane_dam[i]);
671 wr_s16b(p_ptr->mane_num);
673 for (i = 0; i < MAX_KUBI; i++)
675 wr_s16b(current_world_ptr->bounty_r_idx[i]);
678 for (i = 0; i < 4; i++)
680 wr_s16b(battle_mon[i]);
681 wr_u32b(mon_odds[i]);
684 wr_s16b(p_ptr->town_num); /* -KMW- */
686 /* Write arena and rewards information -KMW- */
687 wr_s16b(p_ptr->arena_number);
688 wr_s16b(p_ptr->inside_arena);
689 wr_s16b(p_ptr->inside_quest);
690 wr_s16b(p_ptr->inside_battle);
691 wr_byte(p_ptr->exit_bldg);
692 wr_byte(0); /* Unused */
694 wr_s16b((s16b)p_ptr->oldpx);
695 wr_s16b((s16b)p_ptr->oldpy);
697 /* Was number of p_ptr->rewards[] */
702 wr_u32b(p_ptr->chp_frac);
706 wr_u32b(p_ptr->csp_frac);
708 /* Max Player and Dungeon Levels */
709 wr_s16b(p_ptr->max_plv);
710 tmp8u = (byte)max_d_idx;
712 for (i = 0; i < tmp8u; i++)
713 wr_s16b((s16b)max_dlv[i]);
721 wr_s16b(p_ptr->concent);
723 wr_s16b(0); /* old "rest" */
724 wr_s16b(p_ptr->blind);
725 wr_s16b(p_ptr->paralyzed);
726 wr_s16b(p_ptr->confused);
727 wr_s16b(p_ptr->food);
728 wr_s16b(0); /* old "food_digested" */
729 wr_s16b(0); /* old "protection" */
730 wr_s16b(p_ptr->energy_need);
731 wr_s16b(p_ptr->enchant_energy_need);
732 wr_s16b(p_ptr->fast);
733 wr_s16b(p_ptr->slow);
734 wr_s16b(p_ptr->afraid);
736 wr_s16b(p_ptr->stun);
737 wr_s16b(p_ptr->poisoned);
738 wr_s16b(p_ptr->image);
739 wr_s16b(p_ptr->protevil);
740 wr_s16b(p_ptr->invuln);
741 wr_s16b(p_ptr->ult_res);
742 wr_s16b(p_ptr->hero);
743 wr_s16b(p_ptr->shero);
744 wr_s16b(p_ptr->shield);
745 wr_s16b(p_ptr->blessed);
746 wr_s16b(p_ptr->tim_invis);
747 wr_s16b(p_ptr->word_recall);
748 wr_s16b(p_ptr->recall_dungeon);
749 wr_s16b(p_ptr->alter_reality);
750 wr_s16b(p_ptr->see_infra);
751 wr_s16b(p_ptr->tim_infra);
752 wr_s16b(p_ptr->oppose_fire);
753 wr_s16b(p_ptr->oppose_cold);
754 wr_s16b(p_ptr->oppose_acid);
755 wr_s16b(p_ptr->oppose_elec);
756 wr_s16b(p_ptr->oppose_pois);
757 wr_s16b(p_ptr->tsuyoshi);
758 wr_s16b(p_ptr->tim_esp);
759 wr_s16b(p_ptr->wraith_form);
760 wr_s16b(p_ptr->resist_magic);
761 wr_s16b(p_ptr->tim_regen);
762 wr_s16b(p_ptr->kabenuke);
763 wr_s16b(p_ptr->tim_stealth);
764 wr_s16b(p_ptr->tim_levitation);
765 wr_s16b(p_ptr->tim_sh_touki);
766 wr_s16b(p_ptr->lightspeed);
767 wr_s16b(p_ptr->tsubureru);
768 wr_s16b(p_ptr->magicdef);
769 wr_s16b(p_ptr->tim_res_nether);
770 wr_s16b(p_ptr->tim_res_time);
771 wr_byte((byte)p_ptr->mimic_form);
772 wr_s16b(p_ptr->tim_mimic);
773 wr_s16b(p_ptr->tim_sh_fire);
774 wr_s16b(p_ptr->tim_sh_holy);
775 wr_s16b(p_ptr->tim_eyeeye);
778 wr_s16b(p_ptr->tim_reflect);
779 wr_s16b(p_ptr->multishadow);
780 wr_s16b(p_ptr->dustrobe);
782 wr_s16b(p_ptr->chaos_patron);
783 wr_u32b(p_ptr->muta1);
784 wr_u32b(p_ptr->muta2);
785 wr_u32b(p_ptr->muta3);
787 for (i = 0; i<8; i++)
788 wr_s16b(p_ptr->virtues[i]);
789 for (i = 0; i<8; i++)
790 wr_s16b(p_ptr->vir_types[i]);
792 wr_s16b(p_ptr->ele_attack);
793 wr_u32b(p_ptr->special_attack);
794 wr_s16b(p_ptr->ele_immune);
795 wr_u32b(p_ptr->special_defense);
796 wr_byte(p_ptr->knowledge);
797 wr_byte(p_ptr->autopick_autoregister);
799 wr_byte((byte_hack)p_ptr->action);
801 wr_byte(preserve_mode);
802 wr_byte(p_ptr->wait_report_score);
805 for (i = 0; i < 12; i++) wr_u32b(0L);
807 /* Ignore some flags */
813 /* Write the "object seeds" */
814 wr_u32b(seed_flavor);
819 wr_u16b(p_ptr->panic_save);
820 wr_u16b(p_ptr->total_winner);
821 wr_u16b(p_ptr->noscore);
825 wr_byte(p_ptr->is_dead);
828 wr_byte(p_ptr->feeling);
830 /* Turn when level began */
831 wr_s32b(current_floor_ptr->generated_turn);
833 /* Turn of last "feeling" */
834 wr_s32b(p_ptr->feeling_turn);
836 /* Current current_world_ptr->game_turn */
837 wr_s32b(current_world_ptr->game_turn);
839 wr_s32b(current_world_ptr->dungeon_turn);
844 wr_s16b(p_ptr->today_mon);
845 wr_s16b(p_ptr->riding);
847 /* Current floor_id */
848 wr_s16b(p_ptr->floor_id);
850 /* Save temporary preserved pets (obsolated) */
853 wr_u32b(current_world_ptr->play_time);
855 wr_s32b(p_ptr->visit);
857 wr_u32b(p_ptr->count);
862 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
863 * @param sf_ptr 保存したいフロアの参照ポインタ
866 static void wr_saved_floor(saved_floor_type *sf_ptr)
868 cave_template_type *templates;
883 /* Dungeon floor specific info follows */
887 /*** Not a saved floor ***/
889 wr_s16b((s16b)current_floor_ptr->dun_level);
893 /*** The saved floor ***/
895 wr_s16b(sf_ptr->floor_id);
896 wr_byte((byte_hack)sf_ptr->savefile_id);
897 wr_s16b((s16b)sf_ptr->dun_level);
898 wr_s32b(sf_ptr->last_visit);
899 wr_u32b(sf_ptr->visit_mark);
900 wr_s16b(sf_ptr->upper_floor_id);
901 wr_s16b(sf_ptr->lower_floor_id);
904 wr_u16b((u16b)current_floor_ptr->base_level);
905 wr_u16b((s16b)current_floor_ptr->num_repro);
906 wr_u16b((u16b)p_ptr->y);
907 wr_u16b((u16b)p_ptr->x);
908 wr_u16b((u16b)current_floor_ptr->height);
909 wr_u16b((u16b)current_floor_ptr->width);
910 wr_byte(p_ptr->feeling);
914 /*********** Make template for grid_type **********/
917 * Usually number of templates are fewer than 255. Even if
918 * more than 254 are exist, the occurrence of each template
919 * with larger ID is very small when we sort templates by
920 * occurrence. So we will use two (or more) bytes for
921 * templete ID larger than 254.
923 * Ex: 256 will be "0xff" "0x01".
924 * 515 will be "0xff" "0xff" "0x03"
927 /* Fake max number */
930 /* Allocate the "template" array */
931 C_MAKE(templates, max_num_temp, cave_template_type);
933 /* Extract template array */
934 for (y = 0; y < current_floor_ptr->height; y++)
936 for (x = 0; x < current_floor_ptr->width; x++)
938 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
940 for (i = 0; i < num_temp; i++)
942 if (templates[i].info == g_ptr->info &&
943 templates[i].feat == g_ptr->feat &&
944 templates[i].mimic == g_ptr->mimic &&
945 templates[i].special == g_ptr->special)
947 /* Same terrain is exist */
948 templates[i].occurrence++;
953 /* Are there same one? */
954 if (i < num_temp) continue;
956 /* If the max_num_temp is too small, increase it. */
957 if (num_temp >= max_num_temp)
959 cave_template_type *old_template = templates;
961 /* Re-allocate the "template" array */
962 C_MAKE(templates, max_num_temp + 255, cave_template_type);
963 (void)C_COPY(templates, old_template, max_num_temp, cave_template_type);
964 C_KILL(old_template, max_num_temp, cave_template_type);
968 /* Add new template */
969 templates[num_temp].info = g_ptr->info;
970 templates[num_temp].feat = g_ptr->feat;
971 templates[num_temp].mimic = g_ptr->mimic;
972 templates[num_temp].special = g_ptr->special;
973 templates[num_temp].occurrence = 1;
975 /* Increase number of template */
980 /* Sort by occurrence */
981 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
983 /*** Dump templates ***/
985 /* Total templates */
988 /* Dump the templates */
989 for (i = 0; i < num_temp; i++)
991 cave_template_type *ct_ptr = &templates[i];
994 wr_u16b((u16b)ct_ptr->info);
995 wr_s16b(ct_ptr->feat);
996 wr_s16b(ct_ptr->mimic);
997 wr_s16b(ct_ptr->special);
1002 /*** "Run-Length-Encoding" of current_floor_ptr->grid_array ***/
1004 /* Note that this will induce two wasted bytes */
1008 /* Dump the current_floor_ptr->grid_array */
1009 for (y = 0; y < current_floor_ptr->height; y++)
1011 for (x = 0; x < current_floor_ptr->width; x++)
1013 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1015 for (i = 0; i < num_temp; i++)
1017 if (templates[i].info == g_ptr->info &&
1018 templates[i].feat == g_ptr->feat &&
1019 templates[i].mimic == g_ptr->mimic &&
1020 templates[i].special == g_ptr->special)
1027 /* If the run is broken, or too full, flush it */
1028 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
1030 wr_byte((byte)count);
1032 while (prev_u16b >= MAX_UCHAR)
1034 /* Mark as actual data is larger than 254 */
1036 prev_u16b -= MAX_UCHAR;
1039 wr_byte((byte)prev_u16b);
1044 /* Continue the run */
1052 /* Flush the data (if any) */
1055 wr_byte((byte)count);
1057 while (prev_u16b >= MAX_UCHAR)
1059 /* Mark as actual data is larger than 254 */
1061 prev_u16b -= MAX_UCHAR;
1063 wr_byte((byte)prev_u16b);
1067 /* Free the "template" array */
1068 C_KILL(templates, max_num_temp, cave_template_type);
1071 /*** Dump objects ***/
1076 /* Dump the objects */
1077 for (i = 1; i < o_max; i++)
1079 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
1086 /*** Dump the monsters ***/
1088 /* Total monsters */
1091 /* Dump the monsters */
1092 for (i = 1; i < m_max; i++)
1094 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1103 * @brief 現在フロアの書き込み /
1104 * Write the current dungeon (new method)
1107 static bool wr_dungeon(void)
1109 saved_floor_type *cur_sf_ptr;
1116 /* Update lite/view */
1117 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1118 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1122 /* Number of floor_id used from birth */
1123 wr_s16b(max_floor_id);
1125 /* Current dungeon type */
1126 wr_byte((byte_hack)p_ptr->dungeon_idx);
1129 /*** No saved floor (On the surface etc.) ***/
1130 if (!p_ptr->floor_id)
1132 /* No array elements */
1135 /* Write the current floor data */
1136 wr_saved_floor(NULL);
1143 /*** In the dungeon ***/
1145 /* Number of array elements */
1146 wr_byte(MAX_SAVED_FLOORS);
1148 /* Write the saved_floors array */
1149 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1151 saved_floor_type *sf_ptr = &saved_floors[i];
1153 wr_s16b(sf_ptr->floor_id);
1154 wr_byte((byte_hack)sf_ptr->savefile_id);
1155 wr_s16b((s16b)sf_ptr->dun_level);
1156 wr_s32b(sf_ptr->last_visit);
1157 wr_u32b(sf_ptr->visit_mark);
1158 wr_s16b(sf_ptr->upper_floor_id);
1159 wr_s16b(sf_ptr->lower_floor_id);
1162 /* Extract pointer to current floor */
1163 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1165 /* Save current floor to temporal file */
1166 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1168 /* Move data in temporal files to the savefile */
1169 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1171 saved_floor_type *sf_ptr = &saved_floors[i];
1173 /* Unused element */
1174 if (!sf_ptr->floor_id) continue;
1176 /* Load temporal saved floor file */
1177 if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1182 /* Write saved floor data to the save file */
1183 wr_saved_floor(sf_ptr);
1192 /* Restore current floor */
1193 if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1201 * @brief セーブデータの書き込み /
1202 * Actually write a save-file
1205 static bool wr_savefile_new(void)
1216 KIND_OBJECT_IDX k_idx;
1218 /* Compact the objects */
1220 /* Compact the monsters */
1221 compact_monsters(0);
1223 /* Guess at the current time */
1224 now = (u32b)time((time_t *)0);
1227 /* Note the operating system */
1230 /* Note when the file was saved */
1233 /* Note the number of saves */
1237 /*** Actually write the file ***/
1239 /* Dump the file header */
1241 wr_byte(FAKE_VER_MAJOR);
1243 wr_byte(FAKE_VER_MINOR);
1245 wr_byte(FAKE_VER_PATCH);
1248 /* Initial value of xor_byte */
1249 tmp8u = (byte)Rand_external(256);
1253 /* Reset the checksum */
1257 /* Write the savefile version for Hengband 1.1.1 and later */
1258 wr_byte(H_VER_EXTRA);
1259 wr_byte(H_VER_PATCH);
1260 wr_byte(H_VER_MINOR);
1261 wr_byte(H_VER_MAJOR);
1263 /* Operating system */
1267 /* Time file last saved */
1270 /* Number of past lives */
1273 /* Number of times saved */
1284 /* EUC kanji code */
1288 /* SJIS kanji code */
1296 /* Write the RNG state */
1300 /* Write the boolean "options" */
1304 /* Dump the number of "messages" */
1305 tmp32u = message_num();
1306 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1309 /* Dump the messages (oldest first!) */
1310 for (i = tmp32u - 1; i >= 0; i--)
1312 wr_string(message_str((s16b)i));
1315 /* Dump the monster lore */
1318 for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
1320 /* Dump the object memory */
1323 for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
1325 /* Dump the towns */
1329 /* Dump the quests */
1333 /* Dump the quests */
1334 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1337 for (i = 0; i < max_q_idx; i++)
1339 quest_type* const q_ptr = &quest[i];
1341 /* Save status for every quest */
1342 wr_s16b(q_ptr->status);
1344 /* And the dungeon level too */
1345 /* (prevents problems with multi-level quests) */
1346 wr_s16b((s16b)q_ptr->level);
1348 wr_byte((byte_hack)q_ptr->complev);
1349 wr_u32b(q_ptr->comptime);
1351 /* Save quest status if quest is running */
1352 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1354 wr_s16b((s16b)q_ptr->cur_num);
1355 wr_s16b((s16b)q_ptr->max_num);
1356 wr_s16b(q_ptr->type);
1357 wr_s16b(q_ptr->r_idx);
1358 wr_s16b(q_ptr->k_idx);
1359 wr_byte((byte_hack)q_ptr->flags);
1360 wr_byte((byte_hack)q_ptr->dungeon);
1364 /* Dump the position in the wilderness */
1365 wr_s32b(p_ptr->wilderness_x);
1366 wr_s32b(p_ptr->wilderness_y);
1368 wr_byte(p_ptr->wild_mode);
1369 wr_byte(p_ptr->ambush_flag);
1371 wr_s32b(current_world_ptr->max_wild_x);
1372 wr_s32b(current_world_ptr->max_wild_y);
1374 /* Dump the wilderness seeds */
1375 for (i = 0; i < current_world_ptr->max_wild_x; i++)
1377 for (j = 0; j < current_world_ptr->max_wild_y; j++)
1379 wr_u32b(wilderness[j][i].seed);
1383 /* Hack -- Dump the artifacts */
1386 for (i = 0; i < tmp16u; i++)
1388 artifact_type *a_ptr = &a_info[i];
1389 wr_byte(a_ptr->cur_num);
1390 wr_s16b(a_ptr->floor_id);
1395 /* Write the "extra" information */
1398 /* Dump the "player hp" entries */
1399 tmp16u = PY_MAX_LEVEL;
1401 for (i = 0; i < tmp16u; i++)
1403 wr_s16b((s16b)p_ptr->player_hp[i]);
1407 /* Write spell data */
1408 wr_u32b(p_ptr->spell_learned1);
1409 wr_u32b(p_ptr->spell_learned2);
1410 wr_u32b(p_ptr->spell_worked1);
1411 wr_u32b(p_ptr->spell_worked2);
1412 wr_u32b(p_ptr->spell_forgotten1);
1413 wr_u32b(p_ptr->spell_forgotten2);
1415 wr_s16b(p_ptr->learned_spells);
1416 wr_s16b(p_ptr->add_spells);
1418 /* Dump the ordered spells */
1419 for (i = 0; i < 64; i++)
1421 wr_byte((byte_hack)p_ptr->spell_order[i]);
1425 /* Write the p_ptr->inventory_list */
1426 for (i = 0; i < INVEN_TOTAL; i++)
1428 object_type *o_ptr = &p_ptr->inventory_list[i];
1429 if (!o_ptr->k_idx) continue;
1438 /* Add a sentinel */
1441 /* Note the towns */
1445 /* Note the stores */
1446 tmp16u = MAX_STORES;
1449 /* Dump the stores of all towns */
1450 for (i = 1; i < max_towns; i++)
1452 for (j = 0; j < MAX_STORES; j++)
1454 wr_store(&town_info[i].store[j]);
1458 /* Write the pet command settings */
1459 wr_s16b(p_ptr->pet_follow_distance);
1460 wr_s16b(p_ptr->pet_extra_flags);
1462 /* Write screen dump for sending score */
1463 if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead))
1465 wr_string(screen_dump);
1472 /* Player is not dead, write the dungeon */
1473 if (!p_ptr->is_dead)
1475 /* Dump the dungeon */
1476 if (!wr_dungeon()) return FALSE;
1478 /* Dump the ghost */
1486 /* Write the "value check-sum" */
1489 /* Write the "encoded checksum" */
1494 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1496 /* Successful save */
1502 * @brief セーブデータ書き込みのサブルーチン /
1503 * Medium level player saver
1506 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1508 static bool save_player_aux(char *name)
1517 /* File type is "SAVE" */
1518 FILE_TYPE(FILE_TYPE_SAVE);
1520 /* Grab permissions */
1523 /* Create the savefile */
1524 fd = fd_make(name, mode);
1526 /* Drop permissions */
1532 /* Close the "fd" */
1535 /* Grab permissions */
1538 /* Open the savefile */
1539 fff = my_fopen(name, "wb");
1541 /* Drop permissions */
1544 /* Successful open */
1547 /* Write the savefile */
1548 if (wr_savefile_new()) ok = TRUE;
1550 /* Attempt to close it */
1551 if (my_fclose(fff)) ok = FALSE;
1554 /* Grab permissions */
1557 /* Remove "broken" files */
1558 if (!ok) (void)fd_kill(name);
1560 /* Drop permissions */
1566 if (!ok) return (FALSE);
1568 counts_write(0, current_world_ptr->play_time);
1570 /* Successful save */
1571 character_saved = TRUE;
1580 * @brief セーブデータ書き込みのメインルーチン /
1581 * Attempt to save the player in a savefile
1584 bool save_player(void)
1586 bool result = FALSE;
1595 /* Get "games" permissions */
1604 strcpy(safe, savefile);
1605 strcat(safe, ".new");
1607 /* Grab permissions */
1613 /* Drop permissions */
1618 /* Attempt to save the player */
1619 if (save_player_aux(safe))
1624 strcpy(temp, savefile);
1625 strcat(temp, ".old");
1627 /* Grab permissions */
1633 /* Preserve old savefile */
1634 fd_move(savefile, temp);
1636 /* Activate new savefile */
1637 fd_move(safe, savefile);
1639 /* Remove preserved savefile */
1642 /* Drop permissions */
1645 /* Hack -- Pretend the character was loaded */
1646 character_loaded = TRUE;
1648 #ifdef VERIFY_SAVEFILE
1650 /* Lock on savefile */
1651 strcpy(temp, savefile);
1652 strcat(temp, ".lok");
1654 /* Grab permissions */
1657 /* Remove lock file */
1660 /* Drop permissions */
1674 /* Drop "games" permissions */
1681 /* Return the result */
1687 * @brief セーブデータ読み込みのメインルーチン /
1688 * Attempt to Load a "savefile"
1692 * Version 2.7.0 introduced a slightly different "savefile" format from
1693 * older versions, requiring a completely different parsing method.
1695 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1697 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1699 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1701 * On multi-user systems, you may only "read" a savefile if you will be
1702 * allowed to "write" it later, this prevents painful situations in which
1703 * the player loads a savefile belonging to someone else, and then is not
1704 * allowed to save his game when he quits.
1706 * We return "TRUE" if the savefile was usable, and we set the global
1707 * flag "character_loaded" if a real, living, character was loaded.
1709 * Note that we always try to load the "current" savefile, even if
1710 * there is no such file, so we must check for "empty" savefile names.
1713 bool load_player(void)
1721 #ifdef VERIFY_TIMESTAMP
1722 struct stat statbuf;
1725 concptr what = "generic";
1727 current_world_ptr->game_turn = 0;
1728 p_ptr->is_dead = FALSE;
1731 /* Allow empty savefile name */
1732 if (!savefile[0]) return (TRUE);
1735 #if !defined(MACINTOSH) && !defined(WINDOWS)
1739 /* Verify the existance of the savefile */
1740 if (access(savefile, 0) < 0)
1742 /* Give a message */
1743 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1754 #ifdef VERIFY_SAVEFILE
1756 /* Verify savefile usage */
1763 /* Extract name of lock file */
1764 strcpy(temp, savefile);
1765 strcat(temp, ".lok");
1767 /* Check for lock */
1768 fkk = my_fopen(temp, "r");
1770 /* Oops, lock exists */
1775 msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
1781 /* Create a lock file */
1782 fkk = my_fopen(temp, "w");
1784 /* Dump a line of info */
1785 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1787 /* Close the lock file */
1796 /* Open the savefile */
1797 fd = fd_open(savefile, O_RDONLY);
1800 if (fd < 0) err = -1;
1802 /* Message (below) */
1803 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1810 #ifdef VERIFY_TIMESTAMP
1811 /* Get the timestamp */
1812 (void)fstat(fd, &statbuf);
1815 /* Read the first four bytes */
1816 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1819 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1827 /* Extract version */
1835 /* Attempt to load */
1836 err = rd_savefile_new();
1838 /* Message (below) */
1839 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1843 /* Invalid current_world_ptr->game_turn */
1844 if (!current_world_ptr->game_turn) err = -1;
1846 /* Message (below) */
1847 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1850 #ifdef VERIFY_TIMESTAMP
1851 /* Verify timestamp */
1852 if (!err && !arg_wizard)
1854 /* Hack -- Verify the timestamp */
1855 if (sf_when > (statbuf.st_ctime + 100) ||
1856 sf_when < (statbuf.st_ctime - 100))
1858 what = _("無効なタイム・スタンプです", "Invalid timestamp");
1868 /* Give a conversion warning */
1869 if ((FAKE_VER_MAJOR != z_major) ||
1870 (FAKE_VER_MINOR != z_minor) ||
1871 (FAKE_VER_PATCH != z_patch))
1873 if (z_major == 2 && z_minor == 0 && z_patch == 6)
1875 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1879 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1880 (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
1885 /* Player is dead */
1891 /* A character was loaded */
1892 character_loaded = TRUE;
1896 /* Player is no longer "dead" */
1897 p_ptr->is_dead = FALSE;
1905 /* A character was loaded */
1906 character_loaded = TRUE;
1909 u32b tmp = counts_read(2);
1910 if (tmp > p_ptr->count)
1912 if (counts_read(0) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
1913 counts_write(2, ++p_ptr->count);
1914 counts_write(1, current_world_ptr->play_time);
1922 #ifdef VERIFY_SAVEFILE
1924 /* Verify savefile usage */
1929 /* Extract name of lock file */
1930 strcpy(temp, savefile);
1931 strcat(temp, ".lok");
1939 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1940 what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
1951 void remove_loc(void)
1953 #ifdef VERIFY_SAVEFILE
1955 #endif /* VERIFY_SAVEFILE */
1960 /* Get "games" permissions */
1963 # endif /* SECURE */
1964 #endif /* SET_UID */
1966 #ifdef VERIFY_SAVEFILE
1968 /* Lock on savefile */
1969 strcpy(temp, savefile);
1970 strcat(temp, ".lok");
1972 /* Remove lock file */
1975 #endif /* VERIFY_SAVEFILE */
1980 /* Drop "games" permissions */
1983 # endif /* SECURE */
1984 #endif /* SET_UID */
1990 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporal saved floor file
1991 * @param sf_ptr 保存フロア参照ポインタ
1994 static bool save_floor_aux(saved_floor_type *sf_ptr)
1998 /* Compact the objects */
2000 /* Compact the monsters */
2001 compact_monsters(0);
2004 /*** Actually write the file ***/
2006 /* Initial value of xor_byte */
2007 tmp8u = (byte)randint0(256);
2012 /* Reset the checksum */
2016 /* Write the sign of this process */
2017 wr_u32b(saved_floor_file_sign);
2019 /* Dump the dungeon floor */
2020 wr_saved_floor(sf_ptr);
2023 /* Write the "value check-sum" */
2026 /* Write the "encoded checksum" */
2031 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2033 /* Successful save */
2039 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data
2040 * @param sf_ptr 保存フロア参照ポインタ
2041 * @param mode 保存オプション
2044 bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
2046 FILE *old_fff = NULL;
2047 byte old_xor_byte = 0;
2048 u32b old_v_stamp = 0;
2049 u32b old_x_stamp = 0;
2051 char floor_savefile[1024];
2055 if (!(mode & SLF_SECOND))
2059 /* Get "games" permissions */
2065 /* We have one file already opened */
2068 /* Backup original values */
2070 old_xor_byte = xor_byte;
2071 old_v_stamp = v_stamp;
2072 old_x_stamp = x_stamp;
2076 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2078 /* Grab permissions */
2082 fd_kill(floor_savefile);
2084 /* Drop permissions */
2088 /* Attempt to save the player */
2093 /* File type is "SAVE" */
2094 FILE_TYPE(FILE_TYPE_SAVE);
2096 /* Grab permissions */
2099 /* Create the savefile */
2100 fd = fd_make(floor_savefile, 0644);
2102 /* Drop permissions */
2108 /* Close the "fd" */
2111 /* Grab permissions */
2114 /* Open the savefile */
2115 fff = my_fopen(floor_savefile, "wb");
2117 /* Drop permissions */
2120 /* Successful open */
2123 /* Write the savefile */
2124 if (save_floor_aux(sf_ptr)) ok = TRUE;
2126 /* Attempt to close it */
2127 if (my_fclose(fff)) ok = FALSE;
2130 /* Remove "broken" files */
2133 /* Grab permissions */
2136 (void)fd_kill(floor_savefile);
2138 /* Drop permissions */
2143 if (!(mode & SLF_SECOND))
2147 /* Drop "games" permissions */
2153 /* We have one file already opened */
2156 /* Restore original values */
2158 xor_byte = old_xor_byte;
2159 v_stamp = old_v_stamp;
2160 x_stamp = old_x_stamp;
2163 /* Return the result */