4 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: interact with savefiles */
18 * Some "local" parameters, used to help write savefiles
21 static FILE *fff; /* Current save "file" */
23 static byte xor_byte; /* Simple encryption */
25 static u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
26 static u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
31 * These functions place information into a savefile a byte at a time
34 static void sf_put(byte v)
36 /* Encode the value, write a character */
38 (void)putc((int)xor_byte, fff);
40 /* Maintain the checksum info */
45 static void wr_byte(byte v)
50 static void wr_u16b(u16b v)
52 sf_put((byte)(v & 0xFF));
53 sf_put((byte)((v >> 8) & 0xFF));
56 static void wr_s16b(s16b v)
61 static void wr_u32b(u32b v)
63 sf_put((byte)(v & 0xFF));
64 sf_put((byte)((v >> 8) & 0xFF));
65 sf_put((byte)((v >> 16) & 0xFF));
66 sf_put((byte)((v >> 24) & 0xFF));
69 static void wr_s32b(s32b v)
74 static void wr_string(cptr str)
86 * These functions write info in larger logical records
91 * Write an "item" record
93 static void wr_item(object_type *o_ptr)
95 u32b flags = 0x00000000;
97 if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
98 if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
99 if (o_ptr->number != 1) flags |= SAVE_ITEM_NUMBER;
100 if (o_ptr->name1) flags |= SAVE_ITEM_NAME1;
101 if (o_ptr->name2) flags |= SAVE_ITEM_NAME2;
102 if (o_ptr->timeout) flags |= SAVE_ITEM_TIMEOUT;
103 if (o_ptr->to_h) flags |= SAVE_ITEM_TO_H;
104 if (o_ptr->to_d) flags |= SAVE_ITEM_TO_D;
105 if (o_ptr->to_a) flags |= SAVE_ITEM_TO_A;
106 if (o_ptr->ac) flags |= SAVE_ITEM_AC;
107 if (o_ptr->dd) flags |= SAVE_ITEM_DD;
108 if (o_ptr->ds) flags |= SAVE_ITEM_DS;
109 if (o_ptr->ident) flags |= SAVE_ITEM_IDENT;
110 if (o_ptr->marked) flags |= SAVE_ITEM_MARKED;
111 if (o_ptr->art_flags[0]) flags |= SAVE_ITEM_ART_FLAGS0;
112 if (o_ptr->art_flags[1]) flags |= SAVE_ITEM_ART_FLAGS1;
113 if (o_ptr->art_flags[2]) flags |= SAVE_ITEM_ART_FLAGS2;
114 if (o_ptr->art_flags[3]) flags |= SAVE_ITEM_ART_FLAGS3;
115 if (o_ptr->curse_flags) flags |= SAVE_ITEM_CURSE_FLAGS;
116 if (o_ptr->held_m_idx) flags |= SAVE_ITEM_HELD_M_IDX;
117 if (o_ptr->xtra1) flags |= SAVE_ITEM_XTRA1;
118 if (o_ptr->xtra2) flags |= SAVE_ITEM_XTRA2;
119 if (o_ptr->xtra3) flags |= SAVE_ITEM_XTRA3;
120 if (o_ptr->xtra4) flags |= SAVE_ITEM_XTRA4;
121 if (o_ptr->xtra5) flags |= SAVE_ITEM_XTRA5;
122 if (o_ptr->feeling) flags |= SAVE_ITEM_FEELING;
123 if (o_ptr->inscription) flags |= SAVE_ITEM_INSCRIPTION;
124 if (o_ptr->art_name) flags |= SAVE_ITEM_ART_NAME;
126 /*** Item save flags ***/
129 /*** Write only un-obvious elements ***/
130 wr_s16b(o_ptr->k_idx);
136 if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
138 if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
139 if (flags & SAVE_ITEM_NUMBER) wr_byte(o_ptr->number);
141 wr_s16b(o_ptr->weight);
143 if (flags & SAVE_ITEM_NAME1) wr_byte(o_ptr->name1);
144 if (flags & SAVE_ITEM_NAME2) wr_byte(o_ptr->name2);
145 if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
147 if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
148 if (flags & SAVE_ITEM_TO_D) wr_s16b(o_ptr->to_d);
149 if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
150 if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
151 if (flags & SAVE_ITEM_DD) wr_byte(o_ptr->dd);
152 if (flags & SAVE_ITEM_DS) wr_byte(o_ptr->ds);
154 if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
156 if (flags & SAVE_ITEM_MARKED) wr_byte(o_ptr->marked);
158 if (flags & SAVE_ITEM_ART_FLAGS0) wr_u32b(o_ptr->art_flags[0]);
159 if (flags & SAVE_ITEM_ART_FLAGS1) wr_u32b(o_ptr->art_flags[1]);
160 if (flags & SAVE_ITEM_ART_FLAGS2) wr_u32b(o_ptr->art_flags[2]);
161 if (flags & SAVE_ITEM_ART_FLAGS3) wr_u32b(o_ptr->art_flags[3]);
163 if (flags & SAVE_ITEM_CURSE_FLAGS) wr_u32b(o_ptr->curse_flags);
165 /* Held by monster index */
166 if (flags & SAVE_ITEM_HELD_M_IDX) wr_s16b(o_ptr->held_m_idx);
168 /* Extra information */
169 if (flags & SAVE_ITEM_XTRA1) wr_byte(o_ptr->xtra1);
170 if (flags & SAVE_ITEM_XTRA2) wr_byte(o_ptr->xtra2);
171 if (flags & SAVE_ITEM_XTRA3) wr_byte(o_ptr->xtra3);
172 if (flags & SAVE_ITEM_XTRA4) wr_s16b(o_ptr->xtra4);
173 if (flags & SAVE_ITEM_XTRA5) wr_s16b(o_ptr->xtra5);
176 if (flags & SAVE_ITEM_FEELING) wr_byte(o_ptr->feeling);
178 if (flags & SAVE_ITEM_INSCRIPTION) wr_string(quark_str(o_ptr->inscription));
179 if (flags & SAVE_ITEM_ART_NAME) wr_string(quark_str(o_ptr->art_name));
184 * Write a "monster" record
186 static void wr_monster(monster_type *m_ptr)
188 u32b flags = 0x00000000;
190 if (m_ptr->ap_r_idx != m_ptr->r_idx) flags |= SAVE_MON_AP_R_IDX;
191 if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
192 if (m_ptr->csleep) flags |= SAVE_MON_CSLEEP;
193 if (m_ptr->fast) flags |= SAVE_MON_FAST;
194 if (m_ptr->slow) flags |= SAVE_MON_SLOW;
195 if (m_ptr->stunned) flags |= SAVE_MON_STUNNED;
196 if (m_ptr->confused) flags |= SAVE_MON_CONFUSED;
197 if (m_ptr->monfear) flags |= SAVE_MON_MONFEAR;
198 if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
199 if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
200 if (m_ptr->invulner) flags |= SAVE_MON_INVULNER;
201 if (m_ptr->smart) flags |= SAVE_MON_SMART;
202 if (m_ptr->exp) flags |= SAVE_MON_EXP;
203 if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
204 if (m_ptr->nickname) flags |= SAVE_MON_NICKNAME;
205 if (m_ptr->parent_m_idx) flags |= SAVE_MON_PARENT;
207 /*** Monster save flags ***/
210 /*** Write only un-obvious elements ***/
211 wr_s16b(m_ptr->r_idx);
215 wr_s16b(m_ptr->maxhp);
216 wr_s16b(m_ptr->max_maxhp);
218 /* Monster race index of its appearance */
219 if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
221 if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
222 if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->csleep);
224 wr_byte(m_ptr->mspeed);
225 wr_s16b(m_ptr->energy_need);
227 if (flags & SAVE_MON_FAST) wr_byte(m_ptr->fast);
228 if (flags & SAVE_MON_SLOW) wr_byte(m_ptr->slow);
229 if (flags & SAVE_MON_STUNNED) wr_byte(m_ptr->stunned);
230 if (flags & SAVE_MON_CONFUSED) wr_byte(m_ptr->confused);
231 if (flags & SAVE_MON_MONFEAR) wr_byte(m_ptr->monfear);
232 if (flags & SAVE_MON_TARGET_Y) wr_s16b(m_ptr->target_y);
233 if (flags & SAVE_MON_TARGET_X) wr_s16b(m_ptr->target_x);
234 if (flags & SAVE_MON_INVULNER) wr_byte(m_ptr->invulner);
235 if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
236 if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
237 if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
238 if (flags & SAVE_MON_NICKNAME) wr_string(quark_str(m_ptr->nickname));
239 if (flags & SAVE_MON_PARENT) wr_s16b(m_ptr->parent_m_idx);
244 * Write a "lore" record
246 static void wr_lore(int r_idx)
248 monster_race *r_ptr = &r_info[r_idx];
250 /* Count sights/deaths/kills */
251 wr_s16b(r_ptr->r_sights);
252 wr_s16b(r_ptr->r_deaths);
253 wr_s16b(r_ptr->r_pkills);
254 wr_s16b(r_ptr->r_tkills);
256 /* Count wakes and ignores */
257 wr_byte(r_ptr->r_wake);
258 wr_byte(r_ptr->r_ignore);
261 wr_byte(r_ptr->r_xtra1);
262 wr_byte(r_ptr->r_xtra2);
265 wr_byte(r_ptr->r_drop_gold);
266 wr_byte(r_ptr->r_drop_item);
269 wr_byte(0); /* unused now */
270 wr_byte(r_ptr->r_cast_spell);
272 /* Count blows of each type */
273 wr_byte(r_ptr->r_blows[0]);
274 wr_byte(r_ptr->r_blows[1]);
275 wr_byte(r_ptr->r_blows[2]);
276 wr_byte(r_ptr->r_blows[3]);
279 wr_u32b(r_ptr->r_flags1);
280 wr_u32b(r_ptr->r_flags2);
281 wr_u32b(r_ptr->r_flags3);
282 wr_u32b(r_ptr->r_flags4);
283 wr_u32b(r_ptr->r_flags5);
284 wr_u32b(r_ptr->r_flags6);
285 wr_u32b(r_ptr->r_flagsr);
288 /* Monster limit per level */
289 wr_byte(r_ptr->max_num);
291 /* Location in saved floor */
292 wr_s16b(r_ptr->floor_id);
300 * Write an "xtra" record
302 static void wr_xtra(int k_idx)
306 object_kind *k_ptr = &k_info[k_idx];
308 if (k_ptr->aware) tmp8u |= 0x01;
309 if (k_ptr->tried) tmp8u |= 0x02;
316 * Write a "store" record
318 static void wr_store(store_type *st_ptr)
322 /* Save the "open" counter */
323 wr_u32b(st_ptr->store_open);
325 /* Save the "insults" */
326 wr_s16b(st_ptr->insult_cur);
328 /* Save the current owner */
329 wr_byte(st_ptr->owner);
331 /* Save the stock size */
332 wr_s16b(st_ptr->stock_num);
334 /* Save the "haggle" info */
335 wr_s16b(st_ptr->good_buy);
336 wr_s16b(st_ptr->bad_buy);
338 wr_s32b(st_ptr->last_visit);
341 for (j = 0; j < st_ptr->stock_num; j++)
343 /* Save each item in stock */
344 wr_item(&st_ptr->stock[j]);
352 static errr wr_randomizer(void)
363 for (i = 0; i < RAND_DEG; i++)
365 wr_u32b(Rand_state[i]);
374 * Write the "options"
376 static void wr_options(void)
386 for (i = 0; i < 4; i++) wr_u32b(0L);
389 /*** Special Options ***/
391 /* Write "delay_factor" */
392 wr_byte(delay_factor);
394 /* Write "hitpoint_warn" */
395 wr_byte(hitpoint_warn);
397 /* Write "mana_warn" */
400 /*** Cheating options ***/
404 if (p_ptr->wizard) c |= 0x0002;
406 if (cheat_peek) c |= 0x0100;
407 if (cheat_hear) c |= 0x0200;
408 if (cheat_room) c |= 0x0400;
409 if (cheat_xtra) c |= 0x0800;
410 if (cheat_know) c |= 0x1000;
411 if (cheat_live) c |= 0x2000;
412 if (cheat_save) c |= 0x4000;
419 wr_s16b(autosave_freq);
421 /*** Extract options ***/
423 /* Analyze the options */
424 for (i = 0; option_info[i].o_desc; i++)
426 int os = option_info[i].o_set;
427 int ob = option_info[i].o_bit;
429 /* Process real entries */
430 if (option_info[i].o_var)
433 if (*option_info[i].o_var)
436 option_flag[os] |= (1L << ob);
443 option_flag[os] &= ~(1L << ob);
449 /*** Normal options ***/
452 for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
455 for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
458 /*** Window options ***/
461 for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
464 for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
469 * Hack -- Write the "ghost" info
471 static void wr_ghost(void)
477 wr_string("ÉÔÀµ¤Ê¥´¡¼¥¹¥È");
479 wr_string("Broken Ghost");
483 /* Hack -- stupid data */
484 for (i = 0; i < 60; i++) wr_byte(0);
489 * Save quick start data
491 static void save_quick_start(void)
495 wr_byte(previous_char.psex);
496 wr_byte(previous_char.prace);
497 wr_byte(previous_char.pclass);
498 wr_byte(previous_char.pseikaku);
499 wr_byte(previous_char.realm1);
500 wr_byte(previous_char.realm2);
502 wr_s16b(previous_char.age);
503 wr_s16b(previous_char.ht);
504 wr_s16b(previous_char.wt);
505 wr_s16b(previous_char.sc);
506 wr_s32b(previous_char.au);
508 for (i = 0; i < 6; i++) wr_s16b(previous_char.stat_max[i]);
509 for (i = 0; i < 6; i++) wr_s16b(previous_char.stat_max_max[i]);
511 for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b(previous_char.player_hp[i]);
513 wr_s16b(previous_char.chaos_patron);
515 for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
517 for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
519 /* UNUSED : Was number of random quests */
522 /* No quick start after using debug mode or cheat options */
523 if (p_ptr->noscore) previous_char.quick_ok = FALSE;
525 wr_byte((byte)previous_char.quick_ok);
529 * Write some "extra" info
531 static void wr_extra(void)
536 wr_string(player_name);
538 wr_string(p_ptr->died_from);
540 wr_string(p_ptr->last_message ? p_ptr->last_message : "");
544 for (i = 0; i < 4; i++)
546 wr_string(p_ptr->history[i]);
549 /* Race/Class/Gender/Spells */
550 wr_byte(p_ptr->prace);
551 wr_byte(p_ptr->pclass);
552 wr_byte(p_ptr->pseikaku);
553 wr_byte(p_ptr->psex);
554 wr_byte(p_ptr->realm1);
555 wr_byte(p_ptr->realm2);
556 wr_byte(0); /* oops */
558 wr_byte(p_ptr->hitdie);
559 wr_u16b(p_ptr->expfact);
565 /* Dump the stats (maximum and current) */
566 for (i = 0; i < 6; ++i) wr_s16b(p_ptr->stat_max[i]);
567 for (i = 0; i < 6; ++i) wr_s16b(p_ptr->stat_max_max[i]);
568 for (i = 0; i < 6; ++i) wr_s16b(p_ptr->stat_cur[i]);
570 /* Ignore the transient stats */
571 for (i = 0; i < 12; ++i) wr_s16b(0);
575 wr_u32b(p_ptr->max_exp);
576 wr_u32b(p_ptr->max_max_exp);
578 wr_u16b(p_ptr->exp_frac);
581 for (i = 0; i < 64; i++) wr_s16b(p_ptr->spell_exp[i]);
582 for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(p_ptr->weapon_exp[i][j]);
583 for (i = 0; i < 10; i++) wr_s16b(p_ptr->skill_exp[i]);
584 for (i = 0; i < 108; i++) wr_s32b(p_ptr->magic_num1[i]);
585 for (i = 0; i < 108; i++) wr_byte(p_ptr->magic_num2[i]);
587 wr_byte(p_ptr->start_race);
588 wr_s32b(p_ptr->old_race1);
589 wr_s32b(p_ptr->old_race2);
590 wr_s16b(p_ptr->old_realm);
592 for (i = 0; i < MAX_MANE; i++)
594 wr_s16b(p_ptr->mane_spell[i]);
595 wr_s16b(p_ptr->mane_dam[i]);
597 wr_s16b(p_ptr->mane_num);
599 for (i = 0; i < MAX_KUBI; i++)
601 wr_s16b(kubi_r_idx[i]);
604 for (i = 0; i < 4; i++)
606 wr_s16b(battle_mon[i]);
607 wr_u32b(mon_odds[i]);
610 wr_s16b(p_ptr->town_num); /* -KMW- */
612 /* Write arena and rewards information -KMW- */
613 wr_s16b(p_ptr->arena_number);
614 wr_s16b(p_ptr->inside_arena);
615 wr_s16b(p_ptr->inside_quest);
616 wr_s16b(p_ptr->inside_battle);
617 wr_byte(p_ptr->exit_bldg);
618 wr_byte(0); /* Unused */
620 wr_s16b(p_ptr->oldpx);
621 wr_s16b(p_ptr->oldpy);
623 /* Was number of p_ptr->rewards[] */
628 wr_u16b(p_ptr->chp_frac);
632 wr_u16b(p_ptr->csp_frac);
634 /* Max Player and Dungeon Levels */
635 wr_s16b(p_ptr->max_plv);
636 tmp8u = (byte)max_d_idx;
638 for (i = 0; i < tmp8u; i++)
642 wr_s16b(0); /* oops */
643 wr_s16b(0); /* oops */
644 wr_s16b(0); /* oops */
645 wr_s16b(0); /* oops */
647 wr_s16b(0); /* oops */
649 wr_s16b(0); /* old "rest" */
650 wr_s16b(p_ptr->blind);
651 wr_s16b(p_ptr->paralyzed);
652 wr_s16b(p_ptr->confused);
653 wr_s16b(p_ptr->food);
654 wr_s16b(0); /* old "food_digested" */
655 wr_s16b(0); /* old "protection" */
656 wr_s16b(p_ptr->energy_need);
657 wr_s16b(p_ptr->fast);
658 wr_s16b(p_ptr->slow);
659 wr_s16b(p_ptr->afraid);
661 wr_s16b(p_ptr->stun);
662 wr_s16b(p_ptr->poisoned);
663 wr_s16b(p_ptr->image);
664 wr_s16b(p_ptr->protevil);
665 wr_s16b(p_ptr->invuln);
666 wr_s16b(p_ptr->ult_res);
667 wr_s16b(p_ptr->hero);
668 wr_s16b(p_ptr->shero);
669 wr_s16b(p_ptr->shield);
670 wr_s16b(p_ptr->blessed);
671 wr_s16b(p_ptr->tim_invis);
672 wr_s16b(p_ptr->word_recall);
673 wr_s16b(p_ptr->recall_dungeon);
674 wr_s16b(p_ptr->alter_reality);
675 wr_s16b(p_ptr->see_infra);
676 wr_s16b(p_ptr->tim_infra);
677 wr_s16b(p_ptr->oppose_fire);
678 wr_s16b(p_ptr->oppose_cold);
679 wr_s16b(p_ptr->oppose_acid);
680 wr_s16b(p_ptr->oppose_elec);
681 wr_s16b(p_ptr->oppose_pois);
682 wr_s16b(p_ptr->tsuyoshi);
683 wr_s16b(p_ptr->tim_esp);
684 wr_s16b(p_ptr->wraith_form);
685 wr_s16b(p_ptr->resist_magic);
686 wr_s16b(p_ptr->tim_regen);
687 wr_s16b(p_ptr->kabenuke);
688 wr_s16b(p_ptr->tim_stealth);
689 wr_s16b(p_ptr->tim_ffall);
690 wr_s16b(p_ptr->tim_sh_touki);
691 wr_s16b(p_ptr->lightspeed);
692 wr_s16b(p_ptr->tsubureru);
693 wr_s16b(p_ptr->magicdef);
694 wr_s16b(p_ptr->tim_res_nether);
695 wr_s16b(p_ptr->tim_res_time);
696 wr_byte(p_ptr->mimic_form);
697 wr_s16b(p_ptr->tim_mimic);
698 wr_s16b(p_ptr->tim_sh_fire);
699 wr_s16b(p_ptr->tim_sh_holy);
700 wr_s16b(p_ptr->tim_eyeeye);
703 wr_s16b(p_ptr->tim_reflect);
704 wr_s16b(p_ptr->multishadow);
705 wr_s16b(p_ptr->dustrobe);
707 wr_s16b(p_ptr->chaos_patron);
708 wr_u32b(p_ptr->muta1);
709 wr_u32b(p_ptr->muta2);
710 wr_u32b(p_ptr->muta3);
712 for (i = 0; i<8; i++)
713 wr_s16b(p_ptr->virtues[i]);
714 for (i = 0; i<8; i++)
715 wr_s16b(p_ptr->vir_types[i]);
717 wr_s16b(p_ptr->ele_attack);
718 wr_u32b(p_ptr->special_attack);
719 wr_s16b(p_ptr->ele_immune);
720 wr_u32b(p_ptr->special_defense);
721 wr_byte(p_ptr->knowledge);
722 wr_byte(p_ptr->autopick_autoregister);
723 wr_byte(0); /* oops */
724 wr_byte(p_ptr->action);
726 wr_byte(preserve_mode);
727 wr_byte(p_ptr->wait_report_score);
730 for (i = 0; i < 12; i++) wr_u32b(0L);
732 /* Ignore some flags */
733 wr_u32b(0L); /* oops */
734 wr_u32b(0L); /* oops */
735 wr_u32b(0L); /* oops */
738 /* Write the "object seeds" */
739 wr_u32b(seed_flavor);
744 wr_u16b(p_ptr->panic_save);
745 wr_u16b(p_ptr->total_winner);
746 wr_u16b(p_ptr->noscore);
750 wr_byte(p_ptr->is_dead);
755 /* Turn of last "feeling" */
761 wr_s32b(dungeon_turn);
766 wr_s16b(p_ptr->today_mon);
767 wr_s16b(p_ptr->riding);
769 /* Current floor_id */
770 wr_s16b(p_ptr->floor_id);
772 /* Save temporary preserved pets (obsolated) */
777 wr_s32b(p_ptr->visit);
779 wr_u32b(p_ptr->count);
785 * hook function to sort monsters by level
787 static bool ang_sort_comp_cave_temp(vptr u, vptr v, int a, int b)
789 cave_template_type *who = (cave_template_type *)(u);
791 u16b o1 = who[a].occurrence;
792 u16b o2 = who[b].occurrence;
802 * Sorting hook -- Swap function
804 static void ang_sort_swap_cave_temp(vptr u, vptr v, int a, int b)
806 cave_template_type *who = (cave_template_type *)(u);
808 cave_template_type holder;
821 * Actually write a saved floor data
822 * using effectively compressed format.
824 static void wr_saved_floor(saved_floor_type *sf_ptr)
826 cave_template_type *template;
841 /* Dungeon floor specific info follows */
845 /*** Not a saved floor ***/
851 /*** The saved floor ***/
853 wr_s16b(sf_ptr->floor_id);
854 wr_byte(sf_ptr->savefile_id);
855 wr_s16b(sf_ptr->dun_level);
856 wr_s32b(sf_ptr->last_visit);
857 wr_u32b(sf_ptr->visit_mark);
858 wr_s16b(sf_ptr->upper_floor_id);
859 wr_s16b(sf_ptr->lower_floor_id);
872 /*********** Make template for cave_type **********/
875 * Usually number of templates are fewer than 255. Even if
876 * more than 254 are exist, the occurrence of each template
877 * with larger ID is very small when we sort templates by
878 * occurrence. So we will use two (or more) bytes for
879 * templete ID larger than 254.
881 * Ex: 256 will be "0xff" "0x01".
882 * 515 will be "0xff" "0xff" "0x03"
885 /* Fake max number */
888 /* Allocate the "template" array */
889 C_MAKE(template, max_num_temp, cave_template_type);
891 /* Extract template array */
892 for (y = 0; y < cur_hgt; y++)
894 for (x = 0; x < cur_wid; x++)
896 cave_type *c_ptr = &cave[y][x];
898 for (i = 0; i < num_temp; i++)
900 if (template[i].info == c_ptr->info &&
901 template[i].feat == c_ptr->feat &&
902 template[i].mimic == c_ptr->mimic &&
903 template[i].special == c_ptr->special)
905 /* Same terrain is exist */
906 template[i].occurrence++;
911 /* Are there same one? */
912 if (i < num_temp) continue;
914 /* If the max_num_temp is too small, increase it. */
915 if (num_temp >= max_num_temp)
917 cave_template_type *old_template = template;
919 /* Re-allocate the "template" array */
920 C_MAKE(template, max_num_temp + 255, cave_template_type);
921 C_COPY(template, old_template, max_num_temp, cave_template_type);
922 C_FREE(old_template, max_num_temp, cave_template_type);
926 /* Add new template */
927 template[num_temp].info = c_ptr->info;
928 template[num_temp].feat = c_ptr->feat;
929 template[num_temp].mimic = c_ptr->mimic;
930 template[num_temp].special = c_ptr->special;
931 template[num_temp].occurrence = 1;
933 /* Increase number of template */
938 /* Select the sort method */
939 ang_sort_comp = ang_sort_comp_cave_temp;
940 ang_sort_swap = ang_sort_swap_cave_temp;
942 /* Sort by occurrence */
943 ang_sort(template, &dummy_why, num_temp);
946 /*** Dump templates ***/
948 /* Total templates */
951 /* Dump the templates */
952 for (i = 0; i < num_temp; i++)
954 cave_template_type *ct_ptr = &template[i];
957 wr_u16b(ct_ptr->info);
958 wr_s16b(ct_ptr->feat);
959 wr_s16b(ct_ptr->mimic);
960 wr_s16b(ct_ptr->special);
965 /*** "Run-Length-Encoding" of cave ***/
967 /* Note that this will induce two wasted bytes */
972 for (y = 0; y < cur_hgt; y++)
974 for (x = 0; x < cur_wid; x++)
976 cave_type *c_ptr = &cave[y][x];
978 for (i = 0; i < num_temp; i++)
980 if (template[i].info == c_ptr->info &&
981 template[i].feat == c_ptr->feat &&
982 template[i].mimic == c_ptr->mimic &&
983 template[i].special == c_ptr->special)
990 /* If the run is broken, or too full, flush it */
991 if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
993 wr_byte((byte)count);
995 while (prev_u16b >= MAX_UCHAR)
997 /* Mark as actual data is larger than 254 */
999 prev_u16b -= MAX_UCHAR;
1002 wr_byte((byte)prev_u16b);
1007 /* Continue the run */
1015 /* Flush the data (if any) */
1018 wr_byte((byte)count);
1020 while (prev_u16b >= MAX_UCHAR)
1022 /* Mark as actual data is larger than 254 */
1024 prev_u16b -= MAX_UCHAR;
1026 wr_byte((byte)prev_u16b);
1030 /* Free the "template" array */
1031 C_FREE(template, max_num_temp, cave_template_type);
1034 /*** Dump objects ***/
1039 /* Dump the objects */
1040 for (i = 1; i < o_max; i++)
1042 object_type *o_ptr = &o_list[i];
1049 /*** Dump the monsters ***/
1051 /* Total monsters */
1054 /* Dump the monsters */
1055 for (i = 1; i < m_max; i++)
1057 monster_type *m_ptr = &m_list[i];
1066 * Write the current dungeon (new method)
1068 static bool wr_dungeon(void)
1070 saved_floor_type *cur_sf_ptr;
1073 /* Forget the lite */
1076 /* Forget the view */
1079 /* Forget the view */
1082 /* Update lite/view */
1083 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1085 /* Update monsters */
1086 p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
1091 /* Number of floor_id used from birth */
1092 wr_s16b(max_floor_id);
1094 /* Current dungeon type */
1095 wr_byte(dungeon_type);
1098 /*** No saved floor (On the surface etc.) ***/
1099 if (!p_ptr->floor_id)
1101 /* No array elements */
1104 /* Write the current floor data */
1105 wr_saved_floor(NULL);
1112 /*** In the dungeon ***/
1114 /* Number of array elements */
1115 wr_byte(MAX_SAVED_FLOORS);
1117 /* Write the saved_floors array */
1118 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1120 saved_floor_type *sf_ptr = &saved_floors[i];
1122 wr_s16b(sf_ptr->floor_id);
1123 wr_byte(sf_ptr->savefile_id);
1124 wr_s16b(sf_ptr->dun_level);
1125 wr_s32b(sf_ptr->last_visit);
1126 wr_u32b(sf_ptr->visit_mark);
1127 wr_s16b(sf_ptr->upper_floor_id);
1128 wr_s16b(sf_ptr->lower_floor_id);
1131 /* Extract pointer to current floor */
1132 cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1134 /* Save current floor to temporal file */
1135 if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1137 /* Move data in temporal files to the savefile */
1138 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1140 saved_floor_type *sf_ptr = &saved_floors[i];
1142 /* Unused element */
1143 if (!sf_ptr->floor_id) continue;
1145 /* Load temporal saved floor file */
1146 if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
1151 /* Write saved floor data to the save file */
1152 wr_saved_floor(sf_ptr);
1161 /* Restore current floor */
1162 if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
1171 * Actually write a save-file
1173 static bool wr_savefile_new(void)
1183 /* Compact the objects */
1185 /* Compact the monsters */
1186 compact_monsters(0);
1188 /* Guess at the current time */
1189 now = time((time_t *)0);
1192 /* Note the operating system */
1195 /* Note when the file was saved */
1198 /* Note the number of saves */
1202 /*** Actually write the file ***/
1204 /* Dump the file header */
1206 wr_byte(FAKE_VER_MAJOR);
1208 wr_byte(FAKE_VER_MINOR);
1210 wr_byte(FAKE_VER_PATCH);
1213 /* Initial value of xor_byte */
1214 tmp8u = (byte)randint0(256);
1218 /* Reset the checksum */
1222 /* Write the savefile version for Hengband 1.1.1 and later */
1223 wr_byte(H_VER_EXTRA);
1224 wr_byte(H_VER_PATCH);
1225 wr_byte(H_VER_MINOR);
1226 wr_byte(H_VER_MAJOR);
1228 /* Operating system */
1232 /* Time file last saved */
1235 /* Number of past lives */
1238 /* Number of times saved */
1249 /* EUC kanji code */
1253 /* SJIS kanji code */
1261 /* Write the RNG state */
1265 /* Write the boolean "options" */
1269 /* Dump the number of "messages" */
1270 tmp16u = message_num();
1271 if (compress_savefile && (tmp16u > 40)) tmp16u = 40;
1274 /* Dump the messages (oldest first!) */
1275 for (i = tmp16u - 1; i >= 0; i--)
1277 wr_string(message_str((s16b)i));
1281 /* Dump the monster lore */
1284 for (i = 0; i < tmp16u; i++) wr_lore(i);
1287 /* Dump the object memory */
1290 for (i = 0; i < tmp16u; i++) wr_xtra(i);
1292 /* Dump the towns */
1296 /* Dump the quests */
1297 tmp16u = max_quests;
1300 /* Dump the quests */
1301 tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
1304 for (i = 0; i < max_quests; i++)
1306 /* Save status for every quest */
1307 wr_s16b(quest[i].status);
1309 /* And the dungeon level too */
1310 /* (prevents problems with multi-level quests) */
1311 wr_s16b(quest[i].level);
1313 wr_byte(quest[i].complev);
1315 /* Save quest status if quest is running */
1316 if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
1318 wr_s16b(quest[i].cur_num);
1319 wr_s16b(quest[i].max_num);
1320 wr_s16b(quest[i].type);
1321 wr_s16b(quest[i].r_idx);
1322 wr_s16b(quest[i].k_idx);
1323 wr_byte(quest[i].flags);
1324 wr_byte(quest[i].dungeon);
1328 /* Dump the position in the wilderness */
1329 wr_s32b(p_ptr->wilderness_x);
1330 wr_s32b(p_ptr->wilderness_y);
1332 wr_byte(p_ptr->wild_mode);
1333 wr_byte(ambush_flag);
1335 wr_s32b(max_wild_x);
1336 wr_s32b(max_wild_y);
1338 /* Dump the wilderness seeds */
1339 for (i = 0; i < max_wild_x; i++)
1341 for (j = 0; j < max_wild_y; j++)
1343 wr_u32b(wilderness[j][i].seed);
1347 /* Hack -- Dump the artifacts */
1350 for (i = 0; i < tmp16u; i++)
1352 artifact_type *a_ptr = &a_info[i];
1353 wr_byte(a_ptr->cur_num);
1354 wr_s16b(a_ptr->floor_id);
1359 /* Write the "extra" information */
1362 /* Dump the "player hp" entries */
1363 tmp16u = PY_MAX_LEVEL;
1365 for (i = 0; i < tmp16u; i++)
1367 wr_s16b(p_ptr->player_hp[i]);
1371 /* Write spell data */
1372 wr_u32b(p_ptr->spell_learned1);
1373 wr_u32b(p_ptr->spell_learned2);
1374 wr_u32b(p_ptr->spell_worked1);
1375 wr_u32b(p_ptr->spell_worked2);
1376 wr_u32b(p_ptr->spell_forgotten1);
1377 wr_u32b(p_ptr->spell_forgotten2);
1379 wr_s16b(p_ptr->learned_spells);
1380 wr_s16b(p_ptr->add_spells);
1382 /* Dump the ordered spells */
1383 for (i = 0; i < 64; i++)
1385 wr_byte(p_ptr->spell_order[i]);
1389 /* Write the inventory */
1390 for (i = 0; i < INVEN_TOTAL; i++)
1392 object_type *o_ptr = &inventory[i];
1394 /* Skip non-objects */
1395 if (!o_ptr->k_idx) continue;
1404 /* Add a sentinel */
1407 /* Note the towns */
1411 /* Note the stores */
1412 tmp16u = MAX_STORES;
1415 /* Dump the stores of all towns */
1416 for (i = 1; i < max_towns; i++)
1418 for (j = 0; j < MAX_STORES; j++)
1420 wr_store(&town[i].store[j]);
1424 /* Write the pet command settings */
1425 wr_s16b(p_ptr->pet_follow_distance);
1426 wr_s16b(p_ptr->pet_extra_flags);
1428 /* Write screen dump for sending score */
1429 if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead))
1431 wr_string(screen_dump);
1438 /* Player is not dead, write the dungeon */
1439 if (!p_ptr->is_dead)
1441 /* Dump the dungeon */
1442 if (!wr_dungeon()) return FALSE;
1444 /* Dump the ghost */
1452 /* Write the "value check-sum" */
1455 /* Write the "encoded checksum" */
1460 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
1462 /* Successful save */
1468 * Medium level player saver
1470 * XXX XXX XXX Angband 2.8.0 will use "fd" instead of "fff" if possible
1472 static bool save_player_aux(char *name)
1485 /* File type is "SAVE" */
1486 FILE_TYPE(FILE_TYPE_SAVE);
1489 /* Grab permissions */
1492 /* Create the savefile */
1493 fd = fd_make(name, mode);
1495 /* Drop permissions */
1501 /* Close the "fd" */
1504 /* Grab permissions */
1507 /* Open the savefile */
1508 fff = my_fopen(name, "wb");
1510 /* Drop permissions */
1513 /* Successful open */
1516 /* Write the savefile */
1517 if (wr_savefile_new()) ok = TRUE;
1519 /* Attempt to close it */
1520 if (my_fclose(fff)) ok = FALSE;
1523 /* Grab permissions */
1526 /* Remove "broken" files */
1527 if (!ok) (void)fd_kill(name);
1529 /* Drop permissions */
1535 if (!ok) return (FALSE);
1537 counts_write(0, playtime);
1539 /* Successful save */
1540 character_saved = TRUE;
1549 * Attempt to save the player in a savefile
1551 bool save_player(void)
1562 /* Get "games" permissions */
1571 strcpy(safe, savefile);
1572 strcat(safe, ".new");
1575 /* Hack -- support "flat directory" usage on VM/ESA */
1576 strcpy(safe, savefile);
1580 /* Grab permissions */
1586 /* Drop permissions */
1591 /* Attempt to save the player */
1592 if (save_player_aux(safe))
1597 strcpy(temp, savefile);
1598 strcat(temp, ".old");
1601 /* Hack -- support "flat directory" usage on VM/ESA */
1602 strcpy(temp, savefile);
1606 /* Grab permissions */
1612 /* Preserve old savefile */
1613 fd_move(savefile, temp);
1615 /* Activate new savefile */
1616 fd_move(safe, savefile);
1618 /* Remove preserved savefile */
1621 /* Drop permissions */
1624 /* Hack -- Pretend the character was loaded */
1625 character_loaded = TRUE;
1627 #ifdef VERIFY_SAVEFILE
1629 /* Lock on savefile */
1630 strcpy(temp, savefile);
1631 strcat(temp, ".lok");
1633 /* Grab permissions */
1636 /* Remove lock file */
1639 /* Drop permissions */
1653 /* Drop "games" permissions */
1660 /* Return the result */
1667 * Attempt to Load a "savefile"
1669 * Version 2.7.0 introduced a slightly different "savefile" format from
1670 * older versions, requiring a completely different parsing method.
1672 * Note that savefiles from 2.7.0 - 2.7.2 are completely obsolete.
1674 * Pre-2.8.0 savefiles lose some data, see "load2.c" for info.
1676 * Pre-2.7.0 savefiles lose a lot of things, see "load1.c" for info.
1678 * On multi-user systems, you may only "read" a savefile if you will be
1679 * allowed to "write" it later, this prevents painful situations in which
1680 * the player loads a savefile belonging to someone else, and then is not
1681 * allowed to save his game when he quits.
1683 * We return "TRUE" if the savefile was usable, and we set the global
1684 * flag "character_loaded" if a real, living, character was loaded.
1686 * Note that we always try to load the "current" savefile, even if
1687 * there is no such file, so we must check for "empty" savefile names.
1689 bool load_player(void)
1697 #ifdef VERIFY_TIMESTAMP
1698 struct stat statbuf;
1701 cptr what = "generic";
1708 p_ptr->is_dead = FALSE;
1711 /* Allow empty savefile name */
1712 if (!savefile[0]) return (TRUE);
1715 #if !defined(MACINTOSH) && !defined(WINDOWS) && !defined(VM)
1717 /* XXX XXX XXX Fix this */
1719 /* Verify the existance of the savefile */
1720 if (access(savefile, 0) < 0)
1722 /* Give a message */
1724 msg_print("¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤¬¤¢¤ê¤Þ¤»¤ó¡£");
1726 msg_print("Savefile does not exist.");
1738 #ifdef VERIFY_SAVEFILE
1740 /* Verify savefile usage */
1747 /* Extract name of lock file */
1748 strcpy(temp, savefile);
1749 strcat(temp, ".lok");
1751 /* Check for lock */
1752 fkk = my_fopen(temp, "r");
1754 /* Oops, lock exists */
1757 /* Close the file */
1762 msg_print("¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤Ï¸½ºß»ÈÍÑÃæ¤Ç¤¹¡£");
1764 msg_print("Savefile is currently in use.");
1773 /* Create a lock file */
1774 fkk = my_fopen(temp, "w");
1776 /* Dump a line of info */
1777 fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
1779 /* Close the lock file */
1789 /* Open the savefile */
1790 fd = fd_open(savefile, O_RDONLY);
1793 if (fd < 0) err = -1;
1795 /* Message (below) */
1797 if (err) what = "¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤ò³«¤±¤Þ¤»¤ó¡£";
1799 if (err) what = "Cannot open savefile";
1808 #ifdef VERIFY_TIMESTAMP
1809 /* Get the timestamp */
1810 (void)fstat(fd, &statbuf);
1813 /* Read the first four bytes */
1814 if (fd_read(fd, (char*)(vvv), 4)) err = -1;
1818 if (err) what = "¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤òÆɤá¤Þ¤»¤ó¡£";
1820 if (err) what = "Cannot read savefile";
1824 /* Close the file */
1832 /* Extract version */
1842 /* Attempt to load */
1843 err = rd_savefile_new();
1845 /* Message (below) */
1847 if (err) what = "¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤ò²òÀϽÐÍè¤Þ¤»¤ó¡£";
1849 if (err) what = "Cannot parse savefile";
1858 if (!turn) err = -1;
1860 /* Message (below) */
1862 if (err) what = "¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤¬²õ¤ì¤Æ¤¤¤Þ¤¹";
1864 if (err) what = "Broken savefile";
1869 #ifdef VERIFY_TIMESTAMP
1870 /* Verify timestamp */
1871 if (!err && !arg_wizard)
1873 /* Hack -- Verify the timestamp */
1874 if (sf_when > (statbuf.st_ctime + 100) ||
1875 sf_when < (statbuf.st_ctime - 100))
1879 what = "̵¸ú¤Ê¥¿¥¤¥à¡¦¥¹¥¿¥ó¥×¤Ç¤¹";
1881 what = "Invalid timestamp";
1895 /* Give a conversion warning */
1896 if ((FAKE_VER_MAJOR != z_major) ||
1897 (FAKE_VER_MINOR != z_minor) ||
1898 (FAKE_VER_PATCH != z_patch))
1900 if (z_major == 2 && z_minor == 0 && z_patch == 6)
1903 msg_print("¥Ð¡¼¥¸¥ç¥ó 2.0.* ÍѤΥ»¡¼¥Ö¥Õ¥¡¥¤¥ë¤òÊÑ´¹¤·¤Þ¤·¤¿¡£");
1905 msg_print("Converted a 2.0.* savefile.");
1913 msg_format("¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ÍѤΥ»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤òÊÑ´¹¤·¤Þ¤·¤¿¡£",
1914 (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
1916 msg_format("Converted a %d.%d.%d savefile.",
1917 (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
1923 /* Player is dead */
1929 /* A character was loaded */
1930 character_loaded = TRUE;
1936 /* Player is no longer "dead" */
1937 p_ptr->is_dead = FALSE;
1943 turn = old_turn = 0;
1949 /* A character was loaded */
1950 character_loaded = TRUE;
1953 u32b tmp = counts_read(2);
1954 if (tmp > p_ptr->count)
1956 if (counts_read(0) > playtime || counts_read(1) == playtime)
1957 counts_write(2, ++p_ptr->count);
1958 counts_write(1, playtime);
1966 #ifdef VERIFY_SAVEFILE
1968 /* Verify savefile usage */
1973 /* Extract name of lock file */
1974 strcpy(temp, savefile);
1975 strcat(temp, ".lok");
1986 msg_format("¥¨¥é¡¼(%s)¤¬¥Ð¡¼¥¸¥ç¥ó%d.%d.%d ÍÑ¥»¡¼¥Ö¥Õ¥¡¥¤¥ëÆɤ߹þÃæ¤ËȯÀ¸¡£",
1987 what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
1989 msg_format("Error (%s) reading %d.%d.%d savefile.",
1990 what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
1999 void remove_loc(void)
2001 #ifdef VERIFY_SAVEFILE
2003 #endif /* VERIFY_SAVEFILE */
2008 /* Get "games" permissions */
2011 # endif /* SECURE */
2012 #endif /* SET_UID */
2014 #ifdef VERIFY_SAVEFILE
2016 /* Lock on savefile */
2017 strcpy(temp, savefile);
2018 strcat(temp, ".lok");
2020 /* Remove lock file */
2023 #endif /* VERIFY_SAVEFILE */
2028 /* Drop "games" permissions */
2031 # endif /* SECURE */
2032 #endif /* SET_UID */
2038 * Actually write a temporal saved floor file
2040 static bool save_floor_aux(saved_floor_type *sf_ptr)
2044 /* Compact the objects */
2046 /* Compact the monsters */
2047 compact_monsters(0);
2050 /*** Actually write the file ***/
2052 /* Initial value of xor_byte */
2053 tmp8u = (byte)randint0(256);
2058 /* Reset the checksum */
2062 /* Write the sign of this process */
2063 wr_u32b(saved_floor_file_sign);
2065 /* Dump the dungeon floor */
2066 wr_saved_floor(sf_ptr);
2069 /* Write the "value check-sum" */
2072 /* Write the "encoded checksum" */
2077 if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
2079 /* Successful save */
2085 * Attempt to save the temporally saved-floor data
2087 bool save_floor(saved_floor_type *sf_ptr, u32b mode)
2089 FILE *old_fff = NULL;
2090 byte old_xor_byte = 0;
2091 u32b old_v_stamp = 0;
2092 u32b old_x_stamp = 0;
2094 char floor_savefile[1024];
2098 if (!(mode & SLF_SECOND))
2102 /* Get "games" permissions */
2108 /* We have one file already opened */
2111 /* Backup original values */
2113 old_xor_byte = xor_byte;
2114 old_v_stamp = v_stamp;
2115 old_x_stamp = x_stamp;
2119 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
2121 /* Grab permissions */
2125 fd_kill(floor_savefile);
2127 /* Drop permissions */
2131 /* Attempt to save the player */
2136 /* File type is "SAVE" */
2137 FILE_TYPE(FILE_TYPE_SAVE);
2139 /* Grab permissions */
2142 /* Create the savefile */
2143 fd = fd_make(floor_savefile, 0644);
2145 /* Drop permissions */
2151 /* Close the "fd" */
2154 /* Grab permissions */
2157 /* Open the savefile */
2158 fff = my_fopen(floor_savefile, "wb");
2160 /* Drop permissions */
2163 /* Successful open */
2166 /* Write the savefile */
2167 if (save_floor_aux(sf_ptr)) ok = TRUE;
2169 /* Attempt to close it */
2170 if (my_fclose(fff)) ok = FALSE;
2173 /* Remove "broken" files */
2176 /* Grab permissions */
2179 (void)fd_kill(floor_savefile);
2181 /* Drop permissions */
2186 if (!(mode & SLF_SECOND))
2190 /* Drop "games" permissions */
2196 /* We have one file already opened */
2199 /* Restore original values */
2201 xor_byte = old_xor_byte;
2202 v_stamp = old_v_stamp;
2203 x_stamp = old_x_stamp;
2206 /* Return the result */