OSDN Git Service

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