OSDN Git Service

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