8 #include "monster-floor/monster-generator.h"
9 #include "dungeon/dungeon.h"
10 #include "effect/effect-characteristics.h"
11 #include "floor/cave.h"
12 #include "floor/floor-util.h"
13 #include "game-option/cheat-options.h"
14 #include "grid/grid.h"
15 #include "monster-floor/one-monster-placer.h"
16 #include "monster-floor/place-monster-types.h"
17 #include "monster-race/monster-race-hook.h"
18 #include "monster-race/monster-race.h"
19 #include "monster-race/race-flags1.h"
20 #include "monster-race/race-flags7.h"
21 #include "monster-race/race-indice-types.h"
22 #include "monster/monster-flag-types.h"
23 #include "monster/monster-info.h"
24 #include "monster/monster-list.h"
25 #include "monster/monster-util.h"
26 #include "monster/smart-learn-types.h"
27 #include "mspell/summon-checker.h"
28 #include "spell/summon-types.h"
29 #include "system/floor-type-definition.h"
30 #include "target/projection-path-calculator.h"
31 #include "util/string-processor.h"
32 #include "view/display-messages.h"
34 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
37 * @var place_monster_idx
38 * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
39 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
41 static MONSTER_IDX place_monster_idx = 0;
44 * @var place_monster_m_idx
45 * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
46 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
48 static MONSTER_IDX place_monster_m_idx = 0;
51 * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster
52 * @param player_ptr プレーヤーへの参照ポインタ
53 * @param r_idx 生成モンスター種族
58 * @param max_dist 生成位置の最大半径
62 bool mon_scatter(player_type *player_ptr, MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
64 POSITION place_x[MON_SCAT_MAXD];
65 POSITION place_y[MON_SCAT_MAXD];
66 int num[MON_SCAT_MAXD];
68 if (max_dist >= MON_SCAT_MAXD)
72 for (i = 0; i < MON_SCAT_MAXD; i++)
75 floor_type *floor_ptr = player_ptr->current_floor_ptr;
76 for (POSITION nx = x - max_dist; nx <= x + max_dist; nx++) {
77 for (POSITION ny = y - max_dist; ny <= y + max_dist; ny++) {
78 if (!in_bounds(floor_ptr, ny, nx))
80 if (!projectable(player_ptr, y, x, ny, nx))
83 monster_race *r_ptr = &r_info[r_idx];
84 if (!monster_can_enter(player_ptr, ny, nx, r_ptr, 0))
87 if (!is_cave_empty_bold2(player_ptr, ny, nx))
89 if (pattern_tile(floor_ptr, ny, nx))
93 i = distance(y, x, ny, nx);
98 if (one_in_(num[i])) {
106 while (i < MON_SCAT_MAXD && 0 == num[i])
108 if (i >= MON_SCAT_MAXD)
118 * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
119 * @param player_ptr プレーヤーへの参照ポインタ
120 * @param m_idx 増殖するモンスター情報ID
121 * @param clone クローン・モンスター処理ならばtrue
122 * @param mode 生成オプション
123 * @return 生成できたらtrueを返す
125 * Note that "reproduction" REQUIRES empty space.
127 bool multiply_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
129 floor_type *floor_ptr = player_ptr->current_floor_ptr;
130 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
132 if (!mon_scatter(player_ptr, m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
135 if (m_ptr->mflag2 & MFLAG2_NOPET)
138 if (!place_monster_aux(player_ptr, m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
141 if (clone || (m_ptr->smart & SM_CLONED)) {
142 floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
143 floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
150 * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
151 * @param who 召喚主のモンスター情報ID
154 * @param r_idx 生成モンスター種族
155 * @param mode 生成オプション
158 static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
160 monster_race *r_ptr = &r_info[r_idx];
161 int total = randint1(10);
163 floor_type *floor_ptr = player_ptr->current_floor_ptr;
165 if (r_ptr->level > floor_ptr->dun_level) {
166 extra = r_ptr->level - floor_ptr->dun_level;
167 extra = 0 - randint1(extra);
168 } else if (r_ptr->level < floor_ptr->dun_level) {
169 extra = floor_ptr->dun_level - r_ptr->level;
170 extra = randint1(extra);
180 if (total > GROUP_MAX)
184 POSITION hack_x[GROUP_MAX];
186 POSITION hack_y[GROUP_MAX];
189 for (int n = 0; (n < hack_n) && (hack_n < total); n++) {
190 POSITION hx = hack_x[n];
191 POSITION hy = hack_y[n];
192 for (int i = 0; (i < 8) && (hack_n < total); i++) {
194 scatter(player_ptr, &my, &mx, hy, hx, 4, PROJECT_NONE);
195 if (!is_cave_empty_bold2(player_ptr, my, mx))
198 if (place_monster_one(player_ptr, who, my, mx, r_idx, mode)) {
210 * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
211 * @param r_idx チェックするモンスター種族のID
212 * @return 護衛にできるならばtrue
214 static bool place_monster_can_escort(player_type *player_ptr, MONRACE_IDX r_idx)
216 monster_race *r_ptr = &r_info[place_monster_idx];
217 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[place_monster_m_idx];
218 monster_race *z_ptr = &r_info[r_idx];
220 if (mon_hook_dungeon(player_ptr, place_monster_idx) != mon_hook_dungeon(player_ptr, r_idx))
223 if (z_ptr->d_char != r_ptr->d_char)
226 if (z_ptr->level > r_ptr->level)
229 if (z_ptr->flags1 & RF1_UNIQUE)
232 if (place_monster_idx == r_idx)
235 if (monster_has_hostile_align(player_ptr, m_ptr, 0, 0, z_ptr))
238 if (r_ptr->flags7 & RF7_FRIENDLY) {
239 if (monster_has_hostile_align(player_ptr, NULL, 1, -1, z_ptr))
243 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
250 * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
251 * @param player_ptr プレーヤーへの参照ポインタ
252 * @param who 召喚主のモンスター情報ID
255 * @param r_idx 生成するモンスターの種族ID
256 * @param mode 生成オプション
257 * @return 生成に成功したらtrue
259 bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
261 monster_race *r_ptr = &r_info[r_idx];
263 if (!(mode & PM_NO_KAGE) && one_in_(333))
266 if (!place_monster_one(player_ptr, who, y, x, r_idx, mode))
268 if (!(mode & PM_ALLOW_GROUP))
271 place_monster_m_idx = hack_m_idx_ii;
274 for (int i = 0; i < 6; i++) {
275 if (!r_ptr->reinforce_id[i])
277 int n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
278 for (int j = 0; j < n; j++) {
279 POSITION nx, ny, d = 7;
280 scatter(player_ptr, &ny, &nx, y, x, d, PROJECT_NONE);
281 (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
285 if (r_ptr->flags1 & (RF1_FRIENDS)) {
286 (void)place_monster_group(player_ptr, who, y, x, r_idx, mode);
289 if (!(r_ptr->flags1 & (RF1_ESCORT)))
292 place_monster_idx = r_idx;
293 for (int i = 0; i < 32; i++) {
294 POSITION nx, ny, d = 3;
296 scatter(player_ptr, &ny, &nx, y, x, d, PROJECT_NONE);
297 if (!is_cave_empty_bold2(player_ptr, ny, nx))
300 get_mon_num_prep(player_ptr, place_monster_can_escort, get_monster_hook2(player_ptr, ny, nx));
301 z = get_mon_num(player_ptr, 0, r_ptr->level, 0);
305 (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, z, mode);
306 if ((r_info[z].flags1 & RF1_FRIENDS) || (r_ptr->flags1 & RF1_ESCORTS)) {
307 (void)place_monster_group(player_ptr, place_monster_m_idx, ny, nx, z, mode);
315 * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
316 * @param player_ptr プレーヤーへの参照ポインタ
319 * @param mode 生成オプション
320 * @return 生成に成功したらtrue
322 bool place_monster(player_type *player_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
324 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
325 MONRACE_IDX r_idx = get_mon_num(player_ptr, 0, player_ptr->current_floor_ptr->monster_level, 0);
329 if ((one_in_(5) || (player_ptr->current_floor_ptr->base_level == 0)) && !(r_info[r_idx].flags1 & RF1_UNIQUE)
330 && angband_strchr("hkoptuyAHLOPTUVY", r_info[r_idx].d_char)) {
334 return place_monster_aux(player_ptr, 0, y, x, r_idx, mode);
338 * @brief 指定地点に1種類のモンスター種族による群れを生成する
339 * @param player_ptr プレーヤーへの参照ポインタ
342 * @return 生成に成功したらtrue
344 bool alloc_horde(player_type *player_ptr, POSITION y, POSITION x, summon_specific_pf summon_specific)
346 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
348 floor_type *floor_ptr = player_ptr->current_floor_ptr;
349 MONRACE_IDX r_idx = 0;
351 monster_race *r_ptr = NULL;
353 r_idx = get_mon_num(player_ptr, 0, floor_ptr->monster_level, 0);
357 r_ptr = &r_info[r_idx];
358 if (r_ptr->flags1 & RF1_UNIQUE)
361 if (r_idx == MON_HAGURE)
372 if (place_monster_aux(player_ptr, 0, y, x, r_idx, 0L))
379 MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
380 if (floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON)
381 r_ptr = &r_info[floor_ptr->m_list[m_idx].r_idx];
385 for (attempts = randint1(10) + 5; attempts; attempts--) {
386 scatter(player_ptr, &cy, &cx, y, x, 5, PROJECT_NONE);
387 (void)(*summon_specific)(player_ptr, m_idx, cy, cx, floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
393 msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), r_ptr->d_char);
398 * @brief ダンジョンの主生成を試みる / Put the Guardian
399 * @param player_ptr プレーヤーへの参照ポインタ
400 * @param def_val 現在の主の生成状態
401 * @return 生成に成功したらtrue
403 bool alloc_guardian(player_type *player_ptr, bool def_val)
405 MONRACE_IDX guardian = d_info[player_ptr->dungeon_idx].final_guardian;
406 floor_type *floor_ptr = player_ptr->current_floor_ptr;
407 bool is_guardian_applicable = guardian > 0;
408 is_guardian_applicable &= d_info[player_ptr->dungeon_idx].maxdepth == floor_ptr->dun_level;
409 is_guardian_applicable &= r_info[guardian].cur_num < r_info[guardian].max_num;
410 if (!is_guardian_applicable)
413 int try_count = 4000;
415 POSITION oy = randint1(floor_ptr->height - 4) + 2;
416 POSITION ox = randint1(floor_ptr->width - 4) + 2;
417 if (!is_cave_empty_bold2(player_ptr, oy, ox)) {
422 if (!monster_can_cross_terrain(player_ptr, floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0)) {
427 if (place_monster_aux(player_ptr, 0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET)))
437 * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
438 * @param dis プレイヤーから離れるべき最低距離
439 * @param mode 生成オプション
440 * @return 生成に成功したらtrue
442 * Place the monster at least "dis" distance from the player.
443 * Use "slp" to choose the initial "sleep" status
444 * Use "floor_ptr->monster_level" for the monster level
446 bool alloc_monster(player_type *player_ptr, POSITION dis, BIT_FLAGS mode, summon_specific_pf summon_specific)
448 if (alloc_guardian(player_ptr, FALSE))
451 floor_type *floor_ptr = player_ptr->current_floor_ptr;
452 POSITION y = 0, x = 0;
453 int attempts_left = 10000;
454 while (attempts_left--) {
455 y = randint0(floor_ptr->height);
456 x = randint0(floor_ptr->width);
458 if (floor_ptr->dun_level) {
459 if (!is_cave_empty_bold2(player_ptr, y, x))
462 if (!is_cave_empty_bold(player_ptr, y, x))
466 if (distance(y, x, player_ptr->y, player_ptr->x) > dis)
470 if (!attempts_left) {
471 if (cheat_xtra || cheat_hear) {
472 msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
478 if (randint1(5000) <= floor_ptr->dun_level) {
479 if (alloc_horde(player_ptr, y, x, summon_specific)) {
483 if (place_monster(player_ptr, y, x, (mode | PM_ALLOW_GROUP)))