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.
22 #include "floor-events.h"
23 #include "floor-save.h"
29 * Some "local" parameters, used to help write savefiles
32 static FILE *fff; /* Current save "file" */
33 static byte xor_byte; /* Simple encryption */
34 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
35 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
40 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
44 static void sf_put(byte v)
46 /* Encode the value, write a character */
48 (void)putc((int)xor_byte, fff);
50 /* Maintain the checksum info */
56 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
60 static void wr_byte(byte v)
66 * @brief 符号なし16ビットをファイルに書き込む
67 * @param v 書き込む符号なし16bit値
70 static void wr_u16b(u16b v)
72 sf_put((byte)(v & 0xFF));
73 sf_put((byte)((v >> 8) & 0xFF));
77 * @brief 符号あり16ビットをファイルに書き込む
78 * @param v 書き込む符号あり16bit値
81 static void wr_s16b(s16b v)
87 * @brief 符号なし32ビットをファイルに書き込む
88 * @param v 書き込む符号なし32bit値
91 static void wr_u32b(u32b v)
93 sf_put((byte)(v & 0xFF));
94 sf_put((byte)((v >> 8) & 0xFF));
95 sf_put((byte)((v >> 16) & 0xFF));
96 sf_put((byte)((v >> 24) & 0xFF));
100 * @brief 符号あり32ビットをファイルに書き込む
101 * @param v 書き込む符号あり32bit値
104 static void wr_s32b(s32b v)
110 * @brief 文字列をファイルに書き込む
114 static void wr_string(concptr str)
126 * These functions write info in larger logical records
131 * @brief アイテムオブジェクトを書き込む / Write an "item" record
132 * @param o_ptr アイテムオブジェクト保存元ポインタ
135 static void wr_item(object_type *o_ptr)
137 BIT_FLAGS flags = 0x00000000;
139 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
140 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
141 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
142 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
143 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
144 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
145 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
146 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
147 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
148 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
149 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
150 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
151 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
152 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
153 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
154 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
155 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
156 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
157 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
158 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
159 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
160 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
161 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
162 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
163 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
164 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
165 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
166 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
167 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
169 /*** Item save flags ***/
172 /*** Write only un-obvious elements ***/
173 wr_s16b(o_ptr->k_idx);
175 wr_byte((byte_hack)o_ptr->iy);
176 wr_byte((byte_hack)o_ptr->ix);
178 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
180 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
181 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
183 wr_s16b((s16b)o_ptr->weight);
185 if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
186 if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
187 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
189 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
190 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
191 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
192 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
193 if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
194 if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
196 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
198 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
200 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
201 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
202 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
203 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
204 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
206 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
208 /* Held by monster index */
209 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
211 /* Extra information */
212 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
213 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
214 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
215 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
216 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
219 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
221 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
222 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
227 * @brief モンスター情報を書き込む / Write a "monster" record
228 * @param m_ptr モンスター情報保存元ポインタ
231 static void wr_monster(monster_type *m_ptr)
233 BIT_FLAGS flags = 0x00000000;
236 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
237 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
238 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
239 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
240 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
241 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
242 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
243 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
244 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
245 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
246 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
247 if (m_ptr->smart) flags |= SAVE_MON_SMART;
248 if (m_ptr->exp) flags |= SAVE_MON_EXP;
249 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
250 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
251 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
253 /*** Monster save flags ***/
256 /*** Write only un-obvious elements ***/
257 wr_s16b(m_ptr->r_idx);
258 wr_byte((byte_hack)m_ptr->fy);
259 wr_byte((byte_hack)m_ptr->fx);
260 wr_s16b((s16b)m_ptr->hp);
261 wr_s16b((s16b)m_ptr->maxhp);
262 wr_s16b((s16b)m_ptr->max_maxhp);
263 wr_u32b(m_ptr->dealt_damage);
266 /* Monster race index of its appearance */
267 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
269 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
270 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
272 wr_byte((byte)m_ptr->mspeed);
273 wr_s16b(m_ptr->energy_need);
275 if (flags & SAVE_MON_FAST)
277 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
280 if (flags & SAVE_MON_SLOW)
282 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
285 if (flags & SAVE_MON_STUNNED)
287 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
290 if (flags & SAVE_MON_CONFUSED)
292 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
295 if (flags & SAVE_MON_MONFEAR)
297 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
300 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
301 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
302 if (flags & SAVE_MON_INVULNER)
304 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
307 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
308 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
309 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
310 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
311 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
316 * @brief モンスターの思い出を書き込む / Write a "lore" record
317 * @param r_idx モンスター種族ID
320 static void wr_lore(MONRACE_IDX r_idx)
322 monster_race *r_ptr = &r_info[r_idx];
324 /* Count sights/deaths/kills */
325 wr_s16b((s16b)r_ptr->r_sights);
326 wr_s16b((s16b)r_ptr->r_deaths);
327 wr_s16b((s16b)r_ptr->r_pkills);
328 wr_s16b((s16b)r_ptr->r_akills);
329 wr_s16b((s16b)r_ptr->r_tkills);
331 /* Count wakes and ignores */
332 wr_byte(r_ptr->r_wake);
333 wr_byte(r_ptr->r_ignore);
336 wr_byte(r_ptr->r_xtra1);
337 wr_byte(r_ptr->r_xtra2);
340 wr_byte((byte_hack)r_ptr->r_drop_gold);
341 wr_byte((byte_hack)r_ptr->r_drop_item);
344 wr_byte(0); /* unused now */
345 wr_byte(r_ptr->r_cast_spell);
347 /* Count blows of each type */
348 wr_byte(r_ptr->r_blows[0]);
349 wr_byte(r_ptr->r_blows[1]);
350 wr_byte(r_ptr->r_blows[2]);
351 wr_byte(r_ptr->r_blows[3]);
354 wr_u32b(r_ptr->r_flags1);
355 wr_u32b(r_ptr->r_flags2);
356 wr_u32b(r_ptr->r_flags3);
357 wr_u32b(r_ptr->r_flags4);
358 wr_u32b(r_ptr->r_flags5);
359 wr_u32b(r_ptr->r_flags6);
360 wr_u32b(r_ptr->r_flagsr);
362 /* Monster limit per level */
363 wr_byte((byte_hack)r_ptr->max_num);
365 /* Location in saved floor */
366 wr_s16b(r_ptr->floor_id);
373 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
374 * @param k_idx ベースアイテムのID
377 static void wr_xtra(KIND_OBJECT_IDX k_idx)
381 object_kind *k_ptr = &k_info[k_idx];
383 if (k_ptr->aware) tmp8u |= 0x01;
384 if (k_ptr->tried) tmp8u |= 0x02;
391 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
392 * @param st_ptr 店舗情報の参照ポインタ
395 static void wr_store(store_type *st_ptr)
399 /* Save the "open" counter */
400 wr_u32b(st_ptr->store_open);
402 /* Save the "insults" */
403 wr_s16b(st_ptr->insult_cur);
405 /* Save the current owner */
406 wr_byte(st_ptr->owner);
408 /* Save the stock size */
409 wr_s16b(st_ptr->stock_num);
411 /* Save the "haggle" info */
412 wr_s16b(st_ptr->good_buy);
413 wr_s16b(st_ptr->bad_buy);
415 wr_s32b(st_ptr->last_visit);
418 for (j = 0; j < st_ptr->stock_num; j++)
420 /* Save each item in stock */
421 wr_item(&st_ptr->stock[j]);
427 * @brief セーブデータに乱数情報を書き込む / Write RNG state
430 static errr wr_randomizer(void)
436 for (i = 0; i < RAND_DEG; i++)
438 wr_u32b(Rand_state[i]);
446 * @brief ゲームオプション情報を書き込む / Write the "options"
449 static void wr_options(void)
458 for (i = 0; i < 4; i++) wr_u32b(0L);
461 /*** Special Options ***/
463 /* Write "delay_factor" */
464 wr_byte(delay_factor);
466 /* Write "hitpoint_warn" */
467 wr_byte(hitpoint_warn);
469 /* Write "mana_warn" */
472 /*** Cheating options ***/
476 if (p_ptr->wizard) c |= 0x0002;
478 if (cheat_sight) c |= 0x0040;
479 if (cheat_turn) c |= 0x0080;
481 if (cheat_peek) c |= 0x0100;
482 if (cheat_hear) c |= 0x0200;
483 if (cheat_room) c |= 0x0400;
484 if (cheat_xtra) c |= 0x0800;
485 if (cheat_know) c |= 0x1000;
486 if (cheat_live) c |= 0x2000;
487 if (cheat_save) c |= 0x4000;
488 if (cheat_diary_output) c |= 0x8000;
495 wr_s16b(autosave_freq);
497 /*** Extract options ***/
499 /* Analyze the options */
500 for (i = 0; option_info[i].o_desc; i++)
502 int os = option_info[i].o_set;
503 int ob = option_info[i].o_bit;
505 /* Process real entries */
506 if (option_info[i].o_var)
509 if (*option_info[i].o_var)
512 option_flag[os] |= (1L << ob);
519 option_flag[os] &= ~(1L << ob);
525 /*** Normal options ***/
528 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
531 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
534 /*** Window options ***/
537 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
540 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
545 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
548 static void wr_ghost(void)
553 wr_string(_("不正なゴースト", "Broken Ghost"));
555 /* Hack -- stupid data */
556 for (i = 0; i < 60; i++) wr_byte(0);
561 * @brief クイック・スタート情報を書き込む / Save quick start data
564 static void save_quick_start(void)
568 wr_byte(previous_char.psex);
569 wr_byte((byte_hack)previous_char.prace);
570 wr_byte((byte_hack)previous_char.pclass);
571 wr_byte((byte_hack)previous_char.pseikaku);
572 wr_byte((byte_hack)previous_char.realm1);
573 wr_byte((byte_hack)previous_char.realm2);
575 wr_s16b(previous_char.age);
576 wr_s16b(previous_char.ht);
577 wr_s16b(previous_char.wt);
578 wr_s16b(previous_char.sc);
579 wr_s32b(previous_char.au);
581 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
582 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
584 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
586 wr_s16b(previous_char.chaos_patron);
588 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
590 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
592 /* UNUSED : Was number of random quests */
595 /* No quick start after using debug mode or cheat options */
596 if (p_ptr->noscore) previous_char.quick_ok = FALSE;
598 wr_byte((byte)previous_char.quick_ok);
603 * @brief その他の情報を書き込む / Write some "extra" info
606 static void wr_extra(void)
611 wr_string(p_ptr->name);
612 wr_string(p_ptr->died_from);
613 wr_string(p_ptr->last_message ? p_ptr->last_message : "");
617 for (i = 0; i < 4; i++)
619 wr_string(p_ptr->history[i]);
622 /* Race/Class/Gender/Spells */
623 wr_byte((byte_hack)p_ptr->prace);
624 wr_byte((byte_hack)p_ptr->pclass);
625 wr_byte((byte_hack)p_ptr->pseikaku);
626 wr_byte((byte_hack)p_ptr->psex);
627 wr_byte((byte_hack)p_ptr->realm1);
628 wr_byte((byte_hack)p_ptr->realm2);
631 wr_byte((byte)p_ptr->hitdie);
632 wr_u16b(p_ptr->expfact);
638 /* Dump the stats (maximum and current) */
639 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max[i]);
640 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max_max[i]);
641 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_cur[i]);
643 /* Ignore the transient stats */
644 for (i = 0; i < 12; ++i) wr_s16b(0);
648 wr_u32b(p_ptr->max_exp);
649 wr_u32b(p_ptr->max_max_exp);
651 wr_u32b(p_ptr->exp_frac);
654 for (i = 0; i < 64; i++) wr_s16b(p_ptr->spell_exp[i]);
655 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(p_ptr->weapon_exp[i][j]);
656 for (i = 0; i < GINOU_MAX; i++) wr_s16b(p_ptr->skill_exp[i]);
657 for (i = 0; i < 108; i++) wr_s32b(p_ptr->magic_num1[i]);
658 for (i = 0; i < 108; i++) wr_byte(p_ptr->magic_num2[i]);
660 wr_byte((byte_hack)p_ptr->start_race);
661 wr_s32b(p_ptr->old_race1);
662 wr_s32b(p_ptr->old_race2);
663 wr_s16b(p_ptr->old_realm);
665 for (i = 0; i < MAX_MANE; i++)
667 wr_s16b((s16b)p_ptr->mane_spell[i]);
668 wr_s16b((s16b)p_ptr->mane_dam[i]);
670 wr_s16b(p_ptr->mane_num);
672 for (i = 0; i < MAX_KUBI; i++)
674 wr_s16b(current_world_ptr->bounty_r_idx[i]);
677 for (i = 0; i < 4; i++)
679 wr_s16b(battle_mon[i]);
680 wr_u32b(mon_odds[i]);
683 wr_s16b(p_ptr->town_num); /* -KMW- */
685 /* Write arena and rewards information -KMW- */
686 wr_s16b(p_ptr->arena_number);
687 wr_s16b(p_ptr->inside_arena);
688 wr_s16b(p_ptr->inside_quest);
689 wr_s16b(p_ptr->inside_battle);
690 wr_byte(p_ptr->exit_bldg);
691 wr_byte(0); /* Unused */
693 wr_s16b((s16b)p_ptr->oldpx);
694 wr_s16b((s16b)p_ptr->oldpy);
696 /* Was number of p_ptr->rewards[] */
701 wr_u32b(p_ptr->chp_frac);
705 wr_u32b(p_ptr->csp_frac);
707 /* Max Player and Dungeon Levels */
708 wr_s16b(p_ptr->max_plv);
709 tmp8u = (byte)max_d_idx;
711 for (i = 0; i < tmp8u; i++)
712 wr_s16b((s16b)max_dlv[i]);
720 wr_s16b(p_ptr->concent);
722 wr_s16b(0); /* old "rest" */
723 wr_s16b(p_ptr->blind);
724 wr_s16b(p_ptr->paralyzed);
725 wr_s16b(p_ptr->confused);
726 wr_s16b(p_ptr->food);
727 wr_s16b(0); /* old "food_digested" */
728 wr_s16b(0); /* old "protection" */
729 wr_s16b(p_ptr->energy_need);
730 wr_s16b(p_ptr->enchant_energy_need);
731 wr_s16b(p_ptr->fast);
732 wr_s16b(p_ptr->slow);
733 wr_s16b(p_ptr->afraid);
735 wr_s16b(p_ptr->stun);
736 wr_s16b(p_ptr->poisoned);
737 wr_s16b(p_ptr->image);
738 wr_s16b(p_ptr->protevil);
739 wr_s16b(p_ptr->invuln);
740 wr_s16b(p_ptr->ult_res);
741 wr_s16b(p_ptr->hero);
742 wr_s16b(p_ptr->shero);
743 wr_s16b(p_ptr->shield);
744 wr_s16b(p_ptr->blessed);
745 wr_s16b(p_ptr->tim_invis);
746 wr_s16b(p_ptr->word_recall);
747 wr_s16b(p_ptr->recall_dungeon);
748 wr_s16b(p_ptr->alter_reality);
749 wr_s16b(p_ptr->see_infra);
750 wr_s16b(p_ptr->tim_infra);
751 wr_s16b(p_ptr->oppose_fire);
752 wr_s16b(p_ptr->oppose_cold);
753 wr_s16b(p_ptr->oppose_acid);
754 wr_s16b(p_ptr->oppose_elec);
755 wr_s16b(p_ptr->oppose_pois);
756 wr_s16b(p_ptr->tsuyoshi);
757 wr_s16b(p_ptr->tim_esp);
758 wr_s16b(p_ptr->wraith_form);
759 wr_s16b(p_ptr->resist_magic);
760 wr_s16b(p_ptr->tim_regen);
761 wr_s16b(p_ptr->kabenuke);
762 wr_s16b(p_ptr->tim_stealth);
763 wr_s16b(p_ptr->tim_levitation);
764 wr_s16b(p_ptr->tim_sh_touki);
765 wr_s16b(p_ptr->lightspeed);
766 wr_s16b(p_ptr->tsubureru);
767 wr_s16b(p_ptr->magicdef);
768 wr_s16b(p_ptr->tim_res_nether);
769 wr_s16b(p_ptr->tim_res_time);
770 wr_byte((byte)p_ptr->mimic_form);
771 wr_s16b(p_ptr->tim_mimic);
772 wr_s16b(p_ptr->tim_sh_fire);
773 wr_s16b(p_ptr->tim_sh_holy);
774 wr_s16b(p_ptr->tim_eyeeye);
777 wr_s16b(p_ptr->tim_reflect);
778 wr_s16b(p_ptr->multishadow);
779 wr_s16b(p_ptr->dustrobe);
781 wr_s16b(p_ptr->chaos_patron);
782 wr_u32b(p_ptr->muta1);
783 wr_u32b(p_ptr->muta2);
784 wr_u32b(p_ptr->muta3);
786 for (i = 0; i<8; i++)
787 wr_s16b(p_ptr->virtues[i]);
788 for (i = 0; i<8; i++)
789 wr_s16b(p_ptr->vir_types[i]);
791 wr_s16b(p_ptr->ele_attack);
792 wr_u32b(p_ptr->special_attack);
793 wr_s16b(p_ptr->ele_immune);
794 wr_u32b(p_ptr->special_defense);
795 wr_byte(p_ptr->knowledge);
796 wr_byte(p_ptr->autopick_autoregister);
798 wr_byte((byte_hack)p_ptr->action);
800 wr_byte(preserve_mode);
801 wr_byte(p_ptr->wait_report_score);
804 for (i = 0; i < 12; i++) wr_u32b(0L);
806 /* Ignore some flags */
812 /* Write the "object seeds" */
813 wr_u32b(seed_flavor);
818 wr_u16b(p_ptr->panic_save);
819 wr_u16b(p_ptr->total_winner);
820 wr_u16b(p_ptr->noscore);
824 wr_byte(p_ptr->is_dead);
827 wr_byte(p_ptr->feeling);
829 /* Turn when level began */
830 wr_s32b(current_floor_ptr->generated_turn);
832 /* Turn of last "feeling" */
833 wr_s32b(p_ptr->feeling_turn);
835 /* Current current_world_ptr->game_turn */
836 wr_s32b(current_world_ptr->game_turn);
838 wr_s32b(current_world_ptr->dungeon_turn);
843 wr_s16b(p_ptr->today_mon);
844 wr_s16b(p_ptr->riding);
846 /* Current floor_id */
847 wr_s16b(p_ptr->floor_id);
849 /* Save temporary preserved pets (obsolated) */
852 wr_u32b(current_world_ptr->play_time);
854 wr_s32b(p_ptr->visit);
856 wr_u32b(p_ptr->count);
861 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
862 * @param sf_ptr 保存したいフロアの参照ポインタ
865 static void wr_saved_floor(saved_floor_type *sf_ptr)
867 cave_template_type *templates;
882 /* Dungeon floor specific info follows */
886 /*** Not a saved floor ***/
888 wr_s16b((s16b)current_floor_ptr->dun_level);
892 /*** The saved floor ***/
894 wr_s16b(sf_ptr->floor_id);
895 wr_byte((byte_hack)sf_ptr->savefile_id);
896 wr_s16b((s16b)sf_ptr->dun_level);
897 wr_s32b(sf_ptr->last_visit);
898 wr_u32b(sf_ptr->visit_mark);
899 wr_s16b(sf_ptr->upper_floor_id);
900 wr_s16b(sf_ptr->lower_floor_id);
903 wr_u16b((u16b)current_floor_ptr->base_level);
904 wr_u16b((s16b)current_floor_ptr->num_repro);
905 wr_u16b((u16b)p_ptr->y);
906 wr_u16b((u16b)p_ptr->x);
907 wr_u16b((u16b)current_floor_ptr->height);
908 wr_u16b((u16b)current_floor_ptr->width);
909 wr_byte(p_ptr->feeling);
913 /*********** Make template for grid_type **********/
916 * Usually number of templates are fewer than 255. Even if
917 * more than 254 are exist, the occurrence of each template
918 * with larger ID is very small when we sort templates by
919 * occurrence. So we will use two (or more) bytes for
920 * templete ID larger than 254.
922 * Ex: 256 will be "0xff" "0x01".
923 * 515 will be "0xff" "0xff" "0x03"
926 /* Fake max number */
929 /* Allocate the "template" array */
930 C_MAKE(templates, max_num_temp, cave_template_type);
932 /* Extract template array */
933 for (y = 0; y < current_floor_ptr->height; y++)
935 for (x = 0; x < current_floor_ptr->width; x++)
937 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
939 for (i = 0; i < num_temp; i++)
941 if (templates[i].info == g_ptr->info &&
942 templates[i].feat == g_ptr->feat &&
943 templates[i].mimic == g_ptr->mimic &&
944 templates[i].special == g_ptr->special)
946 /* Same terrain is exist */
947 templates[i].occurrence++;
952 /* Are there same one? */
953 if (i < num_temp) continue;
955 /* If the max_num_temp is too small, increase it. */
956 if (num_temp >= max_num_temp)
958 cave_template_type *old_template = templates;
960 /* Re-allocate the "template" array */
961 C_MAKE(templates, max_num_temp + 255, cave_template_type);
962 (void)C_COPY(templates, old_template, max_num_temp, cave_template_type);
963 C_KILL(old_template, max_num_temp, cave_template_type);
967 /* Add new template */
968 templates[num_temp].info = g_ptr->info;
969 templates[num_temp].feat = g_ptr->feat;
970 templates[num_temp].mimic = g_ptr->mimic;
971 templates[num_temp].special = g_ptr->special;
972 templates[num_temp].occurrence = 1;
974 /* Increase number of template */
979 /* Sort by occurrence */
980 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
982 /*** Dump templates ***/
984 /* Total templates */
987 /* Dump the templates */
988 for (i = 0; i < num_temp; i++)
990 cave_template_type *ct_ptr = &templates[i];
993 wr_u16b((u16b)ct_ptr->info);
994 wr_s16b(ct_ptr->feat);
995 wr_s16b(ct_ptr->mimic);
996 wr_s16b(ct_ptr->special);
1001 /*** "Run-Length-Encoding" of current_floor_ptr->grid_array ***/
1003 /* Note that this will induce two wasted bytes */
1007 /* Dump the current_floor_ptr->grid_array */
1008 for (y = 0; y < current_floor_ptr->height; y++)
1010 for (x = 0; x < current_floor_ptr->width; x++)
1012 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1014 for (i = 0; i < num_temp; i++)
1016 if (templates[i].info == g_ptr->info &&
1017 templates[i].feat == g_ptr->feat &&
1018 templates[i].mimic == g_ptr->mimic &&
1019 templates[i].special == g_ptr->special)
1026 /* If the run is broken, or too full, flush it */
1027 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
1029 wr_byte((byte)count);
1031 while (prev_u16b >= MAX_UCHAR)
1033 /* Mark as actual data is larger than 254 */
1035 prev_u16b -= MAX_UCHAR;
1038 wr_byte((byte)prev_u16b);
1043 /* Continue the run */
1051 /* Flush the data (if any) */
1054 wr_byte((byte)count);
1056 while (prev_u16b >= MAX_UCHAR)
1058 /* Mark as actual data is larger than 254 */
1060 prev_u16b -= MAX_UCHAR;
1062 wr_byte((byte)prev_u16b);
1066 /* Free the "template" array */
1067 C_KILL(templates, max_num_temp, cave_template_type);
1070 /*** Dump objects ***/
1075 /* Dump the objects */
1076 for (i = 1; i < o_max; i++)
1078 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
1085 /*** Dump the monsters ***/
1087 /* Total monsters */
1090 /* Dump the monsters */
1091 for (i = 1; i < m_max; i++)
1093 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1102 * @brief 現在フロアの書き込み /
1103 * Write the current dungeon (new method)
1106 static bool wr_dungeon(void)
1108 saved_floor_type *cur_sf_ptr;
1115 /* Update lite/view */
1116 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1117 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1121 /* Number of floor_id used from birth */
1122 wr_s16b(max_floor_id);
1124 /* Current dungeon type */
1125 wr_byte((byte_hack)p_ptr->dungeon_idx);
1128 /*** No saved floor (On the surface etc.) ***/
1129 if (!p_ptr->floor_id)
1131 /* No array elements */
1134 /* Write the current floor data */
1135 wr_saved_floor(NULL);
1142 /*** In the dungeon ***/
1144 /* Number of array elements */
1145 wr_byte(MAX_SAVED_FLOORS);
1147 /* Write the saved_floors array */
1148 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1150 saved_floor_type *sf_ptr = &saved_floors[i];
1152 wr_s16b(sf_ptr->floor_id);
1153 wr_byte((byte_hack)sf_ptr->savefile_id);
1154 wr_s16b((s16b)sf_ptr->dun_level);
1155 wr_s32b(sf_ptr->last_visit);
1156 wr_u32b(sf_ptr->visit_mark);
1157 wr_s16b(sf_ptr->upper_floor_id);
1158 wr_s16b(sf_ptr->lower_floor_id);
1161 /* Extract pointer to current floor */
1162 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1164 /* Save current floor to temporal file */
1165 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1167 /* Move data in temporal files to the savefile */
1168 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1170 saved_floor_type *sf_ptr = &saved_floors[i];
1172 /* Unused element */
1173 if (!sf_ptr->floor_id) continue;
1175 /* Load temporal saved floor file */
1176 if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1181 /* Write saved floor data to the save file */
1182 wr_saved_floor(sf_ptr);
1191 /* Restore current floor */
1192 if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1200 * @brief セーブデータの書き込み /
1201 * Actually write a save-file
1204 static bool wr_savefile_new(void)
1215 KIND_OBJECT_IDX k_idx;
1217 /* Compact the objects */
1219 /* Compact the monsters */
1220 compact_monsters(0);
1222 /* Guess at the current time */
1223 now = (u32b)time((time_t *)0);
1226 /* Note the operating system */
1229 /* Note when the file was saved */
1232 /* Note the number of saves */
1236 /*** Actually write the file ***/
1238 /* Dump the file header */
1240 wr_byte(FAKE_VER_MAJOR);
1242 wr_byte(FAKE_VER_MINOR);
1244 wr_byte(FAKE_VER_PATCH);
1247 /* Initial value of xor_byte */
1248 tmp8u = (byte)Rand_external(256);
1252 /* Reset the checksum */
1256 /* Write the savefile version for Hengband 1.1.1 and later */
1257 wr_byte(H_VER_EXTRA);
1258 wr_byte(H_VER_PATCH);
1259 wr_byte(H_VER_MINOR);
1260 wr_byte(H_VER_MAJOR);
1262 /* Operating system */
1266 /* Time file last saved */
1269 /* Number of past lives */
1272 /* Number of times saved */
1283 /* EUC kanji code */
1287 /* SJIS kanji code */
1295 /* Write the RNG state */
1299 /* Write the boolean "options" */
1303 /* Dump the number of "messages" */
1304 tmp32u = message_num();
1305 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1308 /* Dump the messages (oldest first!) */
1309 for (i = tmp32u - 1; i >= 0; i--)
1311 wr_string(message_str((s16b)i));
1314 /* Dump the monster lore */
1317 for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
1319 /* Dump the object memory */
1322 for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
1324 /* Dump the towns */
1328 /* Dump the quests */
1332 /* Dump the quests */
1333 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1336 for (i = 0; i < max_q_idx; i++)
1338 quest_type* const q_ptr = &quest[i];
1340 /* Save status for every quest */
1341 wr_s16b(q_ptr->status);
1343 /* And the dungeon level too */
1344 /* (prevents problems with multi-level quests) */
1345 wr_s16b((s16b)q_ptr->level);
1347 wr_byte((byte_hack)q_ptr->complev);
1348 wr_u32b(q_ptr->comptime);
1350 /* Save quest status if quest is running */
1351 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1353 wr_s16b((s16b)q_ptr->cur_num);
1354 wr_s16b((s16b)q_ptr->max_num);
1355 wr_s16b(q_ptr->type);
1356 wr_s16b(q_ptr->r_idx);
1357 wr_s16b(q_ptr->k_idx);
1358 wr_byte((byte_hack)q_ptr->flags);
1359 wr_byte((byte_hack)q_ptr->dungeon);
1363 /* Dump the position in the wilderness */
1364 wr_s32b(p_ptr->wilderness_x);
1365 wr_s32b(p_ptr->wilderness_y);
1367 wr_byte(p_ptr->wild_mode);
1368 wr_byte(p_ptr->ambush_flag);
1370 wr_s32b(current_world_ptr->max_wild_x);
1371 wr_s32b(current_world_ptr->max_wild_y);
1373 /* Dump the wilderness seeds */
1374 for (i = 0; i < current_world_ptr->max_wild_x; i++)
1376 for (j = 0; j < current_world_ptr->max_wild_y; j++)
1378 wr_u32b(wilderness[j][i].seed);
1382 /* Hack -- Dump the artifacts */
1385 for (i = 0; i < tmp16u; i++)
1387 artifact_type *a_ptr = &a_info[i];
1388 wr_byte(a_ptr->cur_num);
1389 wr_s16b(a_ptr->floor_id);
1394 /* Write the "extra" information */
1397 /* Dump the "player hp" entries */
1398 tmp16u = PY_MAX_LEVEL;
1400 for (i = 0; i < tmp16u; i++)
1402 wr_s16b((s16b)p_ptr->player_hp[i]);
1406 /* Write spell data */
1407 wr_u32b(p_ptr->spell_learned1);
1408 wr_u32b(p_ptr->spell_learned2);
1409 wr_u32b(p_ptr->spell_worked1);
1410 wr_u32b(p_ptr->spell_worked2);
1411 wr_u32b(p_ptr->spell_forgotten1);
1412 wr_u32b(p_ptr->spell_forgotten2);
1414 wr_s16b(p_ptr->learned_spells);
1415 wr_s16b(p_ptr->add_spells);
1417 /* Dump the ordered spells */
1418 for (i = 0; i < 64; i++)
1420 wr_byte((byte_hack)p_ptr->spell_order[i]);
1424 /* Write the inventory */
1425 for (i = 0; i < INVEN_TOTAL; i++)
1427 object_type *o_ptr = &inventory[i];
1428 if (!o_ptr->k_idx) continue;
1437 /* Add a sentinel */
1440 /* Note the towns */
1444 /* Note the stores */
1445 tmp16u = MAX_STORES;
1448 /* Dump the stores of all towns */
1449 for (i = 1; i < max_towns; i++)
1451 for (j = 0; j < MAX_STORES; j++)
1453 wr_store(&town_info[i].store[j]);
1457 /* Write the pet command settings */
1458 wr_s16b(p_ptr->pet_follow_distance);
1459 wr_s16b(p_ptr->pet_extra_flags);
1461 /* Write screen dump for sending score */
1462 if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead))
1464 wr_string(screen_dump);
1471 /* Player is not dead, write the dungeon */
1472 if (!p_ptr->is_dead)
1474 /* Dump the dungeon */
1475 if (!wr_dungeon()) return FALSE;
1477 /* Dump the ghost */
1485 /* Write the "value check-sum" */
1488 /* Write the "encoded checksum" */
1493 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1495 /* Successful save */
1501 * @brief セーブデータ書き込みのサブルーチン /
1502 * Medium level player saver
1505 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1507 static bool save_player_aux(char *name)
1516 /* File type is "SAVE" */
1517 FILE_TYPE(FILE_TYPE_SAVE);
1519 /* Grab permissions */
1522 /* Create the savefile */
1523 fd = fd_make(name, mode);
1525 /* Drop permissions */
1531 /* Close the "fd" */
1534 /* Grab permissions */
1537 /* Open the savefile */
1538 fff = my_fopen(name, "wb");
1540 /* Drop permissions */
1543 /* Successful open */
1546 /* Write the savefile */
1547 if (wr_savefile_new()) ok = TRUE;
1549 /* Attempt to close it */
1550 if (my_fclose(fff)) ok = FALSE;
1553 /* Grab permissions */
1556 /* Remove "broken" files */
1557 if (!ok) (void)fd_kill(name);
1559 /* Drop permissions */
1565 if (!ok) return (FALSE);
1567 counts_write(0, current_world_ptr->play_time);
1569 /* Successful save */
1570 character_saved = TRUE;
1579 * @brief セーブデータ書き込みのメインルーチン /
1580 * Attempt to save the player in a savefile
1583 bool save_player(void)
1585 bool result = FALSE;
1594 /* Get "games" permissions */
1603 strcpy(safe, savefile);
1604 strcat(safe, ".new");
1606 /* Grab permissions */
1612 /* Drop permissions */
1617 /* Attempt to save the player */
1618 if (save_player_aux(safe))
1623 strcpy(temp, savefile);
1624 strcat(temp, ".old");
1626 /* Grab permissions */
1632 /* Preserve old savefile */
1633 fd_move(savefile, temp);
1635 /* Activate new savefile */
1636 fd_move(safe, savefile);
1638 /* Remove preserved savefile */
1641 /* Drop permissions */
1644 /* Hack -- Pretend the character was loaded */
1645 character_loaded = TRUE;
1647 #ifdef VERIFY_SAVEFILE
1649 /* Lock on savefile */
1650 strcpy(temp, savefile);
1651 strcat(temp, ".lok");
1653 /* Grab permissions */
1656 /* Remove lock file */
1659 /* Drop permissions */
1673 /* Drop "games" permissions */
1680 /* Return the result */
1686 * @brief セーブデータ読み込みのメインルーチン /
1687 * Attempt to Load a "savefile"
1691 * Version 2.7.0 introduced a slightly different "savefile" format from
1692 * older versions, requiring a completely different parsing method.
1694 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1696 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1698 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1700 * On multi-user systems, you may only "read" a savefile if you will be
1701 * allowed to "write" it later, this prevents painful situations in which
1702 * the player loads a savefile belonging to someone else, and then is not
1703 * allowed to save his game when he quits.
1705 * We return "TRUE" if the savefile was usable, and we set the global
1706 * flag "character_loaded" if a real, living, character was loaded.
1708 * Note that we always try to load the "current" savefile, even if
1709 * there is no such file, so we must check for "empty" savefile names.
1712 bool load_player(void)
1720 #ifdef VERIFY_TIMESTAMP
1721 struct stat statbuf;
1724 concptr what = "generic";
1726 current_world_ptr->game_turn = 0;
1727 p_ptr->is_dead = FALSE;
1730 /* Allow empty savefile name */
1731 if (!savefile[0]) return (TRUE);
1734 #if !defined(MACINTOSH) && !defined(WINDOWS)
1738 /* Verify the existance of the savefile */
1739 if (access(savefile, 0) < 0)
1741 /* Give a message */
1742 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1753 #ifdef VERIFY_SAVEFILE
1755 /* Verify savefile usage */
1762 /* Extract name of lock file */
1763 strcpy(temp, savefile);
1764 strcat(temp, ".lok");
1766 /* Check for lock */
1767 fkk = my_fopen(temp, "r");
1769 /* Oops, lock exists */
1774 msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
1780 /* Create a lock file */
1781 fkk = my_fopen(temp, "w");
1783 /* Dump a line of info */
1784 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1786 /* Close the lock file */
1795 /* Open the savefile */
1796 fd = fd_open(savefile, O_RDONLY);
1799 if (fd < 0) err = -1;
1801 /* Message (below) */
1802 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1809 #ifdef VERIFY_TIMESTAMP
1810 /* Get the timestamp */
1811 (void)fstat(fd, &statbuf);
1814 /* Read the first four bytes */
1815 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1818 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1826 /* Extract version */
1834 /* Attempt to load */
1835 err = rd_savefile_new();
1837 /* Message (below) */
1838 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1842 /* Invalid current_world_ptr->game_turn */
1843 if (!current_world_ptr->game_turn) err = -1;
1845 /* Message (below) */
1846 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1849 #ifdef VERIFY_TIMESTAMP
1850 /* Verify timestamp */
1851 if (!err && !arg_wizard)
1853 /* Hack -- Verify the timestamp */
1854 if (sf_when > (statbuf.st_ctime + 100) ||
1855 sf_when < (statbuf.st_ctime - 100))
1857 what = _("無効なタイム・スタンプです", "Invalid timestamp");
1867 /* Give a conversion warning */
1868 if ((FAKE_VER_MAJOR != z_major) ||
1869 (FAKE_VER_MINOR != z_minor) ||
1870 (FAKE_VER_PATCH != z_patch))
1872 if (z_major == 2 && z_minor == 0 && z_patch == 6)
1874 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1878 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1879 (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
1884 /* Player is dead */
1890 /* A character was loaded */
1891 character_loaded = TRUE;
1895 /* Player is no longer "dead" */
1896 p_ptr->is_dead = FALSE;
1904 /* A character was loaded */
1905 character_loaded = TRUE;
1908 u32b tmp = counts_read(2);
1909 if (tmp > p_ptr->count)
1911 if (counts_read(0) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
1912 counts_write(2, ++p_ptr->count);
1913 counts_write(1, current_world_ptr->play_time);
1921 #ifdef VERIFY_SAVEFILE
1923 /* Verify savefile usage */
1928 /* Extract name of lock file */
1929 strcpy(temp, savefile);
1930 strcat(temp, ".lok");
1938 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1939 what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
1950 void remove_loc(void)
1952 #ifdef VERIFY_SAVEFILE
1954 #endif /* VERIFY_SAVEFILE */
1959 /* Get "games" permissions */
1962 # endif /* SECURE */
1963 #endif /* SET_UID */
1965 #ifdef VERIFY_SAVEFILE
1967 /* Lock on savefile */
1968 strcpy(temp, savefile);
1969 strcat(temp, ".lok");
1971 /* Remove lock file */
1974 #endif /* VERIFY_SAVEFILE */
1979 /* Drop "games" permissions */
1982 # endif /* SECURE */
1983 #endif /* SET_UID */
1989 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporal saved floor file
1990 * @param sf_ptr 保存フロア参照ポインタ
1993 static bool save_floor_aux(saved_floor_type *sf_ptr)
1997 /* Compact the objects */
1999 /* Compact the monsters */
2000 compact_monsters(0);
2003 /*** Actually write the file ***/
2005 /* Initial value of xor_byte */
2006 tmp8u = (byte)randint0(256);
2011 /* Reset the checksum */
2015 /* Write the sign of this process */
2016 wr_u32b(saved_floor_file_sign);
2018 /* Dump the dungeon floor */
2019 wr_saved_floor(sf_ptr);
2022 /* Write the "value check-sum" */
2025 /* Write the "encoded checksum" */
2030 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2032 /* Successful save */
2038 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data
2039 * @param sf_ptr 保存フロア参照ポインタ
2040 * @param mode 保存オプション
2043 bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
2045 FILE *old_fff = NULL;
2046 byte old_xor_byte = 0;
2047 u32b old_v_stamp = 0;
2048 u32b old_x_stamp = 0;
2050 char floor_savefile[1024];
2054 if (!(mode & SLF_SECOND))
2058 /* Get "games" permissions */
2064 /* We have one file already opened */
2067 /* Backup original values */
2069 old_xor_byte = xor_byte;
2070 old_v_stamp = v_stamp;
2071 old_x_stamp = x_stamp;
2075 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2077 /* Grab permissions */
2081 fd_kill(floor_savefile);
2083 /* Drop permissions */
2087 /* Attempt to save the player */
2092 /* File type is "SAVE" */
2093 FILE_TYPE(FILE_TYPE_SAVE);
2095 /* Grab permissions */
2098 /* Create the savefile */
2099 fd = fd_make(floor_savefile, 0644);
2101 /* Drop permissions */
2107 /* Close the "fd" */
2110 /* Grab permissions */
2113 /* Open the savefile */
2114 fff = my_fopen(floor_savefile, "wb");
2116 /* Drop permissions */
2119 /* Successful open */
2122 /* Write the savefile */
2123 if (save_floor_aux(sf_ptr)) ok = TRUE;
2125 /* Attempt to close it */
2126 if (my_fclose(fff)) ok = FALSE;
2129 /* Remove "broken" files */
2132 /* Grab permissions */
2135 (void)fd_kill(floor_savefile);
2137 /* Drop permissions */
2142 if (!(mode & SLF_SECOND))
2146 /* Drop "games" permissions */
2152 /* We have one file already opened */
2155 /* Restore original values */
2157 xor_byte = old_xor_byte;
2158 v_stamp = old_v_stamp;
2159 x_stamp = old_x_stamp;
2162 /* Return the result */