OSDN Git Service

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