OSDN Git Service

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