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 * Some "local" parameters, used to help write savefiles
26 static FILE *fff; /* Current save "file" */
27 static byte xor_byte; /* Simple encryption */
28 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
29 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
34 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
38 static void sf_put(byte v)
40 /* Encode the value, write a character */
42 (void)putc((int)xor_byte, fff);
44 /* Maintain the checksum info */
50 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
54 static void wr_byte(byte v)
60 * @brief 符号なし16ビットをファイルに書き込む
61 * @param v 書き込む符号なし16bit値
64 static void wr_u16b(u16b v)
66 sf_put((byte)(v & 0xFF));
67 sf_put((byte)((v >> 8) & 0xFF));
71 * @brief 符号あり16ビットをファイルに書き込む
72 * @param v 書き込む符号あり16bit値
75 static void wr_s16b(s16b v)
81 * @brief 符号なし32ビットをファイルに書き込む
82 * @param v 書き込む符号なし32bit値
85 static void wr_u32b(u32b v)
87 sf_put((byte)(v & 0xFF));
88 sf_put((byte)((v >> 8) & 0xFF));
89 sf_put((byte)((v >> 16) & 0xFF));
90 sf_put((byte)((v >> 24) & 0xFF));
94 * @brief 符号あり32ビットをファイルに書き込む
95 * @param v 書き込む符号あり32bit値
98 static void wr_s32b(s32b v)
104 * @brief 文字列をファイルに書き込む
108 static void wr_string(concptr str)
120 * These functions write info in larger logical records
125 * @brief アイテムオブジェクトを書き込む / Write an "item" record
126 * @param o_ptr アイテムオブジェクト保存元ポインタ
129 static void wr_item(object_type *o_ptr)
131 BIT_FLAGS flags = 0x00000000;
133 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
134 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
135 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
136 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
137 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
138 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
139 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
140 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
141 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
142 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
143 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
144 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
145 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
146 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
147 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
148 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
149 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
150 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
151 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
152 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
153 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
154 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
155 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
156 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
157 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
158 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
159 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
160 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
161 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
163 /*** Item save flags ***/
166 /*** Write only un-obvious elements ***/
167 wr_s16b(o_ptr->k_idx);
169 wr_byte((byte_hack)o_ptr->iy);
170 wr_byte((byte_hack)o_ptr->ix);
172 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
174 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
175 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
177 wr_s16b((s16b)o_ptr->weight);
179 if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
180 if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
181 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
183 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
184 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
185 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
186 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
187 if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
188 if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
190 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
192 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
194 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
195 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
196 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
197 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
198 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
200 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
202 /* Held by monster index */
203 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
205 /* Extra information */
206 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
207 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
208 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
209 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
210 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
213 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
215 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
216 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
221 * @brief モンスター情報を書き込む / Write a "monster" record
222 * @param m_ptr モンスター情報保存元ポインタ
225 static void wr_monster(monster_type *m_ptr)
227 BIT_FLAGS flags = 0x00000000;
230 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
231 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
232 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
233 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
234 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
235 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
236 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
237 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
238 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
239 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
240 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
241 if (m_ptr->smart) flags |= SAVE_MON_SMART;
242 if (m_ptr->exp) flags |= SAVE_MON_EXP;
243 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
244 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
245 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
247 /*** Monster save flags ***/
250 /*** Write only un-obvious elements ***/
251 wr_s16b(m_ptr->r_idx);
252 wr_byte((byte_hack)m_ptr->fy);
253 wr_byte((byte_hack)m_ptr->fx);
254 wr_s16b((s16b)m_ptr->hp);
255 wr_s16b((s16b)m_ptr->maxhp);
256 wr_s16b((s16b)m_ptr->max_maxhp);
257 wr_u32b(m_ptr->dealt_damage);
260 /* Monster race index of its appearance */
261 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
263 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
264 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
266 wr_byte((byte)m_ptr->mspeed);
267 wr_s16b(m_ptr->energy_need);
269 if (flags & SAVE_MON_FAST)
271 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
274 if (flags & SAVE_MON_SLOW)
276 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
279 if (flags & SAVE_MON_STUNNED)
281 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
284 if (flags & SAVE_MON_CONFUSED)
286 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
289 if (flags & SAVE_MON_MONFEAR)
291 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
294 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
295 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
296 if (flags & SAVE_MON_INVULNER)
298 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
301 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
302 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
303 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
304 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
305 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
310 * @brief モンスターの思い出を書き込む / Write a "lore" record
311 * @param r_idx モンスター種族ID
314 static void wr_lore(MONRACE_IDX r_idx)
316 monster_race *r_ptr = &r_info[r_idx];
318 /* Count sights/deaths/kills */
319 wr_s16b((s16b)r_ptr->r_sights);
320 wr_s16b((s16b)r_ptr->r_deaths);
321 wr_s16b((s16b)r_ptr->r_pkills);
322 wr_s16b((s16b)r_ptr->r_akills);
323 wr_s16b((s16b)r_ptr->r_tkills);
325 /* Count wakes and ignores */
326 wr_byte(r_ptr->r_wake);
327 wr_byte(r_ptr->r_ignore);
330 wr_byte(r_ptr->r_xtra1);
331 wr_byte(r_ptr->r_xtra2);
334 wr_byte((byte_hack)r_ptr->r_drop_gold);
335 wr_byte((byte_hack)r_ptr->r_drop_item);
338 wr_byte(0); /* unused now */
339 wr_byte(r_ptr->r_cast_spell);
341 /* Count blows of each type */
342 wr_byte(r_ptr->r_blows[0]);
343 wr_byte(r_ptr->r_blows[1]);
344 wr_byte(r_ptr->r_blows[2]);
345 wr_byte(r_ptr->r_blows[3]);
348 wr_u32b(r_ptr->r_flags1);
349 wr_u32b(r_ptr->r_flags2);
350 wr_u32b(r_ptr->r_flags3);
351 wr_u32b(r_ptr->r_flags4);
352 wr_u32b(r_ptr->r_flags5);
353 wr_u32b(r_ptr->r_flags6);
354 wr_u32b(r_ptr->r_flagsr);
356 /* Monster limit per level */
357 wr_byte((byte_hack)r_ptr->max_num);
359 /* Location in saved floor */
360 wr_s16b(r_ptr->floor_id);
367 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
368 * @param k_idx ベースアイテムのID
371 static void wr_xtra(KIND_OBJECT_IDX k_idx)
375 object_kind *k_ptr = &k_info[k_idx];
377 if (k_ptr->aware) tmp8u |= 0x01;
378 if (k_ptr->tried) tmp8u |= 0x02;
385 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
386 * @param st_ptr 店舗情報の参照ポインタ
389 static void wr_store(store_type *st_ptr)
393 /* Save the "open" counter */
394 wr_u32b(st_ptr->store_open);
396 /* Save the "insults" */
397 wr_s16b(st_ptr->insult_cur);
399 /* Save the current owner */
400 wr_byte(st_ptr->owner);
402 /* Save the stock size */
403 wr_s16b(st_ptr->stock_num);
405 /* Save the "haggle" info */
406 wr_s16b(st_ptr->good_buy);
407 wr_s16b(st_ptr->bad_buy);
409 wr_s32b(st_ptr->last_visit);
412 for (j = 0; j < st_ptr->stock_num; j++)
414 /* Save each item in stock */
415 wr_item(&st_ptr->stock[j]);
421 * @brief セーブデータに乱数情報を書き込む / Write RNG state
424 static errr wr_randomizer(void)
430 for (i = 0; i < RAND_DEG; i++)
432 wr_u32b(Rand_state[i]);
440 * @brief ゲームオプション情報を書き込む / Write the "options"
443 static void wr_options(void)
452 for (i = 0; i < 4; i++) wr_u32b(0L);
455 /*** Special Options ***/
457 /* Write "delay_factor" */
458 wr_byte(delay_factor);
460 /* Write "hitpoint_warn" */
461 wr_byte(hitpoint_warn);
463 /* Write "mana_warn" */
466 /*** Cheating options ***/
470 if (p_ptr->wizard) c |= 0x0002;
472 if (cheat_sight) c |= 0x0040;
473 if (cheat_turn) c |= 0x0080;
475 if (cheat_peek) c |= 0x0100;
476 if (cheat_hear) c |= 0x0200;
477 if (cheat_room) c |= 0x0400;
478 if (cheat_xtra) c |= 0x0800;
479 if (cheat_know) c |= 0x1000;
480 if (cheat_live) c |= 0x2000;
481 if (cheat_save) c |= 0x4000;
482 if (cheat_diary_output) c |= 0x8000;
489 wr_s16b(autosave_freq);
491 /*** Extract options ***/
493 /* Analyze the options */
494 for (i = 0; option_info[i].o_desc; i++)
496 int os = option_info[i].o_set;
497 int ob = option_info[i].o_bit;
499 /* Process real entries */
500 if (option_info[i].o_var)
503 if (*option_info[i].o_var)
506 option_flag[os] |= (1L << ob);
513 option_flag[os] &= ~(1L << ob);
519 /*** Normal options ***/
522 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
525 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
528 /*** Window options ***/
531 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
534 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
539 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
542 static void wr_ghost(void)
547 wr_string(_("不正なゴースト", "Broken Ghost"));
549 /* Hack -- stupid data */
550 for (i = 0; i < 60; i++) wr_byte(0);
555 * @brief クイック・スタート情報を書き込む / Save quick start data
558 static void save_quick_start(void)
562 wr_byte(previous_char.psex);
563 wr_byte((byte_hack)previous_char.prace);
564 wr_byte((byte_hack)previous_char.pclass);
565 wr_byte((byte_hack)previous_char.pseikaku);
566 wr_byte((byte_hack)previous_char.realm1);
567 wr_byte((byte_hack)previous_char.realm2);
569 wr_s16b(previous_char.age);
570 wr_s16b(previous_char.ht);
571 wr_s16b(previous_char.wt);
572 wr_s16b(previous_char.sc);
573 wr_s32b(previous_char.au);
575 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
576 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
578 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
580 wr_s16b(previous_char.chaos_patron);
582 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
584 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
586 /* UNUSED : Was number of random quests */
589 /* No quick start after using debug mode or cheat options */
590 if (p_ptr->noscore) previous_char.quick_ok = FALSE;
592 wr_byte((byte)previous_char.quick_ok);
597 * @brief その他の情報を書き込む / Write some "extra" info
600 static void wr_extra(void)
605 wr_string(p_ptr->name);
606 wr_string(p_ptr->died_from);
607 wr_string(p_ptr->last_message ? p_ptr->last_message : "");
611 for (i = 0; i < 4; i++)
613 wr_string(p_ptr->history[i]);
616 /* Race/Class/Gender/Spells */
617 wr_byte((byte_hack)p_ptr->prace);
618 wr_byte((byte_hack)p_ptr->pclass);
619 wr_byte((byte_hack)p_ptr->pseikaku);
620 wr_byte((byte_hack)p_ptr->psex);
621 wr_byte((byte_hack)p_ptr->realm1);
622 wr_byte((byte_hack)p_ptr->realm2);
625 wr_byte((byte)p_ptr->hitdie);
626 wr_u16b(p_ptr->expfact);
632 /* Dump the stats (maximum and current) */
633 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max[i]);
634 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max_max[i]);
635 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_cur[i]);
637 /* Ignore the transient stats */
638 for (i = 0; i < 12; ++i) wr_s16b(0);
642 wr_u32b(p_ptr->max_exp);
643 wr_u32b(p_ptr->max_max_exp);
645 wr_u32b(p_ptr->exp_frac);
648 for (i = 0; i < 64; i++) wr_s16b(p_ptr->spell_exp[i]);
649 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(p_ptr->weapon_exp[i][j]);
650 for (i = 0; i < GINOU_MAX; i++) wr_s16b(p_ptr->skill_exp[i]);
651 for (i = 0; i < 108; i++) wr_s32b(p_ptr->magic_num1[i]);
652 for (i = 0; i < 108; i++) wr_byte(p_ptr->magic_num2[i]);
654 wr_byte((byte_hack)p_ptr->start_race);
655 wr_s32b(p_ptr->old_race1);
656 wr_s32b(p_ptr->old_race2);
657 wr_s16b(p_ptr->old_realm);
659 for (i = 0; i < MAX_MANE; i++)
661 wr_s16b((s16b)p_ptr->mane_spell[i]);
662 wr_s16b((s16b)p_ptr->mane_dam[i]);
664 wr_s16b(p_ptr->mane_num);
666 for (i = 0; i < MAX_KUBI; i++)
668 wr_s16b(current_world_ptr->bounty_r_idx[i]);
671 for (i = 0; i < 4; i++)
673 wr_s16b(battle_mon[i]);
674 wr_u32b(mon_odds[i]);
677 wr_s16b(p_ptr->town_num); /* -KMW- */
679 /* Write arena and rewards information -KMW- */
680 wr_s16b(p_ptr->arena_number);
681 wr_s16b(p_ptr->inside_arena);
682 wr_s16b(p_ptr->inside_quest);
683 wr_s16b(p_ptr->inside_battle);
684 wr_byte(p_ptr->exit_bldg);
685 wr_byte(0); /* Unused */
687 wr_s16b((s16b)p_ptr->oldpx);
688 wr_s16b((s16b)p_ptr->oldpy);
690 /* Was number of p_ptr->rewards[] */
695 wr_u32b(p_ptr->chp_frac);
699 wr_u32b(p_ptr->csp_frac);
701 /* Max Player and Dungeon Levels */
702 wr_s16b(p_ptr->max_plv);
703 tmp8u = (byte)max_d_idx;
705 for (i = 0; i < tmp8u; i++)
706 wr_s16b((s16b)max_dlv[i]);
714 wr_s16b(p_ptr->concent);
716 wr_s16b(0); /* old "rest" */
717 wr_s16b(p_ptr->blind);
718 wr_s16b(p_ptr->paralyzed);
719 wr_s16b(p_ptr->confused);
720 wr_s16b(p_ptr->food);
721 wr_s16b(0); /* old "food_digested" */
722 wr_s16b(0); /* old "protection" */
723 wr_s16b(p_ptr->energy_need);
724 wr_s16b(p_ptr->enchant_energy_need);
725 wr_s16b(p_ptr->fast);
726 wr_s16b(p_ptr->slow);
727 wr_s16b(p_ptr->afraid);
729 wr_s16b(p_ptr->stun);
730 wr_s16b(p_ptr->poisoned);
731 wr_s16b(p_ptr->image);
732 wr_s16b(p_ptr->protevil);
733 wr_s16b(p_ptr->invuln);
734 wr_s16b(p_ptr->ult_res);
735 wr_s16b(p_ptr->hero);
736 wr_s16b(p_ptr->shero);
737 wr_s16b(p_ptr->shield);
738 wr_s16b(p_ptr->blessed);
739 wr_s16b(p_ptr->tim_invis);
740 wr_s16b(p_ptr->word_recall);
741 wr_s16b(p_ptr->recall_dungeon);
742 wr_s16b(p_ptr->alter_reality);
743 wr_s16b(p_ptr->see_infra);
744 wr_s16b(p_ptr->tim_infra);
745 wr_s16b(p_ptr->oppose_fire);
746 wr_s16b(p_ptr->oppose_cold);
747 wr_s16b(p_ptr->oppose_acid);
748 wr_s16b(p_ptr->oppose_elec);
749 wr_s16b(p_ptr->oppose_pois);
750 wr_s16b(p_ptr->tsuyoshi);
751 wr_s16b(p_ptr->tim_esp);
752 wr_s16b(p_ptr->wraith_form);
753 wr_s16b(p_ptr->resist_magic);
754 wr_s16b(p_ptr->tim_regen);
755 wr_s16b(p_ptr->kabenuke);
756 wr_s16b(p_ptr->tim_stealth);
757 wr_s16b(p_ptr->tim_levitation);
758 wr_s16b(p_ptr->tim_sh_touki);
759 wr_s16b(p_ptr->lightspeed);
760 wr_s16b(p_ptr->tsubureru);
761 wr_s16b(p_ptr->magicdef);
762 wr_s16b(p_ptr->tim_res_nether);
763 wr_s16b(p_ptr->tim_res_time);
764 wr_byte((byte)p_ptr->mimic_form);
765 wr_s16b(p_ptr->tim_mimic);
766 wr_s16b(p_ptr->tim_sh_fire);
767 wr_s16b(p_ptr->tim_sh_holy);
768 wr_s16b(p_ptr->tim_eyeeye);
771 wr_s16b(p_ptr->tim_reflect);
772 wr_s16b(p_ptr->multishadow);
773 wr_s16b(p_ptr->dustrobe);
775 wr_s16b(p_ptr->chaos_patron);
776 wr_u32b(p_ptr->muta1);
777 wr_u32b(p_ptr->muta2);
778 wr_u32b(p_ptr->muta3);
780 for (i = 0; i<8; i++)
781 wr_s16b(p_ptr->virtues[i]);
782 for (i = 0; i<8; i++)
783 wr_s16b(p_ptr->vir_types[i]);
785 wr_s16b(p_ptr->ele_attack);
786 wr_u32b(p_ptr->special_attack);
787 wr_s16b(p_ptr->ele_immune);
788 wr_u32b(p_ptr->special_defense);
789 wr_byte(p_ptr->knowledge);
790 wr_byte(p_ptr->autopick_autoregister);
792 wr_byte((byte_hack)p_ptr->action);
794 wr_byte(preserve_mode);
795 wr_byte(p_ptr->wait_report_score);
798 for (i = 0; i < 12; i++) wr_u32b(0L);
800 /* Ignore some flags */
806 /* Write the "object seeds" */
807 wr_u32b(seed_flavor);
812 wr_u16b(p_ptr->panic_save);
813 wr_u16b(p_ptr->total_winner);
814 wr_u16b(p_ptr->noscore);
818 wr_byte(p_ptr->is_dead);
821 wr_byte(p_ptr->feeling);
823 /* Turn when level began */
824 wr_s32b(current_floor_ptr->generated_turn);
826 /* Turn of last "feeling" */
827 wr_s32b(p_ptr->feeling_turn);
829 /* Current current_world_ptr->game_turn */
830 wr_s32b(current_world_ptr->game_turn);
832 wr_s32b(current_world_ptr->dungeon_turn);
837 wr_s16b(p_ptr->today_mon);
838 wr_s16b(p_ptr->riding);
840 /* Current floor_id */
841 wr_s16b(p_ptr->floor_id);
843 /* Save temporary preserved pets (obsolated) */
846 wr_u32b(current_world_ptr->play_time);
848 wr_s32b(p_ptr->visit);
850 wr_u32b(p_ptr->count);
855 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
856 * @param sf_ptr 保存したいフロアの参照ポインタ
859 static void wr_saved_floor(saved_floor_type *sf_ptr)
861 cave_template_type *templates;
876 /* Dungeon floor specific info follows */
880 /*** Not a saved floor ***/
882 wr_s16b((s16b)current_floor_ptr->dun_level);
886 /*** The saved floor ***/
888 wr_s16b(sf_ptr->floor_id);
889 wr_byte((byte_hack)sf_ptr->savefile_id);
890 wr_s16b((s16b)sf_ptr->dun_level);
891 wr_s32b(sf_ptr->last_visit);
892 wr_u32b(sf_ptr->visit_mark);
893 wr_s16b(sf_ptr->upper_floor_id);
894 wr_s16b(sf_ptr->lower_floor_id);
897 wr_u16b((u16b)current_floor_ptr->base_level);
898 wr_u16b((s16b)current_floor_ptr->num_repro);
899 wr_u16b((u16b)p_ptr->y);
900 wr_u16b((u16b)p_ptr->x);
901 wr_u16b((u16b)current_floor_ptr->height);
902 wr_u16b((u16b)current_floor_ptr->width);
903 wr_byte(p_ptr->feeling);
907 /*********** Make template for grid_type **********/
910 * Usually number of templates are fewer than 255. Even if
911 * more than 254 are exist, the occurrence of each template
912 * with larger ID is very small when we sort templates by
913 * occurrence. So we will use two (or more) bytes for
914 * templete ID larger than 254.
916 * Ex: 256 will be "0xff" "0x01".
917 * 515 will be "0xff" "0xff" "0x03"
920 /* Fake max number */
923 /* Allocate the "template" array */
924 C_MAKE(templates, max_num_temp, cave_template_type);
926 /* Extract template array */
927 for (y = 0; y < current_floor_ptr->height; y++)
929 for (x = 0; x < current_floor_ptr->width; x++)
931 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
933 for (i = 0; i < num_temp; i++)
935 if (templates[i].info == g_ptr->info &&
936 templates[i].feat == g_ptr->feat &&
937 templates[i].mimic == g_ptr->mimic &&
938 templates[i].special == g_ptr->special)
940 /* Same terrain is exist */
941 templates[i].occurrence++;
946 /* Are there same one? */
947 if (i < num_temp) continue;
949 /* If the max_num_temp is too small, increase it. */
950 if (num_temp >= max_num_temp)
952 cave_template_type *old_template = templates;
954 /* Re-allocate the "template" array */
955 C_MAKE(templates, max_num_temp + 255, cave_template_type);
956 (void)C_COPY(templates, old_template, max_num_temp, cave_template_type);
957 C_KILL(old_template, max_num_temp, cave_template_type);
961 /* Add new template */
962 templates[num_temp].info = g_ptr->info;
963 templates[num_temp].feat = g_ptr->feat;
964 templates[num_temp].mimic = g_ptr->mimic;
965 templates[num_temp].special = g_ptr->special;
966 templates[num_temp].occurrence = 1;
968 /* Increase number of template */
973 /* Sort by occurrence */
974 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
976 /*** Dump templates ***/
978 /* Total templates */
981 /* Dump the templates */
982 for (i = 0; i < num_temp; i++)
984 cave_template_type *ct_ptr = &templates[i];
987 wr_u16b((u16b)ct_ptr->info);
988 wr_s16b(ct_ptr->feat);
989 wr_s16b(ct_ptr->mimic);
990 wr_s16b(ct_ptr->special);
995 /*** "Run-Length-Encoding" of current_floor_ptr->grid_array ***/
997 /* Note that this will induce two wasted bytes */
1001 /* Dump the current_floor_ptr->grid_array */
1002 for (y = 0; y < current_floor_ptr->height; y++)
1004 for (x = 0; x < current_floor_ptr->width; x++)
1006 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1008 for (i = 0; i < num_temp; i++)
1010 if (templates[i].info == g_ptr->info &&
1011 templates[i].feat == g_ptr->feat &&
1012 templates[i].mimic == g_ptr->mimic &&
1013 templates[i].special == g_ptr->special)
1020 /* If the run is broken, or too full, flush it */
1021 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
1023 wr_byte((byte)count);
1025 while (prev_u16b >= MAX_UCHAR)
1027 /* Mark as actual data is larger than 254 */
1029 prev_u16b -= MAX_UCHAR;
1032 wr_byte((byte)prev_u16b);
1037 /* Continue the run */
1045 /* Flush the data (if any) */
1048 wr_byte((byte)count);
1050 while (prev_u16b >= MAX_UCHAR)
1052 /* Mark as actual data is larger than 254 */
1054 prev_u16b -= MAX_UCHAR;
1056 wr_byte((byte)prev_u16b);
1060 /* Free the "template" array */
1061 C_KILL(templates, max_num_temp, cave_template_type);
1064 /*** Dump objects ***/
1069 /* Dump the objects */
1070 for (i = 1; i < o_max; i++)
1072 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
1079 /*** Dump the monsters ***/
1081 /* Total monsters */
1084 /* Dump the monsters */
1085 for (i = 1; i < m_max; i++)
1087 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1096 * @brief 現在フロアの書き込み /
1097 * Write the current dungeon (new method)
1100 static bool wr_dungeon(void)
1102 saved_floor_type *cur_sf_ptr;
1109 /* Update lite/view */
1110 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1111 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1115 /* Number of floor_id used from birth */
1116 wr_s16b(max_floor_id);
1118 /* Current dungeon type */
1119 wr_byte((byte_hack)p_ptr->dungeon_idx);
1122 /*** No saved floor (On the surface etc.) ***/
1123 if (!p_ptr->floor_id)
1125 /* No array elements */
1128 /* Write the current floor data */
1129 wr_saved_floor(NULL);
1136 /*** In the dungeon ***/
1138 /* Number of array elements */
1139 wr_byte(MAX_SAVED_FLOORS);
1141 /* Write the saved_floors array */
1142 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1144 saved_floor_type *sf_ptr = &saved_floors[i];
1146 wr_s16b(sf_ptr->floor_id);
1147 wr_byte((byte_hack)sf_ptr->savefile_id);
1148 wr_s16b((s16b)sf_ptr->dun_level);
1149 wr_s32b(sf_ptr->last_visit);
1150 wr_u32b(sf_ptr->visit_mark);
1151 wr_s16b(sf_ptr->upper_floor_id);
1152 wr_s16b(sf_ptr->lower_floor_id);
1155 /* Extract pointer to current floor */
1156 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1158 /* Save current floor to temporary file */
1159 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1161 /* Move data in temporary files to the savefile */
1162 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1164 saved_floor_type *sf_ptr = &saved_floors[i];
1166 /* Unused element */
1167 if (!sf_ptr->floor_id) continue;
1169 /* Load temporary saved floor file */
1170 if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1175 /* Write saved floor data to the save file */
1176 wr_saved_floor(sf_ptr);
1185 /* Restore current floor */
1186 if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1194 * @brief セーブデータの書き込み /
1195 * Actually write a save-file
1198 static bool wr_savefile_new(void)
1209 KIND_OBJECT_IDX k_idx;
1211 /* Compact the objects */
1213 /* Compact the monsters */
1214 compact_monsters(0);
1216 /* Guess at the current time */
1217 now = (u32b)time((time_t *)0);
1220 /* Note the operating system */
1223 /* Note when the file was saved */
1226 /* Note the number of saves */
1230 /*** Actually write the file ***/
1232 /* Dump the file header */
1234 wr_byte(FAKE_VER_MAJOR);
1236 wr_byte(FAKE_VER_MINOR);
1238 wr_byte(FAKE_VER_PATCH);
1241 /* Initial value of xor_byte */
1242 tmp8u = (byte)Rand_external(256);
1246 /* Reset the checksum */
1250 /* Write the savefile version for Hengband 1.1.1 and later */
1251 wr_byte(H_VER_EXTRA);
1252 wr_byte(H_VER_PATCH);
1253 wr_byte(H_VER_MINOR);
1254 wr_byte(H_VER_MAJOR);
1256 /* Operating system */
1260 /* Time file last saved */
1263 /* Number of past lives */
1266 /* Number of times saved */
1277 /* EUC kanji code */
1281 /* SJIS kanji code */
1289 /* Write the RNG state */
1293 /* Write the boolean "options" */
1297 /* Dump the number of "messages" */
1298 tmp32u = message_num();
1299 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1302 /* Dump the messages (oldest first!) */
1303 for (i = tmp32u - 1; i >= 0; i--)
1305 wr_string(message_str((s16b)i));
1308 /* Dump the monster lore */
1311 for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
1313 /* Dump the object memory */
1316 for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
1318 /* Dump the towns */
1322 /* Dump the quests */
1326 /* Dump the quests */
1327 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1330 for (i = 0; i < max_q_idx; i++)
1332 quest_type* const q_ptr = &quest[i];
1334 /* Save status for every quest */
1335 wr_s16b(q_ptr->status);
1337 /* And the dungeon level too */
1338 /* (prevents problems with multi-level quests) */
1339 wr_s16b((s16b)q_ptr->level);
1341 wr_byte((byte_hack)q_ptr->complev);
1342 wr_u32b(q_ptr->comptime);
1344 /* Save quest status if quest is running */
1345 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1347 wr_s16b((s16b)q_ptr->cur_num);
1348 wr_s16b((s16b)q_ptr->max_num);
1349 wr_s16b(q_ptr->type);
1350 wr_s16b(q_ptr->r_idx);
1351 wr_s16b(q_ptr->k_idx);
1352 wr_byte((byte_hack)q_ptr->flags);
1353 wr_byte((byte_hack)q_ptr->dungeon);
1357 /* Dump the position in the wilderness */
1358 wr_s32b(p_ptr->wilderness_x);
1359 wr_s32b(p_ptr->wilderness_y);
1361 wr_byte(p_ptr->wild_mode);
1362 wr_byte(p_ptr->ambush_flag);
1364 wr_s32b(current_world_ptr->max_wild_x);
1365 wr_s32b(current_world_ptr->max_wild_y);
1367 /* Dump the wilderness seeds */
1368 for (i = 0; i < current_world_ptr->max_wild_x; i++)
1370 for (j = 0; j < current_world_ptr->max_wild_y; j++)
1372 wr_u32b(wilderness[j][i].seed);
1376 /* Hack -- Dump the artifacts */
1379 for (i = 0; i < tmp16u; i++)
1381 artifact_type *a_ptr = &a_info[i];
1382 wr_byte(a_ptr->cur_num);
1383 wr_s16b(a_ptr->floor_id);
1388 /* Write the "extra" information */
1391 /* Dump the "player hp" entries */
1392 tmp16u = PY_MAX_LEVEL;
1394 for (i = 0; i < tmp16u; i++)
1396 wr_s16b((s16b)p_ptr->player_hp[i]);
1400 /* Write spell data */
1401 wr_u32b(p_ptr->spell_learned1);
1402 wr_u32b(p_ptr->spell_learned2);
1403 wr_u32b(p_ptr->spell_worked1);
1404 wr_u32b(p_ptr->spell_worked2);
1405 wr_u32b(p_ptr->spell_forgotten1);
1406 wr_u32b(p_ptr->spell_forgotten2);
1408 wr_s16b(p_ptr->learned_spells);
1409 wr_s16b(p_ptr->add_spells);
1411 /* Dump the ordered spells */
1412 for (i = 0; i < 64; i++)
1414 wr_byte((byte_hack)p_ptr->spell_order[i]);
1418 /* Write the inventory */
1419 for (i = 0; i < INVEN_TOTAL; i++)
1421 object_type *o_ptr = &inventory[i];
1423 /* Skip non-objects */
1424 if (!o_ptr->k_idx) continue;
1433 /* Add a sentinel */
1436 /* Note the towns */
1440 /* Note the stores */
1441 tmp16u = MAX_STORES;
1444 /* Dump the stores of all towns */
1445 for (i = 1; i < max_towns; i++)
1447 for (j = 0; j < MAX_STORES; j++)
1449 wr_store(&town_info[i].store[j]);
1453 /* Write the pet command settings */
1454 wr_s16b(p_ptr->pet_follow_distance);
1455 wr_s16b(p_ptr->pet_extra_flags);
1457 /* Write screen dump for sending score */
1458 if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead))
1460 wr_string(screen_dump);
1467 /* Player is not dead, write the dungeon */
1468 if (!p_ptr->is_dead)
1470 /* Dump the dungeon */
1471 if (!wr_dungeon()) return FALSE;
1473 /* Dump the ghost */
1481 /* Write the "value check-sum" */
1484 /* Write the "encoded checksum" */
1489 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1491 /* Successful save */
1497 * @brief セーブデータ書き込みのサブルーチン /
1498 * Medium level player saver
1501 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1503 static bool save_player_aux(char *name)
1512 /* File type is "SAVE" */
1513 FILE_TYPE(FILE_TYPE_SAVE);
1515 /* Grab permissions */
1518 /* Create the savefile */
1519 fd = fd_make(name, mode);
1521 /* Drop permissions */
1527 /* Close the "fd" */
1530 /* Grab permissions */
1533 /* Open the savefile */
1534 fff = my_fopen(name, "wb");
1536 /* Drop permissions */
1539 /* Successful open */
1542 /* Write the savefile */
1543 if (wr_savefile_new()) ok = TRUE;
1545 /* Attempt to close it */
1546 if (my_fclose(fff)) ok = FALSE;
1549 /* Grab permissions */
1552 /* Remove "broken" files */
1553 if (!ok) (void)fd_kill(name);
1555 /* Drop permissions */
1561 if (!ok) return (FALSE);
1563 counts_write(0, current_world_ptr->play_time);
1565 /* Successful save */
1566 character_saved = TRUE;
1575 * @brief セーブデータ書き込みのメインルーチン /
1576 * Attempt to save the player in a savefile
1579 bool save_player(void)
1581 bool result = FALSE;
1590 /* Get "games" permissions */
1599 strcpy(safe, savefile);
1600 strcat(safe, ".new");
1602 /* Grab permissions */
1608 /* Drop permissions */
1613 /* Attempt to save the player */
1614 if (save_player_aux(safe))
1619 strcpy(temp, savefile);
1620 strcat(temp, ".old");
1622 /* Grab permissions */
1628 /* Preserve old savefile */
1629 fd_move(savefile, temp);
1631 /* Activate new savefile */
1632 fd_move(safe, savefile);
1634 /* Remove preserved savefile */
1637 /* Drop permissions */
1640 /* Hack -- Pretend the character was loaded */
1641 character_loaded = TRUE;
1643 #ifdef VERIFY_SAVEFILE
1645 /* Lock on savefile */
1646 strcpy(temp, savefile);
1647 strcat(temp, ".lok");
1649 /* Grab permissions */
1652 /* Remove lock file */
1655 /* Drop permissions */
1669 /* Drop "games" permissions */
1676 /* Return the result */
1682 * @brief セーブデータ読み込みのメインルーチン /
1683 * Attempt to Load a "savefile"
1687 * Version 2.7.0 introduced a slightly different "savefile" format from
1688 * older versions, requiring a completely different parsing method.
1690 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1692 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1694 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1696 * On multi-user systems, you may only "read" a savefile if you will be
1697 * allowed to "write" it later, this prevents painful situations in which
1698 * the player loads a savefile belonging to someone else, and then is not
1699 * allowed to save his game when he quits.
1701 * We return "TRUE" if the savefile was usable, and we set the global
1702 * flag "character_loaded" if a real, living, character was loaded.
1704 * Note that we always try to load the "current" savefile, even if
1705 * there is no such file, so we must check for "empty" savefile names.
1708 bool load_player(void)
1716 #ifdef VERIFY_TIMESTAMP
1717 struct stat statbuf;
1720 concptr what = "generic";
1722 current_world_ptr->game_turn = 0;
1723 p_ptr->is_dead = FALSE;
1726 /* Allow empty savefile name */
1727 if (!savefile[0]) return (TRUE);
1730 #if !defined(MACINTOSH) && !defined(WINDOWS)
1734 /* Verify the existance of the savefile */
1735 if (access(savefile, 0) < 0)
1737 /* Give a message */
1738 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1749 #ifdef VERIFY_SAVEFILE
1751 /* Verify savefile usage */
1758 /* Extract name of lock file */
1759 strcpy(temp, savefile);
1760 strcat(temp, ".lok");
1762 /* Check for lock */
1763 fkk = my_fopen(temp, "r");
1765 /* Oops, lock exists */
1770 msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
1776 /* Create a lock file */
1777 fkk = my_fopen(temp, "w");
1779 /* Dump a line of info */
1780 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1782 /* Close the lock file */
1791 /* Open the savefile */
1792 fd = fd_open(savefile, O_RDONLY);
1795 if (fd < 0) err = -1;
1797 /* Message (below) */
1798 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1805 #ifdef VERIFY_TIMESTAMP
1806 /* Get the timestamp */
1807 (void)fstat(fd, &statbuf);
1810 /* Read the first four bytes */
1811 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1814 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1822 /* Extract version */
1830 /* Attempt to load */
1831 err = rd_savefile_new();
1833 /* Message (below) */
1834 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1838 /* Invalid current_world_ptr->game_turn */
1839 if (!current_world_ptr->game_turn) err = -1;
1841 /* Message (below) */
1842 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1845 #ifdef VERIFY_TIMESTAMP
1846 /* Verify timestamp */
1847 if (!err && !arg_wizard)
1849 /* Hack -- Verify the timestamp */
1850 if (sf_when > (statbuf.st_ctime + 100) ||
1851 sf_when < (statbuf.st_ctime - 100))
1853 what = _("無効なタイム・スタンプです", "Invalid timestamp");
1863 /* Give a conversion warning */
1864 if ((FAKE_VER_MAJOR != z_major) ||
1865 (FAKE_VER_MINOR != z_minor) ||
1866 (FAKE_VER_PATCH != z_patch))
1868 if (z_major == 2 && z_minor == 0 && z_patch == 6)
1870 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1874 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1875 (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
1880 /* Player is dead */
1886 /* A character was loaded */
1887 character_loaded = TRUE;
1891 /* Player is no longer "dead" */
1892 p_ptr->is_dead = FALSE;
1900 /* A character was loaded */
1901 character_loaded = TRUE;
1904 u32b tmp = counts_read(2);
1905 if (tmp > p_ptr->count)
1907 if (counts_read(0) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
1908 counts_write(2, ++p_ptr->count);
1909 counts_write(1, current_world_ptr->play_time);
1917 #ifdef VERIFY_SAVEFILE
1919 /* Verify savefile usage */
1924 /* Extract name of lock file */
1925 strcpy(temp, savefile);
1926 strcat(temp, ".lok");
1934 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1935 what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
1946 void remove_loc(void)
1948 #ifdef VERIFY_SAVEFILE
1950 #endif /* VERIFY_SAVEFILE */
1955 /* Get "games" permissions */
1958 # endif /* SECURE */
1959 #endif /* SET_UID */
1961 #ifdef VERIFY_SAVEFILE
1963 /* Lock on savefile */
1964 strcpy(temp, savefile);
1965 strcat(temp, ".lok");
1967 /* Remove lock file */
1970 #endif /* VERIFY_SAVEFILE */
1975 /* Drop "games" permissions */
1978 # endif /* SECURE */
1979 #endif /* SET_UID */
1985 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporary saved floor file
1986 * @param sf_ptr 保存フロア参照ポインタ
1989 static bool save_floor_aux(saved_floor_type *sf_ptr)
1993 /* Compact the objects */
1995 /* Compact the monsters */
1996 compact_monsters(0);
1999 /*** Actually write the file ***/
2001 /* Initial value of xor_byte */
2002 tmp8u = (byte)randint0(256);
2007 /* Reset the checksum */
2011 /* Write the sign of this process */
2012 wr_u32b(saved_floor_file_sign);
2014 /* Dump the dungeon floor */
2015 wr_saved_floor(sf_ptr);
2018 /* Write the "value check-sum" */
2021 /* Write the "encoded checksum" */
2026 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2028 /* Successful save */
2034 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporarily saved-floor data
2035 * @param sf_ptr 保存フロア参照ポインタ
2036 * @param mode 保存オプション
2039 bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
2041 FILE *old_fff = NULL;
2042 byte old_xor_byte = 0;
2043 u32b old_v_stamp = 0;
2044 u32b old_x_stamp = 0;
2046 char floor_savefile[1024];
2050 if (!(mode & SLF_SECOND))
2054 /* Get "games" permissions */
2060 /* We have one file already opened */
2063 /* Backup original values */
2065 old_xor_byte = xor_byte;
2066 old_v_stamp = v_stamp;
2067 old_x_stamp = x_stamp;
2071 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2073 /* Grab permissions */
2077 fd_kill(floor_savefile);
2079 /* Drop permissions */
2083 /* Attempt to save the player */
2088 /* File type is "SAVE" */
2089 FILE_TYPE(FILE_TYPE_SAVE);
2091 /* Grab permissions */
2094 /* Create the savefile */
2095 fd = fd_make(floor_savefile, 0644);
2097 /* Drop permissions */
2103 /* Close the "fd" */
2106 /* Grab permissions */
2109 /* Open the savefile */
2110 fff = my_fopen(floor_savefile, "wb");
2112 /* Drop permissions */
2115 /* Successful open */
2118 /* Write the savefile */
2119 if (save_floor_aux(sf_ptr)) ok = TRUE;
2121 /* Attempt to close it */
2122 if (my_fclose(fff)) ok = FALSE;
2125 /* Remove "broken" files */
2128 /* Grab permissions */
2131 (void)fd_kill(floor_savefile);
2133 /* Drop permissions */
2138 if (!(mode & SLF_SECOND))
2142 /* Drop "games" permissions */
2148 /* We have one file already opened */
2151 /* Restore original values */
2153 xor_byte = old_xor_byte;
2154 v_stamp = old_v_stamp;
2155 x_stamp = old_x_stamp;
2158 /* Return the result */