OSDN Git Service

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