OSDN Git Service

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