OSDN Git Service

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