OSDN Git Service

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