OSDN Git Service

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