OSDN Git Service

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