OSDN Git Service

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