OSDN Git Service

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