OSDN Git Service

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