3 /* Purpose: management of the saved floor */
6 * Copyright (c) 2002 Mogami
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
17 static s16b new_floor_id; /* floor_id of the destination */
18 static u32b change_floor_mode; /* Mode flags for changing floor */
19 static u32b latest_visit_mark; /* Max number of visit_mark */
23 * Initialize saved_floors array. Make sure that old temporal files
24 * are not remaining as gurbages.
26 void init_saved_floors(bool force)
28 char floor_savefile[1024];
35 /* Get "games" permissions */
40 for (i = 0; i < MAX_SAVED_FLOORS; i++)
42 saved_floor_type *sf_ptr = &saved_floors[i];
45 sprintf(floor_savefile, "%s.F%02d", savefile, i);
47 /* Grab permissions */
50 /* Try to create the file */
51 fd = fd_make(floor_savefile, mode);
53 /* Drop permissions */
62 msg_print("¥¨¥é¡¼¡§¸Å¤¤¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£");
63 msg_print("ÊѶòÈÚÅܤòÆó½Å¤Ëµ¯Æ°¤·¤Æ¤¤¤Ê¤¤¤«³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£");
64 msg_print("²áµî¤ËÊѶòÈÚÅܤ¬¥¯¥é¥Ã¥·¥å¤·¤¿¾ì¹ç¤Ï°ì»þ¥Õ¥¡¥¤¥ë¤ò");
65 msg_print("¶¯À©Åª¤Ëºï½ü¤·¤Æ¼Â¹Ô¤ò³¤±¤é¤ì¤Þ¤¹¡£");
66 if (!get_check("¶¯À©Åª¤Ëºï½ü¤·¤Æ¤â¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) quit("¼Â¹ÔÃæ»ß");
68 msg_print("Error: There are old temporal files.");
69 msg_print("Make sure you are not running two game processes simultaneously.");
70 msg_print("If the temporal files are garbages of old crashed process, ");
71 msg_print("you can delete it safely.");
72 if (!get_check("Do you delete old temporal files? ")) quit("Aborted.");
83 /* Grab permissions */
86 /* Simply kill the temporal file */
87 (void)fd_kill(floor_savefile);
89 /* Drop permissions */
95 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
98 /* vist_mark is from 1 */
99 latest_visit_mark = 1;
101 /* A sign to mark temporal files */
102 saved_floor_file_sign = time(NULL);
104 /* No next floor yet */
107 /* No change floor mode yet */
108 change_floor_mode = 0;
112 /* Drop "games" permissions */
120 * Kill temporal files
121 * Should be called just before the game quit.
123 void clear_saved_floor_files(void)
125 char floor_savefile[1024];
130 /* Get "games" permissions */
135 for (i = 0; i < MAX_SAVED_FLOORS; i++)
137 saved_floor_type *sf_ptr = &saved_floors[i];
139 /* No temporal file */
140 if (!sf_ptr->floor_id) continue;
141 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
144 sprintf(floor_savefile, "%s.F%02d", savefile, i);
146 /* Grab permissions */
149 /* Simply kill the temporal file */
150 (void)fd_kill(floor_savefile);
152 /* Drop permissions */
158 /* Drop "games" permissions */
166 * Get a pointer for an item of the saved_floors array.
168 saved_floor_type *get_sf_ptr(s16b floor_id)
172 /* floor_id No.0 indicates no floor */
173 if (!floor_id) return NULL;
175 for (i = 0; i < MAX_SAVED_FLOORS; i++)
177 saved_floor_type *sf_ptr = &saved_floors[i];
179 if (sf_ptr->floor_id == floor_id) return sf_ptr;
188 * kill a saved floor and get an empty space
190 static void kill_saved_floor(saved_floor_type *sf_ptr)
192 char floor_savefile[1024];
198 if (!sf_ptr->floor_id) return;
200 if (sf_ptr->floor_id == p_ptr->floor_id)
202 /* Kill current floor */
205 /* Current floor doesn't have temporal file */
210 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
212 /* Grab permissions */
215 /* Simply kill the temporal file */
216 (void)fd_kill(floor_savefile);
218 /* Drop permissions */
222 /* No longer exists */
223 sf_ptr->floor_id = 0;
228 * Initialize new saved floor and get its floor id. If number of
229 * saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
231 s16b get_new_floor_id(void)
233 saved_floor_type *sf_ptr;
236 /* Look for empty space */
237 for (i = 0; i < MAX_SAVED_FLOORS; i++)
239 sf_ptr = &saved_floors[i];
241 if (!sf_ptr->floor_id) break;
245 if (i == MAX_SAVED_FLOORS)
248 u32b oldest_visit = 0xffffffffL;
250 /* Search for oldest */
251 for (i = 0; i < MAX_SAVED_FLOORS; i++)
253 sf_ptr = &saved_floors[i];
255 /* Don't kill current floor */
256 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
258 /* Don't kill newer */
259 if (sf_ptr->visit_mark > oldest_visit) continue;
262 oldest_visit = sf_ptr->visit_mark;
265 /* Kill oldest saved floor */
266 sf_ptr = &saved_floors[oldest];
267 kill_saved_floor(sf_ptr);
273 /* Prepare new floor data */
274 sf_ptr->savefile_id = i;
275 sf_ptr->floor_id = max_floor_id;
276 sf_ptr->last_visit = 0;
277 sf_ptr->upper_floor_id = 0;
278 sf_ptr->lower_floor_id = 0;
279 sf_ptr->visit_mark = latest_visit_mark++;
281 /* sf_ptr->dun_level may be changed later */
282 sf_ptr->dun_level = dun_level;
285 /* Increment number of floor_id */
286 if (max_floor_id < MAX_SHORT) max_floor_id++;
288 /* 32767 floor_ids are all used up! Re-use ancient IDs */
289 else max_floor_id = 1;
291 return sf_ptr->floor_id;
296 * Prepare mode flags of changing floor
298 void prepare_change_floor_mode(u32b mode)
300 change_floor_mode |= mode;
305 * Builds the dead end
307 static void build_dead_end(void)
311 /* Clear and empty the cave */
314 /* Fill the arrays of floors and walls in the good proportions */
315 set_floor_and_wall(0);
318 cur_hgt = SCREEN_HGT;
319 cur_wid = SCREEN_WID;
321 /* Filled with permanent walls */
322 for (y = 0; y < MAX_HGT; y++)
324 for (x = 0; x < MAX_WID; x++)
326 /* Create "solid" perma-wall */
327 place_solid_perm_bold(y, x);
331 /* Place at center of the floor */
335 /* Give one square */
336 place_floor_bold(py, px);
340 /* Maximum number of preservable pets */
341 #define MAX_PARTY_MON 21
343 static monster_type party_mon[MAX_PARTY_MON];
349 static void preserve_pet(void)
353 for (num = 0; num < MAX_PARTY_MON; num++)
355 party_mon[num].r_idx = 0;
360 monster_type *m_ptr = &m_list[p_ptr->riding];
362 /* Pet of other pet don't follow. */
363 if (m_ptr->parent_m_idx)
366 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
367 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
371 /* Preserve the mount */
372 COPY(&party_mon[0], m_ptr, monster_type);
374 /* Delete from this floor */
375 delete_monster_idx(p_ptr->riding);
380 * If player is in wild mode, no pets are preserved
381 * except a monster whom player riding
383 if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
385 for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
387 monster_type *m_ptr = &m_list[i];
389 if (!m_ptr->r_idx) continue;
390 if (!is_pet(m_ptr)) continue;
391 if (i == p_ptr->riding) continue;
393 if (reinit_wilderness)
395 /* Don't lose sight of pets when getting a Quest */
399 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
401 /* Confused (etc.) monsters don't follow. */
402 if (MON_CONFUSED(m_ptr) || MON_STUNNED(m_ptr) || MON_CSLEEP(m_ptr)) continue;
404 /* Pet of other pet don't follow. */
405 if (m_ptr->parent_m_idx) continue;
408 * Pets with nickname will follow even from 3 blocks away
409 * when you or the pet can see the other.
411 if (m_ptr->nickname &&
412 ((player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(py, px, m_ptr->fy, m_ptr->fx)) ||
413 (los(m_ptr->fy, m_ptr->fx, py, px) && projectable(m_ptr->fy, m_ptr->fx, py, px))))
415 if (dis > 3) continue;
419 if (dis > 1) continue;
423 COPY(&party_mon[num], &m_list[i], monster_type);
427 /* Delete from this floor */
428 delete_monster_idx(i);
432 if (record_named_pet)
434 for (i = m_max - 1; i >=1; i--)
436 monster_type *m_ptr = &m_list[i];
439 if (!m_ptr->r_idx) continue;
440 if (!is_pet(m_ptr)) continue;
441 if (!m_ptr->nickname) continue;
442 if (p_ptr->riding == i) continue;
444 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
445 do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
450 /* Pet of other pet may disappear. */
451 for (i = m_max - 1; i >=1; i--)
453 monster_type *m_ptr = &m_list[i];
455 /* Are there its parent? */
456 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
458 /* Its parent have gone, it also goes away. */
464 /* Acquire the monster name */
465 monster_desc(m_name, m_ptr, 0);
468 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
470 msg_format("%^s disappears!", m_name);
474 /* Delete the monster */
475 delete_monster_idx(i);
482 * Pre-calculate the racial counters of preserved pets
483 * To prevent multiple generation of unique monster who is the minion of player
485 void precalc_cur_num_of_pet(void)
489 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
491 for (i = 0; i < max_num; i++)
493 m_ptr = &party_mon[i];
495 /* Skip empty monsters */
496 if (!m_ptr->r_idx) continue;
498 /* Hack -- Increase the racial counter */
499 real_r_ptr(m_ptr)->cur_num++;
505 * Place preserved pet monsters on new floor
507 static void place_pet(void)
510 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
512 for (i = 0; i < max_num; i++)
516 if (!(party_mon[i].r_idx)) continue;
521 p_ptr->riding = m_idx;
532 for (d = 1; d < 6; d++)
534 for (j = 1000; j > 0; j--)
536 scatter(&cy, &cx, py, px, d, 0);
537 if (monster_can_enter(cy, cx, &r_info[party_mon[i].r_idx], 0)) break;
541 m_idx = (d == 6) ? 0 : m_pop();
546 monster_type *m_ptr = &m_list[m_idx];
549 cave[cy][cx].m_idx = m_idx;
551 m_ptr->r_idx = party_mon[i].r_idx;
553 /* Copy all member of the structure */
554 *m_ptr = party_mon[i];
555 r_ptr = real_r_ptr(m_ptr);
560 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
563 m_ptr->hold_o_idx = 0;
566 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
568 /* Monster is still being nice */
569 m_ptr->mflag |= (MFLAG_NICE);
571 /* Must repair monsters */
572 repair_monsters = TRUE;
575 /* Update the monster */
576 update_mon(m_idx, TRUE);
579 /* Pre-calculated in precalc_cur_num_of_pet() */
580 /* r_ptr->cur_num++; */
582 /* Hack -- Count the number of "reproducers" */
583 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
585 /* Hack -- Notice new multi-hued monsters */
587 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
588 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
589 shimmer_monsters = TRUE;
594 monster_type *m_ptr = &party_mon[i];
595 monster_race *r_ptr = real_r_ptr(m_ptr);
598 monster_desc(m_name, m_ptr, 0);
600 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
602 msg_format("You have lost sight of %s.", m_name);
604 if (record_named_pet && m_ptr->nickname)
606 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
607 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
610 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
611 if (r_ptr->cur_num) r_ptr->cur_num--;
615 /* For accuracy of precalc_cur_num_of_pet() */
616 C_WIPE(party_mon, MAX_PARTY_MON, monster_type);
621 * Hack -- Update location of unique monsters and artifacts
623 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly
624 * while new floor creation since dungeons may be re-created by
627 static void update_unique_artifact(s16b cur_floor_id)
631 /* Maintain unique monsters */
632 for (i = 1; i < m_max; i++)
635 monster_type *m_ptr = &m_list[i];
637 /* Skip dead monsters */
638 if (!m_ptr->r_idx) continue;
640 /* Extract real monster race */
641 r_ptr = real_r_ptr(m_ptr);
643 /* Memorize location of the unique monster */
644 if ((r_ptr->flags1 & RF1_UNIQUE) ||
645 (r_ptr->flags7 & RF7_NAZGUL))
647 r_ptr->floor_id = cur_floor_id;
651 /* Maintain artifatcs */
652 for (i = 1; i < o_max; i++)
654 object_type *o_ptr = &o_list[i];
656 /* Skip dead objects */
657 if (!o_ptr->k_idx) continue;
659 /* Memorize location of the artifact */
660 if (object_is_fixed_artifact(o_ptr))
662 a_info[o_ptr->name1].floor_id = cur_floor_id;
669 * When a monster is at a place where player will return,
670 * Get out of the my way!
672 static void get_out_monster(void)
678 int m_idx = cave[oy][ox].m_idx;
680 /* Nothing to do if no monster */
683 /* Look until done */
688 /* Pick a (possibly illegal) location */
689 int ny = rand_spread(oy, dis);
690 int nx = rand_spread(ox, dis);
694 /* Stop after 1000 tries */
695 if (tries > 10000) return;
698 * Increase distance after doing enough tries
699 * compared to area of possible space
701 if (tries > 20 * dis * dis) dis++;
703 /* Ignore illegal locations */
704 if (!in_bounds(ny, nx)) continue;
706 /* Require "empty" floor space */
707 if (!cave_empty_bold(ny, nx)) continue;
709 /* Hack -- no teleport onto glyph of warding */
710 if (is_glyph_grid(&cave[ny][nx])) continue;
711 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
713 /* ...nor onto the Pattern */
714 if (pattern_tile(ny, nx)) continue;
716 /*** It's a good place ***/
718 m_ptr = &m_list[m_idx];
720 /* Update the old location */
721 cave[oy][ox].m_idx = 0;
723 /* Update the new location */
724 cave[ny][nx].m_idx = m_idx;
726 /* Move the monster */
730 /* No need to do update_mon() */
739 * Is this feature has special meaning (except floor_id) with c_ptr->special?
741 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
745 * Virtually teleport onto the stairs that is connecting between two
748 * Teleport level spell and trap doors will always lead the player to
749 * the one of the floors connected by the one of the stairs in the
752 static void locate_connected_stairs(saved_floor_type *sf_ptr)
754 int x, y, sx = 0, sy = 0;
760 /* Search usable stairs */
761 for (y = 0; y < cur_hgt; y++)
763 for (x = 0; x < cur_wid; x++)
765 cave_type *c_ptr = &cave[y][x];
766 feature_type *f_ptr = &f_info[c_ptr->feat];
769 if (change_floor_mode & CFM_UP)
771 if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) &&
772 !have_flag(f_ptr->flags, FF_SPECIAL))
776 /* Found fixed stairs? */
777 if (c_ptr->special &&
778 c_ptr->special == sf_ptr->upper_floor_id)
786 else if (change_floor_mode & CFM_DOWN)
788 if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) &&
789 !have_flag(f_ptr->flags, FF_SPECIAL))
793 /* Found fixed stairs */
794 if (c_ptr->special &&
795 c_ptr->special == sf_ptr->lower_floor_id)
805 if (have_flag(f_ptr->flags, FF_BLDG))
811 if (ok && (num < 20))
828 /* No stairs found! -- No return */
829 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
831 /* Mega Hack -- It's not the stairs you enter. Disable it. */
832 if (!feat_uses_special(cave[py][px].feat)) cave[py][px].special = 0;
836 /* Choose random one */
839 /* Point stair location */
846 * Maintain quest monsters, mark next floor_id at stairs, save current
847 * floor, and prepare to enter next floor.
849 void leave_floor(void)
851 cave_type *c_ptr = NULL;
853 saved_floor_type *sf_ptr;
857 /* Preserve pets and prepare to take these to next floor */
860 /* Remove all mirrors without explosion */
861 remove_all_mirrors(FALSE);
863 if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
865 /* New floor is not yet prepared */
868 /* Temporary get a floor_id (for Arena) */
869 if (!p_ptr->floor_id &&
870 (change_floor_mode & CFM_SAVE_FLOORS) &&
871 !(change_floor_mode & CFM_NO_RETURN))
873 /* Get temporal floor_id */
874 p_ptr->floor_id = get_new_floor_id();
878 /* Search the quest monster index */
879 for (i = 0; i < max_quests; i++)
881 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
882 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
883 (quest[i].type == QUEST_TYPE_RANDOM)) &&
884 (quest[i].level == dun_level) &&
885 (dungeon_type == quest[i].dungeon) &&
886 !(quest[i].flags & QUEST_FLAG_PRESET))
888 quest_r_idx = quest[i].r_idx;
892 /* Maintain quest monsters */
893 for (i = 1; i < m_max; i++)
896 monster_type *m_ptr = &m_list[i];
898 /* Skip dead monsters */
899 if (!m_ptr->r_idx) continue;
901 /* Only maintain quest monsters */
902 if (quest_r_idx != m_ptr->r_idx) continue;
904 /* Extract real monster race */
905 r_ptr = real_r_ptr(m_ptr);
907 /* Ignore unique monsters */
908 if ((r_ptr->flags1 & RF1_UNIQUE) ||
909 (r_ptr->flags7 & RF7_NAZGUL)) continue;
911 /* Delete non-unique quest monsters */
912 delete_monster_idx(i);
915 /* Check if there is a same item */
916 for (i = 0; i < INVEN_PACK; i++)
918 object_type *o_ptr = &inventory[i];
920 /* Skip dead objects */
921 if (!o_ptr->k_idx) continue;
923 /* Delete old memorized location of the artifact */
924 if (object_is_fixed_artifact(o_ptr))
926 a_info[o_ptr->name1].floor_id = 0;
930 /* Extract current floor info or NULL */
931 sf_ptr = get_sf_ptr(p_ptr->floor_id);
933 /* Choose random stairs */
934 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
936 locate_connected_stairs(sf_ptr);
939 /* Extract new dungeon level */
940 if (change_floor_mode & CFM_SAVE_FLOORS)
942 /* Extract stair position */
943 c_ptr = &cave[py][px];
944 f_ptr = &f_info[c_ptr->feat];
946 /* Get back to old saved floor? */
947 if (c_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(c_ptr->special))
949 /* Saved floor is exist. Use it. */
950 new_floor_id = c_ptr->special;
953 /* Mark shaft up/down */
954 if (have_flag(f_ptr->flags, FF_STAIRS) && have_flag(f_ptr->flags, FF_SHAFT))
956 prepare_change_floor_mode(CFM_SHAFT);
960 /* Climb up/down some sort of stairs */
961 if (change_floor_mode & (CFM_DOWN | CFM_UP))
965 /* Extract level movement number */
966 if (change_floor_mode & CFM_DOWN) move_num = 1;
967 else if (change_floor_mode & CFM_UP) move_num = -1;
969 /* Shafts are deeper than normal stairs */
970 if (change_floor_mode & CFM_SHAFT)
971 move_num += SGN(move_num);
973 /* Get out from or Enter the dungeon */
974 if (change_floor_mode & CFM_DOWN)
977 move_num = d_info[dungeon_type].mindepth;
979 else if (change_floor_mode & CFM_UP)
981 if (dun_level + move_num < d_info[dungeon_type].mindepth)
982 move_num = -dun_level;
985 dun_level += move_num;
988 /* Leaving the dungeon to town */
989 if (!dun_level && dungeon_type)
991 p_ptr->leaving_dungeon = TRUE;
992 if (!vanilla_town && !lite_town)
994 p_ptr->wilderness_y = d_info[dungeon_type].dy;
995 p_ptr->wilderness_x = d_info[dungeon_type].dx;
997 p_ptr->recall_dungeon = dungeon_type;
1000 /* Reach to the surface -- Clear all saved floors */
1001 change_floor_mode &= ~CFM_SAVE_FLOORS;
1004 /* Kill some old saved floors */
1005 if (!(change_floor_mode & CFM_SAVE_FLOORS))
1009 /* Kill all saved floors */
1010 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1011 kill_saved_floor(&saved_floors[i]);
1013 /* Reset visit_mark count */
1014 latest_visit_mark = 1;
1016 else if (change_floor_mode & CFM_NO_RETURN)
1018 /* Kill current floor */
1019 kill_saved_floor(sf_ptr);
1022 /* No current floor -- Left/Enter dungeon etc... */
1023 if (!p_ptr->floor_id)
1025 /* No longer need to save current floor */
1030 /* Mark next floor_id on the previous floor */
1034 new_floor_id = get_new_floor_id();
1036 /* Connect from here */
1037 if (c_ptr && !feat_uses_special(c_ptr->feat))
1039 c_ptr->special = new_floor_id;
1043 /* Fix connection -- level teleportation or trap door */
1044 if (change_floor_mode & CFM_RAND_CONNECT)
1046 if (change_floor_mode & CFM_UP)
1047 sf_ptr->upper_floor_id = new_floor_id;
1048 else if (change_floor_mode & CFM_DOWN)
1049 sf_ptr->lower_floor_id = new_floor_id;
1052 /* If you can return, you need to save previous floor */
1053 if ((change_floor_mode & CFM_SAVE_FLOORS) &&
1054 !(change_floor_mode & CFM_NO_RETURN))
1056 /* Get out of the my way! */
1059 /* Record the last visit turn of current floor */
1060 sf_ptr->last_visit = turn;
1062 /* Forget the lite */
1065 /* Forget the view */
1068 /* Forget the view */
1071 /* Save current floor */
1072 if (!save_floor(sf_ptr, 0))
1074 /* Save failed -- No return */
1075 prepare_change_floor_mode(CFM_NO_RETURN);
1077 /* Kill current floor */
1078 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1085 * Enter new floor. If the floor is an old saved floor, it will be
1086 * restored from the temporal file. If the floor is new one, new cave
1087 * will be generated.
1089 void change_floor(void)
1091 saved_floor_type *sf_ptr;
1092 bool loaded = FALSE;
1094 /* The dungeon is not ready */
1095 character_dungeon = FALSE;
1097 /* No longer in the trap detecteded region */
1098 p_ptr->dtrap = FALSE;
1100 /* Mega-Hack -- no panel yet */
1106 /* Mega-Hack -- not ambushed on the wildness? */
1107 ambush_flag = FALSE;
1109 /* No saved floors (On the surface etc.) */
1110 if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
1111 !(change_floor_mode & CFM_FIRST_FLOOR))
1116 /* Paranoia -- No new saved floor */
1120 /* In the dungeon */
1123 /* No floor_id yet */
1127 new_floor_id = get_new_floor_id();
1130 /* Pointer for infomations of new floor */
1131 sf_ptr = get_sf_ptr(new_floor_id);
1133 /* Try to restore old floor */
1134 if (sf_ptr->last_visit)
1136 /* Old saved floor is exist */
1137 if (load_floor(sf_ptr, 0))
1141 /* Forbid return stairs */
1142 if (change_floor_mode & CFM_NO_RETURN)
1144 cave_type *c_ptr = &cave[py][px];
1146 if (!feat_uses_special(c_ptr->feat))
1148 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1150 /* Reset to floor */
1151 c_ptr->feat = floor_type[randint0(100)];
1161 * Set lower/upper_floor_id of new floor when the new
1162 * floor is right-above/right-under the current floor.
1164 * Stair creation/Teleport level/Trap door will take
1165 * you the same floor when you used it later again.
1167 if (p_ptr->floor_id)
1169 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1171 if (change_floor_mode & CFM_UP)
1173 /* New floor is right-above */
1174 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1175 sf_ptr->lower_floor_id = p_ptr->floor_id;
1177 else if (change_floor_mode & CFM_DOWN)
1179 /* New floor is right-under */
1180 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1181 sf_ptr->upper_floor_id = p_ptr->floor_id;
1185 /* Maintain monsters and artifacts */
1189 s32b absence_ticks = (turn - sf_ptr->last_visit) / TURNS_PER_TICK;
1190 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1193 /* Maintain monsters */
1194 for (i = 1; i < m_max; i++)
1196 monster_race *r_ptr;
1197 monster_type *m_ptr = &m_list[i];
1199 /* Skip dead monsters */
1200 if (!m_ptr->r_idx) continue;
1205 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1207 /* Remove timed status (except MTIMED_CSLEEP) */
1208 (void)set_monster_fast(i, 0);
1209 (void)set_monster_slow(i, 0);
1210 (void)set_monster_stunned(i, 0);
1211 (void)set_monster_confused(i, 0);
1212 (void)set_monster_monfear(i, 0);
1213 (void)set_monster_invulner(i, 0, FALSE);
1216 /* Extract real monster race */
1217 r_ptr = real_r_ptr(m_ptr);
1219 /* Ignore non-unique */
1220 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1221 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1223 /* Appear at a different floor? */
1224 if (r_ptr->floor_id != new_floor_id)
1226 /* Disapper from here */
1227 delete_monster_idx(i);
1231 /* Maintain artifatcs */
1232 for (i = 1; i < o_max; i++)
1234 object_type *o_ptr = &o_list[i];
1236 /* Skip dead objects */
1237 if (!o_ptr->k_idx) continue;
1239 /* Ignore non-artifact */
1240 if (!object_is_fixed_artifact(o_ptr)) continue;
1242 /* Appear at a different floor? */
1243 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1245 /* Disappear from here */
1246 delete_object_idx(i);
1250 /* Cancel preserve */
1251 a_info[o_ptr->name1].cur_num = 1;
1255 place_quest_monsters();
1257 /* Place some random monsters */
1258 alloc_times = absence_ticks / alloc_chance;
1260 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1263 for (i = 0; i < alloc_times; i++)
1265 /* Make a (group of) new monster */
1266 (void)alloc_monster(0, 0);
1270 /* New floor_id or failed to restore */
1271 else /* if (!loaded) */
1273 if (sf_ptr->last_visit)
1275 /* Temporal file is broken? */
1277 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1279 msg_print("The staircases come to a dead end...");
1282 /* Create simple dead end */
1285 /* Break connection */
1286 if (change_floor_mode & CFM_UP)
1288 sf_ptr->upper_floor_id = 0;
1290 else if (change_floor_mode & CFM_DOWN)
1292 sf_ptr->lower_floor_id = 0;
1297 /* Newly create cave */
1301 /* Record last visit turn */
1302 sf_ptr->last_visit = turn;
1304 /* Set correct dun_level value */
1305 sf_ptr->dun_level = dun_level;
1307 /* Create connected stairs */
1308 if (!(change_floor_mode & CFM_NO_RETURN))
1310 /* Extract stair position */
1311 cave_type *c_ptr = &cave[py][px];
1313 /*** Create connected stairs ***/
1315 /* No stairs down from Quest */
1316 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1318 if (change_floor_mode & CFM_SHAFT)
1319 c_ptr->feat = FEAT_MORE_MORE;
1321 c_ptr->feat = FEAT_MORE;
1324 /* No stairs up when ironman_downward */
1325 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1327 if (change_floor_mode & CFM_SHAFT)
1328 c_ptr->feat = FEAT_LESS_LESS;
1330 c_ptr->feat = FEAT_LESS;
1333 /* Paranoia -- Clear mimic */
1336 /* Connect to previous floor */
1337 c_ptr->special = p_ptr->floor_id;
1341 /* Arrive at random grid */
1342 if (change_floor_mode & (CFM_RAND_PLACE))
1344 (void)new_player_spot();
1347 /* You see stairs blocked */
1348 else if ((change_floor_mode & CFM_NO_RETURN) &&
1349 (change_floor_mode & (CFM_DOWN | CFM_UP)))
1354 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1356 msg_print("Suddenly the stairs is blocked!");
1362 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1364 msg_print("You hear some noises.");
1372 * The "turn" is not always different number because
1373 * the level teleport doesn't take any turn. Use
1374 * visit mark instead of last visit turn to find the
1375 * oldest saved floor.
1377 sf_ptr->visit_mark = latest_visit_mark++;
1380 /* Place preserved pet monsters */
1383 /* Hack -- maintain unique and artifacts */
1384 update_unique_artifact(new_floor_id);
1386 /* Now the player is in new floor */
1387 p_ptr->floor_id = new_floor_id;
1389 /* The dungeon is ready */
1390 character_dungeon = TRUE;
1392 /* Hack -- Munchkin characters always get whole map */
1393 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1394 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1396 /* Remember when this level was "created" */
1399 /* No dungeon feeling yet */
1400 p_ptr->feeling_turn = old_turn;
1403 /* Clear all flags */
1404 change_floor_mode = 0L;
1410 * Create stairs at or move previously created stairs into the player
1413 void stair_creation(void)
1415 saved_floor_type *sf_ptr;
1416 saved_floor_type *dest_sf_ptr;
1420 s16b dest_floor_id = 0;
1423 /* Forbid up staircases on Ironman mode */
1424 if (ironman_downward) up = FALSE;
1426 /* Forbid down staircases on quest level */
1427 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1429 /* No effect out of standard dungeon floor */
1430 if (!dun_level || (!up && !down) ||
1431 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1432 p_ptr->inside_arena || p_ptr->inside_battle)
1434 /* arena or quest */
1436 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1438 msg_print("There is no effect!");
1443 /* Artifacts resists */
1444 if (!cave_valid_bold(py, px))
1447 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1449 msg_print("The object resists the spell.");
1455 /* Destroy all objects in the grid */
1456 delete_object(py, px);
1458 /* Extract current floor data */
1459 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1464 /* No floor id? -- Create now! */
1465 p_ptr->floor_id = get_new_floor_id();
1466 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1469 /* Choose randomly */
1472 if (randint0(100) < 50) up = FALSE;
1476 /* Destination is already fixed */
1479 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1483 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1487 /* Search old stairs leading to the destination */
1492 for (y = 0; y < cur_hgt; y++)
1494 for (x = 0; x < cur_wid; x++)
1496 cave_type *c_ptr = &cave[y][x];
1498 if (!c_ptr->special) continue;
1499 if (feat_uses_special(c_ptr->feat)) continue;
1500 if (c_ptr->special != dest_floor_id) continue;
1502 /* Remove old stairs */
1504 cave_set_feat(y, x, floor_type[randint0(100)]);
1509 /* No old destination -- Get new one now */
1512 dest_floor_id = get_new_floor_id();
1516 sf_ptr->upper_floor_id = dest_floor_id;
1518 sf_ptr->lower_floor_id = dest_floor_id;
1521 /* Extract destination floor data */
1522 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1525 /* Create a staircase */
1528 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1529 cave_set_feat(py, px, FEAT_LESS_LESS);
1531 cave_set_feat(py, px, FEAT_LESS);
1535 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1536 cave_set_feat(py, px, FEAT_MORE_MORE);
1538 cave_set_feat(py, px, FEAT_MORE);
1542 /* Connect this stairs to the destination */
1543 cave[py][px].special = dest_floor_id;