OSDN Git Service

[Refactor] #37353 複数の is_bound* マクロを floor.h へ移動。
[hengband/hengband.git] / src / shoot.c
1 #include "angband.h"
2 #include "monster.h"
3 #include "monster-status.h"
4 #include "monster-spell.h"
5 #include "artifact.h"
6 #include "avatar.h"
7 #include "player-status.h"
8 #include "object-hook.h"
9 #include "floor.h"
10
11 #include "shoot.h"
12
13 /*!
14  * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
15  * Determines the odds of an object breaking when thrown at a monster
16  * @param o_ptr 矢弾のオブジェクト構造体参照ポインタ
17  * @param tdam 計算途中のダメージ量
18  * @param m_ptr 目標モンスターの構造体参照ポインタ
19  * @return スレイ倍率をかけたダメージ量
20  */
21 static MULTIPLY tot_dam_aux_shot(object_type *o_ptr, HIT_POINT tdam, monster_type *m_ptr, SPELL_IDX snipe_type)
22 {
23         MULTIPLY mult = 10;
24
25         monster_race *r_ptr = &r_info[m_ptr->r_idx];
26
27         BIT_FLAGS flgs[TR_FLAG_SIZE];
28         object_flags(o_ptr, flgs);
29
30         /* Some "weapons" and "ammo" do extra damage */
31         switch (o_ptr->tval)
32         {
33         case TV_SHOT:
34         case TV_ARROW:
35         case TV_BOLT:
36         {
37                 if ((have_flag(flgs, TR_SLAY_ANIMAL)) && (r_ptr->flags3 & RF3_ANIMAL))
38                 {
39                         if (is_original_ap_and_seen(m_ptr))
40                         {
41                                 r_ptr->r_flags3 |= RF3_ANIMAL;
42                         }
43                         if (mult < 17) mult = 17;
44                 }
45
46                 if ((have_flag(flgs, TR_KILL_ANIMAL)) && (r_ptr->flags3 & RF3_ANIMAL))
47                 {
48                         if (is_original_ap_and_seen(m_ptr))
49                         {
50                                 r_ptr->r_flags3 |= RF3_ANIMAL;
51                         }
52                         if (mult < 27) mult = 27;
53                 }
54
55                 if ((have_flag(flgs, TR_SLAY_EVIL)) && (r_ptr->flags3 & RF3_EVIL))
56                 {
57                         if (is_original_ap_and_seen(m_ptr))
58                         {
59                                 r_ptr->r_flags3 |= RF3_EVIL;
60                         }
61                         if (mult < 15) mult = 15;
62                 }
63
64                 if ((have_flag(flgs, TR_KILL_EVIL)) && (r_ptr->flags3 & RF3_EVIL))
65                 {
66                         if (is_original_ap_and_seen(m_ptr))
67                         {
68                                 r_ptr->r_flags3 |= RF3_EVIL;
69                         }
70                         if (mult < 25) mult = 25;
71                 }
72
73                 if ((have_flag(flgs, TR_SLAY_HUMAN)) && (r_ptr->flags2 & RF2_HUMAN))
74                 {
75                         if (is_original_ap_and_seen(m_ptr))
76                         {
77                                 r_ptr->r_flags2 |= RF2_HUMAN;
78                         }
79                         if (mult < 17) mult = 17;
80                 }
81
82                 if ((have_flag(flgs, TR_KILL_HUMAN)) && (r_ptr->flags2 & RF2_HUMAN))
83                 {
84                         if (is_original_ap_and_seen(m_ptr))
85                         {
86                                 r_ptr->r_flags2 |= RF2_HUMAN;
87                         }
88                         if (mult < 27) mult = 27;
89                 }
90
91                 if ((have_flag(flgs, TR_SLAY_UNDEAD)) && (r_ptr->flags3 & RF3_UNDEAD))
92                 {
93                         if (is_original_ap_and_seen(m_ptr))
94                         {
95                                 r_ptr->r_flags3 |= RF3_UNDEAD;
96                         }
97                         if (mult < 20) mult = 20;
98                 }
99
100                 if ((have_flag(flgs, TR_KILL_UNDEAD)) && (r_ptr->flags3 & RF3_UNDEAD))
101                 {
102                         if (is_original_ap_and_seen(m_ptr))
103                         {
104                                 r_ptr->r_flags3 |= RF3_UNDEAD;
105                         }
106                         if (mult < 30) mult = 30;
107                 }
108
109                 if ((have_flag(flgs, TR_SLAY_DEMON)) && (r_ptr->flags3 & RF3_DEMON))
110                 {
111                         if (is_original_ap_and_seen(m_ptr))
112                         {
113                                 r_ptr->r_flags3 |= RF3_DEMON;
114                         }
115                         if (mult < 20) mult = 20;
116                 }
117
118                 if ((have_flag(flgs, TR_KILL_DEMON)) && (r_ptr->flags3 & RF3_DEMON))
119                 {
120                         if (is_original_ap_and_seen(m_ptr))
121                         {
122                                 r_ptr->r_flags3 |= RF3_DEMON;
123                         }
124                         if (mult < 30) mult = 30;
125                 }
126
127                 if ((have_flag(flgs, TR_SLAY_ORC)) && (r_ptr->flags3 & RF3_ORC))
128                 {
129                         if (is_original_ap_and_seen(m_ptr))
130                         {
131                                 r_ptr->r_flags3 |= RF3_ORC;
132                         }
133                         if (mult < 20) mult = 20;
134                 }
135
136                 if ((have_flag(flgs, TR_KILL_ORC)) && (r_ptr->flags3 & RF3_ORC))
137                 {
138                         if (is_original_ap_and_seen(m_ptr))
139                         {
140                                 r_ptr->r_flags3 |= RF3_ORC;
141                         }
142                         if (mult < 30) mult = 30;
143                 }
144
145                 if ((have_flag(flgs, TR_SLAY_TROLL)) && (r_ptr->flags3 & RF3_TROLL))
146                 {
147                         if (is_original_ap_and_seen(m_ptr))
148                         {
149                                 r_ptr->r_flags3 |= RF3_TROLL;
150                         }
151
152                         if (mult < 20) mult = 20;
153                 }
154
155                 if ((have_flag(flgs, TR_KILL_TROLL)) && (r_ptr->flags3 & RF3_TROLL))
156                 {
157                         if (is_original_ap_and_seen(m_ptr))
158                         {
159                                 r_ptr->r_flags3 |= RF3_TROLL;
160                         }
161                         if (mult < 30) mult = 30;
162                 }
163
164                 if ((have_flag(flgs, TR_SLAY_GIANT)) && (r_ptr->flags3 & RF3_GIANT))
165                 {
166                         if (is_original_ap_and_seen(m_ptr))
167                         {
168                                 r_ptr->r_flags3 |= RF3_GIANT;
169                         }
170                         if (mult < 20) mult = 20;
171                 }
172
173                 if ((have_flag(flgs, TR_KILL_GIANT)) && (r_ptr->flags3 & RF3_GIANT))
174                 {
175                         if (is_original_ap_and_seen(m_ptr))
176                         {
177                                 r_ptr->r_flags3 |= RF3_GIANT;
178                         }
179                         if (mult < 30) mult = 30;
180                 }
181
182                 if ((have_flag(flgs, TR_SLAY_DRAGON)) && (r_ptr->flags3 & RF3_DRAGON))
183                 {
184                         if (is_original_ap_and_seen(m_ptr))
185                         {
186                                 r_ptr->r_flags3 |= RF3_DRAGON;
187                         }
188                         if (mult < 20) mult = 20;
189                 }
190
191                 if ((have_flag(flgs, TR_KILL_DRAGON)) && (r_ptr->flags3 & RF3_DRAGON))
192                 {
193                         if (is_original_ap_and_seen(m_ptr))
194                         {
195                                 r_ptr->r_flags3 |= RF3_DRAGON;
196                         }
197                         if (mult < 30) mult = 30;
198                         if ((o_ptr->name1 == ART_BARD_ARROW) && (m_ptr->r_idx == MON_SMAUG) &&
199                                 (inventory[INVEN_BOW].name1 == ART_BARD))
200                                 mult *= 5;
201                 }
202
203                 if (have_flag(flgs, TR_BRAND_ACID))
204                 {
205                         /* Notice immunity */
206                         if (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)
207                         {
208                                 if (is_original_ap_and_seen(m_ptr))
209                                 {
210                                         r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK);
211                                 }
212                         }
213                         else
214                         {
215                                 if (mult < 17) mult = 17;
216                         }
217                 }
218
219                 if (have_flag(flgs, TR_BRAND_ELEC))
220                 {
221                         /* Notice immunity */
222                         if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
223                         {
224                                 if (is_original_ap_and_seen(m_ptr))
225                                 {
226                                         r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
227                                 }
228                         }
229                         else
230                         {
231                                 if (mult < 17) mult = 17;
232                         }
233                 }
234
235                 if (have_flag(flgs, TR_BRAND_FIRE))
236                 {
237                         /* Notice immunity */
238                         if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
239                         {
240                                 if (is_original_ap_and_seen(m_ptr))
241                                 {
242                                         r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
243                                 }
244                         }
245                         /* Otherwise, take the damage */
246                         else
247                         {
248                                 if (r_ptr->flags3 & RF3_HURT_FIRE)
249                                 {
250                                         if (mult < 25) mult = 25;
251                                         if (is_original_ap_and_seen(m_ptr))
252                                         {
253                                                 r_ptr->r_flags3 |= RF3_HURT_FIRE;
254                                         }
255                                 }
256                                 else if (mult < 17) mult = 17;
257                         }
258                 }
259
260                 if (have_flag(flgs, TR_BRAND_COLD))
261                 {
262                         /* Notice immunity */
263                         if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
264                         {
265                                 if (is_original_ap_and_seen(m_ptr))
266                                 {
267                                         r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
268                                 }
269                         }
270                         /* Otherwise, take the damage */
271                         else
272                         {
273                                 if (r_ptr->flags3 & RF3_HURT_COLD)
274                                 {
275                                         if (mult < 25) mult = 25;
276                                         if (is_original_ap_and_seen(m_ptr))
277                                         {
278                                                 r_ptr->r_flags3 |= RF3_HURT_COLD;
279                                         }
280                                 }
281                                 else if (mult < 17) mult = 17;
282                         }
283                 }
284
285                 if (have_flag(flgs, TR_BRAND_POIS))
286                 {
287                         /* Notice immunity */
288                         if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
289                         {
290                                 if (is_original_ap_and_seen(m_ptr))
291                                 {
292                                         r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
293                                 }
294                         }
295                         /* Otherwise, take the damage */
296                         else
297                         {
298                                 if (mult < 17) mult = 17;
299                         }
300                 }
301
302                 if ((have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
303                 {
304                         p_ptr->csp -= (1 + (p_ptr->msp / 30));
305                         p_ptr->redraw |= (PR_MANA);
306                         mult = mult * 5 / 2;
307                 }
308                 break;
309         }
310         }
311
312         /* Sniper */
313         if (snipe_type) mult = tot_dam_aux_snipe(mult, m_ptr, snipe_type);
314
315         /* Return the total damage */
316         return (tdam * mult / 10);
317 }
318
319
320 /*!
321  * @brief 射撃処理実行 /
322  * Fire an object from the pack or floor.
323  * @param item 射撃するオブジェクトの所持ID
324  * @param j_ptr 射撃武器のオブジェクト参照ポインタ
325  * @return なし
326  * @details
327  * <pre>
328  * You may only fire items that "match" your missile launcher.
329  * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
330  * See "calc_bonuses()" for more calculations and such.
331  * Note that "firing" a missile is MUCH better than "throwing" it.
332  * Note: "unseen" monsters are very hard to hit.
333  * Objects are more likely to break if they "attempt" to hit a monster.
334  * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
335  * The "extra shot" code works by decreasing the amount of energy
336  * required to make each shot, spreading the shots out over time.
337  * Note that when firing missiles, the launcher multiplier is applied
338  * after all the bonuses are added in, making multipliers very useful.
339  * Note that Bows of "Extra Might" get extra range and an extra bonus
340  * for the damage multiplier.
341  * Note that Bows of "Extra Shots" give an extra shot.
342  * </pre>
343  */
344 void exe_fire(INVENTORY_IDX item, object_type *j_ptr, SPELL_IDX snipe_type)
345 {
346         DIRECTION dir;
347         int i;
348         POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
349         int tdam_base, tdis, thits, tmul;
350         int bonus, chance;
351         int cur_dis, visible;
352         PERCENTAGE j;
353
354         object_type forge;
355         object_type *q_ptr;
356
357         object_type *o_ptr;
358
359         bool hit_body = FALSE;
360
361         GAME_TEXT o_name[MAX_NLEN];
362
363         u16b path_g[512];       /* For calcuration of path length */
364
365         int msec = delay_factor * delay_factor * delay_factor;
366
367         /* STICK TO */
368         bool stick_to = FALSE;
369
370         /* Access the item (if in the pack) */
371         if (item >= 0)
372         {
373                 o_ptr = &inventory[item];
374         }
375         else
376         {
377                 o_ptr = &current_floor_ptr->o_list[0 - item];
378         }
379
380         /* Sniper - Cannot shot a single arrow twice */
381         if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) snipe_type = SP_NONE;
382
383         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
384
385         /* Use the proper number of shots */
386         thits = p_ptr->num_fire;
387
388         /* Use a base distance */
389         tdis = 10;
390
391         /* Base damage from thrown object plus launcher bonus */
392         tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
393
394         /* Actually "fire" the object */
395         bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
396         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
397                 chance = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
398         else
399                 chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
400
401         p_ptr->energy_use = bow_energy(j_ptr->sval);
402         tmul = bow_tmul(j_ptr->sval);
403
404         /* Get extra "power" from "extra might" */
405         if (p_ptr->xtra_might) tmul++;
406
407         tmul = tmul * (100 + (int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
408
409         /* Boost the damage */
410         tdam_base *= tmul;
411         tdam_base /= 100;
412
413         /* Base range */
414         tdis = 13 + tmul / 80;
415         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
416         {
417                 if (p_ptr->concent)
418                         tdis -= (5 - (p_ptr->concent + 1) / 2);
419                 else
420                         tdis -= 5;
421         }
422
423         project_length = tdis + 1;
424
425         /* Get a direction (or cancel) */
426         if (!get_aim_dir(&dir))
427         {
428                 free_turn(p_ptr);
429
430                 if (snipe_type == SP_AWAY) snipe_type = SP_NONE;
431
432                 /* need not to reset project_length (already did)*/
433
434                 return;
435         }
436
437         /* Predict the "target" location */
438         tx = p_ptr->x + 99 * ddx[dir];
439         ty = p_ptr->y + 99 * ddy[dir];
440
441         /* Check for "target request" */
442         if ((dir == 5) && target_okay())
443         {
444                 tx = target_col;
445                 ty = target_row;
446         }
447
448         /* Get projection path length */
449         tdis = project_path(path_g, project_length, p_ptr->y, p_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU) - 1;
450
451         project_length = 0; /* reset to default */
452
453         /* Don't shoot at my feet */
454         if (tx == p_ptr->x && ty == p_ptr->y)
455         {
456                 free_turn(p_ptr);
457
458                 /* project_length is already reset to 0 */
459
460                 return;
461         }
462
463
464         /* Take a (partial) current_world_ptr->game_turn */
465         p_ptr->energy_use = (p_ptr->energy_use / thits);
466         is_fired = TRUE;
467
468         /* Sniper - Difficult to shot twice at 1 current_world_ptr->game_turn */
469         if (snipe_type == SP_DOUBLE)  p_ptr->concent = (p_ptr->concent + 1) / 2;
470
471         /* Sniper - Repeat shooting when double shots */
472         for (i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++)
473         {
474
475                 /* Start at the player */
476                 y = p_ptr->y;
477                 x = p_ptr->x;
478                 q_ptr = &forge;
479
480                 /* Obtain a local object */
481                 object_copy(q_ptr, o_ptr);
482
483                 /* Single object */
484                 q_ptr->number = 1;
485
486                 /* Reduce and describe inventory */
487                 if (item >= 0)
488                 {
489                         inven_item_increase(item, -1);
490                         inven_item_describe(item);
491                         inven_item_optimize(item);
492                 }
493
494                 /* Reduce and describe floor item */
495                 else
496                 {
497                         floor_item_increase(0 - item, -1);
498                         floor_item_optimize(0 - item);
499                 }
500
501                 sound(SOUND_SHOOT);
502                 handle_stuff();
503
504                 prev_y = y;
505                 prev_x = x;
506
507                 /* The shot does not hit yet */
508                 hit_body = FALSE;
509
510                 /* Travel until stopped */
511                 for (cur_dis = 0; cur_dis <= tdis; )
512                 {
513                         grid_type *g_ptr;
514
515                         /* Hack -- Stop at the target */
516                         if ((y == ty) && (x == tx)) break;
517
518                         /* Calculate the new location (see "project()") */
519                         ny = y;
520                         nx = x;
521                         mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
522
523                         /* Shatter Arrow */
524                         if (snipe_type == SP_KILL_WALL)
525                         {
526                                 g_ptr = &current_floor_ptr->grid_array[ny][nx];
527
528                                 if (cave_have_flag_grid(g_ptr, FF_HURT_ROCK) && !g_ptr->m_idx)
529                                 {
530                                         if (g_ptr->info & (CAVE_MARK)) msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
531                                         /* Forget the wall */
532                                         g_ptr->info &= ~(CAVE_MARK);
533                                         p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
534
535                                         /* Destroy the wall */
536                                         cave_alter_feat(ny, nx, FF_HURT_ROCK);
537
538                                         hit_body = TRUE;
539                                         break;
540                                 }
541                         }
542
543                         /* Stopped by walls/doors */
544                         if (!cave_have_flag_bold(ny, nx, FF_PROJECT) && !current_floor_ptr->grid_array[ny][nx].m_idx) break;
545
546                         /* Advance the distance */
547                         cur_dis++;
548
549                         /* Sniper */
550                         if (snipe_type == SP_LITE)
551                         {
552                                 current_floor_ptr->grid_array[ny][nx].info |= (CAVE_GLOW);
553                                 note_spot(ny, nx);
554                                 lite_spot(ny, nx);
555                         }
556
557                         /* The player can see the (on screen) missile */
558                         if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
559                         {
560                                 char c = object_char(q_ptr);
561                                 byte a = object_attr(q_ptr);
562
563                                 /* Draw, Hilite, Fresh, Pause, Erase */
564                                 print_rel(c, a, ny, nx);
565                                 move_cursor_relative(ny, nx);
566                                 Term_fresh();
567                                 Term_xtra(TERM_XTRA_DELAY, msec);
568                                 lite_spot(ny, nx);
569                                 Term_fresh();
570                         }
571
572                         /* The player cannot see the missile */
573                         else
574                         {
575                                 /* Pause anyway, for consistancy */
576                                 Term_xtra(TERM_XTRA_DELAY, msec);
577                         }
578
579                         /* Sniper */
580                         if (snipe_type == SP_KILL_TRAP)
581                         {
582                                 project(0, 0, ny, nx, 0, GF_KILL_TRAP,
583                                         (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM), -1);
584                         }
585
586                         /* Sniper */
587                         if (snipe_type == SP_EVILNESS)
588                         {
589                                 current_floor_ptr->grid_array[ny][nx].info &= ~(CAVE_GLOW | CAVE_MARK);
590                                 note_spot(ny, nx);
591                                 lite_spot(ny, nx);
592                         }
593
594                         prev_y = y;
595                         prev_x = x;
596
597                         /* Save the new location */
598                         x = nx;
599                         y = ny;
600
601                         /* Monster here, Try to hit it */
602                         if (current_floor_ptr->grid_array[y][x].m_idx)
603                         {
604                                 grid_type *c_mon_ptr = &current_floor_ptr->grid_array[y][x];
605
606                                 monster_type *m_ptr = &current_floor_ptr->m_list[c_mon_ptr->m_idx];
607                                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
608
609                                 /* Check the visibility */
610                                 visible = m_ptr->ml;
611
612                                 /* Note the collision */
613                                 hit_body = TRUE;
614
615                                 if (MON_CSLEEP(m_ptr))
616                                 {
617                                         if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
618                                         if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
619                                 }
620
621                                 if ((r_ptr->level + 10) > p_ptr->lev)
622                                 {
623                                         int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
624                                         if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
625                                         {
626                                                 SUB_EXP amount = 0;
627                                                 if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
628                                                 else if (now_exp < WEAPON_EXP_SKILLED) amount = 25;
629                                                 else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 10;
630                                                 else if (p_ptr->lev > 34) amount = 2;
631                                                 p_ptr->weapon_exp[0][j_ptr->sval] += amount;
632                                                 p_ptr->update |= (PU_BONUS);
633                                         }
634                                 }
635
636                                 if (p_ptr->riding)
637                                 {
638                                         if ((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING])
639                                                 && ((p_ptr->skill_exp[GINOU_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[current_floor_ptr->m_list[p_ptr->riding].r_idx].level)
640                                                 && one_in_(2))
641                                         {
642                                                 p_ptr->skill_exp[GINOU_RIDING] += 1;
643                                                 p_ptr->update |= (PU_BONUS);
644                                         }
645                                 }
646
647                                 /* Did we hit it (penalize range) */
648                                 if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
649                                 {
650                                         bool fear = FALSE;
651                                         int tdam = tdam_base;
652
653                                         /* Get extra damage from concentration */
654                                         if (p_ptr->concent) tdam = boost_concentration_damage(tdam);
655
656                                         /* Handle unseen monster */
657                                         if (!visible)
658                                         {
659                                                 /* Invisible monster */
660                                                 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
661                                         }
662
663                                         /* Handle visible monster */
664                                         else
665                                         {
666                                                 GAME_TEXT m_name[MAX_NLEN];
667
668                                                 /* Get "the monster" or "it" */
669                                                 monster_desc(m_name, m_ptr, 0);
670
671                                                 msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
672
673                                                 if (m_ptr->ml)
674                                                 {
675                                                         if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
676                                                         health_track(c_mon_ptr->m_idx);
677                                                 }
678                                         }
679
680                                         if (snipe_type == SP_NEEDLE)
681                                         {
682                                                 if ((randint1(randint1(r_ptr->level / (3 + p_ptr->concent)) + (8 - p_ptr->concent)) == 1)
683                                                         && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2))
684                                                 {
685                                                         GAME_TEXT m_name[MAX_NLEN];
686
687                                                         /* Get "the monster" or "it" */
688                                                         monster_desc(m_name, m_ptr, 0);
689
690                                                         tdam = m_ptr->hp + 1;
691                                                         msg_format(_("%sの急所に突き刺さった!", "Your shot sticked on a fatal spot of %s!"), m_name);
692                                                 }
693                                                 else tdam = 1;
694                                         }
695                                         else
696                                         {
697                                                 /* Apply special damage */
698                                                 tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr, snipe_type);
699                                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
700
701                                                 /* No negative damage */
702                                                 if (tdam < 0) tdam = 0;
703
704                                                 /* Modify the damage */
705                                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
706                                         }
707
708                                         msg_format_wizard(CHEAT_MONSTER,
709                                                 _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
710                                                 tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
711
712                                         /* Sniper */
713                                         if (snipe_type == SP_EXPLODE)
714                                         {
715                                                 u16b flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
716
717                                                 sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
718                                                 project(0, ((p_ptr->concent + 1) / 2 + 1), ny, nx, tdam, GF_MISSILE, flg, -1);
719                                                 break;
720                                         }
721
722                                         /* Sniper */
723                                         if (snipe_type == SP_HOLYNESS)
724                                         {
725                                                 current_floor_ptr->grid_array[ny][nx].info |= (CAVE_GLOW);
726                                                 note_spot(ny, nx);
727                                                 lite_spot(ny, nx);
728                                         }
729
730                                         /* Hit the monster, check for death */
731                                         if (mon_take_hit(c_mon_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_idx(m_ptr))))
732                                         {
733                                                 /* Dead monster */
734                                         }
735
736                                         /* No death */
737                                         else
738                                         {
739                                                 /* STICK TO */
740                                                 if (object_is_fixed_artifact(q_ptr) &&
741                                                         (p_ptr->pclass != CLASS_SNIPER || p_ptr->concent == 0))
742                                                 {
743                                                         GAME_TEXT m_name[MAX_NLEN];
744
745                                                         monster_desc(m_name, m_ptr, 0);
746
747                                                         stick_to = TRUE;
748                                                         msg_format(_("%sは%sに突き刺さった!", "%^s have stuck into %s!"), o_name, m_name);
749                                                 }
750
751                                                 message_pain(c_mon_ptr->m_idx, tdam);
752
753                                                 /* Anger the monster */
754                                                 if (tdam > 0) anger_monster(m_ptr);
755
756                                                 if (fear && m_ptr->ml)
757                                                 {
758                                                         GAME_TEXT m_name[MAX_NLEN];
759                                                         sound(SOUND_FLEE);
760                                                         monster_desc(m_name, m_ptr, 0);
761                                                         msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
762                                                 }
763
764                                                 set_target(m_ptr, p_ptr->y, p_ptr->x);
765
766                                                 /* Sniper */
767                                                 if (snipe_type == SP_RUSH)
768                                                 {
769                                                         int n = randint1(5) + 3;
770                                                         MONSTER_IDX m_idx = c_mon_ptr->m_idx;
771
772                                                         for (; cur_dis <= tdis; )
773                                                         {
774                                                                 POSITION ox = nx;
775                                                                 POSITION oy = ny;
776
777                                                                 if (!n) break;
778
779                                                                 /* Calculate the new location (see "project()") */
780                                                                 mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
781
782                                                                 /* Stopped by wilderness boundary */
783                                                                 if (!in_bounds2(ny, nx)) break;
784
785                                                                 /* Stopped by walls/doors */
786                                                                 if (!player_can_enter(current_floor_ptr->grid_array[ny][nx].feat, 0)) break;
787
788                                                                 /* Stopped by monsters */
789                                                                 if (!cave_empty_bold(ny, nx)) break;
790
791                                                                 current_floor_ptr->grid_array[ny][nx].m_idx = m_idx;
792                                                                 current_floor_ptr->grid_array[oy][ox].m_idx = 0;
793
794                                                                 m_ptr->fx = nx;
795                                                                 m_ptr->fy = ny;
796
797                                                                 update_monster(c_mon_ptr->m_idx, TRUE);
798
799                                                                 lite_spot(ny, nx);
800                                                                 lite_spot(oy, ox);
801
802                                                                 Term_fresh();
803                                                                 Term_xtra(TERM_XTRA_DELAY, msec);
804
805                                                                 x = nx;
806                                                                 y = ny;
807                                                                 cur_dis++;
808                                                                 n--;
809                                                         }
810                                                 }
811                                         }
812                                 }
813
814                                 /* Sniper */
815                                 if (snipe_type == SP_PIERCE)
816                                 {
817                                         if (p_ptr->concent < 1) break;
818                                         p_ptr->concent--;
819                                         continue;
820                                 }
821
822                                 /* Stop looking */
823                                 break;
824                         }
825                 }
826
827                 /* Chance of breakage (during attacks) */
828                 j = (hit_body ? breakage_chance(q_ptr, snipe_type) : 0);
829
830                 if (stick_to)
831                 {
832                         MONSTER_IDX m_idx = current_floor_ptr->grid_array[y][x].m_idx;
833                         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
834                         OBJECT_IDX o_idx = o_pop();
835
836                         if (!o_idx)
837                         {
838                                 msg_format(_("%sはどこかへ行った。", "The %s have gone to somewhere."), o_name);
839                                 if (object_is_fixed_artifact(q_ptr))
840                                 {
841                                         a_info[j_ptr->name1].cur_num = 0;
842                                 }
843                                 return;
844                         }
845
846                         o_ptr = &current_floor_ptr->o_list[o_idx];
847                         object_copy(o_ptr, q_ptr);
848
849                         /* Forget mark */
850                         o_ptr->marked &= OM_TOUCHED;
851
852                         /* Forget location */
853                         o_ptr->iy = o_ptr->ix = 0;
854
855                         /* Memorize monster */
856                         o_ptr->held_m_idx = m_idx;
857
858                         /* Build a stack */
859                         o_ptr->next_o_idx = m_ptr->hold_o_idx;
860
861                         /* Carry object */
862                         m_ptr->hold_o_idx = o_idx;
863                 }
864                 else if (cave_have_flag_bold(y, x, FF_PROJECT))
865                 {
866                         /* Drop (or break) near that location */
867                         (void)drop_near(q_ptr, j, y, x);
868                 }
869                 else
870                 {
871                         /* Drop (or break) near that location */
872                         (void)drop_near(q_ptr, j, prev_y, prev_x);
873                 }
874
875                 /* Sniper - Repeat shooting when double shots */
876         }
877
878         /* Sniper - Loose his/her concentration after any shot */
879         if (p_ptr->concent) reset_concentration(FALSE);
880 }
881
882
883 /*!
884 * @brief プレイヤーからモンスターへの射撃命中判定 /
885 * Determine if the player "hits" a monster (normal combat).
886 * @param chance 基本命中値
887 * @param m_ptr モンスターの構造体参照ポインタ
888 * @param vis 目標を視界に捕らえているならばTRUEを指定
889 * @param o_name メッセージ表示時のモンスター名
890 * @return 命中と判定された場合TRUEを返す
891 * @note Always miss 5%, always hit 5%, otherwise random.
892 */
893 bool test_hit_fire(int chance, monster_type *m_ptr, int vis, char* o_name)
894 {
895         int k;
896         ARMOUR_CLASS ac;
897         monster_race *r_ptr = &r_info[m_ptr->r_idx];
898
899         /* Percentile dice */
900         k = randint1(100);
901
902         /* Snipers with high-concentration reduce instant miss percentage.*/
903         k += p_ptr->concent;
904
905         /* Hack -- Instant miss or hit */
906         if (k <= 5) return (FALSE);
907         if (k > 95) return (TRUE);
908
909         if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
910                 if (one_in_(20)) return (FALSE);
911
912         /* Never hit */
913         if (chance <= 0) return (FALSE);
914
915         ac = r_ptr->ac;
916         if (p_ptr->concent)
917         {
918                 ac *= (8 - p_ptr->concent);
919                 ac /= 8;
920         }
921
922         if (m_ptr->r_idx == MON_GOEMON && !MON_CSLEEP(m_ptr)) ac *= 3;
923
924         /* Invisible monsters are harder to hit */
925         if (!vis) chance = (chance + 1) / 2;
926
927         /* Power competes against armor */
928         if (randint0(chance) < (ac * 3 / 4))
929         {
930                 if (m_ptr->r_idx == MON_GOEMON && !MON_CSLEEP(m_ptr))
931                 {
932                         GAME_TEXT m_name[MAX_NLEN];
933
934                         /* Extract monster name */
935                         monster_desc(m_name, m_ptr, 0);
936                         msg_format(_("%sは%sを斬り捨てた!", "%s cuts down %s!"), m_name, o_name);
937                 }
938                 return (FALSE);
939         }
940
941         /* Assume hit */
942         return (TRUE);
943 }
944
945
946
947
948 /*!
949 * @brief プレイヤーからモンスターへの射撃クリティカル判定 /
950 * Critical hits (from objects thrown by player) Factor in item weight, total plusses, and player level.
951 * @param weight 矢弾の重量
952 * @param plus_ammo 矢弾の命中修正
953 * @param plus_bow 弓の命中修正
954 * @param dam 現在算出中のダメージ値
955 * @return クリティカル修正が入ったダメージ値
956 */
957 HIT_POINT critical_shot(WEIGHT weight, int plus_ammo, int plus_bow, HIT_POINT dam)
958 {
959         int i, k;
960         object_type *j_ptr = &inventory[INVEN_BOW];
961
962         /* Extract "shot" power */
963         i = p_ptr->to_h_b + plus_ammo;
964
965         if (p_ptr->tval_ammo == TV_BOLT)
966                 i = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + i) * BTH_PLUS_ADJ);
967         else
968                 i = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + i) * BTH_PLUS_ADJ);
969
970
971         /* Snipers can shot more critically with crossbows */
972         if (p_ptr->concent) i += ((i * p_ptr->concent) / 5);
973         if ((p_ptr->pclass == CLASS_SNIPER) && (p_ptr->tval_ammo == TV_BOLT)) i *= 2;
974
975         /* Good bow makes more critical */
976         i += plus_bow * 8 * (p_ptr->concent ? p_ptr->concent + 5 : 5);
977
978         /* Critical hit */
979         if (randint1(10000) <= i)
980         {
981                 k = weight * randint1(500);
982
983                 if (k < 900)
984                 {
985                         msg_print(_("手ごたえがあった!", "It was a good hit!"));
986                         dam += (dam / 2);
987                 }
988                 else if (k < 1350)
989                 {
990                         msg_print(_("かなりの手ごたえがあった!", "It was a great hit!"));
991                         dam *= 2;
992                 }
993                 else
994                 {
995                         msg_print(_("会心の一撃だ!", "It was a superb hit!"));
996                         dam *= 3;
997                 }
998         }
999
1000         return (dam);
1001 }
1002
1003
1004
1005
1006 /*!
1007  * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
1008  * @param sval 射撃武器のアイテム副分類ID
1009  * @return 消費する基本エネルギー
1010  */
1011 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
1012 {
1013         ENERGY energy = 10000;
1014
1015         /* Analyze the launcher */
1016         switch (sval)
1017         {
1018                 /* Sling and ammo */
1019         case SV_SLING:
1020         {
1021                 energy = 8000;
1022                 break;
1023         }
1024
1025         /* Short Bow and Arrow */
1026         case SV_SHORT_BOW:
1027         {
1028                 energy = 10000;
1029                 break;
1030         }
1031
1032         /* Long Bow and Arrow */
1033         case SV_LONG_BOW:
1034         {
1035                 energy = 10000;
1036                 break;
1037         }
1038
1039         /* Bow of irresponsiblity and Arrow */
1040         case SV_NAMAKE_BOW:
1041         {
1042                 energy = 7777;
1043                 break;
1044         }
1045
1046         /* Light Crossbow and Bolt */
1047         case SV_LIGHT_XBOW:
1048         {
1049                 energy = 12000;
1050                 break;
1051         }
1052
1053         /* Heavy Crossbow and Bolt */
1054         case SV_HEAVY_XBOW:
1055         {
1056                 energy = 13333;
1057                 break;
1058         }
1059         }
1060
1061         return (energy);
1062 }
1063
1064
1065 /*
1066  * Return bow tmul
1067  */
1068 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
1069 {
1070         int tmul = 0;
1071
1072         /* Analyze the launcher */
1073         switch (sval)
1074         {
1075                 /* Sling and ammo */
1076         case SV_SLING:
1077         {
1078                 tmul = 2;
1079                 break;
1080         }
1081
1082         /* Short Bow and Arrow */
1083         case SV_SHORT_BOW:
1084         {
1085                 tmul = 2;
1086                 break;
1087         }
1088
1089         /* Long Bow and Arrow */
1090         case SV_LONG_BOW:
1091         {
1092                 tmul = 3;
1093                 break;
1094         }
1095
1096         /* Bow of irresponsiblity and Arrow */
1097         case SV_NAMAKE_BOW:
1098         {
1099                 tmul = 3;
1100                 break;
1101         }
1102
1103         /* Light Crossbow and Bolt */
1104         case SV_LIGHT_XBOW:
1105         {
1106                 tmul = 3;
1107                 break;
1108         }
1109
1110         /* Heavy Crossbow and Bolt */
1111         case SV_HEAVY_XBOW:
1112         {
1113                 tmul = 4;
1114                 break;
1115         }
1116         }
1117
1118         return (tmul);
1119 }
1120
1121