3 * @brief セーブファイル書き込み処理 / Purpose: interact with savefiles
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
23 #include "floor-events.h"
24 #include "floor-save.h"
27 #include "objectkind.h"
28 #include "monsterrace.h"
32 * Some "local" parameters, used to help write savefiles
35 static FILE *fff; /* Current save "file" */
36 static byte xor_byte; /* Simple encryption */
37 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
38 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
43 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
47 static void sf_put(byte v)
49 /* Encode the value, write a character */
51 (void)putc((int)xor_byte, fff);
53 /* Maintain the checksum info */
59 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
63 static void wr_byte(byte v)
69 * @brief 符号なし16ビットをファイルに書き込む
70 * @param v 書き込む符号なし16bit値
73 static void wr_u16b(u16b v)
75 sf_put((byte)(v & 0xFF));
76 sf_put((byte)((v >> 8) & 0xFF));
80 * @brief 符号あり16ビットをファイルに書き込む
81 * @param v 書き込む符号あり16bit値
84 static void wr_s16b(s16b v)
90 * @brief 符号なし32ビットをファイルに書き込む
91 * @param v 書き込む符号なし32bit値
94 static void wr_u32b(u32b v)
96 sf_put((byte)(v & 0xFF));
97 sf_put((byte)((v >> 8) & 0xFF));
98 sf_put((byte)((v >> 16) & 0xFF));
99 sf_put((byte)((v >> 24) & 0xFF));
103 * @brief 符号あり32ビットをファイルに書き込む
104 * @param v 書き込む符号あり32bit値
107 static void wr_s32b(s32b v)
113 * @brief 文字列をファイルに書き込む
117 static void wr_string(concptr str)
129 * These functions write info in larger logical records
134 * @brief アイテムオブジェクトを書き込む / Write an "item" record
135 * @param o_ptr アイテムオブジェクト保存元ポインタ
138 static void wr_item(object_type *o_ptr)
140 BIT_FLAGS flags = 0x00000000;
142 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
143 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
144 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
145 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
146 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
147 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
148 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
149 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
150 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
151 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
152 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
153 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
154 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
155 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
156 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
157 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
158 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
159 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
160 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
161 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
162 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
163 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
164 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
165 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
166 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
167 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
168 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
169 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
170 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
172 /*** Item save flags ***/
175 /*** Write only un-obvious elements ***/
176 wr_s16b(o_ptr->k_idx);
178 wr_byte((byte_hack)o_ptr->iy);
179 wr_byte((byte_hack)o_ptr->ix);
181 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
183 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
184 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
186 wr_s16b((s16b)o_ptr->weight);
188 if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
189 if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
190 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
192 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
193 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
194 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
195 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
196 if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
197 if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
199 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
201 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
203 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
204 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
205 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
206 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
207 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
209 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
211 /* Held by monster index */
212 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
214 /* Extra information */
215 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
216 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
217 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
218 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
219 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
222 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
224 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
225 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
230 * @brief モンスター情報を書き込む / Write a "monster" record
231 * @param m_ptr モンスター情報保存元ポインタ
234 static void wr_monster(monster_type *m_ptr)
236 BIT_FLAGS flags = 0x00000000;
239 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
240 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
241 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
242 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
243 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
244 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
245 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
246 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
247 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
248 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
249 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
250 if (m_ptr->smart) flags |= SAVE_MON_SMART;
251 if (m_ptr->exp) flags |= SAVE_MON_EXP;
252 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
253 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
254 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
256 /*** Monster save flags ***/
259 /*** Write only un-obvious elements ***/
260 wr_s16b(m_ptr->r_idx);
261 wr_byte((byte_hack)m_ptr->fy);
262 wr_byte((byte_hack)m_ptr->fx);
263 wr_s16b((s16b)m_ptr->hp);
264 wr_s16b((s16b)m_ptr->maxhp);
265 wr_s16b((s16b)m_ptr->max_maxhp);
266 wr_u32b(m_ptr->dealt_damage);
269 /* Monster race index of its appearance */
270 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
272 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
273 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
275 wr_byte((byte)m_ptr->mspeed);
276 wr_s16b(m_ptr->energy_need);
278 if (flags & SAVE_MON_FAST)
280 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
283 if (flags & SAVE_MON_SLOW)
285 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
288 if (flags & SAVE_MON_STUNNED)
290 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
293 if (flags & SAVE_MON_CONFUSED)
295 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
298 if (flags & SAVE_MON_MONFEAR)
300 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
303 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
304 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
305 if (flags & SAVE_MON_INVULNER)
307 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
310 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
311 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
312 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
313 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
314 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
319 * @brief モンスターの思い出を書き込む / Write a "lore" record
320 * @param r_idx モンスター種族ID
323 static void wr_lore(MONRACE_IDX r_idx)
325 monster_race *r_ptr = &r_info[r_idx];
327 /* Count sights/deaths/kills */
328 wr_s16b((s16b)r_ptr->r_sights);
329 wr_s16b((s16b)r_ptr->r_deaths);
330 wr_s16b((s16b)r_ptr->r_pkills);
331 wr_s16b((s16b)r_ptr->r_akills);
332 wr_s16b((s16b)r_ptr->r_tkills);
334 /* Count wakes and ignores */
335 wr_byte(r_ptr->r_wake);
336 wr_byte(r_ptr->r_ignore);
339 wr_byte(r_ptr->r_xtra1);
340 wr_byte(r_ptr->r_xtra2);
343 wr_byte((byte_hack)r_ptr->r_drop_gold);
344 wr_byte((byte_hack)r_ptr->r_drop_item);
347 wr_byte(0); /* unused now */
348 wr_byte(r_ptr->r_cast_spell);
350 /* Count blows of each type */
351 wr_byte(r_ptr->r_blows[0]);
352 wr_byte(r_ptr->r_blows[1]);
353 wr_byte(r_ptr->r_blows[2]);
354 wr_byte(r_ptr->r_blows[3]);
357 wr_u32b(r_ptr->r_flags1);
358 wr_u32b(r_ptr->r_flags2);
359 wr_u32b(r_ptr->r_flags3);
360 wr_u32b(r_ptr->r_flags4);
361 wr_u32b(r_ptr->r_flags5);
362 wr_u32b(r_ptr->r_flags6);
363 wr_u32b(r_ptr->r_flagsr);
365 /* Monster limit per level */
366 wr_byte((byte_hack)r_ptr->max_num);
368 /* Location in saved floor */
369 wr_s16b(r_ptr->floor_id);
376 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
377 * @param k_idx ベースアイテムのID
380 static void wr_xtra(KIND_OBJECT_IDX k_idx)
384 object_kind *k_ptr = &k_info[k_idx];
386 if (k_ptr->aware) tmp8u |= 0x01;
387 if (k_ptr->tried) tmp8u |= 0x02;
394 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
395 * @param st_ptr 店舗情報の参照ポインタ
398 static void wr_store(store_type *st_ptr)
402 /* Save the "open" counter */
403 wr_u32b(st_ptr->store_open);
405 /* Save the "insults" */
406 wr_s16b(st_ptr->insult_cur);
408 /* Save the current owner */
409 wr_byte(st_ptr->owner);
411 /* Save the stock size */
412 wr_s16b(st_ptr->stock_num);
414 /* Save the "haggle" info */
415 wr_s16b(st_ptr->good_buy);
416 wr_s16b(st_ptr->bad_buy);
418 wr_s32b(st_ptr->last_visit);
421 for (j = 0; j < st_ptr->stock_num; j++)
423 /* Save each item in stock */
424 wr_item(&st_ptr->stock[j]);
430 * @brief セーブデータに乱数情報を書き込む / Write RNG state
433 static errr wr_randomizer(void)
439 for (i = 0; i < RAND_DEG; i++)
441 wr_u32b(Rand_state[i]);
449 * @brief ゲームオプション情報を書き込む / Write the "options"
452 static void wr_options(void)
461 for (i = 0; i < 4; i++) wr_u32b(0L);
464 /*** Special Options ***/
466 /* Write "delay_factor" */
467 wr_byte(delay_factor);
469 /* Write "hitpoint_warn" */
470 wr_byte(hitpoint_warn);
472 /* Write "mana_warn" */
475 /*** Cheating options ***/
479 if (p_ptr->wizard) c |= 0x0002;
481 if (cheat_sight) c |= 0x0040;
482 if (cheat_turn) c |= 0x0080;
484 if (cheat_peek) c |= 0x0100;
485 if (cheat_hear) c |= 0x0200;
486 if (cheat_room) c |= 0x0400;
487 if (cheat_xtra) c |= 0x0800;
488 if (cheat_know) c |= 0x1000;
489 if (cheat_live) c |= 0x2000;
490 if (cheat_save) c |= 0x4000;
491 if (cheat_diary_output) c |= 0x8000;
498 wr_s16b(autosave_freq);
500 /*** Extract options ***/
502 /* Analyze the options */
503 for (i = 0; option_info[i].o_desc; i++)
505 int os = option_info[i].o_set;
506 int ob = option_info[i].o_bit;
508 /* Process real entries */
509 if (option_info[i].o_var)
512 if (*option_info[i].o_var)
515 option_flag[os] |= (1L << ob);
522 option_flag[os] &= ~(1L << ob);
528 /*** Normal options ***/
531 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
534 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
537 /*** Window options ***/
540 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
543 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
548 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
551 static void wr_ghost(void)
556 wr_string(_("不正なゴースト", "Broken Ghost"));
558 /* Hack -- stupid data */
559 for (i = 0; i < 60; i++) wr_byte(0);
564 * @brief クイック・スタート情報を書き込む / Save quick start data
567 static void save_quick_start(void)
571 wr_byte(previous_char.psex);
572 wr_byte((byte_hack)previous_char.prace);
573 wr_byte((byte_hack)previous_char.pclass);
574 wr_byte((byte_hack)previous_char.pseikaku);
575 wr_byte((byte_hack)previous_char.realm1);
576 wr_byte((byte_hack)previous_char.realm2);
578 wr_s16b(previous_char.age);
579 wr_s16b(previous_char.ht);
580 wr_s16b(previous_char.wt);
581 wr_s16b(previous_char.sc);
582 wr_s32b(previous_char.au);
584 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
585 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
587 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
589 wr_s16b(previous_char.chaos_patron);
591 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
593 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
595 /* UNUSED : Was number of random quests */
598 /* No quick start after using debug mode or cheat options */
599 if (p_ptr->noscore) previous_char.quick_ok = FALSE;
601 wr_byte((byte)previous_char.quick_ok);
606 * @brief その他の情報を書き込む / Write some "extra" info
609 static void wr_extra(void)
614 wr_string(p_ptr->name);
615 wr_string(p_ptr->died_from);
616 wr_string(p_ptr->last_message ? p_ptr->last_message : "");
620 for (i = 0; i < 4; i++)
622 wr_string(p_ptr->history[i]);
625 /* Race/Class/Gender/Spells */
626 wr_byte((byte_hack)p_ptr->prace);
627 wr_byte((byte_hack)p_ptr->pclass);
628 wr_byte((byte_hack)p_ptr->pseikaku);
629 wr_byte((byte_hack)p_ptr->psex);
630 wr_byte((byte_hack)p_ptr->realm1);
631 wr_byte((byte_hack)p_ptr->realm2);
634 wr_byte((byte)p_ptr->hitdie);
635 wr_u16b(p_ptr->expfact);
641 /* Dump the stats (maximum and current) */
642 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max[i]);
643 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max_max[i]);
644 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_cur[i]);
646 /* Ignore the transient stats */
647 for (i = 0; i < 12; ++i) wr_s16b(0);
651 wr_u32b(p_ptr->max_exp);
652 wr_u32b(p_ptr->max_max_exp);
654 wr_u32b(p_ptr->exp_frac);
657 for (i = 0; i < 64; i++) wr_s16b(p_ptr->spell_exp[i]);
658 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(p_ptr->weapon_exp[i][j]);
659 for (i = 0; i < GINOU_MAX; i++) wr_s16b(p_ptr->skill_exp[i]);
660 for (i = 0; i < 108; i++) wr_s32b(p_ptr->magic_num1[i]);
661 for (i = 0; i < 108; i++) wr_byte(p_ptr->magic_num2[i]);
663 wr_byte((byte_hack)p_ptr->start_race);
664 wr_s32b(p_ptr->old_race1);
665 wr_s32b(p_ptr->old_race2);
666 wr_s16b(p_ptr->old_realm);
668 for (i = 0; i < MAX_MANE; i++)
670 wr_s16b((s16b)p_ptr->mane_spell[i]);
671 wr_s16b((s16b)p_ptr->mane_dam[i]);
673 wr_s16b(p_ptr->mane_num);
675 for (i = 0; i < MAX_KUBI; i++)
677 wr_s16b(current_world_ptr->bounty_r_idx[i]);
680 for (i = 0; i < 4; i++)
682 wr_s16b(battle_mon[i]);
683 wr_u32b(mon_odds[i]);
686 wr_s16b(p_ptr->town_num); /* -KMW- */
688 /* Write arena and rewards information -KMW- */
689 wr_s16b(p_ptr->arena_number);
690 wr_s16b(p_ptr->inside_arena);
691 wr_s16b(p_ptr->inside_quest);
692 wr_s16b(p_ptr->inside_battle);
693 wr_byte(p_ptr->exit_bldg);
694 wr_byte(0); /* Unused */
696 wr_s16b((s16b)p_ptr->oldpx);
697 wr_s16b((s16b)p_ptr->oldpy);
699 /* Was number of p_ptr->rewards[] */
704 wr_u32b(p_ptr->chp_frac);
708 wr_u32b(p_ptr->csp_frac);
710 /* Max Player and Dungeon Levels */
711 wr_s16b(p_ptr->max_plv);
712 tmp8u = (byte)max_d_idx;
714 for (i = 0; i < tmp8u; i++)
715 wr_s16b((s16b)max_dlv[i]);
723 wr_s16b(p_ptr->concent);
725 wr_s16b(0); /* old "rest" */
726 wr_s16b(p_ptr->blind);
727 wr_s16b(p_ptr->paralyzed);
728 wr_s16b(p_ptr->confused);
729 wr_s16b(p_ptr->food);
730 wr_s16b(0); /* old "food_digested" */
731 wr_s16b(0); /* old "protection" */
732 wr_s16b(p_ptr->energy_need);
733 wr_s16b(p_ptr->enchant_energy_need);
734 wr_s16b(p_ptr->fast);
735 wr_s16b(p_ptr->slow);
736 wr_s16b(p_ptr->afraid);
738 wr_s16b(p_ptr->stun);
739 wr_s16b(p_ptr->poisoned);
740 wr_s16b(p_ptr->image);
741 wr_s16b(p_ptr->protevil);
742 wr_s16b(p_ptr->invuln);
743 wr_s16b(p_ptr->ult_res);
744 wr_s16b(p_ptr->hero);
745 wr_s16b(p_ptr->shero);
746 wr_s16b(p_ptr->shield);
747 wr_s16b(p_ptr->blessed);
748 wr_s16b(p_ptr->tim_invis);
749 wr_s16b(p_ptr->word_recall);
750 wr_s16b(p_ptr->recall_dungeon);
751 wr_s16b(p_ptr->alter_reality);
752 wr_s16b(p_ptr->see_infra);
753 wr_s16b(p_ptr->tim_infra);
754 wr_s16b(p_ptr->oppose_fire);
755 wr_s16b(p_ptr->oppose_cold);
756 wr_s16b(p_ptr->oppose_acid);
757 wr_s16b(p_ptr->oppose_elec);
758 wr_s16b(p_ptr->oppose_pois);
759 wr_s16b(p_ptr->tsuyoshi);
760 wr_s16b(p_ptr->tim_esp);
761 wr_s16b(p_ptr->wraith_form);
762 wr_s16b(p_ptr->resist_magic);
763 wr_s16b(p_ptr->tim_regen);
764 wr_s16b(p_ptr->kabenuke);
765 wr_s16b(p_ptr->tim_stealth);
766 wr_s16b(p_ptr->tim_levitation);
767 wr_s16b(p_ptr->tim_sh_touki);
768 wr_s16b(p_ptr->lightspeed);
769 wr_s16b(p_ptr->tsubureru);
770 wr_s16b(p_ptr->magicdef);
771 wr_s16b(p_ptr->tim_res_nether);
772 wr_s16b(p_ptr->tim_res_time);
773 wr_byte((byte)p_ptr->mimic_form);
774 wr_s16b(p_ptr->tim_mimic);
775 wr_s16b(p_ptr->tim_sh_fire);
776 wr_s16b(p_ptr->tim_sh_holy);
777 wr_s16b(p_ptr->tim_eyeeye);
780 wr_s16b(p_ptr->tim_reflect);
781 wr_s16b(p_ptr->multishadow);
782 wr_s16b(p_ptr->dustrobe);
784 wr_s16b(p_ptr->chaos_patron);
785 wr_u32b(p_ptr->muta1);
786 wr_u32b(p_ptr->muta2);
787 wr_u32b(p_ptr->muta3);
789 for (i = 0; i<8; i++)
790 wr_s16b(p_ptr->virtues[i]);
791 for (i = 0; i<8; i++)
792 wr_s16b(p_ptr->vir_types[i]);
794 wr_s16b(p_ptr->ele_attack);
795 wr_u32b(p_ptr->special_attack);
796 wr_s16b(p_ptr->ele_immune);
797 wr_u32b(p_ptr->special_defense);
798 wr_byte(p_ptr->knowledge);
799 wr_byte(p_ptr->autopick_autoregister);
801 wr_byte((byte_hack)p_ptr->action);
803 wr_byte(preserve_mode);
804 wr_byte(p_ptr->wait_report_score);
807 for (i = 0; i < 12; i++) wr_u32b(0L);
809 /* Ignore some flags */
815 /* Write the "object seeds" */
816 wr_u32b(current_world_ptr->seed_flavor);
817 wr_u32b(current_world_ptr->seed_town);
821 wr_u16b(p_ptr->panic_save);
822 wr_u16b(p_ptr->total_winner);
823 wr_u16b(p_ptr->noscore);
827 wr_byte(p_ptr->is_dead);
830 wr_byte(p_ptr->feeling);
832 /* Turn when level began */
833 wr_s32b(current_floor_ptr->generated_turn);
835 /* Turn of last "feeling" */
836 wr_s32b(p_ptr->feeling_turn);
838 /* Current current_world_ptr->game_turn */
839 wr_s32b(current_world_ptr->game_turn);
841 wr_s32b(current_world_ptr->dungeon_turn);
846 wr_s16b(p_ptr->today_mon);
847 wr_s16b(p_ptr->riding);
849 /* Current floor_id */
850 wr_s16b(p_ptr->floor_id);
852 /* Save temporary preserved pets (obsolated) */
855 wr_u32b(current_world_ptr->play_time);
857 wr_s32b(p_ptr->visit);
859 wr_u32b(p_ptr->count);
864 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
865 * @param sf_ptr 保存したいフロアの参照ポインタ
868 static void wr_saved_floor(saved_floor_type *sf_ptr)
870 cave_template_type *templates;
885 /* Dungeon floor specific info follows */
889 /*** Not a saved floor ***/
891 wr_s16b((s16b)current_floor_ptr->dun_level);
895 /*** The saved floor ***/
897 wr_s16b(sf_ptr->floor_id);
898 wr_byte((byte_hack)sf_ptr->savefile_id);
899 wr_s16b((s16b)sf_ptr->dun_level);
900 wr_s32b(sf_ptr->last_visit);
901 wr_u32b(sf_ptr->visit_mark);
902 wr_s16b(sf_ptr->upper_floor_id);
903 wr_s16b(sf_ptr->lower_floor_id);
906 wr_u16b((u16b)current_floor_ptr->base_level);
907 wr_u16b((s16b)current_floor_ptr->num_repro);
908 wr_u16b((u16b)p_ptr->y);
909 wr_u16b((u16b)p_ptr->x);
910 wr_u16b((u16b)current_floor_ptr->height);
911 wr_u16b((u16b)current_floor_ptr->width);
912 wr_byte(p_ptr->feeling);
916 /*********** Make template for grid_type **********/
919 * Usually number of templates are fewer than 255. Even if
920 * more than 254 are exist, the occurrence of each template
921 * with larger ID is very small when we sort templates by
922 * occurrence. So we will use two (or more) bytes for
923 * templete ID larger than 254.
925 * Ex: 256 will be "0xff" "0x01".
926 * 515 will be "0xff" "0xff" "0x03"
929 /* Fake max number */
932 /* Allocate the "template" array */
933 C_MAKE(templates, max_num_temp, cave_template_type);
935 /* Extract template array */
936 for (y = 0; y < current_floor_ptr->height; y++)
938 for (x = 0; x < current_floor_ptr->width; x++)
940 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
942 for (i = 0; i < num_temp; i++)
944 if (templates[i].info == g_ptr->info &&
945 templates[i].feat == g_ptr->feat &&
946 templates[i].mimic == g_ptr->mimic &&
947 templates[i].special == g_ptr->special)
949 /* Same terrain is exist */
950 templates[i].occurrence++;
955 /* Are there same one? */
956 if (i < num_temp) continue;
958 /* If the max_num_temp is too small, increase it. */
959 if (num_temp >= max_num_temp)
961 cave_template_type *old_template = templates;
963 /* Re-allocate the "template" array */
964 C_MAKE(templates, max_num_temp + 255, cave_template_type);
965 (void)C_COPY(templates, old_template, max_num_temp, cave_template_type);
966 C_KILL(old_template, max_num_temp, cave_template_type);
970 /* Add new template */
971 templates[num_temp].info = g_ptr->info;
972 templates[num_temp].feat = g_ptr->feat;
973 templates[num_temp].mimic = g_ptr->mimic;
974 templates[num_temp].special = g_ptr->special;
975 templates[num_temp].occurrence = 1;
977 /* Increase number of template */
982 /* Sort by occurrence */
983 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
985 /*** Dump templates ***/
987 /* Total templates */
990 /* Dump the templates */
991 for (i = 0; i < num_temp; i++)
993 cave_template_type *ct_ptr = &templates[i];
996 wr_u16b((u16b)ct_ptr->info);
997 wr_s16b(ct_ptr->feat);
998 wr_s16b(ct_ptr->mimic);
999 wr_s16b(ct_ptr->special);
1004 /*** "Run-Length-Encoding" of current_floor_ptr->grid_array ***/
1006 /* Note that this will induce two wasted bytes */
1010 /* Dump the current_floor_ptr->grid_array */
1011 for (y = 0; y < current_floor_ptr->height; y++)
1013 for (x = 0; x < current_floor_ptr->width; x++)
1015 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1017 for (i = 0; i < num_temp; i++)
1019 if (templates[i].info == g_ptr->info &&
1020 templates[i].feat == g_ptr->feat &&
1021 templates[i].mimic == g_ptr->mimic &&
1022 templates[i].special == g_ptr->special)
1029 /* If the run is broken, or too full, flush it */
1030 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
1032 wr_byte((byte)count);
1034 while (prev_u16b >= MAX_UCHAR)
1036 /* Mark as actual data is larger than 254 */
1038 prev_u16b -= MAX_UCHAR;
1041 wr_byte((byte)prev_u16b);
1046 /* Continue the run */
1054 /* Flush the data (if any) */
1057 wr_byte((byte)count);
1059 while (prev_u16b >= MAX_UCHAR)
1061 /* Mark as actual data is larger than 254 */
1063 prev_u16b -= MAX_UCHAR;
1065 wr_byte((byte)prev_u16b);
1069 /* Free the "template" array */
1070 C_KILL(templates, max_num_temp, cave_template_type);
1073 /*** Dump objects ***/
1076 wr_u16b(current_floor_ptr->o_max);
1078 /* Dump the objects */
1079 for (i = 1; i < current_floor_ptr->o_max; i++)
1081 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
1088 /*** Dump the monsters ***/
1090 /* Total monsters */
1091 wr_u16b(current_floor_ptr->m_max);
1093 /* Dump the monsters */
1094 for (i = 1; i < current_floor_ptr->m_max; i++)
1096 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1105 * @brief 現在フロアの書き込み /
1106 * Write the current dungeon (new method)
1109 static bool wr_dungeon(void)
1111 saved_floor_type *cur_sf_ptr;
1118 /* Update lite/view */
1119 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1120 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1124 /* Number of floor_id used from birth */
1125 wr_s16b(max_floor_id);
1127 /* Current dungeon type */
1128 wr_byte((byte_hack)p_ptr->dungeon_idx);
1131 /*** No saved floor (On the surface etc.) ***/
1132 if (!p_ptr->floor_id)
1134 /* No array elements */
1137 /* Write the current floor data */
1138 wr_saved_floor(NULL);
1145 /*** In the dungeon ***/
1147 /* Number of array elements */
1148 wr_byte(MAX_SAVED_FLOORS);
1150 /* Write the saved_floors array */
1151 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1153 saved_floor_type *sf_ptr = &saved_floors[i];
1155 wr_s16b(sf_ptr->floor_id);
1156 wr_byte((byte_hack)sf_ptr->savefile_id);
1157 wr_s16b((s16b)sf_ptr->dun_level);
1158 wr_s32b(sf_ptr->last_visit);
1159 wr_u32b(sf_ptr->visit_mark);
1160 wr_s16b(sf_ptr->upper_floor_id);
1161 wr_s16b(sf_ptr->lower_floor_id);
1164 /* Extract pointer to current floor */
1165 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1167 /* Save current floor to temporal file */
1168 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1170 /* Move data in temporal files to the savefile */
1171 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1173 saved_floor_type *sf_ptr = &saved_floors[i];
1175 /* Unused element */
1176 if (!sf_ptr->floor_id) continue;
1178 /* Load temporal saved floor file */
1179 if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1184 /* Write saved floor data to the save file */
1185 wr_saved_floor(sf_ptr);
1194 /* Restore current floor */
1195 if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1203 * @brief セーブデータの書き込み /
1204 * Actually write a save-file
1207 static bool wr_savefile_new(void)
1218 KIND_OBJECT_IDX k_idx;
1220 /* Compact the objects */
1222 /* Compact the monsters */
1223 compact_monsters(0);
1225 /* Guess at the current time */
1226 now = (u32b)time((time_t *)0);
1229 /* Note the operating system */
1232 /* Note when the file was saved */
1235 /* Note the number of saves */
1239 /*** Actually write the file ***/
1241 /* Dump the file header */
1243 wr_byte(FAKE_VER_MAJOR);
1245 wr_byte(FAKE_VER_MINOR);
1247 wr_byte(FAKE_VER_PATCH);
1250 /* Initial value of xor_byte */
1251 tmp8u = (byte)Rand_external(256);
1255 /* Reset the checksum */
1259 /* Write the savefile version for Hengband 1.1.1 and later */
1260 wr_byte(H_VER_EXTRA);
1261 wr_byte(H_VER_PATCH);
1262 wr_byte(H_VER_MINOR);
1263 wr_byte(H_VER_MAJOR);
1265 /* Operating system */
1269 /* Time file last saved */
1272 /* Number of past lives */
1275 /* Number of times saved */
1286 /* EUC kanji code */
1290 /* SJIS kanji code */
1298 /* Write the RNG state */
1302 /* Write the boolean "options" */
1306 /* Dump the number of "messages" */
1307 tmp32u = message_num();
1308 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1311 /* Dump the messages (oldest first!) */
1312 for (i = tmp32u - 1; i >= 0; i--)
1314 wr_string(message_str((s16b)i));
1317 /* Dump the monster lore */
1320 for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
1322 /* Dump the object memory */
1325 for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
1327 /* Dump the towns */
1331 /* Dump the quests */
1335 /* Dump the quests */
1336 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1339 for (i = 0; i < max_q_idx; i++)
1341 quest_type* const q_ptr = &quest[i];
1343 /* Save status for every quest */
1344 wr_s16b(q_ptr->status);
1346 /* And the dungeon level too */
1347 /* (prevents problems with multi-level quests) */
1348 wr_s16b((s16b)q_ptr->level);
1350 wr_byte((byte_hack)q_ptr->complev);
1351 wr_u32b(q_ptr->comptime);
1353 /* Save quest status if quest is running */
1354 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1356 wr_s16b((s16b)q_ptr->cur_num);
1357 wr_s16b((s16b)q_ptr->max_num);
1358 wr_s16b(q_ptr->type);
1359 wr_s16b(q_ptr->r_idx);
1360 wr_s16b(q_ptr->k_idx);
1361 wr_byte((byte_hack)q_ptr->flags);
1362 wr_byte((byte_hack)q_ptr->dungeon);
1366 /* Dump the position in the wilderness */
1367 wr_s32b(p_ptr->wilderness_x);
1368 wr_s32b(p_ptr->wilderness_y);
1370 wr_byte(p_ptr->wild_mode);
1371 wr_byte(p_ptr->ambush_flag);
1373 wr_s32b(current_world_ptr->max_wild_x);
1374 wr_s32b(current_world_ptr->max_wild_y);
1376 /* Dump the wilderness seeds */
1377 for (i = 0; i < current_world_ptr->max_wild_x; i++)
1379 for (j = 0; j < current_world_ptr->max_wild_y; j++)
1381 wr_u32b(wilderness[j][i].seed);
1385 /* Hack -- Dump the artifacts */
1388 for (i = 0; i < tmp16u; i++)
1390 artifact_type *a_ptr = &a_info[i];
1391 wr_byte(a_ptr->cur_num);
1392 wr_s16b(a_ptr->floor_id);
1397 /* Write the "extra" information */
1400 /* Dump the "player hp" entries */
1401 tmp16u = PY_MAX_LEVEL;
1403 for (i = 0; i < tmp16u; i++)
1405 wr_s16b((s16b)p_ptr->player_hp[i]);
1409 /* Write spell data */
1410 wr_u32b(p_ptr->spell_learned1);
1411 wr_u32b(p_ptr->spell_learned2);
1412 wr_u32b(p_ptr->spell_worked1);
1413 wr_u32b(p_ptr->spell_worked2);
1414 wr_u32b(p_ptr->spell_forgotten1);
1415 wr_u32b(p_ptr->spell_forgotten2);
1417 wr_s16b(p_ptr->learned_spells);
1418 wr_s16b(p_ptr->add_spells);
1420 /* Dump the ordered spells */
1421 for (i = 0; i < 64; i++)
1423 wr_byte((byte_hack)p_ptr->spell_order[i]);
1427 /* Write the p_ptr->inventory_list */
1428 for (i = 0; i < INVEN_TOTAL; i++)
1430 object_type *o_ptr = &p_ptr->inventory_list[i];
1431 if (!o_ptr->k_idx) continue;
1440 /* Add a sentinel */
1443 /* Note the towns */
1447 /* Note the stores */
1448 tmp16u = MAX_STORES;
1451 /* Dump the stores of all towns */
1452 for (i = 1; i < max_towns; i++)
1454 for (j = 0; j < MAX_STORES; j++)
1456 wr_store(&town_info[i].store[j]);
1460 /* Write the pet command settings */
1461 wr_s16b(p_ptr->pet_follow_distance);
1462 wr_s16b(p_ptr->pet_extra_flags);
1464 /* Write screen dump for sending score */
1465 if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead))
1467 wr_string(screen_dump);
1474 /* Player is not dead, write the dungeon */
1475 if (!p_ptr->is_dead)
1477 /* Dump the dungeon */
1478 if (!wr_dungeon()) return FALSE;
1480 /* Dump the ghost */
1488 /* Write the "value check-sum" */
1491 /* Write the "encoded checksum" */
1496 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1498 /* Successful save */
1504 * @brief セーブデータ書き込みのサブルーチン /
1505 * Medium level player saver
1508 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1510 static bool save_player_aux(char *name)
1519 /* File type is "SAVE" */
1520 FILE_TYPE(FILE_TYPE_SAVE);
1522 /* Grab permissions */
1525 /* Create the savefile */
1526 fd = fd_make(name, mode);
1528 /* Drop permissions */
1534 /* Close the "fd" */
1537 /* Grab permissions */
1540 /* Open the savefile */
1541 fff = my_fopen(name, "wb");
1543 /* Drop permissions */
1546 /* Successful open */
1549 /* Write the savefile */
1550 if (wr_savefile_new()) ok = TRUE;
1552 /* Attempt to close it */
1553 if (my_fclose(fff)) ok = FALSE;
1556 /* Grab permissions */
1559 /* Remove "broken" files */
1560 if (!ok) (void)fd_kill(name);
1562 /* Drop permissions */
1568 if (!ok) return (FALSE);
1570 counts_write(0, current_world_ptr->play_time);
1572 /* Successful save */
1573 character_saved = TRUE;
1582 * @brief セーブデータ書き込みのメインルーチン /
1583 * Attempt to save the player in a savefile
1586 bool save_player(void)
1588 bool result = FALSE;
1597 /* Get "games" permissions */
1606 strcpy(safe, savefile);
1607 strcat(safe, ".new");
1609 /* Grab permissions */
1615 /* Drop permissions */
1620 /* Attempt to save the player */
1621 if (save_player_aux(safe))
1626 strcpy(temp, savefile);
1627 strcat(temp, ".old");
1629 /* Grab permissions */
1635 /* Preserve old savefile */
1636 fd_move(savefile, temp);
1638 /* Activate new savefile */
1639 fd_move(safe, savefile);
1641 /* Remove preserved savefile */
1644 /* Drop permissions */
1647 /* Hack -- Pretend the character was loaded */
1648 character_loaded = TRUE;
1650 #ifdef VERIFY_SAVEFILE
1652 /* Lock on savefile */
1653 strcpy(temp, savefile);
1654 strcat(temp, ".lok");
1656 /* Grab permissions */
1659 /* Remove lock file */
1662 /* Drop permissions */
1676 /* Drop "games" permissions */
1683 /* Return the result */
1689 * @brief セーブデータ読み込みのメインルーチン /
1690 * Attempt to Load a "savefile"
1694 * Version 2.7.0 introduced a slightly different "savefile" format from
1695 * older versions, requiring a completely different parsing method.
1697 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1699 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1701 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1703 * On multi-user systems, you may only "read" a savefile if you will be
1704 * allowed to "write" it later, this prevents painful situations in which
1705 * the player loads a savefile belonging to someone else, and then is not
1706 * allowed to save his game when he quits.
1708 * We return "TRUE" if the savefile was usable, and we set the global
1709 * flag "character_loaded" if a real, living, character was loaded.
1711 * Note that we always try to load the "current" savefile, even if
1712 * there is no such file, so we must check for "empty" savefile names.
1715 bool load_player(void)
1723 #ifdef VERIFY_TIMESTAMP
1724 struct stat statbuf;
1727 concptr what = "generic";
1729 current_world_ptr->game_turn = 0;
1730 p_ptr->is_dead = FALSE;
1733 /* Allow empty savefile name */
1734 if (!savefile[0]) return (TRUE);
1737 #if !defined(MACINTOSH) && !defined(WINDOWS)
1741 /* Verify the existance of the savefile */
1742 if (access(savefile, 0) < 0)
1744 /* Give a message */
1745 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1756 #ifdef VERIFY_SAVEFILE
1758 /* Verify savefile usage */
1765 /* Extract name of lock file */
1766 strcpy(temp, savefile);
1767 strcat(temp, ".lok");
1769 /* Check for lock */
1770 fkk = my_fopen(temp, "r");
1772 /* Oops, lock exists */
1777 msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
1783 /* Create a lock file */
1784 fkk = my_fopen(temp, "w");
1786 /* Dump a line of info */
1787 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1789 /* Close the lock file */
1798 /* Open the savefile */
1799 fd = fd_open(savefile, O_RDONLY);
1802 if (fd < 0) err = -1;
1804 /* Message (below) */
1805 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1812 #ifdef VERIFY_TIMESTAMP
1813 /* Get the timestamp */
1814 (void)fstat(fd, &statbuf);
1817 /* Read the first four bytes */
1818 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1821 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1829 /* Extract version */
1837 /* Attempt to load */
1838 err = rd_savefile_new();
1840 /* Message (below) */
1841 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1845 /* Invalid current_world_ptr->game_turn */
1846 if (!current_world_ptr->game_turn) err = -1;
1848 /* Message (below) */
1849 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1852 #ifdef VERIFY_TIMESTAMP
1853 /* Verify timestamp */
1854 if (!err && !arg_wizard)
1856 /* Hack -- Verify the timestamp */
1857 if (sf_when > (statbuf.st_ctime + 100) ||
1858 sf_when < (statbuf.st_ctime - 100))
1860 what = _("無効なタイム・スタンプです", "Invalid timestamp");
1870 /* Give a conversion warning */
1871 if ((FAKE_VER_MAJOR != z_major) ||
1872 (FAKE_VER_MINOR != z_minor) ||
1873 (FAKE_VER_PATCH != z_patch))
1875 if (z_major == 2 && z_minor == 0 && z_patch == 6)
1877 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1881 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1882 (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
1887 /* Player is dead */
1893 /* A character was loaded */
1894 character_loaded = TRUE;
1898 /* Player is no longer "dead" */
1899 p_ptr->is_dead = FALSE;
1907 /* A character was loaded */
1908 character_loaded = TRUE;
1911 u32b tmp = counts_read(2);
1912 if (tmp > p_ptr->count)
1914 if (counts_read(0) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
1915 counts_write(2, ++p_ptr->count);
1916 counts_write(1, current_world_ptr->play_time);
1924 #ifdef VERIFY_SAVEFILE
1926 /* Verify savefile usage */
1931 /* Extract name of lock file */
1932 strcpy(temp, savefile);
1933 strcat(temp, ".lok");
1941 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1942 what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
1953 void remove_loc(void)
1955 #ifdef VERIFY_SAVEFILE
1957 #endif /* VERIFY_SAVEFILE */
1962 /* Get "games" permissions */
1965 # endif /* SECURE */
1966 #endif /* SET_UID */
1968 #ifdef VERIFY_SAVEFILE
1970 /* Lock on savefile */
1971 strcpy(temp, savefile);
1972 strcat(temp, ".lok");
1974 /* Remove lock file */
1977 #endif /* VERIFY_SAVEFILE */
1982 /* Drop "games" permissions */
1985 # endif /* SECURE */
1986 #endif /* SET_UID */
1992 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporal saved floor file
1993 * @param sf_ptr 保存フロア参照ポインタ
1996 static bool save_floor_aux(saved_floor_type *sf_ptr)
2000 /* Compact the objects */
2002 /* Compact the monsters */
2003 compact_monsters(0);
2006 /*** Actually write the file ***/
2008 /* Initial value of xor_byte */
2009 tmp8u = (byte)randint0(256);
2014 /* Reset the checksum */
2018 /* Write the sign of this process */
2019 wr_u32b(saved_floor_file_sign);
2021 /* Dump the dungeon floor */
2022 wr_saved_floor(sf_ptr);
2025 /* Write the "value check-sum" */
2028 /* Write the "encoded checksum" */
2033 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2035 /* Successful save */
2041 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data
2042 * @param sf_ptr 保存フロア参照ポインタ
2043 * @param mode 保存オプション
2046 bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
2048 FILE *old_fff = NULL;
2049 byte old_xor_byte = 0;
2050 u32b old_v_stamp = 0;
2051 u32b old_x_stamp = 0;
2053 char floor_savefile[1024];
2057 if (!(mode & SLF_SECOND))
2061 /* Get "games" permissions */
2067 /* We have one file already opened */
2070 /* Backup original values */
2072 old_xor_byte = xor_byte;
2073 old_v_stamp = v_stamp;
2074 old_x_stamp = x_stamp;
2078 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2080 /* Grab permissions */
2084 fd_kill(floor_savefile);
2086 /* Drop permissions */
2090 /* Attempt to save the player */
2095 /* File type is "SAVE" */
2096 FILE_TYPE(FILE_TYPE_SAVE);
2098 /* Grab permissions */
2101 /* Create the savefile */
2102 fd = fd_make(floor_savefile, 0644);
2104 /* Drop permissions */
2110 /* Close the "fd" */
2113 /* Grab permissions */
2116 /* Open the savefile */
2117 fff = my_fopen(floor_savefile, "wb");
2119 /* Drop permissions */
2122 /* Successful open */
2125 /* Write the savefile */
2126 if (save_floor_aux(sf_ptr)) ok = TRUE;
2128 /* Attempt to close it */
2129 if (my_fclose(fff)) ok = FALSE;
2132 /* Remove "broken" files */
2135 /* Grab permissions */
2138 (void)fd_kill(floor_savefile);
2140 /* Drop permissions */
2145 if (!(mode & SLF_SECOND))
2149 /* Drop "games" permissions */
2155 /* We have one file already opened */
2158 /* Restore original values */
2160 xor_byte = old_xor_byte;
2161 v_stamp = old_v_stamp;
2162 x_stamp = old_x_stamp;
2165 /* Return the result */