3 * @brief プレイヤーの発動コマンド実装
12 * @brief ペット入りモンスターボールをソートするための比較関数
13 * @param u 所持品配列の参照ポインタ
17 * @return 1の方が大であればTRUE
19 static bool ang_sort_comp_pet(vptr u, vptr v, int a, int b)
21 u16b *who = (u16b*)(u);
26 monster_type *m_ptr1 = &m_list[w1];
27 monster_type *m_ptr2 = &m_list[w2];
28 monster_race *r_ptr1 = &r_info[m_ptr1->r_idx];
29 monster_race *r_ptr2 = &r_info[m_ptr2->r_idx];
34 if (m_ptr1->nickname && !m_ptr2->nickname) return TRUE;
35 if (m_ptr2->nickname && !m_ptr1->nickname) return FALSE;
37 if ((r_ptr1->flags1 & RF1_UNIQUE) && !(r_ptr2->flags1 & RF1_UNIQUE)) return TRUE;
38 if ((r_ptr2->flags1 & RF1_UNIQUE) && !(r_ptr1->flags1 & RF1_UNIQUE)) return FALSE;
40 if (r_ptr1->level > r_ptr2->level) return TRUE;
41 if (r_ptr2->level > r_ptr1->level) return FALSE;
43 if (m_ptr1->hp > m_ptr2->hp) return TRUE;
44 if (m_ptr2->hp > m_ptr1->hp) return FALSE;
50 * @brief オブジェクトをプレイヤーが魔道具として発動できるかを判定する /
51 * Hook to determine if an object is activatable
52 * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
53 * @return 魔道具として発動可能ならばTRUEを返す
55 static bool item_tester_hook_activate(object_type *o_ptr)
57 u32b flgs[TR_FLAG_SIZE];
60 if (!object_is_known(o_ptr)) return (FALSE);
62 /* Extract the flags */
63 object_flags(o_ptr, flgs);
65 /* Check activation flag */
66 if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
73 * @brief 装備を発動するコマンドのサブルーチン /
74 * Activate a wielded object. Wielded objects never stack.
75 * And even if they did, activatable objects never stack.
76 * @param item 発動するオブジェクトの所持品ID
80 * Currently, only (some) artifacts, and Dragon Scale Mail, can be activated.
81 * But one could, for example, easily make an activatable "Ring of Plasma".
82 * Note that it always takes a turn to activate an artifact, even if
83 * the user hits "escape" at the "direction" prompt.
86 void do_cmd_activate_aux(int item)
88 int dir, lev, chance, fail;
93 /* Get the item (in the pack) */
96 o_ptr = &inventory[item];
99 /* Get the item (on the floor) */
102 o_ptr = &o_list[0 - item];
106 p_ptr->energy_use = 100;
108 /* Extract the item level */
109 lev = k_info[o_ptr->k_idx].level;
111 /* Hack -- use artifact level instead */
112 if (object_is_fixed_artifact(o_ptr)) lev = a_info[o_ptr->name1].level;
113 else if (object_is_random_artifact(o_ptr))
115 const activation_type* const act_ptr = find_activation_info(o_ptr);
117 lev = act_ptr->level;
120 else if (((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) && o_ptr->name2) lev = e_info[o_ptr->name2].level;
122 /* Base chance of success */
123 chance = p_ptr->skill_dev;
125 /* Confusion hurts skill */
126 if (p_ptr->confused) chance = chance / 2;
129 if (chance > fail) fail -= (chance - fail)*2;
130 else chance -= (fail - chance)*2;
131 if (fail < USE_DEVICE) fail = USE_DEVICE;
132 if (chance < USE_DEVICE) chance = USE_DEVICE;
136 if (flush_failure) flush();
137 msg_print(_("止まった時の中ではうまく働かないようだ。", "It shows no reaction."));
142 if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
143 else if (chance > fail)
145 if (randint0(chance*2) < fail) success = FALSE;
150 if (randint0(fail*2) < chance) success = TRUE;
151 else success = FALSE;
157 if (flush_failure) flush();
158 msg_print(_("うまく始動させることができなかった。", "You failed to activate it properly."));
163 /* Check the recharge */
166 msg_print(_("それは微かに音を立て、輝き、消えた...", "It whines, glows and fades..."));
170 /* Some lights need enough fuel for activation */
171 if (!o_ptr->xtra4 && (o_ptr->tval == TV_FLASK) &&
172 ((o_ptr->sval == SV_LITE_TORCH) || (o_ptr->sval == SV_LITE_LANTERN)))
174 msg_print(_("燃料がない。", "It has no fuel."));
175 p_ptr->energy_use = 0;
179 /* Activate the artifact */
180 msg_print(_("始動させた...", "You activate it..."));
185 /* Activate object */
186 if (activation_index(o_ptr))
188 (void)activate_random_artifact(o_ptr);
191 p_ptr->window |= (PW_INVEN | PW_EQUIP);
198 else if (o_ptr->tval == TV_WHISTLE)
200 if (music_singing_any()) stop_singing();
201 if (hex_spelling_any()) stop_hex_spell_all();
204 if (object_is_cursed(o_ptr))
206 msg_print(_("カン高い音が響き渡った。", "You produce a shrill whistling sound."));
207 aggravate_monsters(0);
217 /* Allocate the "who" array */
218 C_MAKE(who, max_m_idx, IDX);
220 /* Process the monsters (backwards) */
221 for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
223 if (is_pet(&m_list[pet_ctr]) && (p_ptr->riding != pet_ctr))
224 who[max_pet++] = pet_ctr;
227 /* Select the sort method */
228 ang_sort_comp = ang_sort_comp_pet;
229 ang_sort_swap = ang_sort_swap_hook;
231 ang_sort(who, &dummy_why, max_pet);
233 /* Process the monsters (backwards) */
234 for (i = 0; i < max_pet; i++)
237 teleport_monster_to(pet_ctr, p_ptr->y, p_ptr->x, 100, TELEPORT_PASSIVE);
240 /* Free the "who" array */
241 C_KILL(who, max_m_idx, IDX);
243 o_ptr->timeout = 100+randint1(100);
246 else if (o_ptr->tval == TV_CAPTURE)
250 bool old_target_pet = target_pet;
252 if (!get_aim_dir(&dir))
254 target_pet = old_target_pet;
257 target_pet = old_target_pet;
259 if(fire_ball(GF_CAPTURE, dir, 0, 0))
261 o_ptr->pval = (PARAMETER_VALUE)cap_mon;
262 o_ptr->xtra3 = (XTRA8)cap_mspeed;
263 o_ptr->xtra4 = (XTRA16)cap_hp;
264 o_ptr->xtra5 = (XTRA16)cap_maxhp;
271 if (o_ptr->inscription)
272 strcpy(buf, quark_str(o_ptr->inscription));
274 for (s = buf;*s && (*s != '#'); s++)
277 if (iskanji(*s)) s++;
287 t = quark_str(cap_nickname);
300 o_ptr->inscription = quark_add(buf);
307 if (!get_rep_dir2(&dir)) return;
308 if (monster_can_enter(p_ptr->y + ddy[dir], p_ptr->x + ddx[dir], &r_info[o_ptr->pval], 0))
310 if (place_monster_aux(0, p_ptr->y + ddy[dir], p_ptr->x + ddx[dir], o_ptr->pval, (PM_FORCE_PET | PM_NO_KAGE)))
312 if (o_ptr->xtra3) m_list[hack_m_idx_ii].mspeed = o_ptr->xtra3;
313 if (o_ptr->xtra5) m_list[hack_m_idx_ii].max_maxhp = o_ptr->xtra5;
314 if (o_ptr->xtra4) m_list[hack_m_idx_ii].hp = o_ptr->xtra4;
315 m_list[hack_m_idx_ii].maxhp = m_list[hack_m_idx_ii].max_maxhp;
316 if (o_ptr->inscription)
324 t = quark_str(o_ptr->inscription);
325 for (t = quark_str(o_ptr->inscription);*t && (*t != '#'); t++)
328 if (iskanji(*t)) t++;
353 if (quote && *(s-1) =='\'')
357 m_list[hack_m_idx_ii].nickname = quark_add(buf);
358 t = quark_str(o_ptr->inscription);
360 while(*t && (*t != '#'))
367 o_ptr->inscription = quark_add(buf);
378 msg_print(_("おっと、解放に失敗した。", "Oops. You failed to release your pet."));
385 msg_print(_("おっと、このアイテムは始動できない。", "Oops. That object cannot be activated."));
389 * @brief 装備を発動するコマンドのメインルーチン /
392 void do_cmd_activate(void)
398 if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
400 set_action(ACTION_NONE);
403 item_tester_no_ryoute = TRUE;
404 /* Prepare the hook */
405 item_tester_hook = item_tester_hook_activate;
408 q = _("どのアイテムを始動させますか? ", "Activate which item? ");
409 s = _("始動できるアイテムを装備していない。", "You have nothing to activate.");
411 if (!get_item(&item, q, s, (USE_EQUIP))) return;
413 /* Activate the item */
414 do_cmd_activate_aux(item);