5 * @brief モンスターの時限ステータスを取得する
6 * @return m_idx モンスターの参照ID
7 * @return mproc_type モンスターの時限ステータスID
10 int get_mproc_idx(MONSTER_IDX m_idx, int mproc_type)
12 s16b *cur_mproc_list = mproc_list[mproc_type];
15 for (i = mproc_max[mproc_type] - 1; i >= 0; i--)
17 if (cur_mproc_list[i] == m_idx) return i;
24 * @brief モンスターの時限ステータスリストを追加する
25 * @return m_idx モンスターの参照ID
26 * @return mproc_type 追加したいモンスターの時限ステータスID
29 static void mproc_add(MONSTER_IDX m_idx, int mproc_type)
31 if (mproc_max[mproc_type] < max_m_idx) mproc_list[mproc_type][mproc_max[mproc_type]++] = (s16b)m_idx;
36 * @brief モンスターの時限ステータスリストを削除
37 * @return m_idx モンスターの参照ID
38 * @return mproc_type 削除したいモンスターの時限ステータスID
41 static void mproc_remove(MONSTER_IDX m_idx, int mproc_type)
43 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
44 if (mproc_idx >= 0) mproc_list[mproc_type][mproc_idx] = mproc_list[mproc_type][--mproc_max[mproc_type]];
49 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
58 /* Reset "mproc_max[]" */
59 for (cmi = 0; cmi < MAX_MTIMED; cmi++) mproc_max[cmi] = 0;
61 /* Process the monsters (backwards) */
62 for (i = m_max - 1; i >= 1; i--)
64 /* Access the monster */
67 /* Ignore "dead" monsters */
68 if (!m_ptr->r_idx) continue;
70 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
72 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
79 * @brief モンスターの睡眠状態値をセットする /
80 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
81 * @param m_idx モンスター参照ID
83 * @return 別途更新処理が必要な場合TRUEを返す
85 bool set_monster_csleep(MONSTER_IDX m_idx, int v)
87 monster_type *m_ptr = &m_list[m_idx];
90 /* Hack -- Force good values */
91 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
96 if (!MON_CSLEEP(m_ptr))
98 mproc_add(m_idx, MTIMED_CSLEEP);
106 if (MON_CSLEEP(m_ptr))
108 mproc_remove(m_idx, MTIMED_CSLEEP);
114 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
116 if (!notice) return FALSE;
120 /* Update health bar as needed */
121 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
122 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
125 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
132 * @brief モンスターの加速状態値をセット /
133 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
134 * @param m_idx モンスター参照ID
136 * @return 別途更新処理が必要な場合TRUEを返す
138 bool set_monster_fast(MONSTER_IDX m_idx, int v)
140 monster_type *m_ptr = &m_list[m_idx];
143 /* Hack -- Force good values */
144 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
149 if (!MON_FAST(m_ptr))
151 mproc_add(m_idx, MTIMED_FAST);
161 mproc_remove(m_idx, MTIMED_FAST);
167 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
169 if (!notice) return FALSE;
171 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
178 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
180 bool set_monster_slow(MONSTER_IDX m_idx, int v)
182 monster_type *m_ptr = &m_list[m_idx];
185 /* Hack -- Force good values */
186 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
191 if (!MON_SLOW(m_ptr))
193 mproc_add(m_idx, MTIMED_SLOW);
203 mproc_remove(m_idx, MTIMED_SLOW);
209 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
211 if (!notice) return FALSE;
213 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
220 * @brief モンスターの朦朧状態値をセット /
221 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
222 * @param m_idx モンスター参照ID
224 * @return 別途更新処理が必要な場合TRUEを返す
226 bool set_monster_stunned(MONSTER_IDX m_idx, int v)
228 monster_type *m_ptr = &m_list[m_idx];
231 /* Hack -- Force good values */
232 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
237 if (!MON_STUNNED(m_ptr))
239 mproc_add(m_idx, MTIMED_STUNNED);
247 if (MON_STUNNED(m_ptr))
249 mproc_remove(m_idx, MTIMED_STUNNED);
255 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
262 * @brief モンスターの混乱状態値をセット /
263 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
264 * @param m_idx モンスター参照ID
266 * @return 別途更新処理が必要な場合TRUEを返す
268 bool set_monster_confused(MONSTER_IDX m_idx, int v)
270 monster_type *m_ptr = &m_list[m_idx];
273 /* Hack -- Force good values */
274 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
279 if (!MON_CONFUSED(m_ptr))
281 mproc_add(m_idx, MTIMED_CONFUSED);
289 if (MON_CONFUSED(m_ptr))
291 mproc_remove(m_idx, MTIMED_CONFUSED);
297 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
304 * @brief モンスターの恐慌状態値をセット /
305 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
306 * @param m_idx モンスター参照ID
308 * @return 別途更新処理が必要な場合TRUEを返す
310 bool set_monster_monfear(MONSTER_IDX m_idx, int v)
312 monster_type *m_ptr = &m_list[m_idx];
315 /* Hack -- Force good values */
316 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
321 if (!MON_MONFEAR(m_ptr))
323 mproc_add(m_idx, MTIMED_MONFEAR);
331 if (MON_MONFEAR(m_ptr))
333 mproc_remove(m_idx, MTIMED_MONFEAR);
339 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
341 if (!notice) return FALSE;
345 /* Update health bar as needed */
346 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
347 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
355 * @brief モンスターの無敵状態値をセット /
356 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
357 * @param m_idx モンスター参照ID
359 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
360 * @return 別途更新処理が必要な場合TRUEを返す
362 bool set_monster_invulner(MONSTER_IDX m_idx, int v, bool energy_need)
364 monster_type *m_ptr = &m_list[m_idx];
367 /* Hack -- Force good values */
368 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
373 if (!MON_INVULNER(m_ptr))
375 mproc_add(m_idx, MTIMED_INVULNER);
383 if (MON_INVULNER(m_ptr))
385 mproc_remove(m_idx, MTIMED_INVULNER);
386 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
392 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
394 if (!notice) return FALSE;
398 /* Update health bar as needed */
399 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
400 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
407 static u32b csleep_noise;
410 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
411 * @param m_idx モンスター参照ID
412 * @param mtimed_idx 更新するモンスターの時限ステータスID
415 static void process_monsters_mtimed_aux(MONSTER_IDX m_idx, int mtimed_idx)
417 monster_type *m_ptr = &m_list[m_idx];
423 monster_race *r_ptr = &r_info[m_ptr->r_idx];
425 /* Assume does not wake up */
428 /* Hack -- Require proximity */
429 if (m_ptr->cdis < AAF_LIMIT)
431 /* Handle "sensing radius" */
432 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
438 /* Handle "sight" and "aggravation" */
439 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
448 u32b notice = randint0(1024);
450 /* Nightmare monsters are more alert */
451 if (ironman_nightmare) notice /= 2;
453 /* Hack -- See if monster "notices" player */
454 if ((notice * notice * notice) <= csleep_noise)
456 /* Hack -- amount of "waking" */
457 /* Wake up faster near the player */
458 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
460 /* Hack -- amount of "waking" is affected by speed of player */
461 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
464 /* Monster wakes up "a little bit" */
467 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
469 /* Notice the "not waking up" */
470 if (is_original_ap_and_seen(m_ptr))
472 /* Hack -- Count the ignores */
473 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
480 /* Notice the "waking up" */
483 GAME_TEXT m_name[MAX_NLEN];
484 monster_desc(m_name, m_ptr, 0);
485 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
488 if (is_original_ap_and_seen(m_ptr))
490 /* Hack -- Count the wakings */
491 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
500 /* Reduce by one, note if expires */
501 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
505 GAME_TEXT m_name[MAX_NLEN];
506 monster_desc(m_name, m_ptr, 0);
507 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
513 /* Reduce by one, note if expires */
514 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
518 GAME_TEXT m_name[MAX_NLEN];
519 monster_desc(m_name, m_ptr, 0);
520 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
527 int rlev = r_info[m_ptr->r_idx].level;
529 /* Recover from stun */
530 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
532 /* Message if visible */
535 GAME_TEXT m_name[MAX_NLEN];
536 monster_desc(m_name, m_ptr, 0);
537 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
543 case MTIMED_CONFUSED:
544 /* Reduce the confusion */
545 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
547 /* Message if visible */
550 GAME_TEXT m_name[MAX_NLEN];
551 monster_desc(m_name, m_ptr, 0);
552 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
558 /* Reduce the fear */
559 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
564 GAME_TEXT m_name[MAX_NLEN];
568 /* Acquire the monster possessive */
569 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
571 monster_desc(m_name, m_ptr, 0);
573 msg_format("%^sは勇気を取り戻した。", m_name);
575 msg_format("%^s recovers %s courage.", m_name, m_poss);
581 case MTIMED_INVULNER:
582 /* Reduce by one, note if expires */
583 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
587 GAME_TEXT m_name[MAX_NLEN];
588 monster_desc(m_name, m_ptr, 0);
589 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
598 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
599 * @param mtimed_idx 更新するモンスターの時限ステータスID
602 * Process the counters of monsters (once per 10 game turns)\n
603 * These functions are to process monsters' counters same as player's.
605 void process_monsters_mtimed(int mtimed_idx)
608 s16b *cur_mproc_list = mproc_list[mtimed_idx];
610 /* Hack -- calculate the "player noise" */
611 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
613 /* Process the monsters (backwards) */
614 for (i = mproc_max[mtimed_idx] - 1; i >= 0; i--)
616 /* Access the monster */
617 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
622 * @brief モンスターへの魔力消去処理
623 * @param m_idx 魔力消去を受けるモンスターの参照ID
626 void dispel_monster_status(MONSTER_IDX m_idx)
628 monster_type *m_ptr = &m_list[m_idx];
629 GAME_TEXT m_name[MAX_NLEN];
631 monster_desc(m_name, m_ptr, 0);
632 if (set_monster_invulner(m_idx, 0, TRUE))
634 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
636 if (set_monster_fast(m_idx, 0))
638 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
640 if (set_monster_slow(m_idx, 0))
642 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
647 * @brief モンスターの時間停止処理
648 * @param num 時間停止を行った敵が行動できる回数
649 * @param who 時間停止処理の主体ID
650 * @param vs_player TRUEならば時間停止開始処理を行う
651 * @return 時間停止が行われている状態ならばTRUEを返す
653 bool process_the_world(int num, MONSTER_IDX who, bool vs_player)
655 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
657 if (world_monster) return (FALSE);
661 GAME_TEXT m_name[MAX_NLEN];
662 monster_desc(m_name, m_ptr, 0);
665 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
667 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
668 else msg_print("hek!");
673 /* This monster cast spells */
674 world_monster = hack_m_idx;
676 if (vs_player) do_cmd_redraw();
680 if (!m_ptr->r_idx) break;
681 process_monster(world_monster);
685 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
688 p_ptr->redraw |= (PR_MAP);
689 p_ptr->update |= (PU_MONSTERS);
690 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
693 if (vs_player || (player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)))
695 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
704 * @brief モンスターの経験値取得処理
705 * @param m_idx 経験値を得るモンスターの参照ID
706 * @param s_idx 撃破されたモンスター種族の参照ID
709 void monster_gain_exp(MONSTER_IDX m_idx, IDX s_idx)
717 if (m_idx <= 0 || s_idx <= 0) return;
719 m_ptr = &m_list[m_idx];
721 /* Paranoia -- Skip dead monsters */
722 if (!m_ptr->r_idx) return;
724 r_ptr = &r_info[m_ptr->r_idx];
725 s_ptr = &r_info[s_idx];
727 if (p_ptr->inside_battle) return;
729 if (!r_ptr->next_exp) return;
731 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
732 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
733 if (!dun_level) new_exp /= 5;
734 m_ptr->exp += new_exp;
735 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
737 if (m_ptr->exp >= r_ptr->next_exp)
739 GAME_TEXT m_name[MAX_NLEN];
740 int old_hp = m_ptr->hp;
741 int old_maxhp = m_ptr->max_maxhp;
742 int old_r_idx = m_ptr->r_idx;
743 byte old_sub_align = m_ptr->sub_align;
745 /* Hack -- Reduce the racial counter of previous monster */
746 real_r_ptr(m_ptr)->cur_num--;
748 monster_desc(m_name, m_ptr, 0);
749 m_ptr->r_idx = r_ptr->next_r_idx;
751 /* Count the monsters on the level */
752 real_r_ptr(m_ptr)->cur_num++;
754 m_ptr->ap_r_idx = m_ptr->r_idx;
755 r_ptr = &r_info[m_ptr->r_idx];
757 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
759 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
763 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
765 if (ironman_nightmare)
767 HIT_POINT hp = m_ptr->max_maxhp * 2L;
768 m_ptr->max_maxhp = MIN(30000, hp);
770 m_ptr->maxhp = m_ptr->max_maxhp;
771 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
773 /* dealt damage is 0 at initial*/
774 m_ptr->dealt_damage = 0;
776 /* Extract the monster base speed */
777 m_ptr->mspeed = get_mspeed(r_ptr);
779 /* Sub-alignment of a monster */
780 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
781 m_ptr->sub_align = old_sub_align;
784 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
785 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
786 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
791 if (is_pet(m_ptr) || m_ptr->ml)
793 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
797 monster_race *hallu_race;
801 hallu_race = &r_info[randint1(max_r_idx - 1)];
802 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
803 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
807 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
811 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
813 /* Now you feel very close to this pet. */
814 m_ptr->parent_m_idx = 0;
816 update_monster(m_idx, FALSE);
817 lite_spot(m_ptr->fy, m_ptr->fx);
819 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;