OSDN Git Service

Merge branch 'develop' into feature/Monster-Sweep-Grid-Adjustment
[hengbandforosx/hengbandosx.git] / src / monster-floor / monster-summon.cpp
1 #include "monster-floor/monster-summon.h"
2 #include "dungeon/dungeon-flag-types.h"
3 #include "dungeon/dungeon.h"
4 #include "floor/wild.h"
5 #include "main/sound-definitions-table.h"
6 #include "main/sound-of-music.h"
7 #include "monster-floor/monster-generator.h"
8 #include "monster-floor/place-monster-types.h"
9 #include "monster-race/monster-race-hook.h"
10 #include "monster-race/monster-race.h"
11 #include "monster-race/race-flags1.h"
12 #include "monster-race/race-flags7.h"
13 #include "monster/monster-info.h"
14 #include "monster/monster-list.h"
15 #include "monster/monster-util.h"
16 #include "mspell/summon-checker.h"
17 #include "spell/summon-types.h"
18 #include "system/floor-type-definition.h"
19 #include "system/monster-race-definition.h"
20 #include "system/monster-type-definition.h"
21 #include "system/player-type-definition.h"
22
23 /*!
24  * @var summon_specific_who
25  * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
26  * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
27  */
28 int summon_specific_who = -1;
29
30 /*!
31  * @var summon_unique_okay
32  * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
33  * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
34  */
35 bool summon_unique_okay = false;
36
37 /*!
38  * @brief モンスターが召喚の基本条件に合っているかをチェックする / Hack -- help decide if a monster race is "okay" to summon
39  * @param r_idx チェックするモンスター種族ID
40  * @return 召喚対象にできるならばTRUE
41  */
42 static bool summon_specific_okay(player_type *player_ptr, MONRACE_IDX r_idx)
43 {
44     monster_race *r_ptr = &r_info[r_idx];
45     if (!mon_hook_dungeon(player_ptr, r_idx))
46         return false;
47
48     if (summon_specific_who > 0) {
49         monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[summon_specific_who];
50         if (monster_has_hostile_align(player_ptr, m_ptr, 0, 0, r_ptr))
51             return false;
52     } else if (summon_specific_who < 0) {
53         if (monster_has_hostile_align(player_ptr, NULL, 10, -10, r_ptr) && !one_in_(ABS(player_ptr->alignment) / 2 + 1))
54             return false;
55     }
56
57     if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
58         return false;
59
60     if (!summon_specific_type)
61         return true;
62
63     if ((summon_specific_who < 0) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))
64         && monster_has_hostile_align(player_ptr, NULL, 10, -10, r_ptr))
65         return false;
66
67     if ((r_ptr->flags7 & RF7_CHAMELEON) && d_info[player_ptr->dungeon_idx].flags.has(DF::CHAMELEON))
68         return true;
69
70     if (summon_specific_who > 0) {
71         monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[summon_specific_who];
72         return check_summon_specific(player_ptr, m_ptr->r_idx, r_idx);
73     } else {
74         return check_summon_specific(player_ptr, 0, r_idx);
75     }
76 }
77
78 /*!
79  * @brief モンスター死亡時に召喚されうるモンスターかどうかの判定
80  * @param type モンスター種族ID
81  * @return 召喚されうるならばTRUE (あやしい影として生成されない)
82  */
83 static bool is_dead_summoning(summon_type type)
84 {
85     bool summoning = type == SUMMON_BLUE_HORROR;
86     summoning |= type == SUMMON_DAWN;
87     summoning |= type == SUMMON_TOTEM_MOAI;
88     return summoning;
89 }
90
91 /*!
92  * @brief 荒野のレベルを含めた階層レベルを返す
93  * @param player_ptr プレーヤーへの参照ポインタ
94  * @return 階層レベル
95  * @details
96  * ダンジョン及びクエストはdun_level>0となる。
97  * 荒野はdun_level==0なので、その場合荒野レベルを返す。
98  */
99 DEPTH get_dungeon_or_wilderness_level(player_type *player_ptr)
100 {
101     floor_type *floor_ptr = player_ptr->current_floor_ptr;
102     if (floor_ptr->dun_level > 0)
103         return floor_ptr->dun_level;
104
105     return wilderness[player_ptr->wilderness_y][player_ptr->wilderness_x].level;
106 }
107
108 /*!
109  * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
110  * @param player_ptr プレーヤーへの参照ポインタ
111  * @param who 召喚主のモンスター情報ID
112  * @param y1 目標地点y座標
113  * @param x1 目標地点x座標
114  * @param lev 相当生成階
115  * @param type 召喚種別
116  * @param mode 生成オプション
117  * @return 召喚できたらtrueを返す
118  */
119 bool summon_specific(player_type *player_ptr, MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, summon_type type, BIT_FLAGS mode)
120 {
121     floor_type *floor_ptr = player_ptr->current_floor_ptr;
122     if (floor_ptr->inside_arena)
123         return false;
124
125     POSITION x, y;
126     if (!mon_scatter(player_ptr, 0, &y, &x, y1, x1, 2))
127         return false;
128
129     summon_specific_who = who;
130     summon_specific_type = type;
131     summon_unique_okay = (mode & PM_ALLOW_UNIQUE) != 0;
132     get_mon_num_prep(player_ptr, summon_specific_okay, get_monster_hook2(player_ptr, y, x));
133
134     DEPTH dlev = get_dungeon_or_wilderness_level(player_ptr);
135     MONRACE_IDX r_idx = get_mon_num(player_ptr, 0, (dlev + lev) / 2 + 5, 0);
136     if (!r_idx) {
137         summon_specific_type = SUMMON_NONE;
138         return false;
139     }
140
141     if (is_dead_summoning(type))
142         mode |= PM_NO_KAGE;
143
144     if (!place_monster_aux(player_ptr, who, y, x, r_idx, mode)) {
145         summon_specific_type = SUMMON_NONE;
146         return false;
147     }
148
149     summon_specific_type = SUMMON_NONE;
150     sound(SOUND_SUMMON);
151     return true;
152 }
153
154 /*!
155  * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
156  * @param player_ptr プレーヤーへの参照ポインタ
157  * @param who 召喚主のモンスター情報ID
158  * @param oy 目標地点y座標
159  * @param ox 目標地点x座標
160  * @param r_idx 生成するモンスター種族ID
161  * @param mode 生成オプション
162  * @return 召喚できたらtrueを返す
163  */
164 bool summon_named_creature(player_type *player_ptr, MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
165 {
166     if ((r_idx <= 0) || (r_idx >= max_r_idx)) {
167         return false;
168     }
169     
170     POSITION x, y;
171     if (player_ptr->current_floor_ptr->inside_arena || !mon_scatter(player_ptr, r_idx, &y, &x, oy, ox, 2)) {
172         return false;
173     }
174     
175     return place_monster_aux(player_ptr, who, y, x, r_idx, (mode | PM_NO_KAGE));
176 }