OSDN Git Service

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