OSDN Git Service

Revert "Revert "Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband""
[hengband/hengband.git] / src / grid / stair.c
1 #include "grid/stair.h"
2 #include "dungeon/dungeon.h"
3 #include "dungeon/quest.h"
4 #include "game-option/birth-options.h"
5 #include "floor/cave.h"
6 #include "grid/grid.h"
7 #include "object-hook/hook-enchant.h"
8 #include "system/floor-type-definition.h"
9 #include "system/object-type-definition.h"
10
11 /*!
12  * @brief \8f\8a\92è\82Ì\88Ê\92u\82É\8fã\82è\8aK\92i\82©\89º\82è\8aK\92i\82ð\94z\92u\82·\82é / Place an up/down staircase at given location
13  * @param player_ptr \83v\83\8c\81[\83\84\81[\82Ö\82Ì\8eQ\8fÆ\83|\83C\83\93\83^
14  * @param y \94z\92u\82ð\8e\8e\82Ý\82½\82¢\83}\83X\82ÌY\8dÀ\95W
15  * @param x \94z\92u\82ð\8e\8e\82Ý\82½\82¢\83}\83X\82ÌX\8dÀ\95W
16  * @return \82È\82µ
17  */
18 void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
19 {
20     bool up_stairs = TRUE;
21     bool down_stairs = TRUE;
22     grid_type *g_ptr;
23     floor_type *floor_ptr = player_ptr->current_floor_ptr;
24     g_ptr = &floor_ptr->grid_array[y][x];
25     if (!is_floor_grid(g_ptr) || g_ptr->o_idx)
26         return;
27
28     if (!floor_ptr->dun_level)
29         up_stairs = FALSE;
30
31     if (ironman_downward)
32         up_stairs = FALSE;
33
34     if (floor_ptr->dun_level >= d_info[player_ptr->dungeon_idx].maxdepth)
35         down_stairs = FALSE;
36
37     if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1))
38         down_stairs = FALSE;
39
40     if (down_stairs && up_stairs) {
41         if (randint0(100) < 50)
42             up_stairs = FALSE;
43         else
44             down_stairs = FALSE;
45     }
46
47     if (up_stairs)
48         set_cave_feat(floor_ptr, y, x, feat_up_stair);
49     else if (down_stairs)
50         set_cave_feat(floor_ptr, y, x, feat_down_stair);
51 }
52
53 /*!
54  * @brief \8ew\92è\82³\82ê\82½\8dÀ\95W\82ª\92n\90k\82â\8aK\92i\90\90¬\82Ì\91Î\8fÛ\82Æ\82È\82é\83}\83X\82©\82ð\95Ô\82·\81B / Determine if a given location may be "destroyed"
55  * @param player_ptr \83v\83\8c\81[\83\84\81[\82Ö\82Ì\8eQ\8fÆ\83|\83C\83\93\83^
56  * @param y y\8dÀ\95W
57  * @param x x\8dÀ\95W
58  * @return \8ae\8eí\82Ì\95Ï\8dX\82ª\89Â\94\\82È\82çTRUE\82ð\95Ô\82·\81B
59  * @details
60  * \8fð\8c\8f\82Í\89i\8bv\92n\8c`\82Å\82È\82­\81A\82È\82¨\82©\82Â\8aY\93\96\82Ì\83}\83X\82É\83A\81[\83e\83B\83t\83@\83N\83g\82ª\91\8dÝ\82µ\82È\82¢\82©\81A\82Å\82 \82é\81B\89p\8cê\82Ì\8b\8c\83R\83\81\83\93\83g\82É\94½\82µ\82Ä\81\96\94j\89ó\81\96\82Ì\97}\8e~\94»\92è\82É\82Í\8c»\8dÝ\8eg\82í\82ê\82Ä\82¢\82È\82¢\81B
61  */
62 bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x)
63 {
64     grid_type *g_ptr = &floor_ptr->grid_array[y][x];
65     if (cave_have_flag_grid(g_ptr, FF_PERMANENT))
66         return FALSE;
67
68     OBJECT_IDX next_o_idx = 0;
69     for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
70         object_type *o_ptr;
71         o_ptr = &floor_ptr->o_list[this_o_idx];
72         next_o_idx = o_ptr->next_o_idx;
73         if (object_is_artifact(o_ptr))
74             return FALSE;
75     }
76
77     return TRUE;
78 }