OSDN Git Service

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