2 * @brief モンスターが移動した結果、床のアイテムに重なった時の処理と、モンスターがアイテムを落とす処理
7 #include "monster-floor/monster-object.h"
8 #include "flavor/flavor-describer.h"
9 #include "floor/floor-object.h"
10 #include "floor/cave.h"
11 #include "grid/grid.h"
12 #include "monster-race/monster-race.h"
13 #include "monster-race/race-flags-resistance.h"
14 #include "monster-race/race-flags2.h"
15 #include "monster-race/race-flags3.h"
16 #include "monster/monster-describer.h"
17 #include "monster/monster-description-types.h"
18 #include "monster/monster-info.h"
19 #include "monster/smart-learn-types.h"
20 #include "object-enchant/tr-types.h"
21 #include "object-hook/hook-enchant.h"
22 #include "object/object-flags.h"
23 #include "object/object-generator.h"
24 #include "object/object-mark-types.h"
25 #include "system/floor-type-definition.h"
26 #include "util/bit-flags-calculator.h"
27 #include "view/display-messages.h"
30 * @brief オブジェクトのフラグを更新する
32 static void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr)
34 if (has_flag(flgs, TR_SLAY_DRAGON))
35 *flg3 |= (RF3_DRAGON);
36 if (has_flag(flgs, TR_KILL_DRAGON))
37 *flg3 |= (RF3_DRAGON);
38 if (has_flag(flgs, TR_SLAY_TROLL))
40 if (has_flag(flgs, TR_KILL_TROLL))
42 if (has_flag(flgs, TR_SLAY_GIANT))
44 if (has_flag(flgs, TR_KILL_GIANT))
46 if (has_flag(flgs, TR_SLAY_ORC))
48 if (has_flag(flgs, TR_KILL_ORC))
50 if (has_flag(flgs, TR_SLAY_DEMON))
52 if (has_flag(flgs, TR_KILL_DEMON))
54 if (has_flag(flgs, TR_SLAY_UNDEAD))
55 *flg3 |= (RF3_UNDEAD);
56 if (has_flag(flgs, TR_KILL_UNDEAD))
57 *flg3 |= (RF3_UNDEAD);
58 if (has_flag(flgs, TR_SLAY_ANIMAL))
59 *flg3 |= (RF3_ANIMAL);
60 if (has_flag(flgs, TR_KILL_ANIMAL))
61 *flg3 |= (RF3_ANIMAL);
62 if (has_flag(flgs, TR_SLAY_EVIL))
64 if (has_flag(flgs, TR_KILL_EVIL))
66 if (has_flag(flgs, TR_SLAY_HUMAN))
68 if (has_flag(flgs, TR_KILL_HUMAN))
70 if (has_flag(flgs, TR_BRAND_ACID))
71 *flgr |= (RFR_IM_ACID);
72 if (has_flag(flgs, TR_BRAND_ELEC))
73 *flgr |= (RFR_IM_ELEC);
74 if (has_flag(flgs, TR_BRAND_FIRE))
75 *flgr |= (RFR_IM_FIRE);
76 if (has_flag(flgs, TR_BRAND_COLD))
77 *flgr |= (RFR_IM_COLD);
78 if (has_flag(flgs, TR_BRAND_POIS))
79 *flgr |= (RFR_IM_POIS);
83 * @brief モンスターがアイテムを拾うか壊す処理
84 * @param target_ptr プレーヤーへの参照ポインタ
85 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
86 * @param m_idx モンスターID
87 * @param o_ptr オブジェクトへの参照ポインタ
88 * @param is_special_object モンスターが拾えないアイテム (アーティファクト等)であればTRUE
89 * @param ny 移動後の、モンスターのY座標
90 * @param nx 移動後の、モンスターのX座標
91 * @param m_name モンスター名
93 * @param this_o_idx モンスターが乗ったオブジェクトID
96 static void monster_pickup_object(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, object_type *o_ptr, bool is_special_object,
97 POSITION ny, POSITION nx, GAME_TEXT *m_name, GAME_TEXT *o_name, OBJECT_IDX this_o_idx)
99 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
100 monster_race *r_ptr = &r_info[m_ptr->r_idx];
101 if (is_special_object) {
102 if (turn_flags_ptr->do_take && (r_ptr->flags2 & RF2_STUPID)) {
103 turn_flags_ptr->did_take_item = TRUE;
104 if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx)) {
105 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
112 if (turn_flags_ptr->do_take) {
113 turn_flags_ptr->did_take_item = TRUE;
114 if (player_can_see_bold(target_ptr, ny, nx)) {
115 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
118 excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
119 o_ptr->marked &= OM_TOUCHED;
120 o_ptr->iy = o_ptr->ix = 0;
121 o_ptr->held_m_idx = m_idx;
122 o_ptr->next_o_idx = m_ptr->hold_o_idx;
123 m_ptr->hold_o_idx = this_o_idx;
130 turn_flags_ptr->did_kill_item = TRUE;
131 if (player_has_los_bold(target_ptr, ny, nx)) {
132 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
135 delete_object_idx(target_ptr, this_o_idx);
139 * @brief モンスターの移動に伴うオブジェクト処理 (アイテム破壊等)
140 * @param target_ptr プレーヤーへの参照ポインタ
141 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
142 * @param m_idx モンスターID
143 * @param ny 移動後の、モンスターのY座標
144 * @param nx 移動後の、モンスターのX座標
146 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
148 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
149 monster_race *r_ptr = &r_info[m_ptr->r_idx];
151 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
153 turn_flags_ptr->do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
154 OBJECT_IDX next_o_idx;
155 for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx > 0; this_o_idx = next_o_idx) {
156 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
157 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
158 object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
159 next_o_idx = o_ptr->next_o_idx;
161 if (turn_flags_ptr->do_take) {
162 /* Skip gold, corpse and statue */
163 if (o_ptr->tval == TV_GOLD || (o_ptr->tval == TV_CORPSE) || (o_ptr->tval == TV_STATUE))
167 object_flags(target_ptr, o_ptr, flgs);
168 describe_flavor(target_ptr, o_name, o_ptr, 0);
169 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
170 update_object_flags(flgs, &flg2, &flg3, &flgr);
172 bool is_special_object = object_is_artifact(o_ptr) || ((r_ptr->flags3 & flg3) != 0) || ((r_ptr->flags2 & flg2) != 0)
173 || (((~(r_ptr->flagsr) & flgr) != 0) && !(r_ptr->flagsr & RFR_RES_ALL));
174 monster_pickup_object(target_ptr, turn_flags_ptr, m_idx, o_ptr, is_special_object, ny, nx, m_name, o_name, this_o_idx);
179 * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster
180 * @param player_ptr プレーヤーへの参照ポインタ
181 * @param m_ptr モンスター参照ポインタ
184 void monster_drop_carried_objects(player_type *player_ptr, monster_type *m_ptr)
186 OBJECT_IDX next_o_idx = 0;
187 for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) {
191 o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
192 next_o_idx = o_ptr->next_o_idx;
194 object_copy(q_ptr, o_ptr);
195 q_ptr->held_m_idx = 0;
196 delete_object_idx(player_ptr, this_o_idx);
197 (void)drop_near(player_ptr, q_ptr, -1, m_ptr->fy, m_ptr->fx);
200 m_ptr->hold_o_idx = 0;