OSDN Git Service

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