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.
28 #include "floor-events.h"
29 #include "floor-save.h"
30 #include "floor-town.h"
33 #include "objectkind.h"
34 #include "monsterrace.h"
40 * Some "local" parameters, used to help write savefiles
43 static FILE *fff; /* Current save "file" */
44 static byte xor_byte; /* Simple encryption */
45 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
46 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
51 * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
55 static void sf_put(byte v)
57 /* Encode the value, write a character */
59 (void)putc((int)xor_byte, fff);
61 /* Maintain the checksum info */
67 * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
71 static void wr_byte(byte v)
77 * @brief 符号なし16ビットをファイルに書き込む
78 * @param v 書き込む符号なし16bit値
81 static void wr_u16b(u16b v)
83 sf_put((byte)(v & 0xFF));
84 sf_put((byte)((v >> 8) & 0xFF));
88 * @brief 符号あり16ビットをファイルに書き込む
89 * @param v 書き込む符号あり16bit値
92 static void wr_s16b(s16b v)
98 * @brief 符号なし32ビットをファイルに書き込む
99 * @param v 書き込む符号なし32bit値
102 static void wr_u32b(u32b v)
104 sf_put((byte)(v & 0xFF));
105 sf_put((byte)((v >> 8) & 0xFF));
106 sf_put((byte)((v >> 16) & 0xFF));
107 sf_put((byte)((v >> 24) & 0xFF));
111 * @brief 符号あり32ビットをファイルに書き込む
112 * @param v 書き込む符号あり32bit値
115 static void wr_s32b(s32b v)
121 * @brief 文字列をファイルに書き込む
125 static void wr_string(concptr str)
137 * These functions write info in larger logical records
142 * @brief アイテムオブジェクトを書き込む / Write an "item" record
143 * @param o_ptr アイテムオブジェクト保存元ポインタ
146 static void wr_item(object_type *o_ptr)
148 BIT_FLAGS flags = 0x00000000;
150 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
151 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
152 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
153 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
154 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
155 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
156 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
157 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
158 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
159 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
160 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
161 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
162 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
163 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
164 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
165 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
166 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
167 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
168 if (o_ptr->art_flags[4]) flags |= SAVE_ITEM_ART_FLAGS4;
169 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
170 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
171 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
172 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
173 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
174 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
175 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
176 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
177 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
178 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
180 /*** Item save flags ***/
183 /*** Write only un-obvious elements ***/
184 wr_s16b(o_ptr->k_idx);
186 wr_byte((byte_hack)o_ptr->iy);
187 wr_byte((byte_hack)o_ptr->ix);
189 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
191 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
192 if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
194 wr_s16b((s16b)o_ptr->weight);
196 if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
197 if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
198 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
200 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
201 if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
202 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
203 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
204 if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
205 if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
207 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
209 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
211 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
212 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
213 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
214 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
215 if (flags & SAVE_ITEM_ART_FLAGS4) wr_u32b(o_ptr->art_flags[4]);
217 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
219 /* Held by monster index */
220 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
222 /* Extra information */
223 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
224 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
225 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
226 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
227 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
230 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
232 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
233 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
238 * @brief モンスター情報を書き込む / Write a "monster" record
239 * @param m_ptr モンスター情報保存元ポインタ
242 static void wr_monster(monster_type *m_ptr)
244 BIT_FLAGS flags = 0x00000000;
247 if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
248 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
249 if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
250 if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
251 if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
252 if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
253 if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
254 if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
255 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
256 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
257 if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
258 if (m_ptr->smart) flags |= SAVE_MON_SMART;
259 if (m_ptr->exp) flags |= SAVE_MON_EXP;
260 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
261 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
262 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
264 /*** Monster save flags ***/
267 /*** Write only un-obvious elements ***/
268 wr_s16b(m_ptr->r_idx);
269 wr_byte((byte_hack)m_ptr->fy);
270 wr_byte((byte_hack)m_ptr->fx);
271 wr_s16b((s16b)m_ptr->hp);
272 wr_s16b((s16b)m_ptr->maxhp);
273 wr_s16b((s16b)m_ptr->max_maxhp);
274 wr_u32b(m_ptr->dealt_damage);
277 /* Monster race index of its appearance */
278 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
280 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
281 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
283 wr_byte((byte)m_ptr->mspeed);
284 wr_s16b(m_ptr->energy_need);
286 if (flags & SAVE_MON_FAST)
288 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
291 if (flags & SAVE_MON_SLOW)
293 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
296 if (flags & SAVE_MON_STUNNED)
298 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
301 if (flags & SAVE_MON_CONFUSED)
303 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
306 if (flags & SAVE_MON_MONFEAR)
308 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
311 if (flags & SAVE_MON_TARGET_Y) wr_s16b((s16b)m_ptr->target_y);
312 if (flags & SAVE_MON_TARGET_X) wr_s16b((s16b)m_ptr->target_x);
313 if (flags & SAVE_MON_INVULNER)
315 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
318 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
319 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
320 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
321 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
322 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
327 * @brief モンスターの思い出を書き込む / Write a "lore" record
328 * @param r_idx モンスター種族ID
331 static void wr_lore(MONRACE_IDX r_idx)
333 monster_race *r_ptr = &r_info[r_idx];
335 /* Count sights/deaths/kills */
336 wr_s16b((s16b)r_ptr->r_sights);
337 wr_s16b((s16b)r_ptr->r_deaths);
338 wr_s16b((s16b)r_ptr->r_pkills);
339 wr_s16b((s16b)r_ptr->r_akills);
340 wr_s16b((s16b)r_ptr->r_tkills);
342 /* Count wakes and ignores */
343 wr_byte(r_ptr->r_wake);
344 wr_byte(r_ptr->r_ignore);
347 wr_byte(r_ptr->r_xtra1);
348 wr_byte(r_ptr->r_xtra2);
351 wr_byte((byte_hack)r_ptr->r_drop_gold);
352 wr_byte((byte_hack)r_ptr->r_drop_item);
355 wr_byte(0); /* unused now */
356 wr_byte(r_ptr->r_cast_spell);
358 /* Count blows of each type */
359 wr_byte(r_ptr->r_blows[0]);
360 wr_byte(r_ptr->r_blows[1]);
361 wr_byte(r_ptr->r_blows[2]);
362 wr_byte(r_ptr->r_blows[3]);
365 wr_u32b(r_ptr->r_flags1);
366 wr_u32b(r_ptr->r_flags2);
367 wr_u32b(r_ptr->r_flags3);
368 wr_u32b(r_ptr->r_flags4);
369 wr_u32b(r_ptr->r_flags5);
370 wr_u32b(r_ptr->r_flags6);
371 wr_u32b(r_ptr->r_flagsr);
373 /* Monster limit per level */
374 wr_byte((byte_hack)r_ptr->max_num);
376 /* Location in saved floor */
377 wr_s16b(r_ptr->floor_id);
384 * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
385 * @param k_idx ベースアイテムのID
388 static void wr_xtra(KIND_OBJECT_IDX k_idx)
392 object_kind *k_ptr = &k_info[k_idx];
394 if (k_ptr->aware) tmp8u |= 0x01;
395 if (k_ptr->tried) tmp8u |= 0x02;
402 * @brief セーブデータに店舗情報を書き込む / Write a "store" record
403 * @param st_ptr 店舗情報の参照ポインタ
406 static void wr_store(store_type *st_ptr)
410 /* Save the "open" counter */
411 wr_u32b(st_ptr->store_open);
413 /* Save the "insults" */
414 wr_s16b(st_ptr->insult_cur);
416 /* Save the current owner */
417 wr_byte(st_ptr->owner);
419 /* Save the stock size */
420 wr_s16b(st_ptr->stock_num);
422 /* Save the "haggle" info */
423 wr_s16b(st_ptr->good_buy);
424 wr_s16b(st_ptr->bad_buy);
426 wr_s32b(st_ptr->last_visit);
429 for (j = 0; j < st_ptr->stock_num; j++)
431 /* Save each item in stock */
432 wr_item(&st_ptr->stock[j]);
438 * @brief セーブデータに乱数情報を書き込む / Write RNG state
441 static errr wr_randomizer(void)
447 for (i = 0; i < RAND_DEG; i++)
449 wr_u32b(Rand_state[i]);
457 * @brief ゲームオプション情報を書き込む / Write the "options"
460 static void wr_options(void)
469 for (i = 0; i < 4; i++) wr_u32b(0L);
472 /*** Special Options ***/
474 /* Write "delay_factor" */
475 wr_byte(delay_factor);
477 /* Write "hitpoint_warn" */
478 wr_byte(hitpoint_warn);
480 /* Write "mana_warn" */
483 /*** Cheating options ***/
487 if (current_world_ptr->wizard) c |= 0x0002;
489 if (cheat_sight) c |= 0x0040;
490 if (cheat_turn) c |= 0x0080;
492 if (cheat_peek) c |= 0x0100;
493 if (cheat_hear) c |= 0x0200;
494 if (cheat_room) c |= 0x0400;
495 if (cheat_xtra) c |= 0x0800;
496 if (cheat_know) c |= 0x1000;
497 if (cheat_live) c |= 0x2000;
498 if (cheat_save) c |= 0x4000;
499 if (cheat_diary_output) c |= 0x8000;
506 wr_s16b(autosave_freq);
508 /*** Extract options ***/
510 /* Analyze the options */
511 for (i = 0; option_info[i].o_desc; i++)
513 int os = option_info[i].o_set;
514 int ob = option_info[i].o_bit;
516 /* Process real entries */
517 if (option_info[i].o_var)
520 if (*option_info[i].o_var)
523 option_flag[os] |= (1L << ob);
527 option_flag[os] &= ~(1L << ob);
533 /*** Normal options ***/
536 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
539 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
542 /*** Window options ***/
545 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
548 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
553 * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
556 static void wr_ghost(void)
561 wr_string(_("不正なゴースト", "Broken Ghost"));
563 /* Hack -- stupid data */
564 for (i = 0; i < 60; i++) wr_byte(0);
569 * @brief クイック・スタート情報を書き込む / Save quick start data
572 static void save_quick_start(void)
576 wr_byte(previous_char.psex);
577 wr_byte((byte_hack)previous_char.prace);
578 wr_byte((byte_hack)previous_char.pclass);
579 wr_byte((byte_hack)previous_char.pseikaku);
580 wr_byte((byte_hack)previous_char.realm1);
581 wr_byte((byte_hack)previous_char.realm2);
583 wr_s16b(previous_char.age);
584 wr_s16b(previous_char.ht);
585 wr_s16b(previous_char.wt);
586 wr_s16b(previous_char.sc);
587 wr_s32b(previous_char.au);
589 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
590 for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
592 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
594 wr_s16b(previous_char.chaos_patron);
596 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
598 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
600 /* UNUSED : Was number of random quests */
603 /* No quick start after using debug mode or cheat options */
604 if (current_world_ptr->noscore) previous_char.quick_ok = FALSE;
606 wr_byte((byte)previous_char.quick_ok);
611 * @brief その他の情報を書き込む / Write some "extra" info
614 static void wr_extra(player_type *creature_ptr)
619 wr_string(creature_ptr->name);
620 wr_string(creature_ptr->died_from);
621 wr_string(creature_ptr->last_message ? creature_ptr->last_message : "");
625 for (i = 0; i < 4; i++)
627 wr_string(creature_ptr->history[i]);
630 /* Race/Class/Gender/Spells */
631 wr_byte((byte_hack)creature_ptr->prace);
632 wr_byte((byte_hack)creature_ptr->pclass);
633 wr_byte((byte_hack)creature_ptr->pseikaku);
634 wr_byte((byte_hack)creature_ptr->psex);
635 wr_byte((byte_hack)creature_ptr->realm1);
636 wr_byte((byte_hack)creature_ptr->realm2);
639 wr_byte((byte)creature_ptr->hitdie);
640 wr_u16b(creature_ptr->expfact);
642 wr_s16b(creature_ptr->age);
643 wr_s16b(creature_ptr->ht);
644 wr_s16b(creature_ptr->wt);
646 /* Dump the stats (maximum and current) */
647 for (i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max[i]);
648 for (i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max_max[i]);
649 for (i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_cur[i]);
651 /* Ignore the transient stats */
652 for (i = 0; i < 12; ++i) wr_s16b(0);
654 wr_u32b(creature_ptr->au);
656 wr_u32b(creature_ptr->max_exp);
657 wr_u32b(creature_ptr->max_max_exp);
658 wr_u32b(creature_ptr->exp);
659 wr_u32b(creature_ptr->exp_frac);
660 wr_s16b(creature_ptr->lev);
662 for (i = 0; i < 64; i++) wr_s16b(creature_ptr->spell_exp[i]);
663 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(creature_ptr->weapon_exp[i][j]);
664 for (i = 0; i < GINOU_MAX; i++) wr_s16b(creature_ptr->skill_exp[i]);
665 for (i = 0; i < 108; i++) wr_s32b(creature_ptr->magic_num1[i]);
666 for (i = 0; i < 108; i++) wr_byte(creature_ptr->magic_num2[i]);
668 wr_byte((byte_hack)creature_ptr->start_race);
669 wr_s32b(creature_ptr->old_race1);
670 wr_s32b(creature_ptr->old_race2);
671 wr_s16b(creature_ptr->old_realm);
673 for (i = 0; i < MAX_MANE; i++)
675 wr_s16b((s16b)creature_ptr->mane_spell[i]);
676 wr_s16b((s16b)creature_ptr->mane_dam[i]);
678 wr_s16b(creature_ptr->mane_num);
680 for (i = 0; i < MAX_BOUNTY; i++)
682 wr_s16b(current_world_ptr->bounty_r_idx[i]);
685 for (i = 0; i < 4; i++)
687 wr_s16b(battle_mon[i]);
688 wr_u32b(mon_odds[i]);
691 wr_s16b(creature_ptr->town_num); /* -KMW- */
693 /* Write arena and rewards information -KMW- */
694 wr_s16b(creature_ptr->arena_number);
695 wr_s16b(creature_ptr->current_floor_ptr->inside_arena);
696 wr_s16b(creature_ptr->current_floor_ptr->inside_quest);
697 wr_s16b(creature_ptr->phase_out);
698 wr_byte(creature_ptr->exit_bldg);
699 wr_byte(0); /* Unused */
701 wr_s16b((s16b)creature_ptr->oldpx);
702 wr_s16b((s16b)creature_ptr->oldpy);
704 /* Was number of creature_ptr->rewards[] */
707 wr_s32b(creature_ptr->mhp);
708 wr_s32b(creature_ptr->chp);
709 wr_u32b(creature_ptr->chp_frac);
711 wr_s32b(creature_ptr->msp);
712 wr_s32b(creature_ptr->csp);
713 wr_u32b(creature_ptr->csp_frac);
715 /* Max Player and Dungeon Levels */
716 wr_s16b(creature_ptr->max_plv);
717 tmp8u = (byte)current_world_ptr->max_d_idx;
719 for (i = 0; i < tmp8u; i++)
720 wr_s16b((s16b)max_dlv[i]);
727 wr_s16b(creature_ptr->sc);
728 wr_s16b(creature_ptr->concent);
730 wr_s16b(0); /* old "rest" */
731 wr_s16b(creature_ptr->blind);
732 wr_s16b(creature_ptr->paralyzed);
733 wr_s16b(creature_ptr->confused);
734 wr_s16b(creature_ptr->food);
735 wr_s16b(0); /* old "food_digested" */
736 wr_s16b(0); /* old "protection" */
737 wr_s16b(creature_ptr->energy_need);
738 wr_s16b(creature_ptr->enchant_energy_need);
739 wr_s16b(creature_ptr->fast);
740 wr_s16b(creature_ptr->slow);
741 wr_s16b(creature_ptr->afraid);
742 wr_s16b(creature_ptr->cut);
743 wr_s16b(creature_ptr->stun);
744 wr_s16b(creature_ptr->poisoned);
745 wr_s16b(creature_ptr->image);
746 wr_s16b(creature_ptr->protevil);
747 wr_s16b(creature_ptr->invuln);
748 wr_s16b(creature_ptr->ult_res);
749 wr_s16b(creature_ptr->hero);
750 wr_s16b(creature_ptr->shero);
751 wr_s16b(creature_ptr->shield);
752 wr_s16b(creature_ptr->blessed);
753 wr_s16b(creature_ptr->tim_invis);
754 wr_s16b(creature_ptr->word_recall);
755 wr_s16b(creature_ptr->recall_dungeon);
756 wr_s16b(creature_ptr->alter_reality);
757 wr_s16b(creature_ptr->see_infra);
758 wr_s16b(creature_ptr->tim_infra);
759 wr_s16b(creature_ptr->oppose_fire);
760 wr_s16b(creature_ptr->oppose_cold);
761 wr_s16b(creature_ptr->oppose_acid);
762 wr_s16b(creature_ptr->oppose_elec);
763 wr_s16b(creature_ptr->oppose_pois);
764 wr_s16b(creature_ptr->tsuyoshi);
765 wr_s16b(creature_ptr->tim_esp);
766 wr_s16b(creature_ptr->wraith_form);
767 wr_s16b(creature_ptr->resist_magic);
768 wr_s16b(creature_ptr->tim_regen);
769 wr_s16b(creature_ptr->kabenuke);
770 wr_s16b(creature_ptr->tim_stealth);
771 wr_s16b(creature_ptr->tim_levitation);
772 wr_s16b(creature_ptr->tim_sh_touki);
773 wr_s16b(creature_ptr->lightspeed);
774 wr_s16b(creature_ptr->tsubureru);
775 wr_s16b(creature_ptr->magicdef);
776 wr_s16b(creature_ptr->tim_res_nether);
777 wr_s16b(creature_ptr->tim_res_time);
778 wr_byte((byte)creature_ptr->mimic_form);
779 wr_s16b(creature_ptr->tim_mimic);
780 wr_s16b(creature_ptr->tim_sh_fire);
781 wr_s16b(creature_ptr->tim_sh_holy);
782 wr_s16b(creature_ptr->tim_eyeeye);
785 wr_s16b(creature_ptr->tim_reflect);
786 wr_s16b(creature_ptr->multishadow);
787 wr_s16b(creature_ptr->dustrobe);
789 wr_s16b(creature_ptr->chaos_patron);
790 wr_u32b(creature_ptr->muta1);
791 wr_u32b(creature_ptr->muta2);
792 wr_u32b(creature_ptr->muta3);
794 for (i = 0; i<8; i++)
795 wr_s16b(creature_ptr->virtues[i]);
796 for (i = 0; i<8; i++)
797 wr_s16b(creature_ptr->vir_types[i]);
799 wr_s16b(creature_ptr->ele_attack);
800 wr_u32b(creature_ptr->special_attack);
801 wr_s16b(creature_ptr->ele_immune);
802 wr_u32b(creature_ptr->special_defense);
803 wr_byte(creature_ptr->knowledge);
804 wr_byte(creature_ptr->autopick_autoregister);
806 wr_byte((byte_hack)creature_ptr->action);
808 wr_byte(preserve_mode);
809 wr_byte(creature_ptr->wait_report_score);
812 for (i = 0; i < 12; i++) wr_u32b(0L);
814 /* Ignore some flags */
820 /* Write the "object seeds" */
821 wr_u32b(current_world_ptr->seed_flavor);
822 wr_u32b(current_world_ptr->seed_town);
826 wr_u16b(creature_ptr->panic_save);
827 wr_u16b(current_world_ptr->total_winner);
828 wr_u16b(current_world_ptr->noscore);
832 wr_byte(creature_ptr->is_dead);
835 wr_byte(creature_ptr->feeling);
837 /* Turn when level began */
838 wr_s32b(creature_ptr->current_floor_ptr->generated_turn);
840 /* Turn of last "feeling" */
841 wr_s32b(creature_ptr->feeling_turn);
844 wr_s32b(current_world_ptr->game_turn);
846 wr_s32b(current_world_ptr->dungeon_turn);
848 wr_s32b(current_world_ptr->arena_start_turn);
851 wr_s16b(creature_ptr->today_mon);
852 wr_s16b(creature_ptr->riding);
854 /* Current floor_id */
855 wr_s16b(creature_ptr->floor_id);
857 /* Save temporary preserved pets (obsolated) */
860 wr_u32b(current_world_ptr->play_time);
862 wr_s32b(creature_ptr->visit);
864 wr_u32b(creature_ptr->count);
869 * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
870 * @param sf_ptr 保存したいフロアの参照ポインタ
873 static void wr_saved_floor(saved_floor_type *sf_ptr)
875 grid_template_type *templates;
890 /* Dungeon floor specific info follows */
894 /*** Not a saved floor ***/
896 wr_s16b((s16b)p_ptr->current_floor_ptr->dun_level);
900 /*** The saved floor ***/
902 wr_s16b(sf_ptr->floor_id);
903 wr_byte((byte_hack)sf_ptr->savefile_id);
904 wr_s16b((s16b)sf_ptr->dun_level);
905 wr_s32b(sf_ptr->last_visit);
906 wr_u32b(sf_ptr->visit_mark);
907 wr_s16b(sf_ptr->upper_floor_id);
908 wr_s16b(sf_ptr->lower_floor_id);
911 wr_u16b((u16b)p_ptr->current_floor_ptr->base_level);
912 wr_u16b((s16b)p_ptr->current_floor_ptr->num_repro);
913 wr_u16b((u16b)p_ptr->y);
914 wr_u16b((u16b)p_ptr->x);
915 wr_u16b((u16b)p_ptr->current_floor_ptr->height);
916 wr_u16b((u16b)p_ptr->current_floor_ptr->width);
917 wr_byte(p_ptr->feeling);
921 /*********** Make template for grid_type **********/
924 * Usually number of templates are fewer than 255. Even if
925 * more than 254 are exist, the occurrence of each template
926 * with larger ID is very small when we sort templates by
927 * occurrence. So we will use two (or more) bytes for
928 * templete ID larger than 254.
930 * Ex: 256 will be "0xff" "0x01".
931 * 515 will be "0xff" "0xff" "0x03"
934 /* Fake max number */
937 /* Allocate the "template" array */
938 C_MAKE(templates, max_num_temp, grid_template_type);
940 /* Extract template array */
941 for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
943 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
945 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
947 for (i = 0; i < num_temp; i++)
949 if (templates[i].info == g_ptr->info &&
950 templates[i].feat == g_ptr->feat &&
951 templates[i].mimic == g_ptr->mimic &&
952 templates[i].special == g_ptr->special)
954 /* Same terrain is exist */
955 templates[i].occurrence++;
960 /* Are there same one? */
961 if (i < num_temp) continue;
963 /* If the max_num_temp is too small, increase it. */
964 if (num_temp >= max_num_temp)
966 grid_template_type *old_template = templates;
968 /* Re-allocate the "template" array */
969 C_MAKE(templates, max_num_temp + 255, grid_template_type);
970 (void)C_COPY(templates, old_template, max_num_temp, grid_template_type);
971 C_KILL(old_template, max_num_temp, grid_template_type);
975 /* Add new template */
976 templates[num_temp].info = g_ptr->info;
977 templates[num_temp].feat = g_ptr->feat;
978 templates[num_temp].mimic = g_ptr->mimic;
979 templates[num_temp].special = g_ptr->special;
980 templates[num_temp].occurrence = 1;
982 /* Increase number of template */
987 /* Sort by occurrence */
988 ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
990 /*** Dump templates ***/
992 /* Total templates */
995 /* Dump the templates */
996 for (i = 0; i < num_temp; i++)
998 grid_template_type *ct_ptr = &templates[i];
1001 wr_u16b((u16b)ct_ptr->info);
1002 wr_s16b(ct_ptr->feat);
1003 wr_s16b(ct_ptr->mimic);
1004 wr_s16b(ct_ptr->special);
1009 /*** "Run-Length-Encoding" of floor ***/
1011 /* Note that this will induce two wasted bytes */
1015 for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
1017 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
1019 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1021 for (i = 0; i < num_temp; i++)
1023 if (templates[i].info == g_ptr->info &&
1024 templates[i].feat == g_ptr->feat &&
1025 templates[i].mimic == g_ptr->mimic &&
1026 templates[i].special == g_ptr->special)
1033 /* If the run is broken, or too full, flush it */
1034 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
1036 wr_byte((byte)count);
1038 while (prev_u16b >= MAX_UCHAR)
1040 /* Mark as actual data is larger than 254 */
1042 prev_u16b -= MAX_UCHAR;
1045 wr_byte((byte)prev_u16b);
1050 /* Continue the run */
1058 /* Flush the data (if any) */
1061 wr_byte((byte)count);
1063 while (prev_u16b >= MAX_UCHAR)
1065 /* Mark as actual data is larger than 254 */
1067 prev_u16b -= MAX_UCHAR;
1069 wr_byte((byte)prev_u16b);
1073 /* Free the "template" array */
1074 C_KILL(templates, max_num_temp, grid_template_type);
1077 /*** Dump objects ***/
1080 wr_u16b(p_ptr->current_floor_ptr->o_max);
1082 /* Dump the objects */
1083 for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
1085 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[i];
1092 /*** Dump the monsters ***/
1094 /* Total monsters */
1095 wr_u16b(p_ptr->current_floor_ptr->m_max);
1097 /* Dump the monsters */
1098 for (i = 1; i < p_ptr->current_floor_ptr->m_max; i++)
1100 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i];
1109 * @brief 現在フロアの書き込み /
1110 * Write the current dungeon (new method)
1111 * @player_ptr プレーヤーへの参照ポインタ
1112 * @return 保存に成功したらTRUE
1114 static bool wr_dungeon(player_type *player_ptr)
1116 saved_floor_type *cur_sf_ptr;
1119 forget_lite(p_ptr->current_floor_ptr);
1120 forget_view(p_ptr->current_floor_ptr);
1121 clear_mon_lite(p_ptr->current_floor_ptr);
1123 /* Update lite/view */
1124 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1125 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1129 /* Number of floor_id used from birth */
1130 wr_s16b(max_floor_id);
1132 /* Current dungeon type */
1133 wr_byte((byte_hack)p_ptr->dungeon_idx);
1136 /*** No saved floor (On the surface etc.) ***/
1137 if (!p_ptr->floor_id)
1139 /* No array elements */
1142 /* Write the current floor data */
1143 wr_saved_floor(NULL);
1150 /*** In the dungeon ***/
1152 /* Number of array elements */
1153 wr_byte(MAX_SAVED_FLOORS);
1155 /* Write the saved_floors array */
1156 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1158 saved_floor_type *sf_ptr = &saved_floors[i];
1160 wr_s16b(sf_ptr->floor_id);
1161 wr_byte((byte_hack)sf_ptr->savefile_id);
1162 wr_s16b((s16b)sf_ptr->dun_level);
1163 wr_s32b(sf_ptr->last_visit);
1164 wr_u32b(sf_ptr->visit_mark);
1165 wr_s16b(sf_ptr->upper_floor_id);
1166 wr_s16b(sf_ptr->lower_floor_id);
1169 /* Extract pointer to current floor */
1170 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1172 /* Save current floor to temporal file */
1173 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1175 /* Move data in temporal files to the savefile */
1176 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1178 saved_floor_type *sf_ptr = &saved_floors[i];
1180 /* Unused element */
1181 if (!sf_ptr->floor_id) continue;
1183 /* Load temporal saved floor file */
1184 if (load_floor(player_ptr, sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1189 /* Write saved floor data to the save file */
1190 wr_saved_floor(sf_ptr);
1199 /* Restore current floor */
1200 if (!load_floor(player_ptr, cur_sf_ptr, (SLF_SECOND))) return FALSE;
1208 * @brief セーブデータの書き込み /
1209 * Actually write a save-file
1210 * @param player_ptr プレーヤーへの参照ポインタ
1213 static bool wr_savefile_new(player_type *player_ptr)
1224 KIND_OBJECT_IDX k_idx;
1226 /* Compact the objects */
1227 compact_objects(player_ptr->current_floor_ptr, 0);
1228 /* Compact the monsters */
1229 compact_monsters(0);
1231 /* Guess at the current time */
1232 now = (u32b)time((time_t *)0);
1235 /* Note the operating system */
1236 current_world_ptr->sf_system = 0L;
1238 /* Note when the file was saved */
1239 current_world_ptr->sf_when = now;
1241 /* Note the number of saves */
1242 current_world_ptr->sf_saves++;
1245 /*** Actually write the file ***/
1247 /* Dump the file header */
1249 wr_byte(FAKE_VER_MAJOR);
1251 wr_byte(FAKE_VER_MINOR);
1253 wr_byte(FAKE_VER_PATCH);
1256 /* Initial value of xor_byte */
1257 tmp8u = (byte)Rand_external(256);
1261 /* Reset the checksum */
1265 /* Write the savefile version for Hengband 1.1.1 and later */
1266 wr_byte(H_VER_EXTRA);
1267 wr_byte(H_VER_PATCH);
1268 wr_byte(H_VER_MINOR);
1269 wr_byte(H_VER_MAJOR);
1271 /* Operating system */
1272 wr_u32b(current_world_ptr->sf_system);
1275 /* Time file last saved */
1276 wr_u32b(current_world_ptr->sf_when);
1278 /* Number of past lives */
1279 wr_u16b(current_world_ptr->sf_lives);
1281 /* Number of times saved */
1282 wr_u16b(current_world_ptr->sf_saves);
1292 /* EUC kanji code */
1296 /* SJIS kanji code */
1304 /* Write the RNG state */
1308 /* Write the boolean "options" */
1312 /* Dump the number of "messages" */
1313 tmp32u = message_num();
1314 if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
1317 /* Dump the messages (oldest first!) */
1318 for (i = tmp32u - 1; i >= 0; i--)
1320 wr_string(message_str((s16b)i));
1323 /* Dump the monster lore */
1326 for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
1328 /* Dump the object memory */
1331 for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
1333 /* Dump the towns */
1337 /* Dump the quests */
1341 /* Dump the quests */
1342 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1345 for (i = 0; i < max_q_idx; i++)
1347 quest_type* const q_ptr = &quest[i];
1349 /* Save status for every quest */
1350 wr_s16b(q_ptr->status);
1352 /* And the dungeon level too */
1353 /* (prevents problems with multi-level quests) */
1354 wr_s16b((s16b)q_ptr->level);
1356 wr_byte((byte_hack)q_ptr->complev);
1357 wr_u32b(q_ptr->comptime);
1359 /* Save quest status if quest is running */
1360 if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1362 wr_s16b((s16b)q_ptr->cur_num);
1363 wr_s16b((s16b)q_ptr->max_num);
1364 wr_s16b(q_ptr->type);
1365 wr_s16b(q_ptr->r_idx);
1366 wr_s16b(q_ptr->k_idx);
1367 wr_byte((byte_hack)q_ptr->flags);
1368 wr_byte((byte_hack)q_ptr->dungeon);
1372 /* Dump the position in the wilderness */
1373 wr_s32b(player_ptr->wilderness_x);
1374 wr_s32b(player_ptr->wilderness_y);
1376 wr_byte(player_ptr->wild_mode);
1377 wr_byte(player_ptr->ambush_flag);
1379 wr_s32b(current_world_ptr->max_wild_x);
1380 wr_s32b(current_world_ptr->max_wild_y);
1382 /* Dump the wilderness seeds */
1383 for (i = 0; i < current_world_ptr->max_wild_x; i++)
1385 for (j = 0; j < current_world_ptr->max_wild_y; j++)
1387 wr_u32b(wilderness[j][i].seed);
1391 /* Hack -- Dump the artifacts */
1394 for (i = 0; i < tmp16u; i++)
1396 artifact_type *a_ptr = &a_info[i];
1397 wr_byte(a_ptr->cur_num);
1398 wr_s16b(a_ptr->floor_id);
1403 /* Write the "extra" information */
1404 wr_extra(player_ptr);
1406 /* Dump the "player hp" entries */
1407 tmp16u = PY_MAX_LEVEL;
1409 for (i = 0; i < tmp16u; i++)
1411 wr_s16b((s16b)player_ptr->player_hp[i]);
1415 /* Write spell data */
1416 wr_u32b(player_ptr->spell_learned1);
1417 wr_u32b(player_ptr->spell_learned2);
1418 wr_u32b(player_ptr->spell_worked1);
1419 wr_u32b(player_ptr->spell_worked2);
1420 wr_u32b(player_ptr->spell_forgotten1);
1421 wr_u32b(player_ptr->spell_forgotten2);
1423 wr_s16b(player_ptr->learned_spells);
1424 wr_s16b(player_ptr->add_spells);
1426 /* Dump the ordered spells */
1427 for (i = 0; i < 64; i++)
1429 wr_byte((byte_hack)player_ptr->spell_order[i]);
1432 for (i = 0; i < INVEN_TOTAL; i++)
1434 object_type *o_ptr = &player_ptr->inventory_list[i];
1435 if (!o_ptr->k_idx) continue;
1444 /* Add a sentinel */
1447 /* Note the towns */
1451 /* Note the stores */
1452 tmp16u = MAX_STORES;
1455 /* Dump the stores of all towns */
1456 for (i = 1; i < max_towns; i++)
1458 for (j = 0; j < MAX_STORES; j++)
1460 wr_store(&town_info[i].store[j]);
1464 /* Write the pet command settings */
1465 wr_s16b(player_ptr->pet_follow_distance);
1466 wr_s16b(player_ptr->pet_extra_flags);
1468 /* Write screen dump for sending score */
1469 if (screen_dump && (player_ptr->wait_report_score || !player_ptr->is_dead))
1471 wr_string(screen_dump);
1478 /* Player is not dead, write the dungeon */
1479 if (!player_ptr->is_dead)
1481 /* Dump the dungeon */
1482 if (!wr_dungeon(player_ptr)) return FALSE;
1484 /* Dump the ghost */
1492 /* Write the "value check-sum" */
1495 /* Write the "encoded checksum" */
1500 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1502 /* Successful save */
1508 * @brief セーブデータ書き込みのサブルーチン /
1509 * Medium level player saver
1510 * @param player_ptr プレーヤーへの参照ポインタ
1513 * Angband 2.8.0 will use "fd" instead of "fff" if possible
1515 static bool save_player_aux(player_type *player_ptr, char *name)
1524 /* File type is "SAVE" */
1525 FILE_TYPE(FILE_TYPE_SAVE);
1527 /* Grab permissions */
1530 /* Create the savefile */
1531 fd = fd_make(name, mode);
1533 /* Drop permissions */
1539 /* Close the "fd" */
1542 /* Grab permissions */
1545 /* Open the savefile */
1546 fff = my_fopen(name, "wb");
1548 /* Drop permissions */
1551 /* Successful open */
1554 /* Write the savefile */
1555 if (wr_savefile_new(player_ptr)) ok = TRUE;
1557 /* Attempt to close it */
1558 if (my_fclose(fff)) ok = FALSE;
1561 /* Grab permissions */
1564 /* Remove "broken" files */
1565 if (!ok) (void)fd_kill(name);
1567 /* Drop permissions */
1573 if (!ok) return (FALSE);
1575 counts_write(0, current_world_ptr->play_time);
1577 /* Successful save */
1578 current_world_ptr->character_saved = TRUE;
1587 * @brief セーブデータ書き込みのメインルーチン /
1588 * Attempt to save the player in a savefile
1589 * @param player_ptr プレーヤーへの参照ポインタ
1592 bool save_player(player_type *player_ptr)
1594 bool result = FALSE;
1603 /* Get "games" permissions */
1612 strcpy(safe, savefile);
1613 strcat(safe, ".new");
1615 /* Grab permissions */
1621 /* Drop permissions */
1626 /* Attempt to save the player */
1627 if (save_player_aux(player_ptr, safe))
1632 strcpy(temp, savefile);
1633 strcat(temp, ".old");
1635 /* Grab permissions */
1641 /* Preserve old savefile */
1642 fd_move(savefile, temp);
1644 /* Activate new savefile */
1645 fd_move(safe, savefile);
1647 /* Remove preserved savefile */
1650 /* Drop permissions */
1653 /* Hack -- Pretend the character was loaded */
1654 current_world_ptr->character_loaded = TRUE;
1656 #ifdef VERIFY_SAVEFILE
1658 /* Lock on savefile */
1659 strcpy(temp, savefile);
1660 strcat(temp, ".lok");
1662 /* Grab permissions */
1665 /* Remove lock file */
1668 /* Drop permissions */
1682 /* Drop "games" permissions */
1689 /* Return the result */
1695 * @brief セーブデータ読み込みのメインルーチン /
1696 * Attempt to Load a "savefile"
1700 * Version 2.7.0 introduced a slightly different "savefile" format from
1701 * older versions, requiring a completely different parsing method.
1703 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1705 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1707 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1709 * On multi-user systems, you may only "read" a savefile if you will be
1710 * allowed to "write" it later, this prevents painful situations in which
1711 * the player loads a savefile belonging to someone else, and then is not
1712 * allowed to save his game when he quits.
1714 * We return "TRUE" if the savefile was usable, and we set the global
1715 * flag "current_world_ptr->character_loaded" if a real, living, character was loaded.
1717 * Note that we always try to load the "current" savefile, even if
1718 * there is no such file, so we must check for "empty" savefile names.
1721 bool load_player(void)
1729 #ifdef VERIFY_TIMESTAMP
1730 struct stat statbuf;
1733 concptr what = "generic";
1735 current_world_ptr->game_turn = 0;
1736 p_ptr->is_dead = FALSE;
1739 /* Allow empty savefile name */
1740 if (!savefile[0]) return (TRUE);
1743 #if !defined(MACINTOSH) && !defined(WINDOWS)
1747 /* Verify the existance of the savefile */
1748 if (access(savefile, 0) < 0)
1750 /* Give a message */
1751 msg_print(_("セーブファイルがありません。", "Savefile does not exist."));
1762 #ifdef VERIFY_SAVEFILE
1764 /* Verify savefile usage */
1771 /* Extract name of lock file */
1772 strcpy(temp, savefile);
1773 strcat(temp, ".lok");
1775 /* Check for lock */
1776 fkk = my_fopen(temp, "r");
1778 /* Oops, lock exists */
1783 msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
1789 /* Create a lock file */
1790 fkk = my_fopen(temp, "w");
1792 /* Dump a line of info */
1793 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1795 /* Close the lock file */
1804 /* Open the savefile */
1805 fd = fd_open(savefile, O_RDONLY);
1808 if (fd < 0) err = -1;
1810 /* Message (below) */
1811 if (err) what = _("セーブファイルを開けません。", "Cannot open savefile");
1818 #ifdef VERIFY_TIMESTAMP
1819 /* Get the timestamp */
1820 (void)fstat(fd, &statbuf);
1823 /* Read the first four bytes */
1824 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1827 if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
1835 /* Extract version */
1836 current_world_ptr->z_major = vvv[0];
1837 current_world_ptr->z_minor = vvv[1];
1838 current_world_ptr->z_patch = vvv[2];
1839 current_world_ptr->sf_extra = vvv[3];
1843 /* Attempt to load */
1844 err = rd_savefile_new();
1846 /* Message (below) */
1847 if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
1852 if (!current_world_ptr->game_turn) err = -1;
1854 /* Message (below) */
1855 if (err) what = _("セーブファイルが壊れています", "Broken savefile");
1858 #ifdef VERIFY_TIMESTAMP
1859 /* Verify timestamp */
1860 if (!err && !arg_wizard)
1862 /* Hack -- Verify the timestamp */
1863 if (current_world_ptr->sf_when > (statbuf.st_ctime + 100) ||
1864 current_world_ptr->sf_when < (statbuf.st_ctime - 100))
1866 what = _("無効なタイム・スタンプです", "Invalid timestamp");
1876 /* Give a conversion warning */
1877 if ((FAKE_VER_MAJOR != current_world_ptr->z_major) ||
1878 (FAKE_VER_MINOR != current_world_ptr->z_minor) ||
1879 (FAKE_VER_PATCH != current_world_ptr->z_patch))
1881 if (current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6)
1883 msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
1887 msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
1888 (current_world_ptr->z_major > 9) ? current_world_ptr->z_major-10 : current_world_ptr->z_major , current_world_ptr->z_minor, current_world_ptr->z_patch);
1893 /* Player is dead */
1899 /* A character was loaded */
1900 current_world_ptr->character_loaded = TRUE;
1904 /* Player is no longer "dead" */
1905 p_ptr->is_dead = FALSE;
1908 current_world_ptr->sf_lives++;
1913 /* A character was loaded */
1914 current_world_ptr->character_loaded = TRUE;
1917 u32b tmp = counts_read(2);
1918 if (tmp > p_ptr->count)
1920 if (counts_read(0) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
1921 counts_write(2, ++p_ptr->count);
1922 counts_write(1, current_world_ptr->play_time);
1930 #ifdef VERIFY_SAVEFILE
1932 /* Verify savefile usage */
1937 /* Extract name of lock file */
1938 strcpy(temp, savefile);
1939 strcat(temp, ".lok");
1947 msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
1948 what, (current_world_ptr->z_major>9) ? current_world_ptr->z_major - 10 : current_world_ptr->z_major, current_world_ptr->z_minor, current_world_ptr->z_patch);
1959 void remove_loc(void)
1961 #ifdef VERIFY_SAVEFILE
1963 #endif /* VERIFY_SAVEFILE */
1968 /* Get "games" permissions */
1971 # endif /* SECURE */
1972 #endif /* SET_UID */
1974 #ifdef VERIFY_SAVEFILE
1976 /* Lock on savefile */
1977 strcpy(temp, savefile);
1978 strcat(temp, ".lok");
1980 /* Remove lock file */
1983 #endif /* VERIFY_SAVEFILE */
1988 /* Drop "games" permissions */
1991 # endif /* SECURE */
1992 #endif /* SET_UID */
1998 * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporal saved floor file
1999 * @param sf_ptr 保存フロア参照ポインタ
2002 static bool save_floor_aux(saved_floor_type *sf_ptr)
2006 /* Compact the objects */
2007 compact_objects(p_ptr->current_floor_ptr, 0);
2008 /* Compact the monsters */
2009 compact_monsters(0);
2012 /*** Actually write the file ***/
2014 /* Initial value of xor_byte */
2015 tmp8u = (byte)randint0(256);
2020 /* Reset the checksum */
2024 /* Write the sign of this process */
2025 wr_u32b(saved_floor_file_sign);
2027 /* Dump the dungeon floor */
2028 wr_saved_floor(sf_ptr);
2031 /* Write the "value check-sum" */
2034 /* Write the "encoded checksum" */
2039 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2041 /* Successful save */
2047 * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data
2048 * @param sf_ptr 保存フロア参照ポインタ
2049 * @param mode 保存オプション
2052 bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
2054 FILE *old_fff = NULL;
2055 byte old_xor_byte = 0;
2056 u32b old_v_stamp = 0;
2057 u32b old_x_stamp = 0;
2059 char floor_savefile[1024];
2063 if (!(mode & SLF_SECOND))
2067 /* Get "games" permissions */
2073 /* We have one file already opened */
2076 /* Backup original values */
2078 old_xor_byte = xor_byte;
2079 old_v_stamp = v_stamp;
2080 old_x_stamp = x_stamp;
2084 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2086 /* Grab permissions */
2090 fd_kill(floor_savefile);
2092 /* Drop permissions */
2096 /* Attempt to save the player */
2101 /* File type is "SAVE" */
2102 FILE_TYPE(FILE_TYPE_SAVE);
2104 /* Grab permissions */
2107 /* Create the savefile */
2108 fd = fd_make(floor_savefile, 0644);
2110 /* Drop permissions */
2116 /* Close the "fd" */
2119 /* Grab permissions */
2122 /* Open the savefile */
2123 fff = my_fopen(floor_savefile, "wb");
2125 /* Drop permissions */
2128 /* Successful open */
2131 /* Write the savefile */
2132 if (save_floor_aux(sf_ptr)) ok = TRUE;
2134 /* Attempt to close it */
2135 if (my_fclose(fff)) ok = FALSE;
2138 /* Remove "broken" files */
2141 /* Grab permissions */
2144 (void)fd_kill(floor_savefile);
2146 /* Drop permissions */
2151 if (!(mode & SLF_SECOND))
2155 /* Drop "games" permissions */
2161 /* We have one file already opened */
2164 /* Restore original values */
2166 xor_byte = old_xor_byte;
2167 v_stamp = old_v_stamp;
2168 x_stamp = old_x_stamp;
2171 /* Return the result */