OSDN Git Service

[Refactor] #38997 project() に player_type * 引数を追加. / Add player_type * argument to...
[hengband/hengband.git] / src / spells3.c
1 /*!
2  * @file spells3.c
3  * @brief 魔法効果の実装/ Spell code (part 3)
4  * @date 2014/07/26
5  * @author
6  * <pre>
7  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  * </pre>
12  */
13
14 #include "angband.h"
15 #include "bldg.h"
16 #include "core.h"
17 #include "term.h"
18 #include "util.h"
19 #include "object-ego.h"
20
21 #include "creature.h"
22
23 #include "dungeon.h"
24 #include "floor.h"
25 #include "floor-town.h"
26 #include "object-boost.h"
27 #include "object-flavor.h"
28 #include "object-hook.h"
29 #include "melee.h"
30 #include "player-move.h"
31 #include "player-status.h"
32 #include "player-class.h"
33 #include "player-damage.h"
34 #include "player-inventory.h"
35 #include "spells-summon.h"
36 #include "quest.h"
37 #include "artifact.h"
38 #include "avatar.h"
39 #include "spells.h"
40 #include "spells-floor.h"
41 #include "grid.h"
42 #include "monster-process.h"
43 #include "monster-status.h"
44 #include "monster-spell.h"
45 #include "cmd-spell.h"
46 #include "cmd-dump.h"
47 #include "snipe.h"
48 #include "floor-save.h"
49 #include "files.h"
50 #include "player-effects.h"
51 #include "player-skill.h"
52 #include "player-personality.h"
53 #include "view-mainwindow.h"
54 #include "mind.h"
55 #include "wild.h"
56 #include "world.h"
57 #include "objectkind.h"
58 #include "autopick.h"
59 #include "targeting.h"
60
61
62 /*! テレポート先探索の試行数 / Maximum number of tries for teleporting */
63 #define MAX_TRIES 100
64
65
66 /*!
67  * @brief モンスターのテレポートアウェイ処理 /
68  * Teleport a monster, normally up to "dis" grids away.
69  * @param m_idx モンスターID
70  * @param dis テレポート距離
71  * @param mode オプション
72  * @return テレポートが実際に行われたらtrue
73  * @details
74  * Attempt to move the monster at least "dis/2" grids away.
75  * But allow variation to prevent infinite loops.
76  */
77 bool teleport_away(player_type *caster_ptr, MONSTER_IDX m_idx, POSITION dis, BIT_FLAGS mode)
78 {
79         POSITION oy, ox, d, i, min;
80         int tries = 0;
81         POSITION ny = 0, nx = 0;
82
83         bool look = TRUE;
84
85         monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[m_idx];
86         if (!monster_is_valid(m_ptr)) return (FALSE);
87
88         oy = m_ptr->fy;
89         ox = m_ptr->fx;
90
91         /* Minimum distance */
92         min = dis / 2;
93
94         if ((mode & TELEPORT_DEC_VALOUR) &&
95             (((caster_ptr->chp * 10) / caster_ptr->mhp) > 5) &&
96                 (4+randint1(5) < ((caster_ptr->chp * 10) / caster_ptr->mhp)))
97         {
98                 chg_virtue(caster_ptr, V_VALOUR, -1);
99         }
100
101         /* Look until done */
102         while (look)
103         {
104                 tries++;
105
106                 /* Verify max distance */
107                 if (dis > 200) dis = 200;
108
109                 /* Try several locations */
110                 for (i = 0; i < 500; i++)
111                 {
112                         /* Pick a (possibly illegal) location */
113                         while (1)
114                         {
115                                 ny = rand_spread(oy, dis);
116                                 nx = rand_spread(ox, dis);
117                                 d = distance(oy, ox, ny, nx);
118                                 if ((d >= min) && (d <= dis)) break;
119                         }
120
121                         /* Ignore illegal locations */
122                         if (!in_bounds(caster_ptr->current_floor_ptr, ny, nx)) continue;
123
124                         if (!cave_monster_teleportable_bold(m_idx, ny, nx, mode)) continue;
125
126                         /* No teleporting into vaults and such */
127                         if (!(caster_ptr->current_floor_ptr->inside_quest || caster_ptr->current_floor_ptr->inside_arena))
128                                 if (caster_ptr->current_floor_ptr->grid_array[ny][nx].info & CAVE_ICKY) continue;
129
130                         /* This grid looks good */
131                         look = FALSE;
132
133                         /* Stop looking */
134                         break;
135                 }
136
137                 /* Increase the maximum distance */
138                 dis = dis * 2;
139
140                 /* Decrease the minimum distance */
141                 min = min / 2;
142
143                 /* Stop after MAX_TRIES tries */
144                 if (tries > MAX_TRIES) return (FALSE);
145         }
146
147         sound(SOUND_TPOTHER);
148
149         /* Update the old location */
150         caster_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = 0;
151
152         /* Update the new location */
153         caster_ptr->current_floor_ptr->grid_array[ny][nx].m_idx = m_idx;
154
155         /* Move the monster */
156         m_ptr->fy = ny;
157         m_ptr->fx = nx;
158
159         /* Forget the counter target */
160         reset_target(m_ptr);
161
162         update_monster(caster_ptr, m_idx, TRUE);
163         lite_spot(oy, ox);
164         lite_spot(ny, nx);
165
166         if (r_info[m_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
167                 caster_ptr->update |= (PU_MON_LITE);
168
169         return (TRUE);
170 }
171
172
173 /*!
174  * @brief モンスターを指定された座標付近にテレポートする /
175  * Teleport monster next to a grid near the given location
176  * @param m_idx モンスターID
177  * @param ty 目安Y座標
178  * @param tx 目安X座標
179  * @param power テレポート成功確率
180  * @param mode オプション
181  * @return なし
182  */
183 void teleport_monster_to(MONSTER_IDX m_idx, POSITION ty, POSITION tx, int power, BIT_FLAGS mode)
184 {
185         POSITION ny, nx, oy, ox;
186         int d, i, min;
187         int attempts = 500;
188         POSITION dis = 2;
189         bool look = TRUE;
190         monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
191         if(!m_ptr->r_idx) return;
192
193         /* "Skill" test */
194         if(randint1(100) > power) return;
195
196         ny = m_ptr->fy;
197         nx = m_ptr->fx;
198         oy = m_ptr->fy;
199         ox = m_ptr->fx;
200
201         /* Minimum distance */
202         min = dis / 2;
203
204         /* Look until done */
205         while (look && --attempts)
206         {
207                 /* Verify max distance */
208                 if (dis > 200) dis = 200;
209
210                 /* Try several locations */
211                 for (i = 0; i < 500; i++)
212                 {
213                         /* Pick a (possibly illegal) location */
214                         while (1)
215                         {
216                                 ny = rand_spread(ty, dis);
217                                 nx = rand_spread(tx, dis);
218                                 d = distance(ty, tx, ny, nx);
219                                 if ((d >= min) && (d <= dis)) break;
220                         }
221
222                         /* Ignore illegal locations */
223                         if (!in_bounds(p_ptr->current_floor_ptr, ny, nx)) continue;
224
225                         if (!cave_monster_teleportable_bold(m_idx, ny, nx, mode)) continue;
226
227                         /* 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(p_ptr, 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(creature_ptr, 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(player_type *creature_ptr, POSITION dis, BIT_FLAGS mode)
404 {
405         POSITION yy, xx;
406         POSITION oy = creature_ptr->y;
407         POSITION ox = creature_ptr->x;
408
409         if (!teleport_player_aux(creature_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 = creature_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 && (creature_ptr->riding != tmp_m_idx))
420                         {
421                                 monster_type *m_ptr = &creature_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, creature_ptr->y, creature_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(player_type *creature_ptr, POSITION ny, POSITION nx, BIT_FLAGS mode)
495 {
496         POSITION y, x;
497         POSITION dis = 0, ctr = 0;
498
499         if (creature_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(creature_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) && (!creature_ptr->current_floor_ptr->grid_array[y][x].m_idx || (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx == creature_ptr->riding))) break;
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(creature_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(p_ptr, 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->current_floor_ptr, 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(p_ptr, 200, TELEPORT_PASSIVE);
578                                         msg_print(_("失敗!", "Failed!"));
579                                 }
580                                 else teleport_player_to(p_ptr, 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(p_ptr, target_row, target_col)) return TRUE;
599         if (!projectable(creature_ptr->current_floor_ptr, 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(creature_ptr, 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(player_type *creature_ptr, 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 = &creature_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) && creature_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)) || (creature_ptr->current_floor_ptr->dun_level <= d_info[creature_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 (!creature_ptr->current_floor_ptr->dun_level)
674                         {
675                                 creature_ptr->dungeon_idx = ironman_downward ? DUNGEON_ANGBAND : creature_ptr->recall_dungeon;
676                                 creature_ptr->oldpy = creature_ptr->y;
677                                 creature_ptr->oldpx = creature_ptr->x;
678                         }
679
680                         if (record_stair) exe_write_diary(creature_ptr, NIKKI_TELE_LEV, 1, NULL);
681
682                         if (autosave_l) do_cmd_save_game(TRUE);
683
684                         if (!creature_ptr->current_floor_ptr->dun_level)
685                         {
686                                 creature_ptr->current_floor_ptr->dun_level = d_info[creature_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                         creature_ptr->leaving = TRUE;
694                 }
695         }
696
697         /* Up only */
698         else if (quest_number(creature_ptr->current_floor_ptr->dun_level) || (creature_ptr->current_floor_ptr->dun_level >= d_info[creature_ptr->dungeon_idx].maxdepth))
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(creature_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                         creature_ptr->current_floor_ptr->inside_quest = 0;
717                         creature_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(creature_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                         creature_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 (!creature_ptr->current_floor_ptr->dun_level) creature_ptr->dungeon_idx = creature_ptr->recall_dungeon; */
751                         if (record_stair) exe_write_diary(creature_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                         creature_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 = &creature_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(creature_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->current_floor_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->current_floor_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(player_type *target_ptr, 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 = &target_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(target_ptr, V_HARMONY, 1);
1017                 chg_virtue(target_ptr, V_ENCHANT, -2);
1018                 target_ptr->update |= (PU_BONUS);
1019                 target_ptr->window |= (PW_EQUIP | PW_PLAYER);
1020
1021                 calc_android_exp(target_ptr);
1022         }
1023
1024         return (TRUE);
1025 }
1026
1027
1028 /*!
1029  * @brief 虚無招来によるフロア中の全壁除去処理 /
1030  * Vanish all walls in this floor
1031  * @params caster_ptr 術者の参照ポインタ
1032  * @return 実際に処理が反映された場合TRUE
1033  */
1034 bool vanish_dungeon(player_type *caster_ptr)
1035 {
1036         POSITION y, x;
1037         grid_type *g_ptr;
1038         feature_type *f_ptr;
1039         monster_type *m_ptr;
1040         GAME_TEXT m_name[MAX_NLEN];
1041
1042         /* Prevent vasishing of quest levels and town */
1043         if ((caster_ptr->current_floor_ptr->inside_quest && is_fixed_quest_idx(caster_ptr->current_floor_ptr->inside_quest)) || !caster_ptr->current_floor_ptr->dun_level)
1044         {
1045                 return FALSE;
1046         }
1047
1048         /* Scan all normal grids */
1049         for (y = 1; y < caster_ptr->current_floor_ptr->height - 1; y++)
1050         {
1051                 for (x = 1; x < caster_ptr->current_floor_ptr->width - 1; x++)
1052                 {
1053                         g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][x];
1054
1055                         /* Seeing true feature code (ignore mimic) */
1056                         f_ptr = &f_info[g_ptr->feat];
1057
1058                         /* Lose room and vault */
1059                         g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1060
1061                         m_ptr = &caster_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
1062
1063                         /* Awake monster */
1064                         if (g_ptr->m_idx && MON_CSLEEP(m_ptr))
1065                         {
1066                                 (void)set_monster_csleep(g_ptr->m_idx, 0);
1067
1068                                 /* Notice the "waking up" */
1069                                 if (m_ptr->ml)
1070                                 {
1071                                         monster_desc(m_name, m_ptr, 0);
1072                                         msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1073                                 }
1074                         }
1075
1076                         /* Process all walls, doors and patterns */
1077                         if (have_flag(f_ptr->flags, FF_HURT_DISI)) cave_alter_feat(y, x, FF_HURT_DISI);
1078                 }
1079         }
1080
1081         /* Special boundary walls -- Top and bottom */
1082         for (x = 0; x < caster_ptr->current_floor_ptr->width; x++)
1083         {
1084                 g_ptr = &caster_ptr->current_floor_ptr->grid_array[0][x];
1085                 f_ptr = &f_info[g_ptr->mimic];
1086
1087                 /* Lose room and vault */
1088                 g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1089
1090                 /* Set boundary mimic if needed */
1091                 if (g_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1092                 {
1093                         g_ptr->mimic = feat_state(g_ptr->mimic, FF_HURT_DISI);
1094
1095                         /* Check for change to boring grid */
1096                         if (!have_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1097                 }
1098
1099                 g_ptr = &caster_ptr->current_floor_ptr->grid_array[caster_ptr->current_floor_ptr->height - 1][x];
1100                 f_ptr = &f_info[g_ptr->mimic];
1101
1102                 /* Lose room and vault */
1103                 g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1104
1105                 /* Set boundary mimic if needed */
1106                 if (g_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1107                 {
1108                         g_ptr->mimic = feat_state(g_ptr->mimic, FF_HURT_DISI);
1109
1110                         /* Check for change to boring grid */
1111                         if (!have_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1112                 }
1113         }
1114
1115         /* Special boundary walls -- Left and right */
1116         for (y = 1; y < (caster_ptr->current_floor_ptr->height - 1); y++)
1117         {
1118                 g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][0];
1119                 f_ptr = &f_info[g_ptr->mimic];
1120
1121                 /* Lose room and vault */
1122                 g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1123
1124                 /* Set boundary mimic if needed */
1125                 if (g_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1126                 {
1127                         g_ptr->mimic = feat_state(g_ptr->mimic, FF_HURT_DISI);
1128
1129                         /* Check for change to boring grid */
1130                         if (!have_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1131                 }
1132
1133                 g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][caster_ptr->current_floor_ptr->width - 1];
1134                 f_ptr = &f_info[g_ptr->mimic];
1135
1136                 /* Lose room and vault */
1137                 g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1138
1139                 /* Set boundary mimic if needed */
1140                 if (g_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1141                 {
1142                         g_ptr->mimic = feat_state(g_ptr->mimic, FF_HURT_DISI);
1143
1144                         /* Check for change to boring grid */
1145                         if (!have_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1146                 }
1147         }
1148
1149         /* Mega-Hack -- Forget the view and lite */
1150         caster_ptr->update |= (PU_UN_VIEW | PU_UN_LITE | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
1151         caster_ptr->redraw |= (PR_MAP);
1152         caster_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1153
1154         return TRUE;
1155 }
1156
1157 /*!
1158  * @brief 虚無招来処理 /
1159  * @return なし
1160  * @details
1161  * Sorry, it becomes not (void)...
1162  */
1163 void call_the_void(player_type *caster_ptr)
1164 {
1165         int i;
1166         grid_type *g_ptr;
1167         bool do_call = TRUE;
1168
1169         for (i = 0; i < 9; i++)
1170         {
1171                 g_ptr = &caster_ptr->current_floor_ptr->grid_array[caster_ptr->y + ddy_ddd[i]][caster_ptr->x + ddx_ddd[i]];
1172
1173                 if (!cave_have_flag_grid(g_ptr, FF_PROJECT))
1174                 {
1175                         if (!g_ptr->mimic || !have_flag(f_info[g_ptr->mimic].flags, FF_PROJECT) ||
1176                             !permanent_wall(&f_info[g_ptr->feat]))
1177                         {
1178                                 do_call = FALSE;
1179                                 break;
1180                         }
1181                 }
1182         }
1183
1184         if (do_call)
1185         {
1186                 for (i = 1; i < 10; i++)
1187                 {
1188                         if (i - 5) fire_ball(caster_ptr, GF_ROCKET, i, 175, 2);
1189                 }
1190
1191                 for (i = 1; i < 10; i++)
1192                 {
1193                         if (i - 5) fire_ball(caster_ptr, GF_MANA, i, 175, 3);
1194                 }
1195
1196                 for (i = 1; i < 10; i++)
1197                 {
1198                         if (i - 5) fire_ball(caster_ptr, GF_NUKE, i, 175, 4);
1199                 }
1200         }
1201
1202         /* Prevent destruction of quest levels and town */
1203         else if ((caster_ptr->current_floor_ptr->inside_quest && is_fixed_quest_idx(caster_ptr->current_floor_ptr->inside_quest)) || !caster_ptr->current_floor_ptr->dun_level)
1204         {
1205                 msg_print(_("地面が揺れた。", "The ground trembles."));
1206         }
1207
1208         else
1209         {
1210 #ifdef JP
1211                 msg_format("あなたは%sを壁に近すぎる場所で唱えてしまった!",
1212                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "祈り" : "呪文"));
1213 #else
1214                 msg_format("You %s the %s too close to a wall!",
1215                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1216                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "prayer" : "spell"));
1217 #endif
1218                 msg_print(_("大きな爆発音があった!", "There is a loud explosion!"));
1219
1220                 if (one_in_(666))
1221                 {
1222                         if (!vanish_dungeon(caster_ptr)) msg_print(_("ダンジョンは一瞬静まり返った。", "The dungeon silences a moment."));
1223                 }
1224                 else
1225                 {
1226                         if (destroy_area(caster_ptr->current_floor_ptr, caster_ptr->y, caster_ptr->x, 15 + caster_ptr->lev + randint0(11), FALSE))
1227                                 msg_print(_("ダンジョンが崩壊した...", "The dungeon collapses..."));
1228                         else
1229                                 msg_print(_("ダンジョンは大きく揺れた。", "The dungeon trembles."));
1230                 }
1231
1232                 take_hit(caster_ptr, DAMAGE_NOESCAPE, 100 + randint1(150), _("自殺的な虚無招来", "a suicidal Call the Void"), -1);
1233         }
1234 }
1235
1236
1237 /*!
1238  * @brief アイテム引き寄せ処理 /
1239  * Fetch an item (teleport it right underneath the caster)
1240  * @param dir 魔法の発動方向
1241  * @param wgt 許容重量
1242  * @param require_los 射線の通りを要求するならばTRUE
1243  * @return なし
1244  */
1245 void fetch(player_type *caster_ptr, DIRECTION dir, WEIGHT wgt, bool require_los)
1246 {
1247         POSITION ty, tx;
1248         OBJECT_IDX i;
1249         grid_type *g_ptr;
1250         object_type *o_ptr;
1251         GAME_TEXT o_name[MAX_NLEN];
1252
1253         /* Check to see if an object is already there */
1254         if (caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].o_idx)
1255         {
1256                 msg_print(_("自分の足の下にある物は取れません。", "You can't fetch when you're already standing on something."));
1257                 return;
1258         }
1259
1260         /* Use a target */
1261         if (dir == 5 && target_okay())
1262         {
1263                 tx = target_col;
1264                 ty = target_row;
1265
1266                 if (distance(caster_ptr->y, caster_ptr->x, ty, tx) > MAX_RANGE)
1267                 {
1268                         msg_print(_("そんなに遠くにある物は取れません!", "You can't fetch something that far away!"));
1269                         return;
1270                 }
1271
1272                 g_ptr = &caster_ptr->current_floor_ptr->grid_array[ty][tx];
1273
1274                 /* We need an item to fetch */
1275                 if (!g_ptr->o_idx)
1276                 {
1277                         msg_print(_("そこには何もありません。", "There is no object at this place."));
1278                         return;
1279                 }
1280
1281                 /* No fetching from vault */
1282                 if (g_ptr->info & CAVE_ICKY)
1283                 {
1284                         msg_print(_("アイテムがコントロールを外れて落ちた。", "The item slips from your control."));
1285                         return;
1286                 }
1287
1288                 /* We need to see the item */
1289                 if (require_los)
1290                 {
1291                         if (!player_has_los_bold(p_ptr, ty, tx))
1292                         {
1293                                 msg_print(_("そこはあなたの視界に入っていません。", "You have no direct line of sight to that location."));
1294                                 return;
1295                         }
1296                         else if (!projectable(caster_ptr->current_floor_ptr, caster_ptr->y, caster_ptr->x, ty, tx))
1297                         {
1298                                 msg_print(_("そこは壁の向こうです。", "You have no direct line of sight to that location."));
1299                                 return;
1300                         }
1301                 }
1302         }
1303         else
1304         {
1305                 ty = caster_ptr->y; 
1306                 tx = caster_ptr->x;
1307                 do
1308                 {
1309                         ty += ddy[dir];
1310                         tx += ddx[dir];
1311                         g_ptr = &caster_ptr->current_floor_ptr->grid_array[ty][tx];
1312
1313                         if ((distance(caster_ptr->y, caster_ptr->x, ty, tx) > MAX_RANGE) ||
1314                                 !cave_have_flag_bold(ty, tx, FF_PROJECT)) return;
1315                 }
1316                 while (!g_ptr->o_idx);
1317         }
1318
1319         o_ptr = &caster_ptr->current_floor_ptr->o_list[g_ptr->o_idx];
1320
1321         if (o_ptr->weight > wgt)
1322         {
1323                 /* Too heavy to 'fetch' */
1324                 msg_print(_("そのアイテムは重過ぎます。", "The object is too heavy."));
1325                 return;
1326         }
1327
1328         i = g_ptr->o_idx;
1329         g_ptr->o_idx = o_ptr->next_o_idx;
1330         caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].o_idx = i; /* 'move' it */
1331
1332         o_ptr->next_o_idx = 0;
1333         o_ptr->iy = caster_ptr->y;
1334         o_ptr->ix = caster_ptr->x;
1335
1336         object_desc(o_name, o_ptr, OD_NAME_ONLY);
1337         msg_format(_("%^sがあなたの足元に飛んできた。", "%^s flies through the air to your feet."), o_name);
1338
1339         note_spot(caster_ptr->y, caster_ptr->x);
1340         caster_ptr->redraw |= PR_MAP;
1341 }
1342
1343 /*!
1344  * @brief 現実変容処理
1345  * @return なし
1346  */
1347 void alter_reality(void)
1348 {
1349         /* Ironman option */
1350         if (p_ptr->current_floor_ptr->inside_arena || ironman_downward)
1351         {
1352                 msg_print(_("何も起こらなかった。", "Nothing happens."));
1353                 return;
1354         }
1355
1356         if (!p_ptr->alter_reality)
1357         {
1358                 TIME_EFFECT turns = randint0(21) + 15;
1359
1360                 p_ptr->alter_reality = turns;
1361                 msg_print(_("回りの景色が変わり始めた...", "The view around you begins to change..."));
1362
1363                 p_ptr->redraw |= (PR_STATUS);
1364         }
1365         else
1366         {
1367                 p_ptr->alter_reality = 0;
1368                 msg_print(_("景色が元に戻った...", "The view around you got back..."));
1369                 p_ptr->redraw |= (PR_STATUS);
1370         }
1371         return;
1372 }
1373
1374 /*!
1375  * @brief 全所持アイテム鑑定処理 /
1376  * Identify everything being carried.
1377  * Done by a potion of "self knowledge".
1378  * @return なし
1379  */
1380 void identify_pack(void)
1381 {
1382         INVENTORY_IDX i;
1383
1384         /* Simply identify and know every item */
1385         for (i = 0; i < INVEN_TOTAL; i++)
1386         {
1387                 object_type *o_ptr = &p_ptr->inventory_list[i];
1388                 if (!o_ptr->k_idx) continue;
1389
1390                 identify_item(o_ptr);
1391
1392                 /* Auto-inscription */
1393                 autopick_alter_item(i, FALSE);
1394         }
1395 }
1396
1397 /*!
1398  * @brief 装備の解呪処理 /
1399  * Removes curses from items in p_ptr->inventory_list
1400  * @param all 軽い呪いまでの解除ならば0
1401  * @return 解呪されたアイテムの数
1402  * @details
1403  * <pre>
1404  * Note that Items which are "Perma-Cursed" (The One Ring,
1405  * The Crown of Morgoth) can NEVER be uncursed.
1406  *
1407  * Note that if "all" is FALSE, then Items which are
1408  * "Heavy-Cursed" (Mormegil, Calris, and Weapons of Morgul)
1409  * will not be uncursed.
1410  * </pre>
1411  */
1412 static int remove_curse_aux(player_type *creature_ptr, int all)
1413 {
1414         int i, cnt = 0;
1415
1416         /* Attempt to uncurse items being worn */
1417         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
1418         {
1419                 object_type *o_ptr = &creature_ptr->inventory_list[i];
1420                 if (!o_ptr->k_idx) continue;
1421
1422                 /* Uncursed already */
1423                 if (!object_is_cursed(o_ptr)) continue;
1424
1425                 /* Heavily Cursed Items need a special spell */
1426                 if (!all && (o_ptr->curse_flags & TRC_HEAVY_CURSE)) continue;
1427
1428                 /* Perma-Cursed Items can NEVER be uncursed */
1429                 if (o_ptr->curse_flags & TRC_PERMA_CURSE)
1430                 {
1431                         o_ptr->curse_flags &= (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE);
1432                         continue;
1433                 }
1434
1435                 o_ptr->curse_flags = 0L;
1436                 o_ptr->ident |= (IDENT_SENSE);
1437                 o_ptr->feeling = FEEL_NONE;
1438
1439                 creature_ptr->update |= (PU_BONUS);
1440                 creature_ptr->window |= (PW_EQUIP);
1441
1442                 /* Count the uncursings */
1443                 cnt++;
1444         }
1445
1446         if (cnt)
1447         {
1448                 msg_print(_("誰かに見守られているような気がする。", "You feel as if someone is watching over you."));
1449         }
1450         /* Return "something uncursed" */
1451         return (cnt);
1452 }
1453
1454
1455 /*!
1456  * @brief 装備の軽い呪い解呪処理 /
1457  * Remove most curses
1458  * @return 解呪に成功した装備数
1459  */
1460 int remove_curse(player_type *caster_ptr)
1461 {
1462         return (remove_curse_aux(caster_ptr, FALSE));
1463 }
1464
1465 /*!
1466  * @brief 装備の重い呪い解呪処理 /
1467  * Remove all curses
1468  * @return 解呪に成功した装備数
1469  */
1470 int remove_all_curse(player_type *caster_ptr)
1471 {
1472         return (remove_curse_aux(caster_ptr, TRUE));
1473 }
1474
1475
1476 /*!
1477  * @brief アイテムの価値に応じた錬金術処理 /
1478  * Turns an object into gold, gain some of its value in a shop
1479  * @return 処理が実際に行われたらTRUEを返す
1480  */
1481 bool alchemy(void)
1482 {
1483         OBJECT_IDX item;
1484         int amt = 1;
1485         ITEM_NUMBER old_number;
1486         PRICE price;
1487         bool force = FALSE;
1488         object_type *o_ptr;
1489         GAME_TEXT o_name[MAX_NLEN];
1490         char out_val[MAX_NLEN+40];
1491
1492         concptr q, s;
1493
1494         /* Hack -- force destruction */
1495         if (command_arg > 0) force = TRUE;
1496
1497         q = _("どのアイテムを金に変えますか?", "Turn which item to gold? ");
1498         s = _("金に変えられる物がありません。", "You have nothing to current_world_ptr->game_turn to gold.");
1499
1500         o_ptr = choose_object(p_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
1501         if (!o_ptr) return (FALSE);
1502
1503         /* See how many items */
1504         if (o_ptr->number > 1)
1505         {
1506                 amt = get_quantity(NULL, o_ptr->number);
1507
1508                 /* Allow user abort */
1509                 if (amt <= 0) return FALSE;
1510         }
1511
1512         old_number = o_ptr->number;
1513         o_ptr->number = amt;
1514         object_desc(o_name, o_ptr, 0);
1515         o_ptr->number = old_number;
1516
1517         /* Verify unless quantity given */
1518         if (!force)
1519         {
1520                 if (confirm_destroy || (object_value(o_ptr) > 0))
1521                 {
1522                         /* Make a verification */
1523                         sprintf(out_val, _("本当に%sを金に変えますか?", "Really current_world_ptr->game_turn %s to gold? "), o_name);
1524                         if (!get_check(out_val)) return FALSE;
1525                 }
1526         }
1527
1528         /* Artifacts cannot be destroyed */
1529         if (!can_player_destroy_object(o_ptr))
1530         {
1531                 msg_format(_("%sを金に変えることに失敗した。", "You fail to current_world_ptr->game_turn %s to gold!"), o_name);
1532
1533                 return FALSE;
1534         }
1535
1536         price = object_value_real(o_ptr);
1537
1538         if (price <= 0)
1539         {
1540                 msg_format(_("%sをニセの金に変えた。", "You current_world_ptr->game_turn %s to fool's gold."), o_name);
1541         }
1542         else
1543         {
1544                 price /= 3;
1545
1546                 if (amt > 1) price *= amt;
1547
1548                 if (price > 30000) price = 30000;
1549                 msg_format(_("%sを$%d の金に変えた。", "You current_world_ptr->game_turn %s to %ld coins worth of gold."), o_name, price);
1550
1551                 p_ptr->au += price;
1552                 p_ptr->redraw |= (PR_GOLD);
1553                 p_ptr->window |= (PW_PLAYER);
1554         }
1555
1556         /* Eliminate the item (from the pack) */
1557         if (item >= 0)
1558         {
1559                 inven_item_increase(item, -amt);
1560                 inven_item_describe(item);
1561                 inven_item_optimize(item);
1562         }
1563
1564         /* Eliminate the item (from the floor) */
1565         else
1566         {
1567                 floor_item_increase(0 - item, -amt);
1568                 floor_item_describe(0 - item);
1569                 floor_item_optimize(0 - item);
1570         }
1571
1572         return TRUE;
1573 }
1574
1575
1576 /*!
1577  * @brief アーティファクト生成の巻物処理 /
1578  * @return 生成が実際に試みられたらTRUEを返す
1579  */
1580 bool artifact_scroll(void)
1581 {
1582         OBJECT_IDX item;
1583         bool okay = FALSE;
1584         object_type *o_ptr;
1585         GAME_TEXT o_name[MAX_NLEN];
1586         concptr q, s;
1587
1588         /* Enchant weapon/armour */
1589         item_tester_hook = item_tester_hook_nameless_weapon_armour;
1590
1591         q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
1592         s = _("強化できるアイテムがない。", "You have nothing to enchant.");
1593
1594         o_ptr = choose_object(p_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
1595         if (!o_ptr) return (FALSE);
1596
1597         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1598 #ifdef JP
1599         msg_format("%s は眩い光を発した!",o_name);
1600 #else
1601         msg_format("%s %s radiate%s a blinding light!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
1602 #endif
1603
1604         if (object_is_artifact(o_ptr))
1605         {
1606 #ifdef JP
1607                 msg_format("%sは既に伝説のアイテムです!", o_name  );
1608 #else
1609                 msg_format("The %s %s already %s!", o_name, ((o_ptr->number > 1) ? "are" : "is"), ((o_ptr->number > 1) ? "artifacts" : "an artifact"));
1610 #endif
1611
1612                 okay = FALSE;
1613         }
1614
1615         else if (object_is_ego(o_ptr))
1616         {
1617 #ifdef JP
1618                 msg_format("%sは既に名のあるアイテムです!", o_name );
1619 #else
1620                 msg_format("The %s %s already %s!",
1621                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
1622                     ((o_ptr->number > 1) ? "ego items" : "an ego item"));
1623 #endif
1624
1625                 okay = FALSE;
1626         }
1627
1628         else if (o_ptr->xtra3)
1629         {
1630 #ifdef JP
1631                 msg_format("%sは既に強化されています!", o_name );
1632 #else
1633                 msg_format("The %s %s already %s!", o_name, ((o_ptr->number > 1) ? "are" : "is"),
1634                     ((o_ptr->number > 1) ? "customized items" : "a customized item"));
1635 #endif
1636         }
1637
1638         else
1639         {
1640                 if (o_ptr->number > 1)
1641                 {
1642                         msg_print(_("複数のアイテムに魔法をかけるだけのエネルギーはありません!", "Not enough energy to enchant more than one object!"));
1643 #ifdef JP
1644                         msg_format("%d 個の%sが壊れた!",(o_ptr->number)-1, o_name);
1645 #else
1646                         msg_format("%d of your %s %s destroyed!",(o_ptr->number)-1, o_name, (o_ptr->number>2?"were":"was"));
1647 #endif
1648
1649                         if (item >= 0)
1650                         {
1651                                 inven_item_increase(item, 1 - (o_ptr->number));
1652                         }
1653                         else
1654                         {
1655                                 floor_item_increase(0 - item, 1 - (o_ptr->number));
1656                         }
1657                 }
1658                 okay = become_random_artifact(o_ptr, TRUE);
1659         }
1660
1661         /* Failure */
1662         if (!okay)
1663         {
1664                 if (flush_failure) flush();
1665                 msg_print(_("強化に失敗した。", "The enchantment failed."));
1666                 if (one_in_(3)) chg_virtue(p_ptr, V_ENCHANT, -1);
1667         }
1668         else
1669         {
1670                 if (record_rand_art)
1671                 {
1672                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
1673                         exe_write_diary(p_ptr, NIKKI_ART_SCROLL, 0, o_name);
1674                 }
1675                 chg_virtue(p_ptr, V_ENCHANT, 1);
1676         }
1677
1678         calc_android_exp(p_ptr);
1679
1680         /* Something happened */
1681         return (TRUE);
1682 }
1683
1684
1685 /*!
1686  * @brief アイテム鑑定処理 /
1687  * Identify an object
1688  * @param o_ptr 鑑定されるアイテムの情報参照ポインタ
1689  * @return 実際に鑑定できたらTRUEを返す
1690  */
1691 bool identify_item(object_type *o_ptr)
1692 {
1693         bool old_known = FALSE;
1694         GAME_TEXT o_name[MAX_NLEN];
1695
1696         object_desc(o_name, o_ptr, 0);
1697
1698         if (o_ptr->ident & IDENT_KNOWN)
1699                 old_known = TRUE;
1700
1701         if (!(o_ptr->ident & (IDENT_MENTAL)))
1702         {
1703                 if (object_is_artifact(o_ptr) || one_in_(5))
1704                         chg_virtue(p_ptr, V_KNOWLEDGE, 1);
1705         }
1706
1707         object_aware(o_ptr);
1708         object_known(o_ptr);
1709         o_ptr->marked |= OM_TOUCHED;
1710
1711         p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
1712         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1713
1714         strcpy(record_o_name, o_name);
1715         record_turn = current_world_ptr->game_turn;
1716
1717         object_desc(o_name, o_ptr, OD_NAME_ONLY);
1718
1719         if(record_fix_art && !old_known && object_is_fixed_artifact(o_ptr))
1720                 exe_write_diary(p_ptr, NIKKI_ART, 0, o_name);
1721         if(record_rand_art && !old_known && o_ptr->art_name)
1722                 exe_write_diary(p_ptr, NIKKI_ART, 0, o_name);
1723
1724         return old_known;
1725 }
1726
1727 /*!
1728  * @brief アイテム鑑定のメインルーチン処理 /
1729  * Identify an object in the p_ptr->inventory_list (or on the floor)
1730  * @param only_equip 装備品のみを対象とするならばTRUEを返す
1731  * @return 実際に鑑定を行ったならばTRUEを返す
1732  * @details
1733  * This routine does *not* automatically combine objects.
1734  * Returns TRUE if something was identified, else FALSE.
1735  */
1736 bool ident_spell(player_type *caster_ptr, bool only_equip)
1737 {
1738         OBJECT_IDX item;
1739         object_type *o_ptr;
1740         GAME_TEXT o_name[MAX_NLEN];
1741         concptr q, s;
1742         bool old_known;
1743
1744         if (only_equip)
1745                 item_tester_hook = item_tester_hook_identify_weapon_armour;
1746         else
1747                 item_tester_hook = item_tester_hook_identify;
1748
1749         if (can_get_item(item_tester_tval))
1750         {
1751                 q = _("どのアイテムを鑑定しますか? ", "Identify which item? ");
1752         }
1753         else
1754         {
1755                 if (only_equip)
1756                         item_tester_hook = object_is_weapon_armour_ammo;
1757                 else
1758                         item_tester_hook = NULL;
1759
1760                 q = _("すべて鑑定済みです。 ", "All items are identified. ");
1761         }
1762
1763         s = _("鑑定するべきアイテムがない。", "You have nothing to identify.");
1764
1765         o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
1766         if (!o_ptr) return (FALSE);
1767
1768         old_known = identify_item(o_ptr);
1769
1770         object_desc(o_name, o_ptr, 0);
1771         if (item >= INVEN_RARM)
1772         {
1773                 msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(item), o_name, index_to_label(item));
1774         }
1775         else if (item >= 0)
1776         {
1777                 msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
1778         }
1779         else
1780         {
1781                 msg_format(_("床上: %s。", "On the ground: %s."), o_name);
1782         }
1783
1784         /* Auto-inscription/destroy */
1785         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
1786
1787         /* Something happened */
1788         return (TRUE);
1789 }
1790
1791
1792 /*!
1793  * @brief アイテム凡庸化のメインルーチン処理 /
1794  * Identify an object in the p_ptr->inventory_list (or on the floor)
1795  * @param only_equip 装備品のみを対象とするならばTRUEを返す
1796  * @return 実際に凡庸化をを行ったならばTRUEを返す
1797  * @details
1798  * <pre>
1799  * Mundanify an object in the p_ptr->inventory_list (or on the floor)
1800  * This routine does *not* automatically combine objects.
1801  * Returns TRUE if something was mundanified, else FALSE.
1802  * </pre>
1803  */
1804 bool mundane_spell(bool only_equip)
1805 {
1806         OBJECT_IDX item;
1807         object_type *o_ptr;
1808         concptr q, s;
1809
1810         if (only_equip) item_tester_hook = object_is_weapon_armour_ammo;
1811
1812         q = _("どれを使いますか?", "Use which item? ");
1813         s = _("使えるものがありません。", "You have nothing you can use.");
1814
1815         o_ptr = choose_object(p_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
1816         if (!o_ptr) return (FALSE);
1817
1818         msg_print(_("まばゆい閃光が走った!", "There is a bright flash of light!"));
1819         {
1820                 POSITION iy = o_ptr->iy;                 /* Y-position on map, or zero */
1821                 POSITION ix = o_ptr->ix;                 /* X-position on map, or zero */
1822                 OBJECT_IDX next_o_idx = o_ptr->next_o_idx; /* Next object in stack (if any) */
1823                 byte marked = o_ptr->marked;         /* Object is marked */
1824                 WEIGHT weight = o_ptr->number * o_ptr->weight;
1825                 u16b inscription = o_ptr->inscription;
1826
1827                 /* Wipe it clean */
1828                 object_prep(o_ptr, o_ptr->k_idx);
1829
1830                 o_ptr->iy = iy;
1831                 o_ptr->ix = ix;
1832                 o_ptr->next_o_idx = next_o_idx;
1833                 o_ptr->marked = marked;
1834                 o_ptr->inscription = inscription;
1835                 if (item >= 0) p_ptr->total_weight += (o_ptr->weight - weight);
1836         }
1837         calc_android_exp(p_ptr);
1838
1839         /* Something happened */
1840         return TRUE;
1841 }
1842
1843 /*!
1844  * @brief アイテム*鑑定*のメインルーチン処理 /
1845  * Identify an object in the p_ptr->inventory_list (or on the floor)
1846  * @param only_equip 装備品のみを対象とするならばTRUEを返す
1847  * @return 実際に鑑定を行ったならばTRUEを返す
1848  * @details
1849  * Fully "identify" an object in the p_ptr->inventory_list  -BEN-
1850  * This routine returns TRUE if an item was identified.
1851  */
1852 bool identify_fully(bool only_equip)
1853 {
1854         OBJECT_IDX item;
1855         object_type *o_ptr;
1856         GAME_TEXT o_name[MAX_NLEN];
1857         concptr q, s;
1858         bool old_known;
1859
1860         if (only_equip)
1861                 item_tester_hook = item_tester_hook_identify_fully_weapon_armour;
1862         else
1863                 item_tester_hook = item_tester_hook_identify_fully;
1864
1865         if (can_get_item(item_tester_tval))
1866         {
1867                 q = _("どのアイテムを*鑑定*しますか? ", "*Identify* which item? ");
1868         }
1869         else
1870         {
1871                 if (only_equip)
1872                         item_tester_hook = object_is_weapon_armour_ammo;
1873                 else
1874                         item_tester_hook = NULL;
1875
1876                 q = _("すべて*鑑定*済みです。 ", "All items are *identified*. ");
1877         }
1878
1879         s = _("*鑑定*するべきアイテムがない。", "You have nothing to *identify*.");
1880
1881         o_ptr = choose_object(p_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
1882         if (!o_ptr) return (FALSE);
1883
1884         old_known = identify_item(o_ptr);
1885
1886         /* Mark the item as fully known */
1887         o_ptr->ident |= (IDENT_MENTAL);
1888         handle_stuff();
1889
1890         object_desc(o_name, o_ptr, 0);
1891         if (item >= INVEN_RARM)
1892         {
1893                 msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(item), o_name, index_to_label(item));
1894         }
1895         else if (item >= 0)
1896         {
1897                 msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
1898         }
1899         else
1900         {
1901                 msg_format(_("床上: %s。", "On the ground: %s."), o_name);
1902         }
1903
1904         /* Describe it fully */
1905         (void)screen_object(o_ptr, 0L);
1906
1907         /* Auto-inscription/destroy */
1908         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
1909
1910         /* Success */
1911         return (TRUE);
1912 }
1913
1914
1915
1916 /*!
1917  * @brief 魔力充填処理 /
1918  * Recharge a wand/staff/rod from the pack or on the floor.
1919  * This function has been rewritten in Oangband and ZAngband.
1920  * @param power 充填パワー
1921  * @return ターン消費を要する処理まで進んだらTRUEを返す
1922  *
1923  * Sorcery/Arcane -- Recharge  --> recharge(plev * 4)
1924  * Chaos -- Arcane Binding     --> recharge(90)
1925  *
1926  * Scroll of recharging        --> recharge(130)
1927  * Artifact activation/Thingol --> recharge(130)
1928  *
1929  * It is harder to recharge high level, and highly charged wands,
1930  * staffs, and rods.  The more wands in a stack, the more easily and
1931  * strongly they recharge.  Staffs, however, each get fewer charges if
1932  * stacked.
1933  *
1934  * Beware of "sliding index errors".
1935  */
1936 bool recharge(int power)
1937 {
1938         OBJECT_IDX item;
1939         DEPTH lev;
1940         int recharge_strength;
1941         TIME_EFFECT recharge_amount;
1942
1943         object_type *o_ptr;
1944         object_kind *k_ptr;
1945
1946         bool fail = FALSE;
1947         byte fail_type = 1;
1948
1949         concptr q, s;
1950         GAME_TEXT o_name[MAX_NLEN];
1951
1952         /* Only accept legal items */
1953         item_tester_hook = item_tester_hook_recharge;
1954
1955         q = _("どのアイテムに魔力を充填しますか? ", "Recharge which item? ");
1956         s = _("魔力を充填すべきアイテムがない。", "You have nothing to recharge.");
1957
1958         o_ptr = choose_object(p_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
1959         if (!o_ptr) return (FALSE);
1960
1961         /* Get the object kind. */
1962         k_ptr = &k_info[o_ptr->k_idx];
1963
1964         /* Extract the object "level" */
1965         lev = k_info[o_ptr->k_idx].level;
1966
1967
1968         /* Recharge a rod */
1969         if (o_ptr->tval == TV_ROD)
1970         {
1971                 /* Extract a recharge strength by comparing object level to power. */
1972                 recharge_strength = ((power > lev / 2) ? (power - lev / 2) : 0) / 5;
1973
1974
1975                 /* Back-fire */
1976                 if (one_in_(recharge_strength))
1977                 {
1978                         /* Activate the failure code. */
1979                         fail = TRUE;
1980                 }
1981
1982                 /* Recharge */
1983                 else
1984                 {
1985                         /* Recharge amount */
1986                         recharge_amount = (power * damroll(3, 2));
1987
1988                         /* Recharge by that amount */
1989                         if (o_ptr->timeout > recharge_amount)
1990                                 o_ptr->timeout -= recharge_amount;
1991                         else
1992                                 o_ptr->timeout = 0;
1993                 }
1994         }
1995
1996
1997         /* Recharge wand/staff */
1998         else
1999         {
2000                 /* Extract a recharge strength by comparing object level to power.
2001                  * Divide up a stack of wands' charges to calculate charge penalty.
2002                  */
2003                 if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
2004                         recharge_strength = (100 + power - lev - (8 * o_ptr->pval / o_ptr->number)) / 15;
2005
2006                 /* All staffs, unstacked wands. */
2007                 else recharge_strength = (100 + power - lev - (8 * o_ptr->pval)) / 15;
2008                 if (recharge_strength < 0) recharge_strength = 0;
2009
2010                 /* Back-fire */
2011                 if (one_in_(recharge_strength))
2012                 {
2013                         /* Activate the failure code. */
2014                         fail = TRUE;
2015                 }
2016
2017                 /* If the spell didn't backfire, recharge the wand or staff. */
2018                 else
2019                 {
2020                         /* Recharge based on the standard number of charges. */
2021                         recharge_amount = randint1(1 + k_ptr->pval / 2);
2022
2023                         /* Multiple wands in a stack increase recharging somewhat. */
2024                         if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
2025                         {
2026                                 recharge_amount +=
2027                                         (randint1(recharge_amount * (o_ptr->number - 1))) / 2;
2028                                 if (recharge_amount < 1) recharge_amount = 1;
2029                                 if (recharge_amount > 12) recharge_amount = 12;
2030                         }
2031
2032                         /* But each staff in a stack gets fewer additional charges,
2033                          * although always at least one.
2034                          */
2035                         if ((o_ptr->tval == TV_STAFF) && (o_ptr->number > 1))
2036                         {
2037                                 recharge_amount /= (TIME_EFFECT)o_ptr->number;
2038                                 if (recharge_amount < 1) recharge_amount = 1;
2039                         }
2040
2041                         /* Recharge the wand or staff. */
2042                         o_ptr->pval += recharge_amount;
2043
2044
2045                         /* Hack -- we no longer "know" the item */
2046                         o_ptr->ident &= ~(IDENT_KNOWN);
2047
2048                         /* Hack -- we no longer think the item is empty */
2049                         o_ptr->ident &= ~(IDENT_EMPTY);
2050                 }
2051         }
2052
2053
2054         /* Inflict the penalties for failing a recharge. */
2055         if (fail)
2056         {
2057                 /* Artifacts are never destroyed. */
2058                 if (object_is_fixed_artifact(o_ptr))
2059                 {
2060                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2061                         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
2062
2063                         /* Artifact rods. */
2064                         if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout < 10000))
2065                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
2066
2067                         /* Artifact wands and staffs. */
2068                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
2069                                 o_ptr->pval = 0;
2070                 }
2071                 else
2072                 {
2073                         /* Get the object description */
2074                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2075
2076                         /*** Determine Seriousness of Failure ***/
2077
2078                         /* Mages recharge objects more safely. */
2079                         if (IS_WIZARD_CLASS(p_ptr) || p_ptr->pclass == CLASS_MAGIC_EATER || p_ptr->pclass == CLASS_BLUE_MAGE)
2080                         {
2081                                 /* 10% chance to blow up one rod, otherwise draining. */
2082                                 if (o_ptr->tval == TV_ROD)
2083                                 {
2084                                         if (one_in_(10)) fail_type = 2;
2085                                         else fail_type = 1;
2086                                 }
2087                                 /* 75% chance to blow up one wand, otherwise draining. */
2088                                 else if (o_ptr->tval == TV_WAND)
2089                                 {
2090                                         if (!one_in_(3)) fail_type = 2;
2091                                         else fail_type = 1;
2092                                 }
2093                                 /* 50% chance to blow up one staff, otherwise no effect. */
2094                                 else if (o_ptr->tval == TV_STAFF)
2095                                 {
2096                                         if (one_in_(2)) fail_type = 2;
2097                                         else fail_type = 0;
2098                                 }
2099                         }
2100
2101                         /* All other classes get no special favors. */
2102                         else
2103                         {
2104                                 /* 33% chance to blow up one rod, otherwise draining. */
2105                                 if (o_ptr->tval == TV_ROD)
2106                                 {
2107                                         if (one_in_(3)) fail_type = 2;
2108                                         else fail_type = 1;
2109                                 }
2110                                 /* 20% chance of the entire stack, else destroy one wand. */
2111                                 else if (o_ptr->tval == TV_WAND)
2112                                 {
2113                                         if (one_in_(5)) fail_type = 3;
2114                                         else fail_type = 2;
2115                                 }
2116                                 /* Blow up one staff. */
2117                                 else if (o_ptr->tval == TV_STAFF)
2118                                 {
2119                                         fail_type = 2;
2120                                 }
2121                         }
2122
2123                         /*** Apply draining and destruction. ***/
2124
2125                         /* Drain object or stack of objects. */
2126                         if (fail_type == 1)
2127                         {
2128                                 if (o_ptr->tval == TV_ROD)
2129                                 {
2130                                         msg_print(_("魔力が逆噴射して、ロッドからさらに魔力を吸い取ってしまった!", "The recharge backfires, draining the rod further!"));
2131
2132                                         if (o_ptr->timeout < 10000)
2133                                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
2134                                 }
2135                                 else if (o_ptr->tval == TV_WAND)
2136                                 {
2137                                         msg_format(_("%sは破損を免れたが、魔力が全て失われた。", "You save your %s from destruction, but all charges are lost."), o_name);
2138                                         o_ptr->pval = 0;
2139                                 }
2140                                 /* Staffs aren't drained. */
2141                         }
2142
2143                         /* Destroy an object or one in a stack of objects. */
2144                         if (fail_type == 2)
2145                         {
2146                                 if (o_ptr->number > 1)
2147                                         msg_format(_("乱暴な魔法のために%sが一本壊れた!", "Wild magic consumes one of your %s!"), o_name);
2148                                 else
2149                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
2150
2151                                 /* Reduce rod stack maximum timeout, drain wands. */
2152                                 if (o_ptr->tval == TV_ROD) o_ptr->timeout = (o_ptr->number - 1) * k_ptr->pval;
2153                                 if (o_ptr->tval == TV_WAND) o_ptr->pval = 0;
2154
2155                                 /* Reduce and describe p_ptr->inventory_list */
2156                                 if (item >= 0)
2157                                 {
2158                                         inven_item_increase(item, -1);
2159                                         inven_item_describe(item);
2160                                         inven_item_optimize(item);
2161                                 }
2162
2163                                 /* Reduce and describe floor item */
2164                                 else
2165                                 {
2166                                         floor_item_increase(0 - item, -1);
2167                                         floor_item_describe(0 - item);
2168                                         floor_item_optimize(0 - item);
2169                                 }
2170                         }
2171
2172                         /* Destroy all members of a stack of objects. */
2173                         if (fail_type == 3)
2174                         {
2175                                 if (o_ptr->number > 1)
2176                                         msg_format(_("乱暴な魔法のために%sが全て壊れた!", "Wild magic consumes all your %s!"), o_name);
2177                                 else
2178                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
2179
2180                                 /* Reduce and describe p_ptr->inventory_list */
2181                                 if (item >= 0)
2182                                 {
2183                                         inven_item_increase(item, -999);
2184                                         inven_item_describe(item);
2185                                         inven_item_optimize(item);
2186                                 }
2187
2188                                 /* Reduce and describe floor item */
2189                                 else
2190                                 {
2191                                         floor_item_increase(0 - item, -999);
2192                                         floor_item_describe(0 - item);
2193                                         floor_item_optimize(0 - item);
2194                                 }
2195                         }
2196                 }
2197         }
2198         p_ptr->update |= (PU_COMBINE | PU_REORDER);
2199         p_ptr->window |= (PW_INVEN);
2200
2201         /* Something was done */
2202         return (TRUE);
2203 }
2204
2205
2206 /*!
2207  * @brief クリーチャー全既知呪文を表示する /
2208  * Hack -- Display all known spells in a window
2209  * @param caster_ptr 術者の参照ポインタ
2210  * return なし
2211  * @details
2212  * Need to analyze size of the window.
2213  * Need more color coding.
2214  */
2215 void display_spell_list(player_type *caster_ptr)
2216 {
2217         int i, j;
2218         TERM_LEN y, x;
2219         int m[9];
2220         const magic_type *s_ptr;
2221         GAME_TEXT name[MAX_NLEN];
2222         char out_val[160];
2223
2224         clear_from(0);
2225
2226         /* They have too many spells to list */
2227         if (caster_ptr->pclass == CLASS_SORCERER) return;
2228         if (caster_ptr->pclass == CLASS_RED_MAGE) return;
2229
2230         if (caster_ptr->pclass == CLASS_SNIPER)
2231         {
2232                 display_snipe_list(caster_ptr);
2233                 return;
2234         }
2235
2236         /* mind.c type classes */
2237         if ((caster_ptr->pclass == CLASS_MINDCRAFTER) ||
2238             (caster_ptr->pclass == CLASS_BERSERKER) ||
2239             (caster_ptr->pclass == CLASS_NINJA) ||
2240             (caster_ptr->pclass == CLASS_MIRROR_MASTER) ||
2241             (caster_ptr->pclass == CLASS_FORCETRAINER))
2242         {
2243                 PERCENTAGE minfail = 0;
2244                 PLAYER_LEVEL plev = caster_ptr->lev;
2245                 PERCENTAGE chance = 0;
2246                 mind_type       spell;
2247                 char            comment[80];
2248                 char            psi_desc[80];
2249                 int             use_mind;
2250                 bool use_hp = FALSE;
2251
2252                 y = 1;
2253                 x = 1;
2254
2255                 /* Display a list of spells */
2256                 prt("", y, x);
2257                 put_str(_("名前", "Name"), y, x + 5);
2258                 put_str(_("Lv   MP 失率 効果", "Lv Mana Fail Info"), y, x + 35);
2259
2260                 switch(caster_ptr->pclass)
2261                 {
2262                 case CLASS_MINDCRAFTER: use_mind = MIND_MINDCRAFTER;break;
2263                 case CLASS_FORCETRAINER:          use_mind = MIND_KI;break;
2264                 case CLASS_BERSERKER: use_mind = MIND_BERSERKER; use_hp = TRUE; break;
2265                 case CLASS_MIRROR_MASTER: use_mind = MIND_MIRROR_MASTER; break;
2266                 case CLASS_NINJA: use_mind = MIND_NINJUTSU; use_hp = TRUE; break;
2267                 default:                use_mind = 0;break;
2268                 }
2269
2270                 /* Dump the spells */
2271                 for (i = 0; i < MAX_MIND_POWERS; i++)
2272                 {
2273                         byte a = TERM_WHITE;
2274
2275                         /* Access the available spell */
2276                         spell = mind_powers[use_mind].info[i];
2277                         if (spell.min_lev > plev) break;
2278
2279                         /* Get the failure rate */
2280                         chance = spell.fail;
2281
2282                         /* Reduce failure rate by "effective" level adjustment */
2283                         chance -= 3 * (caster_ptr->lev - spell.min_lev);
2284
2285                         /* Reduce failure rate by INT/WIS adjustment */
2286                         chance -= 3 * (adj_mag_stat[caster_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
2287
2288                         if (!use_hp)
2289                         {
2290                                 /* Not enough mana to cast */
2291                                 if (spell.mana_cost > caster_ptr->csp)
2292                                 {
2293                                         chance += 5 * (spell.mana_cost - caster_ptr->csp);
2294                                         a = TERM_ORANGE;
2295                                 }
2296                         }
2297                         else
2298                         {
2299                                 /* Not enough hp to cast */
2300                                 if (spell.mana_cost > caster_ptr->chp)
2301                                 {
2302                                         chance += 100;
2303                                         a = TERM_RED;
2304                                 }
2305                         }
2306
2307                         /* Extract the minimum failure rate */
2308                         minfail = adj_mag_fail[caster_ptr->stat_ind[mp_ptr->spell_stat]];
2309
2310                         /* Minimum failure rate */
2311                         if (chance < minfail) chance = minfail;
2312
2313                         /* Stunning makes spells harder */
2314                         if (caster_ptr->stun > 50) chance += 25;
2315                         else if (caster_ptr->stun) chance += 15;
2316
2317                         /* Always a 5 percent chance of working */
2318                         if (chance > 95) chance = 95;
2319
2320                         /* Get info */
2321                         mindcraft_info(comment, use_mind, i);
2322
2323                         /* Dump the spell */
2324                         sprintf(psi_desc, "  %c) %-30s%2d %4d %3d%%%s",
2325                             I2A(i), spell.name,
2326                             spell.min_lev, spell.mana_cost, chance, comment);
2327
2328                         Term_putstr(x, y + i + 1, -1, a, psi_desc);
2329                 }
2330                 return;
2331         }
2332
2333         /* Cannot read spellbooks */
2334         if (REALM_NONE == caster_ptr->realm1) return;
2335
2336         /* Normal spellcaster with books */
2337
2338         /* Scan books */
2339         for (j = 0; j < ((caster_ptr->realm2 > REALM_NONE) ? 2 : 1); j++)
2340         {
2341                 int n = 0;
2342
2343                 /* Reset vertical */
2344                 m[j] = 0;
2345
2346                 /* Vertical location */
2347                 y = (j < 3) ? 0 : (m[j - 3] + 2);
2348
2349                 /* Horizontal location */
2350                 x = 27 * (j % 3);
2351
2352                 /* Scan spells */
2353                 for (i = 0; i < 32; i++)
2354                 {
2355                         byte a = TERM_WHITE;
2356
2357                         /* Access the spell */
2358                         if (!is_magic((j < 1) ? caster_ptr->realm1 : caster_ptr->realm2))
2359                         {
2360                                 s_ptr = &technic_info[((j < 1) ? caster_ptr->realm1 : caster_ptr->realm2) - MIN_TECHNIC][i % 32];
2361                         }
2362                         else
2363                         {
2364                                 s_ptr = &mp_ptr->info[((j < 1) ? caster_ptr->realm1 : caster_ptr->realm2) - 1][i % 32];
2365                         }
2366
2367                         strcpy(name, exe_spell(caster_ptr, (j < 1) ? caster_ptr->realm1 : caster_ptr->realm2, i % 32, SPELL_NAME));
2368
2369                         /* Illegible */
2370                         if (s_ptr->slevel >= 99)
2371                         {
2372                                 /* Illegible */
2373                                 strcpy(name, _("(判読不能)", "(illegible)"));
2374
2375                                 /* Unusable */
2376                                 a = TERM_L_DARK;
2377                         }
2378
2379                         /* Forgotten */
2380                         else if ((j < 1) ?
2381                                 ((caster_ptr->spell_forgotten1 & (1L << i))) :
2382                                 ((caster_ptr->spell_forgotten2 & (1L << (i % 32)))))
2383                         {
2384                                 /* Forgotten */
2385                                 a = TERM_ORANGE;
2386                         }
2387
2388                         /* Unknown */
2389                         else if (!((j < 1) ?
2390                                 (caster_ptr->spell_learned1 & (1L << i)) :
2391                                 (caster_ptr->spell_learned2 & (1L << (i % 32)))))
2392                         {
2393                                 /* Unknown */
2394                                 a = TERM_RED;
2395                         }
2396
2397                         /* Untried */
2398                         else if (!((j < 1) ?
2399                                 (caster_ptr->spell_worked1 & (1L << i)) :
2400                                 (caster_ptr->spell_worked2 & (1L << (i % 32)))))
2401                         {
2402                                 /* Untried */
2403                                 a = TERM_YELLOW;
2404                         }
2405
2406                         /* Dump the spell --(-- */
2407                         sprintf(out_val, "%c/%c) %-20.20s",
2408                                 I2A(n / 8), I2A(n % 8), name);
2409
2410                         /* Track maximum */
2411                         m[j] = y + n;
2412
2413                         /* Dump onto the window */
2414                         Term_putstr(x, m[j], -1, a, out_val);
2415
2416                         /* Next */
2417                         n++;
2418                 }
2419         }
2420 }
2421
2422
2423 /*!
2424  * @brief 呪文の経験値を返す /
2425  * Returns experience of a spell
2426  * @param spell 呪文ID
2427  * @param use_realm 魔法領域
2428  * @return 経験値
2429  */
2430 EXP experience_of_spell(player_type *caster_ptr, SPELL_IDX spell, REALM_IDX use_realm)
2431 {
2432         if (caster_ptr->pclass == CLASS_SORCERER) return SPELL_EXP_MASTER;
2433         else if (caster_ptr->pclass == CLASS_RED_MAGE) return SPELL_EXP_SKILLED;
2434         else if (use_realm == caster_ptr->realm1) return caster_ptr->spell_exp[spell];
2435         else if (use_realm == caster_ptr->realm2) return caster_ptr->spell_exp[spell + 32];
2436         else return 0;
2437 }
2438
2439
2440 /*!
2441  * @brief 呪文の消費MPを返す /
2442  * Modify mana consumption rate using spell exp and p_ptr->dec_mana
2443  * @param need_mana 基本消費MP
2444  * @param spell 呪文ID
2445  * @param realm 魔法領域
2446  * @return 消費MP
2447  */
2448 MANA_POINT mod_need_mana(MANA_POINT need_mana, SPELL_IDX spell, REALM_IDX realm)
2449 {
2450 #define MANA_CONST   2400
2451 #define MANA_DIV        4
2452 #define DEC_MANA_DIV    3
2453
2454         /* Realm magic */
2455         if ((realm > REALM_NONE) && (realm <= MAX_REALM))
2456         {
2457                 /*
2458                  * need_mana defaults if spell exp equals SPELL_EXP_EXPERT and !p_ptr->dec_mana.
2459                  * MANA_CONST is used to calculate need_mana effected from spell proficiency.
2460                  */
2461                 need_mana = need_mana * (MANA_CONST + SPELL_EXP_EXPERT - experience_of_spell(p_ptr, spell, realm)) + (MANA_CONST - 1);
2462                 need_mana *= p_ptr->dec_mana ? DEC_MANA_DIV : MANA_DIV;
2463                 need_mana /= MANA_CONST * MANA_DIV;
2464                 if (need_mana < 1) need_mana = 1;
2465         }
2466
2467         /* Non-realm magic */
2468         else
2469         {
2470                 if (p_ptr->dec_mana) need_mana = (need_mana + 1) * DEC_MANA_DIV / MANA_DIV;
2471         }
2472
2473 #undef DEC_MANA_DIV
2474 #undef MANA_DIV
2475 #undef MANA_CONST
2476
2477         return need_mana;
2478 }
2479
2480
2481 /*!
2482  * @brief 呪文の失敗率修正処理1(呪い、消費魔力減少、呪文簡易化) /
2483  * Modify spell fail rate
2484  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
2485  * @param chance 修正前失敗率
2486  * @return 失敗率(%)
2487  * @todo 統合を検討
2488  */
2489 PERCENTAGE mod_spell_chance_1(player_type *caster_ptr, PERCENTAGE chance)
2490 {
2491         chance += caster_ptr->to_m_chance;
2492
2493         if (caster_ptr->heavy_spell) chance += 20;
2494
2495         if (caster_ptr->dec_mana && caster_ptr->easy_spell) chance -= 4;
2496         else if (caster_ptr->easy_spell) chance -= 3;
2497         else if (caster_ptr->dec_mana) chance -= 2;
2498
2499         return chance;
2500 }
2501
2502
2503 /*!
2504  * @brief 呪文の失敗率修正処理2(消費魔力減少、呪い、負値修正) /
2505  * Modify spell fail rate
2506  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
2507  * @param chance 修正前失敗率
2508  * @return 失敗率(%)
2509  * Modify spell fail rate (as "suffix" process)
2510  * Using p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
2511  * Note: variable "chance" cannot be negative.
2512  * @todo 統合を検討
2513  */
2514 PERCENTAGE mod_spell_chance_2(player_type *caster_ptr, PERCENTAGE chance)
2515 {
2516         if (caster_ptr->dec_mana) chance--;
2517         if (caster_ptr->heavy_spell) chance += 5;
2518         return MAX(chance, 0);
2519 }
2520
2521
2522 /*!
2523  * @brief 呪文の失敗率計算メインルーチン /
2524  * Returns spell chance of failure for spell -RAK-
2525  * @param spell 呪文ID
2526  * @param use_realm 魔法領域ID
2527  * @return 失敗率(%)
2528  */
2529 PERCENTAGE spell_chance(player_type *caster_ptr, SPELL_IDX spell, REALM_IDX use_realm)
2530 {
2531         PERCENTAGE chance, minfail;
2532         const magic_type *s_ptr;
2533         MANA_POINT need_mana;
2534         PERCENTAGE penalty = (mp_ptr->spell_stat == A_WIS) ? 10 : 4;
2535
2536
2537         /* Paranoia -- must be literate */
2538         if (!mp_ptr->spell_book) return (100);
2539
2540         if (use_realm == REALM_HISSATSU) return 0;
2541
2542         /* Access the spell */
2543         if (!is_magic(use_realm))
2544         {
2545                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
2546         }
2547         else
2548         {
2549                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
2550         }
2551
2552         /* Extract the base spell failure rate */
2553         chance = s_ptr->sfail;
2554
2555         /* Reduce failure rate by "effective" level adjustment */
2556         chance -= 3 * (caster_ptr->lev - s_ptr->slevel);
2557
2558         /* Reduce failure rate by INT/WIS adjustment */
2559         chance -= 3 * (adj_mag_stat[caster_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
2560
2561         if (caster_ptr->riding)
2562                 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));
2563
2564         /* Extract mana consumption rate */
2565         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
2566
2567         /* Not enough mana to cast */
2568         if (need_mana > caster_ptr->csp)
2569         {
2570                 chance += 5 * (need_mana - caster_ptr->csp);
2571         }
2572
2573         if ((use_realm != caster_ptr->realm1) && ((caster_ptr->pclass == CLASS_MAGE) || (caster_ptr->pclass == CLASS_PRIEST))) chance += 5;
2574
2575         /* Extract the minimum failure rate */
2576         minfail = adj_mag_fail[caster_ptr->stat_ind[mp_ptr->spell_stat]];
2577
2578         /*
2579          * Non mage/priest characters never get too good
2580          * (added high mage, mindcrafter)
2581          */
2582         if (mp_ptr->spell_xtra & MAGIC_FAIL_5PERCENT)
2583         {
2584                 if (minfail < 5) minfail = 5;
2585         }
2586
2587         /* Hack -- Priest prayer penalty for "edged" weapons  -DGK */
2588         if (((caster_ptr->pclass == CLASS_PRIEST) || (caster_ptr->pclass == CLASS_SORCERER)) && caster_ptr->icky_wield[0]) chance += 25;
2589         if (((caster_ptr->pclass == CLASS_PRIEST) || (caster_ptr->pclass == CLASS_SORCERER)) && caster_ptr->icky_wield[1]) chance += 25;
2590
2591         chance = mod_spell_chance_1(caster_ptr, chance);
2592
2593         /* Goodness or evilness gives a penalty to failure rate */
2594         switch (use_realm)
2595         {
2596         case REALM_NATURE:
2597                 if ((caster_ptr->align > 50) || (caster_ptr->align < -50)) chance += penalty;
2598                 break;
2599         case REALM_LIFE: case REALM_CRUSADE:
2600                 if (caster_ptr->align < -20) chance += penalty;
2601                 break;
2602         case REALM_DEATH: case REALM_DAEMON: case REALM_HEX:
2603                 if (caster_ptr->align > 20) chance += penalty;
2604                 break;
2605         }
2606
2607         /* Minimum failure rate */
2608         if (chance < minfail) chance = minfail;
2609
2610         /* Stunning makes spells harder */
2611         if (caster_ptr->stun > 50) chance += 25;
2612         else if (caster_ptr->stun) chance += 15;
2613
2614         /* Always a 5 percent chance of working */
2615         if (chance > 95) chance = 95;
2616
2617         if ((use_realm == caster_ptr->realm1) || (use_realm == caster_ptr->realm2)
2618             || (caster_ptr->pclass == CLASS_SORCERER) || (caster_ptr->pclass == CLASS_RED_MAGE))
2619         {
2620                 EXP exp = experience_of_spell(caster_ptr, spell, use_realm);
2621                 if (exp >= SPELL_EXP_EXPERT) chance--;
2622                 if (exp >= SPELL_EXP_MASTER) chance--;
2623         }
2624
2625         /* Return the chance */
2626         return mod_spell_chance_2(caster_ptr, chance);
2627 }
2628
2629
2630
2631 /*!
2632  * @brief 呪文情報の表示処理 /
2633  * Print a list of spells (for browsing or casting or viewing)
2634  * @param target_spell 呪文ID             
2635  * @param caster_ptr 術者の参照ポインタ
2636  * @param spells 表示するスペルID配列の参照ポインタ
2637  * @param num 表示するスペルの数(spellsの要素数)
2638  * @param y 表示メッセージ左上Y座標
2639  * @param x 表示メッセージ左上X座標
2640  * @param use_realm 魔法領域ID
2641  * @return なし
2642  */
2643 void print_spells(player_type* caster_ptr, SPELL_IDX target_spell, SPELL_IDX *spells, int num, TERM_LEN y, TERM_LEN x, REALM_IDX use_realm)
2644 {
2645         int i;
2646         SPELL_IDX spell;
2647         int  exp_level, increment = 64;
2648         const magic_type *s_ptr;
2649         concptr comment;
2650         char info[80];
2651         char out_val[160];
2652         byte line_attr;
2653         MANA_POINT need_mana;
2654         char ryakuji[5];
2655         char buf[256];
2656         bool max = FALSE;
2657
2658         if (((use_realm <= REALM_NONE) || (use_realm > MAX_REALM)) && current_world_ptr->wizard)
2659         msg_print(_("警告! print_spell が領域なしに呼ばれた", "Warning! print_spells called with null realm"));
2660
2661         /* Title the list */
2662         prt("", y, x);
2663         if (use_realm == REALM_HISSATSU)
2664                 strcpy(buf,_("  Lv   MP", "  Lv   SP"));
2665         else
2666                 strcpy(buf,_("熟練度 Lv   MP 失率 効果", "Profic Lv   SP Fail Effect"));
2667
2668         put_str(_("名前", "Name"), y, x + 5);
2669         put_str(buf, y, x + 29);
2670
2671         if ((caster_ptr->pclass == CLASS_SORCERER) || (caster_ptr->pclass == CLASS_RED_MAGE)) increment = 0;
2672         else if (use_realm == caster_ptr->realm1) increment = 0;
2673         else if (use_realm == caster_ptr->realm2) increment = 32;
2674
2675         /* Dump the spells */
2676         for (i = 0; i < num; i++)
2677         {
2678                 spell = spells[i];
2679
2680                 if (!is_magic(use_realm))
2681                 {
2682                         s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
2683                 }
2684                 else
2685                 {
2686                         s_ptr = &mp_ptr->info[use_realm - 1][spell];
2687                 }
2688
2689                 if (use_realm == REALM_HISSATSU)
2690                         need_mana = s_ptr->smana;
2691                 else
2692                 {
2693                         EXP exp = experience_of_spell(caster_ptr, spell, use_realm);
2694
2695                         /* Extract mana consumption rate */
2696                         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
2697
2698                         if ((increment == 64) || (s_ptr->slevel >= 99)) exp_level = EXP_LEVEL_UNSKILLED;
2699                         else exp_level = spell_exp_level(exp);
2700
2701                         max = FALSE;
2702                         if (!increment && (exp_level == EXP_LEVEL_MASTER)) max = TRUE;
2703                         else if ((increment == 32) && (exp_level >= EXP_LEVEL_EXPERT)) max = TRUE;
2704                         else if (s_ptr->slevel >= 99) max = TRUE;
2705                         else if ((caster_ptr->pclass == CLASS_RED_MAGE) && (exp_level >= EXP_LEVEL_SKILLED)) max = TRUE;
2706
2707                         strncpy(ryakuji, exp_level_str[exp_level], 4);
2708                         ryakuji[3] = ']';
2709                         ryakuji[4] = '\0';
2710                 }
2711
2712                 if (use_menu && target_spell)
2713                 {
2714                         if (i == (target_spell-1))
2715                                 strcpy(out_val, _("  》 ", "  >  "));
2716                         else
2717                                 strcpy(out_val, "     ");
2718                 }
2719                 else sprintf(out_val, "  %c) ", I2A(i));
2720                 /* Skip illegible spells */
2721                 if (s_ptr->slevel >= 99)
2722                 {
2723                         strcat(out_val, format("%-30s", _("(判読不能)", "(illegible)")));
2724                         c_prt(TERM_L_DARK, out_val, y + i + 1, x);
2725                         continue;
2726                 }
2727
2728                 /* XXX XXX Could label spells above the players level */
2729
2730                 /* Get extra info */
2731                 strcpy(info, exe_spell(caster_ptr, use_realm, spell, SPELL_INFO));
2732
2733                 /* Use that info */
2734                 comment = info;
2735
2736                 /* Assume spell is known and tried */
2737                 line_attr = TERM_WHITE;
2738
2739                 /* Analyze the spell */
2740                 if ((caster_ptr->pclass == CLASS_SORCERER) || (caster_ptr->pclass == CLASS_RED_MAGE))
2741                 {
2742                         if (s_ptr->slevel > caster_ptr->max_plv)
2743                         {
2744                                 comment = _("未知", "unknown");
2745                                 line_attr = TERM_L_BLUE;
2746                         }
2747                         else if (s_ptr->slevel > caster_ptr->lev)
2748                         {
2749                                 comment = _("忘却", "forgotten");
2750                                 line_attr = TERM_YELLOW;
2751                         }
2752                 }
2753                 else if ((use_realm != caster_ptr->realm1) && (use_realm != caster_ptr->realm2))
2754                 {
2755                         comment = _("未知", "unknown");
2756                         line_attr = TERM_L_BLUE;
2757                 }
2758                 else if ((use_realm == caster_ptr->realm1) ?
2759                     ((caster_ptr->spell_forgotten1 & (1L << spell))) :
2760                     ((caster_ptr->spell_forgotten2 & (1L << spell))))
2761                 {
2762                         comment = _("忘却", "forgotten");
2763                         line_attr = TERM_YELLOW;
2764                 }
2765                 else if (!((use_realm == caster_ptr->realm1) ?
2766                     (caster_ptr->spell_learned1 & (1L << spell)) :
2767                     (caster_ptr->spell_learned2 & (1L << spell))))
2768                 {
2769                         comment = _("未知", "unknown");
2770                         line_attr = TERM_L_BLUE;
2771                 }
2772                 else if (!((use_realm == caster_ptr->realm1) ?
2773                     (caster_ptr->spell_worked1 & (1L << spell)) :
2774                     (caster_ptr->spell_worked2 & (1L << spell))))
2775                 {
2776                         comment = _("未経験", "untried");
2777                         line_attr = TERM_L_GREEN;
2778                 }
2779
2780                 /* Dump the spell --(-- */
2781                 if (use_realm == REALM_HISSATSU)
2782                 {
2783                         strcat(out_val, format("%-25s %2d %4d",
2784                             exe_spell(caster_ptr, use_realm, spell, SPELL_NAME), /* realm, spell */
2785                             s_ptr->slevel, need_mana));
2786                 }
2787                 else
2788                 {
2789                         strcat(out_val, format("%-25s%c%-4s %2d %4d %3d%% %s",
2790                             exe_spell(caster_ptr, use_realm, spell, SPELL_NAME), /* realm, spell */
2791                             (max ? '!' : ' '), ryakuji,
2792                             s_ptr->slevel, need_mana, spell_chance(caster_ptr, spell, use_realm), comment));
2793                 }
2794                 c_prt(line_attr, out_val, y + i + 1, x);
2795         }
2796
2797         /* Clear the bottom line */
2798         prt("", y + i + 1, x);
2799 }
2800
2801 /*!
2802  * @brief 変身処理向けにモンスターの近隣レベル帯モンスターを返す /
2803  * Helper function -- return a "nearby" race for polymorphing
2804  * @param r_idx 基準となるモンスター種族ID
2805  * @return 変更先のモンスター種族ID
2806  * @details
2807  * Note that this function is one of the more "dangerous" ones...
2808  */
2809 static MONRACE_IDX poly_r_idx(MONRACE_IDX r_idx)
2810 {
2811         monster_race *r_ptr = &r_info[r_idx];
2812
2813         int i;
2814         MONRACE_IDX r;
2815         DEPTH lev1, lev2;
2816
2817         /* Hack -- Uniques/Questors never polymorph */
2818         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags1 & RF1_QUESTOR))
2819                 return (r_idx);
2820
2821         /* Allowable range of "levels" for resulting monster */
2822         lev1 = r_ptr->level - ((randint1(20) / randint1(9)) + 1);
2823         lev2 = r_ptr->level + ((randint1(20) / randint1(9)) + 1);
2824
2825         /* Pick a (possibly new) non-unique race */
2826         for (i = 0; i < 1000; i++)
2827         {
2828                 /* Pick a new race, using a level calculation */
2829                 r = get_mon_num((p_ptr->current_floor_ptr->dun_level + r_ptr->level) / 2 + 5);
2830
2831                 /* Handle failure */
2832                 if (!r) break;
2833
2834                 r_ptr = &r_info[r];
2835
2836                 /* Ignore unique monsters */
2837                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
2838
2839                 /* Ignore monsters with incompatible levels */
2840                 if ((r_ptr->level < lev1) || (r_ptr->level > lev2)) continue;
2841
2842                 /* Use that index */
2843                 r_idx = r;
2844
2845                 break;
2846         }
2847         return (r_idx);
2848 }
2849
2850 /*!
2851  * @brief 指定座標にいるモンスターを変身させる /
2852  * Helper function -- return a "nearby" race for polymorphing
2853  * @param y 指定のY座標
2854  * @param x 指定のX座標
2855  * @return 実際に変身したらTRUEを返す
2856  */
2857 bool polymorph_monster(player_type *caster_ptr, POSITION y, POSITION x)
2858 {
2859         grid_type *g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][x];
2860         monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2861         bool polymorphed = FALSE;
2862         MONRACE_IDX new_r_idx;
2863         MONRACE_IDX old_r_idx = m_ptr->r_idx;
2864         bool targeted = (target_who == g_ptr->m_idx) ? TRUE : FALSE;
2865         bool health_tracked = (caster_ptr->health_who == g_ptr->m_idx) ? TRUE : FALSE;
2866         monster_type back_m;
2867
2868         if (caster_ptr->current_floor_ptr->inside_arena || caster_ptr->phase_out) return (FALSE);
2869
2870         if ((caster_ptr->riding == g_ptr->m_idx) || (m_ptr->mflag2 & MFLAG2_KAGE)) return (FALSE);
2871
2872         /* Memorize the monster before polymorphing */
2873         back_m = *m_ptr;
2874
2875         /* Pick a "new" monster race */
2876         new_r_idx = poly_r_idx(old_r_idx);
2877
2878         /* Handle polymorph */
2879         if (new_r_idx != old_r_idx)
2880         {
2881                 BIT_FLAGS mode = 0L;
2882                 bool preserve_hold_objects = back_m.hold_o_idx ? TRUE : FALSE;
2883                 OBJECT_IDX this_o_idx, next_o_idx = 0;
2884
2885                 /* Get the monsters attitude */
2886                 if (is_friendly(m_ptr)) mode |= PM_FORCE_FRIENDLY;
2887                 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
2888                 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
2889
2890                 /* Mega-hack -- ignore held objects */
2891                 m_ptr->hold_o_idx = 0;
2892
2893                 /* "Kill" the "old" monster */
2894                 delete_monster_idx(g_ptr->m_idx);
2895
2896                 /* Create a new monster (no groups) */
2897                 if (place_monster_aux(0, y, x, new_r_idx, mode))
2898                 {
2899                         caster_ptr->current_floor_ptr->m_list[hack_m_idx_ii].nickname = back_m.nickname;
2900                         caster_ptr->current_floor_ptr->m_list[hack_m_idx_ii].parent_m_idx = back_m.parent_m_idx;
2901                         caster_ptr->current_floor_ptr->m_list[hack_m_idx_ii].hold_o_idx = back_m.hold_o_idx;
2902
2903                         /* Success */
2904                         polymorphed = TRUE;
2905                 }
2906                 else
2907                 {
2908                         /* Placing the new monster failed */
2909                         if (place_monster_aux(0, y, x, old_r_idx, (mode | PM_NO_KAGE | PM_IGNORE_TERRAIN)))
2910                         {
2911                                 caster_ptr->current_floor_ptr->m_list[hack_m_idx_ii] = back_m;
2912
2913                                 /* Re-initialize monster process */
2914                                 mproc_init();
2915                         }
2916                         else preserve_hold_objects = FALSE;
2917                 }
2918
2919                 /* Mega-hack -- preserve held objects */
2920                 if (preserve_hold_objects)
2921                 {
2922                         for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
2923                         {
2924                                 object_type *o_ptr = &caster_ptr->current_floor_ptr->o_list[this_o_idx];
2925                                 next_o_idx = o_ptr->next_o_idx;
2926
2927                                 /* Held by new monster */
2928                                 o_ptr->held_m_idx = hack_m_idx_ii;
2929                         }
2930                 }
2931                 else if (back_m.hold_o_idx) /* Failed (paranoia) */
2932                 {
2933                         for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
2934                         {
2935                                 next_o_idx = caster_ptr->current_floor_ptr->o_list[this_o_idx].next_o_idx;
2936                                 delete_object_idx(this_o_idx);
2937                         }
2938                 }
2939
2940                 if (targeted) target_who = hack_m_idx_ii;
2941                 if (health_tracked) health_track(hack_m_idx_ii);
2942         }
2943
2944         return polymorphed;
2945 }
2946
2947 /*!
2948  * @brief 次元の扉処理 /
2949  * Dimension Door
2950  * @param x テレポート先のX座標
2951  * @param y テレポート先のY座標
2952  * @return 目標に指定通りテレポートできたならばTRUEを返す
2953  */
2954 static bool dimension_door_aux(DEPTH x, DEPTH y)
2955 {
2956         PLAYER_LEVEL plev = p_ptr->lev;
2957
2958         p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
2959
2960         if (!cave_player_teleportable_bold(y, x, 0L) ||
2961             (distance(y, x, p_ptr->y, p_ptr->x) > plev / 2 + 10) ||
2962             (!randint0(plev / 10 + 10)))
2963         {
2964                 p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
2965                 teleport_player(p_ptr, (plev + 2) * 2, TELEPORT_PASSIVE);
2966
2967                 /* Failed */
2968                 return FALSE;
2969         }
2970         else
2971         {
2972                 teleport_player_to(p_ptr, y, x, 0L);
2973
2974                 /* Success */
2975                 return TRUE;
2976         }
2977 }
2978
2979
2980 /*!
2981  * @brief 次元の扉処理のメインルーチン /
2982  * Dimension Door
2983  * @return ターンを消費した場合TRUEを返す
2984  */
2985 bool dimension_door(void)
2986 {
2987         DEPTH x = 0, y = 0;
2988
2989         /* Rerutn FALSE if cancelled */
2990         if (!tgt_pt(&x, &y)) return FALSE;
2991
2992         if (dimension_door_aux(x, y)) return TRUE;
2993
2994         msg_print(_("精霊界から物質界に戻る時うまくいかなかった!", "You fail to exit the astral plane correctly!"));
2995
2996         return TRUE;
2997 }
2998
2999
3000 /*!
3001  * @brief 鏡抜け処理のメインルーチン /
3002  * Mirror Master's Dimension Door
3003  * @return ターンを消費した場合TRUEを返す
3004  */
3005 bool mirror_tunnel(void)
3006 {
3007         POSITION x = 0, y = 0;
3008
3009         /* Rerutn FALSE if cancelled */
3010         if (!tgt_pt(&x, &y)) return FALSE;
3011
3012         if (dimension_door_aux(x, y)) return TRUE;
3013
3014         msg_print(_("鏡の世界をうまく通れなかった!", "You fail to pass the mirror plane correctly!"));
3015
3016         return TRUE;
3017 }
3018
3019 /*!
3020  * @brief 魔力食い処理
3021  * @param power 基本効力
3022  * @return ターンを消費した場合TRUEを返す
3023  */
3024 bool eat_magic(player_type *caster_ptr, int power)
3025 {
3026         object_type *o_ptr;
3027         object_kind *k_ptr;
3028         DEPTH lev;
3029         OBJECT_IDX item;
3030         int recharge_strength = 0;
3031
3032         bool fail = FALSE;
3033         byte fail_type = 1;
3034
3035         concptr q, s;
3036         GAME_TEXT o_name[MAX_NLEN];
3037
3038         item_tester_hook = item_tester_hook_recharge;
3039
3040         q = _("どのアイテムから魔力を吸収しますか?", "Drain which item? ");
3041         s = _("魔力を吸収できるアイテムがありません。", "You have nothing to drain.");
3042
3043         o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
3044         if (!o_ptr) return FALSE;
3045
3046         k_ptr = &k_info[o_ptr->k_idx];
3047         lev = k_info[o_ptr->k_idx].level;
3048
3049         if (o_ptr->tval == TV_ROD)
3050         {
3051                 recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
3052
3053                 /* Back-fire */
3054                 if (one_in_(recharge_strength))
3055                 {
3056                         /* Activate the failure code. */
3057                         fail = TRUE;
3058                 }
3059                 else
3060                 {
3061                         if (o_ptr->timeout > (o_ptr->number - 1) * k_ptr->pval)
3062                         {
3063                                 msg_print(_("充填中のロッドから魔力を吸収することはできません。", "You can't absorb energy from a discharged rod."));
3064                         }
3065                         else
3066                         {
3067                                 caster_ptr->csp += lev;
3068                                 o_ptr->timeout += k_ptr->pval;
3069                         }
3070                 }
3071         }
3072         else
3073         {
3074                 /* All staffs, wands. */
3075                 recharge_strength = (100 + power - lev) / 15;
3076                 if (recharge_strength < 0) recharge_strength = 0;
3077
3078                 /* Back-fire */
3079                 if (one_in_(recharge_strength))
3080                 {
3081                         /* Activate the failure code. */
3082                         fail = TRUE;
3083                 }
3084                 else
3085                 {
3086                         if (o_ptr->pval > 0)
3087                         {
3088                                 caster_ptr->csp += lev / 2;
3089                                 o_ptr->pval --;
3090
3091                                 /* XXX Hack -- unstack if necessary */
3092                                 if ((o_ptr->tval == TV_STAFF) && (item >= 0) && (o_ptr->number > 1))
3093                                 {
3094                                         object_type forge;
3095                                         object_type *q_ptr;
3096                                         q_ptr = &forge;
3097                                         object_copy(q_ptr, o_ptr);
3098
3099                                         /* Modify quantity */
3100                                         q_ptr->number = 1;
3101
3102                                         /* Restore the charges */
3103                                         o_ptr->pval++;
3104
3105                                         /* Unstack the used item */
3106                                         o_ptr->number--;
3107                                         caster_ptr->total_weight -= q_ptr->weight;
3108                                         item = inven_carry(q_ptr);
3109
3110                                         msg_print(_("杖をまとめなおした。", "You unstack your staff."));
3111                                 }
3112                         }
3113                         else
3114                         {
3115                                 msg_print(_("吸収できる魔力がありません!", "There's no energy there to absorb!"));
3116                         }
3117                         if (!o_ptr->pval) o_ptr->ident |= IDENT_EMPTY;
3118                 }
3119         }
3120
3121         /* Inflict the penalties for failing a recharge. */
3122         if (fail)
3123         {
3124                 /* Artifacts are never destroyed. */
3125                 if (object_is_fixed_artifact(o_ptr))
3126                 {
3127                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
3128                         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
3129
3130                         /* Artifact rods. */
3131                         if (o_ptr->tval == TV_ROD)
3132                                 o_ptr->timeout = k_ptr->pval * o_ptr->number;
3133
3134                         /* Artifact wands and staffs. */
3135                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
3136                                 o_ptr->pval = 0;
3137                 }
3138                 else
3139                 {
3140                         /* Get the object description */
3141                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3142
3143                         /*** Determine Seriousness of Failure ***/
3144
3145                         /* Mages recharge objects more safely. */
3146                         if (IS_WIZARD_CLASS(caster_ptr))
3147                         {
3148                                 /* 10% chance to blow up one rod, otherwise draining. */
3149                                 if (o_ptr->tval == TV_ROD)
3150                                 {
3151                                         if (one_in_(10)) fail_type = 2;
3152                                         else fail_type = 1;
3153                                 }
3154                                 /* 75% chance to blow up one wand, otherwise draining. */
3155                                 else if (o_ptr->tval == TV_WAND)
3156                                 {
3157                                         if (!one_in_(3)) fail_type = 2;
3158                                         else fail_type = 1;
3159                                 }
3160                                 /* 50% chance to blow up one staff, otherwise no effect. */
3161                                 else if (o_ptr->tval == TV_STAFF)
3162                                 {
3163                                         if (one_in_(2)) fail_type = 2;
3164                                         else fail_type = 0;
3165                                 }
3166                         }
3167
3168                         /* All other classes get no special favors. */
3169                         else
3170                         {
3171                                 /* 33% chance to blow up one rod, otherwise draining. */
3172                                 if (o_ptr->tval == TV_ROD)
3173                                 {
3174                                         if (one_in_(3)) fail_type = 2;
3175                                         else fail_type = 1;
3176                                 }
3177                                 /* 20% chance of the entire stack, else destroy one wand. */
3178                                 else if (o_ptr->tval == TV_WAND)
3179                                 {
3180                                         if (one_in_(5)) fail_type = 3;
3181                                         else fail_type = 2;
3182                                 }
3183                                 /* Blow up one staff. */
3184                                 else if (o_ptr->tval == TV_STAFF)
3185                                 {
3186                                         fail_type = 2;
3187                                 }
3188                         }
3189
3190                         /*** Apply draining and destruction. ***/
3191
3192                         /* Drain object or stack of objects. */
3193                         if (fail_type == 1)
3194                         {
3195                                 if (o_ptr->tval == TV_ROD)
3196                                 {
3197                                         msg_format(_("ロッドは破損を免れたが、魔力は全て失なわれた。",
3198                                                                  "You save your rod from destruction, but all charges are lost."), o_name);
3199                                         o_ptr->timeout = k_ptr->pval * o_ptr->number;
3200                                 }
3201                                 else if (o_ptr->tval == TV_WAND)
3202                                 {
3203                                         msg_format(_("%sは破損を免れたが、魔力が全て失われた。", "You save your %s from destruction, but all charges are lost."), o_name);
3204                                         o_ptr->pval = 0;
3205                                 }
3206                                 /* Staffs aren't drained. */
3207                         }
3208
3209                         /* Destroy an object or one in a stack of objects. */
3210                         if (fail_type == 2)
3211                         {
3212                                 if (o_ptr->number > 1)
3213                                 {
3214                                         msg_format(_("乱暴な魔法のために%sが一本壊れた!", "Wild magic consumes one of your %s!"), o_name);
3215                                         /* Reduce rod stack maximum timeout, drain wands. */
3216                                         if (o_ptr->tval == TV_ROD) o_ptr->timeout = MIN(o_ptr->timeout, k_ptr->pval * (o_ptr->number - 1));
3217                                         else if (o_ptr->tval == TV_WAND) o_ptr->pval = o_ptr->pval * (o_ptr->number - 1) / o_ptr->number;
3218                                 }
3219                                 else
3220                                 {
3221                                         msg_format(_("乱暴な魔法のために%sが何本か壊れた!", "Wild magic consumes your %s!"), o_name);
3222                                 }
3223                                 
3224                                 /* Reduce and describe caster_ptr->inventory_list */
3225                                 if (item >= 0)
3226                                 {
3227                                         inven_item_increase(item, -1);
3228                                         inven_item_describe(item);
3229                                         inven_item_optimize(item);
3230                                 }
3231
3232                                 /* Reduce and describe floor item */
3233                                 else
3234                                 {
3235                                         floor_item_increase(0 - item, -1);
3236                                         floor_item_describe(0 - item);
3237                                         floor_item_optimize(0 - item);
3238                                 }
3239                         }
3240
3241                         /* Destroy all members of a stack of objects. */
3242                         if (fail_type == 3)
3243                         {
3244                                 if (o_ptr->number > 1)
3245                                         msg_format(_("乱暴な魔法のために%sが全て壊れた!", "Wild magic consumes all your %s!"), o_name);
3246                                 else
3247                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
3248
3249                                 /* Reduce and describe caster_ptr->inventory_list */
3250                                 if (item >= 0)
3251                                 {
3252                                         inven_item_increase(item, -999);
3253                                         inven_item_describe(item);
3254                                         inven_item_optimize(item);
3255                                 }
3256
3257                                 /* Reduce and describe floor item */
3258                                 else
3259                                 {
3260                                         floor_item_increase(0 - item, -999);
3261                                         floor_item_describe(0 - item);
3262                                         floor_item_optimize(0 - item);
3263                                 }
3264                         }
3265                 }
3266         }
3267
3268         if (caster_ptr->csp > caster_ptr->msp)
3269         {
3270                 caster_ptr->csp = caster_ptr->msp;
3271         }
3272
3273         caster_ptr->redraw |= (PR_MANA);
3274         caster_ptr->update |= (PU_COMBINE | PU_REORDER);
3275         caster_ptr->window |= (PW_INVEN);
3276
3277         return TRUE;
3278 }
3279
3280
3281 /*!
3282  * @brief 皆殺し(全方向攻撃)処理
3283  * @param py プレイヤーY座標
3284  * @param px プレイヤーX座標
3285  * @return なし
3286  */
3287 void massacre(player_type *caster_ptr)
3288 {
3289         POSITION x, y;
3290         grid_type *g_ptr;
3291         monster_type *m_ptr;
3292         DIRECTION dir;
3293
3294         for (dir = 0; dir < 8; dir++)
3295         {
3296                 y = caster_ptr->y + ddy_ddd[dir];
3297                 x = caster_ptr->x + ddx_ddd[dir];
3298                 g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][x];
3299                 m_ptr = &caster_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
3300
3301                 /* Hack -- attack monsters */
3302                 if (g_ptr->m_idx && (m_ptr->ml || cave_have_flag_bold(y, x, FF_PROJECT)))
3303                         py_attack(caster_ptr, y, x, 0);
3304         }
3305 }
3306
3307 bool eat_lock(player_type *caster_ptr)
3308 {
3309         POSITION x, y;
3310         grid_type *g_ptr;
3311         feature_type *f_ptr, *mimic_f_ptr;
3312         DIRECTION dir;
3313
3314         if (!get_direction(&dir, FALSE, FALSE)) return FALSE;
3315         y = caster_ptr->y + ddy[dir];
3316         x = caster_ptr->x + ddx[dir];
3317         g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][x];
3318         f_ptr = &f_info[g_ptr->feat];
3319         mimic_f_ptr = &f_info[get_feat_mimic(g_ptr)];
3320
3321         stop_mouth();
3322
3323         if (!have_flag(mimic_f_ptr->flags, FF_HURT_ROCK))
3324         {
3325                 msg_print(_("この地形は食べられない。", "You cannot eat this feature."));
3326         }
3327         else if (have_flag(f_ptr->flags, FF_PERMANENT))
3328         {
3329                 msg_format(_("いてっ!この%sはあなたの歯より硬い!", "Ouch!  This %s is harder than your teeth!"), f_name + mimic_f_ptr->name);
3330         }
3331         else if (g_ptr->m_idx)
3332         {
3333                 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
3334                 msg_print(_("何かが邪魔しています!", "There's something in the way!"));
3335
3336                 if (!m_ptr->ml || !is_pet(m_ptr)) py_attack(caster_ptr, y, x, 0);
3337         }
3338         else if (have_flag(f_ptr->flags, FF_TREE))
3339         {
3340                 msg_print(_("木の味は好きじゃない!", "You don't like the woody taste!"));
3341         }
3342         else if (have_flag(f_ptr->flags, FF_GLASS))
3343         {
3344                 msg_print(_("ガラスの味は好きじゃない!", "You don't like the glassy taste!"));
3345         }
3346         else if (have_flag(f_ptr->flags, FF_DOOR) || have_flag(f_ptr->flags, FF_CAN_DIG))
3347         {
3348                 (void)set_food(caster_ptr, caster_ptr->food + 3000);
3349         }
3350         else if (have_flag(f_ptr->flags, FF_MAY_HAVE_GOLD) || have_flag(f_ptr->flags, FF_HAS_GOLD))
3351         {
3352                 (void)set_food(caster_ptr, caster_ptr->food + 5000);
3353         }
3354         else
3355         {
3356                 msg_format(_("この%sはとてもおいしい!", "This %s is very filling!"), f_name + mimic_f_ptr->name);
3357                 (void)set_food(caster_ptr, caster_ptr->food + 10000);
3358         }
3359
3360         /* Destroy the wall */
3361         cave_alter_feat(y, x, FF_HURT_ROCK);
3362
3363         (void)move_player_effect(caster_ptr, y, x, MPE_DONT_PICKUP);
3364         return TRUE;
3365 }
3366
3367
3368 bool shock_power(player_type *caster_ptr)
3369 {
3370         DIRECTION dir;
3371         POSITION y, x;
3372         HIT_POINT dam;
3373         PLAYER_LEVEL plev = caster_ptr->lev;
3374         int boost = P_PTR_KI;
3375         if (heavy_armor(caster_ptr)) boost /= 2;
3376
3377         project_length = 1;
3378         if (!get_aim_dir(&dir)) return FALSE;
3379
3380         y = caster_ptr->y + ddy[dir];
3381         x = caster_ptr->x + ddx[dir];
3382         dam = damroll(8 + ((plev - 5) / 4) + boost / 12, 8);
3383         fire_beam(GF_MISSILE, dir, dam);
3384         if (caster_ptr->current_floor_ptr->grid_array[y][x].m_idx)
3385         {
3386                 int i;
3387                 POSITION ty = y, tx = x;
3388                 POSITION oy = y, ox = x;
3389                 MONSTER_IDX m_idx = caster_ptr->current_floor_ptr->grid_array[y][x].m_idx;
3390                 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[m_idx];
3391                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3392                 GAME_TEXT m_name[MAX_NLEN];
3393
3394                 monster_desc(m_name, m_ptr, 0);
3395
3396                 if (randint1(r_ptr->level * 3 / 2) > randint0(dam / 2) + dam / 2)
3397                 {
3398                         msg_format(_("%sは飛ばされなかった。", "%^s was not blown away."), m_name);
3399                 }
3400                 else
3401                 {
3402                         for (i = 0; i < 5; i++)
3403                         {
3404                                 y += ddy[dir];
3405                                 x += ddx[dir];
3406                                 if (cave_empty_bold(caster_ptr->current_floor_ptr, y, x))
3407                                 {
3408                                         ty = y;
3409                                         tx = x;
3410                                 }
3411                                 else break;
3412                         }
3413                         if ((ty != oy) || (tx != ox))
3414                         {
3415                                 msg_format(_("%sを吹き飛ばした!", "You blow %s away!"), m_name);
3416                                 caster_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = 0;
3417                                 caster_ptr->current_floor_ptr->grid_array[ty][tx].m_idx = m_idx;
3418                                 m_ptr->fy = ty;
3419                                 m_ptr->fx = tx;
3420
3421                                 update_monster(caster_ptr, m_idx, TRUE);
3422                                 lite_spot(oy, ox);
3423                                 lite_spot(ty, tx);
3424
3425                                 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
3426                                         caster_ptr->update |= (PU_MON_LITE);
3427                         }
3428                 }
3429         }
3430         return TRUE;
3431 }
3432
3433 bool booze(player_type *creature_ptr)
3434 {
3435         bool ident = FALSE;
3436         if (creature_ptr->pclass != CLASS_MONK) chg_virtue(p_ptr, V_HARMONY, -1);
3437         else if (!creature_ptr->resist_conf) creature_ptr->special_attack |= ATTACK_SUIKEN;
3438         if (!creature_ptr->resist_conf)
3439         {
3440                 if (set_confused(p_ptr, randint0(20) + 15))
3441                 {
3442                         ident = TRUE;
3443                 }
3444         }
3445
3446         if (!creature_ptr->resist_chaos)
3447         {
3448                 if (one_in_(2))
3449                 {
3450                         if (set_image(p_ptr, creature_ptr->image + randint0(150) + 150))
3451                         {
3452                                 ident = TRUE;
3453                         }
3454                 }
3455                 if (one_in_(13) && (creature_ptr->pclass != CLASS_MONK))
3456                 {
3457                         ident = TRUE;
3458                         if (one_in_(3)) lose_all_info(p_ptr);
3459                         else wiz_dark(creature_ptr);
3460                         (void)teleport_player_aux(creature_ptr, 100, TELEPORT_NONMAGICAL | TELEPORT_PASSIVE);
3461                         wiz_dark(creature_ptr);
3462                         msg_print(_("知らない場所で目が醒めた。頭痛がする。", "You wake up somewhere with a sore head..."));
3463                         msg_print(_("何も思い出せない。どうやってここへ来たのかも分からない!", "You can't remember a thing, or how you got here!"));
3464                 }
3465         }
3466         return ident;
3467 }
3468
3469 bool detonation(player_type *creature_ptr)
3470 {
3471         msg_print(_("体の中で激しい爆発が起きた!", "Massive explosions rupture your body!"));
3472         take_hit(p_ptr, DAMAGE_NOESCAPE, damroll(50, 20), _("爆発の薬", "a potion of Detonation"), -1);
3473         (void)set_stun(p_ptr, creature_ptr->stun + 75);
3474         (void)set_cut(p_ptr,creature_ptr->cut + 5000);
3475         return TRUE;
3476 }
3477
3478 void blood_curse_to_enemy(player_type *caster_ptr, MONSTER_IDX m_idx)
3479 {
3480         monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[m_idx];
3481         grid_type *g_ptr = &caster_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
3482         BIT_FLAGS curse_flg = (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP);
3483         int count = 0;
3484         do
3485         {
3486                 switch (randint1(28))
3487                 {
3488                 case 1: case 2:
3489                         if (!count)
3490                         {
3491                                 msg_print(_("地面が揺れた...", "The ground trembles..."));
3492                                 earthquake(caster_ptr, m_ptr->fy, m_ptr->fx, 4 + randint0(4), 0);
3493                                 if (!one_in_(6)) break;
3494                         }
3495                 case 3: case 4: case 5: case 6:
3496                         if (!count)
3497                         {
3498                                 int extra_dam = damroll(10, 10);
3499                                 msg_print(_("純粋な魔力の次元への扉が開いた!", "A portal opens to a plane of raw mana!"));
3500
3501                                 project(caster_ptr, 0, 8, m_ptr->fy, m_ptr->fx, extra_dam, GF_MANA, curse_flg, -1);
3502                                 if (!one_in_(6)) break;
3503                         }
3504                 case 7: case 8:
3505                         if (!count)
3506                         {
3507                                 msg_print(_("空間が歪んだ!", "Space warps about you!"));
3508
3509                                 if (m_ptr->r_idx) teleport_away(caster_ptr, g_ptr->m_idx, damroll(10, 10), TELEPORT_PASSIVE);
3510                                 if (one_in_(13)) count += activate_hi_summon(m_ptr->fy, m_ptr->fx, TRUE);
3511                                 if (!one_in_(6)) break;
3512                         }
3513                 case 9: case 10: case 11:
3514                         msg_print(_("エネルギーのうねりを感じた!", "You feel a surge of energy!"));
3515                         project(caster_ptr, 0, 7, m_ptr->fy, m_ptr->fx, 50, GF_DISINTEGRATE, curse_flg, -1);
3516                         if (!one_in_(6)) break;
3517                 case 12: case 13: case 14: case 15: case 16:
3518                         aggravate_monsters(0);
3519                         if (!one_in_(6)) break;
3520                 case 17: case 18:
3521                         count += activate_hi_summon(m_ptr->fy, m_ptr->fx, TRUE);
3522                         if (!one_in_(6)) break;
3523                 case 19: case 20: case 21: case 22:
3524                 {
3525                         bool pet = !one_in_(3);
3526                         BIT_FLAGS mode = PM_ALLOW_GROUP;
3527
3528                         if (pet) mode |= PM_FORCE_PET;
3529                         else mode |= (PM_NO_PET | PM_FORCE_FRIENDLY);
3530
3531                         count += summon_specific((pet ? -1 : 0), caster_ptr->y, caster_ptr->x, (pet ? caster_ptr->lev * 2 / 3 + randint1(caster_ptr->lev / 2) : caster_ptr->current_floor_ptr->dun_level), 0, mode);
3532                         if (!one_in_(6)) break;
3533                 }
3534                 case 23: case 24: case 25:
3535                         if (caster_ptr->hold_exp && (randint0(100) < 75)) break;
3536                         msg_print(_("経験値が体から吸い取られた気がする!", "You feel your experience draining away..."));
3537
3538                         if (caster_ptr->hold_exp) lose_exp(caster_ptr, caster_ptr->exp / 160);
3539                         else lose_exp(caster_ptr, caster_ptr->exp / 16);
3540                         if (!one_in_(6)) break;
3541                 case 26: case 27: case 28:
3542                 {
3543                         int i = 0;
3544                         if (one_in_(13))
3545                         {
3546                                 while (i < A_MAX)
3547                                 {
3548                                         do
3549                                         {
3550                                                 (void)do_dec_stat(caster_ptr, i);
3551                                         } while (one_in_(2));
3552
3553                                         i++;
3554                                 }
3555                         }
3556                         else
3557                         {
3558                                 (void)do_dec_stat(caster_ptr, randint0(6));
3559                         }
3560                         break;
3561                 }
3562                 }
3563         } while (one_in_(5));
3564 }
3565
3566 /*!
3567  * @brief クリムゾンを発射する / Fire Crimson, evoluting gun.
3568  @ @param shooter_ptr 射撃を行うクリーチャー参照
3569  * @return キャンセルした場合 false.
3570  * @details
3571  * Need to analyze size of the window.
3572  * Need more color coding.
3573  */
3574 bool fire_crimson(player_type *shooter_ptr)
3575 {
3576         int num = 1;
3577         int i;
3578         BIT_FLAGS flg = PROJECT_STOP | PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
3579         POSITION tx, ty;
3580         DIRECTION dir;
3581
3582         if (!get_aim_dir(&dir)) return FALSE;
3583
3584         /* Use the given direction */
3585         tx = shooter_ptr->x + 99 * ddx[dir];
3586         ty = shooter_ptr->y + 99 * ddy[dir];
3587
3588         /* Hack -- Use an actual "target" */
3589         if ((dir == 5) && target_okay())
3590         {
3591                 tx = target_col;
3592                 ty = target_row;
3593         }
3594
3595         if (shooter_ptr->pclass == CLASS_ARCHER)
3596         {
3597                 /* Extra shot at level 10 */
3598                 if (shooter_ptr->lev >= 10) num++;
3599
3600                 /* Extra shot at level 30 */
3601                 if (shooter_ptr->lev >= 30) num++;
3602
3603                 /* Extra shot at level 45 */
3604                 if (shooter_ptr->lev >= 45) num++;
3605         }
3606
3607         for (i = 0; i < num; i++)
3608                 project(shooter_ptr, 0, shooter_ptr->lev / 20 + 1, ty, tx, shooter_ptr->lev*shooter_ptr->lev * 6 / 50, GF_ROCKET, flg, -1);
3609
3610         return TRUE;
3611 }
3612
3613
3614 /*!
3615  * @brief 町間のテレポートを行うメインルーチン。
3616  * @return テレポート処理を決定したか否か
3617  */
3618 bool tele_town(player_type *caster_ptr)
3619 {
3620         int i;
3621         POSITION x, y;
3622         int num = 0;
3623
3624         if (caster_ptr->current_floor_ptr->dun_level)
3625         {
3626                 msg_print(_("この魔法は地上でしか使えない!", "This spell can only be used on the surface!"));
3627                 return FALSE;
3628         }
3629
3630         if (caster_ptr->current_floor_ptr->inside_arena || caster_ptr->phase_out)
3631         {
3632                 msg_print(_("この魔法は外でしか使えない!", "This spell can only be used outside!"));
3633                 return FALSE;
3634         }
3635
3636         screen_save();
3637         clear_bldg(4, 10);
3638
3639         for (i = 1; i < max_towns; i++)
3640         {
3641                 char buf[80];
3642
3643                 if ((i == NO_TOWN) || (i == SECRET_TOWN) || (i == caster_ptr->town_num) || !(caster_ptr->visit & (1L << (i - 1)))) continue;
3644
3645                 sprintf(buf, "%c) %-20s", I2A(i - 1), town_info[i].name);
3646                 prt(buf, 5 + i, 5);
3647                 num++;
3648         }
3649
3650         if (!num)
3651         {
3652                 msg_print(_("まだ行けるところがない。", "You have not yet visited any town."));
3653                 msg_print(NULL);
3654                 screen_load();
3655                 return FALSE;
3656         }
3657
3658         prt(_("どこに行きますか:", "Which town you go: "), 0, 0);
3659         while (1)
3660         {
3661                 i = inkey();
3662
3663                 if (i == ESCAPE)
3664                 {
3665                         screen_load();
3666                         return FALSE;
3667                 }
3668                 else if ((i < 'a') || (i > ('a' + max_towns - 2))) continue;
3669                 else if (((i - 'a' + 1) == caster_ptr->town_num) || ((i - 'a' + 1) == NO_TOWN) || ((i - 'a' + 1) == SECRET_TOWN) || !(caster_ptr->visit & (1L << (i - 'a')))) continue;
3670                 break;
3671         }
3672
3673         for (y = 0; y < current_world_ptr->max_wild_y; y++)
3674         {
3675                 for (x = 0; x < current_world_ptr->max_wild_x; x++)
3676                 {
3677                         if (wilderness[y][x].town == (i - 'a' + 1))
3678                         {
3679                                 caster_ptr->wilderness_y = y;
3680                                 caster_ptr->wilderness_x = x;
3681                         }
3682                 }
3683         }
3684
3685         caster_ptr->leaving = TRUE;
3686         caster_ptr->leave_bldg = TRUE;
3687         caster_ptr->teleport_town = TRUE;
3688         screen_load();
3689         return TRUE;
3690 }