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.
19 #include "floor-events.h"
20 #include "floor-save.h"
26 * Some "local" parameters, used to help write savefiles
29 static FILE *fff; /* Current save "file" */
30 static byte xor_byte; /* Simple encryption */
31 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
32 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
37 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
41 static void sf_put(byte v)
43 /* Encode the value, write a character */
45 (void)putc((int)xor_byte, fff);
47 /* Maintain the checksum info */
53 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
57 static void wr_byte(byte v)
63 * @brief 符号なし16ビットをファイルに書き込む
64 * @param v 書き込む符号なし16bit値
67 static void wr_u16b(u16b v)
69 sf_put((byte)(v & 0xFF));
70 sf_put((byte)((v >> 8) & 0xFF));
74 * @brief 符号あり16ビットをファイルに書き込む
75 * @param v 書き込む符号あり16bit値
78 static void wr_s16b(s16b v)
84 * @brief 符号なし32ビットをファイルに書き込む
85 * @param v 書き込む符号なし32bit値
88 static void wr_u32b(u32b v)
90 sf_put((byte)(v & 0xFF));
91 sf_put((byte)((v >> 8) & 0xFF));
92 sf_put((byte)((v >> 16) & 0xFF));
93 sf_put((byte)((v >> 24) & 0xFF));
97 * @brief 符号あり32ビットをファイルに書き込む
98 * @param v 書き込む符号あり32bit値
101 static void wr_s32b(s32b v)
107 * @brief 文字列をファイルに書き込む
111 static void wr_string(concptr str)
123 * These functions write info in larger logical records
128 * @brief アイテムオブジェクトを書き込む / Write an "item" record
129 * @param o_ptr アイテムオブジェクト保存元ポインタ
132 static void wr_item(object_type *o_ptr)
134 BIT_FLAGS flags = 0x00000000;
136 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
137 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
138 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
139 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
140 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
141 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
142 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
143 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
144 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
145 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
146 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
147 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
148 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
149 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
150 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
151 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
152 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
153 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
154 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
155 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
156 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
157 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
158 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
159 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
160 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
161 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
162 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
163 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
164 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
166 /*** Item save flags ***/
169 /*** Write only un-obvious elements ***/
170 wr_s16b(o_ptr->k_idx);
172 wr_byte((byte_hack)o_ptr->iy);
173 wr_byte((byte_hack)o_ptr->ix);
175 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
177 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
178 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
180 wr_s16b((s16b)o_ptr->weight);
182 if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
183 if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
184 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
186 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
187 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
188 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
189 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
190 if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
191 if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
193 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
195 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
197 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
198 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
199 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
200 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
201 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
203 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
205 /* Held by monster index */
206 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
208 /* Extra information */
209 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
210 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
211 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
212 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
213 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
216 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
218 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
219 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
224 * @brief モンスター情報を書き込む / Write a "monster" record
225 * @param m_ptr モンスター情報保存元ポインタ
228 static void wr_monster(monster_type *m_ptr)
230 BIT_FLAGS flags = 0x00000000;
233 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
234 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
235 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
236 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
237 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
238 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
239 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
240 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
241 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
242 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
243 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
244 if (m_ptr->smart) flags |= SAVE_MON_SMART;
245 if (m_ptr->exp) flags |= SAVE_MON_EXP;
246 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
247 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
248 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
250 /*** Monster save flags ***/
253 /*** Write only un-obvious elements ***/
254 wr_s16b(m_ptr->r_idx);
255 wr_byte((byte_hack)m_ptr->fy);
256 wr_byte((byte_hack)m_ptr->fx);
257 wr_s16b((s16b)m_ptr->hp);
258 wr_s16b((s16b)m_ptr->maxhp);
259 wr_s16b((s16b)m_ptr->max_maxhp);
260 wr_u32b(m_ptr->dealt_damage);
263 /* Monster race index of its appearance */
264 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
266 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
267 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
269 wr_byte((byte)m_ptr->mspeed);
270 wr_s16b(m_ptr->energy_need);
272 if (flags & SAVE_MON_FAST)
274 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
277 if (flags & SAVE_MON_SLOW)
279 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
282 if (flags & SAVE_MON_STUNNED)
284 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
287 if (flags & SAVE_MON_CONFUSED)
289 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
292 if (flags & SAVE_MON_MONFEAR)
294 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
297 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
298 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
299 if (flags & SAVE_MON_INVULNER)
301 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
304 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
305 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
306 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
307 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
308 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
313 * @brief モンスターの思い出を書き込む / Write a "lore" record
314 * @param r_idx モンスター種族ID
317 static void wr_lore(MONRACE_IDX r_idx)
319 monster_race *r_ptr = &r_info[r_idx];
321 /* Count sights/deaths/kills */
322 wr_s16b((s16b)r_ptr->r_sights);
323 wr_s16b((s16b)r_ptr->r_deaths);
324 wr_s16b((s16b)r_ptr->r_pkills);
325 wr_s16b((s16b)r_ptr->r_akills);
326 wr_s16b((s16b)r_ptr->r_tkills);
328 /* Count wakes and ignores */
329 wr_byte(r_ptr->r_wake);
330 wr_byte(r_ptr->r_ignore);
333 wr_byte(r_ptr->r_xtra1);
334 wr_byte(r_ptr->r_xtra2);
337 wr_byte((byte_hack)r_ptr->r_drop_gold);
338 wr_byte((byte_hack)r_ptr->r_drop_item);
341 wr_byte(0); /* unused now */
342 wr_byte(r_ptr->r_cast_spell);
344 /* Count blows of each type */
345 wr_byte(r_ptr->r_blows[0]);
346 wr_byte(r_ptr->r_blows[1]);
347 wr_byte(r_ptr->r_blows[2]);
348 wr_byte(r_ptr->r_blows[3]);
351 wr_u32b(r_ptr->r_flags1);
352 wr_u32b(r_ptr->r_flags2);
353 wr_u32b(r_ptr->r_flags3);
354 wr_u32b(r_ptr->r_flags4);
355 wr_u32b(r_ptr->r_flags5);
356 wr_u32b(r_ptr->r_flags6);
357 wr_u32b(r_ptr->r_flagsr);
359 /* Monster limit per level */
360 wr_byte((byte_hack)r_ptr->max_num);
362 /* Location in saved floor */
363 wr_s16b(r_ptr->floor_id);
370 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
371 * @param k_idx ベースアイテムのID
374 static void wr_xtra(KIND_OBJECT_IDX k_idx)
378 object_kind *k_ptr = &k_info[k_idx];
380 if (k_ptr->aware) tmp8u |= 0x01;
381 if (k_ptr->tried) tmp8u |= 0x02;
388 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
389 * @param st_ptr 店舗情報の参照ポインタ
392 static void wr_store(store_type *st_ptr)
396 /* Save the "open" counter */
397 wr_u32b(st_ptr->store_open);
399 /* Save the "insults" */
400 wr_s16b(st_ptr->insult_cur);
402 /* Save the current owner */
403 wr_byte(st_ptr->owner);
405 /* Save the stock size */
406 wr_s16b(st_ptr->stock_num);
408 /* Save the "haggle" info */
409 wr_s16b(st_ptr->good_buy);
410 wr_s16b(st_ptr->bad_buy);
412 wr_s32b(st_ptr->last_visit);
415 for (j = 0; j < st_ptr->stock_num; j++)
417 /* Save each item in stock */
418 wr_item(&st_ptr->stock[j]);
424 * @brief セーブデータに乱数情報を書き込む / Write RNG state
427 static errr wr_randomizer(void)
433 for (i = 0; i < RAND_DEG; i++)
435 wr_u32b(Rand_state[i]);
443 * @brief ゲームオプション情報を書き込む / Write the "options"
446 static void wr_options(void)
455 for (i = 0; i < 4; i++) wr_u32b(0L);
458 /*** Special Options ***/
460 /* Write "delay_factor" */
461 wr_byte(delay_factor);
463 /* Write "hitpoint_warn" */
464 wr_byte(hitpoint_warn);
466 /* Write "mana_warn" */
469 /*** Cheating options ***/
473 if (p_ptr->wizard) c |= 0x0002;
475 if (cheat_sight) c |= 0x0040;
476 if (cheat_turn) c |= 0x0080;
478 if (cheat_peek) c |= 0x0100;
479 if (cheat_hear) c |= 0x0200;
480 if (cheat_room) c |= 0x0400;
481 if (cheat_xtra) c |= 0x0800;
482 if (cheat_know) c |= 0x1000;
483 if (cheat_live) c |= 0x2000;
484 if (cheat_save) c |= 0x4000;
485 if (cheat_diary_output) c |= 0x8000;
492 wr_s16b(autosave_freq);
494 /*** Extract options ***/
496 /* Analyze the options */
497 for (i = 0; option_info[i].o_desc; i++)
499 int os = option_info[i].o_set;
500 int ob = option_info[i].o_bit;
502 /* Process real entries */
503 if (option_info[i].o_var)
506 if (*option_info[i].o_var)
509 option_flag[os] |= (1L << ob);
516 option_flag[os] &= ~(1L << ob);
522 /*** Normal options ***/
525 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
528 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
531 /*** Window options ***/
534 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
537 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
542 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
545 static void wr_ghost(void)
550 wr_string(_("不正なゴースト", "Broken Ghost"));
552 /* Hack -- stupid data */
553 for (i = 0; i < 60; i++) wr_byte(0);
558 * @brief クイック・スタート情報を書き込む / Save quick start data
561 static void save_quick_start(void)
565 wr_byte(previous_char.psex);
566 wr_byte((byte_hack)previous_char.prace);
567 wr_byte((byte_hack)previous_char.pclass);
568 wr_byte((byte_hack)previous_char.pseikaku);
569 wr_byte((byte_hack)previous_char.realm1);
570 wr_byte((byte_hack)previous_char.realm2);
572 wr_s16b(previous_char.age);
573 wr_s16b(previous_char.ht);
574 wr_s16b(previous_char.wt);
575 wr_s16b(previous_char.sc);
576 wr_s32b(previous_char.au);
578 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
579 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
581 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
583 wr_s16b(previous_char.chaos_patron);
585 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
587 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
589 /* UNUSED : Was number of random quests */
592 /* No quick start after using debug mode or cheat options */
593 if (p_ptr->noscore) previous_char.quick_ok = FALSE;
595 wr_byte((byte)previous_char.quick_ok);
600 * @brief その他の情報を書き込む / Write some "extra" info
603 static void wr_extra(void)
608 wr_string(p_ptr->name);
609 wr_string(p_ptr->died_from);
610 wr_string(p_ptr->last_message ? p_ptr->last_message : "");
614 for (i = 0; i < 4; i++)
616 wr_string(p_ptr->history[i]);
619 /* Race/Class/Gender/Spells */
620 wr_byte((byte_hack)p_ptr->prace);
621 wr_byte((byte_hack)p_ptr->pclass);
622 wr_byte((byte_hack)p_ptr->pseikaku);
623 wr_byte((byte_hack)p_ptr->psex);
624 wr_byte((byte_hack)p_ptr->realm1);
625 wr_byte((byte_hack)p_ptr->realm2);
628 wr_byte((byte)p_ptr->hitdie);
629 wr_u16b(p_ptr->expfact);
635 /* Dump the stats (maximum and current) */
636 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max[i]);
637 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max_max[i]);
638 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_cur[i]);
640 /* Ignore the transient stats */
641 for (i = 0; i < 12; ++i) wr_s16b(0);
645 wr_u32b(p_ptr->max_exp);
646 wr_u32b(p_ptr->max_max_exp);
648 wr_u32b(p_ptr->exp_frac);
651 for (i = 0; i < 64; i++) wr_s16b(p_ptr->spell_exp[i]);
652 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(p_ptr->weapon_exp[i][j]);
653 for (i = 0; i < GINOU_MAX; i++) wr_s16b(p_ptr->skill_exp[i]);
654 for (i = 0; i < 108; i++) wr_s32b(p_ptr->magic_num1[i]);
655 for (i = 0; i < 108; i++) wr_byte(p_ptr->magic_num2[i]);
657 wr_byte((byte_hack)p_ptr->start_race);
658 wr_s32b(p_ptr->old_race1);
659 wr_s32b(p_ptr->old_race2);
660 wr_s16b(p_ptr->old_realm);
662 for (i = 0; i < MAX_MANE; i++)
664 wr_s16b((s16b)p_ptr->mane_spell[i]);
665 wr_s16b((s16b)p_ptr->mane_dam[i]);
667 wr_s16b(p_ptr->mane_num);
669 for (i = 0; i < MAX_KUBI; i++)
671 wr_s16b(current_world_ptr->bounty_r_idx[i]);
674 for (i = 0; i < 4; i++)
676 wr_s16b(battle_mon[i]);
677 wr_u32b(mon_odds[i]);
680 wr_s16b(p_ptr->town_num); /* -KMW- */
682 /* Write arena and rewards information -KMW- */
683 wr_s16b(p_ptr->arena_number);
684 wr_s16b(p_ptr->inside_arena);
685 wr_s16b(p_ptr->inside_quest);
686 wr_s16b(p_ptr->inside_battle);
687 wr_byte(p_ptr->exit_bldg);
688 wr_byte(0); /* Unused */
690 wr_s16b((s16b)p_ptr->oldpx);
691 wr_s16b((s16b)p_ptr->oldpy);
693 /* Was number of p_ptr->rewards[] */
698 wr_u32b(p_ptr->chp_frac);
702 wr_u32b(p_ptr->csp_frac);
704 /* Max Player and Dungeon Levels */
705 wr_s16b(p_ptr->max_plv);
706 tmp8u = (byte)max_d_idx;
708 for (i = 0; i < tmp8u; i++)
709 wr_s16b((s16b)max_dlv[i]);
717 wr_s16b(p_ptr->concent);
719 wr_s16b(0); /* old "rest" */
720 wr_s16b(p_ptr->blind);
721 wr_s16b(p_ptr->paralyzed);
722 wr_s16b(p_ptr->confused);
723 wr_s16b(p_ptr->food);
724 wr_s16b(0); /* old "food_digested" */
725 wr_s16b(0); /* old "protection" */
726 wr_s16b(p_ptr->energy_need);
727 wr_s16b(p_ptr->enchant_energy_need);
728 wr_s16b(p_ptr->fast);
729 wr_s16b(p_ptr->slow);
730 wr_s16b(p_ptr->afraid);
732 wr_s16b(p_ptr->stun);
733 wr_s16b(p_ptr->poisoned);
734 wr_s16b(p_ptr->image);
735 wr_s16b(p_ptr->protevil);
736 wr_s16b(p_ptr->invuln);
737 wr_s16b(p_ptr->ult_res);
738 wr_s16b(p_ptr->hero);
739 wr_s16b(p_ptr->shero);
740 wr_s16b(p_ptr->shield);
741 wr_s16b(p_ptr->blessed);
742 wr_s16b(p_ptr->tim_invis);
743 wr_s16b(p_ptr->word_recall);
744 wr_s16b(p_ptr->recall_dungeon);
745 wr_s16b(p_ptr->alter_reality);
746 wr_s16b(p_ptr->see_infra);
747 wr_s16b(p_ptr->tim_infra);
748 wr_s16b(p_ptr->oppose_fire);
749 wr_s16b(p_ptr->oppose_cold);
750 wr_s16b(p_ptr->oppose_acid);
751 wr_s16b(p_ptr->oppose_elec);
752 wr_s16b(p_ptr->oppose_pois);
753 wr_s16b(p_ptr->tsuyoshi);
754 wr_s16b(p_ptr->tim_esp);
755 wr_s16b(p_ptr->wraith_form);
756 wr_s16b(p_ptr->resist_magic);
757 wr_s16b(p_ptr->tim_regen);
758 wr_s16b(p_ptr->kabenuke);
759 wr_s16b(p_ptr->tim_stealth);
760 wr_s16b(p_ptr->tim_levitation);
761 wr_s16b(p_ptr->tim_sh_touki);
762 wr_s16b(p_ptr->lightspeed);
763 wr_s16b(p_ptr->tsubureru);
764 wr_s16b(p_ptr->magicdef);
765 wr_s16b(p_ptr->tim_res_nether);
766 wr_s16b(p_ptr->tim_res_time);
767 wr_byte((byte)p_ptr->mimic_form);
768 wr_s16b(p_ptr->tim_mimic);
769 wr_s16b(p_ptr->tim_sh_fire);
770 wr_s16b(p_ptr->tim_sh_holy);
771 wr_s16b(p_ptr->tim_eyeeye);
774 wr_s16b(p_ptr->tim_reflect);
775 wr_s16b(p_ptr->multishadow);
776 wr_s16b(p_ptr->dustrobe);
778 wr_s16b(p_ptr->chaos_patron);
779 wr_u32b(p_ptr->muta1);
780 wr_u32b(p_ptr->muta2);
781 wr_u32b(p_ptr->muta3);
783 for (i = 0; i<8; i++)
784 wr_s16b(p_ptr->virtues[i]);
785 for (i = 0; i<8; i++)
786 wr_s16b(p_ptr->vir_types[i]);
788 wr_s16b(p_ptr->ele_attack);
789 wr_u32b(p_ptr->special_attack);
790 wr_s16b(p_ptr->ele_immune);
791 wr_u32b(p_ptr->special_defense);
792 wr_byte(p_ptr->knowledge);
793 wr_byte(p_ptr->autopick_autoregister);
795 wr_byte((byte_hack)p_ptr->action);
797 wr_byte(preserve_mode);
798 wr_byte(p_ptr->wait_report_score);
801 for (i = 0; i < 12; i++) wr_u32b(0L);
803 /* Ignore some flags */
809 /* Write the "object seeds" */
810 wr_u32b(seed_flavor);
815 wr_u16b(p_ptr->panic_save);
816 wr_u16b(p_ptr->total_winner);
817 wr_u16b(p_ptr->noscore);
821 wr_byte(p_ptr->is_dead);
824 wr_byte(p_ptr->feeling);
826 /* Turn when level began */
827 wr_s32b(current_floor_ptr->generated_turn);
829 /* Turn of last "feeling" */
830 wr_s32b(p_ptr->feeling_turn);
832 /* Current current_world_ptr->game_turn */
833 wr_s32b(current_world_ptr->game_turn);
835 wr_s32b(current_world_ptr->dungeon_turn);
840 wr_s16b(p_ptr->today_mon);
841 wr_s16b(p_ptr->riding);
843 /* Current floor_id */
844 wr_s16b(p_ptr->floor_id);
846 /* Save temporary preserved pets (obsolated) */
849 wr_u32b(current_world_ptr->play_time);
851 wr_s32b(p_ptr->visit);
853 wr_u32b(p_ptr->count);
858 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
859 * @param sf_ptr 保存したいフロアの参照ポインタ
862 static void wr_saved_floor(saved_floor_type *sf_ptr)
864 cave_template_type *templates;
879 /* Dungeon floor specific info follows */
883 /*** Not a saved floor ***/
885 wr_s16b((s16b)current_floor_ptr->dun_level);
889 /*** The saved floor ***/
891 wr_s16b(sf_ptr->floor_id);
892 wr_byte((byte_hack)sf_ptr->savefile_id);
893 wr_s16b((s16b)sf_ptr->dun_level);
894 wr_s32b(sf_ptr->last_visit);
895 wr_u32b(sf_ptr->visit_mark);
896 wr_s16b(sf_ptr->upper_floor_id);
897 wr_s16b(sf_ptr->lower_floor_id);
900 wr_u16b((u16b)current_floor_ptr->base_level);
901 wr_u16b((s16b)current_floor_ptr->num_repro);
902 wr_u16b((u16b)p_ptr->y);
903 wr_u16b((u16b)p_ptr->x);
904 wr_u16b((u16b)current_floor_ptr->height);
905 wr_u16b((u16b)current_floor_ptr->width);
906 wr_byte(p_ptr->feeling);
910 /*********** Make template for grid_type **********/
913 * Usually number of templates are fewer than 255. Even if
914 * more than 254 are exist, the occurrence of each template
915 * with larger ID is very small when we sort templates by
916 * occurrence. So we will use two (or more) bytes for
917 * templete ID larger than 254.
919 * Ex: 256 will be "0xff" "0x01".
920 * 515 will be "0xff" "0xff" "0x03"
923 /* Fake max number */
926 /* Allocate the "template" array */
927 C_MAKE(templates, max_num_temp, cave_template_type);
929 /* Extract template array */
930 for (y = 0; y < current_floor_ptr->height; y++)
932 for (x = 0; x < current_floor_ptr->width; x++)
934 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
936 for (i = 0; i < num_temp; i++)
938 if (templates[i].info == g_ptr->info &&
939 templates[i].feat == g_ptr->feat &&
940 templates[i].mimic == g_ptr->mimic &&
941 templates[i].special == g_ptr->special)
943 /* Same terrain is exist */
944 templates[i].occurrence++;
949 /* Are there same one? */
950 if (i < num_temp) continue;
952 /* If the max_num_temp is too small, increase it. */
953 if (num_temp >= max_num_temp)
955 cave_template_type *old_template = templates;
957 /* Re-allocate the "template" array */
958 C_MAKE(templates, max_num_temp + 255, cave_template_type);
959 (void)C_COPY(templates, old_template, max_num_temp, cave_template_type);
960 C_KILL(old_template, max_num_temp, cave_template_type);
964 /* Add new template */
965 templates[num_temp].info = g_ptr->info;
966 templates[num_temp].feat = g_ptr->feat;
967 templates[num_temp].mimic = g_ptr->mimic;
968 templates[num_temp].special = g_ptr->special;
969 templates[num_temp].occurrence = 1;
971 /* Increase number of template */
976 /* Sort by occurrence */
977 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
979 /*** Dump templates ***/
981 /* Total templates */
984 /* Dump the templates */
985 for (i = 0; i < num_temp; i++)
987 cave_template_type *ct_ptr = &templates[i];
990 wr_u16b((u16b)ct_ptr->info);
991 wr_s16b(ct_ptr->feat);
992 wr_s16b(ct_ptr->mimic);
993 wr_s16b(ct_ptr->special);
998 /*** "Run-Length-Encoding" of current_floor_ptr->grid_array ***/
1000 /* Note that this will induce two wasted bytes */
1004 /* Dump the current_floor_ptr->grid_array */
1005 for (y = 0; y < current_floor_ptr->height; y++)
1007 for (x = 0; x < current_floor_ptr->width; x++)
1009 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1011 for (i = 0; i < num_temp; i++)
1013 if (templates[i].info == g_ptr->info &&
1014 templates[i].feat == g_ptr->feat &&
1015 templates[i].mimic == g_ptr->mimic &&
1016 templates[i].special == g_ptr->special)
1023 /* If the run is broken, or too full, flush it */
1024 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
1026 wr_byte((byte)count);
1028 while (prev_u16b >= MAX_UCHAR)
1030 /* Mark as actual data is larger than 254 */
1032 prev_u16b -= MAX_UCHAR;
1035 wr_byte((byte)prev_u16b);
1040 /* Continue the run */
1048 /* Flush the data (if any) */
1051 wr_byte((byte)count);
1053 while (prev_u16b >= MAX_UCHAR)
1055 /* Mark as actual data is larger than 254 */
1057 prev_u16b -= MAX_UCHAR;
1059 wr_byte((byte)prev_u16b);
1063 /* Free the "template" array */
1064 C_KILL(templates, max_num_temp, cave_template_type);
1067 /*** Dump objects ***/
1072 /* Dump the objects */
1073 for (i = 1; i < o_max; i++)
1075 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
1082 /*** Dump the monsters ***/
1084 /* Total monsters */
1087 /* Dump the monsters */
1088 for (i = 1; i < m_max; i++)
1090 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1099 * @brief 現在フロアの書き込み /
1100 * Write the current dungeon (new method)
1103 static bool wr_dungeon(void)
1105 saved_floor_type *cur_sf_ptr;
1112 /* Update lite/view */
1113 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1114 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1118 /* Number of floor_id used from birth */
1119 wr_s16b(max_floor_id);
1121 /* Current dungeon type */
1122 wr_byte((byte_hack)p_ptr->dungeon_idx);
1125 /*** No saved floor (On the surface etc.) ***/
1126 if (!p_ptr->floor_id)
1128 /* No array elements */
1131 /* Write the current floor data */
1132 wr_saved_floor(NULL);
1139 /*** In the dungeon ***/
1141 /* Number of array elements */
1142 wr_byte(MAX_SAVED_FLOORS);
1144 /* Write the saved_floors array */
1145 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1147 saved_floor_type *sf_ptr = &saved_floors[i];
1149 wr_s16b(sf_ptr->floor_id);
1150 wr_byte((byte_hack)sf_ptr->savefile_id);
1151 wr_s16b((s16b)sf_ptr->dun_level);
1152 wr_s32b(sf_ptr->last_visit);
1153 wr_u32b(sf_ptr->visit_mark);
1154 wr_s16b(sf_ptr->upper_floor_id);
1155 wr_s16b(sf_ptr->lower_floor_id);
1158 /* Extract pointer to current floor */
1159 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1161 /* Save current floor to temporal file */
1162 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1164 /* Move data in temporal files to the savefile */
1165 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1167 saved_floor_type *sf_ptr = &saved_floors[i];
1169 /* Unused element */
1170 if (!sf_ptr->floor_id) continue;
1172 /* Load temporal saved floor file */
1173 if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1178 /* Write saved floor data to the save file */
1179 wr_saved_floor(sf_ptr);
1188 /* Restore current floor */
1189 if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1197 * @brief セーブデータの書き込み /
1198 * Actually write a save-file
1201 static bool wr_savefile_new(void)
1212 KIND_OBJECT_IDX k_idx;
1214 /* Compact the objects */
1216 /* Compact the monsters */
1217 compact_monsters(0);
1219 /* Guess at the current time */
1220 now = (u32b)time((time_t *)0);
1223 /* Note the operating system */
1226 /* Note when the file was saved */
1229 /* Note the number of saves */
1233 /*** Actually write the file ***/
1235 /* Dump the file header */
1237 wr_byte(FAKE_VER_MAJOR);
1239 wr_byte(FAKE_VER_MINOR);
1241 wr_byte(FAKE_VER_PATCH);
1244 /* Initial value of xor_byte */
1245 tmp8u = (byte)Rand_external(256);
1249 /* Reset the checksum */
1253 /* Write the savefile version for Hengband 1.1.1 and later */
1254 wr_byte(H_VER_EXTRA);
1255 wr_byte(H_VER_PATCH);
1256 wr_byte(H_VER_MINOR);
1257 wr_byte(H_VER_MAJOR);
1259 /* Operating system */
1263 /* Time file last saved */
1266 /* Number of past lives */
1269 /* Number of times saved */
1280 /* EUC kanji code */
1284 /* SJIS kanji code */
1292 /* Write the RNG state */
1296 /* Write the boolean "options" */
1300 /* Dump the number of "messages" */
1301 tmp32u = message_num();
1302 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1305 /* Dump the messages (oldest first!) */
1306 for (i = tmp32u - 1; i >= 0; i--)
1308 wr_string(message_str((s16b)i));
1311 /* Dump the monster lore */
1314 for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
1316 /* Dump the object memory */
1319 for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
1321 /* Dump the towns */
1325 /* Dump the quests */
1329 /* Dump the quests */
1330 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1333 for (i = 0; i < max_q_idx; i++)
1335 quest_type* const q_ptr = &quest[i];
1337 /* Save status for every quest */
1338 wr_s16b(q_ptr->status);
1340 /* And the dungeon level too */
1341 /* (prevents problems with multi-level quests) */
1342 wr_s16b((s16b)q_ptr->level);
1344 wr_byte((byte_hack)q_ptr->complev);
1345 wr_u32b(q_ptr->comptime);
1347 /* Save quest status if quest is running */
1348 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1350 wr_s16b((s16b)q_ptr->cur_num);
1351 wr_s16b((s16b)q_ptr->max_num);
1352 wr_s16b(q_ptr->type);
1353 wr_s16b(q_ptr->r_idx);
1354 wr_s16b(q_ptr->k_idx);
1355 wr_byte((byte_hack)q_ptr->flags);
1356 wr_byte((byte_hack)q_ptr->dungeon);
1360 /* Dump the position in the wilderness */
1361 wr_s32b(p_ptr->wilderness_x);
1362 wr_s32b(p_ptr->wilderness_y);
1364 wr_byte(p_ptr->wild_mode);
1365 wr_byte(p_ptr->ambush_flag);
1367 wr_s32b(current_world_ptr->max_wild_x);
1368 wr_s32b(current_world_ptr->max_wild_y);
1370 /* Dump the wilderness seeds */
1371 for (i = 0; i < current_world_ptr->max_wild_x; i++)
1373 for (j = 0; j < current_world_ptr->max_wild_y; j++)
1375 wr_u32b(wilderness[j][i].seed);
1379 /* Hack -- Dump the artifacts */
1382 for (i = 0; i < tmp16u; i++)
1384 artifact_type *a_ptr = &a_info[i];
1385 wr_byte(a_ptr->cur_num);
1386 wr_s16b(a_ptr->floor_id);
1391 /* Write the "extra" information */
1394 /* Dump the "player hp" entries */
1395 tmp16u = PY_MAX_LEVEL;
1397 for (i = 0; i < tmp16u; i++)
1399 wr_s16b((s16b)p_ptr->player_hp[i]);
1403 /* Write spell data */
1404 wr_u32b(p_ptr->spell_learned1);
1405 wr_u32b(p_ptr->spell_learned2);
1406 wr_u32b(p_ptr->spell_worked1);
1407 wr_u32b(p_ptr->spell_worked2);
1408 wr_u32b(p_ptr->spell_forgotten1);
1409 wr_u32b(p_ptr->spell_forgotten2);
1411 wr_s16b(p_ptr->learned_spells);
1412 wr_s16b(p_ptr->add_spells);
1414 /* Dump the ordered spells */
1415 for (i = 0; i < 64; i++)
1417 wr_byte((byte_hack)p_ptr->spell_order[i]);
1421 /* Write the inventory */
1422 for (i = 0; i < INVEN_TOTAL; i++)
1424 object_type *o_ptr = &inventory[i];
1426 /* Skip non-objects */
1427 if (!o_ptr->k_idx) continue;
1436 /* Add a sentinel */
1439 /* Note the towns */
1443 /* Note the stores */
1444 tmp16u = MAX_STORES;
1447 /* Dump the stores of all towns */
1448 for (i = 1; i < max_towns; i++)
1450 for (j = 0; j < MAX_STORES; j++)
1452 wr_store(&town_info[i].store[j]);
1456 /* Write the pet command settings */
1457 wr_s16b(p_ptr->pet_follow_distance);
1458 wr_s16b(p_ptr->pet_extra_flags);
1460 /* Write screen dump for sending score */
1461 if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead))
1463 wr_string(screen_dump);
1470 /* Player is not dead, write the dungeon */
1471 if (!p_ptr->is_dead)
1473 /* Dump the dungeon */
1474 if (!wr_dungeon()) return FALSE;
1476 /* Dump the ghost */
1484 /* Write the "value check-sum" */
1487 /* Write the "encoded checksum" */
1492 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1494 /* Successful save */
1500 * @brief セーブデータ書き込みのサブルーチン /
1501 * Medium level player saver
1504 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1506 static bool save_player_aux(char *name)
1515 /* File type is "SAVE" */
1516 FILE_TYPE(FILE_TYPE_SAVE);
1518 /* Grab permissions */
1521 /* Create the savefile */
1522 fd = fd_make(name, mode);
1524 /* Drop permissions */
1530 /* Close the "fd" */
1533 /* Grab permissions */
1536 /* Open the savefile */
1537 fff = my_fopen(name, "wb");
1539 /* Drop permissions */
1542 /* Successful open */
1545 /* Write the savefile */
1546 if (wr_savefile_new()) ok = TRUE;
1548 /* Attempt to close it */
1549 if (my_fclose(fff)) ok = FALSE;
1552 /* Grab permissions */
1555 /* Remove "broken" files */
1556 if (!ok) (void)fd_kill(name);
1558 /* Drop permissions */
1564 if (!ok) return (FALSE);
1566 counts_write(0, current_world_ptr->play_time);
1568 /* Successful save */
1569 character_saved = TRUE;
1578 * @brief セーブデータ書き込みのメインルーチン /
1579 * Attempt to save the player in a savefile
1582 bool save_player(void)
1584 bool result = FALSE;
1593 /* Get "games" permissions */
1602 strcpy(safe, savefile);
1603 strcat(safe, ".new");
1605 /* Grab permissions */
1611 /* Drop permissions */
1616 /* Attempt to save the player */
1617 if (save_player_aux(safe))
1622 strcpy(temp, savefile);
1623 strcat(temp, ".old");
1625 /* Grab permissions */
1631 /* Preserve old savefile */
1632 fd_move(savefile, temp);
1634 /* Activate new savefile */
1635 fd_move(safe, savefile);
1637 /* Remove preserved savefile */
1640 /* Drop permissions */
1643 /* Hack -- Pretend the character was loaded */
1644 character_loaded = TRUE;
1646 #ifdef VERIFY_SAVEFILE
1648 /* Lock on savefile */
1649 strcpy(temp, savefile);
1650 strcat(temp, ".lok");
1652 /* Grab permissions */
1655 /* Remove lock file */
1658 /* Drop permissions */
1672 /* Drop "games" permissions */
1679 /* Return the result */
1685 * @brief セーブデータ読み込みのメインルーチン /
1686 * Attempt to Load a "savefile"
1690 * Version 2.7.0 introduced a slightly different "savefile" format from
1691 * older versions, requiring a completely different parsing method.
1693 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1695 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1697 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1699 * On multi-user systems, you may only "read" a savefile if you will be
1700 * allowed to "write" it later, this prevents painful situations in which
1701 * the player loads a savefile belonging to someone else, and then is not
1702 * allowed to save his game when he quits.
1704 * We return "TRUE" if the savefile was usable, and we set the global
1705 * flag "character_loaded" if a real, living, character was loaded.
1707 * Note that we always try to load the "current" savefile, even if
1708 * there is no such file, so we must check for "empty" savefile names.
1711 bool load_player(void)
1719 #ifdef VERIFY_TIMESTAMP
1720 struct stat statbuf;
1723 concptr what = "generic";
1725 current_world_ptr->game_turn = 0;
1726 p_ptr->is_dead = FALSE;
1729 /* Allow empty savefile name */
1730 if (!savefile[0]) return (TRUE);
1733 #if !defined(MACINTOSH) && !defined(WINDOWS)
1737 /* Verify the existance of the savefile */
1738 if (access(savefile, 0) < 0)
1740 /* Give a message */
1741 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1752 #ifdef VERIFY_SAVEFILE
1754 /* Verify savefile usage */
1761 /* Extract name of lock file */
1762 strcpy(temp, savefile);
1763 strcat(temp, ".lok");
1765 /* Check for lock */
1766 fkk = my_fopen(temp, "r");
1768 /* Oops, lock exists */
1773 msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
1779 /* Create a lock file */
1780 fkk = my_fopen(temp, "w");
1782 /* Dump a line of info */
1783 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1785 /* Close the lock file */
1794 /* Open the savefile */
1795 fd = fd_open(savefile, O_RDONLY);
1798 if (fd < 0) err = -1;
1800 /* Message (below) */
1801 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1808 #ifdef VERIFY_TIMESTAMP
1809 /* Get the timestamp */
1810 (void)fstat(fd, &statbuf);
1813 /* Read the first four bytes */
1814 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1817 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1825 /* Extract version */
1833 /* Attempt to load */
1834 err = rd_savefile_new();
1836 /* Message (below) */
1837 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1841 /* Invalid current_world_ptr->game_turn */
1842 if (!current_world_ptr->game_turn) err = -1;
1844 /* Message (below) */
1845 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1848 #ifdef VERIFY_TIMESTAMP
1849 /* Verify timestamp */
1850 if (!err && !arg_wizard)
1852 /* Hack -- Verify the timestamp */
1853 if (sf_when > (statbuf.st_ctime + 100) ||
1854 sf_when < (statbuf.st_ctime - 100))
1856 what = _("無効なタイム・スタンプです", "Invalid timestamp");
1866 /* Give a conversion warning */
1867 if ((FAKE_VER_MAJOR != z_major) ||
1868 (FAKE_VER_MINOR != z_minor) ||
1869 (FAKE_VER_PATCH != z_patch))
1871 if (z_major == 2 && z_minor == 0 && z_patch == 6)
1873 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1877 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1878 (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
1883 /* Player is dead */
1889 /* A character was loaded */
1890 character_loaded = TRUE;
1894 /* Player is no longer "dead" */
1895 p_ptr->is_dead = FALSE;
1903 /* A character was loaded */
1904 character_loaded = TRUE;
1907 u32b tmp = counts_read(2);
1908 if (tmp > p_ptr->count)
1910 if (counts_read(0) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
1911 counts_write(2, ++p_ptr->count);
1912 counts_write(1, current_world_ptr->play_time);
1920 #ifdef VERIFY_SAVEFILE
1922 /* Verify savefile usage */
1927 /* Extract name of lock file */
1928 strcpy(temp, savefile);
1929 strcat(temp, ".lok");
1937 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1938 what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
1949 void remove_loc(void)
1951 #ifdef VERIFY_SAVEFILE
1953 #endif /* VERIFY_SAVEFILE */
1958 /* Get "games" permissions */
1961 # endif /* SECURE */
1962 #endif /* SET_UID */
1964 #ifdef VERIFY_SAVEFILE
1966 /* Lock on savefile */
1967 strcpy(temp, savefile);
1968 strcat(temp, ".lok");
1970 /* Remove lock file */
1973 #endif /* VERIFY_SAVEFILE */
1978 /* Drop "games" permissions */
1981 # endif /* SECURE */
1982 #endif /* SET_UID */
1988 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporal saved floor file
1989 * @param sf_ptr 保存フロア参照ポインタ
1992 static bool save_floor_aux(saved_floor_type *sf_ptr)
1996 /* Compact the objects */
1998 /* Compact the monsters */
1999 compact_monsters(0);
2002 /*** Actually write the file ***/
2004 /* Initial value of xor_byte */
2005 tmp8u = (byte)randint0(256);
2010 /* Reset the checksum */
2014 /* Write the sign of this process */
2015 wr_u32b(saved_floor_file_sign);
2017 /* Dump the dungeon floor */
2018 wr_saved_floor(sf_ptr);
2021 /* Write the "value check-sum" */
2024 /* Write the "encoded checksum" */
2029 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2031 /* Successful save */
2037 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data
2038 * @param sf_ptr 保存フロア参照ポインタ
2039 * @param mode 保存オプション
2042 bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
2044 FILE *old_fff = NULL;
2045 byte old_xor_byte = 0;
2046 u32b old_v_stamp = 0;
2047 u32b old_x_stamp = 0;
2049 char floor_savefile[1024];
2053 if (!(mode & SLF_SECOND))
2057 /* Get "games" permissions */
2063 /* We have one file already opened */
2066 /* Backup original values */
2068 old_xor_byte = xor_byte;
2069 old_v_stamp = v_stamp;
2070 old_x_stamp = x_stamp;
2074 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2076 /* Grab permissions */
2080 fd_kill(floor_savefile);
2082 /* Drop permissions */
2086 /* Attempt to save the player */
2091 /* File type is "SAVE" */
2092 FILE_TYPE(FILE_TYPE_SAVE);
2094 /* Grab permissions */
2097 /* Create the savefile */
2098 fd = fd_make(floor_savefile, 0644);
2100 /* Drop permissions */
2106 /* Close the "fd" */
2109 /* Grab permissions */
2112 /* Open the savefile */
2113 fff = my_fopen(floor_savefile, "wb");
2115 /* Drop permissions */
2118 /* Successful open */
2121 /* Write the savefile */
2122 if (save_floor_aux(sf_ptr)) ok = TRUE;
2124 /* Attempt to close it */
2125 if (my_fclose(fff)) ok = FALSE;
2128 /* Remove "broken" files */
2131 /* Grab permissions */
2134 (void)fd_kill(floor_savefile);
2136 /* Drop permissions */
2141 if (!(mode & SLF_SECOND))
2145 /* Drop "games" permissions */
2151 /* We have one file already opened */
2154 /* Restore original values */
2156 xor_byte = old_xor_byte;
2157 v_stamp = old_v_stamp;
2158 x_stamp = old_x_stamp;
2161 /* Return the result */