OSDN Git Service

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