OSDN Git Service

[Refactor] #37353 ゲームバランス定数を gamevalue.h へ整理。 / Move constant value in game to gameva...
[hengband/hengband.git] / src / spells3.c
1 /*!
2  * @file spells3.c
3  * @brief 魔法効果の実装/ Spell code (part 3)
4  * @date 2014/07/26
5  * @author
6  * <pre>
7  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  * </pre>
12  */
13
14 #include "angband.h"
15
16 /*! テレポート先探索の試行数 / Maximum number of tries for teleporting */
17 #define MAX_TRIES 100
18
19 /*!
20  * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
21  * @param m_idx モンスターID
22  * @param y 移動先Y座標
23  * @param x 移動先X座標
24  * @param mode オプション
25  * @return テレポート先として妥当ならばtrue
26  */
27 static bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, int y, int x, BIT_FLAGS mode)
28 {
29         monster_type *m_ptr = &m_list[m_idx];
30         cave_type    *c_ptr = &cave[y][x];
31         feature_type *f_ptr = &f_info[c_ptr->feat];
32
33         /* Require "teleportable" space */
34         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
35
36         if (c_ptr->m_idx && (c_ptr->m_idx != m_idx)) return FALSE;
37         if (player_bold(y, x)) return FALSE;
38
39         /* Hack -- no teleport onto glyph of warding */
40         if (is_glyph_grid(c_ptr)) return FALSE;
41         if (is_explosive_rune_grid(c_ptr)) return FALSE;
42
43         if (!(mode & TELEPORT_PASSIVE))
44         {
45                 if (!monster_can_cross_terrain(c_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
46         }
47
48         return TRUE;
49 }
50
51
52 /*!
53  * @brief モンスターのテレポートアウェイ処理 /
54  * Teleport a monster, normally up to "dis" grids away.
55  * @param m_idx モンスターID
56  * @param dis テレポート距離
57  * @param mode オプション
58  * @return テレポートが実際に行われたらtrue
59  * @details
60  * Attempt to move the monster at least "dis/2" grids away.
61  * But allow variation to prevent infinite loops.
62  */
63 bool teleport_away(MONSTER_IDX m_idx, int dis, BIT_FLAGS mode)
64 {
65         int oy, ox, d, i, min;
66         int tries = 0;
67         POSITION ny = 0, nx = 0;
68
69         bool look = TRUE;
70
71         monster_type *m_ptr = &m_list[m_idx];
72
73         /* Paranoia */
74         if (!m_ptr->r_idx) return (FALSE);
75
76         /* Save the old location */
77         oy = m_ptr->fy;
78         ox = m_ptr->fx;
79
80         /* Minimum distance */
81         min = dis / 2;
82
83         if ((mode & TELEPORT_DEC_VALOUR) &&
84             (((p_ptr->chp * 10) / p_ptr->mhp) > 5) &&
85                 (4+randint1(5) < ((p_ptr->chp * 10) / p_ptr->mhp)))
86         {
87                 chg_virtue(V_VALOUR, -1);
88         }
89
90         /* Look until done */
91         while (look)
92         {
93                 tries++;
94
95                 /* Verify max distance */
96                 if (dis > 200) dis = 200;
97
98                 /* Try several locations */
99                 for (i = 0; i < 500; i++)
100                 {
101                         /* Pick a (possibly illegal) location */
102                         while (1)
103                         {
104                                 ny = rand_spread(oy, dis);
105                                 nx = rand_spread(ox, dis);
106                                 d = distance(oy, ox, ny, nx);
107                                 if ((d >= min) && (d <= dis)) break;
108                         }
109
110                         /* Ignore illegal locations */
111                         if (!in_bounds(ny, nx)) continue;
112
113                         if (!cave_monster_teleportable_bold(m_idx, ny, nx, mode)) continue;
114
115                         /* No teleporting into vaults and such */
116                         if (!(p_ptr->inside_quest || p_ptr->inside_arena))
117                                 if (cave[ny][nx].info & CAVE_ICKY) continue;
118
119                         /* This grid looks good */
120                         look = FALSE;
121
122                         /* Stop looking */
123                         break;
124                 }
125
126                 /* Increase the maximum distance */
127                 dis = dis * 2;
128
129                 /* Decrease the minimum distance */
130                 min = min / 2;
131
132                 /* Stop after MAX_TRIES tries */
133                 if (tries > MAX_TRIES) return (FALSE);
134         }
135
136         /* Sound */
137         sound(SOUND_TPOTHER);
138
139         /* Update the old location */
140         cave[oy][ox].m_idx = 0;
141
142         /* Update the new location */
143         cave[ny][nx].m_idx = m_idx;
144
145         /* Move the monster */
146         m_ptr->fy = ny;
147         m_ptr->fx = nx;
148
149         /* Forget the counter target */
150         reset_target(m_ptr);
151
152         /* Update the monster (new location) */
153         update_mon(m_idx, TRUE);
154
155         /* Redraw the old grid */
156         lite_spot(oy, ox);
157
158         /* Redraw the new grid */
159         lite_spot(ny, nx);
160
161         if (r_info[m_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
162                 p_ptr->update |= (PU_MON_LITE);
163
164         return (TRUE);
165 }
166
167
168 /*!
169  * @brief モンスターを指定された座標付近にテレポートする /
170  * Teleport monster next to a grid near the given location
171  * @param m_idx モンスターID
172  * @param ty 目安Y座標
173  * @param tx 目安X座標
174  * @param power テレポート成功確率
175  * @param mode オプション
176  * @return なし
177  */
178 void teleport_monster_to(MONSTER_IDX m_idx, POSITION ty, POSITION tx, int power, BIT_FLAGS mode)
179 {
180         int ny, nx, oy, ox, d, i, min;
181         int attempts = 500;
182         int dis = 2;
183         bool look = TRUE;
184         monster_type *m_ptr = &m_list[m_idx];
185
186         /* Paranoia */
187         if (!m_ptr->r_idx) return;
188
189         /* "Skill" test */
190         if (randint1(100) > power) return;
191
192         /* Initialize */
193         ny = m_ptr->fy;
194         nx = m_ptr->fx;
195
196         /* Save the old location */
197         oy = m_ptr->fy;
198         ox = m_ptr->fx;
199
200         /* Minimum distance */
201         min = dis / 2;
202
203         /* Look until done */
204         while (look && --attempts)
205         {
206                 /* Verify max distance */
207                 if (dis > 200) dis = 200;
208
209                 /* Try several locations */
210                 for (i = 0; i < 500; i++)
211                 {
212                         /* Pick a (possibly illegal) location */
213                         while (1)
214                         {
215                                 ny = rand_spread(ty, dis);
216                                 nx = rand_spread(tx, dis);
217                                 d = distance(ty, tx, ny, nx);
218                                 if ((d >= min) && (d <= dis)) break;
219                         }
220
221                         /* Ignore illegal locations */
222                         if (!in_bounds(ny, nx)) continue;
223
224                         if (!cave_monster_teleportable_bold(m_idx, ny, nx, mode)) continue;
225
226                         /* No teleporting into vaults and such */
227                         /* if (cave[ny][nx].info & (CAVE_ICKY)) continue; */
228
229                         /* This grid looks good */
230                         look = FALSE;
231
232                         /* Stop looking */
233                         break;
234                 }
235
236                 /* Increase the maximum distance */
237                 dis = dis * 2;
238
239                 /* Decrease the minimum distance */
240                 min = min / 2;
241         }
242
243         if (attempts < 1) return;
244
245         /* Sound */
246         sound(SOUND_TPOTHER);
247
248         /* Update the old location */
249         cave[oy][ox].m_idx = 0;
250
251         /* Update the new location */
252         cave[ny][nx].m_idx = m_idx;
253
254         /* Move the monster */
255         m_ptr->fy = ny;
256         m_ptr->fx = nx;
257
258         /* Update the monster (new location) */
259         update_mon(m_idx, TRUE);
260
261         /* Redraw the old grid */
262         lite_spot(oy, ox);
263
264         /* Redraw the new grid */
265         lite_spot(ny, nx);
266
267         if (r_info[m_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
268                 p_ptr->update |= (PU_MON_LITE);
269 }
270
271 /*!
272  * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
273  * @param y 移動先Y座標
274  * @param x 移動先X座標
275  * @param mode オプション
276  * @return テレポート先として妥当ならばtrue
277  */
278 bool cave_player_teleportable_bold(int y, int x, BIT_FLAGS mode)
279 {
280         cave_type    *c_ptr = &cave[y][x];
281         feature_type *f_ptr = &f_info[c_ptr->feat];
282
283         /* Require "teleportable" space */
284         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
285
286         /* No magical teleporting into vaults and such */
287         if (!(mode & TELEPORT_NONMAGICAL) && (c_ptr->info & CAVE_ICKY)) return FALSE;
288
289         if (c_ptr->m_idx && (c_ptr->m_idx != p_ptr->riding)) return FALSE;
290
291         /* don't teleport on a trap. */
292         if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
293
294         if (!(mode & TELEPORT_PASSIVE))
295         {
296                 if (!player_can_enter(c_ptr->feat, 0)) return FALSE;
297
298                 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
299                 {
300                         if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
301                 }
302
303                 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
304                 {
305                         /* Always forbid deep lava */
306                         if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
307
308                         /* Forbid shallow lava when the player don't have levitation */
309                         if (!p_ptr->levitation) return FALSE;
310                 }
311
312         }
313
314         return TRUE;
315 }
316
317
318 /*!
319  * @brief プレイヤーのテレポート先選定と移動処理 /
320  * Teleport the player to a location up to "dis" grids away.
321  * @param dis 基本移動距離
322  * @param mode オプション
323  * @return 実際にテレポート処理が行われたらtrue
324  * @details
325  * <pre>
326  * If no such spaces are readily available, the distance may increase.
327  * Try very hard to move the player at least a quarter that distance.
328  *
329  * There was a nasty tendency for a long time; which was causing the
330  * player to "bounce" between two or three different spots because
331  * these are the only spots that are "far enough" way to satisfy the
332  * algorithm.
333  *
334  * But this tendency is now removed; in the new algorithm, a list of
335  * candidates is selected first, which includes at least 50% of all
336  * floor grids within the distance, and any single grid in this list
337  * of candidates has equal possibility to be choosen as a destination.
338  * </pre>
339  */
340
341 bool teleport_player_aux(int dis, BIT_FLAGS mode)
342 {
343         int candidates_at[MAX_TELEPORT_DISTANCE + 1];
344         int total_candidates, cur_candidates;
345         POSITION y = 0, x = 0;
346         int min, pick, i;
347
348         int left = MAX(1, p_ptr->x - dis);
349         int right = MIN(cur_wid - 2, p_ptr->x + dis);
350         int top = MAX(1, p_ptr->y - dis);
351         int bottom = MIN(cur_hgt - 2, p_ptr->y + dis);
352
353         if (p_ptr->wild_mode) return FALSE;
354
355         if (p_ptr->anti_tele && !(mode & TELEPORT_NONMAGICAL))
356         {
357                 msg_print(_("不思議な力がテレポートを防いだ!", "A mysterious force prevents you from teleporting!"));
358                 return FALSE;
359         }
360
361         /* Initialize counters */
362         total_candidates = 0;
363         for (i = 0; i <= MAX_TELEPORT_DISTANCE; i++)
364                 candidates_at[i] = 0;
365
366         /* Limit the distance */
367         if (dis > MAX_TELEPORT_DISTANCE) dis = MAX_TELEPORT_DISTANCE;
368
369         /* Search valid locations */
370         for (y = top; y <= bottom; y++)
371         {
372                 for (x = left; x <= right; x++)
373                 {
374                         int d;
375
376                         /* Skip illegal locations */
377                         if (!cave_player_teleportable_bold(y, x, mode)) continue;
378
379                         /* Calculate distance */
380                         d = distance(p_ptr->y, p_ptr->x, y, x);
381
382                         /* Skip too far locations */
383                         if (d > dis) continue;
384
385                         /* Count the total number of candidates */
386                         total_candidates++;
387
388                         /* Count the number of candidates in this circumference */
389                         candidates_at[d]++;
390                 }
391         }
392
393         /* No valid location! */
394         if (0 == total_candidates) return FALSE;
395
396         /* Fix the minimum distance */
397         for (cur_candidates = 0, min = dis; min >= 0; min--)
398         {
399                 cur_candidates += candidates_at[min];
400
401                 /* 50% of all candidates will have an equal chance to be choosen. */
402                 if (cur_candidates && (cur_candidates >= total_candidates / 2)) break;
403         }
404
405         /* Pick up a single location randomly */
406         pick = randint1(cur_candidates);
407
408         /* Search again the choosen location */
409         for (y = top; y <= bottom; y++)
410         {
411                 for (x = left; x <= right; x++)
412                 {
413                         int d;
414
415                         /* Skip illegal locations */
416                         if (!cave_player_teleportable_bold(y, x, mode)) continue;
417
418                         /* Calculate distance */
419                         d = distance(p_ptr->y, p_ptr->x, y, x);
420
421                         /* Skip too far locations */
422                         if (d > dis) continue;
423
424                         /* Skip too close locations */
425                         if (d < min) continue;
426
427                         /* This grid was picked up? */
428                         pick--;
429                         if (!pick) break;
430                 }
431
432                 /* Exit the loop */
433                 if (!pick) break;
434         }
435
436         if (player_bold(y, x)) return FALSE;
437
438         /* Sound */
439         sound(SOUND_TELEPORT);
440
441 #ifdef JP
442         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
443                 msg_format("『こっちだぁ、%s』", p_ptr->name);
444 #endif
445
446         /* Move the player */
447         (void)move_player_effect(y, x, MPE_FORGET_FLOW | MPE_HANDLE_STUFF | MPE_DONT_PICKUP);
448
449         return TRUE;
450 }
451
452 /*!
453  * @brief プレイヤーのテレポート処理メインルーチン
454  * @param dis 基本移動距離
455  * @param mode オプション
456  * @return なし
457  */
458 void teleport_player(int dis, BIT_FLAGS mode)
459 {
460         int yy, xx;
461
462         /* Save the old location */
463         int oy = p_ptr->y;
464         int ox = p_ptr->x;
465
466         if (!teleport_player_aux(dis, mode)) return;
467
468         /* Monsters with teleport ability may follow the player */
469         for (xx = -1; xx < 2; xx++)
470         {
471                 for (yy = -1; yy < 2; yy++)
472                 {
473                         MONSTER_IDX tmp_m_idx = cave[oy+yy][ox+xx].m_idx;
474
475                         /* A monster except your mount may follow */
476                         if (tmp_m_idx && (p_ptr->riding != tmp_m_idx))
477                         {
478                                 monster_type *m_ptr = &m_list[tmp_m_idx];
479                                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
480
481                                 /*
482                                  * The latter limitation is to avoid
483                                  * totally unkillable suckers...
484                                  */
485                                 if ((r_ptr->a_ability_flags2 & RF6_TPORT) &&
486                                     !(r_ptr->flagsr & RFR_RES_TELE))
487                                 {
488                                         if (!MON_CSLEEP(m_ptr)) teleport_monster_to(tmp_m_idx, p_ptr->y, p_ptr->x, r_ptr->level, 0L);
489                                 }
490                         }
491                 }
492         }
493 }
494
495
496 /*!
497  * @brief プレイヤーのテレポートアウェイ処理 /
498  * @param m_idx アウェイを試みたプレイヤーID
499  * @param dis テレポート距離
500  * @return なし
501  */
502 void teleport_player_away(MONSTER_IDX m_idx, int dis)
503 {
504         int yy, xx;
505
506         /* Save the old location */
507         int oy = p_ptr->y;
508         int ox = p_ptr->x;
509
510         if (!teleport_player_aux(dis, TELEPORT_PASSIVE)) return;
511
512         /* Monsters with teleport ability may follow the player */
513         for (xx = -1; xx < 2; xx++)
514         {
515                 for (yy = -1; yy < 2; yy++)
516                 {
517                         IDX tmp_m_idx = cave[oy+yy][ox+xx].m_idx;
518
519                         /* A monster except your mount or caster may follow */
520                         if (tmp_m_idx && (p_ptr->riding != tmp_m_idx) && (m_idx != tmp_m_idx))
521                         {
522                                 monster_type *m_ptr = &m_list[tmp_m_idx];
523                                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
524
525                                 /*
526                                  * The latter limitation is to avoid
527                                  * totally unkillable suckers...
528                                  */
529                                 if ((r_ptr->a_ability_flags2 & RF6_TPORT) &&
530                                     !(r_ptr->flagsr & RFR_RES_TELE))
531                                 {
532                                         if (!MON_CSLEEP(m_ptr)) teleport_monster_to(tmp_m_idx, p_ptr->y, p_ptr->x, r_ptr->level, 0L);
533                                 }
534                         }
535                 }
536         }
537 }
538
539
540 /*!
541  * @brief プレイヤーを指定位置近辺にテレポートさせる
542  * Teleport player to a grid near the given location
543  * @param ny 目標Y座標
544  * @param nx 目標X座標
545  * @param mode オプションフラグ
546  * @return なし
547  * @details
548  * <pre>
549  * This function is slightly obsessive about correctness.
550  * This function allows teleporting into vaults (!)
551  * </pre>
552  */
553 void teleport_player_to(POSITION ny, POSITION nx, BIT_FLAGS mode)
554 {
555         POSITION y, x;
556         int dis = 0, ctr = 0;
557
558         if (p_ptr->anti_tele && !(mode & TELEPORT_NONMAGICAL))
559         {
560                 msg_print(_("不思議な力がテレポートを防いだ!", "A mysterious force prevents you from teleporting!"));
561                 return;
562         }
563
564         /* Find a usable location */
565         while (1)
566         {
567                 /* Pick a nearby legal location */
568                 while (1)
569                 {
570                         y = (POSITION)rand_spread(ny, dis);
571                         x = (POSITION)rand_spread(nx, dis);
572                         if (in_bounds(y, x)) break;
573                 }
574
575                 /* Accept any grid when wizard mode */
576                 if (p_ptr->wizard && !(mode & TELEPORT_PASSIVE) && (!cave[y][x].m_idx || (cave[y][x].m_idx == p_ptr->riding))) break;
577
578                 /* Accept teleportable floor grids */
579                 if (cave_player_teleportable_bold(y, x, mode)) break;
580
581                 /* Occasionally advance the distance */
582                 if (++ctr > (4 * dis * dis + 4 * dis + 1))
583                 {
584                         ctr = 0;
585                         dis++;
586                 }
587         }
588
589         /* Sound */
590         sound(SOUND_TELEPORT);
591
592         /* Move the player */
593         (void)move_player_effect(y, x, MPE_FORGET_FLOW | MPE_HANDLE_STUFF | MPE_DONT_PICKUP);
594 }
595
596
597 void teleport_away_followable(MONSTER_IDX m_idx)
598 {
599         monster_type *m_ptr = &m_list[m_idx];
600         int          oldfy = m_ptr->fy;
601         int          oldfx = m_ptr->fx;
602         bool         old_ml = m_ptr->ml;
603         int          old_cdis = m_ptr->cdis;
604
605         teleport_away(m_idx, MAX_SIGHT * 2 + 5, 0L);
606
607         if (old_ml && (old_cdis <= MAX_SIGHT) && !world_monster && !p_ptr->inside_battle && los(p_ptr->y, p_ptr->x, oldfy, oldfx))
608         {
609                 bool follow = FALSE;
610
611                 if ((p_ptr->muta1 & MUT1_VTELEPORT) || (p_ptr->pclass == CLASS_IMITATOR)) follow = TRUE;
612                 else
613                 {
614                         u32b flgs[TR_FLAG_SIZE];
615                         object_type *o_ptr;
616                         int i;
617
618                         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
619                         {
620                                 o_ptr = &inventory[i];
621                                 if (o_ptr->k_idx && !object_is_cursed(o_ptr))
622                                 {
623                                         object_flags(o_ptr, flgs);
624                                         if (have_flag(flgs, TR_TELEPORT))
625                                         {
626                                                 follow = TRUE;
627                                                 break;
628                                         }
629                                 }
630                         }
631                 }
632
633                 if (follow)
634                 {
635                         if (get_check_strict(_("ついていきますか?", "Do you follow it? "), CHECK_OKAY_CANCEL))
636                         {
637                                 if (one_in_(3))
638                                 {
639                                         teleport_player(200, TELEPORT_PASSIVE);
640                                         msg_print(_("失敗!", "Failed!"));
641                                 }
642                                 else teleport_player_to(m_ptr->fy, m_ptr->fx, 0L);
643                                 p_ptr->energy_need += ENERGY_NEED();
644                         }
645                 }
646         }
647 }
648
649
650 /*!
651  * @brief プレイヤー及びモンスターをレベルテレポートさせる /
652  * Teleport the player one level up or down (random when legal)
653  * @param m_idx テレポートの対象となるモンスターID(0ならばプレイヤー) / If m_idx <= 0, target is player.
654  * @return なし
655  */
656 void teleport_level(MONSTER_IDX m_idx)
657 {
658         bool         go_up;
659         char         m_name[160];
660         bool         see_m = TRUE;
661
662         if (m_idx <= 0) /* To player */
663         {
664                 strcpy(m_name, _("あなた", "you"));
665         }
666         else /* To monster */
667         {
668                 monster_type *m_ptr = &m_list[m_idx];
669
670                 /* Get the monster name (or "it") */
671                 monster_desc(m_name, m_ptr, 0);
672
673                 see_m = is_seen(m_ptr);
674         }
675
676         /* No effect in some case */
677         if (TELE_LEVEL_IS_INEFF(m_idx))
678         {
679                 if (see_m) msg_print(_("効果がなかった。", "There is no effect."));
680                 return;
681         }
682
683         if ((m_idx <= 0) && p_ptr->anti_tele) /* To player */
684         {
685                 msg_print(_("不思議な力がテレポートを防いだ!", "A mysterious force prevents you from teleporting!"));
686                 return;
687         }
688
689         /* Choose up or down */
690         if (randint0(100) < 50) go_up = TRUE;
691         else go_up = FALSE;
692
693         if ((m_idx <= 0) && p_ptr->wizard)
694         {
695                 if (get_check("Force to go up? ")) go_up = TRUE;
696                 else if (get_check("Force to go down? ")) go_up = FALSE;
697         }
698
699         /* Down only */ 
700         if ((ironman_downward && (m_idx <= 0)) || (dun_level <= d_info[dungeon_type].mindepth))
701         {
702 #ifdef JP
703                 if (see_m) msg_format("%^sは床を突き破って沈んでいく。", m_name);
704 #else
705                 if (see_m) msg_format("%^s sink%s through the floor.", m_name, (m_idx <= 0) ? "" : "s");
706 #endif
707                 if (m_idx <= 0) /* To player */
708                 {
709                         if (!dun_level)
710                         {
711                                 dungeon_type = ironman_downward ? DUNGEON_ANGBAND : p_ptr->recall_dungeon;
712                                 p_ptr->oldpy = p_ptr->y;
713                                 p_ptr->oldpx = p_ptr->x;
714                         }
715
716                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, 1, NULL);
717
718                         if (autosave_l) do_cmd_save_game(TRUE);
719
720                         if (!dun_level)
721                         {
722                                 dun_level = d_info[dungeon_type].mindepth;
723                                 prepare_change_floor_mode(CFM_RAND_PLACE);
724                         }
725                         else
726                         {
727                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
728                         }
729
730                         /* Leaving */
731                         p_ptr->leaving = TRUE;
732                 }
733         }
734
735         /* Up only */
736         else if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth))
737         {
738 #ifdef JP
739                 if (see_m) msg_format("%^sは天井を突き破って宙へ浮いていく。", m_name);
740 #else
741                 if (see_m) msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
742 #endif
743
744
745                 if (m_idx <= 0) /* To player */
746                 {
747                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
748
749                         if (autosave_l) do_cmd_save_game(TRUE);
750
751                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
752
753                         leave_quest_check();
754
755                         /* Leaving */
756                         p_ptr->inside_quest = 0;
757                         p_ptr->leaving = TRUE;
758                 }
759         }
760         else if (go_up)
761         {
762 #ifdef JP
763                 if (see_m) msg_format("%^sは天井を突き破って宙へ浮いていく。", m_name);
764 #else
765                 if (see_m) msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
766 #endif
767
768
769                 if (m_idx <= 0) /* To player */
770                 {
771                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
772
773                         if (autosave_l) do_cmd_save_game(TRUE);
774
775                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
776
777                         /* Leaving */
778                         p_ptr->leaving = TRUE;
779                 }
780         }
781         else
782         {
783 #ifdef JP
784                 if (see_m) msg_format("%^sは床を突き破って沈んでいく。", m_name);
785 #else
786                 if (see_m) msg_format("%^s sink%s through the floor.", m_name, (m_idx <= 0) ? "" : "s");
787 #endif
788
789                 if (m_idx <= 0) /* To player */
790                 {
791                         /* Never reach this code on the surface */
792                         /* if (!dun_level) dungeon_type = p_ptr->recall_dungeon; */
793
794                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, 1, NULL);
795
796                         if (autosave_l) do_cmd_save_game(TRUE);
797
798                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
799
800                         /* Leaving */
801                         p_ptr->leaving = TRUE;
802                 }
803         }
804
805         /* Monster level teleportation is simple deleting now */
806         if (m_idx > 0)
807         {
808                 monster_type *m_ptr = &m_list[m_idx];
809
810                 /* Check for quest completion */
811                 check_quest_completion(m_ptr);
812
813                 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
814                 {
815                         char m2_name[80];
816
817                         monster_desc(m2_name, m_ptr, MD_INDEF_VISIBLE);
818                         do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_TELE_LEVEL, m2_name);
819                 }
820
821                 delete_monster_idx(m_idx);
822         }
823
824         /* Sound */
825         sound(SOUND_TPLEVEL);
826 }
827
828
829 /*!
830  * @brief これまでに入ったダンジョンの一覧を表示し、選択させる。
831  * @param note ダンジョンに施す処理記述
832  * @param y コンソールY座標
833  * @param x コンソールX座標
834  * @return 選択されたダンジョンID
835  */
836 DUNGEON_IDX choose_dungeon(cptr note, POSITION y, POSITION x)
837 {
838         DUNGEON_IDX select_dungeon;
839         DUNGEON_IDX i;
840         int num = 0;
841         DUNGEON_IDX *dun;
842
843         /* Hack -- No need to choose dungeon in some case */
844         if (lite_town || vanilla_town || ironman_downward)
845         {
846                 if (max_dlv[DUNGEON_ANGBAND]) return DUNGEON_ANGBAND;
847                 else
848                 {
849                         msg_format(_("まだ%sに入ったことはない。", "You haven't entered %s yet."), d_name + d_info[DUNGEON_ANGBAND].name);
850                         msg_print(NULL);
851                         return 0;
852                 }
853         }
854
855         /* Allocate the "dun" array */
856         C_MAKE(dun, max_d_idx, s16b);
857
858         screen_save();
859         for(i = 1; i < max_d_idx; i++)
860         {
861                 char buf[80];
862                 bool seiha = FALSE;
863
864                 if (!d_info[i].maxdepth) continue;
865                 if (!max_dlv[i]) continue;
866                 if (d_info[i].final_guardian)
867                 {
868                         if (!r_info[d_info[i].final_guardian].max_num) seiha = TRUE;
869                 }
870                 else if (max_dlv[i] == d_info[i].maxdepth) seiha = TRUE;
871
872                 sprintf(buf,_("      %c) %c%-12s : 最大 %d 階", "      %c) %c%-16s : Max level %d"), 
873                                         'a'+num, seiha ? '!' : ' ', d_name + d_info[i].name, (int)max_dlv[i]);
874                 prt(buf, y + num, x);
875                 dun[num++] = i;
876         }
877
878         if (!num)
879         {
880                 prt(_("      選べるダンジョンがない。", "      No dungeon is available."), y, x);
881         }
882
883         prt(format(_("どのダンジョン%sしますか:", "Which dungeon do you %s?: "), note), 0, 0);
884         while(1)
885         {
886                 i = inkey();
887                 if ((i == ESCAPE) || !num)
888                 {
889                         /* Free the "dun" array */
890                         C_KILL(dun, max_d_idx, s16b);
891
892                         screen_load();
893                         return 0;
894                 }
895                 if (i >= 'a' && i <('a'+num))
896                 {
897                         select_dungeon = dun[i-'a'];
898                         break;
899                 }
900                 else bell();
901         }
902         screen_load();
903
904         /* Free the "dun" array */
905         C_KILL(dun, max_d_idx, s16b);
906
907         return select_dungeon;
908 }
909
910
911 /*!
912  * @brief プレイヤーの帰還発動及び中止処理 /
913  * Recall the player to town or dungeon
914  * @param turns 発動までのターン数
915  * @return 常にTRUEを返す
916  */
917 bool recall_player(TIME_EFFECT turns)
918 {
919         /*
920          * TODO: Recall the player to the last
921          * visited town when in the wilderness
922          */
923
924         /* Ironman option */
925         if (p_ptr->inside_arena || ironman_downward)
926         {
927                 msg_print(_("何も起こらなかった。", "Nothing happens."));
928                 return TRUE;
929         }
930
931         if (dun_level && (max_dlv[dungeon_type] > dun_level) && !p_ptr->inside_quest && !p_ptr->word_recall)
932         {
933                 if (get_check(_("ここは最深到達階より浅い階です。この階に戻って来ますか? ", "Reset recall depth? ")))
934                 {
935                         max_dlv[dungeon_type] = dun_level;
936                         if (record_maxdepth)
937                                 do_cmd_write_nikki(NIKKI_TRUMP, dungeon_type, _("帰還のときに", "when recall from dungeon"));
938                 }
939
940         }
941         if (!p_ptr->word_recall)
942         {
943                 if (!dun_level)
944                 {
945                         DUNGEON_IDX select_dungeon;
946                         select_dungeon = choose_dungeon(_("に帰還", "recall"), 2, 14);
947                         if (!select_dungeon) return FALSE;
948                         p_ptr->recall_dungeon = select_dungeon;
949                 }
950                 p_ptr->word_recall = turns;
951                 msg_print(_("回りの大気が張りつめてきた...", "The air about you becomes charged..."));
952                 p_ptr->redraw |= (PR_STATUS);
953         }
954         else
955         {
956                 p_ptr->word_recall = 0;
957                 msg_print(_("張りつめた大気が流れ去った...", "A tension leaves the air around you..."));
958                 p_ptr->redraw |= (PR_STATUS);
959         }
960         return TRUE;
961 }
962
963 /*!
964  * @brief 帰還用メインルーチン
965  * @return 常にTRUEを返す
966  */
967 bool word_of_recall(void)
968 {
969         return(recall_player(randint0(21) + 15));
970 }
971
972 /*!
973  * @brief フロア・リセット処理
974  * @return リセット処理が実際に行われたらTRUEを返す
975  */
976 bool reset_recall(void)
977 {
978         int select_dungeon, dummy = 0;
979         char ppp[80];
980         char tmp_val[160];
981
982         select_dungeon = choose_dungeon(_("をセット", "reset"), 2, 14);
983
984         /* Ironman option */
985         if (ironman_downward)
986         {
987                 msg_print(_("何も起こらなかった。", "Nothing happens."));
988                 return TRUE;
989         }
990
991         if (!select_dungeon) return FALSE;
992         /* Prompt */
993         sprintf(ppp, _("何階にセットしますか (%d-%d):", "Reset to which level (%d-%d): "),
994                 (int)d_info[select_dungeon].mindepth, (int)max_dlv[select_dungeon]);
995
996         /* Default */
997         sprintf(tmp_val, "%d", (int)MAX(dun_level, 1));
998
999         /* Ask for a level */
1000         if (get_string(ppp, tmp_val, 10))
1001         {
1002                 /* Extract request */
1003                 dummy = atoi(tmp_val);
1004
1005                 /* Paranoia */
1006                 if (dummy < 1) dummy = 1;
1007
1008                 /* Paranoia */
1009                 if (dummy > max_dlv[select_dungeon]) dummy = max_dlv[select_dungeon];
1010                 if (dummy < d_info[select_dungeon].mindepth) dummy = d_info[select_dungeon].mindepth;
1011
1012                 max_dlv[select_dungeon] = dummy;
1013
1014                 if (record_maxdepth)
1015                         do_cmd_write_nikki(NIKKI_TRUMP, select_dungeon, _("フロア・リセットで", "using a scroll of reset recall"));
1016                                         /* Accept request */
1017 #ifdef JP
1018 msg_format("%sの帰還レベルを %d 階にセット。", d_name+d_info[select_dungeon].name, dummy, dummy * 50);
1019 #else
1020                 msg_format("Recall depth set to level %d (%d').", dummy, dummy * 50);
1021 #endif
1022
1023         }
1024         else
1025         {
1026                 return FALSE;
1027         }
1028         return TRUE;
1029 }
1030
1031
1032 /*!
1033  * @brief プレイヤーの装備劣化処理 /
1034  * Apply disenchantment to the player's stuff
1035  * @param mode 最下位ビットが1ならば劣化処理が若干低減される
1036  * @return 劣化処理に関するメッセージが発せられた場合はTRUEを返す /
1037  * Return "TRUE" if the player notices anything
1038  */
1039 bool apply_disenchant(BIT_FLAGS mode)
1040 {
1041         int             t = 0;
1042         object_type     *o_ptr;
1043         char            o_name[MAX_NLEN];
1044         int to_h, to_d, to_a, pval;
1045
1046         /* Pick a random slot */
1047         switch (randint1(8))
1048         {
1049                 case 1: t = INVEN_RARM; break;
1050                 case 2: t = INVEN_LARM; break;
1051                 case 3: t = INVEN_BOW; break;
1052                 case 4: t = INVEN_BODY; break;
1053                 case 5: t = INVEN_OUTER; break;
1054                 case 6: t = INVEN_HEAD; break;
1055                 case 7: t = INVEN_HANDS; break;
1056                 case 8: t = INVEN_FEET; break;
1057         }
1058
1059         /* Get the item */
1060         o_ptr = &inventory[t];
1061
1062         /* No item, nothing happens */
1063         if (!o_ptr->k_idx) return (FALSE);
1064
1065         /* Disenchant equipments only -- No disenchant on monster ball */
1066         if (!object_is_weapon_armour_ammo(o_ptr))
1067                 return FALSE;
1068
1069         /* Nothing to disenchant */
1070         if ((o_ptr->to_h <= 0) && (o_ptr->to_d <= 0) && (o_ptr->to_a <= 0) && (o_ptr->pval <= 1))
1071         {
1072                 /* Nothing to notice */
1073                 return (FALSE);
1074         }
1075
1076
1077         /* Describe the object */
1078         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1079
1080
1081         /* Artifacts have 71% chance to resist */
1082         if (object_is_artifact(o_ptr) && (randint0(100) < 71))
1083         {
1084                 /* Message */
1085 #ifdef JP
1086 msg_format("%s(%c)は劣化を跳ね返した!",o_name, index_to_label(t) );
1087 #else
1088                 msg_format("Your %s (%c) resist%s disenchantment!",
1089                            o_name, index_to_label(t),
1090                            ((o_ptr->number != 1) ? "" : "s"));
1091 #endif
1092
1093
1094                 /* Notice */
1095                 return (TRUE);
1096         }
1097
1098
1099         /* Memorize old value */
1100         to_h = o_ptr->to_h;
1101         to_d = o_ptr->to_d;
1102         to_a = o_ptr->to_a;
1103         pval = o_ptr->pval;
1104
1105         /* Disenchant tohit */
1106         if (o_ptr->to_h > 0) o_ptr->to_h--;
1107         if ((o_ptr->to_h > 5) && (randint0(100) < 20)) o_ptr->to_h--;
1108
1109         /* Disenchant todam */
1110         if (o_ptr->to_d > 0) o_ptr->to_d--;
1111         if ((o_ptr->to_d > 5) && (randint0(100) < 20)) o_ptr->to_d--;
1112
1113         /* Disenchant toac */
1114         if (o_ptr->to_a > 0) o_ptr->to_a--;
1115         if ((o_ptr->to_a > 5) && (randint0(100) < 20)) o_ptr->to_a--;
1116
1117         /* Disenchant pval (occasionally) */
1118         /* Unless called from wild_magic() */
1119         if ((o_ptr->pval > 1) && one_in_(13) && !(mode & 0x01)) o_ptr->pval--;
1120
1121         if ((to_h != o_ptr->to_h) || (to_d != o_ptr->to_d) ||
1122             (to_a != o_ptr->to_a) || (pval != o_ptr->pval))
1123         {
1124                 /* Message */
1125 #ifdef JP
1126                 msg_format("%s(%c)は劣化してしまった!",
1127                            o_name, index_to_label(t) );
1128 #else
1129                 msg_format("Your %s (%c) %s disenchanted!",
1130                            o_name, index_to_label(t),
1131                            ((o_ptr->number != 1) ? "were" : "was"));
1132 #endif
1133
1134                 chg_virtue(V_HARMONY, 1);
1135                 chg_virtue(V_ENCHANT, -2);
1136
1137                 /* Recalculate bonuses */
1138                 p_ptr->update |= (PU_BONUS);
1139
1140                 /* Window stuff */
1141                 p_ptr->window |= (PW_EQUIP | PW_PLAYER);
1142
1143                 calc_android_exp();
1144         }
1145
1146         /* Notice */
1147         return (TRUE);
1148 }
1149
1150 /*!
1151  * @brief プレイヤーの突然変異処理
1152  * @return なし
1153  */
1154 void mutate_player(void)
1155 {
1156         BASE_STATUS max1, cur1, max2, cur2;
1157         int ii, jj, i;
1158
1159         /* Pick a pair of stats */
1160         ii = randint0(6);
1161         for (jj = ii; jj == ii; jj = randint0(6)) /* loop */;
1162
1163         max1 = p_ptr->stat_max[ii];
1164         cur1 = p_ptr->stat_cur[ii];
1165         max2 = p_ptr->stat_max[jj];
1166         cur2 = p_ptr->stat_cur[jj];
1167
1168         p_ptr->stat_max[ii] = max2;
1169         p_ptr->stat_cur[ii] = cur2;
1170         p_ptr->stat_max[jj] = max1;
1171         p_ptr->stat_cur[jj] = cur1;
1172
1173         for (i=0;i<6;i++)
1174         {
1175                 if(p_ptr->stat_max[i] > p_ptr->stat_max_max[i]) p_ptr->stat_max[i] = p_ptr->stat_max_max[i];
1176                 if(p_ptr->stat_cur[i] > p_ptr->stat_max_max[i]) p_ptr->stat_cur[i] = p_ptr->stat_max_max[i];
1177         }
1178
1179         p_ptr->update |= (PU_BONUS);
1180 }
1181
1182
1183 /*!
1184  * @brief プレイヤーの因果混乱処理 / Apply Nexus
1185  * @param m_ptr 因果混乱をプレイヤーに与えたモンスターの情報参照ポインタ
1186  * @return なし
1187  */
1188 void apply_nexus(monster_type *m_ptr)
1189 {
1190         switch (randint1(7))
1191         {
1192                 case 1: case 2: case 3:
1193                 {
1194                         teleport_player(200, TELEPORT_PASSIVE);
1195                         break;
1196                 }
1197
1198                 case 4: case 5:
1199                 {
1200                         teleport_player_to(m_ptr->fy, m_ptr->fx, TELEPORT_PASSIVE);
1201                         break;
1202                 }
1203
1204                 case 6:
1205                 {
1206                         if (randint0(100) < p_ptr->skill_sav)
1207                         {
1208                                 msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
1209                                 break;
1210                         }
1211
1212                         /* Teleport Level */
1213                         teleport_level(0);
1214                         break;
1215                 }
1216
1217                 case 7:
1218                 {
1219                         if (randint0(100) < p_ptr->skill_sav)
1220                         {
1221                                 msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
1222                                 break;
1223                         }
1224
1225                         msg_print(_("体がねじれ始めた...", "Your body starts to scramble..."));
1226                         mutate_player();
1227                         break;
1228                 }
1229         }
1230 }
1231
1232
1233 /*!
1234  * @brief 寿命つき光源の燃素追加処理 /
1235  * Charge a lite (torch or latern)
1236  * @return なし
1237  */
1238 void phlogiston(void)
1239 {
1240         GAME_TURN max_flog = 0;
1241         object_type * o_ptr = &inventory[INVEN_LITE];
1242
1243         /* It's a lamp */
1244         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_LANTERN))
1245         {
1246                 max_flog = FUEL_LAMP;
1247         }
1248
1249         /* It's a torch */
1250         else if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
1251         {
1252                 max_flog = FUEL_TORCH;
1253         }
1254
1255         /* No torch to refill */
1256         else
1257         {
1258                 msg_print(_("燃素を消費するアイテムを装備していません。", "You are not wielding anything which uses phlogiston."));
1259                 return;
1260         }
1261
1262         if (o_ptr->xtra4 >= max_flog)
1263         {
1264                 msg_print(_("このアイテムにはこれ以上燃素を補充できません。", "No more phlogiston can be put in this item."));
1265                 return;
1266         }
1267
1268         /* Refuel */
1269         o_ptr->xtra4 += (XTRA16)(max_flog / 2);
1270
1271         /* Message */
1272         msg_print(_("照明用アイテムに燃素を補充した。", "You add phlogiston to your light item."));
1273
1274         /* Comment */
1275         if (o_ptr->xtra4 >= max_flog)
1276         {
1277                 o_ptr->xtra4 = (XTRA16)max_flog;
1278                 msg_print(_("照明用アイテムは満タンになった。", "Your light item is full."));
1279         }
1280
1281         /* Recalculate torch */
1282         p_ptr->update |= (PU_TORCH);
1283 }
1284
1285
1286 /*!
1287  * @brief 武器へのエゴ付加処理 /
1288  * Brand the current weapon
1289  * @param brand_type エゴ化ID(e_info.txtとは連動していない)
1290  * @return なし
1291  */
1292 void brand_weapon(int brand_type)
1293 {
1294         OBJECT_IDX item;
1295         object_type *o_ptr;
1296         cptr        q, s;
1297
1298
1299         /* Assume enchant weapon */
1300         item_tester_hook = object_allow_enchant_melee_weapon;
1301         item_tester_no_ryoute = TRUE;
1302
1303         /* Get an item */
1304         q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
1305         s = _("強化できる武器がない。", "You have nothing to enchant.");
1306
1307         if (!get_item(&item, q, s, (USE_EQUIP))) return;
1308
1309         /* Get the item (in the pack) */
1310         if (item >= 0)
1311         {
1312                 o_ptr = &inventory[item];
1313         }
1314
1315         /* Get the item (on the floor) */
1316         else
1317         {
1318                 o_ptr = &o_list[0 - item];
1319         }
1320
1321
1322         /* you can never modify artifacts / ego-items */
1323         /* you can never modify cursed items */
1324         /* TY: You _can_ modify broken items (if you're silly enough) */
1325         if (o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) &&
1326             !object_is_cursed(o_ptr) &&
1327             !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) &&
1328             !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE)) &&
1329             !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)))
1330         {
1331                 cptr act = NULL;
1332
1333                 /* Let's get the name before it is changed... */
1334                 char o_name[MAX_NLEN];
1335                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1336
1337                 switch (brand_type)
1338                 {
1339                 case 17:
1340                         if (o_ptr->tval == TV_SWORD)
1341                         {
1342                                 act = _("は鋭さを増した!", "becomes very sharp!");
1343
1344                                 o_ptr->name2 = EGO_SHARPNESS;
1345                                 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, dun_level) + 1;
1346
1347                                 if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
1348                                         o_ptr->pval = 2;
1349                         }
1350                         else
1351                         {
1352                                 act = _("は破壊力を増した!", "seems very powerful.");
1353                                 o_ptr->name2 = EGO_EARTHQUAKES;
1354                                 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, dun_level);
1355                         }
1356                         break;
1357                 case 16:
1358                         act = _("は人間の血を求めている!", "seems to be looking for humans!");
1359                         o_ptr->name2 = EGO_KILL_HUMAN;
1360                         break;
1361                 case 15:
1362                         act = _("は電撃に覆われた!", "covered with lightning!");
1363                         o_ptr->name2 = EGO_BRAND_ELEC;
1364                         break;
1365                 case 14:
1366                         act = _("は酸に覆われた!", "coated with acid!");
1367                         o_ptr->name2 = EGO_BRAND_ACID;
1368                         break;
1369                 case 13:
1370                         act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
1371                         o_ptr->name2 = EGO_KILL_EVIL;
1372                         break;
1373                 case 12:
1374                         act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
1375                         o_ptr->name2 = EGO_KILL_DEMON;
1376                         break;
1377                 case 11:
1378                         act = _("は屍を求めている!", "seems to be looking for undead!");
1379                         o_ptr->name2 = EGO_KILL_UNDEAD;
1380                         break;
1381                 case 10:
1382                         act = _("は動物の血を求めている!", "seems to be looking for animals!");
1383                         o_ptr->name2 = EGO_KILL_ANIMAL;
1384                         break;
1385                 case 9:
1386                         act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
1387                         o_ptr->name2 = EGO_KILL_DRAGON;
1388                         break;
1389                 case 8:
1390                         act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
1391                         o_ptr->name2 = EGO_KILL_TROLL;
1392                         break;
1393                 case 7:
1394                         act = _("はオークの血を求めている!", "seems to be looking for orcs!");
1395                         o_ptr->name2 = EGO_KILL_ORC;
1396                         break;
1397                 case 6:
1398                         act = _("は巨人の血を求めている!", "seems to be looking for giants!");
1399                         o_ptr->name2 = EGO_KILL_GIANT;
1400                         break;
1401                 case 5:
1402                         act = _("は非常に不安定になったようだ。", "seems very unstable now.");
1403                         o_ptr->name2 = EGO_TRUMP;
1404                         o_ptr->pval = randint1(2);
1405                         break;
1406                 case 4:
1407                         act = _("は血を求めている!", "thirsts for blood!");
1408                         o_ptr->name2 = EGO_VAMPIRIC;
1409                         break;
1410                 case 3:
1411                         act = _("は毒に覆われた。", "is coated with poison.");
1412                         o_ptr->name2 = EGO_BRAND_POIS;
1413                         break;
1414                 case 2:
1415                         act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
1416                         o_ptr->name2 = EGO_CHAOTIC;
1417                         break;
1418                 case 1:
1419                         act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
1420                         o_ptr->name2 = EGO_BRAND_FIRE;
1421                         break;
1422                 default:
1423                         act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
1424                         o_ptr->name2 = EGO_BRAND_COLD;
1425                         break;
1426                 }
1427
1428                 msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
1429                 enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
1430
1431                 o_ptr->discount = 99;
1432                 chg_virtue(V_ENCHANT, 2);
1433         }
1434         else
1435         {
1436                 if (flush_failure) flush();
1437
1438                 msg_print(_("属性付加に失敗した。", "The Branding failed."));
1439                 chg_virtue(V_ENCHANT, -2);
1440         }
1441         calc_android_exp();
1442 }
1443
1444
1445 /*!
1446  * @brief 虚無招来によるフロア中の全壁除去処理 /
1447  * Vanish all walls in this floor
1448  * @return 実際に処理が反映された場合TRUE
1449  */
1450 static bool vanish_dungeon(void)
1451 {
1452         int          y, x;
1453         cave_type    *c_ptr;
1454         feature_type *f_ptr;
1455         monster_type *m_ptr;
1456         char         m_name[80];
1457
1458         /* Prevent vasishing of quest levels and town */
1459         if ((p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || !dun_level)
1460         {
1461                 return FALSE;
1462         }
1463
1464         /* Scan all normal grids */
1465         for (y = 1; y < cur_hgt - 1; y++)
1466         {
1467                 for (x = 1; x < cur_wid - 1; x++)
1468                 {
1469                         c_ptr = &cave[y][x];
1470
1471                         /* Seeing true feature code (ignore mimic) */
1472                         f_ptr = &f_info[c_ptr->feat];
1473
1474                         /* Lose room and vault */
1475                         c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1476
1477                         m_ptr = &m_list[c_ptr->m_idx];
1478
1479                         /* Awake monster */
1480                         if (c_ptr->m_idx && MON_CSLEEP(m_ptr))
1481                         {
1482                                 /* Reset sleep counter */
1483                                 (void)set_monster_csleep(c_ptr->m_idx, 0);
1484
1485                                 /* Notice the "waking up" */
1486                                 if (m_ptr->ml)
1487                                 {
1488                                         /* Acquire the monster name */
1489                                         monster_desc(m_name, m_ptr, 0);
1490
1491                                         /* Dump a message */
1492                                         msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1493                                 }
1494                         }
1495
1496                         /* Process all walls, doors and patterns */
1497                         if (have_flag(f_ptr->flags, FF_HURT_DISI)) cave_alter_feat(y, x, FF_HURT_DISI);
1498                 }
1499         }
1500
1501         /* Special boundary walls -- Top and bottom */
1502         for (x = 0; x < cur_wid; x++)
1503         {
1504                 c_ptr = &cave[0][x];
1505                 f_ptr = &f_info[c_ptr->mimic];
1506
1507                 /* Lose room and vault */
1508                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1509
1510                 /* Set boundary mimic if needed */
1511                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1512                 {
1513                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1514
1515                         /* Check for change to boring grid */
1516                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1517                 }
1518
1519                 c_ptr = &cave[cur_hgt - 1][x];
1520                 f_ptr = &f_info[c_ptr->mimic];
1521
1522                 /* Lose room and vault */
1523                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1524
1525                 /* Set boundary mimic if needed */
1526                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1527                 {
1528                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1529
1530                         /* Check for change to boring grid */
1531                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1532                 }
1533         }
1534
1535         /* Special boundary walls -- Left and right */
1536         for (y = 1; y < (cur_hgt - 1); y++)
1537         {
1538                 c_ptr = &cave[y][0];
1539                 f_ptr = &f_info[c_ptr->mimic];
1540
1541                 /* Lose room and vault */
1542                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1543
1544                 /* Set boundary mimic if needed */
1545                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1546                 {
1547                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1548
1549                         /* Check for change to boring grid */
1550                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1551                 }
1552
1553                 c_ptr = &cave[y][cur_wid - 1];
1554                 f_ptr = &f_info[c_ptr->mimic];
1555
1556                 /* Lose room and vault */
1557                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1558
1559                 /* Set boundary mimic if needed */
1560                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1561                 {
1562                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1563
1564                         /* Check for change to boring grid */
1565                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1566                 }
1567         }
1568
1569         /* Mega-Hack -- Forget the view and lite */
1570         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
1571
1572         /* Update stuff */
1573         p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
1574
1575         /* Update the monsters */
1576         p_ptr->update |= (PU_MONSTERS);
1577
1578         /* Redraw map */
1579         p_ptr->redraw |= (PR_MAP);
1580
1581         /* Window stuff */
1582         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1583
1584         return TRUE;
1585 }
1586
1587 /*!
1588  * @brief 虚無招来処理 /
1589  * @return なし
1590  */
1591 void call_the_(void)
1592 {
1593         int i;
1594         cave_type *c_ptr;
1595         bool do_call = TRUE;
1596
1597         for (i = 0; i < 9; i++)
1598         {
1599                 c_ptr = &cave[p_ptr->y + ddy_ddd[i]][p_ptr->x + ddx_ddd[i]];
1600
1601                 if (!cave_have_flag_grid(c_ptr, FF_PROJECT))
1602                 {
1603                         if (!c_ptr->mimic || !have_flag(f_info[c_ptr->mimic].flags, FF_PROJECT) ||
1604                             !permanent_wall(&f_info[c_ptr->feat]))
1605                         {
1606                                 do_call = FALSE;
1607                                 break;
1608                         }
1609                 }
1610         }
1611
1612         if (do_call)
1613         {
1614                 for (i = 1; i < 10; i++)
1615                 {
1616                         if (i - 5) fire_ball(GF_ROCKET, i, 175, 2);
1617                 }
1618
1619                 for (i = 1; i < 10; i++)
1620                 {
1621                         if (i - 5) fire_ball(GF_MANA, i, 175, 3);
1622                 }
1623
1624                 for (i = 1; i < 10; i++)
1625                 {
1626                         if (i - 5) fire_ball(GF_NUKE, i, 175, 4);
1627                 }
1628         }
1629
1630         /* Prevent destruction of quest levels and town */
1631         else if ((p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || !dun_level)
1632         {
1633                 msg_print(_("地面が揺れた。", "The ground trembles."));
1634         }
1635
1636         else
1637         {
1638 #ifdef JP
1639                 msg_format("あなたは%sを壁に近すぎる場所で唱えてしまった!",
1640                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "祈り" : "呪文"));
1641                 msg_print("大きな爆発音があった!");
1642 #else
1643                 msg_format("You %s the %s too close to a wall!",
1644                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1645                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "prayer" : "spell"));
1646                 msg_print("There is a loud explosion!");
1647 #endif
1648
1649                 if (one_in_(666))
1650                 {
1651                         if (!vanish_dungeon()) msg_print(_("ダンジョンは一瞬静まり返った。", "The dungeon silences a moment."));
1652                 }
1653                 else
1654                 {
1655                         if (destroy_area(p_ptr->y, p_ptr->x, 15 + p_ptr->lev + randint0(11), FALSE))
1656                                 msg_print(_("ダンジョンが崩壊した...", "The dungeon collapses..."));
1657                         else
1658                                 msg_print(_("ダンジョンは大きく揺れた。", "The dungeon trembles."));
1659                 }
1660
1661                 take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), _("自殺的な虚無招来", "a suicidal Call the Void"), -1);
1662         }
1663 }
1664
1665
1666 /*!
1667  * @brief アイテム引き寄せ処理 /
1668  * Fetch an item (teleport it right underneath the caster)
1669  * @param dir 魔法の発動方向
1670  * @param wgt 許容重量
1671  * @param require_los 射線の通りを要求するならばTRUE
1672  * @return なし
1673  */
1674 void fetch(DIRECTION dir, WEIGHT wgt, bool require_los)
1675 {
1676         POSITION ty, tx;
1677         OBJECT_IDX i;
1678         cave_type *c_ptr;
1679         object_type *o_ptr;
1680         char o_name[MAX_NLEN];
1681
1682         /* Check to see if an object is already there */
1683         if (cave[p_ptr->y][p_ptr->x].o_idx)
1684         {
1685                 msg_print(_("自分の足の下にある物は取れません。", "You can't fetch when you're already standing on something."));
1686                 return;
1687         }
1688
1689         /* Use a target */
1690         if (dir == 5 && target_okay())
1691         {
1692                 tx = target_col;
1693                 ty = target_row;
1694
1695                 if (distance(p_ptr->y, p_ptr->x, ty, tx) > MAX_RANGE)
1696                 {
1697                         msg_print(_("そんなに遠くにある物は取れません!", "You can't fetch something that far away!"));
1698                         return;
1699                 }
1700
1701                 c_ptr = &cave[ty][tx];
1702
1703                 /* We need an item to fetch */
1704                 if (!c_ptr->o_idx)
1705                 {
1706                         msg_print(_("そこには何もありません。", "There is no object at this place."));
1707                         return;
1708                 }
1709
1710                 /* No fetching from vault */
1711                 if (c_ptr->info & CAVE_ICKY)
1712                 {
1713                         msg_print(_("アイテムがコントロールを外れて落ちた。", "The item slips from your control."));
1714                         return;
1715                 }
1716
1717                 /* We need to see the item */
1718                 if (require_los)
1719                 {
1720                         if (!player_has_los_bold(ty, tx))
1721                         {
1722                                 msg_print(_("そこはあなたの視界に入っていません。", "You have no direct line of sight to that location."));
1723                                 return;
1724                         }
1725                         else if (!projectable(p_ptr->y, p_ptr->x, ty, tx))
1726                         {
1727                                 msg_print(_("そこは壁の向こうです。", "You have no direct line of sight to that location."));
1728                                 return;
1729                         }
1730                 }
1731         }
1732         else
1733         {
1734                 /* Use a direction */
1735                 ty = p_ptr->y; /* Where to drop the item */
1736                 tx = p_ptr->x;
1737
1738                 do
1739                 {
1740                         ty += ddy[dir];
1741                         tx += ddx[dir];
1742                         c_ptr = &cave[ty][tx];
1743
1744                         if ((distance(p_ptr->y, p_ptr->x, ty, tx) > MAX_RANGE) ||
1745                                 !cave_have_flag_bold(ty, tx, FF_PROJECT)) return;
1746                 }
1747                 while (!c_ptr->o_idx);
1748         }
1749
1750         o_ptr = &o_list[c_ptr->o_idx];
1751
1752         if (o_ptr->weight > wgt)
1753         {
1754                 /* Too heavy to 'fetch' */
1755                 msg_print(_("そのアイテムは重過ぎます。", "The object is too heavy."));
1756                 return;
1757         }
1758
1759         i = c_ptr->o_idx;
1760         c_ptr->o_idx = o_ptr->next_o_idx;
1761         cave[p_ptr->y][p_ptr->x].o_idx = i; /* 'move' it */
1762
1763         o_ptr->next_o_idx = 0;
1764         o_ptr->iy = (byte)p_ptr->y;
1765         o_ptr->ix = (byte)p_ptr->x;
1766
1767         object_desc(o_name, o_ptr, OD_NAME_ONLY);
1768         msg_format(_("%^sがあなたの足元に飛んできた。", "%^s flies through the air to your feet."), o_name);
1769
1770         note_spot(p_ptr->y, p_ptr->x);
1771         p_ptr->redraw |= PR_MAP;
1772 }
1773
1774 /*!
1775  * @brief 現実変容処理
1776  * @return なし
1777  */
1778 void alter_reality(void)
1779 {
1780         /* Ironman option */
1781         if (p_ptr->inside_arena || ironman_downward)
1782         {
1783                 msg_print(_("何も起こらなかった。", "Nothing happens."));
1784                 return;
1785         }
1786
1787         if (!p_ptr->alter_reality)
1788         {
1789                 TIME_EFFECT turns = randint0(21) + 15;
1790
1791                 p_ptr->alter_reality = turns;
1792                 msg_print(_("回りの景色が変わり始めた...", "The view around you begins to change..."));
1793
1794                 p_ptr->redraw |= (PR_STATUS);
1795         }
1796         else
1797         {
1798                 p_ptr->alter_reality = 0;
1799                 msg_print(_("景色が元に戻った...", "The view around you got back..."));
1800                 p_ptr->redraw |= (PR_STATUS);
1801         }
1802         return;
1803 }
1804
1805
1806 /*!
1807  * @brief 守りのルーン設置処理 /
1808  * Leave a "glyph of warding" which prevents monster movement
1809  * @return 実際に設置が行われた場合TRUEを返す
1810  */
1811 bool warding_glyph(void)
1812 {
1813         /* XXX XXX XXX */
1814         if (!cave_clean_bold(p_ptr->y, p_ptr->x))
1815         {
1816                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1817                 return FALSE;
1818         }
1819
1820         /* Create a glyph */
1821         cave[p_ptr->y][p_ptr->x].info |= CAVE_OBJECT;
1822         cave[p_ptr->y][p_ptr->x].mimic = feat_glyph;
1823
1824         /* Notice */
1825         note_spot(p_ptr->y, p_ptr->x);
1826
1827         /* Redraw */
1828         lite_spot(p_ptr->y, p_ptr->x);
1829
1830         return TRUE;
1831 }
1832
1833 /*!
1834  * @brief 鏡設置処理
1835  * @return 実際に設置が行われた場合TRUEを返す
1836  */
1837 bool place_mirror(void)
1838 {
1839         /* XXX XXX XXX */
1840         if (!cave_clean_bold(p_ptr->y, p_ptr->x))
1841         {
1842                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1843                 return FALSE;
1844         }
1845
1846         /* Create a mirror */
1847         cave[p_ptr->y][p_ptr->x].info |= CAVE_OBJECT;
1848         cave[p_ptr->y][p_ptr->x].mimic = feat_mirror;
1849
1850         /* Turn on the light */
1851         cave[p_ptr->y][p_ptr->x].info |= CAVE_GLOW;
1852
1853         /* Notice */
1854         note_spot(p_ptr->y, p_ptr->x);
1855
1856         /* Redraw */
1857         lite_spot(p_ptr->y, p_ptr->x);
1858
1859         update_local_illumination(p_ptr->y, p_ptr->x);
1860
1861         return TRUE;
1862 }
1863
1864
1865 /*!
1866  * @brief 爆発のルーン設置処理 /
1867  * Leave an "explosive rune" which prevents monster movement
1868  * @return 実際に設置が行われた場合TRUEを返す
1869  */
1870 bool explosive_rune(void)
1871 {
1872         /* XXX XXX XXX */
1873         if (!cave_clean_bold(p_ptr->y, p_ptr->x))
1874         {
1875                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1876                 return FALSE;
1877         }
1878
1879         /* Create a glyph */
1880         cave[p_ptr->y][p_ptr->x].info |= CAVE_OBJECT;
1881         cave[p_ptr->y][p_ptr->x].mimic = feat_explosive_rune;
1882
1883         /* Notice */
1884         note_spot(p_ptr->y, p_ptr->x);
1885         
1886         /* Redraw */
1887         lite_spot(p_ptr->y, p_ptr->x);
1888
1889         return TRUE;
1890 }
1891
1892
1893 /*!
1894  * @brief 全所持アイテム鑑定処理 /
1895  * Identify everything being carried.
1896  * Done by a potion of "self knowledge".
1897  * @return なし
1898  */
1899 void identify_pack(void)
1900 {
1901         int i;
1902
1903         /* Simply identify and know every item */
1904         for (i = 0; i < INVEN_TOTAL; i++)
1905         {
1906                 object_type *o_ptr = &inventory[i];
1907
1908                 /* Skip non-objects */
1909                 if (!o_ptr->k_idx) continue;
1910
1911                 /* Identify it */
1912                 identify_item(o_ptr);
1913
1914                 /* Auto-inscription */
1915                 autopick_alter_item(i, FALSE);
1916         }
1917 }
1918
1919
1920 /*!
1921  * @brief 装備強化処理の失敗率定数(千分率) /
1922  * Used by the "enchant" function (chance of failure)
1923  * (modified for Zangband, we need better stuff there...) -- TY
1924  * @return なし
1925  */
1926 static int enchant_table[16] =
1927 {
1928         0, 10,  50, 100, 200,
1929         300, 400, 500, 650, 800,
1930         950, 987, 993, 995, 998,
1931         1000
1932 };
1933
1934
1935 /*!
1936  * @brief 装備の解呪処理 /
1937  * Removes curses from items in inventory
1938  * @param all 軽い呪いまでの解除ならば0
1939  * @return 解呪されたアイテムの数
1940  * @details
1941  * <pre>
1942  * Note that Items which are "Perma-Cursed" (The One Ring,
1943  * The Crown of Morgoth) can NEVER be uncursed.
1944  *
1945  * Note that if "all" is FALSE, then Items which are
1946  * "Heavy-Cursed" (Mormegil, Calris, and Weapons of Morgul)
1947  * will not be uncursed.
1948  * </pre>
1949  */
1950 static int remove_curse_aux(int all)
1951 {
1952         int i, cnt = 0;
1953
1954         /* Attempt to uncurse items being worn */
1955         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
1956         {
1957                 object_type *o_ptr = &inventory[i];
1958
1959                 /* Skip non-objects */
1960                 if (!o_ptr->k_idx) continue;
1961
1962                 /* Uncursed already */
1963                 if (!object_is_cursed(o_ptr)) continue;
1964
1965                 /* Heavily Cursed Items need a special spell */
1966                 if (!all && (o_ptr->curse_flags & TRC_HEAVY_CURSE)) continue;
1967
1968                 /* Perma-Cursed Items can NEVER be uncursed */
1969                 if (o_ptr->curse_flags & TRC_PERMA_CURSE)
1970                 {
1971                         /* Uncurse it */
1972                         o_ptr->curse_flags &= (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE);
1973                         continue;
1974                 }
1975
1976                 /* Uncurse it */
1977                 o_ptr->curse_flags = 0L;
1978
1979                 /* Hack -- Assume felt */
1980                 o_ptr->ident |= (IDENT_SENSE);
1981
1982                 /* Take note */
1983                 o_ptr->feeling = FEEL_NONE;
1984
1985                 /* Recalculate the bonuses */
1986                 p_ptr->update |= (PU_BONUS);
1987
1988                 /* Window stuff */
1989                 p_ptr->window |= (PW_EQUIP);
1990
1991                 /* Count the uncursings */
1992                 cnt++;
1993         }
1994
1995         /* Return "something uncursed" */
1996         return (cnt);
1997 }
1998
1999
2000 /*!
2001  * @brief 装備の軽い呪い解呪処理 /
2002  * Remove most curses
2003  * @return 解呪に成功した装備数
2004  */
2005 int remove_curse(void)
2006 {
2007         return (remove_curse_aux(FALSE));
2008 }
2009
2010 /*!
2011  * @brief 装備の重い呪い解呪処理 /
2012  * Remove all curses
2013  * @return 解呪に成功した装備数
2014  */
2015 int remove_all_curse(void)
2016 {
2017         return (remove_curse_aux(TRUE));
2018 }
2019
2020
2021 /*!
2022  * @brief アイテムの価値に応じた錬金術処理 /
2023  * Turns an object into gold, gain some of its value in a shop
2024  * @return 処理が実際に行われたらTRUEを返す
2025  */
2026 bool alchemy(void)
2027 {
2028         OBJECT_IDX item;
2029         int amt = 1;
2030         ITEM_NUMBER old_number;
2031         PRICE price;
2032         bool force = FALSE;
2033         object_type *o_ptr;
2034         char o_name[MAX_NLEN];
2035         char out_val[MAX_NLEN+40];
2036
2037         cptr q, s;
2038
2039         /* Hack -- force destruction */
2040         if (command_arg > 0) force = TRUE;
2041
2042         /* Get an item */
2043         q = _("どのアイテムを金に変えますか?", "Turn which item to gold? ");
2044         s = _("金に変えられる物がありません。", "You have nothing to turn to gold.");
2045
2046         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE);
2047
2048         /* Get the item (in the pack) */
2049         if (item >= 0)
2050         {
2051                 o_ptr = &inventory[item];
2052         }
2053
2054         /* Get the item (on the floor) */
2055         else
2056         {
2057                 o_ptr = &o_list[0 - item];
2058         }
2059
2060
2061         /* See how many items */
2062         if (o_ptr->number > 1)
2063         {
2064                 /* Get a quantity */
2065                 amt = get_quantity(NULL, o_ptr->number);
2066
2067                 /* Allow user abort */
2068                 if (amt <= 0) return FALSE;
2069         }
2070
2071
2072         /* Describe the object */
2073         old_number = o_ptr->number;
2074         o_ptr->number = amt;
2075         object_desc(o_name, o_ptr, 0);
2076         o_ptr->number = old_number;
2077
2078         /* Verify unless quantity given */
2079         if (!force)
2080         {
2081                 if (confirm_destroy || (object_value(o_ptr) > 0))
2082                 {
2083                         /* Make a verification */
2084                         sprintf(out_val, _("本当に%sを金に変えますか?", "Really turn %s to gold? "), o_name);
2085                         if (!get_check(out_val)) return FALSE;
2086                 }
2087         }
2088
2089         /* Artifacts cannot be destroyed */
2090         if (!can_player_destroy_object(o_ptr))
2091         {
2092                 /* Message */
2093                 msg_format(_("%sを金に変えることに失敗した。", "You fail to turn %s to gold!"), o_name);
2094
2095                 /* Done */
2096                 return FALSE;
2097         }
2098
2099         price = object_value_real(o_ptr);
2100
2101         if (price <= 0)
2102         {
2103                 /* Message */
2104                 msg_format(_("%sをニセの金に変えた。", "You turn %s to fool's gold."), o_name);
2105         }
2106         else
2107         {
2108                 price /= 3;
2109
2110                 if (amt > 1) price *= amt;
2111
2112                 if (price > 30000) price = 30000;
2113                 msg_format(_("%sを$%d の金に変えた。", "You turn %s to %ld coins worth of gold."), o_name, price);
2114
2115                 p_ptr->au += price;
2116
2117                 /* Redraw gold */
2118                 p_ptr->redraw |= (PR_GOLD);
2119
2120                 /* Window stuff */
2121                 p_ptr->window |= (PW_PLAYER);
2122
2123         }
2124
2125         /* Eliminate the item (from the pack) */
2126         if (item >= 0)
2127         {
2128                 inven_item_increase(item, -amt);
2129                 inven_item_describe(item);
2130                 inven_item_optimize(item);
2131         }
2132
2133         /* Eliminate the item (from the floor) */
2134         else
2135         {
2136                 floor_item_increase(0 - item, -amt);
2137                 floor_item_describe(0 - item);
2138                 floor_item_optimize(0 - item);
2139         }
2140
2141         return TRUE;
2142 }
2143
2144
2145 /*!
2146  * @brief 呪いの打ち破り処理 /
2147  * Break the curse of an item
2148  * @param o_ptr 呪い装備情報の参照ポインタ
2149  * @return なし
2150  */
2151 static void break_curse(object_type *o_ptr)
2152 {
2153         if (object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25))
2154         {
2155                 msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
2156
2157                 o_ptr->curse_flags = 0L;
2158                 o_ptr->ident |= (IDENT_SENSE);
2159                 o_ptr->feeling = FEEL_NONE;
2160         }
2161 }
2162
2163
2164 /*!
2165  * @brief 装備修正強化処理 /
2166  * Enchants a plus onto an item. -RAK-
2167  * @param o_ptr 強化するアイテムの参照ポインタ
2168  * @param n 強化基本量
2169  * @param eflag 強化オプション(命中/ダメージ/AC)
2170  * @return 強化に成功した場合TRUEを返す
2171  * @details
2172  * <pre>
2173  * Revamped!  Now takes item pointer, number of times to try enchanting,
2174  * and a flag of what to try enchanting.  Artifacts resist enchantment
2175  * some of the time, and successful enchantment to at least +0 might
2176  * break a curse on the item. -CFT-
2177  *
2178  * Note that an item can technically be enchanted all the way to +15 if
2179  * you wait a very, very, long time.  Going from +9 to +10 only works
2180  * about 5% of the time, and from +10 to +11 only about 1% of the time.
2181  *
2182  * Note that this function can now be used on "piles" of items, and
2183  * the larger the pile, the lower the chance of success.
2184  * </pre>
2185  */
2186 bool enchant(object_type *o_ptr, int n, int eflag)
2187 {
2188         int     i, chance, prob;
2189         bool    res = FALSE;
2190         bool    a = object_is_artifact(o_ptr);
2191         bool    force = (eflag & ENCH_FORCE);
2192
2193
2194         /* Large piles resist enchantment */
2195         prob = o_ptr->number * 100;
2196
2197         /* Missiles are easy to enchant */
2198         if ((o_ptr->tval == TV_BOLT) ||
2199             (o_ptr->tval == TV_ARROW) ||
2200             (o_ptr->tval == TV_SHOT))
2201         {
2202                 prob = prob / 20;
2203         }
2204
2205         /* Try "n" times */
2206         for (i = 0; i < n; i++)
2207         {
2208                 /* Hack -- Roll for pile resistance */
2209                 if (!force && randint0(prob) >= 100) continue;
2210
2211                 /* Enchant to hit */
2212                 if (eflag & ENCH_TOHIT)
2213                 {
2214                         if (o_ptr->to_h < 0) chance = 0;
2215                         else if (o_ptr->to_h > 15) chance = 1000;
2216                         else chance = enchant_table[o_ptr->to_h];
2217
2218                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2219                         {
2220                                 o_ptr->to_h++;
2221                                 res = TRUE;
2222
2223                                 /* only when you get it above -1 -CFT */
2224                                 if (o_ptr->to_h >= 0)
2225                                         break_curse(o_ptr);
2226                         }
2227                 }
2228
2229                 /* Enchant to damage */
2230                 if (eflag & ENCH_TODAM)
2231                 {
2232                         if (o_ptr->to_d < 0) chance = 0;
2233                         else if (o_ptr->to_d > 15) chance = 1000;
2234                         else chance = enchant_table[o_ptr->to_d];
2235
2236                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2237                         {
2238                                 o_ptr->to_d++;
2239                                 res = TRUE;
2240
2241                                 /* only when you get it above -1 -CFT */
2242                                 if (o_ptr->to_d >= 0)
2243                                         break_curse(o_ptr);
2244                         }
2245                 }
2246
2247                 /* Enchant to armor class */
2248                 if (eflag & ENCH_TOAC)
2249                 {
2250                         if (o_ptr->to_a < 0) chance = 0;
2251                         else if (o_ptr->to_a > 15) chance = 1000;
2252                         else chance = enchant_table[o_ptr->to_a];
2253
2254                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2255                         {
2256                                 o_ptr->to_a++;
2257                                 res = TRUE;
2258
2259                                 /* only when you get it above -1 -CFT */
2260                                 if (o_ptr->to_a >= 0)
2261                                         break_curse(o_ptr);
2262                         }
2263                 }
2264         }
2265
2266         /* Failure */
2267         if (!res) return (FALSE);
2268
2269         /* Recalculate bonuses */
2270         p_ptr->update |= (PU_BONUS);
2271
2272         /* Combine / Reorder the pack (later) */
2273         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2274
2275         /* Window stuff */
2276         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2277
2278         calc_android_exp();
2279
2280         /* Success */
2281         return (TRUE);
2282 }
2283
2284
2285 /*!
2286  * @brief 装備修正強化処理のメインルーチン /
2287  * Enchant an item (in the inventory or on the floor)
2288  * @param num_hit 命中修正量
2289  * @param num_dam ダメージ修正量
2290  * @param num_ac AC修正量
2291  * @return 強化に成功した場合TRUEを返す
2292  * @details
2293  * Note that "num_ac" requires armour, else weapon
2294  * Returns TRUE if attempted, FALSE if cancelled
2295  */
2296 bool enchant_spell(HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
2297 {
2298         OBJECT_IDX item;
2299         bool        okay = FALSE;
2300         object_type *o_ptr;
2301         char        o_name[MAX_NLEN];
2302         cptr        q, s;
2303
2304
2305         /* Assume enchant weapon */
2306         item_tester_hook = object_allow_enchant_weapon;
2307         item_tester_no_ryoute = TRUE;
2308
2309         /* Enchant armor if requested */
2310         if (num_ac) item_tester_hook = object_is_armour;
2311
2312         /* Get an item */
2313         q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
2314         s = _("強化できるアイテムがない。", "You have nothing to enchant.");
2315
2316         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2317
2318         /* Get the item (in the pack) */
2319         if (item >= 0)
2320         {
2321                 o_ptr = &inventory[item];
2322         }
2323
2324         /* Get the item (on the floor) */
2325         else
2326         {
2327                 o_ptr = &o_list[0 - item];
2328         }
2329
2330
2331         /* Description */
2332         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2333
2334         /* Describe */
2335 #ifdef JP
2336 msg_format("%s は明るく輝いた!",
2337     o_name);
2338 #else
2339         msg_format("%s %s glow%s brightly!",
2340                    ((item >= 0) ? "Your" : "The"), o_name,
2341                    ((o_ptr->number > 1) ? "" : "s"));
2342 #endif
2343
2344
2345         /* Enchant */
2346         if (enchant(o_ptr, num_hit, ENCH_TOHIT)) okay = TRUE;
2347         if (enchant(o_ptr, num_dam, ENCH_TODAM)) okay = TRUE;
2348         if (enchant(o_ptr, num_ac, ENCH_TOAC)) okay = TRUE;
2349
2350         /* Failure */
2351         if (!okay)
2352         {
2353                 /* Flush */
2354                 if (flush_failure) flush();
2355
2356                 /* Message */
2357                 msg_print(_("強化に失敗した。", "The enchantment failed."));
2358
2359                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
2360         }
2361         else
2362                 chg_virtue(V_ENCHANT, 1);
2363
2364         calc_android_exp();
2365
2366         /* Something happened */
2367         return (TRUE);
2368 }
2369
2370
2371 /*!
2372  * @brief アイテムが並の価値のアイテムかどうか判定する /
2373  * Check if an object is nameless weapon or armour
2374  * @param o_ptr 判定するアイテムの情報参照ポインタ
2375  * @return 並ならばTRUEを返す
2376  */
2377 static bool item_tester_hook_nameless_weapon_armour(object_type *o_ptr)
2378 {
2379         /* Require weapon or armour */
2380         if (!object_is_weapon_armour_ammo(o_ptr)) return FALSE;
2381         
2382         /* Require nameless object if the object is well known */
2383         if (object_is_known(o_ptr) && !object_is_nameless(o_ptr))
2384                 return FALSE;
2385
2386         return TRUE;
2387 }
2388
2389 /*!
2390  * @brief アーティファクト生成の巻物処理 /
2391  * @return 生成が実際に試みられたらTRUEを返す
2392  */
2393 bool artifact_scroll(void)
2394 {
2395         OBJECT_IDX item;
2396         bool            okay = FALSE;
2397         object_type     *o_ptr;
2398         char            o_name[MAX_NLEN];
2399         cptr            q, s;
2400
2401
2402         item_tester_no_ryoute = TRUE;
2403
2404         /* Enchant weapon/armour */
2405         item_tester_hook = item_tester_hook_nameless_weapon_armour;
2406
2407         /* Get an item */
2408         q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
2409         s = _("強化できるアイテムがない。", "You have nothing to enchant.");
2410
2411         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2412
2413         /* Get the item (in the pack) */
2414         if (item >= 0)
2415         {
2416                 o_ptr = &inventory[item];
2417         }
2418
2419         /* Get the item (on the floor) */
2420         else
2421         {
2422                 o_ptr = &o_list[0 - item];
2423         }
2424
2425
2426         /* Description */
2427         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2428
2429         /* Describe */
2430 #ifdef JP
2431         msg_format("%s は眩い光を発した!",o_name);
2432 #else
2433         msg_format("%s %s radiate%s a blinding light!",
2434                   ((item >= 0) ? "Your" : "The"), o_name,
2435                   ((o_ptr->number > 1) ? "" : "s"));
2436 #endif
2437
2438         if (object_is_artifact(o_ptr))
2439         {
2440 #ifdef JP
2441                 msg_format("%sは既に伝説のアイテムです!", o_name  );
2442 #else
2443                 msg_format("The %s %s already %s!",
2444                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2445                     ((o_ptr->number > 1) ? "artifacts" : "an artifact"));
2446 #endif
2447
2448                 okay = FALSE;
2449         }
2450
2451         else if (object_is_ego(o_ptr))
2452         {
2453 #ifdef JP
2454                 msg_format("%sは既に名のあるアイテムです!", o_name );
2455 #else
2456                 msg_format("The %s %s already %s!",
2457                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2458                     ((o_ptr->number > 1) ? "ego items" : "an ego item"));
2459 #endif
2460
2461                 okay = FALSE;
2462         }
2463
2464         else if (o_ptr->xtra3)
2465         {
2466 #ifdef JP
2467                 msg_format("%sは既に強化されています!", o_name );
2468 #else
2469                 msg_format("The %s %s already %s!",
2470                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2471                     ((o_ptr->number > 1) ? "customized items" : "a customized item"));
2472 #endif
2473         }
2474
2475         else
2476         {
2477                 if (o_ptr->number > 1)
2478                 {
2479 #ifdef JP
2480                         msg_print("複数のアイテムに魔法をかけるだけのエネルギーはありません!");
2481                         msg_format("%d 個の%sが壊れた!",(o_ptr->number)-1, o_name);
2482 #else
2483                         msg_print("Not enough enough energy to enchant more than one object!");
2484                         msg_format("%d of your %s %s destroyed!",(o_ptr->number)-1, o_name, (o_ptr->number>2?"were":"was"));
2485 #endif
2486
2487                         if (item >= 0)
2488                         {
2489                                 inven_item_increase(item, 1-(o_ptr->number));
2490                         }
2491                         else
2492                         {
2493                                 floor_item_increase(0-item, 1-(o_ptr->number));
2494                         }
2495                 }
2496                 okay = create_artifact(o_ptr, TRUE);
2497         }
2498
2499         /* Failure */
2500         if (!okay)
2501         {
2502                 /* Flush */
2503                 if (flush_failure) flush();
2504
2505                 /* Message */
2506                 msg_print(_("強化に失敗した。", "The enchantment failed."));
2507
2508                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
2509         }
2510         else
2511         {
2512                 if (record_rand_art)
2513                 {
2514                         /* Description */
2515                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2516                         do_cmd_write_nikki(NIKKI_ART_SCROLL, 0, o_name);
2517                 }
2518                 chg_virtue(V_ENCHANT, 1);
2519         }
2520
2521         calc_android_exp();
2522
2523         /* Something happened */
2524         return (TRUE);
2525 }
2526
2527
2528 /*!
2529  * @brief アイテム鑑定処理 /
2530  * Identify an object
2531  * @param o_ptr 鑑定されるアイテムの情報参照ポインタ
2532  * @return 実際に鑑定できたらTRUEを返す
2533  */
2534 bool identify_item(object_type *o_ptr)
2535 {
2536         bool old_known = FALSE;
2537         char o_name[MAX_NLEN];
2538
2539         /* Description */
2540         object_desc(o_name, o_ptr, 0);
2541
2542         if (o_ptr->ident & IDENT_KNOWN)
2543                 old_known = TRUE;
2544
2545         if (!(o_ptr->ident & (IDENT_MENTAL)))
2546         {
2547                 if (object_is_artifact(o_ptr) || one_in_(5))
2548                         chg_virtue(V_KNOWLEDGE, 1);
2549         }
2550
2551         /* Identify it fully */
2552         object_aware(o_ptr);
2553         object_known(o_ptr);
2554
2555         /* Player touches it */
2556         o_ptr->marked |= OM_TOUCHED;
2557
2558         /* Recalculate bonuses */
2559         p_ptr->update |= (PU_BONUS);
2560
2561         /* Combine / Reorder the pack (later) */
2562         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2563
2564         /* Window stuff */
2565         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2566
2567         strcpy(record_o_name, o_name);
2568         record_turn = turn;
2569
2570         /* Description */
2571         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2572
2573         if(record_fix_art && !old_known && object_is_fixed_artifact(o_ptr))
2574                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2575         if(record_rand_art && !old_known && o_ptr->art_name)
2576                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2577
2578         return old_known;
2579 }
2580
2581 /*!
2582  * @brief アイテムが鑑定済みかを判定する /
2583  * @param o_ptr 判定するアイテムの情報参照ポインタ
2584  * @return 実際に鑑定済みならばTRUEを返す
2585  */
2586 static bool item_tester_hook_identify(object_type *o_ptr)
2587 {
2588         return (bool)!object_is_known(o_ptr);
2589 }
2590
2591 /*!
2592  * @brief アイテムが鑑定済みの武器防具かを判定する /
2593  * @param o_ptr 判定するアイテムの情報参照ポインタ
2594  * @return 実際に鑑定済みならばTRUEを返す
2595  */
2596 static bool item_tester_hook_identify_weapon_armour(object_type *o_ptr)
2597 {
2598         if (object_is_known(o_ptr))
2599                 return FALSE;
2600         return object_is_weapon_armour_ammo(o_ptr);
2601 }
2602
2603 /*!
2604  * @brief アイテム鑑定のメインルーチン処理 /
2605  * Identify an object in the inventory (or on the floor)
2606  * @param only_equip 装備品のみを対象とするならばTRUEを返す
2607  * @return 実際に鑑定を行ったならばTRUEを返す
2608  * @details
2609  * This routine does *not* automatically combine objects.
2610  * Returns TRUE if something was identified, else FALSE.
2611  */
2612 bool ident_spell(bool only_equip)
2613 {
2614         OBJECT_IDX item;
2615         object_type     *o_ptr;
2616         char            o_name[MAX_NLEN];
2617         cptr            q, s;
2618         bool old_known;
2619
2620         item_tester_no_ryoute = TRUE;
2621
2622         if (only_equip)
2623                 item_tester_hook = item_tester_hook_identify_weapon_armour;
2624         else
2625                 item_tester_hook = item_tester_hook_identify;
2626
2627         if (can_get_item())
2628         {
2629                 q = _("どのアイテムを鑑定しますか? ", "Identify which item? ");
2630         }
2631         else
2632         {
2633                 if (only_equip)
2634                         item_tester_hook = object_is_weapon_armour_ammo;
2635                 else
2636                         item_tester_hook = NULL;
2637
2638                 q = _("すべて鑑定済みです。 ", "All items are identified. ");
2639         }
2640
2641         /* Get an item */
2642         s = _("鑑定するべきアイテムがない。", "You have nothing to identify.");
2643
2644         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2645
2646         /* Get the item (in the pack) */
2647         if (item >= 0)
2648         {
2649                 o_ptr = &inventory[item];
2650         }
2651
2652         /* Get the item (on the floor) */
2653         else
2654         {
2655                 o_ptr = &o_list[0 - item];
2656         }
2657
2658         /* Identify it */
2659         old_known = identify_item(o_ptr);
2660
2661         /* Description */
2662         object_desc(o_name, o_ptr, 0);
2663
2664         /* Describe */
2665         if (item >= INVEN_RARM)
2666         {
2667                 msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(item), o_name, index_to_label(item));
2668         }
2669         else if (item >= 0)
2670         {
2671                 msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
2672         }
2673         else
2674         {
2675                 msg_format(_("床上: %s。", "On the ground: %s."), o_name);
2676         }
2677
2678         /* Auto-inscription/destroy */
2679         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
2680
2681         /* Something happened */
2682         return (TRUE);
2683 }
2684
2685
2686 /*!
2687  * @brief アイテム凡庸化のメインルーチン処理 /
2688  * Identify an object in the inventory (or on the floor)
2689  * @param only_equip 装備品のみを対象とするならばTRUEを返す
2690  * @return 実際に凡庸化をを行ったならばTRUEを返す
2691  * @details
2692  * <pre>
2693  * Mundanify an object in the inventory (or on the floor)
2694  * This routine does *not* automatically combine objects.
2695  * Returns TRUE if something was mundanified, else FALSE.
2696  * </pre>
2697  */
2698 bool mundane_spell(bool only_equip)
2699 {
2700         OBJECT_IDX item;
2701         object_type     *o_ptr;
2702         cptr            q, s;
2703
2704         if (only_equip) item_tester_hook = object_is_weapon_armour_ammo;
2705         item_tester_no_ryoute = TRUE;
2706
2707         /* Get an item */
2708         q = _("どれを使いますか?", "Use which item? ");
2709         s = _("使えるものがありません。", "You have nothing you can use.");
2710
2711         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2712
2713         /* Get the item (in the pack) */
2714         if (item >= 0)
2715         {
2716                 o_ptr = &inventory[item];
2717         }
2718
2719         /* Get the item (on the floor) */
2720         else
2721         {
2722                 o_ptr = &o_list[0 - item];
2723         }
2724
2725         /* Oops */
2726         msg_print(_("まばゆい閃光が走った!", "There is a bright flash of light!"));
2727         {
2728                 POSITION iy = o_ptr->iy;                 /* Y-position on map, or zero */
2729                 POSITION ix = o_ptr->ix;                 /* X-position on map, or zero */
2730                 s16b next_o_idx = o_ptr->next_o_idx; /* Next object in stack (if any) */
2731                 byte marked = o_ptr->marked;         /* Object is marked */
2732                 s16b weight = o_ptr->number * o_ptr->weight;
2733                 u16b inscription = o_ptr->inscription;
2734
2735                 /* Wipe it clean */
2736                 object_prep(o_ptr, o_ptr->k_idx);
2737
2738                 o_ptr->iy = iy;
2739                 o_ptr->ix = ix;
2740                 o_ptr->next_o_idx = next_o_idx;
2741                 o_ptr->marked = marked;
2742                 o_ptr->inscription = inscription;
2743                 if (item >= 0) p_ptr->total_weight += (o_ptr->weight - weight);
2744         }
2745         calc_android_exp();
2746
2747         /* Something happened */
2748         return TRUE;
2749 }
2750
2751 /*!
2752  * @brief アイテムが*鑑定*済みかを判定する /
2753  * @param o_ptr 判定するアイテムの情報参照ポインタ
2754  * @return 実際に鑑定済みならばTRUEを返す
2755  */
2756 static bool item_tester_hook_identify_fully(object_type *o_ptr)
2757 {
2758         return (bool)(!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL));
2759 }
2760
2761 /*!
2762  * @brief アイテムが*鑑定*済みの武器防具かを判定する /
2763  * @param o_ptr 判定するアイテムの情報参照ポインタ
2764  * @return 実際に鑑定済みならばTRUEを返す
2765  */
2766 static bool item_tester_hook_identify_fully_weapon_armour(object_type *o_ptr)
2767 {
2768         if (!item_tester_hook_identify_fully(o_ptr))
2769                 return FALSE;
2770         return object_is_weapon_armour_ammo(o_ptr);
2771 }
2772
2773 /*!
2774  * @brief アイテム*鑑定*のメインルーチン処理 /
2775  * Identify an object in the inventory (or on the floor)
2776  * @param only_equip 装備品のみを対象とするならばTRUEを返す
2777  * @return 実際に鑑定を行ったならばTRUEを返す
2778  * @details
2779  * Fully "identify" an object in the inventory  -BEN-
2780  * This routine returns TRUE if an item was identified.
2781  */
2782 bool identify_fully(bool only_equip)
2783 {
2784         OBJECT_IDX item;
2785         object_type     *o_ptr;
2786         char            o_name[MAX_NLEN];
2787         cptr            q, s;
2788         bool old_known;
2789
2790         item_tester_no_ryoute = TRUE;
2791         if (only_equip)
2792                 item_tester_hook = item_tester_hook_identify_fully_weapon_armour;
2793         else
2794                 item_tester_hook = item_tester_hook_identify_fully;
2795
2796         if (can_get_item())
2797         {
2798                 q = _("どのアイテムを*鑑定*しますか? ", "*Identify* which item? ");
2799         }
2800         else
2801         {
2802                 if (only_equip)
2803                         item_tester_hook = object_is_weapon_armour_ammo;
2804                 else
2805                         item_tester_hook = NULL;
2806
2807                 q = _("すべて*鑑定*済みです。 ", "All items are *identified*. ");
2808         }
2809
2810         /* Get an item */
2811         s = _("*鑑定*するべきアイテムがない。", "You have nothing to *identify*.");
2812
2813         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2814
2815         /* Get the item (in the pack) */
2816         if (item >= 0)
2817         {
2818                 o_ptr = &inventory[item];
2819         }
2820
2821         /* Get the item (on the floor) */
2822         else
2823         {
2824                 o_ptr = &o_list[0 - item];
2825         }
2826
2827         /* Identify it */
2828         old_known = identify_item(o_ptr);
2829
2830         /* Mark the item as fully known */
2831         o_ptr->ident |= (IDENT_MENTAL);
2832
2833         /* Handle stuff */
2834         handle_stuff();
2835
2836         /* Description */
2837         object_desc(o_name, o_ptr, 0);
2838
2839         /* Describe */
2840         if (item >= INVEN_RARM)
2841         {
2842                 msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(item), o_name, index_to_label(item));
2843         }
2844         else if (item >= 0)
2845         {
2846                 msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
2847         }
2848         else
2849         {
2850                 msg_format(_("床上: %s。", "On the ground: %s."), o_name);
2851         }
2852
2853         /* Describe it fully */
2854         (void)screen_object(o_ptr, 0L);
2855
2856         /* Auto-inscription/destroy */
2857         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
2858
2859         /* Success */
2860         return (TRUE);
2861 }
2862
2863
2864 /*!
2865  * @brief 魔力充填が可能なアイテムかどうか判定する /
2866  * Hook for "get_item()".  Determine if something is rechargable.
2867  * @param o_ptr 判定するアイテムの情報参照ポインタ
2868  * @return 魔力充填が可能ならばTRUEを返す
2869  */
2870 bool item_tester_hook_recharge(object_type *o_ptr)
2871 {
2872         /* Recharge staffs */
2873         if (o_ptr->tval == TV_STAFF) return (TRUE);
2874
2875         /* Recharge wands */
2876         if (o_ptr->tval == TV_WAND) return (TRUE);
2877
2878         /* Hack -- Recharge rods */
2879         if (o_ptr->tval == TV_ROD) return (TRUE);
2880
2881         /* Nope */
2882         return (FALSE);
2883 }
2884
2885
2886 /*!
2887  * @brief 魔力充填処理 /
2888  * Recharge a wand/staff/rod from the pack or on the floor.
2889  * This function has been rewritten in Oangband and ZAngband.
2890  * @param power 充填パワー
2891  * @return ターン消費を要する処理まで進んだらTRUEを返す
2892  *
2893  * Sorcery/Arcane -- Recharge  --> recharge(plev * 4)
2894  * Chaos -- Arcane Binding     --> recharge(90)
2895  *
2896  * Scroll of recharging        --> recharge(130)
2897  * Artifact activation/Thingol --> recharge(130)
2898  *
2899  * It is harder to recharge high level, and highly charged wands,
2900  * staffs, and rods.  The more wands in a stack, the more easily and
2901  * strongly they recharge.  Staffs, however, each get fewer charges if
2902  * stacked.
2903  *
2904  * XXX XXX XXX Beware of "sliding index errors".
2905  */
2906 bool recharge(int power)
2907 {
2908         OBJECT_IDX item;
2909         int lev;
2910         int recharge_strength;
2911         TIME_EFFECT recharge_amount;
2912
2913         object_type *o_ptr;
2914         object_kind *k_ptr;
2915
2916         bool fail = FALSE;
2917         byte fail_type = 1;
2918
2919         cptr q, s;
2920         char o_name[MAX_NLEN];
2921
2922         /* Only accept legal items */
2923         item_tester_hook = item_tester_hook_recharge;
2924
2925         /* Get an item */
2926         q = _("どのアイテムに魔力を充填しますか? ", "Recharge which item? ");
2927         s = _("魔力を充填すべきアイテムがない。", "You have nothing to recharge.");
2928
2929         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE);
2930
2931         /* Get the item (in the pack) */
2932         if (item >= 0)
2933         {
2934                 o_ptr = &inventory[item];
2935         }
2936
2937         /* Get the item (on the floor) */
2938         else
2939         {
2940                 o_ptr = &o_list[0 - item];
2941         }
2942
2943         /* Get the object kind. */
2944         k_ptr = &k_info[o_ptr->k_idx];
2945
2946         /* Extract the object "level" */
2947         lev = k_info[o_ptr->k_idx].level;
2948
2949
2950         /* Recharge a rod */
2951         if (o_ptr->tval == TV_ROD)
2952         {
2953                 /* Extract a recharge strength by comparing object level to power. */
2954                 recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
2955
2956
2957                 /* Back-fire */
2958                 if (one_in_(recharge_strength))
2959                 {
2960                         /* Activate the failure code. */
2961                         fail = TRUE;
2962                 }
2963
2964                 /* Recharge */
2965                 else
2966                 {
2967                         /* Recharge amount */
2968                         recharge_amount = (power * damroll(3, 2));
2969
2970                         /* Recharge by that amount */
2971                         if (o_ptr->timeout > recharge_amount)
2972                                 o_ptr->timeout -= recharge_amount;
2973                         else
2974                                 o_ptr->timeout = 0;
2975                 }
2976         }
2977
2978
2979         /* Recharge wand/staff */
2980         else
2981         {
2982                 /* Extract a recharge strength by comparing object level to power.
2983                  * Divide up a stack of wands' charges to calculate charge penalty.
2984                  */
2985                 if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
2986                         recharge_strength = (100 + power - lev -
2987                         (8 * o_ptr->pval / o_ptr->number)) / 15;
2988
2989                 /* All staffs, unstacked wands. */
2990                 else recharge_strength = (100 + power - lev -
2991                         (8 * o_ptr->pval)) / 15;
2992
2993                 /* Paranoia */
2994                 if (recharge_strength < 0) recharge_strength = 0;
2995
2996                 /* Back-fire */
2997                 if (one_in_(recharge_strength))
2998                 {
2999                         /* Activate the failure code. */
3000                         fail = TRUE;
3001                 }
3002
3003                 /* If the spell didn't backfire, recharge the wand or staff. */
3004                 else
3005                 {
3006                         /* Recharge based on the standard number of charges. */
3007                         recharge_amount = randint1(1 + k_ptr->pval / 2);
3008
3009                         /* Multiple wands in a stack increase recharging somewhat. */
3010                         if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
3011                         {
3012                                 recharge_amount +=
3013                                         (randint1(recharge_amount * (o_ptr->number - 1))) / 2;
3014                                 if (recharge_amount < 1) recharge_amount = 1;
3015                                 if (recharge_amount > 12) recharge_amount = 12;
3016                         }
3017
3018                         /* But each staff in a stack gets fewer additional charges,
3019                          * although always at least one.
3020                          */
3021                         if ((o_ptr->tval == TV_STAFF) && (o_ptr->number > 1))
3022                         {
3023                                 recharge_amount /= (TIME_EFFECT)o_ptr->number;
3024                                 if (recharge_amount < 1) recharge_amount = 1;
3025                         }
3026
3027                         /* Recharge the wand or staff. */
3028                         o_ptr->pval += recharge_amount;
3029
3030
3031                         /* Hack -- we no longer "know" the item */
3032                         o_ptr->ident &= ~(IDENT_KNOWN);
3033
3034                         /* Hack -- we no longer think the item is empty */
3035                         o_ptr->ident &= ~(IDENT_EMPTY);
3036                 }
3037         }
3038
3039
3040         /* Inflict the penalties for failing a recharge. */
3041         if (fail)
3042         {
3043                 /* Artifacts are never destroyed. */
3044                 if (object_is_fixed_artifact(o_ptr))
3045                 {
3046                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
3047                         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
3048
3049                         /* Artifact rods. */
3050                         if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout < 10000))
3051                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
3052
3053                         /* Artifact wands and staffs. */
3054                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
3055                                 o_ptr->pval = 0;
3056                 }
3057                 else
3058                 {
3059                         /* Get the object description */
3060                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3061
3062                         /*** Determine Seriousness of Failure ***/
3063
3064                         /* Mages recharge objects more safely. */
3065                         if (p_ptr->pclass == CLASS_MAGE || p_ptr->pclass == CLASS_HIGH_MAGE || p_ptr->pclass == CLASS_SORCERER || p_ptr->pclass == CLASS_MAGIC_EATER || p_ptr->pclass == CLASS_BLUE_MAGE)
3066                         {
3067                                 /* 10% chance to blow up one rod, otherwise draining. */
3068                                 if (o_ptr->tval == TV_ROD)
3069                                 {
3070                                         if (one_in_(10)) fail_type = 2;
3071                                         else fail_type = 1;
3072                                 }
3073                                 /* 75% chance to blow up one wand, otherwise draining. */
3074                                 else if (o_ptr->tval == TV_WAND)
3075                                 {
3076                                         if (!one_in_(3)) fail_type = 2;
3077                                         else fail_type = 1;
3078                                 }
3079                                 /* 50% chance to blow up one staff, otherwise no effect. */
3080                                 else if (o_ptr->tval == TV_STAFF)
3081                                 {
3082                                         if (one_in_(2)) fail_type = 2;
3083                                         else fail_type = 0;
3084                                 }
3085                         }
3086
3087                         /* All other classes get no special favors. */
3088                         else
3089                         {
3090                                 /* 33% chance to blow up one rod, otherwise draining. */
3091                                 if (o_ptr->tval == TV_ROD)
3092                                 {
3093                                         if (one_in_(3)) fail_type = 2;
3094                                         else fail_type = 1;
3095                                 }
3096                                 /* 20% chance of the entire stack, else destroy one wand. */
3097                                 else if (o_ptr->tval == TV_WAND)
3098                                 {
3099                                         if (one_in_(5)) fail_type = 3;
3100                                         else fail_type = 2;
3101                                 }
3102                                 /* Blow up one staff. */
3103                                 else if (o_ptr->tval == TV_STAFF)
3104                                 {
3105                                         fail_type = 2;
3106                                 }
3107                         }
3108
3109                         /*** Apply draining and destruction. ***/
3110
3111                         /* Drain object or stack of objects. */
3112                         if (fail_type == 1)
3113                         {
3114                                 if (o_ptr->tval == TV_ROD)
3115                                 {
3116                                         msg_print(_("魔力が逆噴射して、ロッドからさらに魔力を吸い取ってしまった!", "The recharge backfires, draining the rod further!"));
3117
3118                                         if (o_ptr->timeout < 10000)
3119                                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
3120                                 }
3121                                 else if (o_ptr->tval == TV_WAND)
3122                                 {
3123                                         msg_format(_("%sは破損を免れたが、魔力が全て失われた。", "You save your %s from destruction, but all charges are lost."), o_name);
3124                                         o_ptr->pval = 0;
3125                                 }
3126                                 /* Staffs aren't drained. */
3127                         }
3128
3129                         /* Destroy an object or one in a stack of objects. */
3130                         if (fail_type == 2)
3131                         {
3132                                 if (o_ptr->number > 1)
3133                                         msg_format(_("乱暴な魔法のために%sが一本壊れた!", "Wild magic consumes one of your %s!"), o_name);
3134                                 else
3135                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
3136
3137                                 /* Reduce rod stack maximum timeout, drain wands. */
3138                                 if (o_ptr->tval == TV_ROD) o_ptr->timeout = (o_ptr->number - 1) * k_ptr->pval;
3139                                 if (o_ptr->tval == TV_WAND) o_ptr->pval = 0;
3140
3141                                 /* Reduce and describe inventory */
3142                                 if (item >= 0)
3143                                 {
3144                                         inven_item_increase(item, -1);
3145                                         inven_item_describe(item);
3146                                         inven_item_optimize(item);
3147                                 }
3148
3149                                 /* Reduce and describe floor item */
3150                                 else
3151                                 {
3152                                         floor_item_increase(0 - item, -1);
3153                                         floor_item_describe(0 - item);
3154                                         floor_item_optimize(0 - item);
3155                                 }
3156                         }
3157
3158                         /* Destroy all members of a stack of objects. */
3159                         if (fail_type == 3)
3160                         {
3161                                 if (o_ptr->number > 1)
3162                                         msg_format(_("乱暴な魔法のために%sが全て壊れた!", "Wild magic consumes all your %s!"), o_name);
3163                                 else
3164                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
3165
3166                                 /* Reduce and describe inventory */
3167                                 if (item >= 0)
3168                                 {
3169                                         inven_item_increase(item, -999);
3170                                         inven_item_describe(item);
3171                                         inven_item_optimize(item);
3172                                 }
3173
3174                                 /* Reduce and describe floor item */
3175                                 else
3176                                 {
3177                                         floor_item_increase(0 - item, -999);
3178                                         floor_item_describe(0 - item);
3179                                         floor_item_optimize(0 - item);
3180                                 }
3181                         }
3182                 }
3183         }
3184
3185         /* Combine / Reorder the pack (later) */
3186         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3187
3188         /* Window stuff */
3189         p_ptr->window |= (PW_INVEN);
3190
3191         /* Something was done */
3192         return (TRUE);
3193 }
3194
3195
3196 /*!
3197  * @brief 武器の祝福処理 /
3198  * Bless a weapon
3199  * @return ターン消費を要する処理を行ったならばTRUEを返す
3200  */
3201 bool bless_weapon(void)
3202 {
3203         OBJECT_IDX item;
3204         object_type     *o_ptr;
3205         BIT_FLAGS flgs[TR_FLAG_SIZE];
3206         char            o_name[MAX_NLEN];
3207         cptr            q, s;
3208
3209         item_tester_no_ryoute = TRUE;
3210
3211         /* Bless only weapons */
3212         item_tester_hook = object_is_weapon;
3213
3214         /* Get an item */
3215         q = _("どのアイテムを祝福しますか?", "Bless which weapon? ");
3216         s = _("祝福できる武器がありません。", "You have weapon to bless.");
3217
3218         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR)))
3219                 return FALSE;
3220
3221         /* Get the item (in the pack) */
3222         if (item >= 0)
3223         {
3224                 o_ptr = &inventory[item];
3225         }
3226
3227         /* Get the item (on the floor) */
3228         else
3229         {
3230                 o_ptr = &o_list[0 - item];
3231         }
3232
3233
3234         /* Description */
3235         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3236
3237         /* Extract the flags */
3238         object_flags(o_ptr, flgs);
3239
3240         if (object_is_cursed(o_ptr))
3241         {
3242                 if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint1(100) < 33)) ||
3243                         have_flag(flgs, TR_ADD_L_CURSE) ||
3244                         have_flag(flgs, TR_ADD_H_CURSE) ||
3245                     (o_ptr->curse_flags & TRC_PERMA_CURSE))
3246                 {
3247 #ifdef JP
3248 msg_format("%sを覆う黒いオーラは祝福を跳ね返した!",
3249     o_name);
3250 #else
3251                         msg_format("The black aura on %s %s disrupts the blessing!",
3252                             ((item >= 0) ? "your" : "the"), o_name);
3253 #endif
3254
3255                         return TRUE;
3256                 }
3257
3258 #ifdef JP
3259 msg_format("%s から邪悪なオーラが消えた。",
3260     o_name);
3261 #else
3262                 msg_format("A malignant aura leaves %s %s.",
3263                     ((item >= 0) ? "your" : "the"), o_name);
3264 #endif
3265
3266
3267                 /* Uncurse it */
3268                 o_ptr->curse_flags = 0L;
3269
3270                 /* Hack -- Assume felt */
3271                 o_ptr->ident |= (IDENT_SENSE);
3272
3273                 /* Take note */
3274                 o_ptr->feeling = FEEL_NONE;
3275
3276                 /* Recalculate the bonuses */
3277                 p_ptr->update |= (PU_BONUS);
3278
3279                 /* Window stuff */
3280                 p_ptr->window |= (PW_EQUIP);
3281         }
3282
3283         /*
3284          * Next, we try to bless it. Artifacts have a 1/3 chance of
3285          * being blessed, otherwise, the operation simply disenchants
3286          * them, godly power negating the magic. Ok, the explanation
3287          * is silly, but otherwise priests would always bless every
3288          * artifact weapon they find. Ego weapons and normal weapons
3289          * can be blessed automatically.
3290          */
3291         if (have_flag(flgs, TR_BLESSED))
3292         {
3293 #ifdef JP
3294 msg_format("%s は既に祝福されている。",
3295     o_name    );
3296 #else
3297                 msg_format("%s %s %s blessed already.",
3298                     ((item >= 0) ? "Your" : "The"), o_name,
3299                     ((o_ptr->number > 1) ? "were" : "was"));
3300 #endif
3301
3302                 return TRUE;
3303         }
3304
3305         if (!(object_is_artifact(o_ptr) || object_is_ego(o_ptr)) || one_in_(3))
3306         {
3307                 /* Describe */
3308 #ifdef JP
3309 msg_format("%sは輝いた!",
3310      o_name);
3311 #else
3312                 msg_format("%s %s shine%s!",
3313                     ((item >= 0) ? "Your" : "The"), o_name,
3314                     ((o_ptr->number > 1) ? "" : "s"));
3315 #endif
3316
3317                 add_flag(o_ptr->art_flags, TR_BLESSED);
3318                 o_ptr->discount = 99;
3319         }
3320         else
3321         {
3322                 bool dis_happened = FALSE;
3323                 msg_print(_("その武器は祝福を嫌っている!", "The weapon resists your blessing!"));
3324
3325                 /* Disenchant tohit */
3326                 if (o_ptr->to_h > 0)
3327                 {
3328                         o_ptr->to_h--;
3329                         dis_happened = TRUE;
3330                 }
3331
3332                 if ((o_ptr->to_h > 5) && (randint0(100) < 33)) o_ptr->to_h--;
3333
3334                 /* Disenchant todam */
3335                 if (o_ptr->to_d > 0)
3336                 {
3337                         o_ptr->to_d--;
3338                         dis_happened = TRUE;
3339                 }
3340
3341                 if ((o_ptr->to_d > 5) && (randint0(100) < 33)) o_ptr->to_d--;
3342
3343                 /* Disenchant toac */
3344                 if (o_ptr->to_a > 0)
3345                 {
3346                         o_ptr->to_a--;
3347                         dis_happened = TRUE;
3348                 }
3349
3350                 if ((o_ptr->to_a > 5) && (randint0(100) < 33)) o_ptr->to_a--;
3351
3352                 if (dis_happened)
3353                 {
3354                         msg_print(_("周囲が凡庸な雰囲気で満ちた...", "There is a static feeling in the air..."));
3355
3356 #ifdef JP
3357 msg_format("%s は劣化した!",
3358      o_name    );
3359 #else
3360                         msg_format("%s %s %s disenchanted!",
3361                             ((item >= 0) ? "Your" : "The"), o_name,
3362                             ((o_ptr->number > 1) ? "were" : "was"));
3363 #endif
3364
3365                 }
3366         }
3367
3368         /* Recalculate bonuses */
3369         p_ptr->update |= (PU_BONUS);
3370
3371         /* Window stuff */
3372         p_ptr->window |= (PW_EQUIP | PW_PLAYER);
3373
3374         calc_android_exp();
3375
3376         return TRUE;
3377 }
3378
3379
3380 /*!
3381  * @brief 盾磨き処理 /
3382  * pulish shield
3383  * @return ターン消費を要する処理を行ったならばTRUEを返す
3384  */
3385 bool pulish_shield(void)
3386 {
3387         OBJECT_IDX item;
3388         object_type     *o_ptr;
3389         u32b flgs[TR_FLAG_SIZE];
3390         char            o_name[MAX_NLEN];
3391         cptr            q, s;
3392
3393         item_tester_no_ryoute = TRUE;
3394         /* Assume enchant weapon */
3395         item_tester_tval = TV_SHIELD;
3396
3397         /* Get an item */
3398         q = _("どの盾を磨きますか?", "Pulish which weapon? ");
3399         s = _("磨く盾がありません。", "You have weapon to pulish.");
3400
3401         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR)))
3402                 return FALSE;
3403
3404         /* Get the item (in the pack) */
3405         if (item >= 0)
3406         {
3407                 o_ptr = &inventory[item];
3408         }
3409
3410         /* Get the item (on the floor) */
3411         else
3412         {
3413                 o_ptr = &o_list[0 - item];
3414         }
3415
3416
3417         /* Description */
3418         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3419
3420         /* Extract the flags */
3421         object_flags(o_ptr, flgs);
3422
3423         if (o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) &&
3424             !object_is_cursed(o_ptr) && (o_ptr->sval != SV_MIRROR_SHIELD))
3425         {
3426 #ifdef JP
3427 msg_format("%sは輝いた!", o_name);
3428 #else
3429                 msg_format("%s %s shine%s!",
3430                     ((item >= 0) ? "Your" : "The"), o_name,
3431                     ((o_ptr->number > 1) ? "" : "s"));
3432 #endif
3433                 o_ptr->name2 = EGO_REFLECTION;
3434                 enchant(o_ptr, randint0(3) + 4, ENCH_TOAC);
3435
3436                 o_ptr->discount = 99;
3437                 chg_virtue(V_ENCHANT, 2);
3438
3439                 return TRUE;
3440         }
3441         else
3442         {
3443                 if (flush_failure) flush();
3444
3445                 msg_print(_("失敗した。", "Failed."));
3446                 chg_virtue(V_ENCHANT, -2);
3447         }
3448         calc_android_exp();
3449
3450         return FALSE;
3451 }
3452
3453
3454 /*!
3455  * @brief 薬の破損効果処理 /
3456  * Potions "smash open" and cause an area effect when
3457  * @param who 薬破損の主体ID(プレイヤー所持アイテムが壊れた場合0、床上のアイテムの場合モンスターID)
3458  * @param y 破壊時のY座標
3459  * @param x 破壊時のX座標
3460  * @param k_idx 破損した薬のアイテムID
3461  * @return 薬を浴びたモンスターが起こるならばTRUEを返す
3462  * @details
3463  * <pre>
3464  * (1) they are shattered while in the player's inventory,
3465  * due to cold (etc) attacks;
3466  * (2) they are thrown at a monster, or obstacle;
3467  * (3) they are shattered by a "cold ball" or other such spell
3468  * while lying on the floor.
3469  *
3470  * Arguments:
3471  *    who   ---  who caused the potion to shatter (0=player)
3472  *          potions that smash on the floor are assumed to
3473  *          be caused by no-one (who = 1), as are those that
3474  *          shatter inside the player inventory.
3475  *          (Not anymore -- I changed this; TY)
3476  *    y, x  --- coordinates of the potion (or player if
3477  *          the potion was in her inventory);
3478  *    o_ptr --- pointer to the potion object.
3479  * </pre>
3480  */
3481 bool potion_smash_effect(MONSTER_IDX who, POSITION y, POSITION x, KIND_OBJECT_IDX k_idx)
3482 {
3483         int     radius = 2;
3484         int     dt = 0;
3485         int     dam = 0;
3486         bool    angry = FALSE;
3487
3488         object_kind *k_ptr = &k_info[k_idx];
3489
3490         switch (k_ptr->sval)
3491         {
3492                 case SV_POTION_SALT_WATER:
3493                 case SV_POTION_SLIME_MOLD:
3494                 case SV_POTION_LOSE_MEMORIES:
3495                 case SV_POTION_DEC_STR:
3496                 case SV_POTION_DEC_INT:
3497                 case SV_POTION_DEC_WIS:
3498                 case SV_POTION_DEC_DEX:
3499                 case SV_POTION_DEC_CON:
3500                 case SV_POTION_DEC_CHR:
3501                 case SV_POTION_WATER:   /* perhaps a 'water' attack? */
3502                 case SV_POTION_APPLE_JUICE:
3503                         return TRUE;
3504
3505                 case SV_POTION_INFRAVISION:
3506                 case SV_POTION_DETECT_INVIS:
3507                 case SV_POTION_SLOW_POISON:
3508                 case SV_POTION_CURE_POISON:
3509                 case SV_POTION_BOLDNESS:
3510                 case SV_POTION_RESIST_HEAT:
3511                 case SV_POTION_RESIST_COLD:
3512                 case SV_POTION_HEROISM:
3513                 case SV_POTION_BESERK_STRENGTH:
3514                 case SV_POTION_RES_STR:
3515                 case SV_POTION_RES_INT:
3516                 case SV_POTION_RES_WIS:
3517                 case SV_POTION_RES_DEX:
3518                 case SV_POTION_RES_CON:
3519                 case SV_POTION_RES_CHR:
3520                 case SV_POTION_INC_STR:
3521                 case SV_POTION_INC_INT:
3522                 case SV_POTION_INC_WIS:
3523                 case SV_POTION_INC_DEX:
3524                 case SV_POTION_INC_CON:
3525                 case SV_POTION_INC_CHR:
3526                 case SV_POTION_AUGMENTATION:
3527                 case SV_POTION_ENLIGHTENMENT:
3528                 case SV_POTION_STAR_ENLIGHTENMENT:
3529                 case SV_POTION_SELF_KNOWLEDGE:
3530                 case SV_POTION_EXPERIENCE:
3531                 case SV_POTION_RESISTANCE:
3532                 case SV_POTION_INVULNERABILITY:
3533                 case SV_POTION_NEW_LIFE:
3534                         /* All of the above potions have no effect when shattered */
3535                         return FALSE;
3536                 case SV_POTION_SLOWNESS:
3537                         dt = GF_OLD_SLOW;
3538                         dam = 5;
3539                         angry = TRUE;
3540                         break;
3541                 case SV_POTION_POISON:
3542                         dt = GF_POIS;
3543                         dam = 3;
3544                         angry = TRUE;
3545                         break;
3546                 case SV_POTION_BLINDNESS:
3547                         dt = GF_DARK;
3548                         angry = TRUE;
3549                         break;
3550                 case SV_POTION_CONFUSION: /* Booze */
3551                         dt = GF_OLD_CONF;
3552                         angry = TRUE;
3553                         break;
3554                 case SV_POTION_SLEEP:
3555                         dt = GF_OLD_SLEEP;
3556                         angry = TRUE;
3557                         break;
3558                 case SV_POTION_RUINATION:
3559                 case SV_POTION_DETONATIONS:
3560                         dt = GF_SHARDS;
3561                         dam = damroll(25, 25);
3562                         angry = TRUE;
3563                         break;
3564                 case SV_POTION_DEATH:
3565                         dt = GF_DEATH_RAY;    /* !! */
3566                         dam = k_ptr->level * 10;
3567                         angry = TRUE;
3568                         radius = 1;
3569                         break;
3570                 case SV_POTION_SPEED:
3571                         dt = GF_OLD_SPEED;
3572                         break;
3573                 case SV_POTION_CURE_LIGHT:
3574                         dt = GF_OLD_HEAL;
3575                         dam = damroll(2, 3);
3576                         break;
3577                 case SV_POTION_CURE_SERIOUS:
3578                         dt = GF_OLD_HEAL;
3579                         dam = damroll(4, 3);
3580                         break;
3581                 case SV_POTION_CURE_CRITICAL:
3582                 case SV_POTION_CURING:
3583                         dt = GF_OLD_HEAL;
3584                         dam = damroll(6, 3);
3585                         break;
3586                 case SV_POTION_HEALING:
3587                         dt = GF_OLD_HEAL;
3588                         dam = damroll(10, 10);
3589                         break;
3590                 case SV_POTION_RESTORE_EXP:
3591                         dt = GF_STAR_HEAL;
3592                         dam = 0;
3593                         radius = 1;
3594                         break;
3595                 case SV_POTION_LIFE:
3596                         dt = GF_STAR_HEAL;
3597                         dam = damroll(50, 50);
3598                         radius = 1;
3599                         break;
3600                 case SV_POTION_STAR_HEALING:
3601                         dt = GF_OLD_HEAL;
3602                         dam = damroll(50, 50);
3603                         radius = 1;
3604                         break;
3605                 case SV_POTION_RESTORE_MANA:   /* MANA */
3606                         dt = GF_MANA;
3607                         dam = damroll(10, 10);
3608                         radius = 1;
3609                         break;
3610                 default:
3611                         /* Do nothing */  ;
3612         }
3613
3614         (void)project(who, radius, y, x, dam, dt,
3615             (PROJECT_JUMP | PROJECT_ITEM | PROJECT_KILL), -1);
3616
3617         /* XXX  those potions that explode need to become "known" */
3618         return angry;
3619 }
3620
3621
3622 /*!
3623  * @brief プレイヤーの全既知呪文を表示する /
3624  * Hack -- Display all known spells in a window
3625  * return なし
3626  * @details
3627  * XXX XXX XXX Need to analyze size of the window.
3628  * XXX XXX XXX Need more color coding.
3629  */
3630 void display_spell_list(void)
3631 {
3632         int             i, j;
3633         int             y, x;
3634         int             m[9];
3635         const magic_type *s_ptr;
3636         char            name[80];
3637         char            out_val[160];
3638
3639
3640         /* Erase window */
3641         clear_from(0);
3642
3643         /* They have too many spells to list */
3644         if (p_ptr->pclass == CLASS_SORCERER) return;
3645         if (p_ptr->pclass == CLASS_RED_MAGE) return;
3646
3647         /* Snipers */
3648         if (p_ptr->pclass == CLASS_SNIPER)
3649         {
3650                 display_snipe_list();
3651                 return;
3652         }
3653
3654         /* mind.c type classes */
3655         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
3656             (p_ptr->pclass == CLASS_BERSERKER) ||
3657             (p_ptr->pclass == CLASS_NINJA) ||
3658             (p_ptr->pclass == CLASS_MIRROR_MASTER) ||
3659             (p_ptr->pclass == CLASS_FORCETRAINER))
3660         {
3661                 int             minfail = 0;
3662                 int             plev = p_ptr->lev;
3663                 int             chance = 0;
3664                 mind_type       spell;
3665                 char            comment[80];
3666                 char            psi_desc[80];
3667                 int             use_mind;
3668                 bool use_hp = FALSE;
3669
3670                 y = 1;
3671                 x = 1;
3672
3673                 /* Display a list of spells */
3674                 prt("", y, x);
3675                 put_str(_("名前", "Name"), y, x + 5);
3676                 put_str(_("Lv   MP 失率 効果", "Lv Mana Fail Info"), y, x + 35);
3677
3678                 switch(p_ptr->pclass)
3679                 {
3680                 case CLASS_MINDCRAFTER: use_mind = MIND_MINDCRAFTER;break;
3681                 case CLASS_FORCETRAINER:          use_mind = MIND_KI;break;
3682                 case CLASS_BERSERKER: use_mind = MIND_BERSERKER; use_hp = TRUE; break;
3683                 case CLASS_MIRROR_MASTER: use_mind = MIND_MIRROR_MASTER; break;
3684                 case CLASS_NINJA: use_mind = MIND_NINJUTSU; use_hp = TRUE; break;
3685                 default:                use_mind = 0;break;
3686                 }
3687
3688                 /* Dump the spells */
3689                 for (i = 0; i < MAX_MIND_POWERS; i++)
3690                 {
3691                         byte a = TERM_WHITE;
3692
3693                         /* Access the available spell */
3694                         spell = mind_powers[use_mind].info[i];
3695                         if (spell.min_lev > plev) break;
3696
3697                         /* Get the failure rate */
3698                         chance = spell.fail;
3699
3700                         /* Reduce failure rate by "effective" level adjustment */
3701                         chance -= 3 * (p_ptr->lev - spell.min_lev);
3702
3703                         /* Reduce failure rate by INT/WIS adjustment */
3704                         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
3705
3706                         if (!use_hp)
3707                         {
3708                                 /* Not enough mana to cast */
3709                                 if (spell.mana_cost > p_ptr->csp)
3710                                 {
3711                                         chance += 5 * (spell.mana_cost - p_ptr->csp);
3712                                         a = TERM_ORANGE;
3713                                 }
3714                         }
3715                         else
3716                         {
3717                                 /* Not enough hp to cast */
3718                                 if (spell.mana_cost > p_ptr->chp)
3719                                 {
3720                                         chance += 100;
3721                                         a = TERM_RED;
3722                                 }
3723                         }
3724
3725                         /* Extract the minimum failure rate */
3726                         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
3727
3728                         /* Minimum failure rate */
3729                         if (chance < minfail) chance = minfail;
3730
3731                         /* Stunning makes spells harder */
3732                         if (p_ptr->stun > 50) chance += 25;
3733                         else if (p_ptr->stun) chance += 15;
3734
3735                         /* Always a 5 percent chance of working */
3736                         if (chance > 95) chance = 95;
3737
3738                         /* Get info */
3739                         mindcraft_info(comment, use_mind, i);
3740
3741                         /* Dump the spell */
3742                         sprintf(psi_desc, "  %c) %-30s%2d %4d %3d%%%s",
3743                             I2A(i), spell.name,
3744                             spell.min_lev, spell.mana_cost, chance, comment);
3745
3746                         Term_putstr(x, y + i + 1, -1, a, psi_desc);
3747                 }
3748                 return;
3749         }
3750
3751         /* Cannot read spellbooks */
3752         if (REALM_NONE == p_ptr->realm1) return;
3753
3754         /* Normal spellcaster with books */
3755
3756         /* Scan books */
3757         for (j = 0; j < ((p_ptr->realm2 > REALM_NONE) ? 2 : 1); j++)
3758         {
3759                 int n = 0;
3760
3761                 /* Reset vertical */
3762                 m[j] = 0;
3763
3764                 /* Vertical location */
3765                 y = (j < 3) ? 0 : (m[j - 3] + 2);
3766
3767                 /* Horizontal location */
3768                 x = 27 * (j % 3);
3769
3770                 /* Scan spells */
3771                 for (i = 0; i < 32; i++)
3772                 {
3773                         byte a = TERM_WHITE;
3774
3775                         /* Access the spell */
3776                         if (!is_magic((j < 1) ? p_ptr->realm1 : p_ptr->realm2))
3777                         {
3778                                 s_ptr = &technic_info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - MIN_TECHNIC][i % 32];
3779                         }
3780                         else
3781                         {
3782                                 s_ptr = &mp_ptr->info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - 1][i % 32];
3783                         }
3784
3785                         strcpy(name, do_spell((j < 1) ? p_ptr->realm1 : p_ptr->realm2, i % 32, SPELL_NAME));
3786
3787                         /* Illegible */
3788                         if (s_ptr->slevel >= 99)
3789                         {
3790                                 /* Illegible */
3791                                 strcpy(name, _("(判読不能)", "(illegible)"));
3792
3793                                 /* Unusable */
3794                                 a = TERM_L_DARK;
3795                         }
3796
3797                         /* Forgotten */
3798                         else if ((j < 1) ?
3799                                 ((p_ptr->spell_forgotten1 & (1L << i))) :
3800                                 ((p_ptr->spell_forgotten2 & (1L << (i % 32)))))
3801                         {
3802                                 /* Forgotten */
3803                                 a = TERM_ORANGE;
3804                         }
3805
3806                         /* Unknown */
3807                         else if (!((j < 1) ?
3808                                 (p_ptr->spell_learned1 & (1L << i)) :
3809                                 (p_ptr->spell_learned2 & (1L << (i % 32)))))
3810                         {
3811                                 /* Unknown */
3812                                 a = TERM_RED;
3813                         }
3814
3815                         /* Untried */
3816                         else if (!((j < 1) ?
3817                                 (p_ptr->spell_worked1 & (1L << i)) :
3818                                 (p_ptr->spell_worked2 & (1L << (i % 32)))))
3819                         {
3820                                 /* Untried */
3821                                 a = TERM_YELLOW;
3822                         }
3823
3824                         /* Dump the spell --(-- */
3825                         sprintf(out_val, "%c/%c) %-20.20s",
3826                                 I2A(n / 8), I2A(n % 8), name);
3827
3828                         /* Track maximum */
3829                         m[j] = y + n;
3830
3831                         /* Dump onto the window */
3832                         Term_putstr(x, m[j], -1, a, out_val);
3833
3834                         /* Next */
3835                         n++;
3836                 }
3837         }
3838 }
3839
3840
3841 /*!
3842  * @brief 呪文の経験値を返す /
3843  * Returns experience of a spell
3844  * @param spell 呪文ID
3845  * @param use_realm 魔法領域
3846  * @return 経験値
3847  */
3848 s16b experience_of_spell(int spell, int use_realm)
3849 {
3850         if (p_ptr->pclass == CLASS_SORCERER) return SPELL_EXP_MASTER;
3851         else if (p_ptr->pclass == CLASS_RED_MAGE) return SPELL_EXP_SKILLED;
3852         else if (use_realm == p_ptr->realm1) return p_ptr->spell_exp[spell];
3853         else if (use_realm == p_ptr->realm2) return p_ptr->spell_exp[spell + 32];
3854         else return 0;
3855 }
3856
3857
3858 /*!
3859  * @brief 呪文の消費MPを返す /
3860  * Modify mana consumption rate using spell exp and p_ptr->dec_mana
3861  * @param need_mana 基本消費MP
3862  * @param spell 呪文ID
3863  * @param realm 魔法領域
3864  * @return 消費MP
3865  */
3866 int mod_need_mana(int need_mana, int spell, int realm)
3867 {
3868 #define MANA_CONST   2400
3869 #define MANA_DIV        4
3870 #define DEC_MANA_DIV    3
3871
3872         /* Realm magic */
3873         if ((realm > REALM_NONE) && (realm <= MAX_REALM))
3874         {
3875                 /*
3876                  * need_mana defaults if spell exp equals SPELL_EXP_EXPERT and !p_ptr->dec_mana.
3877                  * MANA_CONST is used to calculate need_mana effected from spell proficiency.
3878                  */
3879                 need_mana = need_mana * (MANA_CONST + SPELL_EXP_EXPERT - experience_of_spell(spell, realm)) + (MANA_CONST - 1);
3880                 need_mana *= p_ptr->dec_mana ? DEC_MANA_DIV : MANA_DIV;
3881                 need_mana /= MANA_CONST * MANA_DIV;
3882                 if (need_mana < 1) need_mana = 1;
3883         }
3884
3885         /* Non-realm magic */
3886         else
3887         {
3888                 if (p_ptr->dec_mana) need_mana = (need_mana + 1) * DEC_MANA_DIV / MANA_DIV;
3889         }
3890
3891 #undef DEC_MANA_DIV
3892 #undef MANA_DIV
3893 #undef MANA_CONST
3894
3895         return need_mana;
3896 }
3897
3898
3899 /*!
3900  * @brief 呪文の失敗率修正処理1(呪い、消費魔力減少、呪文簡易化) /
3901  * Modify spell fail rate
3902  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
3903  * @param chance 修正前失敗率
3904  * @return 失敗率(%)
3905  * @todo 統合を検討
3906  */
3907 PERCENTAGE mod_spell_chance_1(PERCENTAGE chance)
3908 {
3909         chance += p_ptr->to_m_chance;
3910
3911         if (p_ptr->heavy_spell) chance += 20;
3912
3913         if (p_ptr->dec_mana && p_ptr->easy_spell) chance -= 4;
3914         else if (p_ptr->easy_spell) chance -= 3;
3915         else if (p_ptr->dec_mana) chance -= 2;
3916
3917         return chance;
3918 }
3919
3920
3921 /*!
3922  * @brief 呪文の失敗率修正処理2(消費魔力減少、呪い、負値修正) /
3923  * Modify spell fail rate
3924  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
3925  * @param chance 修正前失敗率
3926  * @return 失敗率(%)
3927  * Modify spell fail rate (as "suffix" process)
3928  * Using p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
3929  * Note: variable "chance" cannot be negative.
3930  * @todo 統合を検討
3931  */
3932 PERCENTAGE mod_spell_chance_2(PERCENTAGE chance)
3933 {
3934         if (p_ptr->dec_mana) chance--;
3935
3936         if (p_ptr->heavy_spell) chance += 5;
3937
3938         return MAX(chance, 0);
3939 }
3940
3941
3942 /*!
3943  * @brief 呪文の失敗率計算メインルーチン /
3944  * Returns spell chance of failure for spell -RAK-
3945  * @param spell 呪文ID
3946  * @param use_realm 魔法領域ID
3947  * @return 失敗率(%)
3948  */
3949 PERCENTAGE spell_chance(SPELL_IDX spell, REALM_IDX use_realm)
3950 {
3951         PERCENTAGE chance, minfail;
3952         const magic_type *s_ptr;
3953         MANA_POINT need_mana;
3954         PERCENTAGE penalty = (mp_ptr->spell_stat == A_WIS) ? 10 : 4;
3955
3956
3957         /* Paranoia -- must be literate */
3958         if (!mp_ptr->spell_book) return (100);
3959
3960         if (use_realm == REALM_HISSATSU) return 0;
3961
3962         /* Access the spell */
3963         if (!is_magic(use_realm))
3964         {
3965                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
3966         }
3967         else
3968         {
3969                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
3970         }
3971
3972         /* Extract the base spell failure rate */
3973         chance = s_ptr->sfail;
3974
3975         /* Reduce failure rate by "effective" level adjustment */
3976         chance -= 3 * (p_ptr->lev - s_ptr->slevel);
3977
3978         /* Reduce failure rate by INT/WIS adjustment */
3979         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
3980
3981         if (p_ptr->riding)
3982                 chance += (MAX(r_info[m_list[p_ptr->riding].r_idx].level - p_ptr->skill_exp[GINOU_RIDING] / 100 - 10, 0));
3983
3984         /* Extract mana consumption rate */
3985         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
3986
3987         /* Not enough mana to cast */
3988         if (need_mana > p_ptr->csp)
3989         {
3990                 chance += 5 * (need_mana - p_ptr->csp);
3991         }
3992
3993         if ((use_realm != p_ptr->realm1) && ((p_ptr->pclass == CLASS_MAGE) || (p_ptr->pclass == CLASS_PRIEST))) chance += 5;
3994
3995         /* Extract the minimum failure rate */
3996         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
3997
3998         /*
3999          * Non mage/priest characters never get too good
4000          * (added high mage, mindcrafter)
4001          */
4002         if (mp_ptr->spell_xtra & MAGIC_FAIL_5PERCENT)
4003         {
4004                 if (minfail < 5) minfail = 5;
4005         }
4006
4007         /* Hack -- Priest prayer penalty for "edged" weapons  -DGK */
4008         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[0]) chance += 25;
4009         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[1]) chance += 25;
4010
4011         chance = mod_spell_chance_1(chance);
4012
4013         /* Goodness or evilness gives a penalty to failure rate */
4014         switch (use_realm)
4015         {
4016         case REALM_NATURE:
4017                 if ((p_ptr->align > 50) || (p_ptr->align < -50)) chance += penalty;
4018                 break;
4019         case REALM_LIFE: case REALM_CRUSADE:
4020                 if (p_ptr->align < -20) chance += penalty;
4021                 break;
4022         case REALM_DEATH: case REALM_DAEMON: case REALM_HEX:
4023                 if (p_ptr->align > 20) chance += penalty;
4024                 break;
4025         }
4026
4027         /* Minimum failure rate */
4028         if (chance < minfail) chance = minfail;
4029
4030         /* Stunning makes spells harder */
4031         if (p_ptr->stun > 50) chance += 25;
4032         else if (p_ptr->stun) chance += 15;
4033
4034         /* Always a 5 percent chance of working */
4035         if (chance > 95) chance = 95;
4036
4037         if ((use_realm == p_ptr->realm1) || (use_realm == p_ptr->realm2)
4038             || (p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4039         {
4040                 s16b exp = experience_of_spell(spell, use_realm);
4041                 if (exp >= SPELL_EXP_EXPERT) chance--;
4042                 if (exp >= SPELL_EXP_MASTER) chance--;
4043         }
4044
4045         /* Return the chance */
4046         return mod_spell_chance_2(chance);
4047 }
4048
4049
4050 /*!
4051  * @brief 魔法が利用可能かどうかを返す /
4052  * Determine if a spell is "okay" for the player to cast or study
4053  * The spell must be legible, not forgotten, and also, to cast,
4054  * it must be known, and to study, it must not be known.
4055  * @param spell 呪文ID
4056  * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
4057  * @param study_pray 祈りの学習判定目的ならばTRUE
4058  * @param use_realm 魔法領域ID
4059  * @return 失敗率(%)
4060  */
4061 bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
4062 {
4063         const magic_type *s_ptr;
4064
4065         /* Access the spell */
4066         if (!is_magic(use_realm))
4067         {
4068                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
4069         }
4070         else
4071         {
4072                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
4073         }
4074
4075         /* Spell is illegal */
4076         if (s_ptr->slevel > p_ptr->lev) return (FALSE);
4077
4078         /* Spell is forgotten */
4079         if ((use_realm == p_ptr->realm2) ?
4080             (p_ptr->spell_forgotten2 & (1L << spell)) :
4081             (p_ptr->spell_forgotten1 & (1L << spell)))
4082         {
4083                 /* Never okay */
4084                 return (FALSE);
4085         }
4086
4087         if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
4088         if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
4089
4090         /* Spell is learned */
4091         if ((use_realm == p_ptr->realm2) ?
4092             (p_ptr->spell_learned2 & (1L << spell)) :
4093             (p_ptr->spell_learned1 & (1L << spell)))
4094         {
4095                 /* Always true */
4096                 return (!study_pray);
4097         }
4098
4099         /* Okay to study, not to cast */
4100         return (!learned);
4101 }
4102
4103
4104
4105 /*!
4106  * @brief 呪文情報の表示処理 /
4107  * Print a list of spells (for browsing or casting or viewing)
4108  * @param target_spell 呪文ID             
4109  * @param spells 表示するスペルID配列の参照ポインタ
4110  * @param num 表示するスペルの数(spellsの要素数)
4111  * @param y 表示メッセージ左上Y座標
4112  * @param x 表示メッセージ左上X座標
4113  * @param use_realm 魔法領域ID
4114  * @return なし
4115  */
4116 void print_spells(SPELL_IDX target_spell, SPELL_IDX *spells, int num, TERM_POSITION y, TERM_POSITION x, REALM_IDX use_realm)
4117 {
4118         int             i, spell, exp_level, increment = 64;
4119         const magic_type *s_ptr;
4120         cptr            comment;
4121         char            info[80];
4122         char            out_val[160];
4123         byte            line_attr;
4124         int             need_mana;
4125         char            ryakuji[5];
4126         char            buf[256];
4127         bool max = FALSE;
4128
4129
4130         if (((use_realm <= REALM_NONE) || (use_realm > MAX_REALM)) && p_ptr->wizard)
4131         msg_print(_("警告! print_spell が領域なしに呼ばれた", "Warning! print_spells called with null realm"));
4132
4133         /* Title the list */
4134         prt("", y, x);
4135         if (use_realm == REALM_HISSATSU)
4136                 strcpy(buf,_("  Lv   MP", "  Lv   SP"));
4137         else
4138                 strcpy(buf,_("熟練度 Lv   MP 失率 効果", "Profic Lv   SP Fail Effect"));
4139
4140         put_str(_("名前", "Name"), y, x + 5);
4141         put_str(buf, y, x + 29);
4142
4143         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) increment = 0;
4144         else if (use_realm == p_ptr->realm1) increment = 0;
4145         else if (use_realm == p_ptr->realm2) increment = 32;
4146
4147         /* Dump the spells */
4148         for (i = 0; i < num; i++)
4149         {
4150                 /* Access the spell */
4151                 spell = spells[i];
4152
4153                 /* Access the spell */
4154                 if (!is_magic(use_realm))
4155                 {
4156                         s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
4157                 }
4158                 else
4159                 {
4160                         s_ptr = &mp_ptr->info[use_realm - 1][spell];
4161                 }
4162
4163                 if (use_realm == REALM_HISSATSU)
4164                         need_mana = s_ptr->smana;
4165                 else
4166                 {
4167                         s16b exp = experience_of_spell(spell, use_realm);
4168
4169                         /* Extract mana consumption rate */
4170                         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
4171
4172                         if ((increment == 64) || (s_ptr->slevel >= 99)) exp_level = EXP_LEVEL_UNSKILLED;
4173                         else exp_level = spell_exp_level(exp);
4174
4175                         max = FALSE;
4176                         if (!increment && (exp_level == EXP_LEVEL_MASTER)) max = TRUE;
4177                         else if ((increment == 32) && (exp_level >= EXP_LEVEL_EXPERT)) max = TRUE;
4178                         else if (s_ptr->slevel >= 99) max = TRUE;
4179                         else if ((p_ptr->pclass == CLASS_RED_MAGE) && (exp_level >= EXP_LEVEL_SKILLED)) max = TRUE;
4180
4181                         strncpy(ryakuji, exp_level_str[exp_level], 4);
4182                         ryakuji[3] = ']';
4183                         ryakuji[4] = '\0';
4184                 }
4185
4186                 if (use_menu && target_spell)
4187                 {
4188                         if (i == (target_spell-1))
4189                                 strcpy(out_val, _("  》 ", "  >  "));
4190                         else
4191                                 strcpy(out_val, "     ");
4192                 }
4193                 else sprintf(out_val, "  %c) ", I2A(i));
4194                 /* Skip illegible spells */
4195                 if (s_ptr->slevel >= 99)
4196                 {
4197                         strcat(out_val, format("%-30s", _("(判読不能)", "(illegible)")));
4198                         c_prt(TERM_L_DARK, out_val, y + i + 1, x);
4199                         continue;
4200                 }
4201
4202                 /* XXX XXX Could label spells above the players level */
4203
4204                 /* Get extra info */
4205                 strcpy(info, do_spell(use_realm, spell, SPELL_INFO));
4206
4207                 /* Use that info */
4208                 comment = info;
4209
4210                 /* Assume spell is known and tried */
4211                 line_attr = TERM_WHITE;
4212
4213                 /* Analyze the spell */
4214                 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4215                 {
4216                         if (s_ptr->slevel > p_ptr->max_plv)
4217                         {
4218                                 comment = _("未知", "unknown");
4219                                 line_attr = TERM_L_BLUE;
4220                         }
4221                         else if (s_ptr->slevel > p_ptr->lev)
4222                         {
4223                                 comment = _("忘却", "forgotten");
4224                                 line_attr = TERM_YELLOW;
4225                         }
4226                 }
4227                 else if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2))
4228                 {
4229                         comment = _("未知", "unknown");
4230                         line_attr = TERM_L_BLUE;
4231                 }
4232                 else if ((use_realm == p_ptr->realm1) ?
4233                     ((p_ptr->spell_forgotten1 & (1L << spell))) :
4234                     ((p_ptr->spell_forgotten2 & (1L << spell))))
4235                 {
4236                         comment = _("忘却", "forgotten");
4237                         line_attr = TERM_YELLOW;
4238                 }
4239                 else if (!((use_realm == p_ptr->realm1) ?
4240                     (p_ptr->spell_learned1 & (1L << spell)) :
4241                     (p_ptr->spell_learned2 & (1L << spell))))
4242                 {
4243                         comment = _("未知", "unknown");
4244                         line_attr = TERM_L_BLUE;
4245                 }
4246                 else if (!((use_realm == p_ptr->realm1) ?
4247                     (p_ptr->spell_worked1 & (1L << spell)) :
4248                     (p_ptr->spell_worked2 & (1L << spell))))
4249                 {
4250                         comment = _("未経験", "untried");
4251                         line_attr = TERM_L_GREEN;
4252                 }
4253
4254                 /* Dump the spell --(-- */
4255                 if (use_realm == REALM_HISSATSU)
4256                 {
4257                         strcat(out_val, format("%-25s %2d %4d",
4258                             do_spell(use_realm, spell, SPELL_NAME), /* realm, spell */
4259                             s_ptr->slevel, need_mana));
4260                 }
4261                 else
4262                 {
4263                         strcat(out_val, format("%-25s%c%-4s %2d %4d %3d%% %s",
4264                             do_spell(use_realm, spell, SPELL_NAME), /* realm, spell */
4265                             (max ? '!' : ' '), ryakuji,
4266                             s_ptr->slevel, need_mana, spell_chance(spell, use_realm), comment));
4267                 }
4268                 c_prt(line_attr, out_val, y + i + 1, x);
4269         }
4270
4271         /* Clear the bottom line */
4272         prt("", y + i + 1, x);
4273 }
4274
4275
4276 /*!
4277  * @brief アイテムが酸で破損するかどうかを判定する
4278  * @param o_ptr アイテムの情報参照ポインタ
4279  * @return 破損するならばTRUEを返す
4280  * Note that amulets, rods, and high-level spell books are immune
4281  * to "inventory damage" of any kind.  Also sling ammo and shovels.
4282  * Does a given class of objects (usually) hate acid?
4283  * Note that acid can either melt or corrode something.
4284  */
4285 bool hates_acid(object_type *o_ptr)
4286 {
4287         /* Analyze the type */
4288         switch (o_ptr->tval)
4289         {
4290                 /* Wearable items */
4291                 case TV_ARROW:
4292                 case TV_BOLT:
4293                 case TV_BOW:
4294                 case TV_SWORD:
4295                 case TV_HAFTED:
4296                 case TV_POLEARM:
4297                 case TV_HELM:
4298                 case TV_CROWN:
4299                 case TV_SHIELD:
4300                 case TV_BOOTS:
4301                 case TV_GLOVES:
4302                 case TV_CLOAK:
4303                 case TV_SOFT_ARMOR:
4304                 case TV_HARD_ARMOR:
4305                 case TV_DRAG_ARMOR:
4306                 {
4307                         return (TRUE);
4308                 }
4309
4310                 /* Staffs/Scrolls are wood/paper */
4311                 case TV_STAFF:
4312                 case TV_SCROLL:
4313                 {
4314                         return (TRUE);
4315                 }
4316
4317                 /* Ouch */
4318                 case TV_CHEST:
4319                 {
4320                         return (TRUE);
4321                 }
4322
4323                 /* Junk is useless */
4324                 case TV_SKELETON:
4325                 case TV_BOTTLE:
4326                 case TV_JUNK:
4327                 {
4328                         return (TRUE);
4329                 }
4330         }
4331
4332         return (FALSE);
4333 }
4334
4335
4336 /*!
4337  * @brief アイテムが電撃で破損するかどうかを判定する /
4338  * Does a given object (usually) hate electricity?
4339  * @param o_ptr アイテムの情報参照ポインタ
4340  * @return 破損するならばTRUEを返す
4341  */
4342 bool hates_elec(object_type *o_ptr)
4343 {
4344         switch (o_ptr->tval)
4345         {
4346                 case TV_RING:
4347                 case TV_WAND:
4348                 {
4349                         return (TRUE);
4350                 }
4351         }
4352
4353         return (FALSE);
4354 }
4355
4356
4357 /*!
4358  * @brief アイテムが火炎で破損するかどうかを判定する /
4359  * Does a given object (usually) hate fire?
4360  * @param o_ptr アイテムの情報参照ポインタ
4361  * @return 破損するならばTRUEを返す
4362  * @details
4363  * Hafted/Polearm weapons have wooden shafts.
4364  * Arrows/Bows are mostly wooden.
4365  */
4366 bool hates_fire(object_type *o_ptr)
4367 {
4368         /* Analyze the type */
4369         switch (o_ptr->tval)
4370         {
4371                 /* Wearable */
4372                 case TV_LITE:
4373                 case TV_ARROW:
4374                 case TV_BOW:
4375                 case TV_HAFTED:
4376                 case TV_POLEARM:
4377                 case TV_BOOTS:
4378                 case TV_GLOVES:
4379                 case TV_CLOAK:
4380                 case TV_SOFT_ARMOR:
4381                 {
4382                         return (TRUE);
4383                 }
4384
4385                 /* Books */
4386                 case TV_LIFE_BOOK:
4387                 case TV_SORCERY_BOOK:
4388                 case TV_NATURE_BOOK:
4389                 case TV_CHAOS_BOOK:
4390                 case TV_DEATH_BOOK:
4391                 case TV_TRUMP_BOOK:
4392                 case TV_ARCANE_BOOK:
4393                 case TV_CRAFT_BOOK:
4394                 case TV_DAEMON_BOOK:
4395                 case TV_CRUSADE_BOOK:
4396                 case TV_MUSIC_BOOK:
4397                 case TV_HISSATSU_BOOK:
4398                 case TV_HEX_BOOK:
4399                 {
4400                         return (TRUE);
4401                 }
4402
4403                 /* Chests */
4404                 case TV_CHEST:
4405                 {
4406                         return (TRUE);
4407                 }
4408
4409                 /* Staffs/Scrolls burn */
4410                 case TV_STAFF:
4411                 case TV_SCROLL:
4412                 {
4413                         return (TRUE);
4414                 }
4415         }
4416
4417         return (FALSE);
4418 }
4419
4420
4421 /*!
4422  * @brief アイテムが冷気で破損するかどうかを判定する /
4423  * Does a given object (usually) hate cold?
4424  * @param o_ptr アイテムの情報参照ポインタ
4425  * @return 破損するならばTRUEを返す
4426  */
4427 bool hates_cold(object_type *o_ptr)
4428 {
4429         switch (o_ptr->tval)
4430         {
4431                 case TV_POTION:
4432                 case TV_FLASK:
4433                 case TV_BOTTLE:
4434                 {
4435                         return (TRUE);
4436                 }
4437         }
4438
4439         return (FALSE);
4440 }
4441
4442
4443 /*!
4444  * @brief アイテムが酸で破損するかどうかを判定する(メインルーチン) /
4445  * Melt something
4446  * @param o_ptr アイテムの情報参照ポインタ
4447  * @return 破損するならばTRUEを返す
4448  * @todo 統合を検討
4449  */
4450 int set_acid_destroy(object_type *o_ptr)
4451 {
4452         u32b flgs[TR_FLAG_SIZE];
4453         if (!hates_acid(o_ptr)) return (FALSE);
4454         object_flags(o_ptr, flgs);
4455         if (have_flag(flgs, TR_IGNORE_ACID)) return (FALSE);
4456         return (TRUE);
4457 }
4458
4459
4460 /*!
4461  * @brief アイテムが電撃で破損するかどうかを判定する(メインルーチン) /
4462  * Electrical damage
4463  * @param o_ptr アイテムの情報参照ポインタ
4464  * @return 破損するならばTRUEを返す
4465  * @todo 統合を検討
4466  */
4467 int set_elec_destroy(object_type *o_ptr)
4468 {
4469         u32b flgs[TR_FLAG_SIZE];
4470         if (!hates_elec(o_ptr)) return (FALSE);
4471         object_flags(o_ptr, flgs);
4472         if (have_flag(flgs, TR_IGNORE_ELEC)) return (FALSE);
4473         return (TRUE);
4474 }
4475
4476
4477 /*!
4478  * @brief アイテムが火炎で破損するかどうかを判定する(メインルーチン) /
4479  * Burn something
4480  * @param o_ptr アイテムの情報参照ポインタ
4481  * @return 破損するならばTRUEを返す
4482  * @todo 統合を検討
4483  */
4484 int set_fire_destroy(object_type *o_ptr)
4485 {
4486         u32b flgs[TR_FLAG_SIZE];
4487         if (!hates_fire(o_ptr)) return (FALSE);
4488         object_flags(o_ptr, flgs);
4489         if (have_flag(flgs, TR_IGNORE_FIRE)) return (FALSE);
4490         return (TRUE);
4491 }
4492
4493
4494 /*!
4495  * @brief アイテムが冷気で破損するかどうかを判定する(メインルーチン) /
4496  * Freeze things
4497  * @param o_ptr アイテムの情報参照ポインタ
4498  * @return 破損するならばTRUEを返す
4499  * @todo 統合を検討
4500  */
4501 int set_cold_destroy(object_type *o_ptr)
4502 {
4503         u32b flgs[TR_FLAG_SIZE];
4504         if (!hates_cold(o_ptr)) return (FALSE);
4505         object_flags(o_ptr, flgs);
4506         if (have_flag(flgs, TR_IGNORE_COLD)) return (FALSE);
4507         return (TRUE);
4508 }
4509
4510
4511 /*!
4512  * @brief アイテムが指定確率で破損するかどうかを判定する /
4513  * Destroys a type of item on a given percent chance
4514  * @param typ 破損判定関数ポインタ
4515  * @param perc 基本確率
4516  * @return 破損したアイテムの数
4517  * @details
4518  * Note that missiles are no longer necessarily all destroyed
4519  * Destruction taken from "melee.c" code for "stealing".
4520  * New-style wands and rods handled correctly. -LM-
4521  * Returns number of items destroyed.
4522  */
4523 int inven_damage(inven_func typ, int perc)
4524 {
4525         int         i, j, k, amt;
4526         object_type *o_ptr;
4527         char        o_name[MAX_NLEN];
4528
4529         if (CHECK_MULTISHADOW()) return 0;
4530
4531         if (p_ptr->inside_arena) return 0;
4532
4533         /* Count the casualties */
4534         k = 0;
4535
4536         /* Scan through the slots backwards */
4537         for (i = 0; i < INVEN_PACK; i++)
4538         {
4539                 o_ptr = &inventory[i];
4540
4541                 /* Skip non-objects */
4542                 if (!o_ptr->k_idx) continue;
4543
4544                 /* Hack -- for now, skip artifacts */
4545                 if (object_is_artifact(o_ptr)) continue;
4546
4547                 /* Give this item slot a shot at death */
4548                 if ((*typ)(o_ptr))
4549                 {
4550                         /* Count the casualties */
4551                         for (amt = j = 0; j < o_ptr->number; ++j)
4552                         {
4553                                 if (randint0(100) < perc) amt++;
4554                         }
4555
4556                         /* Some casualities */
4557                         if (amt)
4558                         {
4559                                 /* Get a description */
4560                                 object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
4561
4562                                 /* Message */
4563                                 msg_format(_("%s(%c)が%s壊れてしまった!", "%sour %s (%c) %s destroyed!"),
4564
4565 #ifdef JP
4566 o_name, index_to_label(i),
4567     ((o_ptr->number > 1) ?
4568     ((amt == o_ptr->number) ? "全部" :
4569     (amt > 1 ? "何個か" : "一個")) : "")    );
4570 #else
4571                                     ((o_ptr->number > 1) ?
4572                                     ((amt == o_ptr->number) ? "All of y" :
4573                                     (amt > 1 ? "Some of y" : "One of y")) : "Y"),
4574                                     o_name, index_to_label(i),
4575                                     ((amt > 1) ? "were" : "was"));
4576 #endif
4577
4578 #ifdef JP
4579                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
4580                                         msg_print("やりやがったな!");
4581 #endif
4582
4583                                 /* Potions smash open */
4584                                 if (object_is_potion(o_ptr))
4585                                 {
4586                                         (void)potion_smash_effect(0, p_ptr->y, p_ptr->x, o_ptr->k_idx);
4587                                 }
4588
4589                                 /* Reduce the charges of rods/wands */
4590                                 reduce_charges(o_ptr, amt);
4591
4592                                 /* Destroy "amt" items */
4593                                 inven_item_increase(i, -amt);
4594                                 inven_item_optimize(i);
4595
4596                                 /* Count the casualties */
4597                                 k += amt;
4598                         }
4599                 }
4600         }
4601
4602         /* Return the casualty count */
4603         return (k);
4604 }
4605
4606
4607 /*!
4608  * @brief 酸攻撃による装備のAC劣化処理 /
4609  * Acid has hit the player, attempt to affect some armor.
4610  * @return ACが実際に劣化したらTRUEを返す
4611  * @details
4612  * Note that the "base armor" of an object never changes.
4613  * If any armor is damaged (or resists), the player takes less damage.
4614  */
4615 static int minus_ac(void)
4616 {
4617         object_type *o_ptr = NULL;
4618         u32b flgs[TR_FLAG_SIZE];
4619         char        o_name[MAX_NLEN];
4620
4621
4622         /* Pick a (possibly empty) inventory slot */
4623         switch (randint1(7))
4624         {
4625                 case 1: o_ptr = &inventory[INVEN_RARM]; break;
4626                 case 2: o_ptr = &inventory[INVEN_LARM]; break;
4627                 case 3: o_ptr = &inventory[INVEN_BODY]; break;
4628                 case 4: o_ptr = &inventory[INVEN_OUTER]; break;
4629                 case 5: o_ptr = &inventory[INVEN_HANDS]; break;
4630                 case 6: o_ptr = &inventory[INVEN_HEAD]; break;
4631                 case 7: o_ptr = &inventory[INVEN_FEET]; break;
4632         }
4633
4634         /* Nothing to damage */
4635         if (!o_ptr->k_idx) return (FALSE);
4636
4637         if (!object_is_armour(o_ptr)) return (FALSE);
4638
4639         /* No damage left to be done */
4640         if (o_ptr->ac + o_ptr->to_a <= 0) return (FALSE);
4641
4642
4643         /* Describe */
4644         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4645
4646         /* Extract the flags */
4647         object_flags(o_ptr, flgs);
4648
4649         /* Object resists */
4650         if (have_flag(flgs, TR_IGNORE_ACID))
4651         {
4652                 msg_format(_("しかし%sには効果がなかった!", "Your %s is unaffected!"), o_name);
4653                 return (TRUE);
4654         }
4655
4656         /* Message */
4657         msg_format(_("%sがダメージを受けた!", "Your %s is damaged!"), o_name);
4658
4659         /* Damage the item */
4660         o_ptr->to_a--;
4661
4662         /* Calculate bonuses */
4663         p_ptr->update |= (PU_BONUS);
4664
4665         /* Window stuff */
4666         p_ptr->window |= (PW_EQUIP | PW_PLAYER);
4667
4668         calc_android_exp();
4669
4670         /* Item was damaged */
4671         return (TRUE);
4672 }
4673
4674
4675 /*!
4676  * @brief 酸属性によるプレイヤー損害処理 /
4677  * Hurt the player with Acid
4678  * @param dam 基本ダメージ量
4679  * @param kb_str ダメージ原因記述
4680  * @param monspell 原因となったモンスター特殊攻撃ID
4681  * @param aura オーラよるダメージが原因ならばTRUE
4682  * @return 修正HPダメージ量
4683  */
4684 int acid_dam(HIT_POINT dam, cptr kb_str, int monspell, bool aura)
4685 {
4686         int get_damage;  
4687         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
4688         bool double_resist = IS_OPPOSE_ACID();
4689
4690         /* Total Immunity */
4691         if (p_ptr->immune_acid || (dam <= 0))
4692         {
4693                 learn_spell(monspell);
4694                 return 0;
4695         }
4696
4697         /* Vulnerability (Ouch!) */
4698         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
4699         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
4700
4701         /* Resist the damage */
4702         if (p_ptr->resist_acid) dam = (dam + 2) / 3;
4703         if (double_resist) dam = (dam + 2) / 3;
4704
4705         if (aura || !CHECK_MULTISHADOW())
4706         {
4707                 if ((!(double_resist || p_ptr->resist_acid)) &&
4708                     one_in_(HURT_CHANCE))
4709                         (void)do_dec_stat(A_CHR);
4710
4711                 /* If any armor gets hit, defend the player */
4712                 if (minus_ac()) dam = (dam + 1) / 2;
4713         }
4714
4715         /* Take damage */
4716         get_damage = take_hit(aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
4717
4718         /* Inventory damage */
4719         if (!aura && !(double_resist && p_ptr->resist_acid))
4720                 inven_damage(set_acid_destroy, inv);
4721         return get_damage;
4722 }
4723
4724
4725 /*!
4726  * @brief 電撃属性によるプレイヤー損害処理 /
4727  * Hurt the player with electricity
4728  * @param dam 基本ダメージ量
4729  * @param kb_str ダメージ原因記述
4730  * @param monspell 原因となったモンスター特殊攻撃ID
4731  * @param aura オーラよるダメージが原因ならばTRUE
4732  * @return 修正HPダメージ量
4733  */
4734 int elec_dam(HIT_POINT dam, cptr kb_str, int monspell, bool aura)
4735 {
4736         int get_damage;  
4737         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
4738         bool double_resist = IS_OPPOSE_ELEC();
4739
4740         /* Total immunity */
4741         if (p_ptr->immune_elec || (dam <= 0))
4742         {
4743                 learn_spell(monspell);
4744                 return 0;
4745         }
4746
4747         /* Vulnerability (Ouch!) */
4748         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
4749         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
4750         if (prace_is_(RACE_ANDROID)) dam += dam / 3;
4751
4752         /* Resist the damage */
4753         if (p_ptr->resist_elec) dam = (dam + 2) / 3;
4754         if (double_resist) dam = (dam + 2) / 3;
4755
4756         if (aura || !CHECK_MULTISHADOW())
4757         {
4758                 if ((!(double_resist || p_ptr->resist_elec)) &&
4759                     one_in_(HURT_CHANCE))
4760                         (void)do_dec_stat(A_DEX);
4761         }
4762
4763         /* Take damage */
4764         get_damage = take_hit(aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
4765
4766         /* Inventory damage */
4767         if (!aura && !(double_resist && p_ptr->resist_elec))
4768                 inven_damage(set_elec_destroy, inv);
4769
4770         return get_damage;
4771 }
4772
4773
4774 /*!
4775  * @brief 火炎属性によるプレイヤー損害処理 /
4776  * Hurt the player with Fire
4777  * @param dam 基本ダメージ量
4778  * @param kb_str ダメージ原因記述
4779  * @param monspell 原因となったモンスター特殊攻撃ID
4780  * @param aura オーラよるダメージが原因ならばTRUE
4781  * @return 修正HPダメージ量
4782  */
4783 int fire_dam(HIT_POINT dam, cptr kb_str, int monspell, bool aura)
4784 {
4785         int get_damage;  
4786         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
4787         bool double_resist = IS_OPPOSE_FIRE();
4788
4789         /* Totally immune */
4790         if (p_ptr->immune_fire || (dam <= 0))
4791         {
4792                 learn_spell(monspell);
4793                 return 0;
4794         }
4795
4796         /* Vulnerability (Ouch!) */
4797         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
4798         if (prace_is_(RACE_ENT)) dam += dam / 3;
4799         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
4800
4801         /* Resist the damage */
4802         if (p_ptr->resist_fire) dam = (dam + 2) / 3;
4803         if (double_resist) dam = (dam + 2) / 3;
4804
4805         if (aura || !CHECK_MULTISHADOW())
4806         {
4807                 if ((!(double_resist || p_ptr->resist_fire)) &&
4808                     one_in_(HURT_CHANCE))
4809                         (void)do_dec_stat(A_STR);
4810         }
4811
4812         /* Take damage */
4813         get_damage = take_hit(aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
4814
4815         /* Inventory damage */
4816         if (!aura && !(double_resist && p_ptr->resist_fire))
4817                 inven_damage(set_fire_destroy, inv);
4818
4819         return get_damage;
4820 }
4821
4822
4823 /*!
4824  * @brief 冷気属性によるプレイヤー損害処理 /
4825  * Hurt the player with Cold
4826  * @param dam 基本ダメージ量
4827  * @param kb_str ダメージ原因記述
4828  * @param monspell 原因となったモンスター特殊攻撃ID
4829  * @param aura オーラよるダメージが原因ならばTRUE
4830  * @return 修正HPダメージ量
4831  */
4832 int cold_dam(HIT_POINT dam, cptr kb_str, int monspell, bool aura)
4833 {
4834         int get_damage;  
4835         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
4836         bool double_resist = IS_OPPOSE_COLD();
4837
4838         /* Total immunity */
4839         if (p_ptr->immune_cold || (dam <= 0))
4840         {
4841                 learn_spell(monspell);
4842                 return 0;
4843         }
4844
4845         /* Vulnerability (Ouch!) */
4846         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
4847         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
4848
4849         /* Resist the damage */
4850         if (p_ptr->resist_cold) dam = (dam + 2) / 3;
4851         if (double_resist) dam = (dam + 2) / 3;
4852
4853         if (aura || !CHECK_MULTISHADOW())
4854         {
4855                 if ((!(double_resist || p_ptr->resist_cold)) &&
4856                     one_in_(HURT_CHANCE))
4857                         (void)do_dec_stat(A_STR);
4858         }
4859
4860         /* Take damage */
4861         get_damage = take_hit(aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
4862
4863         /* Inventory damage */
4864         if (!aura && !(double_resist && p_ptr->resist_cold))
4865                 inven_damage(set_cold_destroy, inv);
4866
4867         return get_damage;
4868 }
4869
4870 /*!
4871  * @brief 防具の錆止め防止処理
4872  * @return ターン消費を要する処理を行ったならばTRUEを返す
4873  */
4874 bool rustproof(void)
4875 {
4876         OBJECT_IDX item;
4877         object_type *o_ptr;
4878         char        o_name[MAX_NLEN];
4879         cptr        q, s;
4880
4881         item_tester_no_ryoute = TRUE;
4882         /* Select a piece of armour */
4883         item_tester_hook = object_is_armour;
4884
4885         /* Get an item */
4886         q = _("どの防具に錆止めをしますか?", "Rustproof which piece of armour? ");
4887         s = _("錆止めできるものがありません。", "You have nothing to rustproof.");
4888
4889         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return FALSE;
4890
4891         /* Get the item (in the pack) */
4892         if (item >= 0)
4893         {
4894                 o_ptr = &inventory[item];
4895         }
4896
4897         /* Get the item (on the floor) */
4898         else
4899         {
4900                 o_ptr = &o_list[0 - item];
4901         }
4902
4903
4904         /* Description */
4905         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4906
4907         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
4908
4909         if ((o_ptr->to_a < 0) && !object_is_cursed(o_ptr))
4910         {
4911 #ifdef JP
4912 msg_format("%sは新品同様になった!",o_name);
4913 #else
4914                 msg_format("%s %s look%s as good as new!",
4915                         ((item >= 0) ? "Your" : "The"), o_name,
4916                         ((o_ptr->number > 1) ? "" : "s"));
4917 #endif
4918
4919                 o_ptr->to_a = 0;
4920         }
4921
4922 #ifdef JP
4923 msg_format("%sは腐食しなくなった。", o_name);
4924 #else
4925         msg_format("%s %s %s now protected against corrosion.",
4926                 ((item >= 0) ? "Your" : "The"), o_name,
4927                 ((o_ptr->number > 1) ? "are" : "is"));
4928 #endif
4929
4930
4931         calc_android_exp();
4932
4933         return TRUE;
4934 }
4935
4936
4937 /*!
4938  * @brief 防具呪縛処理 /
4939  * Curse the players armor
4940  * @return 実際に呪縛されたらTRUEを返す
4941  */
4942 bool curse_armor(void)
4943 {
4944         int i;
4945         object_type *o_ptr;
4946
4947         char o_name[MAX_NLEN];
4948
4949
4950         /* Curse the body armor */
4951         o_ptr = &inventory[INVEN_BODY];
4952
4953         /* Nothing to curse */
4954         if (!o_ptr->k_idx) return (FALSE);
4955
4956
4957         /* Describe */
4958         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
4959
4960         /* Attempt a saving throw for artifacts */
4961         if (object_is_artifact(o_ptr) && (randint0(100) < 50))
4962         {
4963                 /* Cool */
4964 #ifdef JP
4965 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!",
4966 "恐怖の暗黒オーラ", "防具", o_name);
4967 #else
4968                 msg_format("A %s tries to %s, but your %s resists the effects!",
4969                            "terrible black aura", "surround your armor", o_name);
4970 #endif
4971
4972         }
4973
4974         /* not artifact or failed save... */
4975         else
4976         {
4977                 /* Oops */
4978                 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
4979                 chg_virtue(V_ENCHANT, -5);
4980
4981                 /* Blast the armor */
4982                 o_ptr->name1 = 0;
4983                 o_ptr->name2 = EGO_BLASTED;
4984                 o_ptr->to_a = 0 - randint1(5) - randint1(5);
4985                 o_ptr->to_h = 0;
4986                 o_ptr->to_d = 0;
4987                 o_ptr->ac = 0;
4988                 o_ptr->dd = 0;
4989                 o_ptr->ds = 0;
4990
4991                 for (i = 0; i < TR_FLAG_SIZE; i++)
4992                         o_ptr->art_flags[i] = 0;
4993
4994                 /* Curse it */
4995                 o_ptr->curse_flags = TRC_CURSED;
4996
4997                 /* Break it */
4998                 o_ptr->ident |= (IDENT_BROKEN);
4999
5000                 /* Recalculate bonuses */
5001                 p_ptr->update |= (PU_BONUS);
5002
5003                 /* Recalculate mana */
5004                 p_ptr->update |= (PU_MANA);
5005
5006                 /* Window stuff */
5007                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
5008         }
5009
5010         return (TRUE);
5011 }
5012
5013 /*!
5014  * @brief 武器呪縛処理 /
5015  * Curse the players weapon
5016  * @param force 無条件に呪縛を行うならばTRUE
5017  * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
5018  * @return 実際に呪縛されたらTRUEを返す
5019  */
5020 bool curse_weapon_object(bool force, object_type *o_ptr)
5021 {
5022         int i;
5023         char o_name[MAX_NLEN];
5024
5025         /* Nothing to curse */
5026         if (!o_ptr->k_idx) return (FALSE);
5027
5028         /* Describe */
5029         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
5030
5031         /* Attempt a saving throw */
5032         if (object_is_artifact(o_ptr) && (randint0(100) < 50) && !force)
5033         {
5034                 /* Cool */
5035 #ifdef JP
5036                 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!",
5037                                 "恐怖の暗黒オーラ", "武器", o_name);
5038 #else
5039                 msg_format("A %s tries to %s, but your %s resists the effects!",
5040                                 "terrible black aura", "surround your weapon", o_name);
5041 #endif
5042         }
5043
5044         /* not artifact or failed save... */
5045         else
5046         {
5047                 /* Oops */
5048                 if (!force) msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
5049                 chg_virtue(V_ENCHANT, -5);
5050
5051                 /* Shatter the weapon */
5052                 o_ptr->name1 = 0;
5053                 o_ptr->name2 = EGO_SHATTERED;
5054                 o_ptr->to_h = 0 - randint1(5) - randint1(5);
5055                 o_ptr->to_d = 0 - randint1(5) - randint1(5);
5056                 o_ptr->to_a = 0;
5057                 o_ptr->ac = 0;
5058                 o_ptr->dd = 0;
5059                 o_ptr->ds = 0;
5060
5061                 for (i = 0; i < TR_FLAG_SIZE; i++)
5062                         o_ptr->art_flags[i] = 0;
5063
5064                 /* Curse it */
5065                 o_ptr->curse_flags = TRC_CURSED;
5066
5067                 /* Break it */
5068                 o_ptr->ident |= (IDENT_BROKEN);
5069
5070                 /* Recalculate bonuses */
5071                 p_ptr->update |= (PU_BONUS);
5072
5073                 /* Recalculate mana */
5074                 p_ptr->update |= (PU_MANA);
5075
5076                 /* Window stuff */
5077                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
5078         }
5079
5080         /* Notice */
5081         return (TRUE);
5082 }
5083
5084 /*!
5085  * @brief 武器呪縛処理のメインルーチン /
5086  * Curse the players weapon
5087  * @param force 無条件に呪縛を行うならばTRUE
5088  * @param slot 呪縛する武器の装備スロット
5089  * @return 実際に呪縛されたらTRUEを返す
5090  */
5091 bool curse_weapon(bool force, int slot)
5092 {
5093         /* Curse the weapon */
5094         return curse_weapon_object(force, &inventory[slot]);
5095 }
5096
5097
5098 /*!
5099  * @brief ボルトのエゴ化処理(火炎エゴのみ) /
5100  * Enchant some bolts
5101  * @return 常にTRUEを返す
5102  */
5103 bool brand_bolts(void)
5104 {
5105         int i;
5106
5107         /* Use the first acceptable bolts */
5108         for (i = 0; i < INVEN_PACK; i++)
5109         {
5110                 object_type *o_ptr = &inventory[i];
5111
5112                 /* Skip non-bolts */
5113                 if (o_ptr->tval != TV_BOLT) continue;
5114
5115                 /* Skip artifacts and ego-items */
5116                 if (object_is_artifact(o_ptr) || object_is_ego(o_ptr))
5117                         continue;
5118
5119                 /* Skip cursed/broken items */
5120                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) continue;
5121
5122                 /* Randomize */
5123                 if (randint0(100) < 75) continue;
5124
5125                 /* Message */
5126                 msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
5127
5128                 /* Ego-item */
5129                 o_ptr->name2 = EGO_FLAME;
5130
5131                 /* Enchant */
5132                 enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
5133
5134                 /* Notice */
5135                 return (TRUE);
5136         }
5137
5138         /* Flush */
5139         if (flush_failure) flush();
5140
5141         /* Fail */
5142         msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
5143
5144         /* Notice */
5145         return (TRUE);
5146 }
5147
5148
5149 /*!
5150  * @brief 変身処理向けにモンスターの近隣レベル帯モンスターを返す /
5151  * Helper function -- return a "nearby" race for polymorphing
5152  * @param r_idx 基準となるモンスター種族ID
5153  * @return 変更先のモンスター種族ID
5154  * @details
5155  * Note that this function is one of the more "dangerous" ones...
5156  */
5157 static IDX poly_r_idx(MONRACE_IDX r_idx)
5158 {
5159         monster_race *r_ptr = &r_info[r_idx];
5160
5161         int i;
5162         MONRACE_IDX r;
5163         DEPTH lev1, lev2;
5164
5165         /* Hack -- Uniques/Questors never polymorph */
5166         if ((r_ptr->flags1 & RF1_UNIQUE) ||
5167             (r_ptr->flags1 & RF1_QUESTOR))
5168                 return (r_idx);
5169
5170         /* Allowable range of "levels" for resulting monster */
5171         lev1 = r_ptr->level - ((randint1(20) / randint1(9)) + 1);
5172         lev2 = r_ptr->level + ((randint1(20) / randint1(9)) + 1);
5173
5174         /* Pick a (possibly new) non-unique race */
5175         for (i = 0; i < 1000; i++)
5176         {
5177                 /* Pick a new race, using a level calculation */
5178                 r = get_mon_num((dun_level + r_ptr->level) / 2 + 5);
5179
5180                 /* Handle failure */
5181                 if (!r) break;
5182
5183                 /* Obtain race */
5184                 r_ptr = &r_info[r];
5185
5186                 /* Ignore unique monsters */
5187                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
5188
5189                 /* Ignore monsters with incompatible levels */
5190                 if ((r_ptr->level < lev1) || (r_ptr->level > lev2)) continue;
5191
5192                 /* Use that index */
5193                 r_idx = r;
5194
5195                 /* Done */
5196                 break;
5197         }
5198
5199         /* Result */
5200         return (r_idx);
5201 }
5202
5203 /*!
5204  * @brief 指定座標にいるモンスターを変身させる /
5205  * Helper function -- return a "nearby" race for polymorphing
5206  * @param y 指定のY座標
5207  * @param x 指定のX座標
5208  * @return 実際に変身したらTRUEを返す
5209  */
5210 bool polymorph_monster(POSITION y, POSITION x)
5211 {
5212         cave_type *c_ptr = &cave[y][x];
5213         monster_type *m_ptr = &m_list[c_ptr->m_idx];
5214         bool polymorphed = FALSE;
5215         MONRACE_IDX new_r_idx;
5216         MONRACE_IDX old_r_idx = m_ptr->r_idx;
5217         bool targeted = (target_who == c_ptr->m_idx) ? TRUE : FALSE;
5218         bool health_tracked = (p_ptr->health_who == c_ptr->m_idx) ? TRUE : FALSE;
5219         monster_type back_m;
5220
5221         if (p_ptr->inside_arena || p_ptr->inside_battle) return (FALSE);
5222
5223         if ((p_ptr->riding == c_ptr->m_idx) || (m_ptr->mflag2 & MFLAG2_KAGE)) return (FALSE);
5224
5225         /* Memorize the monster before polymorphing */
5226         back_m = *m_ptr;
5227
5228         /* Pick a "new" monster race */
5229         new_r_idx = poly_r_idx(old_r_idx);
5230
5231         /* Handle polymorph */
5232         if (new_r_idx != old_r_idx)
5233         {
5234                 BIT_FLAGS mode = 0L;
5235                 bool preserve_hold_objects = back_m.hold_o_idx ? TRUE : FALSE;
5236                 s16b this_o_idx, next_o_idx = 0;
5237
5238                 /* Get the monsters attitude */
5239                 if (is_friendly(m_ptr)) mode |= PM_FORCE_FRIENDLY;
5240                 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
5241                 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
5242
5243                 /* Mega-hack -- ignore held objects */
5244                 m_ptr->hold_o_idx = 0;
5245
5246                 /* "Kill" the "old" monster */
5247                 delete_monster_idx(c_ptr->m_idx);
5248
5249                 /* Create a new monster (no groups) */
5250                 if (place_monster_aux(0, y, x, new_r_idx, mode))
5251                 {
5252                         m_list[hack_m_idx_ii].nickname = back_m.nickname;
5253                         m_list[hack_m_idx_ii].parent_m_idx = back_m.parent_m_idx;
5254                         m_list[hack_m_idx_ii].hold_o_idx = back_m.hold_o_idx;
5255
5256                         /* Success */
5257                         polymorphed = TRUE;
5258                 }
5259                 else
5260                 {
5261                         /* Placing the new monster failed */
5262                         if (place_monster_aux(0, y, x, old_r_idx, (mode | PM_NO_KAGE | PM_IGNORE_TERRAIN)))
5263                         {
5264                                 m_list[hack_m_idx_ii] = back_m;
5265
5266                                 /* Re-initialize monster process */
5267                                 mproc_init();
5268                         }
5269                         else preserve_hold_objects = FALSE;
5270                 }
5271
5272                 /* Mega-hack -- preserve held objects */
5273                 if (preserve_hold_objects)
5274                 {
5275                         for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
5276                         {
5277                                 /* Acquire object */
5278                                 object_type *o_ptr = &o_list[this_o_idx];
5279
5280                                 /* Acquire next object */
5281                                 next_o_idx = o_ptr->next_o_idx;
5282
5283                                 /* Held by new monster */
5284                                 o_ptr->held_m_idx = hack_m_idx_ii;
5285                         }
5286                 }
5287                 else if (back_m.hold_o_idx) /* Failed (paranoia) */
5288                 {
5289                         /* Delete objects */
5290                         for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
5291                         {
5292                                 /* Acquire next object */
5293                                 next_o_idx = o_list[this_o_idx].next_o_idx;
5294
5295                                 /* Delete the object */
5296                                 delete_object_idx(this_o_idx);
5297                         }
5298                 }
5299
5300                 if (targeted) target_who = hack_m_idx_ii;
5301                 if (health_tracked) health_track(hack_m_idx_ii);
5302         }
5303
5304         return polymorphed;
5305 }
5306
5307 /*!
5308  * @brief 次元の扉処理 /
5309  * Dimension Door
5310  * @param x テレポート先のX座標
5311  * @param y テレポート先のY座標
5312  * @return 目標に指定通りテレポートできたならばTRUEを返す
5313  */
5314 static bool dimension_door_aux(DEPTH x, DEPTH y)
5315 {
5316         PLAYER_LEVEL plev = p_ptr->lev;
5317
5318         p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
5319
5320         if (!cave_player_teleportable_bold(y, x, 0L) ||
5321             (distance(y, x, p_ptr->y, p_ptr->x) > plev / 2 + 10) ||
5322             (!randint0(plev / 10 + 10)))
5323         {
5324                 p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
5325                 teleport_player((plev + 2) * 2, TELEPORT_PASSIVE);
5326
5327                 /* Failed */
5328                 return FALSE;
5329         }
5330         else
5331         {
5332                 teleport_player_to(y, x, 0L);
5333
5334                 /* Success */
5335                 return TRUE;
5336         }
5337 }
5338
5339
5340 /*!
5341  * @brief 次元の扉処理のメインルーチン /
5342  * Dimension Door
5343  * @return ターンを消費した場合TRUEを返す
5344  */
5345 bool dimension_door(void)
5346 {
5347         DEPTH x = 0, y = 0;
5348
5349         /* Rerutn FALSE if cancelled */
5350         if (!tgt_pt(&x, &y)) return FALSE;
5351
5352         if (dimension_door_aux(x, y)) return TRUE;
5353
5354         msg_print(_("精霊界から物質界に戻る時うまくいかなかった!", "You fail to exit the astral plane correctly!"));
5355
5356         return TRUE;
5357 }
5358
5359
5360 /*!
5361  * @brief 鏡抜け処理のメインルーチン /
5362  * Mirror Master's Dimension Door
5363  * @return ターンを消費した場合TRUEを返す
5364  */
5365 bool mirror_tunnel(void)
5366 {
5367         POSITION x = 0, y = 0;
5368
5369         /* Rerutn FALSE if cancelled */
5370         if (!tgt_pt(&x, &y)) return FALSE;
5371
5372         if (dimension_door_aux(x, y)) return TRUE;
5373
5374         msg_print(_("鏡の世界をうまく通れなかった!", "You fail to pass the mirror plane correctly!"));
5375
5376         return TRUE;
5377 }
5378
5379 /*!
5380  * @brief 魔力食い処理
5381  * @param power 基本効力
5382  * @return ターンを消費した場合TRUEを返す
5383  */
5384 bool eat_magic(int power)
5385 {
5386         object_type * o_ptr;
5387         object_kind *k_ptr;
5388         int lev;
5389         OBJECT_IDX item;
5390         int recharge_strength = 0;
5391
5392         bool fail = FALSE;
5393         byte fail_type = 1;
5394
5395         cptr q, s;
5396         char o_name[MAX_NLEN];
5397
5398         item_tester_hook = item_tester_hook_recharge;
5399
5400         /* Get an item */
5401         q = _("どのアイテムから魔力を吸収しますか?", "Drain which item? ");
5402         s = _("魔力を吸収できるアイテムがありません。", "You have nothing to drain.");
5403
5404         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return FALSE;
5405
5406         if (item >= 0)
5407         {
5408                 o_ptr = &inventory[item];
5409         }
5410         else
5411         {
5412                 o_ptr = &o_list[0 - item];
5413         }
5414
5415         k_ptr = &k_info[o_ptr->k_idx];
5416         lev = k_info[o_ptr->k_idx].level;
5417
5418         if (o_ptr->tval == TV_ROD)
5419         {
5420                 recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
5421
5422                 /* Back-fire */
5423                 if (one_in_(recharge_strength))
5424                 {
5425                         /* Activate the failure code. */
5426                         fail = TRUE;
5427                 }
5428                 else
5429                 {
5430                         if (o_ptr->timeout > (o_ptr->number - 1) * k_ptr->pval)
5431                         {
5432                                 msg_print(_("充填中のロッドから魔力を吸収することはできません。", "You can't absorb energy from a discharged rod."));
5433                         }
5434                         else
5435                         {
5436                                 p_ptr->csp += lev;
5437                                 o_ptr->timeout += k_ptr->pval;
5438                         }
5439                 }
5440         }
5441         else
5442         {
5443                 /* All staffs, wands. */
5444                 recharge_strength = (100 + power - lev) / 15;
5445
5446                 /* Paranoia */
5447                 if (recharge_strength < 0) recharge_strength = 0;
5448
5449                 /* Back-fire */
5450                 if (one_in_(recharge_strength))
5451                 {
5452                         /* Activate the failure code. */
5453                         fail = TRUE;
5454                 }
5455                 else
5456                 {
5457                         if (o_ptr->pval > 0)
5458                         {
5459                                 p_ptr->csp += lev / 2;
5460                                 o_ptr->pval --;
5461
5462                                 /* XXX Hack -- unstack if necessary */
5463                                 if ((o_ptr->tval == TV_STAFF) && (item >= 0) && (o_ptr->number > 1))
5464                                 {
5465                                         object_type forge;
5466                                         object_type *q_ptr;
5467
5468                                         /* Get local object */
5469                                         q_ptr = &forge;
5470
5471                                         /* Obtain a local object */
5472                                         object_copy(q_ptr, o_ptr);
5473
5474                                         /* Modify quantity */
5475                                         q_ptr->number = 1;
5476
5477                                         /* Restore the charges */
5478                                         o_ptr->pval++;
5479
5480                                         /* Unstack the used item */
5481                                         o_ptr->number--;
5482                                         p_ptr->total_weight -= q_ptr->weight;
5483                                         item = inven_carry(q_ptr);
5484
5485                                         /* Message */
5486                                         msg_print(_("杖をまとめなおした。", "You unstack your staff."));
5487                                 }
5488                         }
5489                         else
5490                         {
5491                                 msg_print(_("吸収できる魔力がありません!", "There's no energy there to absorb!"));
5492                         }
5493                         if (!o_ptr->pval) o_ptr->ident |= IDENT_EMPTY;
5494                 }
5495         }
5496
5497         /* Inflict the penalties for failing a recharge. */
5498         if (fail)
5499         {
5500                 /* Artifacts are never destroyed. */
5501                 if (object_is_fixed_artifact(o_ptr))
5502                 {
5503                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
5504                         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
5505
5506                         /* Artifact rods. */
5507                         if (o_ptr->tval == TV_ROD)
5508                                 o_ptr->timeout = k_ptr->pval * o_ptr->number;
5509
5510                         /* Artifact wands and staffs. */
5511                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
5512                                 o_ptr->pval = 0;
5513                 }
5514                 else
5515                 {
5516                         /* Get the object description */
5517                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
5518
5519                         /*** Determine Seriousness of Failure ***/
5520
5521                         /* Mages recharge objects more safely. */
5522                         if (p_ptr->pclass == CLASS_MAGE || p_ptr->pclass == CLASS_HIGH_MAGE || p_ptr->pclass == CLASS_SORCERER || p_ptr->pclass == CLASS_MAGIC_EATER || p_ptr->pclass == CLASS_BLUE_MAGE)
5523                         {
5524                                 /* 10% chance to blow up one rod, otherwise draining. */
5525                                 if (o_ptr->tval == TV_ROD)
5526                                 {
5527                                         if (one_in_(10)) fail_type = 2;
5528                                         else fail_type = 1;
5529                                 }
5530                                 /* 75% chance to blow up one wand, otherwise draining. */
5531                                 else if (o_ptr->tval == TV_WAND)
5532                                 {
5533                                         if (!one_in_(3)) fail_type = 2;
5534                                         else fail_type = 1;
5535                                 }
5536                                 /* 50% chance to blow up one staff, otherwise no effect. */
5537                                 else if (o_ptr->tval == TV_STAFF)
5538                                 {
5539                                         if (one_in_(2)) fail_type = 2;
5540                                         else fail_type = 0;
5541                                 }
5542                         }
5543
5544                         /* All other classes get no special favors. */
5545                         else
5546                         {
5547                                 /* 33% chance to blow up one rod, otherwise draining. */
5548                                 if (o_ptr->tval == TV_ROD)
5549                                 {
5550                                         if (one_in_(3)) fail_type = 2;
5551                                         else fail_type = 1;
5552                                 }
5553                                 /* 20% chance of the entire stack, else destroy one wand. */
5554                                 else if (o_ptr->tval == TV_WAND)
5555                                 {
5556                                         if (one_in_(5)) fail_type = 3;
5557                                         else fail_type = 2;
5558                                 }
5559                                 /* Blow up one staff. */
5560                                 else if (o_ptr->tval == TV_STAFF)
5561                                 {
5562                                         fail_type = 2;
5563                                 }
5564                         }
5565
5566                         /*** Apply draining and destruction. ***/
5567
5568                         /* Drain object or stack of objects. */
5569                         if (fail_type == 1)
5570                         {
5571                                 if (o_ptr->tval == TV_ROD)
5572                                 {
5573                                         msg_format(_("ロッドは破損を免れたが、魔力は全て失なわれた。",
5574                                                                  "You save your rod from destruction, but all charges are lost."), o_name);
5575                                         o_ptr->timeout = k_ptr->pval * o_ptr->number;
5576                                 }
5577                                 else if (o_ptr->tval == TV_WAND)
5578                                 {
5579                                         msg_format(_("%sは破損を免れたが、魔力が全て失われた。", "You save your %s from destruction, but all charges are lost."), o_name);
5580                                         o_ptr->pval = 0;
5581                                 }
5582                                 /* Staffs aren't drained. */
5583                         }
5584
5585                         /* Destroy an object or one in a stack of objects. */
5586                         if (fail_type == 2)
5587                         {
5588                                 if (o_ptr->number > 1)
5589                                 {
5590                                         msg_format(_("乱暴な魔法のために%sが一本壊れた!", "Wild magic consumes one of your %s!"), o_name);
5591                                         /* Reduce rod stack maximum timeout, drain wands. */
5592                                         if (o_ptr->tval == TV_ROD) o_ptr->timeout = MIN(o_ptr->timeout, k_ptr->pval * (o_ptr->number - 1));
5593                                         else if (o_ptr->tval == TV_WAND) o_ptr->pval = o_ptr->pval * (o_ptr->number - 1) / o_ptr->number;
5594                                 }
5595                                 else
5596                                 {
5597                                         msg_format(_("乱暴な魔法のために%sが何本か壊れた!", "Wild magic consumes your %s!"), o_name);
5598                                 }
5599                                 
5600                                 /* Reduce and describe inventory */
5601                                 if (item >= 0)
5602                                 {
5603                                         inven_item_increase(item, -1);
5604                                         inven_item_describe(item);
5605                                         inven_item_optimize(item);
5606                                 }
5607
5608                                 /* Reduce and describe floor item */
5609                                 else
5610                                 {
5611                                         floor_item_increase(0 - item, -1);
5612                                         floor_item_describe(0 - item);
5613                                         floor_item_optimize(0 - item);
5614                                 }
5615                         }
5616
5617                         /* Destroy all members of a stack of objects. */
5618                         if (fail_type == 3)
5619                         {
5620                                 if (o_ptr->number > 1)
5621                                         msg_format(_("乱暴な魔法のために%sが全て壊れた!", "Wild magic consumes all your %s!"), o_name);
5622                                 else
5623                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
5624
5625                                 /* Reduce and describe inventory */
5626                                 if (item >= 0)
5627                                 {
5628                                         inven_item_increase(item, -999);
5629                                         inven_item_describe(item);
5630                                         inven_item_optimize(item);
5631                                 }
5632
5633                                 /* Reduce and describe floor item */
5634                                 else
5635                                 {
5636                                         floor_item_increase(0 - item, -999);
5637                                         floor_item_describe(0 - item);
5638                                         floor_item_optimize(0 - item);
5639                                 }
5640                         }
5641                 }
5642         }
5643
5644         if (p_ptr->csp > p_ptr->msp)
5645         {
5646                 p_ptr->csp = p_ptr->msp;
5647         }
5648
5649         /* Redraw mana and hp */
5650         p_ptr->redraw |= (PR_MANA);
5651
5652         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
5653         p_ptr->window |= (PW_INVEN);
5654
5655         return TRUE;
5656 }
5657
5658 /*!
5659  * @brief 同族召喚(援軍)処理
5660  * @param level 召喚基準レベル
5661  * @param y 召喚先Y座標
5662  * @param x 召喚先X座標
5663  * @param mode 召喚オプション
5664  * @return ターンを消費した場合TRUEを返す
5665  */
5666 bool summon_kin_player(int level, int y, int x, BIT_FLAGS mode)
5667 {
5668         bool pet = (bool)(mode & PM_FORCE_PET);
5669         if (!pet) mode |= PM_NO_PET;
5670
5671         switch (p_ptr->mimic_form)
5672         {
5673         case MIMIC_NONE:
5674                 switch (p_ptr->prace)
5675                 {
5676                         case RACE_HUMAN:
5677                         case RACE_AMBERITE:
5678                         case RACE_BARBARIAN:
5679                         case RACE_BEASTMAN:
5680                         case RACE_DUNADAN:
5681                                 summon_kin_type = 'p';
5682                                 break;
5683                         case RACE_HALF_ELF:
5684                         case RACE_ELF:
5685                         case RACE_HOBBIT:
5686                         case RACE_GNOME:
5687                         case RACE_DWARF:
5688                         case RACE_HIGH_ELF:
5689                         case RACE_NIBELUNG:
5690                         case RACE_DARK_ELF:
5691                         case RACE_MIND_FLAYER:
5692                         case RACE_KUTAR:
5693                         case RACE_S_FAIRY:
5694                                 summon_kin_type = 'h';
5695                                 break;
5696                         case RACE_HALF_ORC:
5697                                 summon_kin_type = 'o';
5698                                 break;
5699                         case RACE_HALF_TROLL:
5700                                 summon_kin_type = 'T';
5701                                 break;
5702                         case RACE_HALF_OGRE:
5703                                 summon_kin_type = 'O';
5704                                 break;
5705                         case RACE_HALF_GIANT:
5706                         case RACE_HALF_TITAN:
5707                         case RACE_CYCLOPS:
5708                                 summon_kin_type = 'P';
5709                                 break;
5710                         case RACE_YEEK:
5711                                 summon_kin_type = 'y';
5712                                 break;
5713                         case RACE_KLACKON:
5714                                 summon_kin_type = 'K';
5715                                 break;
5716                         case RACE_KOBOLD:
5717                                 summon_kin_type = 'k';
5718                                 break;
5719                         case RACE_IMP:
5720                                 if (one_in_(13)) summon_kin_type = 'U';
5721                                 else summon_kin_type = 'u';
5722                                 break;
5723                         case RACE_DRACONIAN:
5724                                 summon_kin_type = 'd';
5725                                 break;
5726                         case RACE_GOLEM:
5727                         case RACE_ANDROID:
5728                                 summon_kin_type = 'g';
5729                                 break;
5730                         case RACE_SKELETON:
5731                                 if (one_in_(13)) summon_kin_type = 'L';
5732                                 else summon_kin_type = 's';
5733                                 break;
5734                         case RACE_ZOMBIE:
5735                                 summon_kin_type = 'z';
5736                                 break;
5737                         case RACE_VAMPIRE:
5738                                 summon_kin_type = 'V';
5739                                 break;
5740                         case RACE_SPECTRE:
5741                                 summon_kin_type = 'G';
5742                                 break;
5743                         case RACE_SPRITE:
5744                                 summon_kin_type = 'I';
5745                                 break;
5746                         case RACE_ENT:
5747                                 summon_kin_type = '#';
5748                                 break;
5749                         case RACE_ANGEL:
5750                                 summon_kin_type = 'A';
5751                                 break;
5752                         case RACE_DEMON:
5753                                 summon_kin_type = 'U';
5754                                 break;
5755                         default:
5756                                 summon_kin_type = 'p';
5757                                 break;
5758                 }
5759                 break;
5760         case MIMIC_DEMON:
5761                 if (one_in_(13)) summon_kin_type = 'U';
5762                 else summon_kin_type = 'u';
5763                 break;
5764         case MIMIC_DEMON_LORD:
5765                 summon_kin_type = 'U';
5766                 break;
5767         case MIMIC_VAMPIRE:
5768                 summon_kin_type = 'V';
5769                 break;
5770         }       
5771         return summon_specific((pet ? -1 : 0), y, x, level, SUMMON_KIN, mode);
5772 }
5773
5774 /*!
5775  * @brief 皆殺し(全方向攻撃)処理
5776  * @param py プレイヤーY座標
5777  * @param px プレイヤーX座標
5778  * @return なし
5779  */
5780 void massacre(void)
5781 {
5782         int x, y;
5783         cave_type       *c_ptr;
5784         monster_type    *m_ptr;
5785         int dir;
5786
5787         for (dir = 0; dir < 8; dir++)
5788         {
5789                 y = p_ptr->y + ddy_ddd[dir];
5790                 x = p_ptr->x + ddx_ddd[dir];
5791                 c_ptr = &cave[y][x];
5792
5793                 /* Get the monster */
5794                 m_ptr = &m_list[c_ptr->m_idx];
5795
5796                 /* Hack -- attack monsters */
5797                 if (c_ptr->m_idx && (m_ptr->ml || cave_have_flag_bold(y, x, FF_PROJECT)))
5798                         py_attack(y, x, 0);
5799         }
5800 }