OSDN Git Service

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