OSDN Git Service

闘技場で敗れた時、保存フロアを消去してペットを失なっていたので修正。
[hengband/hengband.git] / src / floors.c
1 /* File: floors.c */
2
3 /* Purpose: management of the saved floor */
4
5 /*
6  * Copyright (c) 2002  Mogami
7  *
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.
11  */
12
13 #include "angband.h"
14 #include "grid.h"
15
16
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 */
20
21
22 /*
23  * Initialize saved_floors array.  Make sure that old temporal files
24  * are not remaining as gurbages.
25  */
26 void init_saved_floors(bool force)
27 {
28         char floor_savefile[1024];
29         int i;
30         int fd = -1;
31         int mode = 0644;
32
33 #ifdef SET_UID
34 # ifdef SECURE
35         /* Get "games" permissions */
36         beGames();
37 # endif
38 #endif
39
40         for (i = 0; i < MAX_SAVED_FLOORS; i++)
41         {
42                 saved_floor_type *sf_ptr = &saved_floors[i];
43
44                 /* File name */
45                 sprintf(floor_savefile, "%s.F%02d", savefile, i);
46
47                 /* Grab permissions */
48                 safe_setuid_grab();
49
50                 /* Try to create the file */
51                 fd = fd_make(floor_savefile, mode);
52
53                 /* Drop permissions */
54                 safe_setuid_drop();
55
56                 /* Failed! */
57                 if (fd < 0)
58                 {
59                         if (!force)
60                         {
61 #ifdef JP
62                                 msg_print("¥¨¥é¡¼¡§¸Å¤¤¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£");
63                                 msg_print("ÊѶòÈÚÅܤòÆó½Å¤Ëµ¯Æ°¤·¤Æ¤¤¤Ê¤¤¤«³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£");
64                                 msg_print("²áµî¤ËÊѶòÈÚÅܤ¬¥¯¥é¥Ã¥·¥å¤·¤¿¾ì¹ç¤Ï°ì»þ¥Õ¥¡¥¤¥ë¤ò");
65                                 msg_print("¶¯À©Åª¤Ëºï½ü¤·¤Æ¼Â¹Ô¤ò³¤±¤é¤ì¤Þ¤¹¡£");
66                                 if (!get_check("¶¯À©Åª¤Ëºï½ü¤·¤Æ¤â¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) quit("¼Â¹ÔÃæ»ß");
67 #else
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.");
73 #endif
74                                 force = TRUE;
75                         }
76                 }
77                 else
78                 {
79                         /* Close the "fd" */
80                         (void)fd_close(fd);
81                 }
82
83                 /* Grab permissions */
84                 safe_setuid_grab();
85
86                 /* Simply kill the temporal file */ 
87                 (void)fd_kill(floor_savefile);
88
89                 /* Drop permissions */
90                 safe_setuid_drop();
91
92                 sf_ptr->floor_id = 0;
93         }
94
95         /* No floor_id used yet (No.0 is reserved to indicate non existance) */
96         max_floor_id = 1;
97
98         /* vist_mark is from 1 */
99         latest_visit_mark = 1;
100
101         /* A sign to mark temporal files */
102         saved_floor_file_sign = time(NULL);
103
104         /* No next floor yet */
105         new_floor_id = 0;
106
107         /* No change floor mode yet */
108         change_floor_mode = 0;
109
110 #ifdef SET_UID
111 # ifdef SECURE
112         /* Drop "games" permissions */
113         bePlayer();
114 # endif
115 #endif
116 }
117
118
119 /*
120  * Kill temporal files
121  * Should be called just before the game quit.
122  */
123 void clear_saved_floor_files(void)
124 {
125         char floor_savefile[1024];
126         int i;
127
128 #ifdef SET_UID
129 # ifdef SECURE
130         /* Get "games" permissions */
131         beGames();
132 # endif
133 #endif
134
135         for (i = 0; i < MAX_SAVED_FLOORS; i++)
136         {
137                 saved_floor_type *sf_ptr = &saved_floors[i];
138
139                 /* No temporal file */
140                 if (!sf_ptr->floor_id) continue;
141                 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
142
143                 /* File name */
144                 sprintf(floor_savefile, "%s.F%02d", savefile, i);
145
146                 /* Grab permissions */
147                 safe_setuid_grab();
148
149                 /* Simply kill the temporal file */ 
150                 (void)fd_kill(floor_savefile);
151
152                 /* Drop permissions */
153                 safe_setuid_drop();
154         }
155
156 #ifdef SET_UID
157 # ifdef SECURE
158         /* Drop "games" permissions */
159         bePlayer();
160 # endif
161 #endif
162 }
163
164
165 /*
166  * Get a pointer for an item of the saved_floors array.
167  */
168 saved_floor_type *get_sf_ptr(s16b floor_id)
169 {
170         int i;
171
172         /* floor_id No.0 indicates no floor */
173         if (!floor_id) return NULL;
174
175         for (i = 0; i < MAX_SAVED_FLOORS; i++)
176         {
177                 saved_floor_type *sf_ptr = &saved_floors[i];
178
179                 if (sf_ptr->floor_id == floor_id) return sf_ptr;
180         }
181
182         /* None found */
183         return NULL;
184 }
185
186
187 /*
188  * kill a saved floor and get an empty space
189  */
190 static void kill_saved_floor(saved_floor_type *sf_ptr)
191 {
192         char floor_savefile[1024];
193
194         /* Already empty */
195         if (!sf_ptr->floor_id) return;
196
197         if (sf_ptr->floor_id == p_ptr->floor_id)
198         {
199                 /* Kill current floor */
200                 p_ptr->floor_id = 0;
201
202                 /* Current floor doesn't have temporal file */
203         }
204         else 
205         {
206                 /* File name */
207                 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
208
209                 /* Grab permissions */
210                 safe_setuid_grab();
211
212                 /* Simply kill the temporal file */ 
213                 (void)fd_kill(floor_savefile);
214
215                 /* Drop permissions */
216                 safe_setuid_drop();
217         }
218
219         /* No longer exists */
220         sf_ptr->floor_id = 0;
221 }
222
223
224 /*
225  * Initialize new saved floor and get its floor id.  If number of
226  * saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
227  */
228 s16b get_new_floor_id(void)
229 {
230         saved_floor_type *sf_ptr;
231         int i;
232
233         /* Look for empty space */
234         for (i = 0; i < MAX_SAVED_FLOORS; i++)
235         {
236                 sf_ptr = &saved_floors[i];
237
238                 if (!sf_ptr->floor_id) break;
239         }
240
241         /* None found */
242         if (i == MAX_SAVED_FLOORS)
243         {
244                 int oldest = 0;
245                 u32b oldest_visit = 0xffffffffL;
246
247                 /* Search for oldest */
248                 for (i = 0; i < MAX_SAVED_FLOORS; i++)
249                 {
250                         sf_ptr = &saved_floors[i];
251
252                         /* Don't kill current floor */
253                         if (sf_ptr->floor_id == p_ptr->floor_id) continue;
254
255                         /* Don't kill newer */
256                         if (sf_ptr->visit_mark > oldest_visit) continue;
257
258                         oldest = i;
259                         oldest_visit = sf_ptr->visit_mark;
260                 }
261
262                 /* Kill oldest saved floor */
263                 sf_ptr = &saved_floors[oldest];
264                 kill_saved_floor(sf_ptr);
265
266                 /* Use it */
267                 i = oldest;
268         }
269
270         /* Prepare new floor data */
271         sf_ptr->savefile_id = i;
272         sf_ptr->floor_id = max_floor_id;
273         sf_ptr->last_visit = 0;
274         sf_ptr->upper_floor_id = 0;
275         sf_ptr->lower_floor_id = 0;
276         sf_ptr->visit_mark = latest_visit_mark++;
277
278         /* sf_ptr->dun_level is not yet decided */
279
280
281         /* Increment number of floor_id */
282         if (max_floor_id < MAX_SHORT) max_floor_id++;
283
284         /* 32767 floor_ids are all used up!  Re-use ancient IDs */
285         else max_floor_id = 1;
286
287         return sf_ptr->floor_id;
288 }
289
290
291 /*
292  * Prepare mode flags of changing floor
293  */
294 void prepare_change_floor_mode(u32b mode)
295 {
296         change_floor_mode |= mode;
297 }
298
299
300 /*
301  * Builds the dead end
302  */
303 static void build_dead_end(void)
304 {
305         int x,y;
306
307         /* Clear and empty the cave */
308         clear_cave();
309
310         /* Fill the arrays of floors and walls in the good proportions */
311         set_floor_and_wall(0);
312
313         /* Smallest area */
314         cur_hgt = SCREEN_HGT;
315         cur_wid = SCREEN_WID;
316
317         /* Filled with permanent walls */
318         for (y = 0; y < MAX_HGT; y++)
319         {
320                 for (x = 0; x < MAX_WID; x++)
321                 {
322                         /* Create "solid" perma-wall */
323                         cave[y][x].feat = FEAT_PERM_SOLID;
324                 }
325         }
326
327         /* Place at center of the floor */
328         py = cur_hgt / 2;
329         px = cur_wid / 2;
330
331         /* Give one square */
332         place_floor_bold(py, px);
333 }
334
335
336 /*
337  * Preserve_pets
338  */
339 static void preserve_pet(void)
340 {
341         int num, i;
342
343         for (num = 0; num < MAX_PARTY_MON; num++)
344         {
345                 party_mon[num].r_idx = 0;
346         }
347
348         if (p_ptr->riding)
349         {
350                 monster_type *m_ptr = &m_list[p_ptr->riding];
351
352                 /* Pet of other pet don't follow. */
353                 if (m_ptr->parent_m_idx)
354                 {
355                         p_ptr->riding = 0;
356                         p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
357                         p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
358                 }
359                 else
360                 {
361                         /* Preserve the mount */
362                         COPY(&party_mon[0], m_ptr, monster_type);
363
364                         /* Delete from this floor */
365                         delete_monster_idx(p_ptr->riding);
366                 }
367         }
368
369         /*
370          * If player is in wild mode, no pets are preserved
371          * except a monster whom player riding
372          */
373         if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
374         {
375                 for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
376                 {
377                         monster_type *m_ptr = &m_list[i];
378
379                         if (!m_ptr->r_idx) continue;
380                         if (!is_pet(m_ptr)) continue;
381                         if (i == p_ptr->riding) continue;
382
383                         if (reinit_wilderness)
384                         {
385                                 /* Don't lose sight of pets when getting a Quest */
386                         }
387                         else
388                         {
389                                 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
390
391                                 /* Confused (etc.) monsters don't follow. */
392                                 if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
393
394                                 /* Pet of other pet don't follow. */
395                                 if (m_ptr->parent_m_idx) continue;
396
397                                 /*
398                                  * Pets with nickname will follow even from 3 blocks away
399                                  * when you or the pet can see the other.
400                                  */
401                                 if (m_ptr->nickname && 
402                                     (player_has_los_bold(m_ptr->fy, m_ptr->fx) ||
403                                      los(m_ptr->fy, m_ptr->fx, py, px)))
404                                 {
405                                         if (dis > 3) continue;
406                                 }
407                                 else
408                                 {
409                                         if (dis > 1) continue;
410                                 }
411                         }
412
413                         COPY(&party_mon[num], &m_list[i], monster_type);
414
415                         num++;
416
417                         /* Delete from this floor */
418                         delete_monster_idx(i);
419                 }
420         }
421
422         if (record_named_pet)
423         {
424                 for (i = m_max - 1; i >=1; i--)
425                 {
426                         monster_type *m_ptr = &m_list[i];
427                         char m_name[80];
428
429                         if (!m_ptr->r_idx) continue;
430                         if (!is_pet(m_ptr)) continue;
431                         if (!m_ptr->nickname) continue;
432                         if (p_ptr->riding == i) continue;
433
434                         monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
435                         do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
436                 }
437         }
438
439
440         /* Pet of other pet may disappear. */
441         for (i = m_max - 1; i >=1; i--)
442         {
443                 monster_type *m_ptr = &m_list[i];
444
445                 /* Are there its parent? */
446                 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
447                 {
448                         /* Its parent have gone, it also goes away. */
449
450                         if (m_ptr->ml)
451                         {
452                                 char m_name[80];
453                         
454                                 /* Acquire the monster name */
455                                 monster_desc(m_name, m_ptr, 0);
456
457 #ifdef JP
458                                 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
459 #else
460                                 msg_format("%^s disappears!", m_name);
461 #endif
462                         }
463
464                         /* Delete the monster */
465                         delete_monster_idx(i);
466                 }
467         }
468 }
469
470
471 /*
472  * Pre-calculate the racial counters of preserved pets
473  * To prevent multiple generation of unique monster who is the minion of player
474  */
475 void precalc_cur_num_of_pet(void)
476 {
477         monster_type *m_ptr;
478         int i;
479         int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
480
481         for (i = 0; i < max_num; i++)
482         {
483                 m_ptr = &party_mon[i];
484
485                 /* Skip empty monsters */
486                 if (!m_ptr->r_idx) continue;
487
488                 /* Hack -- Increase the racial counter */
489                 real_r_ptr(m_ptr)->cur_num++;
490         }
491 }
492
493
494 /*
495  * Place preserved pet monsters on new floor
496  */
497 static void place_pet(void)
498 {
499         int i;
500         int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
501
502         for (i = 0; i < max_num; i++)
503         {
504                 int cy, cx, m_idx;
505
506                 if (!(party_mon[i].r_idx)) continue;
507
508                 if (i == 0)
509                 {
510                         m_idx = m_pop();
511                         p_ptr->riding = m_idx;
512                         if (m_idx)
513                         {
514                                 cy = py;
515                                 cx = px;
516                         }
517                 }
518                 else
519                 {
520                         int j, d;
521
522                         for (d = 1; d < 6; d++)
523                         {
524                                 for (j = 1000; j > 0; j--)
525                                 {
526                                         scatter(&cy, &cx, py, px, d, 0);
527                                         if ((cave_floor_bold(cy, cx) || (cave[cy][cx].feat == FEAT_TREES)) && !cave[cy][cx].m_idx && !player_bold(cy, cx)) break;
528                                 }
529                                 if (j) break;
530                         }
531                         m_idx = (d == 6) ? 0 : m_pop();
532                 }
533
534                 if (m_idx)
535                 {
536                         monster_type *m_ptr = &m_list[m_idx];
537                         monster_race *r_ptr;
538
539                         cave[cy][cx].m_idx = m_idx;
540
541                         m_ptr->r_idx = party_mon[i].r_idx;
542
543                         /* Copy all member of the structure */
544                         *m_ptr = party_mon[i];
545                         r_ptr = real_r_ptr(m_ptr);
546
547                         m_ptr->fy = cy;
548                         m_ptr->fx = cx;
549                         m_ptr->ml = TRUE;
550                         m_ptr->csleep = 0;
551
552                         /* Paranoia */
553                         m_ptr->hold_o_idx = 0;
554                         m_ptr->target_y = 0;
555
556                         if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
557                         {
558                                 /* Monster is still being nice */
559                                 m_ptr->mflag |= (MFLAG_NICE);
560
561                                 /* Must repair monsters */
562                                 repair_monsters = TRUE;
563                         }
564
565                         /* Update the monster */
566                         update_mon(m_idx, TRUE);
567                         lite_spot(cy, cx);
568
569                         /* Pre-calculated in precalc_cur_num_of_pet() */
570                         /* r_ptr->cur_num++; */
571
572                         /* Hack -- Count the number of "reproducers" */
573                         if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
574
575                         /* Hack -- Notice new multi-hued monsters */
576                         {
577                                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
578                                 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
579                                         shimmer_monsters = TRUE;
580                         }
581                 }
582                 else
583                 {
584                         monster_type *m_ptr = &party_mon[i];
585                         monster_race *r_ptr = real_r_ptr(m_ptr);
586                         char m_name[80];
587
588                         monster_desc(m_name, m_ptr, 0);
589 #ifdef JP
590                         msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
591 #else
592                         msg_format("You have lost sight of %s.", m_name);
593 #endif
594                         if (record_named_pet && m_ptr->nickname)
595                         {
596                                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
597                                 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
598                         }
599
600                         /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
601                         if (r_ptr->cur_num) r_ptr->cur_num--;
602                 }
603         }
604
605         /* For accuracy of precalc_cur_num_of_pet() */               
606         C_WIPE(party_mon, MAX_PARTY_MON, monster_type);                            
607 }
608
609
610 /*
611  * Hack -- Update location of unique monsters and artifacts
612  *
613  * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly
614  * while new floor creation since dungeons may be re-created by
615  * auto-scum option.
616  */
617 static void update_unique_artifact(s16b cur_floor_id)
618 {
619         int i;
620
621         /* Maintain unique monsters */
622         for (i = 1; i < m_max; i++)
623         {
624                 monster_race *r_ptr;
625                 monster_type *m_ptr = &m_list[i];
626
627                 /* Skip dead monsters */
628                 if (!m_ptr->r_idx) continue;
629
630                 /* Extract real monster race */
631                 r_ptr = real_r_ptr(m_ptr);
632
633                 /* Memorize location of the unique monster */
634                 if ((r_ptr->flags1 & RF1_UNIQUE) ||
635                     (r_ptr->flags7 & RF7_NAZGUL))
636                 {
637                         r_ptr->floor_id = cur_floor_id;
638                 }
639         }
640
641         /* Maintain artifatcs */
642         for (i = 1; i < o_max; i++)
643         {
644                 object_type *o_ptr = &o_list[i];
645
646                 /* Skip dead objects */
647                 if (!o_ptr->k_idx) continue;
648
649                 /* Memorize location of the artifact */
650                 if (artifact_p(o_ptr))
651                 {
652                         a_info[o_ptr->name1].floor_id = cur_floor_id;
653                 }
654         }
655 }
656
657
658 /*
659  * When a monster is at a place where player will return,
660  * Get out of the my way!
661  */
662 static void get_out_monster(void)
663 {
664         int tries = 0;
665         int dis = 1;
666         int oy = py;
667         int ox = px;
668         int m_idx = cave[oy][ox].m_idx;
669
670         /* Nothing to do if no monster */
671         if (!m_idx) return;
672
673         /* Look until done */
674         while (TRUE)
675         {
676                 monster_type *m_ptr;
677
678                 /* Pick a (possibly illegal) location */
679                 int ny = rand_spread(oy, dis);
680                 int nx = rand_spread(ox, dis);
681
682                 tries++;
683
684                 /* Stop after 1000 tries */
685                 if (tries > 10000) return;
686
687                 /*
688                  * Increase distance after doing enough tries
689                  * compared to area of possible space
690                  */
691                 if (tries > 20 * dis * dis) dis++;
692
693                 /* Ignore illegal locations */
694                 if (!in_bounds(ny, nx)) continue;
695
696                 /* Require "empty" floor space */
697                 if (!cave_empty_bold(ny, nx)) continue;
698
699                 /* Hack -- no teleport onto glyph of warding */
700                 if (is_glyph_grid(&cave[ny][nx])) continue;
701                 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
702
703                 /* ...nor onto the Pattern */
704                 if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
705                     (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2)) continue;
706
707                 /*** It's a good place ***/
708
709                 m_ptr = &m_list[m_idx];
710
711                 /* Update the new location */
712                 cave[ny][nx].m_idx = m_idx;
713
714                 /* Update the old location */
715                 cave[oy][ox].m_idx = 0;
716
717                 /* Move the monster */
718                 m_ptr->fy = ny;
719                 m_ptr->fx = nx; 
720
721                 /* No need to do update_mon() */
722
723                 /* Success */
724                 return;
725         }
726 }
727
728
729 /*
730  * Is this feature has special meaning (except floor_id) with c_ptr->special?
731  */
732 static bool feat_uses_special(byte feat)
733 {
734         switch (feat)
735         {
736         case FEAT_QUEST_ENTER:
737         case FEAT_QUEST_EXIT:
738         case FEAT_QUEST_DOWN:
739         case FEAT_QUEST_UP:
740         case FEAT_TOWN:
741         case FEAT_ENTRANCE:
742                 return TRUE;
743         }
744
745         return FALSE;
746 }
747
748
749 /*
750  * Virtually teleport onto the stairs that is connecting between two
751  * floors.
752  *
753  * Teleport level spell and trap doors will always lead the player to
754  * the one of the floors connected by the one of the stairs in the
755  * current floor.
756  */
757 static void locate_connected_stairs(saved_floor_type *sf_ptr)
758 {
759         int x, y, sx = 0, sy = 0;
760         int x_table[20];
761         int y_table[20];
762         int num = 0;
763         int i;
764
765         /* Search usable stairs */
766         for (y = 0; y < cur_hgt; y++)
767         {
768                 for (x = 0; x < cur_wid; x++)
769                 {
770                         cave_type *c_ptr = &cave[y][x];
771                         bool ok = FALSE;
772
773                         if (change_floor_mode & CFM_UP)
774                         {
775                                 if (c_ptr->feat == FEAT_LESS ||
776                                     c_ptr->feat == FEAT_LESS_LESS)
777                                 {
778                                         ok = TRUE;
779
780                                         /* Found fixed stairs? */
781                                         if (c_ptr->special &&
782                                             c_ptr->special == sf_ptr->upper_floor_id)
783                                         {
784                                                 sx = x;
785                                                 sy = y;
786                                         }
787                                 }
788                         }
789
790                         else if (change_floor_mode & CFM_DOWN)
791                         {
792                                 if (c_ptr->feat == FEAT_MORE ||
793                                     c_ptr->feat == FEAT_MORE_MORE)
794                                 {
795                                         ok = TRUE;
796
797                                         /* Found fixed stairs */
798                                         if (c_ptr->special &&
799                                             c_ptr->special == sf_ptr->lower_floor_id)
800                                         {
801                                                 sx = x;
802                                                 sy = y;
803                                         }
804                                 }
805                         }
806
807                         else
808                         {
809                                 if (FEAT_BLDG_HEAD <= c_ptr->feat &&
810                                     c_ptr->feat <= FEAT_BLDG_TAIL)
811                                 {
812                                         ok = TRUE;
813                                 }
814                         }
815
816                         if (ok && num < 20)
817                         {
818                                 x_table[num] = x;
819                                 y_table[num] = y;
820                                 num++;
821                         }
822                 }
823         }
824
825         if (sx)
826         {
827                 /* Already fixed */
828                 py = sy;
829                 px = sx;
830         }
831         else if (!num)
832         {
833                 /* No stairs found! -- No return */
834                 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
835
836                 /* Mega Hack -- It's not the stairs you enter.  Disable it.  */
837                 if (!feat_uses_special(cave[py][px].feat)) cave[py][px].special = 0;
838         }
839         else
840         {
841                 /* Choose random one */
842                 i = randint0(num);
843
844                 /* Point stair location */
845                 py = y_table[i];
846                 px = x_table[i];
847         }
848 }
849
850 /*
851  * Maintain quest monsters, mark next floor_id at stairs, save current
852  * floor, and prepare to enter next floor.
853  */
854 void leave_floor(void)
855 {
856         cave_type *c_ptr = NULL;
857         saved_floor_type *sf_ptr;
858         int quest_r_idx = 0;
859         int i;
860
861         /* Preserve pets and prepare to take these to next floor */
862         preserve_pet();
863
864         /* Remove all mirrors without explosion */
865         remove_all_mirrors(FALSE);
866
867         /* New floor is not yet prepared */
868         new_floor_id = 0;
869
870         /* Temporary get a floor_id (for Arena) */
871         if (!p_ptr->floor_id &&
872             (change_floor_mode & CFM_SAVE_FLOORS) &&
873             !(change_floor_mode & CFM_NO_RETURN))
874         {
875             /* Get temporal floor_id */
876             p_ptr->floor_id = get_new_floor_id();
877             
878             /* Record the dungeon level */
879             get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
880         }
881
882
883         /* Search the quest monster index */
884         for (i = 0; i < max_quests; i++)
885         {
886                 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
887                     ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
888                     (quest[i].type == QUEST_TYPE_RANDOM)) &&
889                     (quest[i].level == dun_level) &&
890                     (dungeon_type == quest[i].dungeon) &&
891                     !(quest[i].flags & QUEST_FLAG_PRESET))
892                 {
893                         quest_r_idx = quest[i].r_idx;
894                 }
895         }
896
897         /* Maintain quest monsters */
898         for (i = 1; i < m_max; i++)
899         {
900                 monster_race *r_ptr;
901                 monster_type *m_ptr = &m_list[i];
902
903                 /* Skip dead monsters */
904                 if (!m_ptr->r_idx) continue;
905
906                 /* Only maintain quest monsters */
907                 if (quest_r_idx != m_ptr->r_idx) continue;
908
909                 /* Extract real monster race */
910                 r_ptr = real_r_ptr(m_ptr);
911
912                 /* Ignore unique monsters */
913                 if ((r_ptr->flags1 & RF1_UNIQUE) ||
914                     (r_ptr->flags7 & RF7_NAZGUL)) continue;
915
916                 /* Delete non-unique quest monsters */
917                 delete_monster_idx(i);
918         }
919
920         /* Check if there is a same item */
921         for (i = 0; i < INVEN_PACK; i++)
922         {
923                 object_type *o_ptr = &inventory[i];
924
925                 /* Skip dead objects */
926                 if (!o_ptr->k_idx) continue;
927
928                 /* Delete old memorized location of the artifact */
929                 if (artifact_p(o_ptr))
930                 {
931                         a_info[o_ptr->name1].floor_id = 0;
932                 }
933         }
934
935         /* Extract current floor info or NULL */
936         sf_ptr = get_sf_ptr(p_ptr->floor_id);
937
938         /* Choose random stairs */
939         if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
940         {
941                 locate_connected_stairs(sf_ptr);
942         }
943
944         /* Extract new dungeon level */
945         if (change_floor_mode & CFM_SAVE_FLOORS)
946         {
947                 /* Extract stair position */
948                 c_ptr = &cave[py][px];
949
950                 /* Get back to old saved floor? */
951                 if (c_ptr->special && !feat_uses_special(c_ptr->feat) && get_sf_ptr(c_ptr->special))
952                 {
953                         /* Saved floor is exist.  Use it. */
954                         new_floor_id = c_ptr->special;
955                 }
956
957                 /* Mark shaft up/down */
958                 if (c_ptr->feat == FEAT_LESS_LESS ||
959                     c_ptr->feat == FEAT_MORE_MORE)
960                 {
961                         prepare_change_floor_mode(CFM_SHAFT);
962                 }
963         }
964
965         /* Climb up/down some sort of stairs */
966         if (change_floor_mode & (CFM_DOWN | CFM_UP))
967         {
968                 int move_num = 0;
969
970                 /* Extract level movement number */
971                 if (change_floor_mode & CFM_DOWN) move_num = 1;
972                 else if (change_floor_mode & CFM_UP) move_num = -1;
973
974                 /* Shafts are deeper than normal stairs */
975                 if (change_floor_mode & CFM_SHAFT)
976                         move_num += SGN(move_num);
977
978                 /* Get out from or Enter the dungeon */
979                 if (change_floor_mode & CFM_DOWN)
980                 {
981                         if (!dun_level)
982                                 move_num = d_info[dungeon_type].mindepth;
983                 }
984                 else if (change_floor_mode & CFM_UP)
985                 {
986                         if (dun_level + move_num < d_info[dungeon_type].mindepth)
987                                 move_num = -dun_level;
988                 }
989
990                 dun_level += move_num;
991         }
992
993         /* Leaving the dungeon to town */
994         if (!dun_level && dungeon_type)
995         {
996                 p_ptr->leaving_dungeon = TRUE;
997                 if (!vanilla_town && !lite_town)
998                 {
999                         p_ptr->wilderness_y = d_info[dungeon_type].dy;
1000                         p_ptr->wilderness_x = d_info[dungeon_type].dx;
1001                 }
1002                 p_ptr->recall_dungeon = dungeon_type;
1003                 dungeon_type = 0;
1004
1005                 /* Reach to the surface -- Clear all saved floors */
1006                 change_floor_mode &= ~CFM_SAVE_FLOORS;
1007         }
1008
1009         /* Kill some old saved floors */
1010         if (!(change_floor_mode & CFM_SAVE_FLOORS))
1011         {
1012                 int i;
1013
1014                 /* Kill all saved floors */
1015                 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1016                         kill_saved_floor(&saved_floors[i]);
1017
1018                 /* Reset visit_mark count */
1019                 latest_visit_mark = 1;
1020         }
1021         else if (change_floor_mode & CFM_NO_RETURN)
1022         {
1023                 /* Kill current floor */
1024                 kill_saved_floor(sf_ptr);
1025         }
1026
1027         /* No current floor -- Left/Enter dungeon etc... */
1028         if (!p_ptr->floor_id)
1029         {
1030                 /* No longer need to save current floor */
1031                 return;
1032         }
1033
1034
1035         /* Mark next floor_id on the previous floor */
1036         if (!new_floor_id)
1037         {
1038                 /* Get new id */
1039                 new_floor_id = get_new_floor_id();
1040
1041                 /* Connect from here */
1042                 if (c_ptr && !feat_uses_special(c_ptr->feat))
1043                 {
1044                         c_ptr->special = new_floor_id;
1045                 }
1046
1047                 /* Record new dungeon level */
1048                 get_sf_ptr(new_floor_id)->dun_level = dun_level;
1049         }
1050
1051         /* Fix connection -- level teleportation or trap door */
1052         if (change_floor_mode & CFM_RAND_CONNECT)
1053         {
1054                 if (change_floor_mode & CFM_UP)
1055                         sf_ptr->upper_floor_id = new_floor_id;
1056                 else if (change_floor_mode & CFM_DOWN)
1057                         sf_ptr->lower_floor_id = new_floor_id;
1058         }
1059
1060         /* If you can return, you need to save previous floor */
1061         if ((change_floor_mode & CFM_SAVE_FLOORS) &&
1062             !(change_floor_mode & CFM_NO_RETURN))
1063         {
1064                 /* Get out of the my way! */
1065                 get_out_monster();
1066
1067                 /* Record the last visit turn of current floor */
1068                 sf_ptr->last_visit = turn;
1069
1070                 /* Forget the lite */
1071                 forget_lite();
1072
1073                 /* Forget the view */
1074                 forget_view();
1075
1076                 /* Forget the view */
1077                 clear_mon_lite();
1078
1079                 /* Save current floor */
1080                 if (!save_floor(sf_ptr, 0))
1081                 {
1082                         /* Save failed -- No return */
1083                         prepare_change_floor_mode(CFM_NO_RETURN);
1084
1085                         /* Kill current floor */
1086                         kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1087                 }
1088         }
1089 }
1090
1091
1092 /*
1093  * Enter new floor.  If the floor is an old saved floor, it will be
1094  * restored from the temporal file.  If the floor is new one, new cave
1095  * will be generated.
1096  */
1097 void change_floor(void)
1098 {
1099         saved_floor_type *sf_ptr;
1100         bool loaded = FALSE;
1101
1102         /* The dungeon is not ready */
1103         character_dungeon = FALSE;
1104
1105         /* No longer in the trap detecteded region */
1106         p_ptr->dtrap = FALSE;
1107
1108         /* Mega-Hack -- no panel yet */
1109         panel_row_min = 0;
1110         panel_row_max = 0;
1111         panel_col_min = 0;
1112         panel_col_max = 0;
1113
1114         /* Mega-Hack -- not ambushed on the wildness? */
1115         ambush_flag = FALSE;
1116
1117         /* No saved floors (On the surface etc.) */
1118         if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
1119             !(change_floor_mode & CFM_FIRST_FLOOR))
1120         {
1121                 /* Create cave */
1122                 generate_cave();
1123
1124                 /* Paranoia -- No new saved floor */
1125                 new_floor_id = 0;
1126         }
1127
1128         /* In the dungeon */
1129         else
1130         {
1131                 /* No floor_id yet */
1132                 if (!new_floor_id)
1133                 {
1134                         /* Get new id */
1135                         new_floor_id = get_new_floor_id();
1136                 }
1137
1138                 /* Pointer for infomations of new floor */
1139                 sf_ptr = get_sf_ptr(new_floor_id);
1140
1141                 /* Try to restore old floor */
1142                 if (sf_ptr->last_visit)
1143                 {
1144                         /* Old saved floor is exist */
1145                         if (load_floor(sf_ptr, 0))
1146                         {
1147                                 loaded = TRUE;
1148
1149                                 /* Forbid return stairs */
1150                                 if (change_floor_mode & CFM_NO_RETURN)
1151                                 {
1152                                         cave_type *c_ptr = &cave[py][px];
1153
1154                                         if (!feat_uses_special(c_ptr->feat))
1155                                         {
1156                                                 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1157                                                 {
1158                                                         /* Reset to floor */
1159                                                         c_ptr->feat = floor_type[randint0(100)];
1160                                                 }
1161
1162                                                 c_ptr->special = 0;
1163                                         }
1164                                 }
1165                         }
1166                 }
1167
1168                 /*
1169                  * Set lower/upper_floor_id of new floor when the new
1170                  * floor is right-above/right-under the current floor.
1171                  *
1172                  * Stair creation/Teleport level/Trap door will take
1173                  * you the same floor when you used it later again.
1174                  */
1175                 if (p_ptr->floor_id)
1176                 {
1177                         saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1178
1179                         if (change_floor_mode & CFM_UP)
1180                         {
1181                                 /* New floor is right-above */
1182                                 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1183                                         sf_ptr->lower_floor_id = p_ptr->floor_id;
1184                         }
1185                         else if (change_floor_mode & CFM_DOWN)
1186                         {
1187                                 /* New floor is right-under */
1188                                 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1189                                         sf_ptr->upper_floor_id = p_ptr->floor_id;
1190                         }
1191                 }
1192
1193                 /* Maintain monsters and artifacts */
1194                 if (loaded)
1195                 {
1196                         int i;
1197                         s32b absence_ticks = (turn - sf_ptr->last_visit) / TURNS_PER_TICK;
1198                         int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1199                         int alloc_times;
1200
1201                         /* Maintain monsters */
1202                         for (i = 1; i < m_max; i++)
1203                         {
1204                                 monster_race *r_ptr;
1205                                 monster_type *m_ptr = &m_list[i];
1206
1207                                 /* Skip dead monsters */
1208                                 if (!m_ptr->r_idx) continue;
1209
1210                                 if (!is_pet(m_ptr))
1211                                 {
1212                                         /* Restore HP */
1213                                         m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1214
1215                                         /* Remove fear */
1216                                         m_ptr->monfear = 0;
1217
1218                                         /* Remove invulnerability */
1219                                         m_ptr->invulner = 0;
1220
1221                                         /* Remove fast status */
1222                                         m_ptr->fast = 0;
1223
1224                                         /* Remove slow status */
1225                                         m_ptr->slow = 0;
1226
1227                                         /* Remove stun */
1228                                         m_ptr->stunned = 0;
1229
1230                                         /* Remove confusion */
1231                                         m_ptr->confused = 0;
1232                                 }
1233
1234                                 /* Extract real monster race */
1235                                 r_ptr = real_r_ptr(m_ptr);
1236
1237                                 /* Ignore non-unique */
1238                                 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1239                                     !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1240
1241                                 /* Appear at a different floor? */
1242                                 if (r_ptr->floor_id != new_floor_id)
1243                                 {
1244                                         /* Disapper from here */
1245                                         delete_monster_idx(i);
1246                                 }
1247                         }
1248
1249                         /* Maintain artifatcs */
1250                         for (i = 1; i < o_max; i++)
1251                         {
1252                                 object_type *o_ptr = &o_list[i];
1253
1254                                 /* Skip dead objects */
1255                                 if (!o_ptr->k_idx) continue;
1256
1257                                 /* Ignore non-artifact */
1258                                 if (!artifact_p(o_ptr)) continue;
1259
1260                                 /* Appear at a different floor? */
1261                                 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1262                                 {
1263                                         /* Disappear from here */
1264                                         delete_object_idx(i);
1265                                 }
1266                                 else
1267                                 {
1268                                         /* Cancel preserve */
1269                                         a_info[o_ptr->name1].cur_num = 1;
1270                                 }
1271                         }
1272
1273                         place_quest_monsters();
1274
1275                         /* Place some random monsters */
1276                         alloc_times = absence_ticks / alloc_chance;
1277
1278                         if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1279                                 alloc_times++;
1280
1281                         for (i = 0; i < alloc_times; i++)
1282                         {
1283                                 /* Make a (group of) new monster */
1284                                 (void)alloc_monster(0, 0);
1285                         }
1286                 }
1287
1288                 /* New floor_id or failed to restore */
1289                 else /* if (!loaded) */
1290                 {
1291                         if (sf_ptr->last_visit)
1292                         {
1293                                 /* Temporal file is broken? */
1294 #ifdef JP
1295                                 msg_print("³¬ÃʤϹԤ­»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1296 #else
1297                                 msg_print("The staircases come to a dead end...");
1298 #endif
1299
1300                                 /* Create simple dead end */
1301                                 build_dead_end();
1302
1303                                 /* Break connection */
1304                                 if (change_floor_mode & CFM_UP)
1305                                 {
1306                                         sf_ptr->upper_floor_id = 0;
1307                                 }
1308                                 else if (change_floor_mode & CFM_DOWN)
1309                                 {
1310                                         sf_ptr->lower_floor_id = 0;
1311                                 }
1312                         }
1313                         else
1314                         {
1315                                 /* Newly create cave */
1316                                 generate_cave();
1317                         }
1318
1319                         /* Record last visit turn */
1320                         sf_ptr->last_visit = turn;
1321
1322                         /* Set correct dun_level value */
1323                         sf_ptr->dun_level = dun_level;
1324
1325                         /* Create connected stairs */
1326                         if (!(change_floor_mode & CFM_NO_RETURN))
1327                         {
1328                                 /* Extract stair position */
1329                                 cave_type *c_ptr = &cave[py][px];
1330
1331                                 /*** Create connected stairs ***/
1332
1333                                 /* No stairs down from Quest */
1334                                 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1335                                 {
1336                                         if (change_floor_mode & CFM_SHAFT)
1337                                                 c_ptr->feat = FEAT_MORE_MORE;
1338                                         else
1339                                                 c_ptr->feat = FEAT_MORE;
1340                                 }
1341
1342                                 /* No stairs up when ironman_downward */
1343                                 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1344                                 {
1345                                         if (change_floor_mode & CFM_SHAFT)
1346                                                 c_ptr->feat = FEAT_LESS_LESS;
1347                                         else
1348                                                 c_ptr->feat = FEAT_LESS;
1349                                 }
1350
1351                                 /* Paranoia -- Clear mimic */
1352                                 c_ptr->mimic = 0;
1353
1354                                 /* Connect to previous floor */
1355                                 c_ptr->special = p_ptr->floor_id;
1356                         }
1357                 }
1358
1359                 /* Arrive at random grid */
1360                 if (change_floor_mode & (CFM_RAND_PLACE))
1361                 {
1362                         (void)new_player_spot();
1363                 }
1364
1365                 /* You see stairs blocked */
1366                 else if ((change_floor_mode & CFM_NO_RETURN) &&
1367                          (change_floor_mode & (CFM_DOWN | CFM_UP)))
1368                 {
1369                         if (!p_ptr->blind)
1370                         {
1371 #ifdef JP
1372                                 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1373 #else
1374                                 msg_print("Suddenly the stairs is blocked!");
1375 #endif
1376                         }
1377                         else
1378                         {
1379 #ifdef JP
1380                                 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1381 #else
1382                                 msg_print("You hear some noises.");
1383 #endif
1384                         }
1385                 }
1386
1387                 /*
1388                  * Update visit mark
1389                  *
1390                  * The "turn" is not always different number because
1391                  * the level teleport doesn't take any turn.  Use
1392                  * visit mark instead of last visit turn to find the
1393                  * oldest saved floor.
1394                  */
1395                 sf_ptr->visit_mark = latest_visit_mark++;
1396         }
1397
1398         /* Place preserved pet monsters */
1399         place_pet();
1400
1401         /* Hack -- maintain unique and artifacts */
1402         update_unique_artifact(new_floor_id);
1403
1404         /* Now the player is in new floor */
1405         p_ptr->floor_id = new_floor_id;
1406
1407         /* The dungeon is ready */
1408         character_dungeon = TRUE;
1409
1410         /* Hack -- Munchkin characters always get whole map */
1411         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1412                 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1413
1414         /* Remember when this level was "created" */
1415         old_turn = turn;
1416
1417         /* Clear all flags */
1418         change_floor_mode = 0L;
1419 }
1420
1421
1422
1423 /*
1424  * Create stairs at or move previously created stairs into the player
1425  * location.
1426  */
1427 void stair_creation(void)
1428 {
1429         saved_floor_type *sf_ptr;
1430         saved_floor_type *dest_sf_ptr;
1431
1432         bool up = TRUE;
1433         bool down = TRUE;
1434         s16b dest_floor_id = 0;
1435
1436
1437         /* Forbid up staircases on Ironman mode */
1438         if (ironman_downward) up = FALSE;
1439
1440         /* Forbid down staircases on quest level */
1441         if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1442
1443         /* No effect out of standard dungeon floor */
1444         if (!dun_level || (!up && !down) ||
1445             (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1446             p_ptr->inside_arena || p_ptr->inside_battle)
1447         {
1448                 /* arena or quest */
1449 #ifdef JP
1450                 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1451 #else
1452                 msg_print("There is no effect!");
1453 #endif
1454                 return;
1455         }
1456
1457         /* Artifacts resists */
1458         if (!cave_valid_bold(py, px))
1459         {
1460 #ifdef JP
1461                 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1462 #else
1463                 msg_print("The object resists the spell.");
1464 #endif
1465
1466                 return;
1467         }
1468
1469         /* Destroy all objects in the grid */
1470         delete_object(py, px);
1471
1472         /* Extract current floor data */
1473         sf_ptr = get_sf_ptr(p_ptr->floor_id);
1474
1475         /* Choose randomly */
1476         if (up && down)
1477         {
1478                 if (randint0(100) < 50) up = FALSE;
1479                 else down = FALSE;
1480         }
1481
1482         /* Destination is already fixed */
1483         if (up)
1484         {
1485                 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1486         }
1487         else
1488         {
1489                 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1490         }
1491
1492
1493         /* Search old stairs leading to the destination */
1494         if (dest_floor_id)
1495         {
1496                 int x, y;
1497
1498                 for (y = 0; y < cur_hgt; y++)
1499                 {
1500                         for (x = 0; x < cur_wid; x++)
1501                         {
1502                                 cave_type *c_ptr = &cave[y][x];
1503
1504                                 if (!c_ptr->special) continue;
1505                                 if (feat_uses_special(c_ptr->feat)) continue;
1506                                 if (c_ptr->special != dest_floor_id) continue;
1507
1508                                 /* Remove old stairs */
1509                                 c_ptr->special = 0;
1510                                 cave_set_feat(y, x, floor_type[randint0(100)]);
1511                         }
1512                 }
1513         }
1514
1515         /* No old destination -- Get new one now */
1516         else
1517         {
1518                 dest_floor_id = get_new_floor_id();
1519
1520                 /* Fix it */
1521                 if (up)
1522                         sf_ptr->upper_floor_id = dest_floor_id;
1523                 else
1524                         sf_ptr->lower_floor_id = dest_floor_id;
1525         }
1526
1527         /* Extract destination floor data */
1528         dest_sf_ptr = get_sf_ptr(dest_floor_id);
1529
1530
1531         /* Create a staircase */
1532         if (up)
1533         {
1534                 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1535                         cave_set_feat(py, px, FEAT_LESS_LESS);
1536                 else
1537                         cave_set_feat(py, px, FEAT_LESS);
1538         }
1539         else
1540         {
1541                 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1542                         cave_set_feat(py, px, FEAT_MORE_MORE);
1543                 else
1544                         cave_set_feat(py, px, FEAT_MORE);
1545         }
1546
1547
1548         /* Connect this stairs to the destination */
1549         cave[py][px].special = dest_floor_id;
1550 }