OSDN Git Service

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