OSDN Git Service

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