1 #include "cmd-item/cmd-throw.h"
2 #include "action/weapon-shield.h"
3 #include "art-definition/art-weapon-types.h"
4 #include "combat/attack-power-table.h"
5 #include "combat/shoot.h"
6 #include "combat/slaying.h"
7 #include "core/player-redraw-types.h"
8 #include "core/player-update-types.h"
9 #include "core/stuff-handler.h"
10 #include "core/window-redrawer.h"
11 #include "effect/spells-effect-util.h"
12 #include "flavor/flavor-describer.h"
13 #include "flavor/object-flavor-types.h"
14 #include "floor/cave.h"
15 #include "floor/floor-object.h"
16 #include "floor/geometry.h"
17 #include "game-option/cheat-types.h"
18 #include "game-option/special-options.h"
19 #include "grid/feature-flag-types.h"
20 #include "grid/grid.h"
21 #include "inventory/inventory-object.h"
22 #include "inventory/inventory-slot-types.h"
23 #include "io/cursor.h"
24 #include "io/screen-util.h"
25 #include "io/targeting.h"
26 #include "main/sound-definitions-table.h"
27 #include "main/sound-of-music.h"
28 #include "monster-floor/monster-death.h"
29 #include "monster-floor/monster-summon.h"
30 #include "monster-floor/place-monster-types.h"
31 #include "monster/monster-describer.h"
32 #include "monster/monster-info.h"
33 #include "monster/monster-status.h"
34 #include "object-enchant/tr-types.h"
35 #include "object-hook/hook-checker.h"
36 #include "object-hook/hook-expendable.h"
37 #include "object-hook/hook-weapon.h"
38 #include "object/item-tester-hooker.h"
39 #include "object/item-use-flags.h"
40 #include "object/object-broken.h"
41 #include "object/object-flags.h"
42 #include "object/object-generator.h"
43 #include "object/object-info.h"
44 #include "object/object-kind.h"
45 #include "object/object-stack.h"
46 #include "player/attack-defense-types.h"
47 #include "player/special-defense-types.h"
48 #include "racial/racial-android.h"
49 #include "specific-object/torch.h"
50 #include "status/action-setter.h"
51 #include "system/floor-type-definition.h"
52 #include "system/object-type-definition.h"
53 #include "term/screen-processor.h"
54 #include "util/bit-flags-calculator.h"
55 #include "view/display-messages.h"
56 #include "view/object-describer.h"
57 #include "wizard/wizard-messages.h"
60 * @brief 投射処理メインルーチン /
61 * Throw an object from the pack or floor.
63 * @param creature_ptr プレーヤーへの参照ポインタ
64 * @param boomerang ブーメラン処理ならばTRUE
65 * @param shuriken 忍者の手裏剣処理ならばTRUE
66 * @return ターンを消費した場合TRUEを返す
69 * Note: "unseen" monsters are very hard to hit.
71 * Should throwing a weapon do full damage? Should it allow the magic
72 * to hit bonus of the weapon to have an effect? Should it ever cause
73 * the item to be destroyed? Should it do any damage at all?
76 bool do_cmd_throw(player_type *creature_ptr, int mult, bool boomerang, OBJECT_IDX shuriken)
81 POSITION y, x, ty, tx, prev_y, prev_x;
82 POSITION ny[19], nx[19];
83 int chance, tdam, tdis;
90 bool hit_body = FALSE;
91 bool hit_wall = FALSE;
92 bool equiped_item = FALSE;
93 bool return_when_thrown = FALSE;
94 GAME_TEXT o_name[MAX_NLEN];
95 int msec = delay_factor * delay_factor * delay_factor;
96 BIT_FLAGS flgs[TR_FLAG_SIZE];
98 bool come_back = FALSE;
100 if (creature_ptr->wild_mode)
103 if (creature_ptr->special_defense & KATA_MUSOU)
104 set_action(creature_ptr, ACTION_NONE);
108 o_ptr = &creature_ptr->inventory_list[item];
109 } else if (boomerang) {
110 if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM)) {
111 item_tester_hook = item_tester_hook_boomerang;
112 q = _("どの武器を投げますか? ", "Throw which item? ");
113 s = _("投げる武器がない。", "You have nothing to throw.");
114 o_ptr = choose_object(creature_ptr, &item, q, s, USE_EQUIP, 0);
119 } else if (has_melee_weapon(creature_ptr, INVEN_LARM)) {
121 o_ptr = &creature_ptr->inventory_list[item];
124 o_ptr = &creature_ptr->inventory_list[item];
127 q = _("どのアイテムを投げますか? ", "Throw which item? ");
128 s = _("投げるアイテムがない。", "You have nothing to throw.");
129 o_ptr = choose_object(creature_ptr, &item, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
136 if (object_is_cursed(o_ptr) && (item >= INVEN_RARM)) {
137 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
141 if (creature_ptr->current_floor_ptr->inside_arena && !boomerang && (o_ptr->tval != TV_SPIKE)) {
142 msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
148 object_copy(q_ptr, o_ptr);
149 object_flags(creature_ptr, q_ptr, flgs);
150 torch_flags(q_ptr, flgs);
151 distribute_charges(o_ptr, q_ptr, 1);
153 describe_flavor(creature_ptr, o_name, q_ptr, OD_OMIT_PREFIX);
154 if (creature_ptr->mighty_throw)
157 mul = 10 + 2 * (mult - 1);
158 div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
159 if ((have_flag(flgs, TR_THROW)) || boomerang)
162 tdis = (adj_str_blow[creature_ptr->stat_ind[A_STR]] + 20) * mul / div;
167 ty = randint0(101) - 50 + creature_ptr->y;
168 tx = randint0(101) - 50 + creature_ptr->x;
170 project_length = tdis + 1;
171 if (!get_aim_dir(creature_ptr, &dir))
174 tx = creature_ptr->x + 99 * ddx[dir];
175 ty = creature_ptr->y + 99 * ddy[dir];
176 if ((dir == 5) && target_okay(creature_ptr)) {
181 project_length = 0; /* reset to default */
184 if ((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG) || boomerang)
185 return_when_thrown = TRUE;
188 inven_item_increase(creature_ptr, item, -1);
189 if (!return_when_thrown)
190 inven_item_describe(creature_ptr, item);
191 inven_item_optimize(creature_ptr, item);
193 floor_item_increase(creature_ptr->current_floor_ptr, 0 - item, -1);
194 floor_item_optimize(creature_ptr, 0 - item);
197 if (item >= INVEN_RARM) {
199 creature_ptr->redraw |= PR_EQUIPPY;
202 take_turn(creature_ptr, 100);
203 if ((creature_ptr->pclass == CLASS_ROGUE) || (creature_ptr->pclass == CLASS_NINJA))
204 creature_ptr->energy_use -= creature_ptr->lev;
208 handle_stuff(creature_ptr);
209 if ((creature_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD))))
214 if (have_flag(flgs, TR_THROW))
215 chance = ((creature_ptr->skill_tht) + ((creature_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
217 chance = (creature_ptr->skill_tht + (creature_ptr->to_h_b * BTH_PLUS_ADJ));
224 for (cur_dis = 0; cur_dis <= tdis;) {
225 if ((y == ty) && (x == tx))
230 mmove2(&ny[cur_dis], &nx[cur_dis], creature_ptr->y, creature_ptr->x, ty, tx);
231 if (!cave_have_flag_bold(creature_ptr->current_floor_ptr, ny[cur_dis], nx[cur_dis], FF_PROJECT)) {
233 if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !creature_ptr->current_floor_ptr->grid_array[ny[cur_dis]][nx[cur_dis]].m_idx)
237 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(creature_ptr, ny[cur_dis], nx[cur_dis])) {
238 SYMBOL_CODE c = object_char(q_ptr);
239 TERM_COLOR a = object_attr(q_ptr);
240 print_rel(creature_ptr, c, a, ny[cur_dis], nx[cur_dis]);
241 move_cursor_relative(ny[cur_dis], nx[cur_dis]);
243 term_xtra(TERM_XTRA_DELAY, msec);
244 lite_spot(creature_ptr, ny[cur_dis], nx[cur_dis]);
247 term_xtra(TERM_XTRA_DELAY, msec);
255 if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
256 grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
257 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
258 GAME_TEXT m_name[MAX_NLEN];
259 monster_name(creature_ptr, g_ptr->m_idx, m_name);
262 if (test_hit_fire(creature_ptr, chance - cur_dis, m_ptr, m_ptr->ml, o_name)) {
265 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
267 msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
269 if (!creature_ptr->image)
270 monster_race_track(creature_ptr, m_ptr->ap_r_idx);
271 health_track(creature_ptr, g_ptr->m_idx);
277 torch_dice(q_ptr, &dd, &ds);
278 tdam = damroll(dd, ds);
279 tdam = calc_attack_damage_with_slay(creature_ptr, q_ptr, tdam, m_ptr, 0, TRUE);
280 tdam = critical_shot(creature_ptr, q_ptr->weight, q_ptr->to_h, 0, tdam);
284 tdam += -q_ptr->to_d;
287 tdam *= (mult + creature_ptr->num_blow[item - INVEN_RARM]);
288 tdam += creature_ptr->to_d_m;
289 } else if (have_flag(flgs, TR_THROW)) {
291 tdam += creature_ptr->to_d_m;
297 tdam += ((creature_ptr->lev + 30) * (creature_ptr->lev + 30) - 900) / 55;
302 tdam = mon_damage_mod(creature_ptr, m_ptr, tdam, FALSE);
303 msg_format_wizard(creature_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), tdam,
304 m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
306 if (mon_take_hit(creature_ptr, g_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_idx(m_ptr)))) {
309 message_pain(creature_ptr, g_ptr->m_idx, tdam);
310 if ((tdam > 0) && !object_is_potion(q_ptr))
311 anger_monster(creature_ptr, m_ptr);
313 if (fear && m_ptr->ml) {
315 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
325 torch_lost_fuel(q_ptr);
327 j = (hit_body ? breakage_chance(creature_ptr, q_ptr, creature_ptr->pclass == CLASS_ARCHER, 0) : 0);
329 if ((q_ptr->tval == TV_FIGURINE) && !(creature_ptr->current_floor_ptr->inside_arena)) {
331 if (!(summon_named_creature(creature_ptr, 0, y, x, q_ptr->pval, !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
332 msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
333 else if (object_is_cursed(q_ptr))
334 msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
337 if (object_is_potion(q_ptr)) {
338 if (hit_body || hit_wall || (randint1(100) < j)) {
339 msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
340 if (potion_smash_effect(creature_ptr, 0, y, x, q_ptr->k_idx)) {
341 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx];
342 if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx && is_friendly(m_ptr) && !monster_invulner_remaining(m_ptr)) {
343 GAME_TEXT m_name[MAX_NLEN];
344 monster_desc(creature_ptr, m_name, m_ptr, 0);
345 msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
346 set_hostile(creature_ptr, &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx]);
356 if (return_when_thrown) {
357 int back_chance = randint1(30) + 20 + ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
358 char o2_name[MAX_NLEN];
359 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
362 back_chance += 4 + randint1(5);
365 describe_flavor(creature_ptr, o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
366 if ((back_chance > 30) && (!one_in_(100) || super_boomerang)) {
367 for (i = cur_dis - 1; i > 0; i--) {
368 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(creature_ptr, ny[i], nx[i])) {
369 SYMBOL_CODE c = object_char(q_ptr);
370 byte a = object_attr(q_ptr);
371 print_rel(creature_ptr, c, a, ny[i], nx[i]);
372 move_cursor_relative(ny[i], nx[i]);
374 term_xtra(TERM_XTRA_DELAY, msec);
375 lite_spot(creature_ptr, ny[i], nx[i]);
378 term_xtra(TERM_XTRA_DELAY, msec);
382 if ((back_chance > 37) && !creature_ptr->blind && (item >= 0)) {
383 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
387 msg_format(_("%sを受け損ねた!", "%s comes back, but you can't catch!"), o2_name);
389 msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
395 msg_format(_("%sが返ってこなかった!", "%s doesn't come back!"), o2_name);
400 if (item == INVEN_RARM || item == INVEN_LARM) {
401 o_ptr = &creature_ptr->inventory_list[item];
402 object_copy(o_ptr, q_ptr);
403 creature_ptr->total_weight += q_ptr->weight;
404 creature_ptr->equip_cnt++;
405 creature_ptr->update |= PU_BONUS | PU_TORCH | PU_MANA;
406 creature_ptr->window |= PW_EQUIP;
408 store_item_to_inventory(creature_ptr, q_ptr);
412 } else if (equiped_item) {
413 verify_equip_slot(creature_ptr, item);
414 calc_android_exp(creature_ptr);
418 if (cave_have_flag_bold(creature_ptr->current_floor_ptr, y, x, FF_PROJECT)) {
419 (void)drop_near(creature_ptr, q_ptr, j, y, x);
421 (void)drop_near(creature_ptr, q_ptr, j, prev_y, prev_x);