8 #include "monster-floor/monster-generator.h"
9 #include "dungeon/dungeon.h"
10 #include "game-option/cheat-options.h"
11 #include "grid/grid.h"
12 #include "monster-floor/one-monster-placer.h"
13 #include "monster-floor/place-monster-types.h"
14 #include "monster-race/monster-race-hook.h"
15 #include "monster-race/monster-race.h"
16 #include "monster-race/race-flags1.h"
17 #include "monster-race/race-flags7.h"
18 #include "monster-race/race-indice-types.h"
19 #include "monster/monster-flag-types.h"
20 #include "monster/monster-info.h"
21 #include "monster/monster-list.h"
22 #include "monster/monster-util.h"
23 #include "monster/smart-learn-types.h"
24 #include "mspell/summon-checker.h"
25 #include "spell/spells-summon.h"
26 #include "system/floor-type-definition.h"
27 #include "util/string-processor.h"
28 #include "view/display-messages.h"
30 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
33 * @var place_monster_idx
34 * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
35 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
37 static MONSTER_IDX place_monster_idx = 0;
40 * @var place_monster_m_idx
41 * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
42 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
44 static MONSTER_IDX place_monster_m_idx = 0;
47 * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster
48 * @param player_ptr プレーヤーへの参照ポインタ
49 * @param r_idx 生成モンスター種族
54 * @param max_dist 生成位置の最大半径
58 bool mon_scatter(player_type *player_ptr, MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
60 POSITION place_x[MON_SCAT_MAXD];
61 POSITION place_y[MON_SCAT_MAXD];
62 int num[MON_SCAT_MAXD];
64 if (max_dist >= MON_SCAT_MAXD)
68 for (i = 0; i < MON_SCAT_MAXD; i++)
71 floor_type *floor_ptr = player_ptr->current_floor_ptr;
72 for (POSITION nx = x - max_dist; nx <= x + max_dist; nx++) {
73 for (POSITION ny = y - max_dist; ny <= y + max_dist; ny++) {
74 if (!in_bounds(floor_ptr, ny, nx))
76 if (!projectable(player_ptr, y, x, ny, nx))
79 monster_race *r_ptr = &r_info[r_idx];
80 if (!monster_can_enter(player_ptr, ny, nx, r_ptr, 0))
83 if (!is_cave_empty_bold2(player_ptr, ny, nx))
85 if (pattern_tile(floor_ptr, ny, nx))
89 i = distance(y, x, ny, nx);
94 if (one_in_(num[i])) {
102 while (i < MON_SCAT_MAXD && 0 == num[i])
104 if (i >= MON_SCAT_MAXD)
114 * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
115 * @param player_ptr プレーヤーへの参照ポインタ
116 * @param m_idx 増殖するモンスター情報ID
117 * @param clone クローン・モンスター処理ならばtrue
118 * @param mode 生成オプション
119 * @return 生成できたらtrueを返す
121 * Note that "reproduction" REQUIRES empty space.
123 bool multiply_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
125 floor_type *floor_ptr = player_ptr->current_floor_ptr;
126 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
128 if (!mon_scatter(player_ptr, m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
131 if (m_ptr->mflag2 & MFLAG2_NOPET)
134 if (!place_monster_aux(player_ptr, m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
137 if (clone || (m_ptr->smart & SM_CLONED)) {
138 floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
139 floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
146 * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
147 * @param who 召喚主のモンスター情報ID
150 * @param r_idx 生成モンスター種族
151 * @param mode 生成オプション
154 static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
156 monster_race *r_ptr = &r_info[r_idx];
157 int total = randint1(10);
159 floor_type *floor_ptr = player_ptr->current_floor_ptr;
161 if (r_ptr->level > floor_ptr->dun_level) {
162 extra = r_ptr->level - floor_ptr->dun_level;
163 extra = 0 - randint1(extra);
164 } else if (r_ptr->level < floor_ptr->dun_level) {
165 extra = floor_ptr->dun_level - r_ptr->level;
166 extra = randint1(extra);
176 if (total > GROUP_MAX)
180 POSITION hack_x[GROUP_MAX];
182 POSITION hack_y[GROUP_MAX];
185 for (int n = 0; (n < hack_n) && (hack_n < total); n++) {
186 POSITION hx = hack_x[n];
187 POSITION hy = hack_y[n];
188 for (int i = 0; (i < 8) && (hack_n < total); i++) {
190 scatter(player_ptr, &my, &mx, hy, hx, 4, 0);
191 if (!is_cave_empty_bold2(player_ptr, my, mx))
194 if (place_monster_one(player_ptr, who, my, mx, r_idx, mode)) {
206 * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
207 * @param r_idx チェックするモンスター種族のID
208 * @return 護衛にできるならばtrue
210 static bool place_monster_can_escort(player_type *player_ptr, MONRACE_IDX r_idx)
212 monster_race *r_ptr = &r_info[place_monster_idx];
213 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[place_monster_m_idx];
214 monster_race *z_ptr = &r_info[r_idx];
216 if (mon_hook_dungeon(player_ptr, place_monster_idx) != mon_hook_dungeon(player_ptr, r_idx))
218 if (z_ptr->d_char != r_ptr->d_char)
220 if (z_ptr->level > r_ptr->level)
222 if (z_ptr->flags1 & RF1_UNIQUE)
224 if (place_monster_idx == r_idx)
226 if (monster_has_hostile_align(player_ptr, m_ptr, 0, 0, z_ptr))
229 if (r_ptr->flags7 & RF7_FRIENDLY) {
230 if (monster_has_hostile_align(player_ptr, NULL, 1, -1, z_ptr))
234 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
241 * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
242 * @param player_ptr プレーヤーへの参照ポインタ
243 * @param who 召喚主のモンスター情報ID
246 * @param r_idx 生成するモンスターの種族ID
247 * @param mode 生成オプション
248 * @return 生成に成功したらtrue
250 bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
252 monster_race *r_ptr = &r_info[r_idx];
254 if (!(mode & PM_NO_KAGE) && one_in_(333))
257 if (!place_monster_one(player_ptr, who, y, x, r_idx, mode))
259 if (!(mode & PM_ALLOW_GROUP))
262 place_monster_m_idx = hack_m_idx_ii;
265 for (int i = 0; i < 6; i++) {
266 if (!r_ptr->reinforce_id[i])
268 int n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
269 for (int j = 0; j < n; j++) {
270 POSITION nx, ny, d = 7;
271 scatter(player_ptr, &ny, &nx, y, x, d, 0);
272 (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
276 if (r_ptr->flags1 & (RF1_FRIENDS)) {
277 (void)place_monster_group(player_ptr, who, y, x, r_idx, mode);
280 if (!(r_ptr->flags1 & (RF1_ESCORT)))
283 place_monster_idx = r_idx;
284 for (int i = 0; i < 32; i++) {
285 POSITION nx, ny, d = 3;
287 scatter(player_ptr, &ny, &nx, y, x, d, 0);
288 if (!is_cave_empty_bold2(player_ptr, ny, nx))
291 get_mon_num_prep(player_ptr, place_monster_can_escort, get_monster_hook2(player_ptr, ny, nx));
292 z = get_mon_num(player_ptr, r_ptr->level, 0);
296 (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, z, mode);
297 if ((r_info[z].flags1 & RF1_FRIENDS) || (r_ptr->flags1 & RF1_ESCORTS)) {
298 (void)place_monster_group(player_ptr, place_monster_m_idx, ny, nx, z, mode);
306 * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
307 * @param player_ptr プレーヤーへの参照ポインタ
310 * @param mode 生成オプション
311 * @return 生成に成功したらtrue
313 bool place_monster(player_type *player_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
316 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
317 r_idx = get_mon_num(player_ptr, player_ptr->current_floor_ptr->monster_level, 0);
321 if ((one_in_(5) || (player_ptr->current_floor_ptr->base_level == 0)) && !(r_info[r_idx].flags1 & RF1_UNIQUE)
322 && angband_strchr("hkoptuyAHLOPTUVY", r_info[r_idx].d_char)) {
326 if (place_monster_aux(player_ptr, 0, y, x, r_idx, mode))
333 * @brief 指定地点に1種類のモンスター種族による群れを生成する
334 * @param player_ptr プレーヤーへの参照ポインタ
337 * @return 生成に成功したらtrue
339 bool alloc_horde(player_type *player_ptr, POSITION y, POSITION x, summon_specific_pf summon_specific)
341 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
343 floor_type *floor_ptr = player_ptr->current_floor_ptr;
344 MONRACE_IDX r_idx = 0;
346 monster_race *r_ptr = NULL;
348 r_idx = get_mon_num(player_ptr, floor_ptr->monster_level, 0);
352 r_ptr = &r_info[r_idx];
353 if (r_ptr->flags1 & RF1_UNIQUE)
356 if (r_idx == MON_HAGURE)
367 if (place_monster_aux(player_ptr, 0, y, x, r_idx, 0L))
374 MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
375 if (floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON)
376 r_ptr = &r_info[floor_ptr->m_list[m_idx].r_idx];
380 for (attempts = randint1(10) + 5; attempts; attempts--) {
381 scatter(player_ptr, &cy, &cx, y, x, 5, 0);
382 (void)(*summon_specific)(player_ptr, m_idx, cy, cx, floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
388 msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), r_ptr->d_char);
393 * @brief ダンジョンの主生成を試みる / Put the Guardian
394 * @param player_ptr プレーヤーへの参照ポインタ
395 * @param def_val 現在の主の生成状態
396 * @return 生成に成功したらtrue
398 bool alloc_guardian(player_type *player_ptr, bool def_val)
400 MONRACE_IDX guardian = d_info[player_ptr->dungeon_idx].final_guardian;
401 floor_type *floor_ptr = player_ptr->current_floor_ptr;
402 bool is_guardian_applicable = guardian > 0;
403 is_guardian_applicable &= d_info[player_ptr->dungeon_idx].maxdepth == floor_ptr->dun_level;
404 is_guardian_applicable &= r_info[guardian].cur_num < r_info[guardian].max_num;
405 if (!is_guardian_applicable)
408 int try_count = 4000;
410 POSITION oy = randint1(floor_ptr->height - 4) + 2;
411 POSITION ox = randint1(floor_ptr->width - 4) + 2;
412 if (!is_cave_empty_bold2(player_ptr, oy, ox)) {
417 if (!monster_can_cross_terrain(player_ptr, floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0)) {
422 if (place_monster_aux(player_ptr, 0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET)))
432 * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
433 * @param dis プレイヤーから離れるべき最低距離
434 * @param mode 生成オプション
435 * @return 生成に成功したらtrue
437 * Place the monster at least "dis" distance from the player.
438 * Use "slp" to choose the initial "sleep" status
439 * Use "floor_ptr->monster_level" for the monster level
441 bool alloc_monster(player_type *player_ptr, POSITION dis, BIT_FLAGS mode, summon_specific_pf summon_specific)
443 if (alloc_guardian(player_ptr, FALSE))
446 floor_type *floor_ptr = player_ptr->current_floor_ptr;
447 POSITION y = 0, x = 0;
448 int attempts_left = 10000;
449 while (attempts_left--) {
450 y = randint0(floor_ptr->height);
451 x = randint0(floor_ptr->width);
453 if (floor_ptr->dun_level) {
454 if (!is_cave_empty_bold2(player_ptr, y, x))
457 if (!is_cave_empty_bold(player_ptr, y, x))
461 if (distance(y, x, player_ptr->y, player_ptr->x) > dis)
465 if (!attempts_left) {
466 if (cheat_xtra || cheat_hear) {
467 msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
473 if (randint1(5000) <= floor_ptr->dun_level) {
474 if (alloc_horde(player_ptr, y, x, summon_specific)) {
478 if (place_monster(player_ptr, y, x, (mode | PM_ALLOW_GROUP)))