3 * @brief モンスター処理 / misc code for monsters
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7 * This software may be copied and distributed for educational, research,
8 * and not for profit purposes provided that this copyright and statement
9 * are included in all such copies. Other copyrights may also apply.
10 * 2014 Deskull rearranged comment for Doxygen.
20 #include "object-flavor.h"
21 #include "monsterrace-hook.h"
22 #include "monster-status.h"
25 #include "spells-summon.h"
28 #include "player-move.h"
29 #include "player-status.h"
30 #include "player-race.h"
33 #include "monster-spell.h"
35 #include "view-mainwindow.h"
37 #include "monsterrace.h"
39 #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */
40 #define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */
44 * @brief モンスターの目標地点をセットする / Set the target of counter attack
45 * @param m_ptr モンスターの参照ポインタ
50 void set_target(monster_type *m_ptr, POSITION y, POSITION x)
58 * @brief モンスターの目標地点をリセットする / Reset the target of counter attack
59 * @param m_ptr モンスターの参照ポインタ
62 void reset_target(monster_type *m_ptr)
64 set_target(m_ptr, 0, 0);
69 * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form
70 * @param m_ptr モンスターの参照ポインタ
71 * @return 本当のモンスター種族参照ポインタ
73 monster_race *real_r_ptr(monster_type *m_ptr)
75 return &r_info[real_r_idx(m_ptr)];
78 MONRACE_IDX real_r_idx(monster_type *m_ptr)
80 monster_race *r_ptr = &r_info[m_ptr->r_idx];
82 /* Extract real race */
83 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
85 if (r_ptr->flags1 & RF1_UNIQUE)
86 return MON_CHAMELEON_K;
98 * @brief モンスター配列からモンスターを消去する / Delete a monster by index.
99 * @param i 消去するモンスターのID
102 * モンスターを削除するとそのモンスターが拾っていたアイテムも同時に削除される。 /
103 * When a monster is deleted, all of its objects are deleted.
105 void delete_monster_idx(MONSTER_IDX i)
108 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
109 monster_race *r_ptr = &r_info[m_ptr->r_idx];
110 OBJECT_IDX this_o_idx, next_o_idx = 0;
115 /* Hack -- Reduce the racial counter */
116 real_r_ptr(m_ptr)->cur_num--;
118 /* Hack -- count the number of "reproducers" */
119 if (r_ptr->flags2 & (RF2_MULTIPLY)) current_floor_ptr->num_repro--;
121 if (MON_CSLEEP(m_ptr)) (void)set_monster_csleep(i, 0);
122 if (MON_FAST(m_ptr)) (void)set_monster_fast(i, 0);
123 if (MON_SLOW(m_ptr)) (void)set_monster_slow(i, 0);
124 if (MON_STUNNED(m_ptr)) (void)set_monster_stunned(i, 0);
125 if (MON_CONFUSED(m_ptr)) (void)set_monster_confused(i, 0);
126 if (MON_MONFEAR(m_ptr)) (void)set_monster_monfear(i, 0);
127 if (MON_INVULNER(m_ptr)) (void)set_monster_invulner(i, 0, FALSE);
129 /* Hack -- remove target monster */
130 if (i == target_who) target_who = 0;
132 /* Hack -- remove tracked monster */
133 if (i == p_ptr->health_who) health_track(0);
135 if (pet_t_m_idx == i ) pet_t_m_idx = 0;
136 if (riding_t_m_idx == i) riding_t_m_idx = 0;
137 if (p_ptr->riding == i) p_ptr->riding = 0;
139 /* Monster is gone */
140 current_floor_ptr->grid_array[y][x].m_idx = 0;
142 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
145 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
146 next_o_idx = o_ptr->next_o_idx;
149 * o_ptr->held_m_idx is needed in delete_object_idx()
150 * to prevent calling lite_spot()
153 delete_object_idx(this_o_idx);
156 (void)WIPE(m_ptr, monster_type);
159 current_floor_ptr->m_cnt--;
162 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
164 p_ptr->update |= (PU_MON_LITE);
170 * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
175 void delete_monster(POSITION y, POSITION x)
178 if (!in_bounds(y, x)) return;
181 g_ptr = ¤t_floor_ptr->grid_array[y][x];
183 /* Delete the monster (if any) */
184 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
189 * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
194 static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
200 OBJECT_IDX this_o_idx, next_o_idx = 0;
203 if (i1 == i2) return;
206 m_ptr = ¤t_floor_ptr->m_list[i1];
212 g_ptr = ¤t_floor_ptr->grid_array[y][x];
214 /* Update the current_floor_ptr->grid_array */
217 /* Repair objects being carried by monster */
218 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
221 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
222 next_o_idx = o_ptr->next_o_idx;
224 /* Reset monster pointer */
225 o_ptr->held_m_idx = i2;
228 /* Hack -- Update the target */
229 if (target_who == i1) target_who = i2;
231 /* Hack -- Update the target */
232 if (pet_t_m_idx == i1) pet_t_m_idx = i2;
233 if (riding_t_m_idx == i1) riding_t_m_idx = i2;
235 /* Hack -- Update the riding */
236 if (p_ptr->riding == i1) p_ptr->riding = i2;
238 /* Hack -- Update the health bar */
239 if (p_ptr->health_who == i1) health_track(i2);
241 /* Hack -- Update parent index */
244 for (i = 1; i < current_floor_ptr->m_max; i++)
246 monster_type *m2_ptr = ¤t_floor_ptr->m_list[i];
248 if (m2_ptr->parent_m_idx == i1)
249 m2_ptr->parent_m_idx = i2;
254 (void)COPY(¤t_floor_ptr->m_list[i2], ¤t_floor_ptr->m_list[i1], monster_type);
257 (void)WIPE(¤t_floor_ptr->m_list[i1], monster_type);
259 for (i = 0; i < MAX_MTIMED; i++)
261 int mproc_idx = get_mproc_idx(i1, i);
262 if (mproc_idx >= 0) current_floor_ptr->mproc_list[i][mproc_idx] = i2;
268 * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
269 * @param size 圧縮後のモンスター件数目標
272 * This function can be very dangerous, use with caution!
274 * When actually "compacting" monsters, we base the saving throw
275 * on a combination of monster level, distance from player, and
276 * current "desperation".
278 * After "compacting" (if needed), we "reorder" the monsters into a more
279 * compact order, and we reset the allocation info, and the "live" array.
281 void compact_monsters(int size)
285 int cur_lev, cur_dis, chance;
287 /* Message (only if compacting) */
288 if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
291 /* Compact at least 'size' objects */
292 for (num = 0, cnt = 1; num < size; cnt++)
294 /* Get more vicious each iteration */
297 /* Get closer each iteration */
298 cur_dis = 5 * (20 - cnt);
300 /* Check all the monsters */
301 for (i = 1; i < current_floor_ptr->m_max; i++)
303 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
305 monster_race *r_ptr = &r_info[m_ptr->r_idx];
307 /* Paranoia -- skip "dead" monsters */
308 if (!monster_is_valid(m_ptr)) continue;
310 /* Hack -- High level monsters start out "immune" */
311 if (r_ptr->level > cur_lev) continue;
313 if (i == p_ptr->riding) continue;
315 /* Ignore nearby monsters */
316 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
318 /* Saving throw chance */
321 /* Only compact "Quest" Monsters in emergencies */
322 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
324 /* Try not to compact Unique Monsters */
325 if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
327 /* All monsters get a saving throw */
328 if (randint0(100) < chance) continue;
330 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
332 GAME_TEXT m_name[MAX_NLEN];
333 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
334 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
337 delete_monster_idx(i);
339 /* Count the monster */
345 /* Excise dead monsters (backwards!) */
346 for (i = current_floor_ptr->m_max - 1; i >= 1; i--)
348 /* Get the i'th monster */
349 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
351 /* Skip real monsters */
352 if (m_ptr->r_idx) continue;
354 /* Move last monster into open hole */
355 compact_monsters_aux(current_floor_ptr->m_max - 1, i);
357 /* Compress "current_floor_ptr->m_max" */
358 current_floor_ptr->m_max--;
364 * @brief プレイヤーのフロア離脱に伴う全モンスター配列の消去 / Delete/Remove all the monsters when the player leaves the level
367 * This is an efficient method of simulating multiple calls to the
368 * "delete_monster()" function, with no visual effects.
370 void wipe_m_list(void)
374 /* Hack -- if Banor or Lupart dies, stay another dead */
375 if (!r_info[MON_BANORLUPART].max_num)
377 if (r_info[MON_BANOR].max_num)
379 r_info[MON_BANOR].max_num = 0;
380 r_info[MON_BANOR].r_pkills++;
381 r_info[MON_BANOR].r_akills++;
382 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
384 if (r_info[MON_LUPART].max_num)
386 r_info[MON_LUPART].max_num = 0;
387 r_info[MON_LUPART].r_pkills++;
388 r_info[MON_LUPART].r_akills++;
389 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
393 /* Delete all the monsters */
394 for (i = current_floor_ptr->m_max - 1; i >= 1; i--)
396 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
397 if (!monster_is_valid(m_ptr)) continue;
399 /* Monster is gone */
400 current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx = 0;
402 (void)WIPE(m_ptr, monster_type);
407 * Wiping racial counters of all monsters and incrementing of racial
408 * counters of monsters in party_mon[] are required to prevent multiple
409 * generation of unique monster who is the minion of player.
412 /* Hack -- Wipe the racial counter of all monster races */
413 for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
415 /* Reset "current_floor_ptr->m_max" */
416 current_floor_ptr->m_max = 1;
418 /* Reset "current_floor_ptr->m_cnt" */
419 current_floor_ptr->m_cnt = 0;
421 /* Reset "current_floor_ptr->mproc_max[]" */
422 for (i = 0; i < MAX_MTIMED; i++) current_floor_ptr->mproc_max[i] = 0;
424 /* Hack -- reset "reproducer" count */
425 current_floor_ptr->num_repro = 0;
427 /* Hack -- no more target */
432 /* Hack -- no more tracking */
438 * @brief モンスター配列の空きを探す / Acquires and returns the index of a "free" monster.
439 * @return 利用可能なモンスター配列の添字
441 * This routine should almost never fail, but it *can* happen.
443 MONSTER_IDX m_pop(void)
447 /* Normal allocation */
448 if (current_floor_ptr->m_max < current_floor_ptr->max_m_idx)
450 /* Access the next hole */
451 i = current_floor_ptr->m_max;
453 /* Expand the array */
454 current_floor_ptr->m_max++;
457 current_floor_ptr->m_cnt++;
459 /* Return the index */
463 /* Recycle dead monsters */
464 for (i = 1; i < current_floor_ptr->m_max; i++)
468 /* Acquire monster */
469 m_ptr = ¤t_floor_ptr->m_list[i];
471 /* Skip live monsters */
472 if (m_ptr->r_idx) continue;
475 current_floor_ptr->m_cnt++;
477 /* Use this monster */
481 /* Warn the player (except during dungeon creation) */
482 if (character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
484 /* Try not to crash */
492 * @var summon_specific_type
493 * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
494 * @todo summon_specific_typeグローバル変数の除去と関数引数への代替を行う
496 static int summon_specific_type = 0;
500 * @var summon_specific_who
501 * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
502 * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
504 static int summon_specific_who = -1;
507 * @var summon_unique_okay
508 * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
509 * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
511 static bool summon_unique_okay = FALSE;
514 * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
515 * @return 召喚条件が一致するならtrue
518 static bool summon_specific_aux(MONRACE_IDX summoner_idx, MONRACE_IDX r_idx)
520 monster_race *r_ptr = &r_info[r_idx];
523 /* Check our requirements */
524 switch (summon_specific_type)
528 okay = (r_ptr->d_char == 'a');
534 okay = (r_ptr->d_char == 'S');
540 okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
546 okay = (r_ptr->d_char == 'M');
552 okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
558 okay = (r_ptr->flags3 & RF3_DEMON);
564 okay = (r_ptr->flags3 & RF3_UNDEAD);
570 okay = (r_ptr->flags3 & RF3_DRAGON);
574 case SUMMON_HI_UNDEAD:
576 okay = ((r_ptr->d_char == 'L') ||
577 (r_ptr->d_char == 'V') ||
578 (r_ptr->d_char == 'W'));
582 case SUMMON_HI_DRAGON:
584 okay = (r_ptr->d_char == 'D');
588 case SUMMON_HI_DEMON:
590 okay = (((r_ptr->d_char == 'U') ||
591 (r_ptr->d_char == 'H') ||
592 (r_ptr->d_char == 'B')) &&
593 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
597 case SUMMON_AMBERITES:
599 okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
605 okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
611 okay = (r_ptr->d_char == 'm');
616 okay = (r_ptr->d_char == 'b');
619 case SUMMON_QUYLTHULG:
621 okay = (r_ptr->d_char == 'Q');
625 case SUMMON_COIN_MIMIC:
627 okay = (r_ptr->d_char == '$');
633 okay = ((r_ptr->d_char == '!') ||
634 (r_ptr->d_char == '?') ||
635 (r_ptr->d_char == '=') ||
636 (r_ptr->d_char == '$') ||
637 (r_ptr->d_char == '|'));
643 okay = (r_ptr->d_char == 'g');
649 okay = ((r_ptr->d_char == 'U') &&
650 (r_ptr->flags4 & RF4_ROCKET));
656 SYMBOL_CODE summon_kin_type;
659 summon_kin_type = r_info[summoner_idx].d_char;
663 summon_kin_type = get_summon_symbol_from_player(p_ptr);
666 okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
672 okay = (r_idx == MON_DAWN);
678 okay = (r_ptr->flags3 & (RF3_ANIMAL));
682 case SUMMON_ANIMAL_RANGER:
684 okay = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
685 (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
686 !(r_ptr->flags3 & (RF3_DRAGON)) &&
687 !(r_ptr->flags3 & (RF3_EVIL)) &&
688 !(r_ptr->flags3 & (RF3_UNDEAD)) &&
689 !(r_ptr->flags3 & (RF3_DEMON)) &&
690 !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
691 !(r_ptr->flags4 || r_ptr->a_ability_flags1 || r_ptr->a_ability_flags2));
695 case SUMMON_HI_DRAGON_LIVING:
697 okay = ((r_ptr->d_char == 'D') && monster_living(r_idx));
703 okay = monster_living(r_idx);
709 okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
713 case SUMMON_BLUE_HORROR:
715 okay = (r_idx == MON_BLUE_HORROR);
719 case SUMMON_ELEMENTAL:
721 okay = (r_ptr->d_char == 'E');
727 okay = (r_ptr->d_char == 'v');
733 okay = (r_ptr->d_char == 'H');
739 okay = (r_ptr->d_char == 'B');
743 case SUMMON_KAMIKAZE:
746 for (i = 0; i < 4; i++)
747 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
751 case SUMMON_KAMIKAZE_LIVING:
755 for (i = 0; i < 4; i++)
756 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
757 okay = (okay && monster_living(r_idx));
763 okay = (r_idx == MON_MANES);
769 okay = (r_idx == MON_LOUSE);
773 case SUMMON_GUARDIANS:
775 okay = (r_ptr->flags7 & RF7_GUARDIAN);
781 okay = ((r_idx == MON_NOV_PALADIN) ||
782 (r_idx == MON_NOV_PALADIN_G) ||
783 (r_idx == MON_PALADIN) ||
784 (r_idx == MON_W_KNIGHT) ||
785 (r_idx == MON_ULTRA_PALADIN) ||
786 (r_idx == MON_KNI_TEMPLAR));
792 okay = (r_ptr->d_char == 'B' &&
793 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
794 (r_ptr->flags8 & RF8_WILD_ONLY));
798 case SUMMON_PIRANHAS:
800 okay = (r_idx == MON_PIRANHA);
804 case SUMMON_ARMAGE_GOOD:
806 okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
810 case SUMMON_ARMAGE_EVIL:
812 okay = ((r_ptr->flags3 & RF3_DEMON) ||
813 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
817 /* Since okay is int, "return (okay);" is not correct. */
818 return (bool)(okay ? TRUE : FALSE);
822 * @var chameleon_change_m_idx
823 * @brief カメレオンの変身先モンスターIDを受け渡すためのグローバル変数
824 * @todo 変数渡しの問題などもあるができればchameleon_change_m_idxのグローバル変数を除去し、関数引き渡しに移行すること
826 static int chameleon_change_m_idx = 0;
830 * @brief 指定されたモンスター種族がダンジョンの制限にかかるかどうかをチェックする / Some dungeon types restrict the possible monsters.
831 * @param r_idx チェックするモンスター種族ID
832 * @return 召喚条件が一致するならtrue / Return TRUE is the monster is OK and FALSE otherwise
834 static bool restrict_monster_to_dungeon(DUNGEON_IDX d_idx, MONRACE_IDX r_idx)
836 dungeon_type *d_ptr = &d_info[d_idx];
837 monster_race *r_ptr = &r_info[r_idx];
840 if (d_ptr->flags1 & DF1_CHAMELEON)
842 if (chameleon_change_m_idx) return TRUE;
844 if (d_ptr->flags1 & DF1_NO_MAGIC)
846 if (r_idx != MON_CHAMELEON &&
848 !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
849 !(r_ptr->a_ability_flags1 & RF5_NOMAGIC_MASK) &&
850 !(r_ptr->a_ability_flags2 & RF6_NOMAGIC_MASK))
853 if (d_ptr->flags1 & DF1_NO_MELEE)
855 if (r_idx == MON_CHAMELEON) return TRUE;
856 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
857 !(r_ptr->a_ability_flags1 & (RF5_BOLT_MASK | RF5_BEAM_MASK | RF5_BALL_MASK | RF5_CAUSE_1 | RF5_CAUSE_2 | RF5_CAUSE_3 | RF5_CAUSE_4 | RF5_MIND_BLAST | RF5_BRAIN_SMASH)) &&
858 !(r_ptr->a_ability_flags2 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
861 if (d_ptr->flags1 & DF1_BEGINNER)
863 if (r_ptr->level > current_floor_ptr->dun_level)
867 if (d_ptr->special_div >= 64) return TRUE;
868 if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
872 case DUNGEON_MODE_AND:
875 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
880 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
885 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
890 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
893 if (d_ptr->m_a_ability_flags1)
895 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
898 if (d_ptr->m_a_ability_flags2)
900 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
905 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
910 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
915 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
920 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
923 for (a = 0; a < 5; a++)
924 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
928 case DUNGEON_MODE_NAND:
931 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
936 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
941 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
946 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
949 if (d_ptr->m_a_ability_flags1)
951 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
954 if (d_ptr->m_a_ability_flags2)
956 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
961 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
966 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
971 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
976 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
979 for (a = 0; a < 5; a++)
980 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
984 case DUNGEON_MODE_OR:
985 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
986 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
987 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
988 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
989 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return TRUE;
990 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return TRUE;
991 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
992 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
993 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
994 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
995 for (a = 0; a < 5; a++)
996 if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
1000 case DUNGEON_MODE_NOR:
1001 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
1002 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
1003 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
1004 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
1005 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return FALSE;
1006 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return FALSE;
1007 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
1008 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
1009 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
1010 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
1011 for (a = 0; a < 5; a++)
1012 if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1021 * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
1022 * @param monster_hook 制限関数1
1023 * @param monster_hook2 制限関数2
1026 errr get_mon_num_prep(monsterrace_hook_type monster_hook,
1027 monsterrace_hook_type monster_hook2)
1031 /* Todo: Check the hooks for non-changes */
1033 /* Set the new hooks */
1034 get_mon_num_hook = monster_hook;
1035 get_mon_num2_hook = monster_hook2;
1037 /* Scan the allocation table */
1038 for (i = 0; i < alloc_race_size; i++)
1040 monster_race *r_ptr;
1043 alloc_entry *entry = &alloc_race_table[i];
1046 r_ptr = &r_info[entry->index];
1048 /* Skip monsters which don't pass the restriction */
1049 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1050 (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1053 if (!p_ptr->inside_battle && !chameleon_change_m_idx &&
1054 summon_specific_type != SUMMON_GUARDIANS)
1056 /* Hack -- don't create questors */
1057 if (r_ptr->flags1 & RF1_QUESTOR)
1060 if (r_ptr->flags7 & RF7_GUARDIAN)
1063 /* Depth Monsters never appear out of depth */
1064 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1065 (r_ptr->level > current_floor_ptr->dun_level))
1069 /* Accept this monster */
1070 entry->prob2 = entry->prob1;
1072 if (current_floor_ptr->dun_level && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest)) &&
1073 !restrict_monster_to_dungeon(p_ptr->dungeon_idx, entry->index) && !p_ptr->inside_battle)
1075 int hoge = entry->prob2 * d_info[p_ptr->dungeon_idx].special_div;
1076 entry->prob2 = hoge / 64;
1077 if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1087 * @brief 生成モンスター種族を1種生成テーブルから選択する
1089 * @return 選択されたモンスター生成種族
1091 * Choose a monster race that seems "appropriate" to the given level
1093 * This function uses the "prob2" field of the "monster allocation table",
1094 * and various local information, to calculate the "prob3" field of the
1095 * same table, which is then used to choose an "appropriate" monster, in
1096 * a relatively efficient manner.
1098 * Note that "town" monsters will *only* be created in the town, and
1099 * "normal" monsters will *never* be created in the town, unless the
1100 * "level" is "modified", for example, by polymorph or summoning.
1102 * There is a small chance (1/50) of "boosting" the given depth by
1103 * a small amount (up to four levels), except in the town.
1105 * It is (slightly) more likely to acquire a monster of the given level
1106 * than one of a lower level. This is done by choosing several monsters
1107 * appropriate to the given level and keeping the "hardest" one.
1109 * Note that if no monsters are "appropriate", then this function will
1110 * fail, and return zero, but this should *almost* never happen.
1112 MONRACE_IDX get_mon_num(DEPTH level)
1117 monster_race *r_ptr;
1118 alloc_entry *table = alloc_race_table;
1120 int pls_kakuritu, pls_level;
1121 int delay = mysqrt(level * 10000L) + 400L;
1123 pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10)));
1124 pls_level = MIN(NASTY_MON_PLUS_MAX, 3 + current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10)) ;
1126 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_MAZE)
1128 pls_kakuritu = MIN(pls_kakuritu / 2, pls_kakuritu - 10);
1129 if (pls_kakuritu < 2) pls_kakuritu = 2;
1134 /* Boost the level */
1135 if (!p_ptr->inside_battle && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1137 /* Nightmare mode allows more out-of depth monsters */
1138 if (ironman_nightmare && !randint0(pls_kakuritu))
1140 /* What a bizarre calculation */
1141 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1145 /* Occasional "nasty" monster */
1146 if (!randint0(pls_kakuritu))
1148 /* Pick a level bonus */
1154 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1155 if (level < 0) level = 0;
1160 /* Process probabilities */
1161 for (i = 0; i < alloc_race_size; i++)
1163 /* Monsters are sorted by depth */
1164 if (table[i].level > level) break;
1169 /* Access the "r_idx" of the chosen monster */
1170 r_idx = table[i].index;
1172 /* Access the actual race */
1173 r_ptr = &r_info[r_idx];
1175 if (!p_ptr->inside_battle && !chameleon_change_m_idx)
1177 /* Hack -- "unique" monsters must be "unique" */
1178 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1179 (r_ptr->flags7 & (RF7_NAZGUL))) &&
1180 (r_ptr->cur_num >= r_ptr->max_num))
1185 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1186 (r_ptr->cur_num >= 1))
1191 if (r_idx == MON_BANORLUPART)
1193 if (r_info[MON_BANOR].cur_num > 0) continue;
1194 if (r_info[MON_LUPART].cur_num > 0) continue;
1199 table[i].prob3 = table[i].prob2;
1202 total += table[i].prob3;
1205 /* No legal monsters */
1206 if (total <= 0) return (0);
1208 /* Pick a monster */
1209 value = randint0(total);
1211 /* Find the monster */
1212 for (i = 0; i < alloc_race_size; i++)
1214 /* Found the entry */
1215 if (value < table[i].prob3) break;
1218 value = value - table[i].prob3;
1224 /* Try for a "harder" monster once (50%) or twice (10%) */
1230 /* Pick a monster */
1231 value = randint0(total);
1233 /* Find the monster */
1234 for (i = 0; i < alloc_race_size; i++)
1236 /* Found the entry */
1237 if (value < table[i].prob3) break;
1240 value = value - table[i].prob3;
1243 /* Keep the "best" one */
1244 if (table[i].level < table[j].level) i = j;
1247 /* Try for a "harder" monster twice (10%) */
1253 /* Pick a monster */
1254 value = randint0(total);
1256 /* Find the monster */
1257 for (i = 0; i < alloc_race_size; i++)
1259 /* Found the entry */
1260 if (value < table[i].prob3) break;
1263 value = value - table[i].prob3;
1266 /* Keep the "best" one */
1267 if (table[i].level < table[j].level) i = j;
1269 return (table[i].index);
1274 * @brief モンスターの呼称を作成する / Build a string describing a monster in some way.
1275 * @param desc 記述出力先の文字列参照ポインタ
1276 * @param m_ptr モンスターの参照ポインタ
1277 * @param mode 呼称オプション
1280 * We can correctly describe monsters based on their visibility.
1281 * We can force all monsters to be treated as visible or invisible.
1282 * We can build nominatives, objectives, possessives, or reflexives.
1283 * We can selectively pronominalize hidden, visible, or all monsters.
1284 * We can use definite or indefinite descriptions for hidden monsters.
1285 * We can use definite or indefinite descriptions for visible monsters.
1287 * Pronominalization involves the gender whenever possible and allowed,
1288 * so that by cleverly requesting pronominalization / visibility, you
1289 * can get messages like "You hit someone. She screams in agony!".
1291 * Reflexives are acquired by requesting Objective plus Possessive.
1293 * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1294 * unless the "Assume Visible" mode is requested.
1296 * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1297 * If neither m_ptr nor r_ptr is given, the monster is assumed to
1298 * be neuter, singular, and hidden (unless "Assume Visible" is set),
1299 * in which case you may be in trouble... :-)
1301 * I am assuming that no monster name is more than 70 characters long,
1302 * so that "char desc[80];" is sufficiently large for any result.
1305 * MD_OBJECTIVE --> Objective (or Reflexive)
1306 * MD_POSSESSIVE --> Possessive (or Reflexive)
1307 * MD_INDEF_HIDDEN --> Use indefinites for hidden monsters ("something")
1308 * MD_INDEF_VISIBLE --> Use indefinites for visible monsters ("a kobold")
1309 * MD_PRON_HIDDEN --> Pronominalize hidden monsters
1310 * MD_PRON_VISIBLE --> Pronominalize visible monsters
1311 * MD_ASSUME_HIDDEN --> Assume the monster is hidden
1312 * MD_ASSUME_VISIBLE --> Assume the monster is visible
1313 * MD_TRUE_NAME --> Chameleon's true name
1314 * MD_IGNORE_HALLU --> Ignore hallucination, and penetrate shape change
1317 * 0x00 --> Full nominative name ("the kobold") or "it"
1318 * MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1319 * MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1320 * MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1321 * MD_PRON_VISIBLE | MD_POSSESSIVE
1322 * --> Possessive, genderized if visable ("his") or "its"
1323 * MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1324 * --> Reflexive, genderized if visable ("himself") or "itself"
1326 void monster_desc(char *desc, monster_type *m_ptr, BIT_FLAGS mode)
1329 monster_race *r_ptr;
1333 GAME_TEXT silly_name[1024];
1337 r_ptr = &r_info[m_ptr->ap_r_idx];
1339 /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1340 if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1341 else name = (r_name + r_ptr->name);
1343 /* Are we hallucinating? (Idea from Nethack...) */
1344 if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1348 if (!get_rnd_line(_("silly_j.txt", "silly.txt"), m_ptr->r_idx, silly_name))
1354 monster_race *hallu_race;
1358 hallu_race = &r_info[randint1(max_r_idx - 1)];
1360 while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
1362 strcpy(silly_name, (r_name + hallu_race->name));
1365 /* Better not strcpy it, or we could corrupt r_info... */
1369 /* Can we "see" it (exists + forced, or visible + not unforced) */
1370 seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1372 /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1373 pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1376 /* First, try using pronouns, or describing hidden monsters */
1379 /* an encoding of the monster "sex" */
1382 /* Extract the gender (if applicable) */
1383 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1384 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1386 /* Ignore the gender (if desired) */
1387 if (!m_ptr || !pron) kind = 0x00;
1390 /* Assume simple result */
1391 res = _("何か", "it");
1393 /* Brute force: split on the possibilities */
1394 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1396 /* Neuter, or unknown */
1398 case 0x00: res = "何か"; break;
1399 case 0x00 + (MD_OBJECTIVE): res = "何か"; break;
1400 case 0x00 + (MD_POSSESSIVE): res = "何かの"; break;
1401 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "何か自身"; break;
1402 case 0x00 + (MD_INDEF_HIDDEN): res = "何か"; break;
1403 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "何か"; break;
1404 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "何か"; break;
1405 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "それ自身"; break;
1407 case 0x00: res = "it"; break;
1408 case 0x00 + (MD_OBJECTIVE): res = "it"; break;
1409 case 0x00 + (MD_POSSESSIVE): res = "its"; break;
1410 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1411 case 0x00 + (MD_INDEF_HIDDEN): res = "something"; break;
1412 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "something"; break;
1413 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "something's"; break;
1414 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1418 /* Male (assume human if vague) */
1420 case 0x10: res = "彼"; break;
1421 case 0x10 + (MD_OBJECTIVE): res = "彼"; break;
1422 case 0x10 + (MD_POSSESSIVE): res = "彼の"; break;
1423 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "彼自身"; break;
1424 case 0x10 + (MD_INDEF_HIDDEN): res = "誰か"; break;
1425 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "誰か"; break;
1426 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "誰かの"; break;
1427 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "彼自身"; break;
1429 case 0x10: res = "he"; break;
1430 case 0x10 + (MD_OBJECTIVE): res = "him"; break;
1431 case 0x10 + (MD_POSSESSIVE): res = "his"; break;
1432 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1433 case 0x10 + (MD_INDEF_HIDDEN): res = "someone"; break;
1434 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1435 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1436 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1440 /* Female (assume human if vague) */
1442 case 0x20: res = "彼女"; break;
1443 case 0x20 + (MD_OBJECTIVE): res = "彼女"; break;
1444 case 0x20 + (MD_POSSESSIVE): res = "彼女の"; break;
1445 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "彼女自身"; break;
1446 case 0x20 + (MD_INDEF_HIDDEN): res = "誰か"; break;
1447 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "誰か"; break;
1448 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "誰かの"; break;
1449 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "彼女自身"; break;
1451 case 0x20: res = "she"; break;
1452 case 0x20 + (MD_OBJECTIVE): res = "her"; break;
1453 case 0x20 + (MD_POSSESSIVE): res = "her"; break;
1454 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1455 case 0x20 + (MD_INDEF_HIDDEN): res = "someone"; break;
1456 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1457 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1458 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1462 /* Copy the result */
1463 (void)strcpy(desc, res);
1467 /* Handle visible monsters, "reflexive" request */
1468 else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1470 /* The monster is visible, so use its gender */
1471 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, _("彼女自身", "herself"));
1472 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, _("彼自身", "himself"));
1473 else strcpy(desc, _("それ自身", "itself"));
1477 /* Handle all other visible monster requests */
1481 if (is_pet(m_ptr) && !is_original_ap(m_ptr))
1487 while(strncmp(t, "』", 2) && *t) t++;
1491 (void)sprintf(desc, "%s?』", buf);
1494 (void)sprintf(desc, "%s?", name);
1496 (void)sprintf(desc, "%s?", name);
1501 /* It could be a Unique */
1502 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1504 /* Start with the name (thus nominative and objective) */
1505 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1511 while (strncmp(t, "』", 2) && *t) t++;
1515 (void)sprintf(desc, "%s?』", buf);
1518 (void)sprintf(desc, "%s?", name);
1520 (void)sprintf(desc, "%s?", name);
1524 /* Inside monster arena, and it is not your mount */
1525 else if (p_ptr->inside_battle &&
1526 !(p_ptr->riding && (¤t_floor_ptr->m_list[p_ptr->riding] == m_ptr)))
1528 /* It is a fake unique monster */
1529 (void)sprintf(desc, _("%sもどき", "fake %s"), name);
1534 (void)strcpy(desc, name);
1538 /* It could be an indefinite monster */
1539 else if (mode & MD_INDEF_VISIBLE)
1541 /* XXX Check plurality for "some" */
1543 /* Indefinite monsters need an indefinite article */
1545 (void)strcpy(desc, "");
1547 (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1550 (void)strcat(desc, name);
1553 /* It could be a normal, definite, monster */
1556 /* Definite monsters need a definite article */
1558 (void)strcpy(desc, _("あなたの", "your "));
1560 (void)strcpy(desc, _("", "the "));
1562 (void)strcat(desc, name);
1565 if (m_ptr->nickname)
1567 sprintf(buf,_("「%s」", " called %s"),quark_str(m_ptr->nickname));
1571 if (p_ptr->riding && (¤t_floor_ptr->m_list[p_ptr->riding] == m_ptr))
1573 strcat(desc,_("(乗馬中)", "(riding)"));
1576 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1578 if (r_ptr->flags1 & RF1_UNIQUE)
1580 strcat(desc,_("(カメレオンの王)", "(Chameleon Lord)"));
1584 strcat(desc,_("(カメレオン)", "(Chameleon)"));
1588 if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr))
1590 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1593 /* Handle the Possessive as a special afterthought */
1594 if (mode & MD_POSSESSIVE)
1596 /* XXX Check for trailing "s" */
1598 /* Simply append "apostrophe" and "s" */
1599 (void)strcat(desc, _("の", "'s"));
1605 * @brief モンスターIDを取り、モンスター名をm_nameに代入する /
1606 * @param m_idx モンスターID
1607 * @param m_name モンスター名を入力する配列
1609 void monster_name(MONSTER_IDX m_idx, char* m_name)
1611 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1612 monster_desc(m_name, m_ptr, 0x00);
1617 * @brief モンスターの調査による思い出補完処理 / Learn about a monster (by "probing" it)
1618 * @param r_idx 補完されるモンスター種族ID
1619 * @return 明らかになった情報の度数
1621 * Return the number of new flags learnt. -Mogami-
1623 int lore_do_probe(MONRACE_IDX r_idx)
1625 monster_race *r_ptr = &r_info[r_idx];
1629 /* Maximal info about awareness */
1630 if (r_ptr->r_wake != MAX_UCHAR) n++;
1631 if (r_ptr->r_ignore != MAX_UCHAR) n++;
1632 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1634 /* Observe "maximal" attacks */
1635 for (i = 0; i < 4; i++)
1637 /* Examine "actual" blows */
1638 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1640 /* Maximal observations */
1641 if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1642 r_ptr->r_blows[i] = MAX_UCHAR;
1648 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1649 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1650 ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1651 ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1652 ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1653 ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1655 /* Only "valid" drops */
1656 if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1658 if (r_ptr->r_drop_item != tmp_byte) n++;
1659 r_ptr->r_drop_item = tmp_byte;
1661 if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1663 if (r_ptr->r_drop_gold != tmp_byte) n++;
1664 r_ptr->r_drop_gold = tmp_byte;
1667 /* Observe many spells */
1668 if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1669 r_ptr->r_cast_spell = MAX_UCHAR;
1671 /* Count unknown flags */
1672 for (i = 0; i < 32; i++)
1674 if (!(r_ptr->r_flags1 & (1L << i)) &&
1675 (r_ptr->flags1 & (1L << i))) n++;
1676 if (!(r_ptr->r_flags2 & (1L << i)) &&
1677 (r_ptr->flags2 & (1L << i))) n++;
1678 if (!(r_ptr->r_flags3 & (1L << i)) &&
1679 (r_ptr->flags3 & (1L << i))) n++;
1680 if (!(r_ptr->r_flags4 & (1L << i)) &&
1681 (r_ptr->flags4 & (1L << i))) n++;
1682 if (!(r_ptr->r_flags5 & (1L << i)) &&
1683 (r_ptr->a_ability_flags1 & (1L << i))) n++;
1684 if (!(r_ptr->r_flags6 & (1L << i)) &&
1685 (r_ptr->a_ability_flags2 & (1L << i))) n++;
1686 if (!(r_ptr->r_flagsr & (1L << i)) &&
1687 (r_ptr->flagsr & (1L << i))) n++;
1689 /* r_flags7 is actually unused */
1691 if (!(r_ptr->r_flags7 & (1L << i)) &&
1692 (r_ptr->flags7 & (1L << i))) n++;
1696 /* Know all the flags */
1697 r_ptr->r_flags1 = r_ptr->flags1;
1698 r_ptr->r_flags2 = r_ptr->flags2;
1699 r_ptr->r_flags3 = r_ptr->flags3;
1700 r_ptr->r_flags4 = r_ptr->flags4;
1701 r_ptr->r_flags5 = r_ptr->a_ability_flags1;
1702 r_ptr->r_flags6 = r_ptr->a_ability_flags2;
1703 r_ptr->r_flagsr = r_ptr->flagsr;
1705 /* r_flags7 is actually unused */
1706 /* r_ptr->r_flags7 = r_ptr->flags7; */
1708 /* Know about evolution */
1709 if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1710 r_ptr->r_xtra1 |= MR1_SINKA;
1712 /* Update monster recall window */
1713 if (p_ptr->monster_race_idx == r_idx)
1715 p_ptr->window |= (PW_MONSTER);
1718 /* Return the number of new flags learnt */
1724 * @brief モンスターの撃破に伴うドロップ情報の保管処理 / Take note that the given monster just dropped some treasure
1725 * @param m_idx モンスター情報のID
1726 * @param num_item 手に入れたアイテム数
1727 * @param num_gold 手に入れた財宝の単位数
1730 * Note that learning the "GOOD"/"GREAT" flags gives information
1731 * about the treasure (even when the monster is killed for the first
1732 * time, such as uniques, and the treasure has not been examined yet).
1734 * This "indirect" method is used to prevent the player from learning
1735 * exactly how much treasure a monster can drop from observing only
1736 * a single example of a drop. This method actually observes how much
1737 * gold and items are dropped, and remembers that information to be
1738 * described later by the monster recall code.
1740 void lore_treasure(MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
1742 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1744 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1746 /* If the monster doesn't have original appearance, don't note */
1747 if (!is_original_ap(m_ptr)) return;
1749 /* Note the number of things dropped */
1750 if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1751 if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1753 /* Hack -- memorize the good/great flags */
1754 if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1755 if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1757 /* Update monster recall window */
1758 if (p_ptr->monster_race_idx == m_ptr->r_idx)
1760 p_ptr->window |= (PW_MONSTER);
1766 * @brief モンスターの各情報を更新する / This function updates the monster record of the given monster
1767 * @param m_idx 更新するモンスター情報のID
1768 * @param full プレイヤーとの距離更新を行うならばtrue
1771 * This involves extracting the distance to the player (if requested),
1772 * and then checking for visibility (natural, infravision, see-invis,
1773 * telepathy), updating the monster visibility flag, redrawing (or
1774 * erasing) the monster when its visibility changes, and taking note
1775 * of any interesting monster flags (cold-blooded, invisible, etc).
1777 * Note the new "mflag" field which encodes several monster state flags,
1778 * including "view" for when the monster is currently in line of sight,
1779 * and "mark" for when the monster is currently visible via detection.
1781 * The only monster fields that are changed here are "cdis" (the
1782 * distance from the player), "ml" (visible to the player), and
1783 * "mflag" (to maintain the "MFLAG_VIEW" flag).
1785 * Note the special "update_monsters()" function which can be used to
1786 * call this function once for every monster.
1788 * Note the "full" flag which requests that the "cdis" field be updated,
1789 * this is only needed when the monster (or the player) has moved.
1791 * Every time a monster moves, we must call this function for that
1792 * monster, and update the distance, and the visibility. Every time
1793 * the player moves, we must call this function for every monster, and
1794 * update the distance, and the visibility. Whenever the player "state"
1795 * changes in certain ways ("blindness", "infravision", "telepathy",
1796 * and "see invisible"), we must call this function for every monster,
1797 * and update the visibility.
1799 * Routines that change the "illumination" of a grid must also call this
1800 * function for any monster in that grid, since the "visibility" of some
1801 * monsters may be based on the illumination of their grid.
1803 * Note that this function is called once per monster every time the
1804 * player moves. When the player is running, this function is one
1805 * of the primary bottlenecks, along with "update_view()" and the
1806 * "process_monsters()" code, so efficiency is important.
1808 * Note the optimized "inline" version of the "distance()" function.
1810 * A monster is "visible" to the player if (1) it has been detected
1811 * by the player, (2) it is close to the player and the player has
1812 * telepathy, or (3) it is close to the player, and in line of sight
1813 * of the player, and it is "illuminated" by some combination of
1814 * infravision, torch light, or permanent light (invisible monsters
1815 * are only affected by "light" if the player can see invisible).
1817 * Monsters which are not on the current panel may be "visible" to
1818 * the player, and their descriptions will include an "offscreen"
1819 * reference. Currently, offscreen monsters cannot be targetted
1820 * or viewed directly, but old targets will remain set. XXX XXX
1822 * The player can choose to be disturbed by several things, including
1823 * "disturb_move" (monster which is viewable moves in some way), and
1824 * "disturb_near" (monster which is "easily" viewable moves in some
1825 * way). Note that "moves" includes "appears" and "disappears".
1827 void update_monster(MONSTER_IDX m_idx, bool full)
1829 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1830 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1832 bool do_disturb = disturb_move;
1835 POSITION fy = m_ptr->fy;
1836 POSITION fx = m_ptr->fx;
1841 /* Seen by vision */
1844 /* Non-Ninja player in the darkness */
1845 bool in_darkness = (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
1850 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1852 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
1856 /* Compute distance */
1859 /* Distance components */
1860 int dy = (p_ptr->y > fy) ? (p_ptr->y - fy) : (fy - p_ptr->y);
1861 int dx = (p_ptr->x > fx) ? (p_ptr->x - fx) : (fx - p_ptr->x);
1863 /* Approximate distance */
1864 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
1866 /* Restrict distance */
1867 if (d > 255) d = 255;
1871 /* Save the distance */
1875 /* Extract distance */
1878 /* Extract the distance */
1883 if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
1886 if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
1888 if (!in_darkness || (d <= MAX_SIGHT / 4))
1890 if (p_ptr->special_defense & KATA_MUSOU)
1895 if (is_original_ap(m_ptr) && !p_ptr->image)
1897 /* Hack -- Memorize mental flags */
1898 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1899 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1903 /* Basic telepathy */
1904 /* Snipers get telepathy when they concentrate deeper */
1905 else if (p_ptr->telepathy)
1907 /* Empty mind, no telepathy */
1908 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
1910 /* Memorize flags */
1911 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
1914 /* Weird mind, occasional telepathy */
1915 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
1917 /* One in ten individuals are detectable */
1918 if ((m_idx % 10) == 5)
1923 if (is_original_ap(m_ptr) && !p_ptr->image)
1925 /* Memorize flags */
1926 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
1928 /* Hack -- Memorize mental flags */
1929 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1930 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1935 /* Normal mind, allow telepathy */
1941 if (is_original_ap(m_ptr) && !p_ptr->image)
1943 /* Hack -- Memorize mental flags */
1944 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1945 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1950 if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
1953 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
1956 if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
1959 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
1962 if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
1965 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
1968 if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
1971 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
1974 if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
1977 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
1980 if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
1983 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
1986 if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
1989 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
1992 if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
1995 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
1998 if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2001 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
2004 if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2007 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
2010 if ((p_ptr->esp_nonliving) &&
2011 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2014 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
2017 if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2020 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
2024 /* Normal line of sight, and not blind */
2025 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2027 bool do_invisible = FALSE;
2028 bool do_cold_blood = FALSE;
2030 /* Snipers can see targets in darkness when they concentrate deeper */
2031 if (p_ptr->concent >= CONCENT_RADAR_THRESHOLD)
2037 /* Use "infravision" */
2038 if (d <= p_ptr->see_infra)
2040 /* Handle "cold blooded" monsters */
2041 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2043 do_cold_blood = TRUE;
2046 /* Handle "warm blooded" monsters */
2054 /* Use "illumination" */
2055 if (player_can_see_bold(fy, fx))
2057 /* Handle "invisible" monsters */
2058 if (r_ptr->flags2 & (RF2_INVISIBLE))
2060 do_invisible = TRUE;
2070 /* Handle "normal" monsters */
2081 if (is_original_ap(m_ptr) && !p_ptr->image)
2083 /* Memorize flags */
2084 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2085 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2092 /* The monster is now visible */
2095 /* It was previously unseen */
2098 /* Mark as visible */
2101 /* Draw the monster */
2104 /* Update health bar as needed */
2105 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2106 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2108 /* Hack -- Count "fresh" sightings */
2111 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2112 r_info[MON_KAGE].r_sights++;
2113 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
2117 if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
2119 sanity_blast(m_ptr, FALSE);
2122 /* Disturb on appearance */
2123 if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)))
2125 if (disturb_pets || is_hostile(m_ptr))
2126 disturb(TRUE, TRUE);
2131 /* The monster is not visible */
2134 /* It was previously seen */
2137 /* Mark as not visible */
2140 /* Erase the monster */
2143 /* Update health bar as needed */
2144 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2145 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2147 /* Disturb on disappearance */
2150 if (disturb_pets || is_hostile(m_ptr))
2151 disturb(TRUE, TRUE);
2157 /* The monster is now easily visible */
2161 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2163 /* Mark as easily visible */
2164 m_ptr->mflag |= (MFLAG_VIEW);
2166 /* Disturb on appearance */
2169 if (disturb_pets || is_hostile(m_ptr))
2170 disturb(TRUE, TRUE);
2175 /* The monster is not easily visible */
2179 if (m_ptr->mflag & (MFLAG_VIEW))
2181 /* Mark as not easily visible */
2182 m_ptr->mflag &= ~(MFLAG_VIEW);
2184 /* Disturb on disappearance */
2187 if (disturb_pets || is_hostile(m_ptr))
2188 disturb(TRUE, TRUE);
2196 * @brief 単純に生存している全モンスターの更新処理を行う / This function simply updates all the (non-dead) monsters (see above).
2197 * @param full 距離更新を行うならtrue
2200 void update_monsters(bool full)
2204 /* Update each (live) monster */
2205 for (i = 1; i < current_floor_ptr->m_max; i++)
2207 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
2208 if (!monster_is_valid(m_ptr)) continue;
2209 update_monster(i, full);
2215 * @brief カメレオンの王の変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2216 * @param r_idx モンスター種族ID
2217 * @return 対象にできるならtrueを返す
2219 static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
2221 monster_race *r_ptr = &r_info[r_idx];
2222 monster_type *m_ptr = ¤t_floor_ptr->m_list[chameleon_change_m_idx];
2223 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2225 if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2226 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2228 if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2230 if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2233 if (!monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2236 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2238 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2242 else if (summon_specific_who > 0)
2244 if (monster_has_hostile_align(¤t_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2251 * @brief カメレオンの変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2252 * @param r_idx モンスター種族ID
2253 * @return 対象にできるならtrueを返す
2254 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2256 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
2258 monster_race *r_ptr = &r_info[r_idx];
2259 monster_type *m_ptr = ¤t_floor_ptr->m_list[chameleon_change_m_idx];
2260 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2262 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2263 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2264 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2266 if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2269 if (!monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2272 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2274 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2275 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2276 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2280 else if (summon_specific_who > 0)
2282 if (monster_has_hostile_align(¤t_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2285 return (*(get_monster_hook()))(r_idx);
2290 * @param m_idx 変身処理を受けるモンスター情報のID
2291 * @param born 生成時の初変身先指定ならばtrue
2292 * @param r_idx 旧モンスター種族のID
2295 void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
2298 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
2299 monster_race *r_ptr;
2300 char old_m_name[MAX_NLEN];
2301 bool old_unique = FALSE;
2302 int old_r_idx = m_ptr->r_idx;
2304 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2306 if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2307 r_ptr = &r_info[r_idx];
2309 monster_desc(old_m_name, m_ptr, 0);
2315 chameleon_change_m_idx = m_idx;
2317 get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2319 get_mon_num_prep(monster_hook_chameleon, NULL);
2322 level = r_info[MON_CHAMELEON_K].level;
2323 else if (!current_floor_ptr->dun_level)
2324 level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2326 level = current_floor_ptr->dun_level;
2328 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2330 r_idx = get_mon_num(level);
2331 r_ptr = &r_info[r_idx];
2333 chameleon_change_m_idx = 0;
2337 m_ptr->r_idx = r_idx;
2338 m_ptr->ap_r_idx = r_idx;
2339 update_monster(m_idx, FALSE);
2340 lite_spot(m_ptr->fy, m_ptr->fx);
2342 if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2343 (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2344 p_ptr->update |= (PU_MON_LITE);
2348 /* Sub-alignment of a chameleon */
2349 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2351 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2352 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2353 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2358 if (m_idx == p_ptr->riding)
2360 GAME_TEXT m_name[MAX_NLEN];
2361 monster_desc(m_name, m_ptr, 0);
2362 msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
2363 if (!(r_ptr->flags7 & RF7_RIDING))
2364 if (rakuba(0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
2367 /* Extract the monster base speed */
2368 m_ptr->mspeed = get_mspeed(r_ptr);
2370 oldmaxhp = m_ptr->max_maxhp;
2371 /* Assign maximal hitpoints */
2372 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2374 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2378 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2381 /* Monsters have double hitpoints in Nightmare mode */
2382 if (ironman_nightmare)
2384 u32b hp = m_ptr->max_maxhp * 2L;
2385 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2388 m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2389 if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2390 m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2392 /* reset dealt_damage */
2393 m_ptr->dealt_damage = 0;
2398 * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
2399 * @param r_idx モンスター種族ID
2400 * @return 対象にできるならtrueを返す
2401 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2403 static bool monster_hook_tanuki(MONRACE_IDX r_idx)
2405 monster_race *r_ptr = &r_info[r_idx];
2407 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2408 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2409 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2410 if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2412 if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2415 return (*(get_monster_hook()))(r_idx);
2420 * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
2421 * @param r_idx モンスター種族ID
2422 * @return モンスター種族の表層ID
2424 static MONRACE_IDX initial_r_appearance(MONRACE_IDX r_idx, BIT_FLAGS generate_mode)
2426 int attempts = 1000;
2427 MONRACE_IDX ap_r_idx;
2428 DEPTH min = MIN(current_floor_ptr->base_level - 5, 50);
2430 if (p_ptr->pseikaku == SEIKAKU_CHARGEMAN && !(generate_mode & (PM_MULTIPLY | PM_KAGE)))
2432 if (current_floor_ptr->base_level == 0 || one_in_(5)) return MON_ALIEN_JURAL;
2435 if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2438 get_mon_num_prep(monster_hook_tanuki, NULL);
2442 ap_r_idx = get_mon_num(current_floor_ptr->base_level + 10);
2443 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2451 * @brief モンスターの個体加速を設定する / Get initial monster speed
2452 * @param r_ptr モンスター種族の参照ポインタ
2455 SPEED get_mspeed(monster_race *r_ptr)
2457 /* Extract the monster base speed */
2458 SPEED mspeed = r_ptr->speed;
2460 /* Hack -- small racial variety */
2461 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2463 /* Allow some small variation per monster */
2464 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2465 if (i) mspeed += rand_spread(0, i);
2468 if (mspeed > 199) mspeed = 199;
2475 * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
2476 * @param who 召喚を行ったモンスターID
2479 * @param r_idx 生成モンスター種族
2480 * @param mode 生成オプション
2483 * To give the player a sporting chance, any monster that appears in
2484 * line-of-sight and is extremely dangerous can be marked as
2485 * "FORCE_SLEEP", which will cause them to be placed with low energy,
2486 * which often (but not always) lets the player move before they do.
2488 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2490 * Use special "here" and "dead" flags for unique monsters,
2491 * remove old "cur_num" and "max_num" fields.
2493 * Actually, do something similar for artifacts, to simplify
2494 * the "preserve" mode, and to make the "what artifacts" flag more useful.
2496 * This is the only function which may place a monster in the dungeon,
2497 * except for the savefile loading code.
2499 static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2501 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2502 monster_type *m_ptr;
2503 monster_race *r_ptr = &r_info[r_idx];
2504 concptr name = (r_name + r_ptr->name);
2508 /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2509 if (p_ptr->wild_mode) return FALSE;
2511 if (!in_bounds(y, x)) return (FALSE);
2512 if (!r_idx) return (FALSE);
2513 if (!r_ptr->name) return (FALSE);
2515 if (!(mode & PM_IGNORE_TERRAIN))
2517 /* Not on the Pattern */
2518 if (pattern_tile(y, x)) return FALSE;
2520 /* Require empty space (if not ghostly) */
2521 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
2524 if (!p_ptr->inside_battle)
2526 /* Hack -- "unique" monsters must be "unique" */
2527 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2528 (r_ptr->flags7 & (RF7_NAZGUL))) &&
2529 (r_ptr->cur_num >= r_ptr->max_num))
2535 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
2536 (r_ptr->cur_num >= 1))
2541 if (r_idx == MON_BANORLUPART)
2543 if (r_info[MON_BANOR].cur_num > 0) return FALSE;
2544 if (r_info[MON_LUPART].cur_num > 0) return FALSE;
2547 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
2548 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (current_floor_ptr->dun_level < r_ptr->level) &&
2549 (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
2556 if (quest_number(current_floor_ptr->dun_level))
2558 int hoge = quest_number(current_floor_ptr->dun_level);
2559 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
2561 if(r_idx == quest[hoge].r_idx)
2563 int number_mon, i2, j2;
2566 /* Count all quest monsters */
2567 for (i2 = 0; i2 < current_floor_ptr->width; ++i2)
2568 for (j2 = 0; j2 < current_floor_ptr->height; j2++)
2569 if (current_floor_ptr->grid_array[j2][i2].m_idx > 0)
2570 if (current_floor_ptr->m_list[current_floor_ptr->grid_array[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
2572 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
2578 if (is_glyph_grid(g_ptr))
2580 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
2582 /* Describe observable breakage */
2583 if (g_ptr->info & CAVE_MARK)
2585 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2588 /* Forget the rune */
2589 g_ptr->info &= ~(CAVE_MARK);
2591 /* Break the rune */
2592 g_ptr->info &= ~(CAVE_OBJECT);
2600 msg_format_wizard(CHEAT_MONSTER, _("%s(Lv%d)を生成しました。", "%s(Lv%d) was generated."), name, r_ptr->level);
2602 if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
2604 /* Make a new monster */
2605 g_ptr->m_idx = m_pop();
2606 hack_m_idx_ii = g_ptr->m_idx;
2608 /* Mega-Hack -- catch "failure" */
2609 if (!g_ptr->m_idx) return (FALSE);
2612 /* Get a new monster record */
2613 m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
2616 m_ptr->r_idx = r_idx;
2617 m_ptr->ap_r_idx = initial_r_appearance(r_idx, mode);
2623 /* Hack -- Appearance transfer */
2624 if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(¤t_floor_ptr->m_list[who]))
2626 m_ptr->ap_r_idx = current_floor_ptr->m_list[who].ap_r_idx;
2628 /* Hack -- Shadower spawns Shadower */
2629 if (current_floor_ptr->m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
2632 /* Sub-alignment of a monster */
2633 if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
2634 m_ptr->sub_align = current_floor_ptr->m_list[who].sub_align;
2637 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2638 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2639 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2642 /* Place the monster at the location */
2647 /* No "timed status" yet */
2648 for (cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
2650 /* Unknown distance */
2653 reset_target(m_ptr);
2655 m_ptr->nickname = 0;
2660 /* Your pet summons its pet. */
2661 if (who > 0 && is_pet(¤t_floor_ptr->m_list[who]))
2663 mode |= PM_FORCE_PET;
2664 m_ptr->parent_m_idx = who;
2668 m_ptr->parent_m_idx = 0;
2671 if (r_ptr->flags7 & RF7_CHAMELEON)
2673 choose_new_monster(g_ptr->m_idx, TRUE, 0);
2674 r_ptr = &r_info[m_ptr->r_idx];
2675 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
2677 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
2678 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
2679 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2681 else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
2683 m_ptr->ap_r_idx = MON_KAGE;
2684 m_ptr->mflag2 |= MFLAG2_KAGE;
2687 if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
2693 if (mode & PM_FORCE_PET)
2698 else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
2699 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
2701 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
2704 /* Assume no sleeping */
2705 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
2707 /* Enforce sleeping if needed */
2708 if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
2710 int val = r_ptr->sleep;
2711 (void)set_monster_csleep(g_ptr->m_idx, (val * 2) + randint1(val * 10));
2714 /* Assign maximal hitpoints */
2715 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2717 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2721 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2724 /* Monsters have double hitpoints in Nightmare mode */
2725 if (ironman_nightmare)
2727 u32b hp = m_ptr->max_maxhp * 2L;
2729 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2732 m_ptr->maxhp = m_ptr->max_maxhp;
2734 /* And start out fully healthy */
2735 if (m_ptr->r_idx == MON_WOUNDED_BEAR)
2736 m_ptr->hp = m_ptr->maxhp / 2;
2737 else m_ptr->hp = m_ptr->maxhp;
2740 /* dealt damage is 0 at initial*/
2741 m_ptr->dealt_damage = 0;
2744 /* Extract the monster base speed */
2745 m_ptr->mspeed = get_mspeed(r_ptr);
2747 if (mode & PM_HASTE) (void)set_monster_fast(g_ptr->m_idx, 100);
2749 /* Give a random starting energy */
2750 if (!ironman_nightmare)
2752 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
2756 /* Nightmare monsters are more prepared */
2757 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
2760 /* Force monster to wait for player, unless in Nightmare mode */
2761 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
2763 /* Monster is still being nice */
2764 m_ptr->mflag |= (MFLAG_NICE);
2766 /* Must repair monsters */
2767 repair_monsters = TRUE;
2770 /* Hack -- see "process_monsters()" */
2771 if (g_ptr->m_idx < hack_m_idx)
2773 /* Monster is still being born */
2774 m_ptr->mflag |= (MFLAG_BORN);
2778 if (r_ptr->flags7 & RF7_SELF_LD_MASK)
2779 p_ptr->update |= (PU_MON_LITE);
2780 else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
2781 p_ptr->update |= (PU_MON_LITE);
2782 update_monster(g_ptr->m_idx, TRUE);
2785 /* Count the monsters on the level */
2786 real_r_ptr(m_ptr)->cur_num++;
2789 * Memorize location of the unique monster in saved floors.
2790 * A unique monster move from old saved floor.
2792 if (character_dungeon &&
2793 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
2794 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
2796 /* Hack -- Count the number of "reproducers" */
2797 if (r_ptr->flags2 & RF2_MULTIPLY) current_floor_ptr->num_repro++;
2799 if (p_ptr->warning && character_dungeon)
2801 if (r_ptr->flags1 & RF1_UNIQUE)
2805 GAME_TEXT o_name[MAX_NLEN];
2807 if (r_ptr->level > p_ptr->lev + 30)
2808 color = _("黒く", "black");
2809 else if (r_ptr->level > p_ptr->lev + 15)
2810 color = _("紫色に", "purple");
2811 else if (r_ptr->level > p_ptr->lev + 5)
2812 color = _("ルビー色に", "deep red");
2813 else if (r_ptr->level > p_ptr->lev - 5)
2814 color = _("赤く", "red");
2815 else if (r_ptr->level > p_ptr->lev - 15)
2816 color = _("ピンク色に", "pink");
2818 color = _("白く", "white");
2820 o_ptr = choose_warning_item();
2823 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2824 msg_format(_("%sは%s光った。", "%s glows %s."), o_name, color);
2828 msg_format(_("%s光る物が頭に浮かんだ。", "An %s image forms in your mind."), color);
2833 if (is_explosive_rune_grid(g_ptr))
2835 /* Break the ward */
2836 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2838 /* Describe observable breakage */
2839 if (g_ptr->info & CAVE_MARK)
2841 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2842 project(0, 2, y, x, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
2847 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2850 /* Forget the rune */
2851 g_ptr->info &= ~(CAVE_MARK);
2853 /* Break the rune */
2854 g_ptr->info &= ~(CAVE_OBJECT);
2867 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
2870 * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster
2871 * @param r_idx 生成モンスター種族
2872 * @param yp 結果生成位置y座標
2873 * @param xp 結果生成位置x座標
2874 * @param y 中心生成位置y座標
2875 * @param x 中心生成位置x座標
2876 * @param max_dist 生成位置の最大半径
2880 static bool mon_scatter(MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
2882 POSITION place_x[MON_SCAT_MAXD];
2883 POSITION place_y[MON_SCAT_MAXD];
2884 int num[MON_SCAT_MAXD];
2888 if (max_dist >= MON_SCAT_MAXD)
2891 for (i = 0; i < MON_SCAT_MAXD; i++)
2894 for (nx = x - max_dist; nx <= x + max_dist; nx++)
2896 for (ny = y - max_dist; ny <= y + max_dist; ny++)
2898 /* Ignore annoying locations */
2899 if (!in_bounds(ny, nx)) continue;
2901 /* Require "line of projection" */
2902 if (!projectable(y, x, ny, nx)) continue;
2906 monster_race *r_ptr = &r_info[r_idx];
2908 /* Require empty space (if not ghostly) */
2909 if (!monster_can_enter(ny, nx, r_ptr, 0))
2914 /* Walls and Monsters block flow */
2915 if (!cave_empty_bold2(ny, nx)) continue;
2917 /* ... nor on the Pattern */
2918 if (pattern_tile(ny, nx)) continue;
2921 i = distance(y, x, ny, nx);
2929 if (one_in_(num[i]))
2938 while (i < MON_SCAT_MAXD && 0 == num[i])
2940 if (i >= MON_SCAT_MAXD)
2950 * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
2951 * @param who 召喚主のモンスター情報ID
2952 * @param y 中心生成位置y座標
2953 * @param x 中心生成位置x座標
2954 * @param r_idx 生成モンスター種族
2955 * @param mode 生成オプション
2958 static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2960 monster_race *r_ptr = &r_info[r_idx];
2963 int total = 0, extra = 0;
2967 POSITION hack_y[GROUP_MAX];
2968 POSITION hack_x[GROUP_MAX];
2971 /* Pick a group size */
2972 total = randint1(10);
2974 /* Hard monsters, small groups */
2975 if (r_ptr->level > current_floor_ptr->dun_level)
2977 extra = r_ptr->level - current_floor_ptr->dun_level;
2978 extra = 0 - randint1(extra);
2981 /* Easy monsters, large groups */
2982 else if (r_ptr->level < current_floor_ptr->dun_level)
2984 extra = current_floor_ptr->dun_level - r_ptr->level;
2985 extra = randint1(extra);
2988 /* Hack -- limit group reduction */
2989 if (extra > 9) extra = 9;
2991 /* Modify the group size */
2995 if (total < 1) total = 1;
2998 if (total > GROUP_MAX) total = GROUP_MAX;
3001 /* Start on the monster */
3006 /* Puddle monsters, breadth first, up to total */
3007 for (n = 0; (n < hack_n) && (hack_n < total); n++)
3009 /* Grab the location */
3010 POSITION hx = hack_x[n];
3011 POSITION hy = hack_y[n];
3013 /* Check each direction, up to total */
3014 for (i = 0; (i < 8) && (hack_n < total); i++)
3018 scatter(&my, &mx, hy, hx, 4, 0);
3020 /* Walls and Monsters block flow */
3021 if (!cave_empty_bold2(my, mx)) continue;
3023 /* Attempt to place another monster */
3024 if (place_monster_one(who, my, mx, r_idx, mode))
3026 /* Add it to the "hack" set */
3027 hack_y[hack_n] = my;
3028 hack_x[hack_n] = mx;
3040 * @var place_monster_idx
3041 * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
3042 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
3044 static MONSTER_IDX place_monster_idx = 0;
3047 * @var place_monster_m_idx
3048 * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
3049 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
3051 static MONSTER_IDX place_monster_m_idx = 0;
3054 * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
3055 * @param r_idx チェックするモンスター種族のID
3056 * @return 護衛にできるならばtrue
3058 static bool place_monster_can_escort(MONRACE_IDX r_idx)
3060 monster_race *r_ptr = &r_info[place_monster_idx];
3061 monster_type *m_ptr = ¤t_floor_ptr->m_list[place_monster_m_idx];
3063 monster_race *z_ptr = &r_info[r_idx];
3065 /* Hack - Escorts have to have the same dungeon flag */
3066 if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return (FALSE);
3068 /* Require similar "race" */
3069 if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3071 /* Skip more advanced monsters */
3072 if (z_ptr->level > r_ptr->level) return (FALSE);
3074 /* Skip unique monsters */
3075 if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3077 /* Paranoia -- Skip identical monsters */
3078 if (place_monster_idx == r_idx) return (FALSE);
3080 /* Skip different alignment */
3081 if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3083 if (r_ptr->flags7 & RF7_FRIENDLY)
3085 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3088 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3096 * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
3097 * @param who 召喚主のモンスター情報ID
3100 * @param r_idx 生成するモンスターの種族ID
3101 * @param mode 生成オプション
3102 * @return 生成に成功したらtrue
3104 * Note that certain monsters are now marked as requiring "friends".
3105 * These monsters, if successfully placed, and if the "grp" parameter
3106 * is TRUE, will be surrounded by a "group" of identical monsters.
3108 * Note that certain monsters are now marked as requiring an "escort",
3109 * which is a collection of monsters with similar "race" but lower level.
3111 * Some monsters induce a fake "group" flag on their escorts.
3113 * Note the "bizarre" use of non-recursion to prevent annoying output
3114 * when running a code profiler.
3116 * Note the use of the new "monster allocation table" code to restrict
3117 * the "get_mon_num()" function to "legal" escort types.
3119 bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
3122 monster_race *r_ptr = &r_info[r_idx];
3124 if (!(mode & PM_NO_KAGE) && one_in_(333))
3127 /* Place one monster, or fail */
3128 if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3130 /* Require the "group" flag */
3131 if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3133 place_monster_m_idx = hack_m_idx_ii;
3136 for(i = 0; i < 6; i++)
3138 if(!r_ptr->reinforce_id[i]) break;
3139 n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
3140 for(j = 0; j < n; j++)
3142 POSITION nx, ny, d = 7;
3143 scatter(&ny, &nx, y, x, d, 0);
3144 (void)place_monster_one(place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
3148 /* Friends for certain monsters */
3149 if (r_ptr->flags1 & (RF1_FRIENDS))
3151 /* Attempt to place a group */
3152 (void)place_monster_group(who, y, x, r_idx, mode);
3155 /* Escorts for certain monsters */
3156 if (r_ptr->flags1 & (RF1_ESCORT))
3158 /* Set the escort index */
3159 place_monster_idx = r_idx;
3161 /* Try to place several "escorts" */
3162 for (i = 0; i < 32; i++)
3164 POSITION nx, ny, d = 3;
3167 /* Pick a location */
3168 scatter(&ny, &nx, y, x, d, 0);
3170 /* Require empty grids */
3171 if (!cave_empty_bold2(ny, nx)) continue;
3172 get_mon_num_prep(place_monster_can_escort, get_monster_hook2(ny, nx));
3174 /* Pick a random race */
3175 z = get_mon_num(r_ptr->level);
3177 /* Handle failure */
3180 /* Place a single escort */
3181 (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3183 /* Place a "group" of escorts if needed */
3184 if ((r_info[z].flags1 & RF1_FRIENDS) ||
3185 (r_ptr->flags1 & RF1_ESCORTS))
3187 /* Place a group of monsters */
3188 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3198 * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
3201 * @param mode 生成オプション
3202 * @return 生成に成功したらtrue
3204 bool place_monster(POSITION y, POSITION x, BIT_FLAGS mode)
3207 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3209 /* Pick a monster */
3210 r_idx = get_mon_num(current_floor_ptr->monster_level);
3212 /* Handle failure */
3213 if (!r_idx) return (FALSE);
3215 /* Attempt to place the monster */
3216 if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3222 * @brief 指定地点に1種類のモンスター種族による群れを生成する
3225 * @return 生成に成功したらtrue
3227 bool alloc_horde(POSITION y, POSITION x)
3229 monster_race *r_ptr = NULL;
3230 MONRACE_IDX r_idx = 0;
3232 int attempts = 1000;
3235 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3239 /* Pick a monster */
3240 r_idx = get_mon_num(current_floor_ptr->monster_level);
3242 /* Handle failure */
3243 if (!r_idx) return (FALSE);
3245 r_ptr = &r_info[r_idx];
3247 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3249 if (r_idx == MON_HAGURE) continue;
3252 if (attempts < 1) return FALSE;
3258 /* Attempt to place the monster */
3259 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3262 if (attempts < 1) return FALSE;
3264 m_idx = current_floor_ptr->grid_array[y][x].m_idx;
3266 if (current_floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[current_floor_ptr->m_list[m_idx].r_idx];
3268 for (attempts = randint1(10) + 5; attempts; attempts--)
3270 scatter(&cy, &cx, y, x, 5, 0);
3272 (void)summon_specific(m_idx, cy, cx, current_floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3278 if (cheat_hear) msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), r_ptr->d_char);
3283 * @brief ダンジョンの主生成を試みる / Put the Guardian
3284 * @param def_val 現在の主の生成状態
3285 * @return 生成に成功したらtrue
3287 bool alloc_guardian(bool def_val)
3289 MONRACE_IDX guardian = d_info[p_ptr->dungeon_idx].final_guardian;
3291 if (guardian && (d_info[p_ptr->dungeon_idx].maxdepth == current_floor_ptr->dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3295 int try_count = 4000;
3297 /* Find a good position */
3300 /* Get a random spot */
3301 oy = randint1(current_floor_ptr->height - 4) + 2;
3302 ox = randint1(current_floor_ptr->width - 4) + 2;
3304 /* Is it a good spot ? */
3305 if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(current_floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0))
3307 /* Place the guardian */
3308 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3311 /* One less try count */
3323 * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
3324 * @param dis プレイヤーから離れるべき最低距離
3325 * @param mode 生成オプション
3326 * @return 生成に成功したらtrue
3328 * Place the monster at least "dis" distance from the player.
3329 * Use "slp" to choose the initial "sleep" status
3330 * Use "current_floor_ptr->monster_level" for the monster level
3332 bool alloc_monster(POSITION dis, BIT_FLAGS mode)
3334 POSITION y = 0, x = 0;
3335 int attempts_left = 10000;
3337 /* Put the Guardian */
3338 if (alloc_guardian(FALSE)) return TRUE;
3340 /* Find a legal, distant, unoccupied, space */
3341 while (attempts_left--)
3343 /* Pick a location */
3344 y = randint0(current_floor_ptr->height);
3345 x = randint0(current_floor_ptr->width);
3347 /* Require empty floor grid (was "naked") */
3348 if (current_floor_ptr->dun_level)
3350 if (!cave_empty_bold2(y, x)) continue;
3354 if (!cave_empty_bold(y, x)) continue;
3357 /* Accept far away grids */
3358 if (distance(y, x, p_ptr->y, p_ptr->x) > dis) break;
3363 if (cheat_xtra || cheat_hear)
3365 msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
3372 if (randint1(5000) <= current_floor_ptr->dun_level)
3374 if (alloc_horde(y, x))
3381 /* Attempt to place the monster, allow groups */
3382 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3390 * @brief モンスターが召喚の基本条件に合っているかをチェックする / Hack -- help decide if a monster race is "okay" to summon
3391 * @param r_idx チェックするモンスター種族ID
3392 * @return 召喚対象にできるならばTRUE
3394 static bool summon_specific_okay(MONRACE_IDX r_idx)
3396 monster_race *r_ptr = &r_info[r_idx];
3397 monster_type *m_ptr = ¤t_floor_ptr->m_list[summon_specific_who];
3399 /* Hack - Only summon dungeon monsters */
3400 if (!mon_hook_dungeon(r_idx)) return (FALSE);
3402 /* Hack -- identify the summoning monster */
3403 if (summon_specific_who > 0)
3406 /* Do not summon enemies */
3408 /* Friendly vs. opposite aligned normal or pet */
3409 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3411 /* Use the player's alignment */
3412 else if (summon_specific_who < 0)
3414 /* Do not summon enemies of the pets */
3415 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3417 if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3421 if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
3423 /* Hack -- no specific type specified */
3424 if (!summon_specific_type) return (TRUE);
3426 if ((summon_specific_who < 0) &&
3427 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
3428 monster_has_hostile_align(NULL, 10, -10, r_ptr))
3431 if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON)) return TRUE;
3433 return (summon_specific_aux(m_ptr->r_idx, r_idx));
3438 * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
3439 * @param who 召喚主のモンスター情報ID
3444 * @param mode 生成オプション
3445 * @return 召喚できたらtrueを返す
3448 * We will attempt to place the monster up to 10 times before giving up.
3450 * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3451 * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3452 * Note: None of the other summon codes will ever summon Unique's.
3454 * This function has been changed. We now take the "monster level"
3455 * of the summoning monster as a parameter, and use that, along with
3456 * the current dungeon level, to help determine the level of the
3457 * desired monster. Note that this is an upper bound, and also
3458 * tends to "prefer" monsters of that level. Currently, we use
3459 * the average of the dungeon and monster levels, and then add
3460 * five to allow slight increases in monster power.
3462 * Note that we use the new "monster allocation table" creation code
3463 * to restrict the "get_mon_num()" function to the set of "legal"
3464 * monsters, making this function much faster and more reliable.
3466 * Note that this function may not succeed, though this is very rare.
3468 bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode)
3473 if (p_ptr->inside_arena) return (FALSE);
3475 if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
3477 /* Save the summoner */
3478 summon_specific_who = who;
3480 /* Save the "summon" type */
3481 summon_specific_type = type;
3483 summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
3484 get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
3486 /* Pick a monster, using the level calculation */
3487 r_idx = get_mon_num((current_floor_ptr->dun_level + lev) / 2 + 5);
3489 /* Handle failure */
3492 summon_specific_type = 0;
3496 if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
3498 /* Attempt to place the monster (awake, allow groups) */
3499 if (!place_monster_aux(who, y, x, r_idx, mode))
3501 summon_specific_type = 0;
3505 summon_specific_type = 0;
3507 sound(SOUND_SUMMON);
3513 * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
3514 * @param who 召喚主のモンスター情報ID
3517 * @param r_idx 生成するモンスター種族ID
3518 * @param mode 生成オプション
3519 * @return 召喚できたらtrueを返す
3521 bool summon_named_creature(MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
3524 /* if (!r_idx) return; */
3526 /* Prevent illegal monsters */
3527 if (r_idx >= max_r_idx) return FALSE;
3529 if (p_ptr->inside_arena) return FALSE;
3531 if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
3533 /* Place it (allow groups) */
3534 return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
3539 * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
3540 * @param m_idx 増殖するモンスター情報ID
3541 * @param clone クローン・モンスター処理ならばtrue
3542 * @param mode 生成オプション
3543 * @return 生成できたらtrueを返す
3545 * Note that "reproduction" REQUIRES empty space.
3547 bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
3549 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
3552 if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
3555 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
3557 /* Create a new monster (awake, no groups) */
3558 if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
3561 /* Hack -- Transfer "clone" flag */
3562 if (clone || (m_ptr->smart & SM_CLONED))
3564 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3565 current_floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
3574 * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
3575 * @param m_idx モンスター情報ID
3576 * @param dam 与えたダメージ
3579 * Technically should attempt to treat "Beholder"'s as jelly's
3581 void message_pain(MONSTER_IDX m_idx, HIT_POINT dam)
3583 HIT_POINT oldhp, newhp;
3585 PERCENTAGE percentage;
3587 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
3588 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3590 GAME_TEXT m_name[MAX_NLEN];
3592 monster_desc(m_name, m_ptr, 0);
3594 if(dam == 0) // Notice non-damage
3596 msg_format(_("%^sはダメージを受けていない。", "%^s is unharmed."), m_name);
3600 /* Note -- subtle fix -CFT */
3602 oldhp = newhp + dam;
3603 tmp = (newhp * 100L) / oldhp;
3606 if(my_strchr(",ejmvwQ", r_ptr->d_char)) // Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs
3609 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3610 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
3611 else if(percentage > 50) msg_format("%^sは縮こまった。", m_name);
3612 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3613 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
3614 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3615 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3617 if(percentage > 95) msg_format("%^s barely notices.", m_name);
3618 else if(percentage > 75) msg_format("%^s flinches.", m_name);
3619 else if(percentage > 50) msg_format("%^s squelches.", m_name);
3620 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
3621 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
3622 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3623 else msg_format("%^s jerks limply.", m_name);
3627 else if(my_strchr("l", r_ptr->d_char)) // Fish
3630 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3631 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
3632 else if(percentage > 50) msg_format("%^sは躊躇した。", m_name);
3633 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3634 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
3635 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3636 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3638 if(percentage > 95) msg_format("%^s barely notices.", m_name);
3639 else if(percentage > 75) msg_format("%^s flinches.", m_name);
3640 else if(percentage > 50) msg_format("%^s hesitates.", m_name);
3641 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
3642 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
3643 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3644 else msg_format("%^s jerks limply.", m_name);
3648 else if(my_strchr("g#+<>", r_ptr->d_char)) // Golems, Walls, Doors, Stairs
3651 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3652 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3653 else if(percentage > 50) msg_format("%^sは雷鳴のように吠えた。", m_name);
3654 else if(percentage > 35) msg_format("%^sは苦しげに吠えた。", m_name);
3655 else if(percentage > 20) msg_format("%^sはうめいた。", m_name);
3656 else if(percentage > 10) msg_format("%^sは躊躇した。", m_name);
3657 else msg_format("%^sはくしゃくしゃになった。", m_name);
3659 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3660 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3661 else if(percentage > 50) msg_format("%^s roars thunderously.", m_name);
3662 else if(percentage > 35) msg_format("%^s rumbles.", m_name);
3663 else if(percentage > 20) msg_format("%^s grunts.", m_name);
3664 else if(percentage > 10) msg_format("%^s hesitates.", m_name);
3665 else msg_format("%^s crumples.", m_name);
3669 else if(my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) // Snakes, Hydrae, Reptiles, Mimics
3672 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3673 else if(percentage > 75) msg_format("%^sはシーッと鳴いた。", m_name);
3674 else if(percentage > 50) msg_format("%^sは怒って頭を上げた。", m_name);
3675 else if(percentage > 35) msg_format("%^sは猛然と威嚇した。", m_name);
3676 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
3677 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3678 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3680 if(percentage > 95) msg_format("%^s barely notices.", m_name);
3681 else if(percentage > 75) msg_format("%^s hisses.", m_name);
3682 else if(percentage > 50) msg_format("%^s rears up in anger.", m_name);
3683 else if(percentage > 35) msg_format("%^s hisses furiously.", m_name);
3684 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
3685 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3686 else msg_format("%^s jerks limply.", m_name);
3690 else if(my_strchr("f", r_ptr->d_char))
3693 if(percentage > 95) msg_format("%sは攻撃に肩をすくめた。", m_name);
3694 else if(percentage > 75) msg_format("%^sは吠えた。", m_name);
3695 else if(percentage > 50) msg_format("%^sは怒って吠えた。", m_name);
3696 else if(percentage > 35) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3697 else if(percentage > 20) msg_format("%^sは痛みで弱々しく鳴いた。", m_name);
3698 else if(percentage > 10) msg_format("%^sは苦痛にうめいた。", m_name);
3699 else msg_format("%sは哀れな鳴き声を出した。", m_name);
3701 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3702 else if(percentage > 75) msg_format("%^s roars.", m_name);
3703 else if(percentage > 50) msg_format("%^s growls angrily.", m_name);
3704 else if(percentage > 35) msg_format("%^s hisses with pain.", m_name);
3705 else if(percentage > 20) msg_format("%^s mewls in pain.", m_name);
3706 else if(percentage > 10) msg_format("%^s hisses in agony.", m_name);
3707 else msg_format("%^s mewls pitifully.", m_name);
3711 else if(my_strchr("acFIKS", r_ptr->d_char)) // Ants, Centipedes, Flies, Insects, Beetles, Spiders
3714 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3715 else if(percentage > 75) msg_format("%^sはキーキー鳴いた。", m_name);
3716 else if(percentage > 50) msg_format("%^sはヨロヨロ逃げ回った。", m_name);
3717 else if(percentage > 35) msg_format("%^sはうるさく鳴いた。", m_name);
3718 else if(percentage > 20) msg_format("%^sは痛みに痙攣した。", m_name);
3719 else if(percentage > 10) msg_format("%^sは苦痛で痙攣した。", m_name);
3720 else msg_format("%^sはピクピクひきつった。", m_name);
3722 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3723 else if(percentage > 75) msg_format("%^s chitters.", m_name);
3724 else if(percentage > 50) msg_format("%^s scuttles about.", m_name);
3725 else if(percentage > 35) msg_format("%^s twitters.", m_name);
3726 else if(percentage > 20) msg_format("%^s jerks in pain.", m_name);
3727 else if(percentage > 10) msg_format("%^s jerks in agony.", m_name);
3728 else msg_format("%^s twitches.", m_name);
3732 else if(my_strchr("B", r_ptr->d_char)) // Birds
3735 if(percentage > 95) msg_format("%^sはさえずった。", m_name);
3736 else if(percentage > 75) msg_format("%^sはピーピー鳴いた。", m_name);
3737 else if(percentage > 50) msg_format("%^sはギャーギャー鳴いた。", m_name);
3738 else if(percentage > 35) msg_format("%^sはギャーギャー鳴きわめいた。", m_name);
3739 else if(percentage > 20) msg_format("%^sは苦しんだ。", m_name);
3740 else if(percentage > 10) msg_format("%^sはのたうち回った。", m_name);
3741 else msg_format("%^sはキーキーと鳴き叫んだ。", m_name);
3743 if(percentage > 95) msg_format("%^s chirps.", m_name);
3744 else if(percentage > 75) msg_format("%^s twitters.", m_name);
3745 else if(percentage > 50) msg_format("%^s squawks.", m_name);
3746 else if(percentage > 35) msg_format("%^s chatters.", m_name);
3747 else if(percentage > 20) msg_format("%^s jeers.", m_name);
3748 else if(percentage > 10) msg_format("%^s flutters about.", m_name);
3749 else msg_format("%^s squeaks.", m_name);
3753 else if(my_strchr("duDLUW", r_ptr->d_char)) // Dragons, Demons, High Undead
3756 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3757 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
3758 else if(percentage > 50) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3759 else if(percentage > 35) msg_format("%^sは痛みでうなった。", m_name);
3760 else if(percentage > 20) msg_format("%^sは痛みに吠えた。", m_name);
3761 else if(percentage > 10) msg_format("%^sは苦しげに叫んだ。", m_name);
3762 else msg_format("%^sは弱々しくうなった。", m_name);
3764 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3765 else if(percentage > 75) msg_format("%^s flinches.", m_name);
3766 else if(percentage > 50) msg_format("%^s hisses in pain.", m_name);
3767 else if(percentage > 35) msg_format("%^s snarls with pain.", m_name);
3768 else if(percentage > 20) msg_format("%^s roars with pain.", m_name);
3769 else if(percentage > 10) msg_format("%^s gasps.", m_name);
3770 else msg_format("%^s snarls feebly.", m_name);
3774 else if(my_strchr("s", r_ptr->d_char)) // Skeletons
3777 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3778 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3779 else if(percentage > 50) msg_format("%^sはカタカタと笑った。", m_name);
3780 else if(percentage > 35) msg_format("%^sはよろめいた。", m_name);
3781 else if(percentage > 20) msg_format("%^sはカタカタ言った。", m_name);
3782 else if(percentage > 10) msg_format("%^sはよろめいた。", m_name);
3783 else msg_format("%^sはガタガタ言った。", m_name);
3785 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3786 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3787 else if(percentage > 50) msg_format("%^s rattles.", m_name);
3788 else if(percentage > 35) msg_format("%^s stumbles.", m_name);
3789 else if(percentage > 20) msg_format("%^s rattles.", m_name);
3790 else if(percentage > 10) msg_format("%^s staggers.", m_name);
3791 else msg_format("%^s clatters.", m_name);
3795 else if(my_strchr("z", r_ptr->d_char)) // Zombies
3798 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3799 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3800 else if(percentage > 50) msg_format("%^sはうめいた。", m_name);
3801 else if(percentage > 35) msg_format("%sは苦しげにうめいた。", m_name);
3802 else if(percentage > 20) msg_format("%^sは躊躇した。", m_name);
3803 else if(percentage > 10) msg_format("%^sはうなった。", m_name);
3804 else msg_format("%^sはよろめいた。", m_name);
3806 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3807 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3808 else if(percentage > 50) msg_format("%^s groans.", m_name);
3809 else if(percentage > 35) msg_format("%^s moans.", m_name);
3810 else if(percentage > 20) msg_format("%^s hesitates.", m_name);
3811 else if(percentage > 10) msg_format("%^s grunts.", m_name);
3812 else msg_format("%^s staggers.", m_name);
3816 else if(my_strchr("G", r_ptr->d_char)) // Ghosts
3819 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3820 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3821 else if(percentage > 50) msg_format("%sはうめいた。", m_name);
3822 else if(percentage > 35) msg_format("%^sは泣きわめいた。", m_name);
3823 else if(percentage > 20) msg_format("%^sは吠えた。", m_name);
3824 else if(percentage > 10) msg_format("%sは弱々しくうめいた。", m_name);
3825 else msg_format("%^sはかすかにうめいた。", m_name);
3827 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3828 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3829 else if(percentage > 50) msg_format("%^s moans.", m_name);
3830 else if(percentage > 35) msg_format("%^s wails.", m_name);
3831 else if(percentage > 20) msg_format("%^s howls.", m_name);
3832 else if(percentage > 10) msg_format("%^s moans softly.", m_name);
3833 else msg_format("%^s sighs.", m_name);
3837 else if(my_strchr("CZ", r_ptr->d_char)) // Dogs and Hounds
3840 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3841 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3842 else if(percentage > 50) msg_format("%^sは痛みでキャンキャン吠えた。", m_name);
3843 else if(percentage > 35) msg_format("%^sは痛みで鳴きわめいた。", m_name);
3844 else if(percentage > 20) msg_format("%^sは苦痛のあまり鳴きわめいた。", m_name);
3845 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3846 else msg_format("%^sは弱々しく吠えた。", m_name);
3848 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3849 else if(percentage > 75) msg_format("%^s snarls with pain.", m_name);
3850 else if(percentage > 50) msg_format("%^s yelps in pain.", m_name);
3851 else if(percentage > 35) msg_format("%^s howls in pain.", m_name);
3852 else if(percentage > 20) msg_format("%^s howls in agony.", m_name);
3853 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3854 else msg_format("%^s yelps feebly.", m_name);
3858 else if(my_strchr("Xbilqrt", r_ptr->d_char)) // One type of creatures (ignore,squeal,shriek)
3861 if(percentage > 95) msg_format("%^sは攻撃を気にとめていない。", m_name);
3862 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3863 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3864 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3865 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3866 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3867 else msg_format("%^sは弱々しく叫んだ。", m_name);
3869 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3870 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
3871 else if(percentage > 50) msg_format("%^s squeals in pain.", m_name);
3872 else if(percentage > 35) msg_format("%^s shrieks in pain.", m_name);
3873 else if(percentage > 20) msg_format("%^s shrieks in agony.", m_name);
3874 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3875 else msg_format("%^s cries out feebly.", m_name);
3879 else // Another type of creatures (shrug,cry,scream)
3882 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3883 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3884 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3885 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3886 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3887 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3888 else msg_format("%^sは弱々しく叫んだ。", m_name);
3890 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3891 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
3892 else if(percentage > 50) msg_format("%^s cries out in pain.", m_name);
3893 else if(percentage > 35) msg_format("%^s screams in pain.", m_name);
3894 else if(percentage > 20) msg_format("%^s screams in agony.", m_name);
3895 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3896 else msg_format("%^s cries out feebly.", m_name);
3904 * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance.
3905 * @param m_idx 更新を行う「モンスター情報ID
3906 * @param what 学習対象ID
3909 void update_smart_learn(MONSTER_IDX m_idx, int what)
3911 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
3912 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3914 /* Not allowed to learn */
3915 if (!smart_learn) return;
3917 /* Too stupid to learn anything */
3918 if (r_ptr->flags2 & (RF2_STUPID)) return;
3920 /* Not intelligent, only learn sometimes */
3921 if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
3923 /* Analyze the knowledge */
3927 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
3928 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
3929 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
3933 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
3934 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
3935 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
3939 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
3940 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
3941 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
3945 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
3946 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
3947 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
3951 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
3952 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
3957 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
3961 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
3965 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
3969 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
3973 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
3977 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
3981 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
3985 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
3989 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
3993 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
3997 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4001 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4005 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4009 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4016 * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster
4017 * @param m_ptr モンスター参照ポインタ
4020 void monster_drop_carried_objects(monster_type *m_ptr)
4022 OBJECT_IDX this_o_idx, next_o_idx = 0;
4028 /* Drop objects being carried */
4029 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4031 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
4032 next_o_idx = o_ptr->next_o_idx;
4035 object_copy(q_ptr, o_ptr);
4037 /* Forget monster */
4038 q_ptr->held_m_idx = 0;
4040 delete_object_idx(this_o_idx);
4043 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4046 /* Forget objects */
4047 m_ptr->hold_o_idx = 0;
4051 * @brief 指定したモンスターに隣接しているモンスターの数を返す。
4052 * / Count number of adjacent monsters
4053 * @param m_idx 隣接数を調べたいモンスターのID
4054 * @return 隣接しているモンスターの数
4056 int get_monster_crowd_number(MONSTER_IDX m_idx)
4058 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
4059 POSITION my = m_ptr->fy;
4060 POSITION mx = m_ptr->fx;
4064 for (i = 0; i < 7; i++)
4066 int ay = my + ddy_ddd[i];
4067 int ax = mx + ddx_ddd[i];
4069 if (!in_bounds(ay, ax)) continue;
4071 /* Count number of monsters */
4072 if (current_floor_ptr->grid_array[ay][ax].m_idx > 0) count++;