OSDN Git Service

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