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"
25 * Some "local" parameters, used to help write savefiles
28 static FILE *fff; /* Current save "file" */
29 static byte xor_byte; /* Simple encryption */
30 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
31 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
36 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
40 static void sf_put(byte v)
42 /* Encode the value, write a character */
44 (void)putc((int)xor_byte, fff);
46 /* Maintain the checksum info */
52 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
56 static void wr_byte(byte v)
62 * @brief 符号なし16ビットをファイルに書き込む
63 * @param v 書き込む符号なし16bit値
66 static void wr_u16b(u16b v)
68 sf_put((byte)(v & 0xFF));
69 sf_put((byte)((v >> 8) & 0xFF));
73 * @brief 符号あり16ビットをファイルに書き込む
74 * @param v 書き込む符号あり16bit値
77 static void wr_s16b(s16b v)
83 * @brief 符号なし32ビットをファイルに書き込む
84 * @param v 書き込む符号なし32bit値
87 static void wr_u32b(u32b v)
89 sf_put((byte)(v & 0xFF));
90 sf_put((byte)((v >> 8) & 0xFF));
91 sf_put((byte)((v >> 16) & 0xFF));
92 sf_put((byte)((v >> 24) & 0xFF));
96 * @brief 符号あり32ビットをファイルに書き込む
97 * @param v 書き込む符号あり32bit値
100 static void wr_s32b(s32b v)
106 * @brief 文字列をファイルに書き込む
110 static void wr_string(concptr str)
122 * These functions write info in larger logical records
127 * @brief アイテムオブジェクトを書き込む / Write an "item" record
128 * @param o_ptr アイテムオブジェクト保存元ポインタ
131 static void wr_item(object_type *o_ptr)
133 BIT_FLAGS flags = 0x00000000;
135 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
136 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
137 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
138 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
139 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
140 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
141 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
142 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
143 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
144 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
145 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
146 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
147 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
148 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
149 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
150 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
151 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
152 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
153 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
154 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
155 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
156 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
157 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
158 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
159 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
160 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
161 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
162 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
163 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
165 /*** Item save flags ***/
168 /*** Write only un-obvious elements ***/
169 wr_s16b(o_ptr->k_idx);
171 wr_byte((byte_hack)o_ptr->iy);
172 wr_byte((byte_hack)o_ptr->ix);
174 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
176 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
177 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
179 wr_s16b((s16b)o_ptr->weight);
181 if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
182 if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
183 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
185 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
186 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
187 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
188 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
189 if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
190 if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
192 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
194 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
196 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
197 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
198 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
199 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
200 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
202 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
204 /* Held by monster index */
205 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
207 /* Extra information */
208 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
209 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
210 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
211 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
212 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
215 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
217 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
218 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
223 * @brief モンスター情報を書き込む / Write a "monster" record
224 * @param m_ptr モンスター情報保存元ポインタ
227 static void wr_monster(monster_type *m_ptr)
229 BIT_FLAGS flags = 0x00000000;
232 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
233 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
234 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
235 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
236 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
237 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
238 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
239 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
240 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
241 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
242 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
243 if (m_ptr->smart) flags |= SAVE_MON_SMART;
244 if (m_ptr->exp) flags |= SAVE_MON_EXP;
245 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
246 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
247 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
249 /*** Monster save flags ***/
252 /*** Write only un-obvious elements ***/
253 wr_s16b(m_ptr->r_idx);
254 wr_byte((byte_hack)m_ptr->fy);
255 wr_byte((byte_hack)m_ptr->fx);
256 wr_s16b((s16b)m_ptr->hp);
257 wr_s16b((s16b)m_ptr->maxhp);
258 wr_s16b((s16b)m_ptr->max_maxhp);
259 wr_u32b(m_ptr->dealt_damage);
262 /* Monster race index of its appearance */
263 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
265 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
266 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
268 wr_byte((byte)m_ptr->mspeed);
269 wr_s16b(m_ptr->energy_need);
271 if (flags & SAVE_MON_FAST)
273 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
276 if (flags & SAVE_MON_SLOW)
278 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
281 if (flags & SAVE_MON_STUNNED)
283 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
286 if (flags & SAVE_MON_CONFUSED)
288 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
291 if (flags & SAVE_MON_MONFEAR)
293 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
296 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
297 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
298 if (flags & SAVE_MON_INVULNER)
300 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
303 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
304 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
305 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
306 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
307 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
312 * @brief モンスターの思い出を書き込む / Write a "lore" record
313 * @param r_idx モンスター種族ID
316 static void wr_lore(MONRACE_IDX r_idx)
318 monster_race *r_ptr = &r_info[r_idx];
320 /* Count sights/deaths/kills */
321 wr_s16b((s16b)r_ptr->r_sights);
322 wr_s16b((s16b)r_ptr->r_deaths);
323 wr_s16b((s16b)r_ptr->r_pkills);
324 wr_s16b((s16b)r_ptr->r_akills);
325 wr_s16b((s16b)r_ptr->r_tkills);
327 /* Count wakes and ignores */
328 wr_byte(r_ptr->r_wake);
329 wr_byte(r_ptr->r_ignore);
332 wr_byte(r_ptr->r_xtra1);
333 wr_byte(r_ptr->r_xtra2);
336 wr_byte((byte_hack)r_ptr->r_drop_gold);
337 wr_byte((byte_hack)r_ptr->r_drop_item);
340 wr_byte(0); /* unused now */
341 wr_byte(r_ptr->r_cast_spell);
343 /* Count blows of each type */
344 wr_byte(r_ptr->r_blows[0]);
345 wr_byte(r_ptr->r_blows[1]);
346 wr_byte(r_ptr->r_blows[2]);
347 wr_byte(r_ptr->r_blows[3]);
350 wr_u32b(r_ptr->r_flags1);
351 wr_u32b(r_ptr->r_flags2);
352 wr_u32b(r_ptr->r_flags3);
353 wr_u32b(r_ptr->r_flags4);
354 wr_u32b(r_ptr->r_flags5);
355 wr_u32b(r_ptr->r_flags6);
356 wr_u32b(r_ptr->r_flagsr);
358 /* Monster limit per level */
359 wr_byte((byte_hack)r_ptr->max_num);
361 /* Location in saved floor */
362 wr_s16b(r_ptr->floor_id);
369 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
370 * @param k_idx ベースアイテムのID
373 static void wr_xtra(KIND_OBJECT_IDX k_idx)
377 object_kind *k_ptr = &k_info[k_idx];
379 if (k_ptr->aware) tmp8u |= 0x01;
380 if (k_ptr->tried) tmp8u |= 0x02;
387 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
388 * @param st_ptr 店舗情報の参照ポインタ
391 static void wr_store(store_type *st_ptr)
395 /* Save the "open" counter */
396 wr_u32b(st_ptr->store_open);
398 /* Save the "insults" */
399 wr_s16b(st_ptr->insult_cur);
401 /* Save the current owner */
402 wr_byte(st_ptr->owner);
404 /* Save the stock size */
405 wr_s16b(st_ptr->stock_num);
407 /* Save the "haggle" info */
408 wr_s16b(st_ptr->good_buy);
409 wr_s16b(st_ptr->bad_buy);
411 wr_s32b(st_ptr->last_visit);
414 for (j = 0; j < st_ptr->stock_num; j++)
416 /* Save each item in stock */
417 wr_item(&st_ptr->stock[j]);
423 * @brief セーブデータに乱数情報を書き込む / Write RNG state
426 static errr wr_randomizer(void)
432 for (i = 0; i < RAND_DEG; i++)
434 wr_u32b(Rand_state[i]);
442 * @brief ゲームオプション情報を書き込む / Write the "options"
445 static void wr_options(void)
454 for (i = 0; i < 4; i++) wr_u32b(0L);
457 /*** Special Options ***/
459 /* Write "delay_factor" */
460 wr_byte(delay_factor);
462 /* Write "hitpoint_warn" */
463 wr_byte(hitpoint_warn);
465 /* Write "mana_warn" */
468 /*** Cheating options ***/
472 if (p_ptr->wizard) c |= 0x0002;
474 if (cheat_sight) c |= 0x0040;
475 if (cheat_turn) c |= 0x0080;
477 if (cheat_peek) c |= 0x0100;
478 if (cheat_hear) c |= 0x0200;
479 if (cheat_room) c |= 0x0400;
480 if (cheat_xtra) c |= 0x0800;
481 if (cheat_know) c |= 0x1000;
482 if (cheat_live) c |= 0x2000;
483 if (cheat_save) c |= 0x4000;
484 if (cheat_diary_output) c |= 0x8000;
491 wr_s16b(autosave_freq);
493 /*** Extract options ***/
495 /* Analyze the options */
496 for (i = 0; option_info[i].o_desc; i++)
498 int os = option_info[i].o_set;
499 int ob = option_info[i].o_bit;
501 /* Process real entries */
502 if (option_info[i].o_var)
505 if (*option_info[i].o_var)
508 option_flag[os] |= (1L << ob);
515 option_flag[os] &= ~(1L << ob);
521 /*** Normal options ***/
524 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
527 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
530 /*** Window options ***/
533 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
536 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
541 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
544 static void wr_ghost(void)
549 wr_string(_("不正なゴースト", "Broken Ghost"));
551 /* Hack -- stupid data */
552 for (i = 0; i < 60; i++) wr_byte(0);
557 * @brief クイック・スタート情報を書き込む / Save quick start data
560 static void save_quick_start(void)
564 wr_byte(previous_char.psex);
565 wr_byte((byte_hack)previous_char.prace);
566 wr_byte((byte_hack)previous_char.pclass);
567 wr_byte((byte_hack)previous_char.pseikaku);
568 wr_byte((byte_hack)previous_char.realm1);
569 wr_byte((byte_hack)previous_char.realm2);
571 wr_s16b(previous_char.age);
572 wr_s16b(previous_char.ht);
573 wr_s16b(previous_char.wt);
574 wr_s16b(previous_char.sc);
575 wr_s32b(previous_char.au);
577 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
578 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
580 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
582 wr_s16b(previous_char.chaos_patron);
584 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
586 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
588 /* UNUSED : Was number of random quests */
591 /* No quick start after using debug mode or cheat options */
592 if (p_ptr->noscore) previous_char.quick_ok = FALSE;
594 wr_byte((byte)previous_char.quick_ok);
599 * @brief その他の情報を書き込む / Write some "extra" info
602 static void wr_extra(void)
607 wr_string(p_ptr->name);
608 wr_string(p_ptr->died_from);
609 wr_string(p_ptr->last_message ? p_ptr->last_message : "");
613 for (i = 0; i < 4; i++)
615 wr_string(p_ptr->history[i]);
618 /* Race/Class/Gender/Spells */
619 wr_byte((byte_hack)p_ptr->prace);
620 wr_byte((byte_hack)p_ptr->pclass);
621 wr_byte((byte_hack)p_ptr->pseikaku);
622 wr_byte((byte_hack)p_ptr->psex);
623 wr_byte((byte_hack)p_ptr->realm1);
624 wr_byte((byte_hack)p_ptr->realm2);
627 wr_byte((byte)p_ptr->hitdie);
628 wr_u16b(p_ptr->expfact);
634 /* Dump the stats (maximum and current) */
635 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max[i]);
636 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max_max[i]);
637 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_cur[i]);
639 /* Ignore the transient stats */
640 for (i = 0; i < 12; ++i) wr_s16b(0);
644 wr_u32b(p_ptr->max_exp);
645 wr_u32b(p_ptr->max_max_exp);
647 wr_u32b(p_ptr->exp_frac);
650 for (i = 0; i < 64; i++) wr_s16b(p_ptr->spell_exp[i]);
651 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(p_ptr->weapon_exp[i][j]);
652 for (i = 0; i < GINOU_MAX; i++) wr_s16b(p_ptr->skill_exp[i]);
653 for (i = 0; i < 108; i++) wr_s32b(p_ptr->magic_num1[i]);
654 for (i = 0; i < 108; i++) wr_byte(p_ptr->magic_num2[i]);
656 wr_byte((byte_hack)p_ptr->start_race);
657 wr_s32b(p_ptr->old_race1);
658 wr_s32b(p_ptr->old_race2);
659 wr_s16b(p_ptr->old_realm);
661 for (i = 0; i < MAX_MANE; i++)
663 wr_s16b((s16b)p_ptr->mane_spell[i]);
664 wr_s16b((s16b)p_ptr->mane_dam[i]);
666 wr_s16b(p_ptr->mane_num);
668 for (i = 0; i < MAX_KUBI; i++)
670 wr_s16b(current_world_ptr->bounty_r_idx[i]);
673 for (i = 0; i < 4; i++)
675 wr_s16b(battle_mon[i]);
676 wr_u32b(mon_odds[i]);
679 wr_s16b(p_ptr->town_num); /* -KMW- */
681 /* Write arena and rewards information -KMW- */
682 wr_s16b(p_ptr->arena_number);
683 wr_s16b(p_ptr->inside_arena);
684 wr_s16b(p_ptr->inside_quest);
685 wr_s16b(p_ptr->inside_battle);
686 wr_byte(p_ptr->exit_bldg);
687 wr_byte(0); /* Unused */
689 wr_s16b((s16b)p_ptr->oldpx);
690 wr_s16b((s16b)p_ptr->oldpy);
692 /* Was number of p_ptr->rewards[] */
697 wr_u32b(p_ptr->chp_frac);
701 wr_u32b(p_ptr->csp_frac);
703 /* Max Player and Dungeon Levels */
704 wr_s16b(p_ptr->max_plv);
705 tmp8u = (byte)max_d_idx;
707 for (i = 0; i < tmp8u; i++)
708 wr_s16b((s16b)max_dlv[i]);
716 wr_s16b(p_ptr->concent);
718 wr_s16b(0); /* old "rest" */
719 wr_s16b(p_ptr->blind);
720 wr_s16b(p_ptr->paralyzed);
721 wr_s16b(p_ptr->confused);
722 wr_s16b(p_ptr->food);
723 wr_s16b(0); /* old "food_digested" */
724 wr_s16b(0); /* old "protection" */
725 wr_s16b(p_ptr->energy_need);
726 wr_s16b(p_ptr->enchant_energy_need);
727 wr_s16b(p_ptr->fast);
728 wr_s16b(p_ptr->slow);
729 wr_s16b(p_ptr->afraid);
731 wr_s16b(p_ptr->stun);
732 wr_s16b(p_ptr->poisoned);
733 wr_s16b(p_ptr->image);
734 wr_s16b(p_ptr->protevil);
735 wr_s16b(p_ptr->invuln);
736 wr_s16b(p_ptr->ult_res);
737 wr_s16b(p_ptr->hero);
738 wr_s16b(p_ptr->shero);
739 wr_s16b(p_ptr->shield);
740 wr_s16b(p_ptr->blessed);
741 wr_s16b(p_ptr->tim_invis);
742 wr_s16b(p_ptr->word_recall);
743 wr_s16b(p_ptr->recall_dungeon);
744 wr_s16b(p_ptr->alter_reality);
745 wr_s16b(p_ptr->see_infra);
746 wr_s16b(p_ptr->tim_infra);
747 wr_s16b(p_ptr->oppose_fire);
748 wr_s16b(p_ptr->oppose_cold);
749 wr_s16b(p_ptr->oppose_acid);
750 wr_s16b(p_ptr->oppose_elec);
751 wr_s16b(p_ptr->oppose_pois);
752 wr_s16b(p_ptr->tsuyoshi);
753 wr_s16b(p_ptr->tim_esp);
754 wr_s16b(p_ptr->wraith_form);
755 wr_s16b(p_ptr->resist_magic);
756 wr_s16b(p_ptr->tim_regen);
757 wr_s16b(p_ptr->kabenuke);
758 wr_s16b(p_ptr->tim_stealth);
759 wr_s16b(p_ptr->tim_levitation);
760 wr_s16b(p_ptr->tim_sh_touki);
761 wr_s16b(p_ptr->lightspeed);
762 wr_s16b(p_ptr->tsubureru);
763 wr_s16b(p_ptr->magicdef);
764 wr_s16b(p_ptr->tim_res_nether);
765 wr_s16b(p_ptr->tim_res_time);
766 wr_byte((byte)p_ptr->mimic_form);
767 wr_s16b(p_ptr->tim_mimic);
768 wr_s16b(p_ptr->tim_sh_fire);
769 wr_s16b(p_ptr->tim_sh_holy);
770 wr_s16b(p_ptr->tim_eyeeye);
773 wr_s16b(p_ptr->tim_reflect);
774 wr_s16b(p_ptr->multishadow);
775 wr_s16b(p_ptr->dustrobe);
777 wr_s16b(p_ptr->chaos_patron);
778 wr_u32b(p_ptr->muta1);
779 wr_u32b(p_ptr->muta2);
780 wr_u32b(p_ptr->muta3);
782 for (i = 0; i<8; i++)
783 wr_s16b(p_ptr->virtues[i]);
784 for (i = 0; i<8; i++)
785 wr_s16b(p_ptr->vir_types[i]);
787 wr_s16b(p_ptr->ele_attack);
788 wr_u32b(p_ptr->special_attack);
789 wr_s16b(p_ptr->ele_immune);
790 wr_u32b(p_ptr->special_defense);
791 wr_byte(p_ptr->knowledge);
792 wr_byte(p_ptr->autopick_autoregister);
794 wr_byte((byte_hack)p_ptr->action);
796 wr_byte(preserve_mode);
797 wr_byte(p_ptr->wait_report_score);
800 for (i = 0; i < 12; i++) wr_u32b(0L);
802 /* Ignore some flags */
808 /* Write the "object seeds" */
809 wr_u32b(seed_flavor);
814 wr_u16b(p_ptr->panic_save);
815 wr_u16b(p_ptr->total_winner);
816 wr_u16b(p_ptr->noscore);
820 wr_byte(p_ptr->is_dead);
823 wr_byte(p_ptr->feeling);
825 /* Turn when level began */
826 wr_s32b(current_floor_ptr->generated_turn);
828 /* Turn of last "feeling" */
829 wr_s32b(p_ptr->feeling_turn);
831 /* Current current_world_ptr->game_turn */
832 wr_s32b(current_world_ptr->game_turn);
834 wr_s32b(current_world_ptr->dungeon_turn);
839 wr_s16b(p_ptr->today_mon);
840 wr_s16b(p_ptr->riding);
842 /* Current floor_id */
843 wr_s16b(p_ptr->floor_id);
845 /* Save temporary preserved pets (obsolated) */
848 wr_u32b(current_world_ptr->play_time);
850 wr_s32b(p_ptr->visit);
852 wr_u32b(p_ptr->count);
857 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
858 * @param sf_ptr 保存したいフロアの参照ポインタ
861 static void wr_saved_floor(saved_floor_type *sf_ptr)
863 cave_template_type *templates;
878 /* Dungeon floor specific info follows */
882 /*** Not a saved floor ***/
884 wr_s16b((s16b)current_floor_ptr->dun_level);
888 /*** The saved floor ***/
890 wr_s16b(sf_ptr->floor_id);
891 wr_byte((byte_hack)sf_ptr->savefile_id);
892 wr_s16b((s16b)sf_ptr->dun_level);
893 wr_s32b(sf_ptr->last_visit);
894 wr_u32b(sf_ptr->visit_mark);
895 wr_s16b(sf_ptr->upper_floor_id);
896 wr_s16b(sf_ptr->lower_floor_id);
899 wr_u16b((u16b)current_floor_ptr->base_level);
900 wr_u16b((s16b)current_floor_ptr->num_repro);
901 wr_u16b((u16b)p_ptr->y);
902 wr_u16b((u16b)p_ptr->x);
903 wr_u16b((u16b)current_floor_ptr->height);
904 wr_u16b((u16b)current_floor_ptr->width);
905 wr_byte(p_ptr->feeling);
909 /*********** Make template for grid_type **********/
912 * Usually number of templates are fewer than 255. Even if
913 * more than 254 are exist, the occurrence of each template
914 * with larger ID is very small when we sort templates by
915 * occurrence. So we will use two (or more) bytes for
916 * templete ID larger than 254.
918 * Ex: 256 will be "0xff" "0x01".
919 * 515 will be "0xff" "0xff" "0x03"
922 /* Fake max number */
925 /* Allocate the "template" array */
926 C_MAKE(templates, max_num_temp, cave_template_type);
928 /* Extract template array */
929 for (y = 0; y < current_floor_ptr->height; y++)
931 for (x = 0; x < current_floor_ptr->width; x++)
933 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
935 for (i = 0; i < num_temp; i++)
937 if (templates[i].info == g_ptr->info &&
938 templates[i].feat == g_ptr->feat &&
939 templates[i].mimic == g_ptr->mimic &&
940 templates[i].special == g_ptr->special)
942 /* Same terrain is exist */
943 templates[i].occurrence++;
948 /* Are there same one? */
949 if (i < num_temp) continue;
951 /* If the max_num_temp is too small, increase it. */
952 if (num_temp >= max_num_temp)
954 cave_template_type *old_template = templates;
956 /* Re-allocate the "template" array */
957 C_MAKE(templates, max_num_temp + 255, cave_template_type);
958 (void)C_COPY(templates, old_template, max_num_temp, cave_template_type);
959 C_KILL(old_template, max_num_temp, cave_template_type);
963 /* Add new template */
964 templates[num_temp].info = g_ptr->info;
965 templates[num_temp].feat = g_ptr->feat;
966 templates[num_temp].mimic = g_ptr->mimic;
967 templates[num_temp].special = g_ptr->special;
968 templates[num_temp].occurrence = 1;
970 /* Increase number of template */
975 /* Sort by occurrence */
976 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
978 /*** Dump templates ***/
980 /* Total templates */
983 /* Dump the templates */
984 for (i = 0; i < num_temp; i++)
986 cave_template_type *ct_ptr = &templates[i];
989 wr_u16b((u16b)ct_ptr->info);
990 wr_s16b(ct_ptr->feat);
991 wr_s16b(ct_ptr->mimic);
992 wr_s16b(ct_ptr->special);
997 /*** "Run-Length-Encoding" of current_floor_ptr->grid_array ***/
999 /* Note that this will induce two wasted bytes */
1003 /* Dump the current_floor_ptr->grid_array */
1004 for (y = 0; y < current_floor_ptr->height; y++)
1006 for (x = 0; x < current_floor_ptr->width; x++)
1008 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1010 for (i = 0; i < num_temp; i++)
1012 if (templates[i].info == g_ptr->info &&
1013 templates[i].feat == g_ptr->feat &&
1014 templates[i].mimic == g_ptr->mimic &&
1015 templates[i].special == g_ptr->special)
1022 /* If the run is broken, or too full, flush it */
1023 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
1025 wr_byte((byte)count);
1027 while (prev_u16b >= MAX_UCHAR)
1029 /* Mark as actual data is larger than 254 */
1031 prev_u16b -= MAX_UCHAR;
1034 wr_byte((byte)prev_u16b);
1039 /* Continue the run */
1047 /* Flush the data (if any) */
1050 wr_byte((byte)count);
1052 while (prev_u16b >= MAX_UCHAR)
1054 /* Mark as actual data is larger than 254 */
1056 prev_u16b -= MAX_UCHAR;
1058 wr_byte((byte)prev_u16b);
1062 /* Free the "template" array */
1063 C_KILL(templates, max_num_temp, cave_template_type);
1066 /*** Dump objects ***/
1071 /* Dump the objects */
1072 for (i = 1; i < o_max; i++)
1074 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
1081 /*** Dump the monsters ***/
1083 /* Total monsters */
1086 /* Dump the monsters */
1087 for (i = 1; i < m_max; i++)
1089 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1098 * @brief 現在フロアの書き込み /
1099 * Write the current dungeon (new method)
1102 static bool wr_dungeon(void)
1104 saved_floor_type *cur_sf_ptr;
1111 /* Update lite/view */
1112 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1113 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1117 /* Number of floor_id used from birth */
1118 wr_s16b(max_floor_id);
1120 /* Current dungeon type */
1121 wr_byte((byte_hack)p_ptr->dungeon_idx);
1124 /*** No saved floor (On the surface etc.) ***/
1125 if (!p_ptr->floor_id)
1127 /* No array elements */
1130 /* Write the current floor data */
1131 wr_saved_floor(NULL);
1138 /*** In the dungeon ***/
1140 /* Number of array elements */
1141 wr_byte(MAX_SAVED_FLOORS);
1143 /* Write the saved_floors array */
1144 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1146 saved_floor_type *sf_ptr = &saved_floors[i];
1148 wr_s16b(sf_ptr->floor_id);
1149 wr_byte((byte_hack)sf_ptr->savefile_id);
1150 wr_s16b((s16b)sf_ptr->dun_level);
1151 wr_s32b(sf_ptr->last_visit);
1152 wr_u32b(sf_ptr->visit_mark);
1153 wr_s16b(sf_ptr->upper_floor_id);
1154 wr_s16b(sf_ptr->lower_floor_id);
1157 /* Extract pointer to current floor */
1158 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1160 /* Save current floor to temporal file */
1161 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1163 /* Move data in temporal files to the savefile */
1164 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1166 saved_floor_type *sf_ptr = &saved_floors[i];
1168 /* Unused element */
1169 if (!sf_ptr->floor_id) continue;
1171 /* Load temporal saved floor file */
1172 if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1177 /* Write saved floor data to the save file */
1178 wr_saved_floor(sf_ptr);
1187 /* Restore current floor */
1188 if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1196 * @brief セーブデータの書き込み /
1197 * Actually write a save-file
1200 static bool wr_savefile_new(void)
1211 KIND_OBJECT_IDX k_idx;
1213 /* Compact the objects */
1215 /* Compact the monsters */
1216 compact_monsters(0);
1218 /* Guess at the current time */
1219 now = (u32b)time((time_t *)0);
1222 /* Note the operating system */
1225 /* Note when the file was saved */
1228 /* Note the number of saves */
1232 /*** Actually write the file ***/
1234 /* Dump the file header */
1236 wr_byte(FAKE_VER_MAJOR);
1238 wr_byte(FAKE_VER_MINOR);
1240 wr_byte(FAKE_VER_PATCH);
1243 /* Initial value of xor_byte */
1244 tmp8u = (byte)Rand_external(256);
1248 /* Reset the checksum */
1252 /* Write the savefile version for Hengband 1.1.1 and later */
1253 wr_byte(H_VER_EXTRA);
1254 wr_byte(H_VER_PATCH);
1255 wr_byte(H_VER_MINOR);
1256 wr_byte(H_VER_MAJOR);
1258 /* Operating system */
1262 /* Time file last saved */
1265 /* Number of past lives */
1268 /* Number of times saved */
1279 /* EUC kanji code */
1283 /* SJIS kanji code */
1291 /* Write the RNG state */
1295 /* Write the boolean "options" */
1299 /* Dump the number of "messages" */
1300 tmp32u = message_num();
1301 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1304 /* Dump the messages (oldest first!) */
1305 for (i = tmp32u - 1; i >= 0; i--)
1307 wr_string(message_str((s16b)i));
1310 /* Dump the monster lore */
1313 for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
1315 /* Dump the object memory */
1318 for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
1320 /* Dump the towns */
1324 /* Dump the quests */
1328 /* Dump the quests */
1329 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1332 for (i = 0; i < max_q_idx; i++)
1334 quest_type* const q_ptr = &quest[i];
1336 /* Save status for every quest */
1337 wr_s16b(q_ptr->status);
1339 /* And the dungeon level too */
1340 /* (prevents problems with multi-level quests) */
1341 wr_s16b((s16b)q_ptr->level);
1343 wr_byte((byte_hack)q_ptr->complev);
1344 wr_u32b(q_ptr->comptime);
1346 /* Save quest status if quest is running */
1347 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1349 wr_s16b((s16b)q_ptr->cur_num);
1350 wr_s16b((s16b)q_ptr->max_num);
1351 wr_s16b(q_ptr->type);
1352 wr_s16b(q_ptr->r_idx);
1353 wr_s16b(q_ptr->k_idx);
1354 wr_byte((byte_hack)q_ptr->flags);
1355 wr_byte((byte_hack)q_ptr->dungeon);
1359 /* Dump the position in the wilderness */
1360 wr_s32b(p_ptr->wilderness_x);
1361 wr_s32b(p_ptr->wilderness_y);
1363 wr_byte(p_ptr->wild_mode);
1364 wr_byte(p_ptr->ambush_flag);
1366 wr_s32b(current_world_ptr->max_wild_x);
1367 wr_s32b(current_world_ptr->max_wild_y);
1369 /* Dump the wilderness seeds */
1370 for (i = 0; i < current_world_ptr->max_wild_x; i++)
1372 for (j = 0; j < current_world_ptr->max_wild_y; j++)
1374 wr_u32b(wilderness[j][i].seed);
1378 /* Hack -- Dump the artifacts */
1381 for (i = 0; i < tmp16u; i++)
1383 artifact_type *a_ptr = &a_info[i];
1384 wr_byte(a_ptr->cur_num);
1385 wr_s16b(a_ptr->floor_id);
1390 /* Write the "extra" information */
1393 /* Dump the "player hp" entries */
1394 tmp16u = PY_MAX_LEVEL;
1396 for (i = 0; i < tmp16u; i++)
1398 wr_s16b((s16b)p_ptr->player_hp[i]);
1402 /* Write spell data */
1403 wr_u32b(p_ptr->spell_learned1);
1404 wr_u32b(p_ptr->spell_learned2);
1405 wr_u32b(p_ptr->spell_worked1);
1406 wr_u32b(p_ptr->spell_worked2);
1407 wr_u32b(p_ptr->spell_forgotten1);
1408 wr_u32b(p_ptr->spell_forgotten2);
1410 wr_s16b(p_ptr->learned_spells);
1411 wr_s16b(p_ptr->add_spells);
1413 /* Dump the ordered spells */
1414 for (i = 0; i < 64; i++)
1416 wr_byte((byte_hack)p_ptr->spell_order[i]);
1420 /* Write the inventory */
1421 for (i = 0; i < INVEN_TOTAL; i++)
1423 object_type *o_ptr = &inventory[i];
1425 /* Skip non-objects */
1426 if (!o_ptr->k_idx) continue;
1435 /* Add a sentinel */
1438 /* Note the towns */
1442 /* Note the stores */
1443 tmp16u = MAX_STORES;
1446 /* Dump the stores of all towns */
1447 for (i = 1; i < max_towns; i++)
1449 for (j = 0; j < MAX_STORES; j++)
1451 wr_store(&town_info[i].store[j]);
1455 /* Write the pet command settings */
1456 wr_s16b(p_ptr->pet_follow_distance);
1457 wr_s16b(p_ptr->pet_extra_flags);
1459 /* Write screen dump for sending score */
1460 if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead))
1462 wr_string(screen_dump);
1469 /* Player is not dead, write the dungeon */
1470 if (!p_ptr->is_dead)
1472 /* Dump the dungeon */
1473 if (!wr_dungeon()) return FALSE;
1475 /* Dump the ghost */
1483 /* Write the "value check-sum" */
1486 /* Write the "encoded checksum" */
1491 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1493 /* Successful save */
1499 * @brief セーブデータ書き込みのサブルーチン /
1500 * Medium level player saver
1503 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1505 static bool save_player_aux(char *name)
1514 /* File type is "SAVE" */
1515 FILE_TYPE(FILE_TYPE_SAVE);
1517 /* Grab permissions */
1520 /* Create the savefile */
1521 fd = fd_make(name, mode);
1523 /* Drop permissions */
1529 /* Close the "fd" */
1532 /* Grab permissions */
1535 /* Open the savefile */
1536 fff = my_fopen(name, "wb");
1538 /* Drop permissions */
1541 /* Successful open */
1544 /* Write the savefile */
1545 if (wr_savefile_new()) ok = TRUE;
1547 /* Attempt to close it */
1548 if (my_fclose(fff)) ok = FALSE;
1551 /* Grab permissions */
1554 /* Remove "broken" files */
1555 if (!ok) (void)fd_kill(name);
1557 /* Drop permissions */
1563 if (!ok) return (FALSE);
1565 counts_write(0, current_world_ptr->play_time);
1567 /* Successful save */
1568 character_saved = TRUE;
1577 * @brief セーブデータ書き込みのメインルーチン /
1578 * Attempt to save the player in a savefile
1581 bool save_player(void)
1583 bool result = FALSE;
1592 /* Get "games" permissions */
1601 strcpy(safe, savefile);
1602 strcat(safe, ".new");
1604 /* Grab permissions */
1610 /* Drop permissions */
1615 /* Attempt to save the player */
1616 if (save_player_aux(safe))
1621 strcpy(temp, savefile);
1622 strcat(temp, ".old");
1624 /* Grab permissions */
1630 /* Preserve old savefile */
1631 fd_move(savefile, temp);
1633 /* Activate new savefile */
1634 fd_move(safe, savefile);
1636 /* Remove preserved savefile */
1639 /* Drop permissions */
1642 /* Hack -- Pretend the character was loaded */
1643 character_loaded = TRUE;
1645 #ifdef VERIFY_SAVEFILE
1647 /* Lock on savefile */
1648 strcpy(temp, savefile);
1649 strcat(temp, ".lok");
1651 /* Grab permissions */
1654 /* Remove lock file */
1657 /* Drop permissions */
1671 /* Drop "games" permissions */
1678 /* Return the result */
1684 * @brief セーブデータ読み込みのメインルーチン /
1685 * Attempt to Load a "savefile"
1689 * Version 2.7.0 introduced a slightly different "savefile" format from
1690 * older versions, requiring a completely different parsing method.
1692 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1694 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1696 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1698 * On multi-user systems, you may only "read" a savefile if you will be
1699 * allowed to "write" it later, this prevents painful situations in which
1700 * the player loads a savefile belonging to someone else, and then is not
1701 * allowed to save his game when he quits.
1703 * We return "TRUE" if the savefile was usable, and we set the global
1704 * flag "character_loaded" if a real, living, character was loaded.
1706 * Note that we always try to load the "current" savefile, even if
1707 * there is no such file, so we must check for "empty" savefile names.
1710 bool load_player(void)
1718 #ifdef VERIFY_TIMESTAMP
1719 struct stat statbuf;
1722 concptr what = "generic";
1724 current_world_ptr->game_turn = 0;
1725 p_ptr->is_dead = FALSE;
1728 /* Allow empty savefile name */
1729 if (!savefile[0]) return (TRUE);
1732 #if !defined(MACINTOSH) && !defined(WINDOWS)
1736 /* Verify the existance of the savefile */
1737 if (access(savefile, 0) < 0)
1739 /* Give a message */
1740 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1751 #ifdef VERIFY_SAVEFILE
1753 /* Verify savefile usage */
1760 /* Extract name of lock file */
1761 strcpy(temp, savefile);
1762 strcat(temp, ".lok");
1764 /* Check for lock */
1765 fkk = my_fopen(temp, "r");
1767 /* Oops, lock exists */
1772 msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
1778 /* Create a lock file */
1779 fkk = my_fopen(temp, "w");
1781 /* Dump a line of info */
1782 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1784 /* Close the lock file */
1793 /* Open the savefile */
1794 fd = fd_open(savefile, O_RDONLY);
1797 if (fd < 0) err = -1;
1799 /* Message (below) */
1800 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1807 #ifdef VERIFY_TIMESTAMP
1808 /* Get the timestamp */
1809 (void)fstat(fd, &statbuf);
1812 /* Read the first four bytes */
1813 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1816 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1824 /* Extract version */
1832 /* Attempt to load */
1833 err = rd_savefile_new();
1835 /* Message (below) */
1836 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1840 /* Invalid current_world_ptr->game_turn */
1841 if (!current_world_ptr->game_turn) err = -1;
1843 /* Message (below) */
1844 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1847 #ifdef VERIFY_TIMESTAMP
1848 /* Verify timestamp */
1849 if (!err && !arg_wizard)
1851 /* Hack -- Verify the timestamp */
1852 if (sf_when > (statbuf.st_ctime + 100) ||
1853 sf_when < (statbuf.st_ctime - 100))
1855 what = _("無効なタイム・スタンプです", "Invalid timestamp");
1865 /* Give a conversion warning */
1866 if ((FAKE_VER_MAJOR != z_major) ||
1867 (FAKE_VER_MINOR != z_minor) ||
1868 (FAKE_VER_PATCH != z_patch))
1870 if (z_major == 2 && z_minor == 0 && z_patch == 6)
1872 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1876 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1877 (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
1882 /* Player is dead */
1888 /* A character was loaded */
1889 character_loaded = TRUE;
1893 /* Player is no longer "dead" */
1894 p_ptr->is_dead = FALSE;
1902 /* A character was loaded */
1903 character_loaded = TRUE;
1906 u32b tmp = counts_read(2);
1907 if (tmp > p_ptr->count)
1909 if (counts_read(0) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
1910 counts_write(2, ++p_ptr->count);
1911 counts_write(1, current_world_ptr->play_time);
1919 #ifdef VERIFY_SAVEFILE
1921 /* Verify savefile usage */
1926 /* Extract name of lock file */
1927 strcpy(temp, savefile);
1928 strcat(temp, ".lok");
1936 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1937 what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
1948 void remove_loc(void)
1950 #ifdef VERIFY_SAVEFILE
1952 #endif /* VERIFY_SAVEFILE */
1957 /* Get "games" permissions */
1960 # endif /* SECURE */
1961 #endif /* SET_UID */
1963 #ifdef VERIFY_SAVEFILE
1965 /* Lock on savefile */
1966 strcpy(temp, savefile);
1967 strcat(temp, ".lok");
1969 /* Remove lock file */
1972 #endif /* VERIFY_SAVEFILE */
1977 /* Drop "games" permissions */
1980 # endif /* SECURE */
1981 #endif /* SET_UID */
1987 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporal saved floor file
1988 * @param sf_ptr 保存フロア参照ポインタ
1991 static bool save_floor_aux(saved_floor_type *sf_ptr)
1995 /* Compact the objects */
1997 /* Compact the monsters */
1998 compact_monsters(0);
2001 /*** Actually write the file ***/
2003 /* Initial value of xor_byte */
2004 tmp8u = (byte)randint0(256);
2009 /* Reset the checksum */
2013 /* Write the sign of this process */
2014 wr_u32b(saved_floor_file_sign);
2016 /* Dump the dungeon floor */
2017 wr_saved_floor(sf_ptr);
2020 /* Write the "value check-sum" */
2023 /* Write the "encoded checksum" */
2028 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2030 /* Successful save */
2036 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data
2037 * @param sf_ptr 保存フロア参照ポインタ
2038 * @param mode 保存オプション
2041 bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
2043 FILE *old_fff = NULL;
2044 byte old_xor_byte = 0;
2045 u32b old_v_stamp = 0;
2046 u32b old_x_stamp = 0;
2048 char floor_savefile[1024];
2052 if (!(mode & SLF_SECOND))
2056 /* Get "games" permissions */
2062 /* We have one file already opened */
2065 /* Backup original values */
2067 old_xor_byte = xor_byte;
2068 old_v_stamp = v_stamp;
2069 old_x_stamp = x_stamp;
2073 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2075 /* Grab permissions */
2079 fd_kill(floor_savefile);
2081 /* Drop permissions */
2085 /* Attempt to save the player */
2090 /* File type is "SAVE" */
2091 FILE_TYPE(FILE_TYPE_SAVE);
2093 /* Grab permissions */
2096 /* Create the savefile */
2097 fd = fd_make(floor_savefile, 0644);
2099 /* Drop permissions */
2105 /* Close the "fd" */
2108 /* Grab permissions */
2111 /* Open the savefile */
2112 fff = my_fopen(floor_savefile, "wb");
2114 /* Drop permissions */
2117 /* Successful open */
2120 /* Write the savefile */
2121 if (save_floor_aux(sf_ptr)) ok = TRUE;
2123 /* Attempt to close it */
2124 if (my_fclose(fff)) ok = FALSE;
2127 /* Remove "broken" files */
2130 /* Grab permissions */
2133 (void)fd_kill(floor_savefile);
2135 /* Drop permissions */
2140 if (!(mode & SLF_SECOND))
2144 /* Drop "games" permissions */
2150 /* We have one file already opened */
2153 /* Restore original values */
2155 xor_byte = old_xor_byte;
2156 v_stamp = old_v_stamp;
2157 x_stamp = old_x_stamp;
2160 /* Return the result */