OSDN Git Service

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