OSDN Git Service

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