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"
25 #include "floor-town.h"
28 #include "objectkind.h"
29 #include "monsterrace.h"
33 * Some "local" parameters, used to help write savefiles
36 static FILE *fff; /* Current save "file" */
37 static byte xor_byte; /* Simple encryption */
38 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
39 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
44 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
48 static void sf_put(byte v)
50 /* Encode the value, write a character */
52 (void)putc((int)xor_byte, fff);
54 /* Maintain the checksum info */
60 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
64 static void wr_byte(byte v)
70 * @brief 符号なし16ビットをファイルに書き込む
71 * @param v 書き込む符号なし16bit値
74 static void wr_u16b(u16b v)
76 sf_put((byte)(v & 0xFF));
77 sf_put((byte)((v >> 8) & 0xFF));
81 * @brief 符号あり16ビットをファイルに書き込む
82 * @param v 書き込む符号あり16bit値
85 static void wr_s16b(s16b v)
91 * @brief 符号なし32ビットをファイルに書き込む
92 * @param v 書き込む符号なし32bit値
95 static void wr_u32b(u32b v)
97 sf_put((byte)(v & 0xFF));
98 sf_put((byte)((v >> 8) & 0xFF));
99 sf_put((byte)((v >> 16) & 0xFF));
100 sf_put((byte)((v >> 24) & 0xFF));
104 * @brief 符号あり32ビットをファイルに書き込む
105 * @param v 書き込む符号あり32bit値
108 static void wr_s32b(s32b v)
114 * @brief 文字列をファイルに書き込む
118 static void wr_string(concptr str)
130 * These functions write info in larger logical records
135 * @brief アイテムオブジェクトを書き込む / Write an "item" record
136 * @param o_ptr アイテムオブジェクト保存元ポインタ
139 static void wr_item(object_type *o_ptr)
141 BIT_FLAGS flags = 0x00000000;
143 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
144 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
145 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
146 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
147 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
148 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
149 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
150 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
151 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
152 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
153 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
154 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
155 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
156 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
157 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
158 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
159 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
160 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
161 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
162 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
163 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
164 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
165 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
166 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
167 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
168 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
169 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
170 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
171 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
173 /*** Item save flags ***/
176 /*** Write only un-obvious elements ***/
177 wr_s16b(o_ptr->k_idx);
179 wr_byte((byte_hack)o_ptr->iy);
180 wr_byte((byte_hack)o_ptr->ix);
182 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
184 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
185 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
187 wr_s16b((s16b)o_ptr->weight);
189 if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
190 if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
191 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
193 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
194 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
195 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
196 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
197 if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
198 if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
200 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
202 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
204 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
205 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
206 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
207 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
208 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
210 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
212 /* Held by monster index */
213 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
215 /* Extra information */
216 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
217 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
218 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
219 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
220 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
223 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
225 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
226 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
231 * @brief モンスター情報を書き込む / Write a "monster" record
232 * @param m_ptr モンスター情報保存元ポインタ
235 static void wr_monster(monster_type *m_ptr)
237 BIT_FLAGS flags = 0x00000000;
240 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
241 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
242 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
243 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
244 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
245 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
246 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
247 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
248 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
249 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
250 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
251 if (m_ptr->smart) flags |= SAVE_MON_SMART;
252 if (m_ptr->exp) flags |= SAVE_MON_EXP;
253 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
254 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
255 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
257 /*** Monster save flags ***/
260 /*** Write only un-obvious elements ***/
261 wr_s16b(m_ptr->r_idx);
262 wr_byte((byte_hack)m_ptr->fy);
263 wr_byte((byte_hack)m_ptr->fx);
264 wr_s16b((s16b)m_ptr->hp);
265 wr_s16b((s16b)m_ptr->maxhp);
266 wr_s16b((s16b)m_ptr->max_maxhp);
267 wr_u32b(m_ptr->dealt_damage);
270 /* Monster race index of its appearance */
271 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
273 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
274 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
276 wr_byte((byte)m_ptr->mspeed);
277 wr_s16b(m_ptr->energy_need);
279 if (flags & SAVE_MON_FAST)
281 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
284 if (flags & SAVE_MON_SLOW)
286 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
289 if (flags & SAVE_MON_STUNNED)
291 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
294 if (flags & SAVE_MON_CONFUSED)
296 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
299 if (flags & SAVE_MON_MONFEAR)
301 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
304 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
305 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
306 if (flags & SAVE_MON_INVULNER)
308 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
311 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
312 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
313 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
314 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
315 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
320 * @brief モンスターの思い出を書き込む / Write a "lore" record
321 * @param r_idx モンスター種族ID
324 static void wr_lore(MONRACE_IDX r_idx)
326 monster_race *r_ptr = &r_info[r_idx];
328 /* Count sights/deaths/kills */
329 wr_s16b((s16b)r_ptr->r_sights);
330 wr_s16b((s16b)r_ptr->r_deaths);
331 wr_s16b((s16b)r_ptr->r_pkills);
332 wr_s16b((s16b)r_ptr->r_akills);
333 wr_s16b((s16b)r_ptr->r_tkills);
335 /* Count wakes and ignores */
336 wr_byte(r_ptr->r_wake);
337 wr_byte(r_ptr->r_ignore);
340 wr_byte(r_ptr->r_xtra1);
341 wr_byte(r_ptr->r_xtra2);
344 wr_byte((byte_hack)r_ptr->r_drop_gold);
345 wr_byte((byte_hack)r_ptr->r_drop_item);
348 wr_byte(0); /* unused now */
349 wr_byte(r_ptr->r_cast_spell);
351 /* Count blows of each type */
352 wr_byte(r_ptr->r_blows[0]);
353 wr_byte(r_ptr->r_blows[1]);
354 wr_byte(r_ptr->r_blows[2]);
355 wr_byte(r_ptr->r_blows[3]);
358 wr_u32b(r_ptr->r_flags1);
359 wr_u32b(r_ptr->r_flags2);
360 wr_u32b(r_ptr->r_flags3);
361 wr_u32b(r_ptr->r_flags4);
362 wr_u32b(r_ptr->r_flags5);
363 wr_u32b(r_ptr->r_flags6);
364 wr_u32b(r_ptr->r_flagsr);
366 /* Monster limit per level */
367 wr_byte((byte_hack)r_ptr->max_num);
369 /* Location in saved floor */
370 wr_s16b(r_ptr->floor_id);
377 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
378 * @param k_idx ベースアイテムのID
381 static void wr_xtra(KIND_OBJECT_IDX k_idx)
385 object_kind *k_ptr = &k_info[k_idx];
387 if (k_ptr->aware) tmp8u |= 0x01;
388 if (k_ptr->tried) tmp8u |= 0x02;
395 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
396 * @param st_ptr 店舗情報の参照ポインタ
399 static void wr_store(store_type *st_ptr)
403 /* Save the "open" counter */
404 wr_u32b(st_ptr->store_open);
406 /* Save the "insults" */
407 wr_s16b(st_ptr->insult_cur);
409 /* Save the current owner */
410 wr_byte(st_ptr->owner);
412 /* Save the stock size */
413 wr_s16b(st_ptr->stock_num);
415 /* Save the "haggle" info */
416 wr_s16b(st_ptr->good_buy);
417 wr_s16b(st_ptr->bad_buy);
419 wr_s32b(st_ptr->last_visit);
422 for (j = 0; j < st_ptr->stock_num; j++)
424 /* Save each item in stock */
425 wr_item(&st_ptr->stock[j]);
431 * @brief セーブデータに乱数情報を書き込む / Write RNG state
434 static errr wr_randomizer(void)
440 for (i = 0; i < RAND_DEG; i++)
442 wr_u32b(Rand_state[i]);
450 * @brief ゲームオプション情報を書き込む / Write the "options"
453 static void wr_options(void)
462 for (i = 0; i < 4; i++) wr_u32b(0L);
465 /*** Special Options ***/
467 /* Write "delay_factor" */
468 wr_byte(delay_factor);
470 /* Write "hitpoint_warn" */
471 wr_byte(hitpoint_warn);
473 /* Write "mana_warn" */
476 /*** Cheating options ***/
480 if (p_ptr->wizard) c |= 0x0002;
482 if (cheat_sight) c |= 0x0040;
483 if (cheat_turn) c |= 0x0080;
485 if (cheat_peek) c |= 0x0100;
486 if (cheat_hear) c |= 0x0200;
487 if (cheat_room) c |= 0x0400;
488 if (cheat_xtra) c |= 0x0800;
489 if (cheat_know) c |= 0x1000;
490 if (cheat_live) c |= 0x2000;
491 if (cheat_save) c |= 0x4000;
492 if (cheat_diary_output) c |= 0x8000;
499 wr_s16b(autosave_freq);
501 /*** Extract options ***/
503 /* Analyze the options */
504 for (i = 0; option_info[i].o_desc; i++)
506 int os = option_info[i].o_set;
507 int ob = option_info[i].o_bit;
509 /* Process real entries */
510 if (option_info[i].o_var)
513 if (*option_info[i].o_var)
516 option_flag[os] |= (1L << ob);
523 option_flag[os] &= ~(1L << ob);
529 /*** Normal options ***/
532 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
535 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
538 /*** Window options ***/
541 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
544 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
549 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
552 static void wr_ghost(void)
557 wr_string(_("不正なゴースト", "Broken Ghost"));
559 /* Hack -- stupid data */
560 for (i = 0; i < 60; i++) wr_byte(0);
565 * @brief クイック・スタート情報を書き込む / Save quick start data
568 static void save_quick_start(void)
572 wr_byte(previous_char.psex);
573 wr_byte((byte_hack)previous_char.prace);
574 wr_byte((byte_hack)previous_char.pclass);
575 wr_byte((byte_hack)previous_char.pseikaku);
576 wr_byte((byte_hack)previous_char.realm1);
577 wr_byte((byte_hack)previous_char.realm2);
579 wr_s16b(previous_char.age);
580 wr_s16b(previous_char.ht);
581 wr_s16b(previous_char.wt);
582 wr_s16b(previous_char.sc);
583 wr_s32b(previous_char.au);
585 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
586 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
588 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
590 wr_s16b(previous_char.chaos_patron);
592 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
594 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
596 /* UNUSED : Was number of random quests */
599 /* No quick start after using debug mode or cheat options */
600 if (p_ptr->noscore) previous_char.quick_ok = FALSE;
602 wr_byte((byte)previous_char.quick_ok);
607 * @brief その他の情報を書き込む / Write some "extra" info
610 static void wr_extra(void)
615 wr_string(p_ptr->name);
616 wr_string(p_ptr->died_from);
617 wr_string(p_ptr->last_message ? p_ptr->last_message : "");
621 for (i = 0; i < 4; i++)
623 wr_string(p_ptr->history[i]);
626 /* Race/Class/Gender/Spells */
627 wr_byte((byte_hack)p_ptr->prace);
628 wr_byte((byte_hack)p_ptr->pclass);
629 wr_byte((byte_hack)p_ptr->pseikaku);
630 wr_byte((byte_hack)p_ptr->psex);
631 wr_byte((byte_hack)p_ptr->realm1);
632 wr_byte((byte_hack)p_ptr->realm2);
635 wr_byte((byte)p_ptr->hitdie);
636 wr_u16b(p_ptr->expfact);
642 /* Dump the stats (maximum and current) */
643 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max[i]);
644 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max_max[i]);
645 for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_cur[i]);
647 /* Ignore the transient stats */
648 for (i = 0; i < 12; ++i) wr_s16b(0);
652 wr_u32b(p_ptr->max_exp);
653 wr_u32b(p_ptr->max_max_exp);
655 wr_u32b(p_ptr->exp_frac);
658 for (i = 0; i < 64; i++) wr_s16b(p_ptr->spell_exp[i]);
659 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(p_ptr->weapon_exp[i][j]);
660 for (i = 0; i < GINOU_MAX; i++) wr_s16b(p_ptr->skill_exp[i]);
661 for (i = 0; i < 108; i++) wr_s32b(p_ptr->magic_num1[i]);
662 for (i = 0; i < 108; i++) wr_byte(p_ptr->magic_num2[i]);
664 wr_byte((byte_hack)p_ptr->start_race);
665 wr_s32b(p_ptr->old_race1);
666 wr_s32b(p_ptr->old_race2);
667 wr_s16b(p_ptr->old_realm);
669 for (i = 0; i < MAX_MANE; i++)
671 wr_s16b((s16b)p_ptr->mane_spell[i]);
672 wr_s16b((s16b)p_ptr->mane_dam[i]);
674 wr_s16b(p_ptr->mane_num);
676 for (i = 0; i < MAX_KUBI; i++)
678 wr_s16b(current_world_ptr->bounty_r_idx[i]);
681 for (i = 0; i < 4; i++)
683 wr_s16b(battle_mon[i]);
684 wr_u32b(mon_odds[i]);
687 wr_s16b(p_ptr->town_num); /* -KMW- */
689 /* Write arena and rewards information -KMW- */
690 wr_s16b(p_ptr->arena_number);
691 wr_s16b(p_ptr->inside_arena);
692 wr_s16b(p_ptr->inside_quest);
693 wr_s16b(p_ptr->inside_battle);
694 wr_byte(p_ptr->exit_bldg);
695 wr_byte(0); /* Unused */
697 wr_s16b((s16b)p_ptr->oldpx);
698 wr_s16b((s16b)p_ptr->oldpy);
700 /* Was number of p_ptr->rewards[] */
705 wr_u32b(p_ptr->chp_frac);
709 wr_u32b(p_ptr->csp_frac);
711 /* Max Player and Dungeon Levels */
712 wr_s16b(p_ptr->max_plv);
713 tmp8u = (byte)max_d_idx;
715 for (i = 0; i < tmp8u; i++)
716 wr_s16b((s16b)max_dlv[i]);
724 wr_s16b(p_ptr->concent);
726 wr_s16b(0); /* old "rest" */
727 wr_s16b(p_ptr->blind);
728 wr_s16b(p_ptr->paralyzed);
729 wr_s16b(p_ptr->confused);
730 wr_s16b(p_ptr->food);
731 wr_s16b(0); /* old "food_digested" */
732 wr_s16b(0); /* old "protection" */
733 wr_s16b(p_ptr->energy_need);
734 wr_s16b(p_ptr->enchant_energy_need);
735 wr_s16b(p_ptr->fast);
736 wr_s16b(p_ptr->slow);
737 wr_s16b(p_ptr->afraid);
739 wr_s16b(p_ptr->stun);
740 wr_s16b(p_ptr->poisoned);
741 wr_s16b(p_ptr->image);
742 wr_s16b(p_ptr->protevil);
743 wr_s16b(p_ptr->invuln);
744 wr_s16b(p_ptr->ult_res);
745 wr_s16b(p_ptr->hero);
746 wr_s16b(p_ptr->shero);
747 wr_s16b(p_ptr->shield);
748 wr_s16b(p_ptr->blessed);
749 wr_s16b(p_ptr->tim_invis);
750 wr_s16b(p_ptr->word_recall);
751 wr_s16b(p_ptr->recall_dungeon);
752 wr_s16b(p_ptr->alter_reality);
753 wr_s16b(p_ptr->see_infra);
754 wr_s16b(p_ptr->tim_infra);
755 wr_s16b(p_ptr->oppose_fire);
756 wr_s16b(p_ptr->oppose_cold);
757 wr_s16b(p_ptr->oppose_acid);
758 wr_s16b(p_ptr->oppose_elec);
759 wr_s16b(p_ptr->oppose_pois);
760 wr_s16b(p_ptr->tsuyoshi);
761 wr_s16b(p_ptr->tim_esp);
762 wr_s16b(p_ptr->wraith_form);
763 wr_s16b(p_ptr->resist_magic);
764 wr_s16b(p_ptr->tim_regen);
765 wr_s16b(p_ptr->kabenuke);
766 wr_s16b(p_ptr->tim_stealth);
767 wr_s16b(p_ptr->tim_levitation);
768 wr_s16b(p_ptr->tim_sh_touki);
769 wr_s16b(p_ptr->lightspeed);
770 wr_s16b(p_ptr->tsubureru);
771 wr_s16b(p_ptr->magicdef);
772 wr_s16b(p_ptr->tim_res_nether);
773 wr_s16b(p_ptr->tim_res_time);
774 wr_byte((byte)p_ptr->mimic_form);
775 wr_s16b(p_ptr->tim_mimic);
776 wr_s16b(p_ptr->tim_sh_fire);
777 wr_s16b(p_ptr->tim_sh_holy);
778 wr_s16b(p_ptr->tim_eyeeye);
781 wr_s16b(p_ptr->tim_reflect);
782 wr_s16b(p_ptr->multishadow);
783 wr_s16b(p_ptr->dustrobe);
785 wr_s16b(p_ptr->chaos_patron);
786 wr_u32b(p_ptr->muta1);
787 wr_u32b(p_ptr->muta2);
788 wr_u32b(p_ptr->muta3);
790 for (i = 0; i<8; i++)
791 wr_s16b(p_ptr->virtues[i]);
792 for (i = 0; i<8; i++)
793 wr_s16b(p_ptr->vir_types[i]);
795 wr_s16b(p_ptr->ele_attack);
796 wr_u32b(p_ptr->special_attack);
797 wr_s16b(p_ptr->ele_immune);
798 wr_u32b(p_ptr->special_defense);
799 wr_byte(p_ptr->knowledge);
800 wr_byte(p_ptr->autopick_autoregister);
802 wr_byte((byte_hack)p_ptr->action);
804 wr_byte(preserve_mode);
805 wr_byte(p_ptr->wait_report_score);
808 for (i = 0; i < 12; i++) wr_u32b(0L);
810 /* Ignore some flags */
816 /* Write the "object seeds" */
817 wr_u32b(current_world_ptr->seed_flavor);
818 wr_u32b(current_world_ptr->seed_town);
822 wr_u16b(p_ptr->panic_save);
823 wr_u16b(p_ptr->total_winner);
824 wr_u16b(p_ptr->noscore);
828 wr_byte(p_ptr->is_dead);
831 wr_byte(p_ptr->feeling);
833 /* Turn when level began */
834 wr_s32b(current_floor_ptr->generated_turn);
836 /* Turn of last "feeling" */
837 wr_s32b(p_ptr->feeling_turn);
839 /* Current current_world_ptr->game_turn */
840 wr_s32b(current_world_ptr->game_turn);
842 wr_s32b(current_world_ptr->dungeon_turn);
847 wr_s16b(p_ptr->today_mon);
848 wr_s16b(p_ptr->riding);
850 /* Current floor_id */
851 wr_s16b(p_ptr->floor_id);
853 /* Save temporary preserved pets (obsolated) */
856 wr_u32b(current_world_ptr->play_time);
858 wr_s32b(p_ptr->visit);
860 wr_u32b(p_ptr->count);
865 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
866 * @param sf_ptr 保存したいフロアの参照ポインタ
869 static void wr_saved_floor(saved_floor_type *sf_ptr)
871 grid_template_type *templates;
886 /* Dungeon floor specific info follows */
890 /*** Not a saved floor ***/
892 wr_s16b((s16b)current_floor_ptr->dun_level);
896 /*** The saved floor ***/
898 wr_s16b(sf_ptr->floor_id);
899 wr_byte((byte_hack)sf_ptr->savefile_id);
900 wr_s16b((s16b)sf_ptr->dun_level);
901 wr_s32b(sf_ptr->last_visit);
902 wr_u32b(sf_ptr->visit_mark);
903 wr_s16b(sf_ptr->upper_floor_id);
904 wr_s16b(sf_ptr->lower_floor_id);
907 wr_u16b((u16b)current_floor_ptr->base_level);
908 wr_u16b((s16b)current_floor_ptr->num_repro);
909 wr_u16b((u16b)p_ptr->y);
910 wr_u16b((u16b)p_ptr->x);
911 wr_u16b((u16b)current_floor_ptr->height);
912 wr_u16b((u16b)current_floor_ptr->width);
913 wr_byte(p_ptr->feeling);
917 /*********** Make template for grid_type **********/
920 * Usually number of templates are fewer than 255. Even if
921 * more than 254 are exist, the occurrence of each template
922 * with larger ID is very small when we sort templates by
923 * occurrence. So we will use two (or more) bytes for
924 * templete ID larger than 254.
926 * Ex: 256 will be "0xff" "0x01".
927 * 515 will be "0xff" "0xff" "0x03"
930 /* Fake max number */
933 /* Allocate the "template" array */
934 C_MAKE(templates, max_num_temp, grid_template_type);
936 /* Extract template array */
937 for (y = 0; y < current_floor_ptr->height; y++)
939 for (x = 0; x < current_floor_ptr->width; x++)
941 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
943 for (i = 0; i < num_temp; i++)
945 if (templates[i].info == g_ptr->info &&
946 templates[i].feat == g_ptr->feat &&
947 templates[i].mimic == g_ptr->mimic &&
948 templates[i].special == g_ptr->special)
950 /* Same terrain is exist */
951 templates[i].occurrence++;
956 /* Are there same one? */
957 if (i < num_temp) continue;
959 /* If the max_num_temp is too small, increase it. */
960 if (num_temp >= max_num_temp)
962 grid_template_type *old_template = templates;
964 /* Re-allocate the "template" array */
965 C_MAKE(templates, max_num_temp + 255, grid_template_type);
966 (void)C_COPY(templates, old_template, max_num_temp, grid_template_type);
967 C_KILL(old_template, max_num_temp, grid_template_type);
971 /* Add new template */
972 templates[num_temp].info = g_ptr->info;
973 templates[num_temp].feat = g_ptr->feat;
974 templates[num_temp].mimic = g_ptr->mimic;
975 templates[num_temp].special = g_ptr->special;
976 templates[num_temp].occurrence = 1;
978 /* Increase number of template */
983 /* Sort by occurrence */
984 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
986 /*** Dump templates ***/
988 /* Total templates */
991 /* Dump the templates */
992 for (i = 0; i < num_temp; i++)
994 grid_template_type *ct_ptr = &templates[i];
997 wr_u16b((u16b)ct_ptr->info);
998 wr_s16b(ct_ptr->feat);
999 wr_s16b(ct_ptr->mimic);
1000 wr_s16b(ct_ptr->special);
1005 /*** "Run-Length-Encoding" of current_floor_ptr->grid_array ***/
1007 /* Note that this will induce two wasted bytes */
1011 /* Dump the current_floor_ptr->grid_array */
1012 for (y = 0; y < current_floor_ptr->height; y++)
1014 for (x = 0; x < current_floor_ptr->width; x++)
1016 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1018 for (i = 0; i < num_temp; i++)
1020 if (templates[i].info == g_ptr->info &&
1021 templates[i].feat == g_ptr->feat &&
1022 templates[i].mimic == g_ptr->mimic &&
1023 templates[i].special == g_ptr->special)
1030 /* If the run is broken, or too full, flush it */
1031 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
1033 wr_byte((byte)count);
1035 while (prev_u16b >= MAX_UCHAR)
1037 /* Mark as actual data is larger than 254 */
1039 prev_u16b -= MAX_UCHAR;
1042 wr_byte((byte)prev_u16b);
1047 /* Continue the run */
1055 /* Flush the data (if any) */
1058 wr_byte((byte)count);
1060 while (prev_u16b >= MAX_UCHAR)
1062 /* Mark as actual data is larger than 254 */
1064 prev_u16b -= MAX_UCHAR;
1066 wr_byte((byte)prev_u16b);
1070 /* Free the "template" array */
1071 C_KILL(templates, max_num_temp, grid_template_type);
1074 /*** Dump objects ***/
1077 wr_u16b(current_floor_ptr->o_max);
1079 /* Dump the objects */
1080 for (i = 1; i < current_floor_ptr->o_max; i++)
1082 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
1089 /*** Dump the monsters ***/
1091 /* Total monsters */
1092 wr_u16b(current_floor_ptr->m_max);
1094 /* Dump the monsters */
1095 for (i = 1; i < current_floor_ptr->m_max; i++)
1097 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1106 * @brief 現在フロアの書き込み /
1107 * Write the current dungeon (new method)
1110 static bool wr_dungeon(void)
1112 saved_floor_type *cur_sf_ptr;
1119 /* Update lite/view */
1120 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1121 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1125 /* Number of floor_id used from birth */
1126 wr_s16b(max_floor_id);
1128 /* Current dungeon type */
1129 wr_byte((byte_hack)p_ptr->dungeon_idx);
1132 /*** No saved floor (On the surface etc.) ***/
1133 if (!p_ptr->floor_id)
1135 /* No array elements */
1138 /* Write the current floor data */
1139 wr_saved_floor(NULL);
1146 /*** In the dungeon ***/
1148 /* Number of array elements */
1149 wr_byte(MAX_SAVED_FLOORS);
1151 /* Write the saved_floors array */
1152 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1154 saved_floor_type *sf_ptr = &saved_floors[i];
1156 wr_s16b(sf_ptr->floor_id);
1157 wr_byte((byte_hack)sf_ptr->savefile_id);
1158 wr_s16b((s16b)sf_ptr->dun_level);
1159 wr_s32b(sf_ptr->last_visit);
1160 wr_u32b(sf_ptr->visit_mark);
1161 wr_s16b(sf_ptr->upper_floor_id);
1162 wr_s16b(sf_ptr->lower_floor_id);
1165 /* Extract pointer to current floor */
1166 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1168 /* Save current floor to temporal file */
1169 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1171 /* Move data in temporal files to the savefile */
1172 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1174 saved_floor_type *sf_ptr = &saved_floors[i];
1176 /* Unused element */
1177 if (!sf_ptr->floor_id) continue;
1179 /* Load temporal saved floor file */
1180 if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1185 /* Write saved floor data to the save file */
1186 wr_saved_floor(sf_ptr);
1195 /* Restore current floor */
1196 if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1204 * @brief セーブデータの書き込み /
1205 * Actually write a save-file
1208 static bool wr_savefile_new(void)
1219 KIND_OBJECT_IDX k_idx;
1221 /* Compact the objects */
1223 /* Compact the monsters */
1224 compact_monsters(0);
1226 /* Guess at the current time */
1227 now = (u32b)time((time_t *)0);
1230 /* Note the operating system */
1233 /* Note when the file was saved */
1236 /* Note the number of saves */
1240 /*** Actually write the file ***/
1242 /* Dump the file header */
1244 wr_byte(FAKE_VER_MAJOR);
1246 wr_byte(FAKE_VER_MINOR);
1248 wr_byte(FAKE_VER_PATCH);
1251 /* Initial value of xor_byte */
1252 tmp8u = (byte)Rand_external(256);
1256 /* Reset the checksum */
1260 /* Write the savefile version for Hengband 1.1.1 and later */
1261 wr_byte(H_VER_EXTRA);
1262 wr_byte(H_VER_PATCH);
1263 wr_byte(H_VER_MINOR);
1264 wr_byte(H_VER_MAJOR);
1266 /* Operating system */
1270 /* Time file last saved */
1273 /* Number of past lives */
1276 /* Number of times saved */
1287 /* EUC kanji code */
1291 /* SJIS kanji code */
1299 /* Write the RNG state */
1303 /* Write the boolean "options" */
1307 /* Dump the number of "messages" */
1308 tmp32u = message_num();
1309 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1312 /* Dump the messages (oldest first!) */
1313 for (i = tmp32u - 1; i >= 0; i--)
1315 wr_string(message_str((s16b)i));
1318 /* Dump the monster lore */
1321 for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
1323 /* Dump the object memory */
1326 for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
1328 /* Dump the towns */
1332 /* Dump the quests */
1336 /* Dump the quests */
1337 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1340 for (i = 0; i < max_q_idx; i++)
1342 quest_type* const q_ptr = &quest[i];
1344 /* Save status for every quest */
1345 wr_s16b(q_ptr->status);
1347 /* And the dungeon level too */
1348 /* (prevents problems with multi-level quests) */
1349 wr_s16b((s16b)q_ptr->level);
1351 wr_byte((byte_hack)q_ptr->complev);
1352 wr_u32b(q_ptr->comptime);
1354 /* Save quest status if quest is running */
1355 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1357 wr_s16b((s16b)q_ptr->cur_num);
1358 wr_s16b((s16b)q_ptr->max_num);
1359 wr_s16b(q_ptr->type);
1360 wr_s16b(q_ptr->r_idx);
1361 wr_s16b(q_ptr->k_idx);
1362 wr_byte((byte_hack)q_ptr->flags);
1363 wr_byte((byte_hack)q_ptr->dungeon);
1367 /* Dump the position in the wilderness */
1368 wr_s32b(p_ptr->wilderness_x);
1369 wr_s32b(p_ptr->wilderness_y);
1371 wr_byte(p_ptr->wild_mode);
1372 wr_byte(p_ptr->ambush_flag);
1374 wr_s32b(current_world_ptr->max_wild_x);
1375 wr_s32b(current_world_ptr->max_wild_y);
1377 /* Dump the wilderness seeds */
1378 for (i = 0; i < current_world_ptr->max_wild_x; i++)
1380 for (j = 0; j < current_world_ptr->max_wild_y; j++)
1382 wr_u32b(wilderness[j][i].seed);
1386 /* Hack -- Dump the artifacts */
1389 for (i = 0; i < tmp16u; i++)
1391 artifact_type *a_ptr = &a_info[i];
1392 wr_byte(a_ptr->cur_num);
1393 wr_s16b(a_ptr->floor_id);
1398 /* Write the "extra" information */
1401 /* Dump the "player hp" entries */
1402 tmp16u = PY_MAX_LEVEL;
1404 for (i = 0; i < tmp16u; i++)
1406 wr_s16b((s16b)p_ptr->player_hp[i]);
1410 /* Write spell data */
1411 wr_u32b(p_ptr->spell_learned1);
1412 wr_u32b(p_ptr->spell_learned2);
1413 wr_u32b(p_ptr->spell_worked1);
1414 wr_u32b(p_ptr->spell_worked2);
1415 wr_u32b(p_ptr->spell_forgotten1);
1416 wr_u32b(p_ptr->spell_forgotten2);
1418 wr_s16b(p_ptr->learned_spells);
1419 wr_s16b(p_ptr->add_spells);
1421 /* Dump the ordered spells */
1422 for (i = 0; i < 64; i++)
1424 wr_byte((byte_hack)p_ptr->spell_order[i]);
1428 /* Write the p_ptr->inventory_list */
1429 for (i = 0; i < INVEN_TOTAL; i++)
1431 object_type *o_ptr = &p_ptr->inventory_list[i];
1432 if (!o_ptr->k_idx) continue;
1441 /* Add a sentinel */
1444 /* Note the towns */
1448 /* Note the stores */
1449 tmp16u = MAX_STORES;
1452 /* Dump the stores of all towns */
1453 for (i = 1; i < max_towns; i++)
1455 for (j = 0; j < MAX_STORES; j++)
1457 wr_store(&town_info[i].store[j]);
1461 /* Write the pet command settings */
1462 wr_s16b(p_ptr->pet_follow_distance);
1463 wr_s16b(p_ptr->pet_extra_flags);
1465 /* Write screen dump for sending score */
1466 if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead))
1468 wr_string(screen_dump);
1475 /* Player is not dead, write the dungeon */
1476 if (!p_ptr->is_dead)
1478 /* Dump the dungeon */
1479 if (!wr_dungeon()) return FALSE;
1481 /* Dump the ghost */
1489 /* Write the "value check-sum" */
1492 /* Write the "encoded checksum" */
1497 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1499 /* Successful save */
1505 * @brief セーブデータ書き込みのサブルーチン /
1506 * Medium level player saver
1509 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1511 static bool save_player_aux(char *name)
1520 /* File type is "SAVE" */
1521 FILE_TYPE(FILE_TYPE_SAVE);
1523 /* Grab permissions */
1526 /* Create the savefile */
1527 fd = fd_make(name, mode);
1529 /* Drop permissions */
1535 /* Close the "fd" */
1538 /* Grab permissions */
1541 /* Open the savefile */
1542 fff = my_fopen(name, "wb");
1544 /* Drop permissions */
1547 /* Successful open */
1550 /* Write the savefile */
1551 if (wr_savefile_new()) ok = TRUE;
1553 /* Attempt to close it */
1554 if (my_fclose(fff)) ok = FALSE;
1557 /* Grab permissions */
1560 /* Remove "broken" files */
1561 if (!ok) (void)fd_kill(name);
1563 /* Drop permissions */
1569 if (!ok) return (FALSE);
1571 counts_write(0, current_world_ptr->play_time);
1573 /* Successful save */
1574 character_saved = TRUE;
1583 * @brief セーブデータ書き込みのメインルーチン /
1584 * Attempt to save the player in a savefile
1587 bool save_player(void)
1589 bool result = FALSE;
1598 /* Get "games" permissions */
1607 strcpy(safe, savefile);
1608 strcat(safe, ".new");
1610 /* Grab permissions */
1616 /* Drop permissions */
1621 /* Attempt to save the player */
1622 if (save_player_aux(safe))
1627 strcpy(temp, savefile);
1628 strcat(temp, ".old");
1630 /* Grab permissions */
1636 /* Preserve old savefile */
1637 fd_move(savefile, temp);
1639 /* Activate new savefile */
1640 fd_move(safe, savefile);
1642 /* Remove preserved savefile */
1645 /* Drop permissions */
1648 /* Hack -- Pretend the character was loaded */
1649 character_loaded = TRUE;
1651 #ifdef VERIFY_SAVEFILE
1653 /* Lock on savefile */
1654 strcpy(temp, savefile);
1655 strcat(temp, ".lok");
1657 /* Grab permissions */
1660 /* Remove lock file */
1663 /* Drop permissions */
1677 /* Drop "games" permissions */
1684 /* Return the result */
1690 * @brief セーブデータ読み込みのメインルーチン /
1691 * Attempt to Load a "savefile"
1695 * Version 2.7.0 introduced a slightly different "savefile" format from
1696 * older versions, requiring a completely different parsing method.
1698 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1700 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1702 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1704 * On multi-user systems, you may only "read" a savefile if you will be
1705 * allowed to "write" it later, this prevents painful situations in which
1706 * the player loads a savefile belonging to someone else, and then is not
1707 * allowed to save his game when he quits.
1709 * We return "TRUE" if the savefile was usable, and we set the global
1710 * flag "character_loaded" if a real, living, character was loaded.
1712 * Note that we always try to load the "current" savefile, even if
1713 * there is no such file, so we must check for "empty" savefile names.
1716 bool load_player(void)
1724 #ifdef VERIFY_TIMESTAMP
1725 struct stat statbuf;
1728 concptr what = "generic";
1730 current_world_ptr->game_turn = 0;
1731 p_ptr->is_dead = FALSE;
1734 /* Allow empty savefile name */
1735 if (!savefile[0]) return (TRUE);
1738 #if !defined(MACINTOSH) && !defined(WINDOWS)
1742 /* Verify the existance of the savefile */
1743 if (access(savefile, 0) < 0)
1745 /* Give a message */
1746 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1757 #ifdef VERIFY_SAVEFILE
1759 /* Verify savefile usage */
1766 /* Extract name of lock file */
1767 strcpy(temp, savefile);
1768 strcat(temp, ".lok");
1770 /* Check for lock */
1771 fkk = my_fopen(temp, "r");
1773 /* Oops, lock exists */
1778 msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
1784 /* Create a lock file */
1785 fkk = my_fopen(temp, "w");
1787 /* Dump a line of info */
1788 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1790 /* Close the lock file */
1799 /* Open the savefile */
1800 fd = fd_open(savefile, O_RDONLY);
1803 if (fd < 0) err = -1;
1805 /* Message (below) */
1806 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1813 #ifdef VERIFY_TIMESTAMP
1814 /* Get the timestamp */
1815 (void)fstat(fd, &statbuf);
1818 /* Read the first four bytes */
1819 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1822 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1830 /* Extract version */
1838 /* Attempt to load */
1839 err = rd_savefile_new();
1841 /* Message (below) */
1842 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1846 /* Invalid current_world_ptr->game_turn */
1847 if (!current_world_ptr->game_turn) err = -1;
1849 /* Message (below) */
1850 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1853 #ifdef VERIFY_TIMESTAMP
1854 /* Verify timestamp */
1855 if (!err && !arg_wizard)
1857 /* Hack -- Verify the timestamp */
1858 if (sf_when > (statbuf.st_ctime + 100) ||
1859 sf_when < (statbuf.st_ctime - 100))
1861 what = _("無効なタイム・スタンプです", "Invalid timestamp");
1871 /* Give a conversion warning */
1872 if ((FAKE_VER_MAJOR != z_major) ||
1873 (FAKE_VER_MINOR != z_minor) ||
1874 (FAKE_VER_PATCH != z_patch))
1876 if (z_major == 2 && z_minor == 0 && z_patch == 6)
1878 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1882 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1883 (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
1888 /* Player is dead */
1894 /* A character was loaded */
1895 character_loaded = TRUE;
1899 /* Player is no longer "dead" */
1900 p_ptr->is_dead = FALSE;
1908 /* A character was loaded */
1909 character_loaded = TRUE;
1912 u32b tmp = counts_read(2);
1913 if (tmp > p_ptr->count)
1915 if (counts_read(0) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
1916 counts_write(2, ++p_ptr->count);
1917 counts_write(1, current_world_ptr->play_time);
1925 #ifdef VERIFY_SAVEFILE
1927 /* Verify savefile usage */
1932 /* Extract name of lock file */
1933 strcpy(temp, savefile);
1934 strcat(temp, ".lok");
1942 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1943 what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
1954 void remove_loc(void)
1956 #ifdef VERIFY_SAVEFILE
1958 #endif /* VERIFY_SAVEFILE */
1963 /* Get "games" permissions */
1966 # endif /* SECURE */
1967 #endif /* SET_UID */
1969 #ifdef VERIFY_SAVEFILE
1971 /* Lock on savefile */
1972 strcpy(temp, savefile);
1973 strcat(temp, ".lok");
1975 /* Remove lock file */
1978 #endif /* VERIFY_SAVEFILE */
1983 /* Drop "games" permissions */
1986 # endif /* SECURE */
1987 #endif /* SET_UID */
1993 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporal saved floor file
1994 * @param sf_ptr 保存フロア参照ポインタ
1997 static bool save_floor_aux(saved_floor_type *sf_ptr)
2001 /* Compact the objects */
2003 /* Compact the monsters */
2004 compact_monsters(0);
2007 /*** Actually write the file ***/
2009 /* Initial value of xor_byte */
2010 tmp8u = (byte)randint0(256);
2015 /* Reset the checksum */
2019 /* Write the sign of this process */
2020 wr_u32b(saved_floor_file_sign);
2022 /* Dump the dungeon floor */
2023 wr_saved_floor(sf_ptr);
2026 /* Write the "value check-sum" */
2029 /* Write the "encoded checksum" */
2034 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2036 /* Successful save */
2042 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data
2043 * @param sf_ptr 保存フロア参照ポインタ
2044 * @param mode 保存オプション
2047 bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
2049 FILE *old_fff = NULL;
2050 byte old_xor_byte = 0;
2051 u32b old_v_stamp = 0;
2052 u32b old_x_stamp = 0;
2054 char floor_savefile[1024];
2058 if (!(mode & SLF_SECOND))
2062 /* Get "games" permissions */
2068 /* We have one file already opened */
2071 /* Backup original values */
2073 old_xor_byte = xor_byte;
2074 old_v_stamp = v_stamp;
2075 old_x_stamp = x_stamp;
2079 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2081 /* Grab permissions */
2085 fd_kill(floor_savefile);
2087 /* Drop permissions */
2091 /* Attempt to save the player */
2096 /* File type is "SAVE" */
2097 FILE_TYPE(FILE_TYPE_SAVE);
2099 /* Grab permissions */
2102 /* Create the savefile */
2103 fd = fd_make(floor_savefile, 0644);
2105 /* Drop permissions */
2111 /* Close the "fd" */
2114 /* Grab permissions */
2117 /* Open the savefile */
2118 fff = my_fopen(floor_savefile, "wb");
2120 /* Drop permissions */
2123 /* Successful open */
2126 /* Write the savefile */
2127 if (save_floor_aux(sf_ptr)) ok = TRUE;
2129 /* Attempt to close it */
2130 if (my_fclose(fff)) ok = FALSE;
2133 /* Remove "broken" files */
2136 /* Grab permissions */
2139 (void)fd_kill(floor_savefile);
2141 /* Drop permissions */
2146 if (!(mode & SLF_SECOND))
2150 /* Drop "games" permissions */
2156 /* We have one file already opened */
2159 /* Restore original values */
2161 xor_byte = old_xor_byte;
2162 v_stamp = old_v_stamp;
2163 x_stamp = old_x_stamp;
2166 /* Return the result */