OSDN Git Service

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