OSDN Git Service

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