OSDN Git Service

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