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" */
485 /* Acquire the monster name */
486 monster_desc(m_name, m_ptr, 0);
489 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
492 if (is_original_ap_and_seen(m_ptr))
494 /* Hack -- Count the wakings */
495 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
504 /* Reduce by one, note if expires */
505 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
511 /* Acquire the monster name */
512 monster_desc(m_name, m_ptr, 0);
515 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
521 /* Reduce by one, note if expires */
522 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
528 /* Acquire the monster name */
529 monster_desc(m_name, m_ptr, 0);
532 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
539 int rlev = r_info[m_ptr->r_idx].level;
541 /* Recover from stun */
542 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
544 /* Message if visible */
549 /* Acquire the monster name */
550 monster_desc(m_name, m_ptr, 0);
553 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
559 case MTIMED_CONFUSED:
560 /* Reduce the confusion */
561 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
563 /* Message if visible */
568 /* Acquire the monster name */
569 monster_desc(m_name, m_ptr, 0);
572 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
578 /* Reduce the fear */
579 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
588 /* Acquire the monster possessive */
589 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
592 /* Acquire the monster name */
593 monster_desc(m_name, m_ptr, 0);
597 msg_format("%^sは勇気を取り戻した。", m_name);
599 msg_format("%^s recovers %s courage.", m_name, m_poss);
605 case MTIMED_INVULNER:
606 /* Reduce by one, note if expires */
607 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
613 /* Acquire the monster name */
614 monster_desc(m_name, m_ptr, 0);
617 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
626 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
627 * @param mtimed_idx 更新するモンスターの時限ステータスID
630 * Process the counters of monsters (once per 10 game turns)\n
631 * These functions are to process monsters' counters same as player's.
633 void process_monsters_mtimed(int mtimed_idx)
636 s16b *cur_mproc_list = mproc_list[mtimed_idx];
638 /* Hack -- calculate the "player noise" */
639 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
641 /* Process the monsters (backwards) */
642 for (i = mproc_max[mtimed_idx] - 1; i >= 0; i--)
644 /* Access the monster */
645 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
650 * @brief モンスターへの魔力消去処理
651 * @param m_idx 魔力消去を受けるモンスターの参照ID
654 void dispel_monster_status(MONSTER_IDX m_idx)
656 monster_type *m_ptr = &m_list[m_idx];
659 monster_desc(m_name, m_ptr, 0);
660 if (set_monster_invulner(m_idx, 0, TRUE))
662 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
664 if (set_monster_fast(m_idx, 0))
666 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
668 if (set_monster_slow(m_idx, 0))
670 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
675 * @brief モンスターの時間停止処理
676 * @param num 時間停止を行った敵が行動できる回数
677 * @param who 時間停止処理の主体ID
678 * @param vs_player TRUEならば時間停止開始処理を行う
679 * @return 時間停止が行われている状態ならばTRUEを返す
681 bool process_the_world(int num, MONSTER_IDX who, bool vs_player)
683 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
685 if (world_monster) return (FALSE);
690 monster_desc(m_name, m_ptr, 0);
693 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
695 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
696 else msg_print("hek!");
701 /* This monster cast spells */
702 world_monster = hack_m_idx;
704 if (vs_player) do_cmd_redraw();
708 if (!m_ptr->r_idx) break;
709 process_monster(world_monster);
714 if (p_ptr->notice) notice_stuff();
717 if (p_ptr->update) update_stuff();
720 if (p_ptr->redraw) redraw_stuff();
723 if (p_ptr->window) window_stuff();
726 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
730 p_ptr->redraw |= (PR_MAP);
732 /* Update monsters */
733 p_ptr->update |= (PU_MONSTERS);
736 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
739 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)))
741 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
751 * @brief モンスターの経験値取得処理
752 * @param m_idx 経験値を得るモンスターの参照ID
753 * @param s_idx 撃破されたモンスター種族の参照ID
756 void monster_gain_exp(MONSTER_IDX m_idx, IDX s_idx)
764 if (m_idx <= 0 || s_idx <= 0) return;
766 m_ptr = &m_list[m_idx];
768 /* Paranoia -- Skip dead monsters */
769 if (!m_ptr->r_idx) return;
771 r_ptr = &r_info[m_ptr->r_idx];
772 s_ptr = &r_info[s_idx];
774 if (p_ptr->inside_battle) return;
776 if (!r_ptr->next_exp) return;
778 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
779 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
780 if (!dun_level) new_exp /= 5;
781 m_ptr->exp += new_exp;
782 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
784 if (m_ptr->exp >= r_ptr->next_exp)
787 int old_hp = m_ptr->hp;
788 int old_maxhp = m_ptr->max_maxhp;
789 int old_r_idx = m_ptr->r_idx;
790 byte old_sub_align = m_ptr->sub_align;
792 /* Hack -- Reduce the racial counter of previous monster */
793 real_r_ptr(m_ptr)->cur_num--;
795 monster_desc(m_name, m_ptr, 0);
796 m_ptr->r_idx = r_ptr->next_r_idx;
798 /* Count the monsters on the level */
799 real_r_ptr(m_ptr)->cur_num++;
801 m_ptr->ap_r_idx = m_ptr->r_idx;
802 r_ptr = &r_info[m_ptr->r_idx];
804 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
806 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
810 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
812 if (ironman_nightmare)
814 HIT_POINT hp = m_ptr->max_maxhp * 2L;
815 m_ptr->max_maxhp = MIN(30000, hp);
817 m_ptr->maxhp = m_ptr->max_maxhp;
818 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
820 /* dealt damage is 0 at initial*/
821 m_ptr->dealt_damage = 0;
823 /* Extract the monster base speed */
824 m_ptr->mspeed = get_mspeed(r_ptr);
826 /* Sub-alignment of a monster */
827 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
828 m_ptr->sub_align = old_sub_align;
831 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
832 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
833 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
838 if (is_pet(m_ptr) || m_ptr->ml)
840 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
844 monster_race *hallu_race;
848 hallu_race = &r_info[randint1(max_r_idx - 1)];
849 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
850 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
854 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
858 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
860 /* Now you feel very close to this pet. */
861 m_ptr->parent_m_idx = 0;
863 update_mon(m_idx, FALSE);
864 lite_spot(m_ptr->fy, m_ptr->fx);
866 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;