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/floor-object.h"
15 #include "floor/floor.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 "mind/racial-android.h"
29 #include "monster-floor/monster-death.h"
30 #include "monster-floor/monster-summon.h"
31 #include "monster-floor/place-monster-types.h"
32 #include "monster/monster-describer.h"
33 #include "monster/monster-info.h"
34 #include "monster/monster-status.h"
35 #include "object-enchant/tr-types.h"
36 #include "object-hook/hook-checker.h"
37 #include "object-hook/hook-expendable.h"
38 #include "object-hook/hook-weapon.h"
39 #include "object/item-tester-hooker.h"
40 #include "object/item-use-flags.h"
41 #include "object/object-broken.h"
42 #include "object/object-flags.h"
43 #include "object/object-generator.h"
44 #include "object/object-info.h"
45 #include "object/object-kind.h"
46 #include "object/object-stack.h"
47 #include "player/attack-defense-types.h"
48 #include "player/special-defense-types.h"
49 #include "specific-object/torch.h"
50 #include "status/action-setter.h"
51 #include "system/object-type-definition.h"
52 #include "term/screen-processor.h"
53 #include "util/bit-flags-calculator.h"
54 #include "view/display-messages.h"
55 #include "view/object-describer.h"
56 #include "wizard/wizard-messages.h"
59 * @brief 投射処理メインルーチン /
60 * Throw an object from the pack or floor.
62 * @param creature_ptr プレーヤーへの参照ポインタ
63 * @param boomerang ブーメラン処理ならばTRUE
64 * @param shuriken 忍者の手裏剣処理ならばTRUE
65 * @return ターンを消費した場合TRUEを返す
68 * Note: "unseen" monsters are very hard to hit.
70 * Should throwing a weapon do full damage? Should it allow the magic
71 * to hit bonus of the weapon to have an effect? Should it ever cause
72 * the item to be destroyed? Should it do any damage at all?
75 bool do_cmd_throw(player_type *creature_ptr, int mult, bool boomerang, OBJECT_IDX shuriken)
80 POSITION y, x, ty, tx, prev_y, prev_x;
81 POSITION ny[19], nx[19];
82 int chance, tdam, tdis;
89 bool hit_body = FALSE;
90 bool hit_wall = FALSE;
91 bool equiped_item = FALSE;
92 bool return_when_thrown = FALSE;
93 GAME_TEXT o_name[MAX_NLEN];
94 int msec = delay_factor * delay_factor * delay_factor;
95 BIT_FLAGS flgs[TR_FLAG_SIZE];
97 bool come_back = FALSE;
99 if (creature_ptr->wild_mode)
102 if (creature_ptr->special_defense & KATA_MUSOU)
103 set_action(creature_ptr, ACTION_NONE);
107 o_ptr = &creature_ptr->inventory_list[item];
108 } else if (boomerang) {
109 if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM)) {
110 item_tester_hook = item_tester_hook_boomerang;
111 q = _("どの武器を投げますか? ", "Throw which item? ");
112 s = _("投げる武器がない。", "You have nothing to throw.");
113 o_ptr = choose_object(creature_ptr, &item, q, s, USE_EQUIP, 0);
118 } else if (has_melee_weapon(creature_ptr, INVEN_LARM)) {
120 o_ptr = &creature_ptr->inventory_list[item];
123 o_ptr = &creature_ptr->inventory_list[item];
126 q = _("どのアイテムを投げますか? ", "Throw which item? ");
127 s = _("投げるアイテムがない。", "You have nothing to throw.");
128 o_ptr = choose_object(creature_ptr, &item, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
135 if (object_is_cursed(o_ptr) && (item >= INVEN_RARM)) {
136 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
140 if (creature_ptr->current_floor_ptr->inside_arena && !boomerang && (o_ptr->tval != TV_SPIKE)) {
141 msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
147 object_copy(q_ptr, o_ptr);
148 object_flags(creature_ptr, q_ptr, flgs);
149 torch_flags(q_ptr, flgs);
150 distribute_charges(o_ptr, q_ptr, 1);
152 describe_flavor(creature_ptr, o_name, q_ptr, OD_OMIT_PREFIX);
153 if (creature_ptr->mighty_throw)
156 mul = 10 + 2 * (mult - 1);
157 div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
158 if ((have_flag(flgs, TR_THROW)) || boomerang)
161 tdis = (adj_str_blow[creature_ptr->stat_ind[A_STR]] + 20) * mul / div;
166 ty = randint0(101) - 50 + creature_ptr->y;
167 tx = randint0(101) - 50 + creature_ptr->x;
169 project_length = tdis + 1;
170 if (!get_aim_dir(creature_ptr, &dir))
173 tx = creature_ptr->x + 99 * ddx[dir];
174 ty = creature_ptr->y + 99 * ddy[dir];
175 if ((dir == 5) && target_okay(creature_ptr)) {
180 project_length = 0; /* reset to default */
183 if ((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG) || boomerang)
184 return_when_thrown = TRUE;
187 inven_item_increase(creature_ptr, item, -1);
188 if (!return_when_thrown)
189 inven_item_describe(creature_ptr, item);
190 inven_item_optimize(creature_ptr, item);
192 floor_item_increase(creature_ptr->current_floor_ptr, 0 - item, -1);
193 floor_item_optimize(creature_ptr, 0 - item);
196 if (item >= INVEN_RARM) {
198 creature_ptr->redraw |= PR_EQUIPPY;
201 take_turn(creature_ptr, 100);
202 if ((creature_ptr->pclass == CLASS_ROGUE) || (creature_ptr->pclass == CLASS_NINJA))
203 creature_ptr->energy_use -= creature_ptr->lev;
207 handle_stuff(creature_ptr);
208 if ((creature_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD))))
213 if (have_flag(flgs, TR_THROW))
214 chance = ((creature_ptr->skill_tht) + ((creature_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
216 chance = (creature_ptr->skill_tht + (creature_ptr->to_h_b * BTH_PLUS_ADJ));
223 for (cur_dis = 0; cur_dis <= tdis;) {
224 if ((y == ty) && (x == tx))
229 mmove2(&ny[cur_dis], &nx[cur_dis], creature_ptr->y, creature_ptr->x, ty, tx);
230 if (!cave_have_flag_bold(creature_ptr->current_floor_ptr, ny[cur_dis], nx[cur_dis], FF_PROJECT)) {
232 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)
236 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(creature_ptr, ny[cur_dis], nx[cur_dis])) {
237 SYMBOL_CODE c = object_char(q_ptr);
238 TERM_COLOR a = object_attr(q_ptr);
239 print_rel(creature_ptr, c, a, ny[cur_dis], nx[cur_dis]);
240 move_cursor_relative(ny[cur_dis], nx[cur_dis]);
242 term_xtra(TERM_XTRA_DELAY, msec);
243 lite_spot(creature_ptr, ny[cur_dis], nx[cur_dis]);
246 term_xtra(TERM_XTRA_DELAY, msec);
254 if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
255 grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
256 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
257 GAME_TEXT m_name[MAX_NLEN];
258 monster_name(creature_ptr, g_ptr->m_idx, m_name);
261 if (test_hit_fire(creature_ptr, chance - cur_dis, m_ptr, m_ptr->ml, o_name)) {
264 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
266 msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
268 if (!creature_ptr->image)
269 monster_race_track(creature_ptr, m_ptr->ap_r_idx);
270 health_track(creature_ptr, g_ptr->m_idx);
276 torch_dice(q_ptr, &dd, &ds);
277 tdam = damroll(dd, ds);
278 tdam = calc_attack_damage_with_slay(creature_ptr, q_ptr, tdam, m_ptr, 0, TRUE);
279 tdam = critical_shot(creature_ptr, q_ptr->weight, q_ptr->to_h, 0, tdam);
283 tdam += -q_ptr->to_d;
286 tdam *= (mult + creature_ptr->num_blow[item - INVEN_RARM]);
287 tdam += creature_ptr->to_d_m;
288 } else if (have_flag(flgs, TR_THROW)) {
290 tdam += creature_ptr->to_d_m;
296 tdam += ((creature_ptr->lev + 30) * (creature_ptr->lev + 30) - 900) / 55;
301 tdam = mon_damage_mod(creature_ptr, m_ptr, tdam, FALSE);
302 msg_format_wizard(creature_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), tdam,
303 m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
305 if (mon_take_hit(creature_ptr, g_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_idx(m_ptr)))) {
308 message_pain(creature_ptr, g_ptr->m_idx, tdam);
309 if ((tdam > 0) && !object_is_potion(q_ptr))
310 anger_monster(creature_ptr, m_ptr);
312 if (fear && m_ptr->ml) {
314 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
324 torch_lost_fuel(q_ptr);
326 j = (hit_body ? breakage_chance(creature_ptr, q_ptr, creature_ptr->pclass == CLASS_ARCHER, 0) : 0);
328 if ((q_ptr->tval == TV_FIGURINE) && !(creature_ptr->current_floor_ptr->inside_arena)) {
330 if (!(summon_named_creature(creature_ptr, 0, y, x, q_ptr->pval, !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
331 msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
332 else if (object_is_cursed(q_ptr))
333 msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
336 if (object_is_potion(q_ptr)) {
337 if (hit_body || hit_wall || (randint1(100) < j)) {
338 msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
339 if (potion_smash_effect(creature_ptr, 0, y, x, q_ptr->k_idx)) {
340 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx];
341 if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx && is_friendly(m_ptr) && !monster_invulner_remaining(m_ptr)) {
342 GAME_TEXT m_name[MAX_NLEN];
343 monster_desc(creature_ptr, m_name, m_ptr, 0);
344 msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
345 set_hostile(creature_ptr, &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx]);
355 if (return_when_thrown) {
356 int back_chance = randint1(30) + 20 + ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
357 char o2_name[MAX_NLEN];
358 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
361 back_chance += 4 + randint1(5);
364 describe_flavor(creature_ptr, o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
365 if ((back_chance > 30) && (!one_in_(100) || super_boomerang)) {
366 for (i = cur_dis - 1; i > 0; i--) {
367 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(creature_ptr, ny[i], nx[i])) {
368 SYMBOL_CODE c = object_char(q_ptr);
369 byte a = object_attr(q_ptr);
370 print_rel(creature_ptr, c, a, ny[i], nx[i]);
371 move_cursor_relative(ny[i], nx[i]);
373 term_xtra(TERM_XTRA_DELAY, msec);
374 lite_spot(creature_ptr, ny[i], nx[i]);
377 term_xtra(TERM_XTRA_DELAY, msec);
381 if ((back_chance > 37) && !creature_ptr->blind && (item >= 0)) {
382 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
386 msg_format(_("%sを受け損ねた!", "%s comes back, but you can't catch!"), o2_name);
388 msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
394 msg_format(_("%sが返ってこなかった!", "%s doesn't come back!"), o2_name);
399 if (item == INVEN_RARM || item == INVEN_LARM) {
400 o_ptr = &creature_ptr->inventory_list[item];
401 object_copy(o_ptr, q_ptr);
402 creature_ptr->total_weight += q_ptr->weight;
403 creature_ptr->equip_cnt++;
404 creature_ptr->update |= PU_BONUS | PU_TORCH | PU_MANA;
405 creature_ptr->window |= PW_EQUIP;
407 store_item_to_inventory(creature_ptr, q_ptr);
411 } else if (equiped_item) {
412 verify_equip_slot(creature_ptr, item);
413 calc_android_exp(creature_ptr);
417 if (cave_have_flag_bold(creature_ptr->current_floor_ptr, y, x, FF_PROJECT)) {
418 (void)drop_near(creature_ptr, q_ptr, j, y, x);
420 (void)drop_near(creature_ptr, q_ptr, j, prev_y, prev_x);