OSDN Git Service

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