OSDN Git Service

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