OSDN Git Service

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