2 * @brief モンスターをフロアに1体配置する処理
7 #include "monster-floor/one-monster-placer.h"
8 #include "core/player-update-types.h"
9 #include "core/speed-table.h"
10 #include "dungeon/quest.h"
11 #include "effect/attribute-types.h"
12 #include "effect/effect-characteristics.h"
13 #include "effect/effect-processor.h"
14 #include "flavor/flavor-describer.h"
15 #include "flavor/object-flavor-types.h"
16 #include "floor/cave.h"
17 #include "floor/floor-save-util.h"
18 #include "game-option/birth-options.h"
19 #include "game-option/cheat-types.h"
20 #include "grid/grid.h"
21 #include "monster-attack/monster-attack-types.h"
22 #include "monster-floor/monster-move.h"
23 #include "monster-floor/monster-summon.h"
24 #include "monster-floor/place-monster-types.h"
25 #include "monster-race/monster-race.h"
26 #include "monster-race/race-flags1.h"
27 #include "monster-race/race-flags2.h"
28 #include "monster-race/race-flags3.h"
29 #include "monster-race/race-flags7.h"
30 #include "monster-race/race-indice-types.h"
31 #include "monster/monster-flag-types.h"
32 #include "monster/monster-info.h"
33 #include "monster/monster-list.h"
34 #include "monster/monster-status-setter.h"
35 #include "monster/monster-status.h"
36 #include "monster/monster-update.h"
37 #include "monster/monster-util.h"
38 #include "object/warning.h"
39 #include "player/player-status.h"
40 #include "system/floor-type-definition.h"
41 #include "system/grid-type-definition.h"
42 #include "system/monster-race-definition.h"
43 #include "system/player-type-definition.h"
44 #include "util/bit-flags-calculator.h"
45 #include "view/display-messages.h"
46 #include "wizard/wizard-messages.h"
47 #include "world/world.h"
49 static bool is_friendly_idx(PlayerType *player_ptr, MONSTER_IDX m_idx)
51 return m_idx > 0 && is_friendly(&player_ptr->current_floor_ptr->m_list[(m_idx)]);
55 * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
56 * @param r_idx モンスター種族ID
57 * @return 対象にできるならtrueを返す
58 * @todo グローバル変数対策の上 monster_hook.cへ移す。
60 static bool monster_hook_tanuki(PlayerType *player_ptr, MONRACE_IDX r_idx)
62 monster_race *r_ptr = &r_info[r_idx];
63 bool unselectable = any_bits(r_ptr->flags1, RF1_UNIQUE);
64 unselectable |= any_bits(r_ptr->flags2, RF2_MULTIPLY);
65 unselectable |= r_ptr->behavior_flags.has(MonsterBehaviorType::FRIENDLY);
66 unselectable |= any_bits(r_ptr->flags7, RF7_AQUATIC | RF7_CHAMELEON);
70 for (int i = 0; i < 4; i++)
71 if (r_ptr->blow[i].method == RaceBlowMethodType::EXPLODE)
74 return (*(get_monster_hook(player_ptr)))(player_ptr, r_idx);
78 * @param player_ptr プレイヤーへの参照ポインタ
79 * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
80 * @param r_idx モンスター種族ID
81 * @return モンスター種族の表層ID
83 static MONRACE_IDX initial_r_appearance(PlayerType *player_ptr, MONRACE_IDX r_idx, BIT_FLAGS generate_mode)
85 auto *floor_ptr = player_ptr->current_floor_ptr;
86 if (is_chargeman(player_ptr) && any_bits(generate_mode, PM_JURAL) && none_bits(generate_mode, PM_MULTIPLY | PM_KAGE))
87 return MON_ALIEN_JURAL;
89 if (none_bits(r_info[r_idx].flags7, RF7_TANUKI))
92 get_mon_num_prep(player_ptr, monster_hook_tanuki, nullptr);
94 DEPTH min = std::min(floor_ptr->base_level - 5, 50);
96 MONRACE_IDX ap_r_idx = get_mon_num(player_ptr, 0, floor_ptr->base_level + 10, 0);
97 if (r_info[ap_r_idx].level >= min)
105 * @brief ユニークが生成可能か評価する
106 * @param player_ptr プレイヤーへの参照ポインタ
107 * @param r_idx 生成モンスター種族
108 * @return ユニークの生成が不可能な条件ならFALSE、それ以外はTRUE
110 static bool check_unique_placeable(PlayerType *player_ptr, MONRACE_IDX r_idx)
112 if (player_ptr->phase_out)
115 monster_race *r_ptr = &r_info[r_idx];
116 if ((any_bits(r_ptr->flags1, RF1_UNIQUE) || any_bits(r_ptr->flags7, RF7_NAZGUL)) && (r_ptr->cur_num >= r_ptr->max_num)) {
120 if (any_bits(r_ptr->flags7, RF7_UNIQUE2) && (r_ptr->cur_num >= 1)) {
124 if (r_idx == MON_BANORLUPART) {
125 if (r_info[MON_BANOR].cur_num > 0)
127 if (r_info[MON_LUPART].cur_num > 0)
131 if (any_bits(r_ptr->flags1, RF1_FORCE_DEPTH) && (player_ptr->current_floor_ptr->dun_level < r_ptr->level) && (!ironman_nightmare || any_bits(r_ptr->flags1, RF1_QUESTOR))) {
139 * @brief クエスト内に生成可能か評価する
140 * @param player_ptr プレイヤーへの参照ポインタ
141 * @param r_idx 生成モンスター種族
142 * @return 生成が可能ならTRUE、不可能ならFALSE
144 static bool check_quest_placeable(PlayerType *player_ptr, MONRACE_IDX r_idx)
146 auto *floor_ptr = player_ptr->current_floor_ptr;
147 if (!inside_quest(quest_number(player_ptr, floor_ptr->dun_level)))
150 QuestId hoge = quest_number(player_ptr, floor_ptr->dun_level);
151 if ((quest[enum2i(hoge)].type != QuestKindType::KILL_LEVEL) && (quest[enum2i(hoge)].type != QuestKindType::RANDOM))
154 if (r_idx != quest[enum2i(hoge)].r_idx)
158 for (int i2 = 0; i2 < floor_ptr->width; ++i2)
159 for (int j2 = 0; j2 < floor_ptr->height; j2++)
160 if ((floor_ptr->grid_array[j2][i2].m_idx > 0) && (floor_ptr->m_list[floor_ptr->grid_array[j2][i2].m_idx].r_idx == quest[enum2i(hoge)].r_idx))
163 if (number_mon + quest[enum2i(hoge)].cur_num >= quest[enum2i(hoge)].max_num)
170 * @brief 守りのルーン上にモンスターの配置を試みる
171 * @param player_ptr プレイヤーへの参照ポインタ
172 * @param r_idx 生成モンスター種族
175 * @return 生成が可能ならTRUE、不可能ならFALSE
177 static bool check_procection_rune(PlayerType *player_ptr, MONRACE_IDX r_idx, POSITION y, POSITION x)
179 grid_type *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
180 if (!g_ptr->is_rune_protection())
183 monster_race *r_ptr = &r_info[r_idx];
184 if (randint1(BREAK_RUNE_PROTECTION) >= (r_ptr->level + 20))
187 if (any_bits(g_ptr->info, CAVE_MARK))
188 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
190 reset_bits(g_ptr->info, CAVE_MARK);
191 reset_bits(g_ptr->info, CAVE_OBJECT);
193 note_spot(player_ptr, y, x);
197 static void warn_unique_generation(PlayerType *player_ptr, MONRACE_IDX r_idx)
199 if (!player_ptr->warning || !w_ptr->character_dungeon)
202 monster_race *r_ptr = &r_info[r_idx];
203 if (none_bits(r_ptr->flags1, RF1_UNIQUE))
208 GAME_TEXT o_name[MAX_NLEN];
209 if (r_ptr->level > player_ptr->lev + 30)
210 color = _("黒く", "black");
211 else if (r_ptr->level > player_ptr->lev + 15)
212 color = _("紫色に", "purple");
213 else if (r_ptr->level > player_ptr->lev + 5)
214 color = _("ルビー色に", "deep red");
215 else if (r_ptr->level > player_ptr->lev - 5)
216 color = _("赤く", "red");
217 else if (r_ptr->level > player_ptr->lev - 15)
218 color = _("ピンク色に", "pink");
220 color = _("白く", "white");
222 o_ptr = choose_warning_item(player_ptr);
223 if (o_ptr != nullptr) {
224 describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
225 msg_format(_("%sは%s光った。", "%s glows %s."), o_name, color);
227 msg_format(_("%s光る物が頭に浮かんだ。", "A %s image forms in your mind."), color);
232 * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
233 * @param player_ptr プレイヤーへの参照ポインタ
234 * @param who 召喚を行ったモンスターID
237 * @param r_idx 生成モンスター種族
238 * @param mode 生成オプション
241 bool place_monster_one(PlayerType *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
243 auto *floor_ptr = player_ptr->current_floor_ptr;
244 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
245 monster_race *r_ptr = &r_info[r_idx];
246 concptr name = r_ptr->name.c_str();
248 if (player_ptr->wild_mode || !in_bounds(floor_ptr, y, x) || (r_idx == 0) || r_ptr->name.empty())
251 if (none_bits(mode, PM_IGNORE_TERRAIN) && (pattern_tile(floor_ptr, y, x) || !monster_can_enter(player_ptr, y, x, r_ptr, 0)))
254 if (!check_unique_placeable(player_ptr, r_idx) || !check_quest_placeable(player_ptr, r_idx) || !check_procection_rune(player_ptr, r_idx, y, x))
257 msg_format_wizard(player_ptr, CHEAT_MONSTER, _("%s(Lv%d)を生成しました。", "%s(Lv%d) was generated."), name, r_ptr->level);
258 if (any_bits(r_ptr->flags1, RF1_UNIQUE) || any_bits(r_ptr->flags7, RF7_NAZGUL) || (r_ptr->level < 10))
259 reset_bits(mode, PM_KAGE);
261 g_ptr->m_idx = m_pop(floor_ptr);
262 hack_m_idx_ii = g_ptr->m_idx;
267 m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
268 m_ptr->r_idx = r_idx;
269 m_ptr->ap_r_idx = initial_r_appearance(player_ptr, r_idx, mode);
271 m_ptr->mflag.clear();
272 m_ptr->mflag2.clear();
273 if (any_bits(mode, PM_MULTIPLY) && (who > 0) && !is_original_ap(&floor_ptr->m_list[who])) {
274 m_ptr->ap_r_idx = floor_ptr->m_list[who].ap_r_idx;
275 if (floor_ptr->m_list[who].mflag2.has(MonsterConstantFlagType::KAGE))
276 m_ptr->mflag2.set(MonsterConstantFlagType::KAGE);
279 if ((who > 0) && none_bits(r_ptr->flags3, RF3_EVIL | RF3_GOOD))
280 m_ptr->sub_align = floor_ptr->m_list[who].sub_align;
282 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
283 if (any_bits(r_ptr->flags3, RF3_EVIL))
284 set_bits(m_ptr->sub_align, SUB_ALIGN_EVIL);
285 if (any_bits(r_ptr->flags3, RF3_GOOD))
286 set_bits(m_ptr->sub_align, SUB_ALIGN_GOOD);
291 m_ptr->current_floor_ptr = floor_ptr;
293 for (int cmi = 0; cmi < MAX_MTIMED; cmi++)
294 m_ptr->mtimed[cmi] = 0;
301 if (who > 0 && is_pet(&floor_ptr->m_list[who])) {
302 set_bits(mode, PM_FORCE_PET);
303 m_ptr->parent_m_idx = who;
305 m_ptr->parent_m_idx = 0;
308 if (any_bits(r_ptr->flags7, RF7_CHAMELEON)) {
309 choose_new_monster(player_ptr, g_ptr->m_idx, true, 0);
310 r_ptr = &r_info[m_ptr->r_idx];
311 m_ptr->mflag2.set(MonsterConstantFlagType::CHAMELEON);
312 if (any_bits(r_ptr->flags1, RF1_UNIQUE) && (who <= 0))
313 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
314 } else if (any_bits(mode, PM_KAGE) && none_bits(mode, PM_FORCE_PET)) {
315 m_ptr->ap_r_idx = MON_KAGE;
316 m_ptr->mflag2.set(MonsterConstantFlagType::KAGE);
319 if (any_bits(mode, PM_CLONE))
320 m_ptr->mflag2.set(MonsterConstantFlagType::CLONED);
322 if (any_bits(mode, PM_NO_PET))
323 m_ptr->mflag2.set(MonsterConstantFlagType::NOPET);
326 if (any_bits(mode, PM_FORCE_PET)) {
327 set_pet(player_ptr, m_ptr);
328 } else if (((who == 0) && r_ptr->behavior_flags.has(MonsterBehaviorType::FRIENDLY)) || is_friendly_idx(player_ptr, who) || any_bits(mode, PM_FORCE_FRIENDLY)) {
329 if (!monster_has_hostile_align(player_ptr, nullptr, 0, -1, r_ptr) && !player_ptr->current_floor_ptr->inside_arena)
333 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
334 if (any_bits(mode, PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare) {
335 int val = r_ptr->sleep;
336 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, (val * 2) + randint1(val * 10));
339 if (any_bits(r_ptr->flags1, RF1_FORCE_MAXHP)) {
340 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
342 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
345 if (ironman_nightmare) {
346 auto hp = m_ptr->max_maxhp * 2;
347 m_ptr->max_maxhp = std::min(MONSTER_MAXHP, hp);
350 m_ptr->maxhp = m_ptr->max_maxhp;
351 if (r_ptr->cur_hp_per != 0) {
352 m_ptr->hp = m_ptr->maxhp * r_ptr->cur_hp_per / 100;
354 m_ptr->hp = m_ptr->maxhp;
357 m_ptr->dealt_damage = 0;
359 m_ptr->mspeed = get_mspeed(floor_ptr, r_ptr);
361 if (any_bits(mode, PM_HASTE))
362 (void)set_monster_fast(player_ptr, g_ptr->m_idx, 100);
364 if (!ironman_nightmare) {
365 m_ptr->energy_need = ENERGY_NEED() - (int16_t)randint0(100);
367 m_ptr->energy_need = ENERGY_NEED() - (int16_t)randint0(100) * 2;
370 if (r_ptr->behavior_flags.has(MonsterBehaviorType::PREVENT_SUDDEN_MAGIC) && !ironman_nightmare) {
371 m_ptr->mflag.set(MonsterTemporaryFlagType::PREVENT_MAGIC);
374 if (g_ptr->m_idx < hack_m_idx) {
375 m_ptr->mflag.set(MonsterTemporaryFlagType::BORN);
378 if (any_bits(r_ptr->flags7, RF7_SELF_LD_MASK))
379 set_bits(player_ptr->update, PU_MON_LITE);
380 else if (any_bits(r_ptr->flags7, RF7_HAS_LD_MASK) && !monster_csleep_remaining(m_ptr))
381 set_bits(player_ptr->update, PU_MON_LITE);
382 update_monster(player_ptr, g_ptr->m_idx, true);
384 real_r_ptr(m_ptr)->cur_num++;
387 * Memorize location of the unique monster in saved floors.
388 * A unique monster move from old saved floor.
390 if (w_ptr->character_dungeon && (any_bits(r_ptr->flags1, RF1_UNIQUE) || any_bits(r_ptr->flags7, RF7_NAZGUL)))
391 real_r_ptr(m_ptr)->floor_id = player_ptr->floor_id;
393 if (any_bits(r_ptr->flags2, RF2_MULTIPLY))
394 floor_ptr->num_repro++;
396 warn_unique_generation(player_ptr, r_idx);
397 if (!g_ptr->is_rune_explosion())
400 if (randint1(BREAK_RUNE_EXPLOSION) > r_ptr->level) {
401 if (any_bits(g_ptr->info, CAVE_MARK)) {
402 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
403 project(player_ptr, 0, 2, y, x, 2 * (player_ptr->lev + damroll(7, 7)), AttributeType::MANA,
404 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI));
407 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
410 reset_bits(g_ptr->info, CAVE_MARK);
411 reset_bits(g_ptr->info, CAVE_OBJECT);
414 note_spot(player_ptr, y, x);
415 lite_spot(player_ptr, y, x);