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(void)
28 char floor_savefile[1024];
36 /* Get "games" permissions */
41 for (i = 0; i < MAX_SAVED_FLOORS; i++)
43 saved_floor_type *sf_ptr = &saved_floors[i];
46 sprintf(floor_savefile, "%s.F%02d", savefile, i);
48 /* Try to create the file */
49 fd = fd_make(floor_savefile, mode);
57 msg_print("¥¨¥é¡¼¡§¸Å¤¤¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£");
58 msg_print("ÊѶòÈÚÅܤòÆó½Å¤Ëµ¯Æ°¤·¤Æ¤¤¤Ê¤¤¤«³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£");
59 msg_print("²áµî¤ËÊѶòÈÚÅܤ¬¥¯¥é¥Ã¥·¥å¤·¤¿¾ì¹ç¤Ï°ì»þ¥Õ¥¡¥¤¥ë¤ò");
60 msg_print("¶¯À©Åª¤Ëºï½ü¤·¤Æ¼Â¹Ô¤ò³¤±¤é¤ì¤Þ¤¹¡£");
61 if (!get_check("¶¯À©Åª¤Ëºï½ü¤·¤Æ¤â¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) quit("¼Â¹ÔÃæ»ß");
63 msg_print("Error: There are old temporal files.");
64 msg_print("Make sure you are not running two game processes simultaneously.");
65 msg_print("If the temporal files are garbages of old crashed process, ");
66 msg_print("you can delete it safely.");
67 if (!get_check("Do you delete old temporal files? ")) quit("Aborted.");
78 /* Simply kill the temporal file */
79 (void)fd_kill(floor_savefile);
84 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
87 /* vist_mark is from 1 */
88 latest_visit_mark = 1;
90 /* A sign to mark temporal files */
91 saved_floor_file_sign = time(NULL);
93 /* No next floor yet */
96 /* No change floor mode yet */
97 change_floor_mode = 0;
101 /* Drop "games" permissions */
109 * Kill temporal files
110 * Should be called just before the game quit
111 * and before new game discarding saved game.
113 void clear_saved_floor_files(void)
115 char floor_savefile[1024];
123 /* Get "games" permissions */
128 for (i = 0; i < MAX_SAVED_FLOORS; i++)
130 saved_floor_type *sf_ptr = &saved_floors[i];
132 /* No temporal file */
133 if (!sf_ptr->floor_id) continue;
134 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
137 sprintf(floor_savefile, "%s.F%02d", savefile, i);
139 /* Simply kill the temporal file */
140 (void)fd_kill(floor_savefile);
145 /* Drop "games" permissions */
153 * Get a pointer for an item of the saved_floors array.
155 saved_floor_type *get_sf_ptr(s16b floor_id)
159 /* floor_id No.0 indicates no floor */
160 if (!floor_id) return NULL;
162 for (i = 0; i < MAX_SAVED_FLOORS; i++)
164 saved_floor_type *sf_ptr = &saved_floors[i];
166 if (sf_ptr->floor_id == floor_id) return sf_ptr;
175 * kill a saved floor and get an empty space
177 static void kill_saved_floor(saved_floor_type *sf_ptr)
179 char floor_savefile[1024];
182 if (!sf_ptr->floor_id) return;
184 if (sf_ptr->floor_id == p_ptr->floor_id)
186 /* Kill current floor */
189 /* Current floor doesn't have temporal file */
194 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
196 /* Simply kill the temporal file */
197 (void)fd_kill(floor_savefile);
200 /* No longer exists */
201 sf_ptr->floor_id = 0;
206 * Initialize new saved floor and get its floor id. If number of
207 * saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
209 s16b get_new_floor_id(void)
211 saved_floor_type *sf_ptr;
214 /* Look for empty space */
215 for (i = 0; i < MAX_SAVED_FLOORS; i++)
217 sf_ptr = &saved_floors[i];
219 if (!sf_ptr->floor_id) break;
223 if (i == MAX_SAVED_FLOORS)
226 u32b oldest_visit = 0xffffffffL;
228 /* Search for oldest */
229 for (i = 0; i < MAX_SAVED_FLOORS; i++)
231 sf_ptr = &saved_floors[i];
233 /* Don't kill current floor */
234 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
236 /* Don't kill newer */
237 if (sf_ptr->visit_mark > oldest_visit) continue;
240 oldest_visit = sf_ptr->visit_mark;
243 /* Kill oldest saved floor */
244 sf_ptr = &saved_floors[oldest];
245 kill_saved_floor(sf_ptr);
251 /* Prepare new floor data */
252 sf_ptr->savefile_id = i;
253 sf_ptr->floor_id = max_floor_id;
254 sf_ptr->last_visit = 0;
255 sf_ptr->upper_floor_id = 0;
256 sf_ptr->lower_floor_id = 0;
257 sf_ptr->visit_mark = latest_visit_mark++;
259 /* sf_ptr->dun_level is not yet decided */
262 /* Increment number of floor_id */
263 if (max_floor_id < MAX_SHORT) max_floor_id++;
265 /* 32767 floor_ids are all used up! Re-use ancient IDs */
266 else max_floor_id = 1;
268 return sf_ptr->floor_id;
273 * Prepare mode flags of changing floor
275 void prepare_change_floor_mode(u32b mode)
277 change_floor_mode |= mode;
282 * Builds the dead end
284 static void build_dead_end(void)
288 /* Clear and empty the cave */
292 cur_hgt = SCREEN_HGT;
293 cur_wid = SCREEN_WID;
295 /* Filled with permanent walls */
296 for (y = 0; y < MAX_HGT; y++)
298 for (x = 0; x < MAX_WID; x++)
300 /* Create "solid" perma-wall */
301 cave[y][x].feat = FEAT_PERM_SOLID;
305 /* Place at center of the floor */
309 /* Give one square */
310 place_floor_bold(py, px);
317 static void preserve_pet(void)
321 for(num = 0; num < 21; num++)
323 party_mon[num].r_idx = 0;
328 COPY(&party_mon[0], &m_list[p_ptr->riding], monster_type);
330 /* Delete from this floor */
331 delete_monster_idx(p_ptr->riding);
334 for(i = m_max - 1, num = 1; (i >= 1 && num < 21); i--)
336 monster_type *m_ptr = &m_list[i];
338 if (!m_ptr->r_idx) continue;
339 if (!is_pet(m_ptr)) continue;
340 if (i == p_ptr->riding) continue;
342 if (reinit_wilderness)
344 /* Don't lose sight of pets when getting a Quest */
348 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
351 * Pets with nickname will follow even from 3 blocks away
352 * when you or the pet can see the other.
354 if (m_ptr->nickname &&
355 (player_has_los_bold(m_ptr->fy, m_ptr->fx) ||
356 los(m_ptr->fy, m_ptr->fx, py, px)))
358 if (dis > 3) continue;
362 if (dis > 1) continue;
364 if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
367 COPY(&party_mon[num], &m_list[i], monster_type);
370 /* Delete from this floor */
371 delete_monster_idx(i);
374 if (record_named_pet)
376 for (i = m_max - 1; i >=1; i--)
378 monster_type *m_ptr = &m_list[i];
381 if (!m_ptr->r_idx) continue;
382 if (!is_pet(m_ptr)) continue;
383 if (!m_ptr->nickname) continue;
384 if (p_ptr->riding == i) continue;
386 monster_desc(m_name, m_ptr, 0x88);
387 do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
394 * Place preserved pet monsters on new floor
396 static void place_pet(void)
400 if (p_ptr->wild_mode)
405 for (i = 0; i < max_num; i++)
409 if (!(party_mon[i].r_idx)) continue;
415 p_ptr->riding = m_idx;
426 for(d = 1; d < 6; d++)
428 for(j = 1000; j > 0; j--)
430 scatter(&cy, &cx, py, px, d, 0);
431 if ((cave_floor_bold(cy, cx) || (cave[cy][cx].feat == FEAT_TREES)) && !cave[cy][cx].m_idx && !((cy == py) && (cx == px))) break;
435 if (d == 6 || p_ptr->inside_arena || p_ptr->inside_battle)
443 monster_type *m_ptr = &m_list[m_idx];
446 cave[cy][cx].m_idx = m_idx;
448 m_ptr->r_idx = party_mon[i].r_idx;
449 r_ptr = &r_info[m_ptr->r_idx];
451 /* Copy all member of the structure */
452 *m_ptr = party_mon[i];
460 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
462 /* Monster is still being nice */
463 m_ptr->mflag |= (MFLAG_NICE);
465 /* Must repair monsters */
466 repair_monsters = TRUE;
469 /* Update the monster */
470 update_mon(m_idx, TRUE);
475 /* Hack -- Count the number of "reproducers" */
476 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
478 /* Hack -- Notice new multi-hued monsters */
479 if (r_ptr->flags1 & RF1_ATTR_MULTI) shimmer_monsters = TRUE;
485 monster_desc(m_name, &party_mon[i], 0);
487 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
489 msg_format("You have lost sight of %s.", m_name);
491 if (record_named_pet && party_mon[i].nickname)
493 monster_desc(m_name, &party_mon[i], 0x08);
494 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
502 * Maintain unique monsters and artifatcs, mark next floor_id at
503 * stairs, save current floor, and prepare to enter next floor.
505 void leave_floor(void)
507 cave_type *c_ptr = NULL;
508 saved_floor_type *sf_ptr;
512 /* Preserve pets and prepare to take these to next floor */
515 /* New floor is not yet prepared */
519 /* From somewhere of the surface to somewhere of the surface */
522 /* No need to save current floor */
526 /* Search the quest monster index */
527 for (i = 0; i < max_quests; i++)
529 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
530 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
531 (quest[i].type == QUEST_TYPE_RANDOM)) &&
532 (quest[i].level == dun_level) &&
533 (dungeon_type == quest[i].dungeon) &&
534 !(quest[i].flags & QUEST_FLAG_PRESET))
536 quest_r_idx = quest[i].r_idx;
540 /* Maintain unique monsters and quest monsters */
541 for (i = 1; i < m_max; i++)
544 monster_type *m_ptr = &m_list[i];
546 /* Skip dead monsters */
547 if (!m_ptr->r_idx) continue;
549 /* Extract real monster race */
550 r_ptr = &r_info[m_ptr->r_idx];
551 if (m_ptr->mflag2 & MFLAG_CHAMELEON)
553 if (r_ptr->flags1 & RF1_UNIQUE)
554 r_ptr = &r_info[MON_CHAMELEON_K];
556 r_ptr = &r_info[MON_CHAMELEON];
559 /* Memorize location of unique */
560 if ((r_ptr->flags1 & RF1_UNIQUE) ||
561 (r_ptr->flags7 & RF7_UNIQUE_7))
563 r_ptr->floor_id = p_ptr->floor_id;
566 else if (quest_r_idx == m_ptr->r_idx)
568 /* Delete non-unique quest monsters */
569 delete_monster_idx(i);
573 /* Maintain artifatcs */
574 for (i = 1; i < o_max; i++)
576 object_type *o_ptr = &o_list[i];
578 /* Skip dead objects */
579 if (!o_ptr->k_idx) continue;
581 /* Memorize location of the artifact */
582 if (artifact_p(o_ptr))
584 a_info[o_ptr->name1].floor_id = p_ptr->floor_id;
588 /* Check if there is a same item */
589 for (i = 0; i < INVEN_PACK; i++)
591 object_type *o_ptr = &inventory[i];
593 /* Skip dead objects */
594 if (!o_ptr->k_idx) continue;
596 /* Delete old memorized location of the artifact */
597 if (artifact_p(o_ptr))
599 a_info[o_ptr->name1].floor_id = 0;
603 /* Extract current floor info or NULL */
604 sf_ptr = get_sf_ptr(p_ptr->floor_id);
606 /* Choose random stairs */
607 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
609 int x, y, sx = 0, sy = 0;
615 /* Search usable stairs */
616 for (y = 0; y < cur_hgt; y++)
618 for (x = 0; x < cur_wid; x++)
620 cave_type *c_ptr = &cave[y][x];
623 if (change_floor_mode & CFM_UP)
625 /* Found fixed stairs */
626 if (c_ptr->special &&
627 c_ptr->special == sf_ptr->upper_floor_id)
633 if (c_ptr->feat == FEAT_LESS ||
634 c_ptr->feat == FEAT_LESS_LESS)
637 else if (change_floor_mode & CFM_DOWN)
639 /* Found fixed stairs */
640 if (c_ptr->special &&
641 c_ptr->special == sf_ptr->lower_floor_id)
647 if (c_ptr->feat == FEAT_MORE ||
648 c_ptr->feat == FEAT_MORE_MORE)
669 /* No stairs found! -- No return */
670 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
672 /* Mega Hack -- It's not the stairs you enter. Disable it. */
673 cave[py][px].special = 0;
677 /* Choose random one */
680 /* Point stair location */
686 /* Extract new dungeon level */
687 if (!(change_floor_mode & CFM_CLEAR_ALL))
691 /* Extract stair position */
692 c_ptr = &cave[py][px];
694 /* Get back to old saved floor? */
695 if (dun_level && c_ptr->special && get_sf_ptr(c_ptr->special))
697 /* Saved floor is exist. Use it. */
698 new_floor_id = c_ptr->special;
701 /* Extract level movement number */
702 if (change_floor_mode & CFM_DOWN)
706 move_num = d_info[c_ptr->special].mindepth;
708 else if (change_floor_mode & CFM_UP)
711 if (dun_level + move_num < d_info[dungeon_type].mindepth)
712 move_num = -dun_level;
715 /* Mark shaft up/down */
716 if (c_ptr->feat == FEAT_LESS_LESS ||
717 c_ptr->feat == FEAT_MORE_MORE)
719 prepare_change_floor_mode(CFM_SHAFT);
720 move_num += SGN(move_num);
723 dun_level += move_num;
726 /* Leaving the dungeon to town */
727 if (!dun_level && dungeon_type)
729 p_ptr->leaving_dungeon = TRUE;
730 if (!vanilla_town && !lite_town)
732 p_ptr->wilderness_y = d_info[dungeon_type].dy;
733 p_ptr->wilderness_x = d_info[dungeon_type].dx;
735 p_ptr->recall_dungeon = dungeon_type;
738 /* Reach to the surface -- Clear all saved floors */
739 prepare_change_floor_mode(CFM_CLEAR_ALL);
742 if (change_floor_mode & CFM_CLEAR_ALL)
746 /* Kill all saved floors */
747 for (i = 0; i < MAX_SAVED_FLOORS; i++)
748 kill_saved_floor(&saved_floors[i]);
750 /* Reset visit_mark count */
751 latest_visit_mark = 1;
753 else if (change_floor_mode & CFM_NO_RETURN)
755 /* Kill current floor */
756 kill_saved_floor(sf_ptr);
759 /* No current floor -- Left/Enter dungeon etc... */
760 if (!p_ptr->floor_id)
762 /* No longer need to save current floor */
767 /* Mark next floor_id on the previous floor */
771 new_floor_id = get_new_floor_id();
773 /* Connect from here */
776 c_ptr->special = new_floor_id;
779 /* Record new dungeon level */
780 get_sf_ptr(new_floor_id)->dun_level = dun_level;
783 /* Fix connection -- level teleportation or trap door */
784 if (change_floor_mode & CFM_RAND_CONNECT)
786 if (change_floor_mode & CFM_UP)
787 sf_ptr->upper_floor_id = new_floor_id;
788 else if (change_floor_mode & CFM_DOWN)
789 sf_ptr->lower_floor_id = new_floor_id;
792 /* If you can return, you need to save previous floor */
793 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)))
795 /* Record the last visit turn of current floor */
796 sf_ptr->last_visit = turn;
798 /* Forget the lite */
801 /* Forget the view */
804 /* Forget the view */
807 /* Save current floor */
808 if (!save_floor(sf_ptr, 0))
810 /* Save failed -- No return */
811 prepare_change_floor_mode(CFM_NO_RETURN);
813 /* Kill current floor */
814 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
821 * Enter new floor. If the floor is an old saved floor, it will be
822 * restored from the temporal file. If the floor is new one, new cave
825 void change_floor(void)
827 saved_floor_type *sf_ptr;
830 /* The dungeon is not ready */
831 character_dungeon = FALSE;
833 /* No longer in the trap detecteded region */
834 p_ptr->dtrap = FALSE;
836 /* Mega-Hack -- no panel yet */
842 /* Mega-Hack -- not ambushed on the wildness? */
858 /* No floor_id yet */
862 new_floor_id = get_new_floor_id();
865 /* Pointer for infomations of new floor */
866 sf_ptr = get_sf_ptr(new_floor_id);
868 /* Try to restore old floor */
869 if (sf_ptr->last_visit)
871 /* Old saved floor is exist */
872 if (load_floor(sf_ptr, 0))
876 /* Forbid return stairs */
877 if (change_floor_mode & CFM_NO_RETURN)
879 cave_type *c_ptr = &cave[py][px];
882 place_floor_grid(c_ptr);
889 * Next floor is right-above/right-under the current floor.
891 * Stair creation/Teleport level/Trap door will take
892 * you the same floor when you used it later again.
896 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
898 if (change_floor_mode & CFM_UP)
900 if (cur_sf_ptr->upper_floor_id == new_floor_id)
901 sf_ptr->lower_floor_id = p_ptr->floor_id;
903 else if (change_floor_mode & CFM_DOWN)
905 if (cur_sf_ptr->lower_floor_id == new_floor_id)
906 sf_ptr->upper_floor_id = p_ptr->floor_id;
910 /* Maintain monsters and artifacts */
914 s32b absence_ticks = (turn - sf_ptr->last_visit) / TURNS_PER_TICK;
915 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
918 /* Maintain monsters */
919 for (i = 1; i < m_max; i++)
922 monster_type *m_ptr = &m_list[i];
924 /* Skip dead monsters */
925 if (!m_ptr->r_idx) continue;
930 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
935 /* Remove invulnerability */
938 /* Remove fast status */
941 /* Remove slow status */
950 /* Remove confusion */
954 /* Extract real monster race */
955 r_ptr = &r_info[m_ptr->r_idx];
956 if (m_ptr->mflag2 & MFLAG_CHAMELEON)
958 if (r_ptr->flags1 & RF1_UNIQUE)
959 r_ptr = &r_info[MON_CHAMELEON_K];
961 r_ptr = &r_info[MON_CHAMELEON];
964 /* Ignore non-unique */
965 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
966 !(r_ptr->flags7 & RF7_UNIQUE_7)) continue;
968 /* Appear at a different floor? */
969 if (r_ptr->floor_id != new_floor_id)
971 /* Disapper from here */
972 delete_monster_idx(i);
976 /* Maintain artifatcs */
977 for (i = 1; i < o_max; i++)
979 object_type *o_ptr = &o_list[i];
981 /* Skip dead objects */
982 if (!o_ptr->k_idx) continue;
984 /* Ignore non-artifact */
985 if (!artifact_p(o_ptr)) continue;
987 /* Appear at a different floor? */
988 if (a_info[o_ptr->name1].floor_id != new_floor_id)
990 /* Disappear from here */
991 delete_object_idx(i);
995 /* Cancel preserve */
996 a_info[o_ptr->name1].cur_num = 1;
1000 place_quest_monsters();
1002 /* Place some random monsters */
1003 alloc_times = absence_ticks / alloc_chance;
1005 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1008 for (i = 0; i < alloc_times; i++)
1010 /* Make a (group of) new monster */
1011 (void)alloc_monster(0, 0);
1015 /* New floor_id or failed to restore */
1016 else /* if (!loaded) */
1018 if (sf_ptr->last_visit)
1020 /* Temporal file is broken? */
1022 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1024 msg_print("The staircases come to a dead end...");
1027 /* Create simple dead end */
1030 /* Break connection */
1031 if (change_floor_mode & CFM_UP)
1033 sf_ptr->upper_floor_id = 0;
1035 else if (change_floor_mode & CFM_DOWN)
1037 sf_ptr->lower_floor_id = 0;
1042 /* Newly create cave */
1046 /* Record last visit turn */
1047 sf_ptr->last_visit = turn;
1049 /* Set correct dun_level value */
1050 sf_ptr->dun_level = dun_level;
1052 /* Creat connected stairs */
1053 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)) && dun_level)
1057 /* Extract stair position */
1058 cave_type *c_ptr = &cave[py][px];
1060 /*** Create connected stairs ***/
1062 /* No stairs down from Quest */
1063 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1065 if (change_floor_mode & CFM_SHAFT)
1066 c_ptr->feat = FEAT_MORE_MORE;
1068 c_ptr->feat = FEAT_MORE;
1071 /* No stairs up when ironman_downward */
1072 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1074 if (change_floor_mode & CFM_SHAFT)
1075 c_ptr->feat = FEAT_LESS_LESS;
1077 c_ptr->feat = FEAT_LESS;
1087 /* Paranoia -- Clear mimic */
1090 /* Connect to previous floor */
1091 c_ptr->special = p_ptr->floor_id;
1096 /* Arrive at random grid */
1097 if (change_floor_mode & (CFM_RAND_PLACE))
1099 (void)new_player_spot();
1102 /* You see stairs blocked */
1103 else if (change_floor_mode & CFM_NO_RETURN)
1108 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1110 msg_print("Suddenly the stairs is blocked!");
1116 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1118 msg_print("You hear some noises.");
1126 * The "turn" is not always different number because
1127 * the level teleport doesn't take any turn. Use
1128 * visit mark instead of last visit turn to find the
1129 * oldest saved floor.
1131 sf_ptr->visit_mark = latest_visit_mark++;
1134 /* Place preserved pet monsters */
1137 /* Now the player is in new floor */
1138 p_ptr->floor_id = new_floor_id;
1140 /* The dungeon is ready */
1141 character_dungeon = TRUE;
1143 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1144 wiz_lite(TRUE, (bool)(p_ptr->pclass == CLASS_NINJA));
1146 /* Remember when this level was "created" */
1149 /* Clear all flags */
1150 change_floor_mode = 0L;
1156 * Create stairs at or move previously created stairs into the player
1159 void stair_creation(void)
1161 saved_floor_type *sf_ptr;
1162 saved_floor_type *dest_sf_ptr;
1166 s16b dest_floor_id = 0;
1170 /* Forbid up staircases on Ironman mode */
1171 if (ironman_downward) up = FALSE;
1173 /* Forbid down staircases on quest level */
1174 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1176 /* No effect out of standard dungeon floor */
1177 if (!dun_level || (!up && !down) ||
1178 (p_ptr->inside_quest && (p_ptr->inside_quest < MIN_RANDOM_QUEST)) ||
1179 p_ptr->inside_arena || p_ptr->inside_battle)
1181 /* arena or quest */
1183 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1185 msg_print("There is no effect!");
1190 /* Artifacts resists */
1191 if (!cave_valid_bold(py, px))
1194 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1196 msg_print("The object resists the spell.");
1202 /* Destroy all objects in the grid */
1203 delete_object(py, px);
1205 /* Extract current floor data */
1206 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1208 /* Choose randomly */
1211 if (randint0(100) < 50) up = FALSE;
1215 /* Destination is already fixed */
1218 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1222 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1226 /* Search old stairs leading to the destination */
1231 for (y = 0; y < cur_hgt; y++)
1233 for (x = 0; x < cur_wid; x++)
1235 cave_type *c_ptr = &cave[y][x];
1238 if (!c_ptr->special) continue;
1239 if (c_ptr->special != dest_floor_id) continue;
1241 /* Remove old stairs */
1243 cave_set_feat(y, x, floor_type[randint0(100)]);
1248 /* No old destination -- Get new one now */
1251 dest_floor_id = get_new_floor_id();
1255 sf_ptr->upper_floor_id = dest_floor_id;
1257 sf_ptr->lower_floor_id = dest_floor_id;
1260 /* Extract destination floor data */
1261 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1264 /* Create a staircase */
1267 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1268 cave_set_feat(py, px, FEAT_LESS_LESS);
1270 cave_set_feat(py, px, FEAT_LESS);
1274 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1275 cave_set_feat(py, px, FEAT_MORE_MORE);
1277 cave_set_feat(py, px, FEAT_MORE);
1281 /* Connect this stairs to the destination */
1282 cave[py][px].special = dest_floor_id;