OSDN Git Service

[Refactor] #37353 PROJECT_* 定義を新規ファイル projection.h へ移動。 / Move PROJECT_* definition...
[hengband/hengband.git] / src / xtra2.c
1 /*!
2  * @file xtra2.c
3  * @brief 雑多なその他の処理2 / effects of various "objects"
4  * @date 2014/02/06
5  * @author
6  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke\n
7  * This software may be copied and distributed for educational, research, and\n
8  * not for profit purposes provided that this copyright and statement are\n
9  * included in all such copies.\n
10  * 2014 Deskull rearranged comment for Doxygen.
11  */
12
13
14 #include "angband.h"
15 #include "cmd-pet.h"
16 #include "object-curse.h"
17 #include "monsterrace-hook.h"
18 #include "objectkind-hook.h"
19 #include "sort.h"
20 #include "projection.h"
21
22 #define REWARD_CHANCE 10
23
24
25 /*!
26  * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
27  * Advance experience levels and print experience
28  * @return なし
29  */
30 void check_experience(void)
31 {
32         bool level_reward = FALSE;
33         bool level_mutation = FALSE;
34         bool level_inc_stat = FALSE;
35         bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
36         PLAYER_LEVEL old_lev = p_ptr->lev;
37
38         /* Hack -- lower limit */
39         if (p_ptr->exp < 0) p_ptr->exp = 0;
40         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
41         if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
42
43         /* Hack -- upper limit */
44         if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
45         if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
46         if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
47
48         /* Hack -- maintain "max" experience */
49         if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
50
51         /* Hack -- maintain "max max" experience */
52         if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
53
54         /* Redraw experience */
55         p_ptr->redraw |= (PR_EXP);
56         handle_stuff();
57
58
59         /* Lose levels while possible */
60         while ((p_ptr->lev > 1) &&
61                (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
62         {
63                 /* Lose a level */
64                 p_ptr->lev--;
65                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
66                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
67                 p_ptr->window |= (PW_PLAYER);
68                 handle_stuff();
69         }
70
71
72         /* Gain levels while possible */
73         while ((p_ptr->lev < PY_MAX_LEVEL) &&
74                (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
75         {
76                 /* Gain a level */
77                 p_ptr->lev++;
78
79                 /* Save the highest level */
80                 if (p_ptr->lev > p_ptr->max_plv)
81                 {
82                         p_ptr->max_plv = p_ptr->lev;
83
84                         if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
85                             (p_ptr->muta2 & MUT2_CHAOS_GIFT))
86                         {
87                                 level_reward = TRUE;
88                         }
89                         if (p_ptr->prace == RACE_BEASTMAN)
90                         {
91                                 if (one_in_(5)) level_mutation = TRUE;
92                         }
93                         level_inc_stat = TRUE;
94
95                         do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
96                 }
97
98                 sound(SOUND_LEVEL);
99
100                 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
101
102                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
103                 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
104                 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
105
106                 /* HPとMPの上昇量を表示 */
107                 level_up = 1;
108                 handle_stuff();
109
110                 level_up = 0;
111
112                 if (level_inc_stat)
113                 {
114                         if(!(p_ptr->max_plv % 10))
115                         {
116                                 int choice;
117                                 screen_save();
118                                 while(1)
119                                 {
120                                         int n;
121                                         char tmp[32];
122
123                                         cnv_stat(p_ptr->stat_max[0], tmp);
124                                         prt(format(_("        a) 腕力 (現在値 %s)", "        a) Str (cur %s)"), tmp), 2, 14);
125                                         cnv_stat(p_ptr->stat_max[1], tmp);
126                                         prt(format(_("        b) 知能 (現在値 %s)", "        a) Int (cur %s)"), tmp), 3, 14);
127                                         cnv_stat(p_ptr->stat_max[2], tmp);
128                                         prt(format(_("        c) 賢さ (現在値 %s)", "        a) Wis (cur %s)"), tmp), 4, 14);
129                                         cnv_stat(p_ptr->stat_max[3], tmp);
130                                         prt(format(_("        d) 器用 (現在値 %s)", "        a) Dex (cur %s)"), tmp), 5, 14);
131                                         cnv_stat(p_ptr->stat_max[4], tmp);
132                                         prt(format(_("        e) 耐久 (現在値 %s)", "        a) Con (cur %s)"), tmp), 6, 14);
133                                         cnv_stat(p_ptr->stat_max[5], tmp);
134                                         prt(format(_("        f) 魅力 (現在値 %s)", "        a) Chr (cur %s)"), tmp), 7, 14);
135
136                                         prt("", 8, 14);
137                                         prt(_("        どの能力値を上げますか?", "        Which stat do you want to raise?"), 1, 14);
138
139                                         while(1)
140                                         {
141                                                 choice = inkey();
142                                                 if ((choice >= 'a') && (choice <= 'f')) break;
143                                         }
144                                         for(n = 0; n < A_MAX; n++)
145                                                 if (n != choice - 'a')
146                                                         prt("",n+2,14);
147                                         if (get_check(_("よろしいですか?", "Are you sure? "))) break;
148                                 }
149                                 do_inc_stat(choice - 'a');
150                                 screen_load();
151                         }
152                         else if(!(p_ptr->max_plv % 2))
153                                 do_inc_stat(randint0(6));
154                 }
155
156                 if (level_mutation)
157                 {
158                         msg_print(_("あなたは変わった気がする...", "You feel different..."));
159                         (void)gain_random_mutation(0);
160                         level_mutation = FALSE;
161                 }
162
163                 /*
164                  * 報酬でレベルが上ると再帰的に check_experience() が
165                  * 呼ばれるので順番を最後にする。
166                  */
167                 if (level_reward)
168                 {
169                         gain_level_reward(0);
170                         level_reward = FALSE;
171                 }
172
173                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
174                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
175                 p_ptr->window |= (PW_PLAYER | PW_SPELL);
176                 handle_stuff();
177         }
178
179         /* Load an autopick preference file */
180         if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
181 }
182
183
184 /*!
185  * @brief モンスターを倒した際の財宝svalを返す
186  * @param r_idx 倒したモンスターの種族ID
187  * @return 財宝のsval
188  * @details
189  * Hack -- Return the "automatic coin type" of a monster race
190  * Used to allocate proper treasure when "Creeping coins" die
191  * Note the use of actual "monster names"
192  */
193 static OBJECT_SUBTYPE_VALUE get_coin_type(MONRACE_IDX r_idx)
194 {
195         /* Analyze monsters */
196         switch (r_idx)
197         {
198                 case MON_COPPER_COINS: return 2;
199                 case MON_SILVER_COINS: return 5;
200                 case MON_GOLD_COINS: return 10;
201                 case MON_MITHRIL_COINS:
202                 case MON_MITHRIL_GOLEM: return 16;
203                 case MON_ADAMANT_COINS: return 17;
204         }
205
206         /* Assume nothing */
207         return 0;
208 }
209
210
211
212 /*!
213  * @brief クエストを達成状態にする /
214  * @param quest_num 達成状態にしたいクエストのID
215  * @return なし
216  */
217 void complete_quest(QUEST_IDX quest_num)
218 {
219         quest_type* const q_ptr = &quest[quest_num];
220
221         switch (q_ptr->type)
222         {
223         case QUEST_TYPE_RANDOM:
224                 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
225                 break;
226         default:
227                 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
228                 break;
229         }
230
231         q_ptr->status = QUEST_STATUS_COMPLETED;
232         q_ptr->complev = (byte)p_ptr->lev;
233         update_playtime();
234         q_ptr->comptime = playtime;
235
236         if (!(q_ptr->flags & QUEST_FLAG_SILENT))
237         {
238                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
239                 msg_print(_("クエストを達成した!", "You just completed your quest!"));
240                 msg_print(NULL);
241         }
242 }
243
244 /*!
245  * @brief 現在フロアに残っている敵モンスターの数を返す /
246  * @return 現在の敵モンスターの数
247  */
248 static MONSTER_NUMBER count_all_hostile_monsters(void)
249 {
250         POSITION x, y;
251         MONSTER_NUMBER number_mon = 0;
252
253         for (x = 0; x < cur_wid; ++ x)
254         {
255                 for (y = 0; y < cur_hgt; ++ y)
256                 {
257                         MONSTER_IDX m_idx = cave[y][x].m_idx;
258
259                         if (m_idx > 0 && is_hostile(&m_list[m_idx]))
260                         {
261                                 ++number_mon;
262                         }
263                 }
264         }
265
266         return number_mon;
267 }
268
269 /*!
270  * @brief 特定の敵を倒した際にクエスト達成処理 /
271  * Check for "Quest" completion when a quest monster is killed or charmed.
272  * @param m_ptr 撃破したモンスターの構造体参照ポインタ
273  * @return なし
274  */
275 void check_quest_completion(monster_type *m_ptr)
276 {
277         POSITION y, x;
278         QUEST_IDX quest_num;
279
280         bool create_stairs = FALSE;
281         bool reward = FALSE;
282
283         object_type forge;
284         object_type *o_ptr;
285
286         y = m_ptr->fy;
287         x = m_ptr->fx;
288
289         /* Inside a quest */
290         quest_num = p_ptr->inside_quest;
291
292         /* Search for an active quest on this dungeon level */
293         if (!quest_num)
294         {
295                 QUEST_IDX i;
296
297                 for (i = max_q_idx - 1; i > 0; i--)
298                 {
299                         quest_type* const q_ptr = &quest[i];
300                         
301                         /* Quest is not active */
302                         if (q_ptr->status != QUEST_STATUS_TAKEN)
303                                 continue;
304
305                         /* Quest is not a dungeon quest */
306                         if (q_ptr->flags & QUEST_FLAG_PRESET)
307                                 continue;
308
309                         /* Quest is not on this level */
310                         if ((q_ptr->level != dun_level) &&
311                             (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
312                                 continue;
313
314                         /* Not a "kill monster" quest */
315                         if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
316                             (q_ptr->type == QUEST_TYPE_FIND_EXIT))
317                                 continue;
318
319                         /* Interesting quest */
320                         if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
321                             (q_ptr->type == QUEST_TYPE_TOWER) ||
322                             (q_ptr->type == QUEST_TYPE_KILL_ALL))
323                                 break;
324
325                         /* Interesting quest */
326                         if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
327                              (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
328                              (q_ptr->type == QUEST_TYPE_RANDOM)) &&
329                              (q_ptr->r_idx == m_ptr->r_idx))
330                                 break;
331                 }
332
333                 quest_num = i;
334         }
335
336         /* Handle the current quest */
337         if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
338         {
339                 /* Current quest */
340                 quest_type* const q_ptr = &quest[quest_num];
341
342                 switch (q_ptr->type)
343                 {
344                         case QUEST_TYPE_KILL_NUMBER:
345                         {
346                                 q_ptr->cur_num++;
347
348                                 if (q_ptr->cur_num >= q_ptr->num_mon)
349                                 {
350                                         complete_quest(quest_num);
351
352                                         q_ptr->cur_num = 0;
353                                 }
354                                 break;
355                         }
356                         case QUEST_TYPE_KILL_ALL:
357                         {
358                                 if (!is_hostile(m_ptr)) break;
359
360                                 if (count_all_hostile_monsters() == 1)
361                                 {
362                                         if (q_ptr->flags & QUEST_FLAG_SILENT)
363                                         {
364                                                 q_ptr->status = QUEST_STATUS_FINISHED;
365                                         }
366                                         else
367                                         {
368                                                 complete_quest(quest_num);
369                                         }
370                                 }
371                                 break;
372                         }
373                         case QUEST_TYPE_KILL_LEVEL:
374                         case QUEST_TYPE_RANDOM:
375                         {
376                                 /* Only count valid monsters */
377                                 if (q_ptr->r_idx != m_ptr->r_idx)
378                                         break;
379
380                                 q_ptr->cur_num++;
381
382                                 if (q_ptr->cur_num >= q_ptr->max_num)
383                                 {
384                                         complete_quest(quest_num);
385
386                                         if (!(q_ptr->flags & QUEST_FLAG_PRESET))
387                                         {
388                                                 create_stairs = TRUE;
389                                                 p_ptr->inside_quest = 0;
390                                         }
391
392                                         /* Finish the two main quests without rewarding */
393                                         if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
394                                         {
395                                                 q_ptr->status = QUEST_STATUS_FINISHED;
396                                         }
397
398                                         if (q_ptr->type == QUEST_TYPE_RANDOM)
399                                         {
400                                                 reward = TRUE;
401                                                 q_ptr->status = QUEST_STATUS_FINISHED;
402                                         }
403                                 }
404                                 break;
405                         }
406                         case QUEST_TYPE_KILL_ANY_LEVEL:
407                         {
408                                 q_ptr->cur_num++;
409                                 if (q_ptr->cur_num >= q_ptr->max_num)
410                                 {
411                                         complete_quest(quest_num);
412                                         q_ptr->cur_num = 0;
413                                 }
414                                 break;
415                         }
416                         case QUEST_TYPE_TOWER:
417                         {
418                                 if (!is_hostile(m_ptr)) break;
419
420                                 if (count_all_hostile_monsters() == 1)
421                                 {
422                                         q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
423
424                                         if((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
425                                            (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
426                                            (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
427                                         {
428
429                                                 complete_quest(QUEST_TOWER1);
430                                         }
431                                 }
432                                 break;
433                         }
434                 }
435         }
436
437         /* Create a magical staircase */
438         if (create_stairs)
439         {
440                 POSITION ny, nx;
441
442                 /* Stagger around */
443                 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT) )
444                 {
445                         /* Pick a location */
446                         scatter(&ny, &nx, y, x, 1, 0);
447
448                         /* Stagger */
449                         y = ny; x = nx;
450                 }
451
452                 /* Explain the staircase */
453                 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
454
455                 /* Create stairs down */
456                 cave_set_feat(y, x, feat_down_stair);
457
458                 /* Remember to update everything */
459                 p_ptr->update |= (PU_FLOW);
460         }
461
462         /*
463          * Drop quest reward
464          */
465         if (reward)
466         {
467                 int i;
468
469                 for (i = 0; i < (dun_level / 15)+1; i++)
470                 {
471                         o_ptr = &forge;
472                         object_wipe(o_ptr);
473
474                         /* Make a great object */
475                         make_object(o_ptr, AM_GOOD | AM_GREAT);
476                         (void)drop_near(o_ptr, -1, y, x);
477                 }
478         }
479 }
480
481 /*!
482  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
483  * Check for "Quest" completion when a quest monster is killed or charmed.
484  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
485  * @return なし
486  */
487 void check_find_art_quest_completion(object_type *o_ptr)
488 {
489         QUEST_IDX i;
490         /* Check if completed a quest */
491         for (i = 0; i < max_q_idx; i++)
492         {
493                 if((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
494                         (quest[i].status == QUEST_STATUS_TAKEN) &&
495                         (quest[i].k_idx == o_ptr->name1))
496                 {
497                         complete_quest(i);
498                 }
499         }
500 }
501
502
503 /*!
504  * @brief モンスターを撃破した際の述語メッセージを返す /
505  * Return monster death string
506  * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
507  * @return 撃破されたモンスターの述語
508  */
509 concptr extract_note_dies(MONRACE_IDX r_idx)
510 {
511         monster_race *r_ptr = &r_info[r_idx];
512         /* Some monsters get "destroyed" */
513         if (!monster_living(r_idx))
514         {
515                 int i;
516
517                 for (i = 0; i < 4; i++)
518                 {
519                         if (r_ptr->blow[i].method == RBM_EXPLODE)
520                         {
521                                 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
522                         }
523                 }
524                 return _("を倒した。", " is destroyed.");
525         }
526
527         /* Assume a default death */
528         return _("は死んだ。", " dies.");
529 }
530
531
532 /*!
533  * @brief モンスターが死亡した時の処理 /
534  * Handle the "death" of a monster.
535  * @param m_idx 死亡したモンスターのID
536  * @param drop_item TRUEならばモンスターのドロップ処理を行う
537  * @return 撃破されたモンスターの述語
538  * @details
539  * <pre>
540  * Disperse treasures centered at the monster location based on the
541  * various flags contained in the monster flags fields.
542  * Check for "Quest" completion when a quest monster is killed.
543  * Note that only the player can induce "monster_death()" on Uniques.
544  * Thus (for now) all Quest monsters should be Uniques.
545  * Note that monsters can now carry objects, and when a monster dies,
546  * it drops all of its objects, which may disappear in crowded rooms.
547  * </pre>
548  */
549 void monster_death(MONSTER_IDX m_idx, bool drop_item)
550 {
551         int i, j;
552         POSITION y, x;
553
554         int dump_item = 0;
555         int dump_gold = 0;
556         int number = 0;
557
558         monster_type *m_ptr = &m_list[m_idx];
559         monster_race *r_ptr = &r_info[m_ptr->r_idx];
560
561         bool visible = ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE));
562
563         u32b mo_mode = 0L;
564
565         bool do_gold = (!(r_ptr->flags1 & RF1_ONLY_ITEM));
566         bool do_item = (!(r_ptr->flags1 & RF1_ONLY_GOLD));
567         bool cloned = (m_ptr->smart & SM_CLONED) ? TRUE : FALSE;
568         int force_coin = get_coin_type(m_ptr->r_idx);
569
570         object_type forge;
571         object_type *q_ptr;
572
573         bool drop_chosen_item = drop_item && !cloned && !p_ptr->inside_arena
574                 && !p_ptr->inside_battle && !is_pet(m_ptr);
575
576         /* The caster is dead? */
577         if (world_monster && world_monster == m_idx) world_monster = 0;
578
579         /* Notice changes in view */
580         if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
581         {
582                 /* Update some things */
583                 p_ptr->update |= (PU_MON_LITE);
584         }
585
586         y = m_ptr->fy;
587         x = m_ptr->fx;
588
589         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
590         {
591                 GAME_TEXT m_name[MAX_NLEN];
592
593                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
594                 do_cmd_write_nikki(NIKKI_NAMED_PET, 3, m_name);
595         }
596
597         /* Let monsters explode! */
598         for (i = 0; i < 4; i++)
599         {
600                 if (r_ptr->blow[i].method == RBM_EXPLODE)
601                 {
602                         BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
603                         EFFECT_ID typ = mbe_info[r_ptr->blow[i].effect].explode_type;
604                         DICE_NUMBER d_dice = r_ptr->blow[i].d_dice;
605                         DICE_SID d_side = r_ptr->blow[i].d_side;
606                         HIT_POINT damage = damroll(d_dice, d_side);
607
608                         project(m_idx, 3, y, x, damage, typ, flg, -1);
609                         break;
610                 }
611         }
612
613         if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
614         {
615                 choose_new_monster(m_idx, TRUE, MON_CHAMELEON);
616                 r_ptr = &r_info[m_ptr->r_idx];
617         }
618
619         /* Check for quest completion */
620         check_quest_completion(m_ptr);
621
622         /* Handle the possibility of player vanquishing arena combatant -KMW- */
623         if (p_ptr->inside_arena && !is_pet(m_ptr))
624         {
625                 p_ptr->exit_bldg = TRUE;
626
627                 if (p_ptr->arena_number > MAX_ARENA_MONS)
628                 {
629                         msg_print(_("素晴らしい!君こそ真の勝利者だ。", "You are a Genuine Champion!"));
630                 }
631                 else
632                 {
633                         msg_print(_("勝利!チャンピオンへの道を進んでいる。", "Victorious! You're on your way to becoming Champion."));
634                 }
635
636                 if (arena_info[p_ptr->arena_number].tval)
637                 {
638                         q_ptr = &forge;
639
640                         /* Prepare to make a prize */
641                         object_prep(q_ptr, lookup_kind(arena_info[p_ptr->arena_number].tval, arena_info[p_ptr->arena_number].sval));
642                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
643                         (void)drop_near(q_ptr, -1, y, x);
644                 }
645
646                 if (p_ptr->arena_number > MAX_ARENA_MONS) p_ptr->arena_number++;
647                 p_ptr->arena_number++;
648                 if (record_arena)
649                 {
650                         GAME_TEXT m_name[MAX_NLEN];
651                         
652                         /* Extract monster name */
653                         monster_desc(m_name, m_ptr, MD_IGNORE_HALLU | MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
654                         
655                         do_cmd_write_nikki(NIKKI_ARENA, p_ptr->arena_number, m_name);
656                 }
657         }
658
659         if (m_idx == p_ptr->riding)
660         {
661                 if (rakuba(-1, FALSE))
662                 {
663                         msg_print(_("地面に落とされた。", "You have fallen from your riding pet."));
664                 }
665         }
666
667         /* Drop a dead corpse? */
668         if (one_in_(r_ptr->flags1 & RF1_UNIQUE ? 1 : 4) &&
669             (r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) &&
670             !(p_ptr->inside_arena || p_ptr->inside_battle || cloned || ((m_ptr->r_idx == today_mon) && is_pet(m_ptr))))
671         {
672                 /* Assume skeleton */
673                 bool corpse = FALSE;
674
675                 /*
676                  * We cannot drop a skeleton? Note, if we are in this check,
677                  * we *know* we can drop at least a corpse or a skeleton
678                  */
679                 if (!(r_ptr->flags9 & RF9_DROP_SKELETON))
680                         corpse = TRUE;
681                 else if ((r_ptr->flags9 & RF9_DROP_CORPSE) && (r_ptr->flags1 & RF1_UNIQUE))
682                         corpse = TRUE;
683
684                 /* Else, a corpse is more likely unless we did a "lot" of damage */
685                 else if (r_ptr->flags9 & RF9_DROP_CORPSE)
686                 {
687                         /* Lots of damage in one blow */
688                         if ((0 - ((m_ptr->maxhp) / 4)) > m_ptr->hp)
689                         {
690                                 if (one_in_(5)) corpse = TRUE;
691                         }
692                         else
693                         {
694                                 if (!one_in_(5)) corpse = TRUE;
695                         }
696                 }
697                 q_ptr = &forge;
698
699                 /* Prepare to make an object */
700                 object_prep(q_ptr, lookup_kind(TV_CORPSE, (corpse ? SV_CORPSE : SV_SKELETON)));
701
702                 apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
703
704                 q_ptr->pval = m_ptr->r_idx;
705                 (void)drop_near(q_ptr, -1, y, x);
706         }
707
708         /* Drop objects being carried */
709         monster_drop_carried_objects(m_ptr);
710
711         if (r_ptr->flags1 & RF1_DROP_GOOD) mo_mode |= AM_GOOD;
712         if (r_ptr->flags1 & RF1_DROP_GREAT) mo_mode |= AM_GREAT;
713
714         switch (m_ptr->r_idx)
715         {
716         case MON_PINK_HORROR:
717                 /* Pink horrors are replaced with 2 Blue horrors */
718                 if (!(p_ptr->inside_arena || p_ptr->inside_battle))
719                 {
720                         bool notice = FALSE;
721
722                         for (i = 0; i < 2; i++)
723                         {
724                                 POSITION wy = y, wx = x;
725                                 bool pet = is_pet(m_ptr);
726                                 BIT_FLAGS mode = 0L;
727
728                                 if (pet) mode |= PM_FORCE_PET;
729
730                                 if (summon_specific((pet ? -1 : m_idx), wy, wx, 100, SUMMON_BLUE_HORROR, mode, '\0'))
731                                 {
732                                         if (player_can_see_bold(wy, wx)) notice = TRUE;
733                                 }
734                         }
735
736                         if (notice) msg_print(_("ピンク・ホラーは分裂した!", "The Pink horror divides!"));
737                 }
738                 break;
739
740         case MON_BLOODLETTER:
741                 /* Bloodletters of Khorne may drop a blade of chaos */
742                 if (drop_chosen_item && (randint1(100) < 15))
743                 {
744                         q_ptr = &forge;
745
746                         /* Prepare to make a Blade of Chaos */
747                         object_prep(q_ptr, lookup_kind(TV_SWORD, SV_BLADE_OF_CHAOS));
748
749                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART | mo_mode);
750                         (void)drop_near(q_ptr, -1, y, x);
751                 }
752                 break;
753
754         case MON_RAAL:
755                 if (drop_chosen_item && (dun_level > 9))
756                 {
757                         q_ptr = &forge;
758                         object_wipe(q_ptr);
759
760                         /* Activate restriction */
761                         if ((dun_level > 49) && one_in_(5))
762                                 get_obj_num_hook = kind_is_good_book;
763                         else
764                                 get_obj_num_hook = kind_is_book;
765
766                         /* Make a book */
767                         make_object(q_ptr, mo_mode);
768                         (void)drop_near(q_ptr, -1, y, x);
769                 }
770                 break;
771
772         case MON_DAWN:
773                 /*
774                  * Mega^3-hack: killing a 'Warrior of the Dawn' is likely to
775                  * spawn another in the fallen one's place!
776                  */
777                 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
778                 {
779                         if (!one_in_(7))
780                         {
781                                 POSITION wy = y, wx = x;
782                                 int attempts = 100;
783                                 bool pet = is_pet(m_ptr);
784
785                                 do
786                                 {
787                                         scatter(&wy, &wx, y, x, 20, 0);
788                                 }
789                                 while (!(in_bounds(wy, wx) && cave_empty_bold2(wy, wx)) && --attempts);
790
791                                 if (attempts > 0)
792                                 {
793                                         BIT_FLAGS mode = 0L;
794                                         if (pet) mode |= PM_FORCE_PET;
795
796                                         if (summon_specific((pet ? -1 : m_idx), wy, wx, 100, SUMMON_DAWN, mode, '\0'))
797                                         {
798                                                 if (player_can_see_bold(wy, wx))
799                                                         msg_print(_("新たな戦士が現れた!", "A new warrior steps forth!"));
800                                         }
801                                 }
802                         }
803                 }
804                 break;
805
806         case MON_UNMAKER:
807                 /* One more ultra-hack: An Unmaker goes out with a big bang! */
808                 {
809                         BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
810                         (void)project(m_idx, 6, y, x, 100, GF_CHAOS, flg, -1);
811                 }
812                 break;
813
814         case MON_UNICORN_ORD:
815         case MON_MORGOTH:
816         case MON_ONE_RING:
817                 /* Reward for "lazy" player */
818                 if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
819                 {
820                         ARTIFACT_IDX a_idx = 0;
821                         artifact_type *a_ptr = NULL;
822
823                         if (!drop_chosen_item) break;
824
825                         do
826                         {
827                                 switch (randint0(3))
828                                 {
829                                 case 0:
830                                         a_idx = ART_NAMAKE_HAMMER;
831                                         break;
832                                 case 1:
833                                         a_idx = ART_NAMAKE_BOW;
834                                         break;
835                                 case 2:
836                                         a_idx = ART_NAMAKE_ARMOR;
837                                         break;
838                                 }
839
840                                 a_ptr = &a_info[a_idx];
841                         }
842                         while (a_ptr->cur_num);
843
844                         /* Create the artifact */
845                         if (create_named_art(a_idx, y, x))
846                         {
847                                 a_ptr->cur_num = 1;
848
849                                 /* Hack -- Memorize location of artifact in saved floors */
850                                 if (character_dungeon) a_ptr->floor_id = p_ptr->floor_id;
851                         }
852                         else if (!preserve_mode) a_ptr->cur_num = 1;
853                 }
854                 break;
855
856         case MON_SERPENT:
857                 if (!drop_chosen_item) break;
858                 q_ptr = &forge;
859
860                 /* Mega-Hack -- Prepare to make "Grond" */
861                 object_prep(q_ptr, lookup_kind(TV_HAFTED, SV_GROND));
862
863                 /* Mega-Hack -- Mark this item as "Grond" */
864                 q_ptr->name1 = ART_GROND;
865
866                 /* Mega-Hack -- Actually create "Grond" */
867                 apply_magic(q_ptr, -1, AM_GOOD | AM_GREAT);
868                 (void)drop_near(q_ptr, -1, y, x);
869                 q_ptr = &forge;
870
871                 /* Mega-Hack -- Prepare to make "Chaos" */
872                 object_prep(q_ptr, lookup_kind(TV_CROWN, SV_CHAOS));
873
874                 /* Mega-Hack -- Mark this item as "Chaos" */
875                 q_ptr->name1 = ART_CHAOS;
876
877                 /* Mega-Hack -- Actually create "Chaos" */
878                 apply_magic(q_ptr, -1, AM_GOOD | AM_GREAT);
879                 (void)drop_near(q_ptr, -1, y, x);
880                 break;
881
882         case MON_B_DEATH_SWORD:
883                 if (drop_chosen_item)
884                 {
885                         q_ptr = &forge;
886
887                         /* Prepare to make a broken sword */
888                         object_prep(q_ptr, lookup_kind(TV_SWORD, randint1(2)));
889                         (void)drop_near(q_ptr, -1, y, x);
890                 }
891                 break;
892
893         case MON_A_GOLD:
894         case MON_A_SILVER:
895                 if (drop_chosen_item && ((m_ptr->r_idx == MON_A_GOLD) ||
896                      ((m_ptr->r_idx == MON_A_SILVER) && (r_ptr->r_akills % 5 == 0))))
897                 {
898                         q_ptr = &forge;
899
900                         /* Prepare to make a Can of Toys */
901                         object_prep(q_ptr, lookup_kind(TV_CHEST, SV_CHEST_KANDUME));
902
903                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
904                         (void)drop_near(q_ptr, -1, y, x);
905                 }
906                 break;
907
908         case MON_ROLENTO:
909                 {
910                         BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
911                         (void)project(m_idx, 3, y, x, damroll(20, 10), GF_FIRE, flg, -1);
912                 }
913                 break;
914
915         default:
916                 if (!drop_chosen_item) break;
917
918                 switch (r_ptr->d_char)
919                 {
920                 case '(':
921                         if (dun_level > 0)
922                         {
923                                 q_ptr = &forge;
924                                 object_wipe(q_ptr);
925
926                                 /* Activate restriction */
927                                 get_obj_num_hook = kind_is_cloak;
928
929                                 /* Make a cloak */
930                                 make_object(q_ptr, mo_mode);
931                                 (void)drop_near(q_ptr, -1, y, x);
932                         }
933                         break;
934
935                 case '/':
936                         if (dun_level > 4)
937                         {
938                                 q_ptr = &forge;
939                                 object_wipe(q_ptr);
940
941                                 /* Activate restriction */
942                                 get_obj_num_hook = kind_is_polearm;
943
944                                 /* Make a poleweapon */
945                                 make_object(q_ptr, mo_mode);
946                                 (void)drop_near(q_ptr, -1, y, x);
947                         }
948                         break;
949
950                 case '[':
951                         if (dun_level > 19)
952                         {
953                                 q_ptr = &forge;
954                                 object_wipe(q_ptr);
955
956                                 /* Activate restriction */
957                                 get_obj_num_hook = kind_is_armor;
958
959                                 /* Make a hard armor */
960                                 make_object(q_ptr, mo_mode);
961                                 (void)drop_near(q_ptr, -1, y, x);
962                         }
963                         break;
964
965                 case '\\':
966                         if (dun_level > 4)
967                         {
968                                 q_ptr = &forge;
969                                 object_wipe(q_ptr);
970
971                                 /* Activate restriction */
972                                 get_obj_num_hook = kind_is_hafted;
973
974                                 /* Make a hafted weapon */
975                                 make_object(q_ptr, mo_mode);
976                                 (void)drop_near(q_ptr, -1, y, x);
977                         }
978                         break;
979
980                 case '|':
981                         if (m_ptr->r_idx != MON_STORMBRINGER)
982                         {
983                                 q_ptr = &forge;
984                                 object_wipe(q_ptr);
985
986                                 /* Activate restriction */
987                                 get_obj_num_hook = kind_is_sword;
988
989                                 /* Make a sword */
990                                 make_object(q_ptr, mo_mode);
991                                 (void)drop_near(q_ptr, -1, y, x);
992                         }
993                         break;
994                 }
995                 break;
996         }
997
998         /* Mega-Hack -- drop fixed items */
999         if (drop_chosen_item)
1000         {
1001                 ARTIFACT_IDX a_idx = 0;
1002                 int chance = 0;
1003
1004                 for(i = 0; i < 4; i++)
1005                 {
1006                         if(!r_ptr->artifact_id[i]) break;
1007                         a_idx = r_ptr->artifact_id[i];
1008                         chance = r_ptr->artifact_percent[i];
1009                 }
1010
1011                 if ((a_idx > 0) && ((randint0(100) < chance) || p_ptr->wizard))
1012                 {
1013                         artifact_type *a_ptr = &a_info[a_idx];
1014
1015                         if (!a_ptr->cur_num)
1016                         {
1017                                 /* Create the artifact */
1018                                 if (create_named_art(a_idx, y, x))
1019                                 {
1020                                         a_ptr->cur_num = 1;
1021
1022                                         /* Hack -- Memorize location of artifact in saved floors */
1023                                         if (character_dungeon) a_ptr->floor_id = p_ptr->floor_id;
1024                                 }
1025                                 else if (!preserve_mode) a_ptr->cur_num = 1;
1026                         }
1027                 }
1028
1029                 if ((r_ptr->flags7 & RF7_GUARDIAN) && (d_info[dungeon_type].final_guardian == m_ptr->r_idx))
1030                 {
1031                         KIND_OBJECT_IDX k_idx = d_info[dungeon_type].final_object ? d_info[dungeon_type].final_object
1032                                 : lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
1033
1034                         if (d_info[dungeon_type].final_artifact)
1035                         {
1036                                 a_idx = d_info[dungeon_type].final_artifact;
1037                                 artifact_type *a_ptr = &a_info[a_idx];
1038
1039                                 if (!a_ptr->cur_num)
1040                                 {
1041                                         /* Create the artifact */
1042                                         if (create_named_art(a_idx, y, x))
1043                                         {
1044                                                 a_ptr->cur_num = 1;
1045
1046                                                 /* Hack -- Memorize location of artifact in saved floors */
1047                                                 if (character_dungeon) a_ptr->floor_id = p_ptr->floor_id;
1048                                         }
1049                                         else if (!preserve_mode) a_ptr->cur_num = 1;
1050
1051                                         /* Prevent rewarding both artifact and "default" object */
1052                                         if (!d_info[dungeon_type].final_object) k_idx = 0;
1053                                 }
1054                         }
1055
1056                         if (k_idx)
1057                         {
1058                                 q_ptr = &forge;
1059
1060                                 /* Prepare to make a reward */
1061                                 object_prep(q_ptr, k_idx);
1062
1063                                 apply_magic(q_ptr, object_level, AM_NO_FIXED_ART | AM_GOOD);
1064                                 (void)drop_near(q_ptr, -1, y, x);
1065                         }
1066                         msg_format(_("あなたは%sを制覇した!", "You have conquered %s!"),d_name+d_info[dungeon_type].name);
1067                 }
1068         }
1069
1070         /* Determine how much we can drop */
1071         if ((r_ptr->flags1 & RF1_DROP_60) && (randint0(100) < 60)) number++;
1072         if ((r_ptr->flags1 & RF1_DROP_90) && (randint0(100) < 90)) number++;
1073         if  (r_ptr->flags1 & RF1_DROP_1D2) number += damroll(1, 2);
1074         if  (r_ptr->flags1 & RF1_DROP_2D2) number += damroll(2, 2);
1075         if  (r_ptr->flags1 & RF1_DROP_3D2) number += damroll(3, 2);
1076         if  (r_ptr->flags1 & RF1_DROP_4D2) number += damroll(4, 2);
1077
1078         if (cloned && !(r_ptr->flags1 & RF1_UNIQUE))
1079                 number = 0; /* Clones drop no stuff unless Cloning Pits */
1080
1081         if (is_pet(m_ptr) || p_ptr->inside_battle || p_ptr->inside_arena)
1082                 number = 0; /* Pets drop no stuff */
1083         if (!drop_item && (r_ptr->d_char != '$')) number = 0;
1084         
1085         if((r_ptr->flags2 & (RF2_MULTIPLY)) && (r_ptr->r_akills > 1024))
1086                 number = 0; /* Limit of Multiply monster drop */
1087
1088         /* Hack -- handle creeping coins */
1089         coin_type = force_coin;
1090
1091         /* Average dungeon and monster levels */
1092         object_level = (dun_level + r_ptr->level) / 2;
1093
1094         /* Drop some objects */
1095         for (j = 0; j < number; j++)
1096         {
1097                 q_ptr = &forge;
1098                 object_wipe(q_ptr);
1099
1100                 /* Make Gold */
1101                 if (do_gold && (!do_item || (randint0(100) < 50)))
1102                 {
1103                         /* Make some gold */
1104                         if (!make_gold(q_ptr)) continue;
1105
1106                         dump_gold++;
1107                 }
1108
1109                 /* Make Object */
1110                 else
1111                 {
1112                         /* Make an object */
1113                         if (!make_object(q_ptr, mo_mode)) continue;
1114
1115                         dump_item++;
1116                 }
1117                 (void)drop_near(q_ptr, -1, y, x);
1118         }
1119
1120         /* Reset the object level */
1121         object_level = base_level;
1122
1123         /* Reset "coin" type */
1124         coin_type = 0;
1125
1126
1127         /* Take note of any dropped treasure */
1128         if (visible && (dump_item || dump_gold))
1129         {
1130                 /* Take notes on treasure */
1131                 lore_treasure(m_idx, dump_item, dump_gold);
1132         }
1133
1134         /* Only process "Quest Monsters" */
1135         if (!(r_ptr->flags1 & RF1_QUESTOR)) return;
1136         if (p_ptr->inside_battle) return;
1137
1138         /* Winner? */
1139         if ((m_ptr->r_idx == MON_SERPENT) && !cloned)
1140         {
1141                 /* Total winner */
1142                 p_ptr->total_winner = TRUE;
1143
1144                 /* Redraw the "title" */
1145                 p_ptr->redraw |= (PR_TITLE);
1146
1147                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FINAL_QUEST_CLEAR);
1148
1149                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("見事に変愚蛮怒の勝利者となった!", "become *WINNER* of Hengband finely!"));
1150
1151                 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) || (p_ptr->muta2 & MUT2_CHAOS_GIFT))
1152                 {
1153                         msg_format(_("%sからの声が響いた。", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
1154                         msg_print(_("『よくやった、定命の者よ!』", "'Thou art donst well, mortal!'"));
1155                 }
1156
1157                 /* Congratulations */
1158                 msg_print(_("*** おめでとう ***", "*** CONGRATULATIONS ***"));
1159                 msg_print(_("あなたはゲームをコンプリートしました。", "You have won the game!"));
1160                 msg_print(_("準備が整ったら引退(自殺コマンド)しても結構です。", "You may retire (commit suicide) when you are ready."));
1161         }
1162 }
1163
1164 /*!
1165  * @brief モンスターに与えたダメージの修正処理 /
1166  * Modify the physical damage done to the monster.
1167  * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
1168  * @param dam ダメージ基本値
1169  * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
1170  * @return 修正を行った結果のダメージ量
1171  * @details
1172  * <pre>
1173  * (for example when it's invulnerable or shielded)
1174  * ToDo: Accept a damage-type to calculate the modified damage from
1175  * things like fire, frost, lightning, poison, ... attacks.
1176  * "type" is not yet used and should be 0.
1177  * </pre>
1178  */
1179 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
1180 {
1181         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1182
1183         if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
1184         {
1185                 dam /= 100;
1186                 if ((dam == 0) && one_in_(3)) dam = 1;
1187         }
1188
1189         if (MON_INVULNER(m_ptr))
1190         {
1191                 if (is_psy_spear)
1192                 {
1193                         if (!p_ptr->blind && is_seen(m_ptr))
1194                         {
1195                                 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
1196                         }
1197                 }
1198                 else if (!one_in_(PENETRATE_INVULNERABILITY))
1199                 {
1200                         return (0);
1201                 }
1202         }
1203         return (dam);
1204 }
1205
1206
1207 /*!
1208  * @brief モンスターに与えたダメージを元に経験値を加算する /
1209  * Calculate experience point to be get
1210  * @param dam 与えたダメージ量
1211  * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
1212  * @return なし
1213  * @details
1214  * <pre>
1215  * Even the 64 bit operation is not big enough to avoid overflaw
1216  * unless we carefully choose orders of multiplication and division.
1217  * Get the coefficient first, and multiply (potentially huge) base
1218  * experience point of a monster later.
1219  * </pre>
1220  */
1221 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
1222 {
1223         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1224
1225         s32b new_exp;
1226         u32b new_exp_frac;
1227         s32b div_h;
1228         u32b div_l;
1229
1230         if (!m_ptr->r_idx) return;
1231         if (is_pet(m_ptr) || p_ptr->inside_battle) return;
1232
1233         /*
1234          * - Ratio of monster's level to player's level effects
1235          * - Varying speed effects
1236          * - Get a fraction in proportion of damage point
1237          */
1238         new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
1239         new_exp_frac = 0;
1240         div_h = 0L;
1241         div_l = (p_ptr->max_plv+2) * SPEED_TO_ENERGY(r_ptr->speed);
1242
1243         /* Use (average maxhp * 2) as a denominator */
1244         if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
1245                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
1246         else
1247                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
1248
1249         /* Special penalty in the wilderness */
1250         if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
1251                 s64b_mul(&div_h, &div_l, 0, 5);
1252
1253         /* Do division first to prevent overflaw */
1254         s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
1255
1256         /* Special penalty for mutiply-monster */
1257         if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
1258         {
1259                 int monnum_penarty = r_ptr->r_akills / 400;
1260                 if (monnum_penarty > 8) monnum_penarty = 8;
1261
1262                 while (monnum_penarty--)
1263                 {
1264                         /* Divide by 4 */
1265                         s64b_RSHIFT(new_exp, new_exp_frac, 2);
1266                 }
1267         }
1268         
1269         /* Special penalty for rest_and_shoot exp scum */
1270         if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
1271         {
1272                 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
1273                 if (over_damage > 32) over_damage = 32;
1274
1275                 while (over_damage--)
1276                 {
1277                         /* 9/10 for once */
1278                         s64b_mul(&new_exp, &new_exp_frac, 0, 9);
1279                         s64b_div(&new_exp, &new_exp_frac, 0, 10);
1280                 }
1281         }
1282
1283         /* Finally multiply base experience point of the monster */
1284         s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
1285
1286         /* Gain experience */
1287         gain_exp_64(new_exp, new_exp_frac);
1288 }
1289
1290
1291 /*!
1292  * @brief モンスターのHPをダメージに応じて減算する /
1293  * Decreases monsters hit points, handling monster death.
1294  * @param dam 与えたダメージ量
1295  * @param m_idx ダメージを与えたモンスターのID
1296  * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
1297  * @param note モンスターが倒された際の特別なメッセージ述語
1298  * @return なし
1299  * @details
1300  * <pre>
1301  * We return TRUE if the monster has been killed (and deleted).
1302  * We announce monster death (using an optional "death message"
1303  * if given, and a otherwise a generic killed/destroyed message).
1304  * Only "physical attacks" can induce the "You have slain" message.
1305  * Missile and Spell attacks will induce the "dies" message, or
1306  * various "specialized" messages.  Note that "You have destroyed"
1307  * and "is destroyed" are synonyms for "You have slain" and "dies".
1308  * Hack -- unseen monsters yield "You have killed it." message.
1309  * Added fear (DGK) and check whether to print fear messages -CWS
1310  * Made name, sex, and capitalization generic -BEN-
1311  * As always, the "ghost" processing is a total hack.
1312  * Hack -- we "delay" fear messages by passing around a "fear" flag.
1313  * Consider decreasing monster experience over time, say,
1314  * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
1315  * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
1316  * monster worth more than subsequent monsters.  This would also need
1317  * to induce changes in the monster recall code.
1318  * </pre>
1319  */
1320 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
1321 {
1322         monster_type *m_ptr = &m_list[m_idx];
1323         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1324         monster_type exp_mon;
1325
1326         /* Innocent until proven otherwise */
1327         bool innocent = TRUE, thief = FALSE;
1328         int i;
1329         HIT_POINT expdam;
1330
1331         (void)COPY(&exp_mon, m_ptr, monster_type);
1332         
1333         expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1334
1335         get_exp_from_mon(expdam, &exp_mon);
1336
1337         /* Genocided by chaos patron */
1338         if (!m_ptr->r_idx) m_idx = 0;
1339         
1340         /* Redraw (later) if needed */
1341         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1342         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1343
1344         (void)set_monster_csleep(m_idx, 0);
1345
1346         /* Hack - Cancel any special player stealth magics. -LM- */
1347         if (p_ptr->special_defense & NINJA_S_STEALTH)
1348         {
1349                 set_superstealth(FALSE);
1350         }
1351
1352         /* Genocided by chaos patron */
1353         if (!m_idx) return TRUE;
1354         
1355         m_ptr->hp -= dam;
1356         m_ptr->dealt_damage += dam;
1357
1358         if(m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1359
1360         if (p_ptr->wizard)
1361         {
1362                 msg_format( _("合計%d/%dのダメージを与えた。","You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1363         }
1364
1365         /* It is dead now */
1366         if (m_ptr->hp < 0)
1367         {
1368                 GAME_TEXT m_name[MAX_NLEN];
1369
1370                 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1371                 {
1372                         /* You might have unmasked Tanuki first time */
1373                         r_ptr = &r_info[m_ptr->r_idx];
1374                         m_ptr->ap_r_idx = m_ptr->r_idx;
1375                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1376                 }
1377
1378                 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1379                 {
1380                         /* You might have unmasked Chameleon first time */
1381                         r_ptr = real_r_ptr(m_ptr);
1382                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1383                 }
1384
1385                 if (!(m_ptr->smart & SM_CLONED))
1386                 {
1387                         /* When the player kills a Unique, it stays dead */
1388                         if (r_ptr->flags1 & RF1_UNIQUE)
1389                         {
1390                                 r_ptr->max_num = 0;
1391
1392                                 /* Mega-Hack -- Banor & Lupart */
1393                                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1394                                 {
1395                                         r_info[MON_BANORLUPART].max_num = 0;
1396                                         r_info[MON_BANORLUPART].r_pkills++;
1397                                         r_info[MON_BANORLUPART].r_akills++;
1398                                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1399                                 }
1400                                 else if (m_ptr->r_idx == MON_BANORLUPART)
1401                                 {
1402                                         r_info[MON_BANOR].max_num = 0;
1403                                         r_info[MON_BANOR].r_pkills++;
1404                                         r_info[MON_BANOR].r_akills++;
1405                                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1406                                         r_info[MON_LUPART].max_num = 0;
1407                                         r_info[MON_LUPART].r_pkills++;
1408                                         r_info[MON_LUPART].r_akills++;
1409                                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1410                                 }
1411                         }
1412
1413                         /* When the player kills a Nazgul, it stays dead */
1414                         else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1415                 }
1416
1417                 /* Count all monsters killed */
1418                 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1419
1420                 /* Recall even invisible uniques or winners */
1421                 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1422                 {
1423                         /* Count kills this life */
1424                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1425                         else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1426
1427                         /* Count kills in all lives */
1428                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1429                         else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1430
1431                         /* Hack -- Auto-recall */
1432                         monster_race_track(m_ptr->ap_r_idx);
1433                 }
1434
1435                 /* Extract monster name */
1436                 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1437
1438                 /* Don't kill Amberites */
1439                 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1440                 {
1441                         int curses = 1 + randint1(3);
1442                         bool stop_ty = FALSE;
1443                         int count = 0;
1444
1445                         msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1446                         curse_equipment(100, 50);
1447
1448                         do
1449                         {
1450                                 stop_ty = activate_ty_curse(stop_ty, &count);
1451                         }
1452                         while (--curses);
1453                 }
1454
1455                 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1456                 {
1457                         char line_got[1024];
1458                         if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1459                         {
1460                                 msg_format("%^s %s", m_name, line_got);
1461                         }
1462
1463 #ifdef WORLD_SCORE
1464                         if (m_ptr->r_idx == MON_SERPENT)
1465                         {
1466                                 screen_dump = make_screen_dump();
1467                         }
1468 #endif
1469                 }
1470
1471                 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1472                 {
1473                         if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
1474                         {
1475                                 chg_virtue(V_VALOUR, -1);
1476                         }
1477                         else if (r_ptr->level > dun_level)
1478                         {
1479                                 if (randint1(10) <= (r_ptr->level - dun_level))
1480                                         chg_virtue(V_VALOUR, 1);
1481                         }
1482                         if (r_ptr->level > 60)
1483                         {
1484                                 chg_virtue(V_VALOUR, 1);
1485                         }
1486                         if (r_ptr->level >= 2 * (p_ptr->lev+1))
1487                                 chg_virtue(V_VALOUR, 2);
1488                 }
1489
1490                 if (r_ptr->flags1 & RF1_UNIQUE)
1491                 {
1492                         if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1493
1494                         if (r_ptr->flags3 & RF3_GOOD)
1495                         {
1496                                 chg_virtue(V_UNLIFE, 2);
1497                                 chg_virtue(V_VITALITY, -2);
1498                         }
1499
1500                         if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1501                 }
1502
1503                 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1504                 {
1505                         chg_virtue(V_COMPASSION, -1);
1506                 }
1507
1508                 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
1509                         chg_virtue(V_UNLIFE, 1);
1510
1511                 if (r_ptr->d_char == 'A')
1512                 {
1513                         if (r_ptr->flags1 & RF1_UNIQUE)
1514                                 chg_virtue(V_FAITH, -2);
1515                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1516                         {
1517                                 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1518                                 else chg_virtue(V_FAITH, 1);
1519                         }
1520                 }
1521                 else if (r_ptr->flags3 & RF3_DEMON)
1522                 {
1523                         if (r_ptr->flags1 & RF1_UNIQUE)
1524                                 chg_virtue(V_FAITH, 2);
1525                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1526                                 chg_virtue(V_FAITH, 1);
1527                 }
1528
1529                 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1530                         chg_virtue(V_VITALITY, 2);
1531
1532                 if (r_ptr->r_deaths)
1533                 {
1534                         if (r_ptr->flags1 & RF1_UNIQUE)
1535                         {
1536                                 chg_virtue(V_HONOUR, 10);
1537                         }
1538                         else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
1539                         {
1540                                 chg_virtue(V_HONOUR, 1);
1541                         }
1542                 }
1543                 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1544                 {
1545                         chg_virtue(V_VALOUR, -1);
1546                 }
1547
1548                 for (i = 0; i < 4; i++)
1549                 {
1550                         if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1551
1552                         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1553                                 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1554
1555                                 thief = TRUE; /* Thief! */
1556                 }
1557
1558                 /* The new law says it is illegal to live in the dungeon */
1559                 if (r_ptr->level != 0) innocent = FALSE;
1560
1561                 if (thief)
1562                 {
1563                         if (r_ptr->flags1 & RF1_UNIQUE)
1564                                 chg_virtue(V_JUSTICE, 3);
1565                         else if (1+((r_ptr->level) / 10 + (2 * dun_level)) >= randint1(100))
1566                                 chg_virtue(V_JUSTICE, 1);
1567                 }
1568                 else if (innocent)
1569                 {
1570                         chg_virtue (V_JUSTICE, -1);
1571                 }
1572
1573                 if ((r_ptr->flags3 & RF3_ANIMAL) && !(r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags4 & ~(RF4_NOMAGIC_MASK))  && !(r_ptr->a_ability_flags1 & ~(RF5_NOMAGIC_MASK)) && !(r_ptr->a_ability_flags2 & ~(RF6_NOMAGIC_MASK)))
1574                 {
1575                         if (one_in_(4)) chg_virtue(V_NATURE, -1);
1576                 }
1577
1578                 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1579                 {
1580                         char note_buf[160];
1581                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1582                         do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
1583                 }
1584
1585                 /* Make a sound */
1586                 sound(SOUND_KILL);
1587
1588                 /* Death by Missile/Spell attack */
1589                 if (note)
1590                 {
1591                         msg_format("%^s%s", m_name, note);
1592                 }
1593
1594                 /* Death by physical attack -- invisible monster */
1595                 else if (!m_ptr->ml)
1596                 {
1597 #ifdef JP
1598                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1599                                 msg_format("せっかくだから%sを殺した。", m_name);
1600                         else
1601                                 msg_format("%sを殺した。", m_name);
1602 #else
1603                                 msg_format("You have killed %s.", m_name);
1604 #endif
1605
1606                 }
1607
1608                 /* Death by Physical attack -- non-living monster */
1609                 else if (!monster_living(m_ptr->r_idx))
1610                 {
1611                         bool explode = FALSE;
1612
1613                         for (i = 0; i < 4; i++)
1614                         {
1615                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1616                         }
1617
1618                         /* Special note at death */
1619                         if (explode)
1620                                 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1621                         else
1622                         {
1623 #ifdef JP
1624                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1625                                         msg_format("せっかくだから%sを倒した。", m_name);
1626                                 else
1627                                 msg_format("%sを倒した。", m_name);
1628 #else
1629                                 msg_format("You have destroyed %s.", m_name);
1630 #endif
1631                         }
1632                 }
1633
1634                 /* Death by Physical attack -- living monster */
1635                 else
1636                 {
1637 #ifdef JP
1638                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1639                                 msg_format("せっかくだから%sを葬り去った。", m_name);
1640                         else
1641                                 msg_format("%sを葬り去った。", m_name);
1642 #else
1643                                 msg_format("You have slain %s.", m_name);
1644 #endif
1645
1646                 }
1647                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1648                 {
1649                         for (i = 0; i < MAX_KUBI; i++)
1650                         {
1651                                 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1652                                 {
1653                                         msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1654                                         break;
1655                                 }
1656                         }
1657                 }
1658
1659                 /* Generate treasure */
1660                 monster_death(m_idx, TRUE);
1661
1662                 /* Mega hack : replace IKETA to BIKETAL */
1663                 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1664                 {
1665                         POSITION dummy_y = m_ptr->fy;
1666                         POSITION dummy_x = m_ptr->fx;
1667                         BIT_FLAGS mode = 0L;
1668                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1669                         delete_monster_idx(m_idx);
1670                         if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1671                         {
1672                                 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha!  *I* am Biketal!"));
1673                         }
1674                 }
1675                 else
1676                 {
1677                         delete_monster_idx(m_idx);
1678                 }
1679
1680                 get_exp_from_mon((long)exp_mon.max_maxhp*2, &exp_mon);
1681
1682                 /* Not afraid */
1683                 (*fear) = FALSE;
1684
1685                 /* Monster is dead */
1686                 return (TRUE);
1687         }
1688
1689
1690 #ifdef ALLOW_FEAR
1691
1692         /* Mega-Hack -- Pain cancels fear */
1693         if (MON_MONFEAR(m_ptr) && (dam > 0))
1694         {
1695                 /* Cure fear */
1696                 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1697                 {
1698                         /* No more fear */
1699                         (*fear) = FALSE;
1700                 }
1701         }
1702
1703         /* Sometimes a monster gets scared by damage */
1704         if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1705         {
1706                 /* Percentage of fully healthy */
1707                 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1708
1709                 /*
1710                  * Run (sometimes) if at 10% or less of max hit points,
1711                  * or (usually) when hit for half its current hit points
1712                  */
1713                 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1714                 {
1715                         /* Hack -- note fear */
1716                         (*fear) = TRUE;
1717
1718                         /* Hack -- Add some timed fear */
1719                         (void)set_monster_monfear(m_idx, (randint1(10) +
1720                                           (((dam >= m_ptr->hp) && (percentage > 7)) ?
1721                                            20 : ((11 - percentage) * 5))));
1722                 }
1723         }
1724
1725 #endif
1726
1727         /* Not dead yet */
1728         return (FALSE);
1729 }
1730
1731
1732 /*!
1733  * @brief 現在のコンソール表示の縦横を返す。 /
1734  * Get term size and calculate screen size
1735  * @param wid_p コンソールの表示幅文字数を返す
1736  * @param hgt_p コンソールの表示行数を返す
1737  * @return なし
1738  */
1739 void get_screen_size(TERM_LEN *wid_p, TERM_LEN *hgt_p)
1740 {
1741         Term_get_size(wid_p, hgt_p);
1742         *hgt_p -= ROW_MAP + 2;
1743         *wid_p -= COL_MAP + 2;
1744         if (use_bigtile) *wid_p /= 2;
1745 }
1746
1747
1748 /*!
1749  * @brief コンソール上におけるマップ表示の左上位置を返す /
1750  * Calculates current boundaries Called below and from "do_cmd_locate()".
1751  * @return なし
1752  */
1753 void panel_bounds_center(void)
1754 {
1755         TERM_LEN wid, hgt;
1756
1757         get_screen_size(&wid, &hgt);
1758
1759         panel_row_max = panel_row_min + hgt - 1;
1760         panel_row_prt = panel_row_min - 1;
1761         panel_col_max = panel_col_min + wid - 1;
1762         panel_col_prt = panel_col_min - 13;
1763 }
1764
1765
1766 /*!
1767  * @brief コンソールのリサイズに合わせてマップを再描画する /
1768  * Map resizing whenever the main term changes size
1769  * @return なし
1770  */
1771 void resize_map(void)
1772 {
1773         /* Only if the dungeon exists */
1774         if (!character_dungeon) return;
1775         
1776         /* Mega-Hack -- no panel yet */
1777         panel_row_max = 0;
1778         panel_col_max = 0;
1779
1780         /* Reset the panels */
1781         panel_row_min = cur_hgt;
1782         panel_col_min = cur_wid;
1783                                 
1784         verify_panel();
1785
1786         p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
1787         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
1788         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1789         p_ptr->update |= (PU_MONSTERS);
1790         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
1791
1792         handle_stuff();
1793         Term_redraw();
1794
1795         /*
1796          * Waiting command;
1797          * Place the cursor on the player
1798          */
1799         if (can_save) move_cursor_relative(p_ptr->y, p_ptr->x);
1800
1801         Term_fresh();
1802 }
1803
1804 /*!
1805  * @brief コンソールを再描画する /
1806  * Redraw a term when it is resized
1807  * @return なし
1808  */
1809 void redraw_window(void)
1810 {
1811         /* Only if the dungeon exists */
1812         if (!character_dungeon) return;
1813
1814         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1815         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
1816
1817         handle_stuff();
1818         Term_redraw();
1819 }
1820
1821
1822 /*!
1823  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
1824  * @param dy 変更先のフロアY座標
1825  * @param dx 変更先のフロアX座標
1826  * Handle a request to change the current panel
1827  * Return TRUE if the panel was changed.
1828  * Also used in do_cmd_locate
1829  * @return 実際に再描画が必要だった場合TRUEを返す
1830  */
1831 bool change_panel(POSITION dy, POSITION dx)
1832 {
1833         POSITION y, x;
1834         TERM_LEN wid, hgt;
1835
1836         get_screen_size(&wid, &hgt);
1837
1838         /* Apply the motion */
1839         y = panel_row_min + dy * hgt / 2;
1840         x = panel_col_min + dx * wid / 2;
1841
1842         /* Verify the row */
1843         if (y > cur_hgt - hgt) y = cur_hgt - hgt;
1844         if (y < 0) y = 0;
1845
1846         /* Verify the col */
1847         if (x > cur_wid - wid) x = cur_wid - wid;
1848         if (x < 0) x = 0;
1849
1850         /* Handle "changes" */
1851         if ((y != panel_row_min) || (x != panel_col_min))
1852         {
1853                 /* Save the new panel info */
1854                 panel_row_min = y;
1855                 panel_col_min = x;
1856
1857                 /* Recalculate the boundaries */
1858                 panel_bounds_center();
1859
1860                 p_ptr->update |= (PU_MONSTERS);
1861                 p_ptr->redraw |= (PR_MAP);
1862                 handle_stuff();
1863
1864                 /* Success */
1865                 return (TRUE);
1866         }
1867
1868         /* No change */
1869         return (FALSE);
1870 }
1871
1872 /*!
1873  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
1874  * @param y 変更先のフロアY座標
1875  * @param x 変更先のフロアX座標
1876  * @details
1877  * Handle a request to change the current panel
1878  * Return TRUE if the panel was changed.
1879  * Also used in do_cmd_locate
1880  * @return 実際に再描画が必要だった場合TRUEを返す
1881  */
1882 static bool change_panel_xy(POSITION y, POSITION x)
1883 {
1884         POSITION dy = 0, dx = 0;
1885         TERM_LEN wid, hgt;
1886
1887         get_screen_size(&wid, &hgt);
1888
1889         if (y < panel_row_min) dy = -1;
1890         if (y > panel_row_max) dy = 1;
1891         if (x < panel_col_min) dx = -1;
1892         if (x > panel_col_max) dx = 1;
1893
1894         if (!dy && !dx) return (FALSE);
1895
1896         return change_panel(dy, dx);
1897 }
1898
1899
1900 /*!
1901  * @brief マップ描画のフォーカスを当てるべき座標を更新する
1902  * @details
1903  * Given an row (y) and col (x), this routine detects when a move
1904  * off the screen has occurred and figures new borders. -RAK-
1905  * "Update" forces a "full update" to take place.
1906  * The map is reprinted if necessary, and "TRUE" is returned.
1907  * @return 実際に再描画が必要だった場合TRUEを返す
1908  */
1909 void verify_panel(void)
1910 {
1911         POSITION y = p_ptr->y;
1912         POSITION x = p_ptr->x;
1913         TERM_LEN wid, hgt;
1914
1915         int prow_min;
1916         int pcol_min;
1917         int max_prow_min;
1918         int max_pcol_min;
1919
1920         get_screen_size(&wid, &hgt);
1921
1922         max_prow_min = cur_hgt - hgt;
1923         max_pcol_min = cur_wid - wid;
1924
1925         /* Bounds checking */
1926         if (max_prow_min < 0) max_prow_min = 0;
1927         if (max_pcol_min < 0) max_pcol_min = 0;
1928
1929                 /* Center on player */
1930         if (center_player && (center_running || !running))
1931         {
1932                 /* Center vertically */
1933                 prow_min = y - hgt / 2;
1934                 if (prow_min < 0) prow_min = 0;
1935                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
1936
1937                 /* Center horizontally */
1938                 pcol_min = x - wid / 2;
1939                 if (pcol_min < 0) pcol_min = 0;
1940                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1941         }
1942         else
1943         {
1944                 prow_min = panel_row_min;
1945                 pcol_min = panel_col_min;
1946
1947                 /* Scroll screen when 2 grids from top/bottom edge */
1948                 if (y > panel_row_max - 2)
1949                 {
1950                         while (y > prow_min + hgt-1 - 2)
1951                         {
1952                                 prow_min += (hgt / 2);
1953                         }
1954                 }
1955
1956                 if (y < panel_row_min + 2)
1957                 {
1958                         while (y < prow_min + 2)
1959                         {
1960                                 prow_min -= (hgt / 2);
1961                         }
1962                 }
1963
1964                 if (prow_min > max_prow_min) prow_min = max_prow_min;
1965                 if (prow_min < 0) prow_min = 0;
1966
1967                 /* Scroll screen when 4 grids from left/right edge */
1968                 if (x > panel_col_max - 4)
1969                 {
1970                         while (x > pcol_min + wid-1 - 4)
1971                         {
1972                                 pcol_min += (wid / 2);
1973                         }
1974                 }
1975                 
1976                 if (x < panel_col_min + 4)
1977                 {
1978                         while (x < pcol_min + 4)
1979                         {
1980                                 pcol_min -= (wid / 2);
1981                         }
1982                 }
1983
1984                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1985                 if (pcol_min < 0) pcol_min = 0;
1986         }
1987
1988         /* Check for "no change" */
1989         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
1990
1991         /* Save the new panel info */
1992         panel_row_min = prow_min;
1993         panel_col_min = pcol_min;
1994
1995         /* Hack -- optional disturb on "panel change" */
1996         if (disturb_panel && !center_player) disturb(FALSE, FALSE);
1997
1998         /* Recalculate the boundaries */
1999         panel_bounds_center();
2000
2001         p_ptr->update |= (PU_MONSTERS);
2002         p_ptr->redraw |= (PR_MAP);
2003         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2004 }
2005
2006
2007 /*
2008  * Monster health description
2009  */
2010 concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
2011 {
2012         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2013         bool living;
2014         int perc;
2015         concptr desc;
2016         concptr attitude;
2017         concptr clone;
2018
2019         /* Determine if the monster is "living" */
2020         living = monster_living(m_ptr->ap_r_idx);
2021
2022         /* Calculate a health "percentage" */
2023         perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
2024
2025         /* Healthy monsters */
2026         if (m_ptr->hp >= m_ptr->maxhp)
2027         {
2028                 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
2029         }
2030
2031         else if (perc >= 60)
2032         {
2033                 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
2034         }
2035
2036         else if (perc >= 25)
2037         {
2038                 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
2039         }
2040
2041         else if (perc >= 10)
2042         {
2043                 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
2044         }
2045
2046         else 
2047         {
2048                 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
2049         }
2050
2051         /* Need attitude information? */
2052         if (!(mode & 0x01))
2053         {
2054                 /* Full information is not needed */
2055                 attitude = "";
2056         }
2057         else if (is_pet(m_ptr))
2058         {
2059                 attitude = _(", ペット", ", pet");
2060         }
2061         else if (is_friendly(m_ptr))
2062         {
2063                 attitude = _(", 友好的", ", friendly");
2064         }
2065         else
2066         {
2067                 attitude = _("", "");
2068         }
2069
2070         /* Clone monster? */
2071         if (m_ptr->smart & SM_CLONED)
2072         {
2073                 clone = ", clone";
2074         }
2075         else
2076         {
2077                 clone = "";
2078         }
2079
2080         /* Display monster's level --- idea borrowed from ToME */
2081         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
2082         {
2083                 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
2084         }
2085         else 
2086         {
2087                 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
2088         }
2089
2090 }
2091
2092
2093
2094 /*** Targeting Code ***/
2095
2096
2097 /*
2098  * Determine is a monster makes a reasonable target
2099  *
2100  * The concept of "targeting" was stolen from "Morgul" (?)
2101  *
2102  * The player can target any location, or any "target-able" monster.
2103  *
2104  * Currently, a monster is "target_able" if it is visible, and if
2105  * the player can hit it with a projection, and the player is not
2106  * hallucinating.  This allows use of "use closest target" macros.
2107  *
2108  * Future versions may restrict the ability to target "trappers"
2109  * and "mimics", but the semantics is a little bit weird.
2110  */
2111 bool target_able(MONSTER_IDX m_idx)
2112 {
2113         monster_type *m_ptr = &m_list[m_idx];
2114
2115         /* Monster must be alive */
2116         if (!m_ptr->r_idx) return (FALSE);
2117
2118         /* Hack -- no targeting hallucinations */
2119         if (p_ptr->image) return (FALSE);
2120
2121         /* Monster must be visible */
2122         if (!m_ptr->ml) return (FALSE);
2123
2124         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
2125
2126         /* Monster must be projectable */
2127         if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
2128
2129         /* Hack -- Never target trappers */
2130         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
2131
2132         /* Assume okay */
2133         return (TRUE);
2134 }
2135
2136
2137
2138
2139 /*
2140  * Update (if necessary) and verify (if possible) the target.
2141  *
2142  * We return TRUE if the target is "okay" and FALSE otherwise.
2143  */
2144 bool target_okay(void)
2145 {
2146         /* Accept stationary targets */
2147         if (target_who < 0) return (TRUE);
2148
2149         /* Check moving targets */
2150         if (target_who > 0)
2151         {
2152                 /* Accept reasonable targets */
2153                 if (target_able(target_who))
2154                 {
2155                         monster_type *m_ptr = &m_list[target_who];
2156
2157                         /* Acquire monster location */
2158                         target_row = m_ptr->fy;
2159                         target_col = m_ptr->fx;
2160
2161                         /* Good target */
2162                         return (TRUE);
2163                 }
2164         }
2165
2166         /* Assume no target */
2167         return (FALSE);
2168 }
2169
2170
2171 /*
2172  * Sorting hook -- comp function -- by "distance to player"
2173  *
2174  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2175  * and sort the arrays by double-distance to the player.
2176  */
2177 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
2178 {
2179         POSITION *x = (POSITION*)(u);
2180         POSITION *y = (POSITION*)(v);
2181
2182         POSITION da, db, kx, ky;
2183
2184         /* Absolute distance components */
2185         kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
2186         ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
2187
2188         /* Approximate Double Distance to the first point */
2189         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2190
2191         /* Absolute distance components */
2192         kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
2193         ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
2194
2195         /* Approximate Double Distance to the first point */
2196         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2197
2198         /* Compare the distances */
2199         return (da <= db);
2200 }
2201
2202
2203 /*
2204  * Sorting hook -- comp function -- by importance level of grids
2205  *
2206  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2207  * and sort the arrays by level of monster
2208  */
2209 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
2210 {
2211         POSITION *x = (POSITION*)(u);
2212         POSITION *y = (POSITION*)(v);
2213         cave_type *ca_ptr = &cave[y[a]][x[a]];
2214         cave_type *cb_ptr = &cave[y[b]][x[b]];
2215         monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
2216         monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
2217         monster_race *ap_ra_ptr, *ap_rb_ptr;
2218
2219         /* The player grid */
2220         if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
2221         if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
2222
2223         /* Extract monster race */
2224         if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
2225         else ap_ra_ptr = NULL;
2226         if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
2227         else ap_rb_ptr = NULL;
2228
2229         if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
2230         if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
2231
2232         /* Compare two monsters */
2233         if (ap_ra_ptr && ap_rb_ptr)
2234         {
2235                 /* Unique monsters first */
2236                 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
2237                 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
2238
2239                 /* Shadowers first (あやしい影) */
2240                 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
2241                 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
2242
2243                 /* Unknown monsters first */
2244                 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
2245                 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
2246
2247                 /* Higher level monsters first (if known) */
2248                 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
2249                 {
2250                         if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
2251                         if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
2252                 }
2253
2254                 /* Sort by index if all conditions are same */
2255                 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
2256                 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
2257         }
2258
2259         /* An object get higher priority */
2260         if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
2261         if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
2262
2263         /* Priority from the terrain */
2264         if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
2265         if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
2266
2267         /* If all conditions are same, compare distance */
2268         return ang_sort_comp_distance(u, v, a, b);
2269 }
2270
2271
2272 /*
2273  * Sorting hook -- swap function -- by "distance to player"
2274  *
2275  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2276  * and sort the arrays by distance to the player.
2277  */
2278 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
2279 {
2280         POSITION *x = (POSITION*)(u);
2281         POSITION *y = (POSITION*)(v);
2282
2283         POSITION temp;
2284
2285         /* Swap "x" */
2286         temp = x[a];
2287         x[a] = x[b];
2288         x[b] = temp;
2289
2290         /* Swap "y" */
2291         temp = y[a];
2292         y[a] = y[b];
2293         y[b] = temp;
2294 }
2295
2296
2297
2298 /*
2299  * Hack -- help "select" a location (see below)
2300  */
2301 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
2302 {
2303         POSITION_IDX i, v;
2304         POSITION x2, y2, x3, y3, x4, y4;
2305         POSITION_IDX b_i = -1, b_v = 9999;
2306
2307
2308         /* Scan the locations */
2309         for (i = 0; i < temp_n; i++)
2310         {
2311                 /* Point 2 */
2312                 x2 = temp_x[i];
2313                 y2 = temp_y[i];
2314
2315                 /* Directed distance */
2316                 x3 = (x2 - x1);
2317                 y3 = (y2 - y1);
2318
2319                 /* Verify quadrant */
2320                 if (dx && (x3 * dx <= 0)) continue;
2321                 if (dy && (y3 * dy <= 0)) continue;
2322
2323                 /* Absolute distance */
2324                 x4 = ABS(x3);
2325                 y4 = ABS(y3);
2326
2327                 /* Verify quadrant */
2328                 if (dy && !dx && (x4 > y4)) continue;
2329                 if (dx && !dy && (y4 > x4)) continue;
2330
2331                 /* Approximate Double Distance */
2332                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
2333
2334                 /* Penalize location */
2335
2336                 /* Track best */
2337                 if ((b_i >= 0) && (v >= b_v)) continue;
2338
2339                 /* Track best */
2340                 b_i = i; b_v = v;
2341         }
2342         return (b_i);
2343 }
2344
2345
2346 /*
2347  * Hack -- determine if a given location is "interesting"
2348  */
2349 static bool target_set_accept(POSITION y, POSITION x)
2350 {
2351         cave_type *c_ptr;
2352         OBJECT_IDX this_o_idx, next_o_idx = 0;
2353
2354         /* Bounds */
2355         if (!(in_bounds(y, x))) return (FALSE);
2356
2357         /* Player grid is always interesting */
2358         if (player_bold(y, x)) return (TRUE);
2359
2360         /* Handle hallucination */
2361         if (p_ptr->image) return (FALSE);
2362
2363         /* Examine the grid */
2364         c_ptr = &cave[y][x];
2365
2366         /* Visible monsters */
2367         if (c_ptr->m_idx)
2368         {
2369                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2370
2371                 /* Visible monsters */
2372                 if (m_ptr->ml) return (TRUE);
2373         }
2374
2375         /* Scan all objects in the grid */
2376         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2377         {
2378                 object_type *o_ptr;
2379                 o_ptr = &o_list[this_o_idx];
2380
2381                 /* Acquire next object */
2382                 next_o_idx = o_ptr->next_o_idx;
2383
2384                 /* Memorized object */
2385                 if (o_ptr->marked & OM_FOUND) return (TRUE);
2386         }
2387
2388         /* Interesting memorized features */
2389         if (c_ptr->info & (CAVE_MARK))
2390         {
2391                 /* Notice object features */
2392                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
2393
2394                 /* Feature code (applying "mimic" field) */
2395                 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
2396         }
2397
2398         return (FALSE);
2399 }
2400
2401
2402 /*
2403  * Prepare the "temp" array for "target_set"
2404  *
2405  * Return the number of target_able monsters in the set.
2406  */
2407 static void target_set_prepare(BIT_FLAGS mode)
2408 {
2409         POSITION y, x;
2410         POSITION min_hgt, max_hgt, min_wid, max_wid;
2411
2412         if (mode & TARGET_KILL)
2413         {
2414                 /* Inner range */
2415                 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
2416                 max_hgt = MIN((p_ptr->y + MAX_RANGE), cur_hgt - 1);
2417                 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
2418                 max_wid = MIN((p_ptr->x + MAX_RANGE), cur_wid - 1);
2419         }
2420         else /* not targetting */
2421         {
2422                 /* Inner panel */
2423                 min_hgt = panel_row_min;
2424                 max_hgt = panel_row_max;
2425                 min_wid = panel_col_min;
2426                 max_wid = panel_col_max;
2427         }
2428
2429         /* Reset "temp" array */
2430         temp_n = 0;
2431
2432         /* Scan the current panel */
2433         for (y = min_hgt; y <= max_hgt; y++)
2434         {
2435                 for (x = min_wid; x <= max_wid; x++)
2436                 {
2437                         cave_type *c_ptr;
2438
2439                         /* Require "interesting" contents */
2440                         if (!target_set_accept(y, x)) continue;
2441
2442                         c_ptr = &cave[y][x];
2443
2444                         /* Require target_able monsters for "TARGET_KILL" */
2445                         if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
2446
2447                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
2448
2449                         /* Save the location */
2450                         temp_x[temp_n] = x;
2451                         temp_y[temp_n] = y;
2452                         temp_n++;
2453                 }
2454         }
2455
2456         /* Set the sort hooks */
2457         if (mode & (TARGET_KILL))
2458         {
2459                 /* Target the nearest monster for shooting */
2460                 ang_sort_comp = ang_sort_comp_distance;
2461                 ang_sort_swap = ang_sort_swap_distance;
2462         }
2463         else
2464         {
2465                 /* Look important grids first in Look command */
2466                 ang_sort_comp = ang_sort_comp_importance;
2467                 ang_sort_swap = ang_sort_swap_distance;
2468         }
2469
2470         /* Sort the positions */
2471         ang_sort(temp_x, temp_y, temp_n);
2472
2473         if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
2474         {
2475                 POSITION tmp;
2476
2477                 tmp = temp_y[0];
2478                 temp_y[0] = temp_y[1];
2479                 temp_y[1] = tmp;
2480                 tmp = temp_x[0];
2481                 temp_x[0] = temp_x[1];
2482                 temp_x[1] = tmp;
2483         }
2484 }
2485
2486 void target_set_prepare_look(void){
2487         target_set_prepare(TARGET_LOOK);
2488 }
2489
2490
2491 /*
2492  * Evaluate number of kill needed to gain level
2493  */
2494 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
2495 {
2496         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2497         u32b num;
2498         s32b exp_mon, exp_adv;
2499         u32b exp_mon_frac, exp_adv_frac;
2500
2501         if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
2502         {
2503                 sprintf(buf,"**");
2504                 return;
2505         }
2506         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
2507         {
2508                 if (!p_ptr->wizard)
2509                 {
2510                         sprintf(buf,"??");
2511                         return;
2512                 }
2513         }
2514
2515
2516         /* The monster's experience point (assuming average monster speed) */
2517         exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
2518         exp_mon_frac = 0;
2519         s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
2520
2521
2522         /* Total experience value for next level */
2523         exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
2524         exp_adv_frac = 0;
2525         s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
2526
2527         /* Experience value need to get */
2528         s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
2529
2530
2531         /* You need to kill at least one monster to get any experience */
2532         s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
2533         s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
2534
2535         /* Extract number of monsters needed */
2536         s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
2537
2538         /* If 999 or more monsters needed, only display "999". */
2539         num = MIN(999, exp_adv_frac);
2540
2541         /* Display the number */
2542         sprintf(buf,"%03ld", (long int)num);
2543 }
2544
2545
2546 bool show_gold_on_floor = FALSE;
2547
2548 /*
2549  * Examine a grid, return a keypress.
2550  *
2551  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
2552  * indicates that the "space" key should scan through the contents
2553  * of the grid, instead of simply returning immediately.  This lets
2554  * the "look" command get complete information, without making the
2555  * "target" command annoying.
2556  *
2557  * The "info" argument contains the "commands" which should be shown
2558  * inside the "[xxx]" text.  This string must never be empty, or grids
2559  * containing monsters will be displayed with an extra comma.
2560  *
2561  * Note that if a monster is in the grid, we update both the monster
2562  * recall info and the health bar info to track that monster.
2563  *
2564  * Eventually, we may allow multiple objects per grid, or objects
2565  * and terrain features in the same grid. 
2566  *
2567  * This function must handle blindness/hallucination.
2568  */
2569 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
2570 {
2571         cave_type *c_ptr = &cave[y][x];
2572         OBJECT_IDX this_o_idx, next_o_idx = 0;
2573         concptr s1 = "", s2 = "", s3 = "", x_info = "";
2574         bool boring = TRUE;
2575         FEAT_IDX feat;
2576         feature_type *f_ptr;
2577         char query = '\001';
2578         char out_val[MAX_NLEN+80];
2579         OBJECT_IDX floor_list[23];
2580         ITEM_NUMBER floor_num = 0;
2581
2582         /* Scan all objects in the grid */
2583         if (easy_floor)
2584         {
2585                 floor_num = scan_floor(floor_list, y, x, 0x02);
2586
2587                 if (floor_num)
2588                 {
2589                         x_info = _("x物 ", "x,");
2590                 }
2591         }
2592
2593         /* Hack -- under the player */
2594         if (player_bold(y, x))
2595         {
2596 #ifdef JP
2597                 s1 = "あなたは";
2598                 s2 = "の上";
2599                 s3 = "にいる";
2600 #else
2601                 s1 = "You are ";
2602                 s2 = "on ";
2603 #endif
2604         }
2605         else
2606         {
2607                 s1 = _("ターゲット:", "Target:");
2608         }
2609
2610         /* Hack -- hallucination */
2611         if (p_ptr->image)
2612         {
2613                 concptr name = _("何か奇妙な物", "something strange");
2614
2615                 /* Display a message */
2616 #ifdef JP
2617                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
2618 #else
2619                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
2620 #endif
2621
2622                 prt(out_val, 0, 0);
2623                 move_cursor_relative(y, x);
2624                 query = inkey();
2625
2626                 /* Stop on everything but "return" */
2627                 if ((query != '\r') && (query != '\n')) return query;
2628
2629                 /* Repeat forever */
2630                 return 0;
2631         }
2632
2633
2634         /* Actual monsters */
2635         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
2636         {
2637                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2638                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2639                 GAME_TEXT m_name[MAX_NLEN];
2640                 bool recall = FALSE;
2641
2642                 /* Not boring */
2643                 boring = FALSE;
2644
2645                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
2646                 monster_race_track(m_ptr->ap_r_idx);
2647                 health_track(c_ptr->m_idx);
2648                 handle_stuff();
2649
2650                 /* Interact */
2651                 while (1)
2652                 {
2653                         char acount[10];
2654
2655                         /* Recall */
2656                         if (recall)
2657                         {
2658                                 screen_save();
2659
2660                                 /* Recall on screen */
2661                                 screen_roff(m_ptr->ap_r_idx, 0);
2662
2663                                 /* Hack -- Complete the prompt (again) */
2664                                 Term_addstr(-1, TERM_WHITE, format(_("  [r思 %s%s]", "  [r,%s%s]"), x_info, info));
2665
2666                                 /* Command */
2667                                 query = inkey();
2668
2669                                 screen_load();
2670
2671                                 /* Normal commands */
2672                                 if (query != 'r') break;
2673
2674                                 /* Toggle recall */
2675                                 recall = FALSE;
2676
2677                                 /* Cleare recall text and repeat */
2678                                 continue;
2679                         }
2680
2681                         /*** Normal ***/
2682
2683                         /* Describe, and prompt for recall */
2684                         evaluate_monster_exp(acount, m_ptr);
2685
2686 #ifdef JP
2687                         sprintf(out_val, "[%s]%s%s(%s)%s%s [r思 %s%s]", acount, s1, m_name, look_mon_desc(m_ptr, 0x01), s2, s3, x_info, info);
2688 #else
2689                         sprintf(out_val, "[%s]%s%s%s%s(%s) [r, %s%s]", acount, s1, s2, s3, m_name, look_mon_desc(m_ptr, 0x01), x_info, info);
2690 #endif
2691
2692                         prt(out_val, 0, 0);
2693
2694                         /* Place cursor */
2695                         move_cursor_relative(y, x);
2696
2697                         /* Command */
2698                         query = inkey();
2699
2700                         /* Normal commands */
2701                         if (query != 'r') break;
2702
2703                         /* Toggle recall */
2704                         recall = TRUE;
2705                 }
2706
2707                 /* Always stop at "normal" keys */
2708                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2709
2710                 /* Sometimes stop at "space" key */
2711                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2712
2713                 /* Change the intro */
2714                 s1 = _("それは", "It is ");
2715
2716                 /* Hack -- take account of gender */
2717                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
2718                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
2719
2720                 /* Use a preposition */
2721 #ifdef JP
2722                 s2 = "を";
2723                 s3 = "持っている";
2724 #else
2725                 s2 = "carrying ";
2726 #endif
2727
2728
2729                 /* Scan all objects being carried */
2730                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
2731                 {
2732                         GAME_TEXT o_name[MAX_NLEN];
2733
2734                         object_type *o_ptr;
2735                         o_ptr = &o_list[this_o_idx];
2736
2737                         /* Acquire next object */
2738                         next_o_idx = o_ptr->next_o_idx;
2739
2740                         /* Obtain an object description */
2741                         object_desc(o_name, o_ptr, 0);
2742
2743 #ifdef JP
2744                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2745 #else
2746                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2747 #endif
2748
2749                         prt(out_val, 0, 0);
2750                         move_cursor_relative(y, x);
2751                         query = inkey();
2752
2753                         /* Always stop at "normal" keys */
2754                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2755
2756                         /* Sometimes stop at "space" key */
2757                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2758
2759                         /* Change the intro */
2760                         s2 = _("をまた", "also carrying ");
2761                 }
2762
2763                 /* Use a preposition */
2764 #ifdef JP
2765                 s2 = "の上";
2766                 s3 = "にいる";
2767 #else
2768                 s2 = "on ";
2769 #endif
2770         }
2771
2772         if (floor_num)
2773         {
2774                 int min_width = 0;
2775
2776                 while (1)
2777                 {
2778                         if (floor_num == 1)
2779                         {
2780                                 GAME_TEXT o_name[MAX_NLEN];
2781
2782                                 object_type *o_ptr;
2783                                 o_ptr = &o_list[floor_list[0]];
2784
2785                                 object_desc(o_name, o_ptr, 0);
2786
2787 #ifdef JP
2788                                 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2789 #else
2790                                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2791 #endif
2792
2793                                 prt(out_val, 0, 0);
2794                                 move_cursor_relative(y, x);
2795
2796                                 /* Command */
2797                                 query = inkey();
2798
2799                                 /* End this grid */
2800                                 return query;
2801                         }
2802
2803                         /* Provide one cushion before item listing  */
2804                         if (boring)
2805                         {
2806                                 /* Display rough information about items */
2807 #ifdef JP
2808                                 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
2809 #else
2810                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
2811 #endif
2812
2813                                 prt(out_val, 0, 0);
2814                                 move_cursor_relative(y, x);
2815
2816                                 /* Command */
2817                                 query = inkey();
2818
2819                                 /* No request for listing */
2820                                 if (query != 'x' && query != ' ') return query;
2821                         }
2822
2823
2824                         /** Display list of items **/
2825
2826                         /* Continue scrolling list if requested */
2827                         while (1)
2828                         {
2829                                 int i;
2830                                 OBJECT_IDX o_idx;
2831                                 screen_save();
2832
2833                                 /* Display */
2834                                 show_gold_on_floor = TRUE;
2835                                 (void)show_floor(0, y, x, &min_width);
2836                                 show_gold_on_floor = FALSE;
2837
2838                                 /* Prompt */
2839 #ifdef JP
2840                                 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
2841 #else
2842                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
2843 #endif
2844                                 prt(out_val, 0, 0);
2845
2846                                 query = inkey();
2847                                 screen_load();
2848
2849                                 /* Exit unless 'Enter' */
2850                                 if (query != '\n' && query != '\r')
2851                                 {
2852                                         return query;
2853                                 }
2854
2855                                 /* Get the object being moved. */
2856                                 o_idx = c_ptr->o_idx;
2857  
2858                                 /* Only rotate a pile of two or more objects. */
2859                                 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
2860
2861                                 /* Remove the first object from the list. */
2862                                 excise_object_idx(o_idx);
2863
2864                                 /* Find end of the list. */
2865                                 i = c_ptr->o_idx;
2866                                 while (o_list[i].next_o_idx)
2867                                         i = o_list[i].next_o_idx;
2868
2869                                 /* Add after the last object. */
2870                                 o_list[i].next_o_idx = o_idx;
2871
2872                                 /* Loop and re-display the list */
2873                         }
2874                 }
2875
2876                 /* NOTREACHED */
2877         }
2878
2879         /* Scan all objects in the grid */
2880         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2881         {
2882                 object_type *o_ptr;
2883                 o_ptr = &o_list[this_o_idx];
2884
2885                 /* Acquire next object */
2886                 next_o_idx = o_ptr->next_o_idx;
2887
2888                 if (o_ptr->marked & OM_FOUND)
2889                 {
2890                         GAME_TEXT o_name[MAX_NLEN];
2891
2892                         /* Not boring */
2893                         boring = FALSE;
2894
2895                         /* Obtain an object description */
2896                         object_desc(o_name, o_ptr, 0);
2897
2898 #ifdef JP
2899                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2900 #else
2901                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2902 #endif
2903
2904                         prt(out_val, 0, 0);
2905                         move_cursor_relative(y, x);
2906                         query = inkey();
2907
2908                         /* Always stop at "normal" keys */
2909                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2910
2911                         /* Sometimes stop at "space" key */
2912                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
2913
2914                         /* Change the intro */
2915                         s1 = _("それは", "It is ");
2916
2917                         /* Plurals */
2918                         if (o_ptr->number != 1) s1 = _("それらは", "They are ");
2919
2920                         /* Preposition */
2921 #ifdef JP
2922                         s2 = "の上";
2923                         s3 = "に見える";
2924 #else
2925                         s2 = "on ";
2926 #endif
2927
2928                 }
2929         }
2930
2931
2932         /* Feature code (applying "mimic" field) */
2933         feat = get_feat_mimic(c_ptr);
2934
2935         /* Require knowledge about grid, or ability to see grid */
2936         if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
2937         {
2938                 /* Forget feature */
2939                 feat = feat_none;
2940         }
2941
2942         f_ptr = &f_info[feat];
2943
2944         /* Terrain feature if needed */
2945         if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
2946         {
2947                 concptr name;
2948
2949                 /* Hack -- special handling for quest entrances */
2950                 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
2951                 {
2952                         /* Set the quest number temporary */
2953                         IDX old_quest = p_ptr->inside_quest;
2954                         int j;
2955
2956                         /* Clear the text */
2957                         for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
2958                         quest_text_line = 0;
2959
2960                         p_ptr->inside_quest = c_ptr->special;
2961
2962                         /* Get the quest text */
2963                         init_flags = INIT_NAME_ONLY;
2964
2965                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
2966
2967                         name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"), 
2968                                                 quest[c_ptr->special].name, quest[c_ptr->special].level);
2969
2970                         /* Reset the old quest number */
2971                         p_ptr->inside_quest = old_quest;
2972                 }
2973
2974                 /* Hack -- special handling for building doors */
2975                 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
2976                 {
2977                         name = building[f_ptr->subtype].name;
2978                 }
2979                 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
2980                 {
2981                         name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
2982                 }
2983                 else if (have_flag(f_ptr->flags, FF_TOWN))
2984                 {
2985                         name = town[c_ptr->special].name;
2986                 }
2987                 else if (p_ptr->wild_mode && (feat == feat_floor))
2988                 {
2989                         name = _("道", "road");
2990                 }
2991                 else
2992                 {
2993                         name = f_name + f_ptr->name;
2994                 }
2995
2996
2997                 /* Pick a prefix */
2998                 if (*s2 &&
2999                     ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
3000                      (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
3001                      have_flag(f_ptr->flags, FF_TOWN)))
3002                 {
3003                         s2 = _("の中", "in ");
3004                 }
3005
3006                 /* Hack -- special introduction for store & building doors -KMW- */
3007                 if (have_flag(f_ptr->flags, FF_STORE) ||
3008                     have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
3009                     (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
3010                     have_flag(f_ptr->flags, FF_ENTRANCE))
3011                 {
3012                         s2 = _("の入口", "");
3013                 }
3014 #ifndef JP
3015                 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
3016                          have_flag(f_ptr->flags, FF_TOWN) ||
3017                          have_flag(f_ptr->flags, FF_SHALLOW) ||
3018                          have_flag(f_ptr->flags, FF_DEEP))
3019                 {
3020                         s3 ="";
3021                 }
3022                 else
3023                 {
3024                         /* Pick proper indefinite article */
3025                         s3 = (is_a_vowel(name[0])) ? "an " : "a ";
3026                 }
3027 #endif
3028
3029                 /* Display a message */
3030                 if (p_ptr->wizard)
3031                 {
3032                         char f_idx_str[32];
3033                         if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
3034                         else sprintf(f_idx_str, "%d", c_ptr->feat);
3035 #ifdef JP
3036                         sprintf(out_val, "%s%s%s%s[%s] %x %s %d %d %d (%d,%d) %d", s1, name, s2, s3, info, (unsigned int)c_ptr->info, f_idx_str, c_ptr->dist, c_ptr->cost, c_ptr->when, (int)y, (int)x, travel.cost[y][x]);
3037 #else
3038                         sprintf(out_val, "%s%s%s%s [%s] %x %s %d %d %d (%d,%d)", s1, s2, s3, name, info, c_ptr->info, f_idx_str, c_ptr->dist, c_ptr->cost, c_ptr->when, (int)y, (int)x);
3039 #endif
3040                 }
3041                 else
3042 #ifdef JP
3043                         sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
3044 #else
3045                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3046 #endif
3047
3048                 prt(out_val, 0, 0);
3049                 move_cursor_relative(y, x);
3050                 query = inkey();
3051
3052                 /* Always stop at "normal" keys */
3053                 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
3054         }
3055
3056         /* Stop on everything but "return" */
3057         if ((query != '\r') && (query != '\n')) return query;
3058
3059         /* Repeat forever */
3060         return 0;
3061 }
3062
3063
3064 /*
3065  * Handle "target" and "look".
3066  *
3067  * Note that this code can be called from "get_aim_dir()".
3068  *
3069  * All locations must be on the current panel.  Consider the use of
3070  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
3071  * some form of "scrolling" the map around the cursor.  
3072  * That is, consider the possibility of "auto-scrolling" the screen
3073  * while the cursor moves around.  This may require changes in the
3074  * "update_monster()" code to allow "visibility" even if off panel, and
3075  * may require dynamic recalculation of the "temp" grid set.
3076  *
3077  * Hack -- targeting/observing an "outer border grid" may induce
3078  * problems, so this is not currently allowed.
3079  *
3080  * The player can use the direction keys to move among "interesting"
3081  * grids in a heuristic manner, or the "space", "+", and "-" keys to
3082  * move through the "interesting" grids in a sequential manner, or
3083  * can enter "location" mode, and use the direction keys to move one
3084  * grid at a time in any direction.  The "t" (set target) command will
3085  * only target a monster (as opposed to a location) if the monster is
3086  * target_able and the "interesting" mode is being used.
3087  *
3088  * The current grid is described using the "look" method above, and
3089  * a new command may be entered at any time, but note that if the
3090  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
3091  * where "space" has no obvious meaning) then "space" will scan
3092  * through the description of the current grid until done, instead
3093  * of immediately jumping to the next "interesting" grid.  This
3094  * allows the "target" command to retain its old semantics.
3095  *
3096  * The "*", "+", and "-" keys may always be used to jump immediately
3097  * to the next (or previous) interesting grid, in the proper mode.
3098  *
3099  * The "return" key may always be used to scan through a complete
3100  * grid description (forever).
3101  *
3102  * This command will cancel any old target, even if used from
3103  * inside the "look" command.
3104  */
3105 bool target_set(BIT_FLAGS mode)
3106 {
3107         int i, d, m, t, bd;
3108         POSITION y = p_ptr->y;
3109         POSITION x = p_ptr->x;
3110
3111         bool done = FALSE;
3112         bool flag = TRUE;
3113         char query;
3114         char info[80];
3115         char same_key;
3116         cave_type *c_ptr;
3117         TERM_LEN wid, hgt;
3118         
3119         get_screen_size(&wid, &hgt);
3120
3121         /* Cancel target */
3122         target_who = 0;
3123
3124         if (rogue_like_commands)
3125         {
3126                 same_key = 'x';
3127         }
3128         else
3129         {
3130                 same_key = 'l';
3131         }
3132
3133         /* Prepare the "temp" array */
3134         target_set_prepare(mode);
3135
3136         /* Start near the player */
3137         m = 0;
3138
3139         /* Interact */
3140         while (!done)
3141         {
3142                 /* Interesting grids */
3143                 if (flag && temp_n)
3144                 {
3145                         y = temp_y[m];
3146                         x = temp_x[m];
3147
3148                         /* Set forcus */
3149                         change_panel_xy(y, x);
3150
3151                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3152
3153                         /* Access */
3154                         c_ptr = &cave[y][x];
3155
3156                         /* Allow target */
3157                         if (target_able(c_ptr->m_idx))
3158                         {
3159                                 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
3160                         }
3161
3162                         /* Dis-allow target */
3163                         else
3164                         {
3165                                 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
3166                         }
3167
3168                         if (cheat_sight)
3169                         {
3170                                 char cheatinfo[30];
3171                                 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
3172                                         los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
3173                                 strcat(info, cheatinfo);
3174                         }
3175                         
3176                         /* Describe and Prompt */
3177                         while (TRUE){
3178                                 query = target_set_aux(y, x, mode, info);
3179                                 if(query)break;
3180                         }
3181
3182                         /* Assume no "direction" */
3183                         d = 0;
3184
3185                         if (use_menu)
3186                         {
3187                                 if (query == '\r') query = 't';
3188                         }  
3189
3190                         /* Analyze */
3191                         switch (query)
3192                         {
3193                                 case ESCAPE:
3194                                 case 'q':
3195                                 {
3196                                         done = TRUE;
3197                                         break;
3198                                 }
3199
3200                                 case 't':
3201                                 case '.':
3202                                 case '5':
3203                                 case '0':
3204                                 {
3205                                         if (target_able(c_ptr->m_idx))
3206                                         {
3207                                                 health_track(c_ptr->m_idx);
3208                                                 target_who = c_ptr->m_idx;
3209                                                 target_row = y;
3210                                                 target_col = x;
3211                                                 done = TRUE;
3212                                         }
3213                                         else
3214                                         {
3215                                                 bell();
3216                                         }
3217                                         break;
3218                                 }
3219
3220                                 case ' ':
3221                                 case '*':
3222                                 case '+':
3223                                 {
3224                                         if (++m == temp_n)
3225                                         {
3226                                                 m = 0;
3227                                                 if (!expand_list) done = TRUE;
3228                                         }
3229                                         break;
3230                                 }
3231
3232                                 case '-':
3233                                 {
3234                                         if (m-- == 0)
3235                                         {
3236                                                 m = temp_n - 1;
3237                                                 if (!expand_list) done = TRUE;
3238                                         }
3239                                         break;
3240                                 }
3241
3242                                 case 'p':
3243                                 {
3244                                         /* Recenter the map around the player */
3245                                         verify_panel();
3246                                         p_ptr->update |= (PU_MONSTERS);
3247                                         p_ptr->redraw |= (PR_MAP);
3248                                         p_ptr->window |= (PW_OVERHEAD);
3249                                         handle_stuff();
3250
3251                                         /* Recalculate interesting grids */
3252                                         target_set_prepare(mode);
3253
3254                                         y = p_ptr->y;
3255                                         x = p_ptr->x;
3256                                 }
3257
3258                                 case 'o':
3259                                 {
3260                                         flag = FALSE;
3261                                         break;
3262                                 }
3263
3264                                 case 'm':
3265                                 {
3266                                         break;
3267                                 }
3268
3269                                 default:
3270                                 {
3271                                         if(query == same_key)
3272                                         {
3273                                                 if (++m == temp_n)
3274                                                 {
3275                                                         m = 0;
3276                                                         if (!expand_list) done = TRUE;
3277                                                 }
3278                                         }
3279                                         else
3280                                         {
3281                                                 /* Extract the action (if any) */
3282                                                 d = get_keymap_dir(query);
3283
3284                                                 if (!d) bell();
3285                                                 break;
3286                                         }
3287                                 }
3288                         }
3289                         /* Hack -- move around */
3290                         if (d)
3291                         {
3292                                 /* Modified to scroll to monster */
3293                                 POSITION y2 = panel_row_min;
3294                                 POSITION x2 = panel_col_min;
3295
3296                                 /* Find a new monster */
3297                                 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
3298
3299                                 /* Request to target past last interesting grid */
3300                                 while (flag && (i < 0))
3301                                 {
3302                                         /* Note the change */
3303                                         if (change_panel(ddy[d], ddx[d]))
3304                                         {
3305                                                 int v = temp_y[m];
3306                                                 int u = temp_x[m];
3307
3308                                                 /* Recalculate interesting grids */
3309                                                 target_set_prepare(mode);
3310
3311                                                 /* Look at interesting grids */
3312                                                 flag = TRUE;
3313
3314                                                 /* Find a new monster */
3315                                                 i = target_pick(v, u, ddy[d], ddx[d]);
3316
3317                                                 /* Use that grid */
3318                                                 if (i >= 0) m = i;
3319                                         }
3320
3321                                         /* Nothing interesting */
3322                                         else
3323                                         {
3324                                                 POSITION dx = ddx[d];
3325                                                 POSITION dy = ddy[d];
3326
3327                                                 /* Restore previous position */
3328                                                 panel_row_min = y2;
3329                                                 panel_col_min = x2;
3330                                                 panel_bounds_center();
3331
3332                                                 p_ptr->update |= (PU_MONSTERS);
3333                                                 p_ptr->redraw |= (PR_MAP);
3334                                                 p_ptr->window |= (PW_OVERHEAD);
3335                                                 handle_stuff();
3336
3337                                                 /* Recalculate interesting grids */
3338                                                 target_set_prepare(mode);
3339
3340                                                 /* Look at boring grids */
3341                                                 flag = FALSE;
3342
3343                                                 /* Move */
3344                                                 x += dx;
3345                                                 y += dy;
3346
3347                                                 /* Do not move horizontally if unnecessary */
3348                                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3349                                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
3350                                                 {
3351                                                         dx = 0;
3352                                                 }
3353
3354                                                 /* Do not move vertically if unnecessary */
3355                                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3356                                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
3357                                                 {
3358                                                         dy = 0;
3359                                                 }
3360
3361                                                 /* Apply the motion */
3362                                                 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
3363                                                     (x >= panel_col_min+wid) || (x < panel_col_min))
3364                                                 {
3365                                                         if (change_panel(dy, dx)) target_set_prepare(mode);
3366                                                 }
3367
3368                                                 /* Slide into legality */
3369                                                 if (x >= cur_wid-1) x = cur_wid - 2;
3370                                                 else if (x <= 0) x = 1;
3371
3372                                                 /* Slide into legality */
3373                                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
3374                                                 else if (y <= 0) y = 1;
3375                                         }
3376                                 }
3377
3378                                 /* Use that grid */
3379                                 m = i;
3380                         }
3381                 }
3382
3383                 /* Arbitrary grids */
3384                 else
3385                 {
3386                         bool move_fast = FALSE;
3387
3388                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3389
3390                         /* Access */
3391                         c_ptr = &cave[y][x];
3392
3393                         /* Default prompt */
3394                         strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
3395
3396                         if (cheat_sight)
3397                         {
3398                                 char cheatinfo[30];
3399                                 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
3400                                         los(p_ptr->y, p_ptr->x, y, x),
3401                                         projectable(p_ptr->y, p_ptr->x, y, x));
3402                                 strcat(info, cheatinfo);
3403                         }
3404
3405                         /* Describe and Prompt (enable "TARGET_LOOK") */
3406                         while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
3407
3408                         /* Assume no direction */
3409                         d = 0;
3410
3411                         if (use_menu)
3412                         {
3413                                 if (query == '\r') query = 't';
3414                         }  
3415
3416                         /* Analyze the keypress */
3417                         switch (query)
3418                         {
3419                                 case ESCAPE:
3420                                 case 'q':
3421                                 {
3422                                         done = TRUE;
3423                                         break;
3424                                 }
3425
3426                                 case 't':
3427                                 case '.':
3428                                 case '5':
3429                                 case '0':
3430                                 {
3431                                         target_who = -1;
3432                                         target_row = y;
3433                                         target_col = x;
3434                                         done = TRUE;
3435                                         break;
3436                                 }
3437
3438                                 case 'p':
3439                                 {
3440                                         /* Recenter the map around the player */
3441                                         verify_panel();
3442                                         p_ptr->update |= (PU_MONSTERS);
3443                                         p_ptr->redraw |= (PR_MAP);
3444                                         p_ptr->window |= (PW_OVERHEAD);
3445                                         handle_stuff();
3446
3447                                         /* Recalculate interesting grids */
3448                                         target_set_prepare(mode);
3449
3450                                         y = p_ptr->y;
3451                                         x = p_ptr->x;
3452                                 }
3453
3454                                 case 'o':
3455                                 {
3456                                         break;
3457                                 }
3458
3459                                 case ' ':
3460                                 case '*':
3461                                 case '+':
3462                                 case '-':
3463                                 case 'm':
3464                                 {
3465                                         flag = TRUE;
3466
3467                                         m = 0;
3468                                         bd = 999;
3469
3470                                         /* Pick a nearby monster */
3471                                         for (i = 0; i < temp_n; i++)
3472                                         {
3473                                                 t = distance(y, x, temp_y[i], temp_x[i]);
3474
3475                                                 /* Pick closest */
3476                                                 if (t < bd)
3477                                                 {
3478                                                         m = i;
3479                                                         bd = t;
3480                                                 }
3481                                         }
3482
3483                                         /* Nothing interesting */
3484                                         if (bd == 999) flag = FALSE;
3485
3486                                         break;
3487                                 }
3488
3489                                 default:
3490                                 {
3491                                         /* Extract the action (if any) */
3492                                         d = get_keymap_dir(query);
3493
3494                                         /* XTRA HACK MOVEFAST */
3495                                         if (isupper(query)) move_fast = TRUE;
3496
3497                                         if (!d) bell();
3498                                         break;
3499                                 }
3500                         }
3501
3502                         /* Handle "direction" */
3503                         if (d)
3504                         {
3505                                 POSITION dx = ddx[d];
3506                                 POSITION dy = ddy[d];
3507
3508                                 /* XTRA HACK MOVEFAST */
3509                                 if (move_fast)
3510                                 {
3511                                         int mag = MIN(wid / 2, hgt / 2);
3512                                         x += dx * mag;
3513                                         y += dy * mag;
3514                                 }
3515                                 else
3516                                 {
3517                                         x += dx;
3518                                         y += dy;
3519                                 }
3520
3521                                 /* Do not move horizontally if unnecessary */
3522                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3523                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
3524                                 {
3525                                         dx = 0;
3526                                 }
3527
3528                                 /* Do not move vertically if unnecessary */
3529                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3530                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
3531                                 {
3532                                         dy = 0;
3533                                 }
3534
3535                                 /* Apply the motion */
3536                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
3537                                          (x >= panel_col_min + wid) || (x < panel_col_min))
3538                                 {
3539                                         if (change_panel(dy, dx)) target_set_prepare(mode);
3540                                 }
3541
3542                                 /* Slide into legality */
3543                                 if (x >= cur_wid-1) x = cur_wid - 2;
3544                                 else if (x <= 0) x = 1;
3545
3546                                 /* Slide into legality */
3547                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
3548                                 else if (y <= 0) y = 1;
3549                         }
3550                 }
3551         }
3552
3553         /* Forget */
3554         temp_n = 0;
3555
3556         /* Clear the top line */
3557         prt("", 0, 0);
3558
3559         /* Recenter the map around the player */
3560         verify_panel();
3561         p_ptr->update |= (PU_MONSTERS);
3562         p_ptr->redraw |= (PR_MAP);
3563         p_ptr->window |= (PW_OVERHEAD);
3564         handle_stuff();
3565
3566         /* Failure to set target */
3567         if (!target_who) return (FALSE);
3568
3569         /* Success */
3570         return (TRUE);
3571 }
3572
3573
3574 /*
3575  * Get an "aiming direction" from the user.
3576  *
3577  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
3578  * "0" for "current target", and "-1" for "entry aborted".
3579  *
3580  * Note that "Force Target", if set, will pre-empt user interaction,
3581  * if there is a usable target already set.
3582  *
3583  * Note that confusion over-rides any (explicit?) user choice.
3584  */
3585 bool get_aim_dir(DIRECTION *dp)
3586 {
3587         DIRECTION dir;
3588         char    command;
3589         concptr p;
3590         COMMAND_CODE code;
3591
3592         (*dp) = 0;
3593
3594         /* Global direction */
3595         dir = command_dir;
3596
3597         /* Hack -- auto-target if requested */
3598         if (use_old_target && target_okay()) dir = 5;
3599
3600         if (repeat_pull(&code))
3601         {
3602                 /* Confusion? */
3603
3604                 /* Verify */
3605                 if (!(code == 5 && !target_okay()))
3606                 {
3607 /*                      return (TRUE); */
3608                         dir = (DIRECTION)code;
3609                 }
3610         }
3611         *dp = (DIRECTION)code;
3612
3613         /* Ask until satisfied */
3614         while (!dir)
3615         {
3616                 /* Choose a prompt */
3617                 if (!target_okay())
3618                 {
3619                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
3620                 }
3621                 else
3622                 {
3623                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
3624                 }
3625
3626                 /* Get a command (or Cancel) */
3627                 if (!get_com(p, &command, TRUE)) break;
3628
3629                 if (use_menu)
3630                 {
3631                         if (command == '\r') command = 't';
3632                 }  
3633
3634                 /* Convert various keys to "standard" keys */
3635                 switch (command)
3636                 {
3637                         /* Use current target */
3638                         case 'T':
3639                         case 't':
3640                         case '.':
3641                         case '5':
3642                         case '0':
3643                         {
3644                                 dir = 5;
3645                                 break;
3646                         }
3647
3648                         /* Set new target */
3649                         case '*':
3650                         case ' ':
3651                         case '\r':
3652                         {
3653                                 if (target_set(TARGET_KILL)) dir = 5;
3654                                 break;
3655                         }
3656
3657                         default:
3658                         {
3659                                 /* Extract the action (if any) */
3660                                 dir = get_keymap_dir(command);
3661
3662                                 break;
3663                         }
3664                 }
3665
3666                 /* Verify requested targets */
3667                 if ((dir == 5) && !target_okay()) dir = 0;
3668
3669                 /* Error */
3670                 if (!dir) bell();
3671         }
3672
3673         /* No direction */
3674         if (!dir)
3675         {
3676                 project_length = 0; /* reset to default */
3677                 return (FALSE);
3678         }
3679
3680         /* Save the direction */
3681         command_dir = dir;
3682
3683         /* Check for confusion */
3684         if (p_ptr->confused)
3685         {
3686                 /* Random direction */
3687                 dir = ddd[randint0(8)];
3688         }
3689
3690         /* Notice confusion */
3691         if (command_dir != dir)
3692         {
3693                 /* Warn the user */
3694                 msg_print(_("あなたは混乱している。", "You are confused."));
3695         }
3696
3697         /* Save direction */
3698         (*dp) = dir;
3699
3700 /*      repeat_push(dir); */
3701         repeat_push((COMMAND_CODE)command_dir);
3702
3703         /* A "valid" direction was entered */
3704         return (TRUE);
3705 }
3706
3707
3708 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
3709 {
3710         DIRECTION dir;
3711         concptr prompt;
3712         COMMAND_CODE code;
3713
3714         (*dp) = 0;
3715
3716         /* Global direction */
3717         dir = command_dir;
3718
3719         if (repeat_pull(&code))
3720         {
3721                 dir = (DIRECTION)code;
3722                 /*              return (TRUE); */
3723         }
3724         *dp = (DIRECTION)code;
3725
3726         if (allow_under)
3727         {
3728                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3729         }
3730         else
3731         {
3732                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3733         }
3734
3735         /* Get a direction */
3736         while (!dir)
3737         {
3738                 char ch;
3739
3740                 /* Get a command (or Cancel) */
3741                 if (!get_com(prompt, &ch, TRUE)) break;
3742
3743                 /* Look down */
3744                 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3745                 {
3746                         dir = 5;
3747                 }
3748                 else
3749                 {
3750                         /* Look up the direction */
3751                         dir = get_keymap_dir(ch);
3752
3753                         if (!dir) bell();
3754                 }
3755         }
3756
3757         /* Prevent weirdness */
3758         if ((dir == 5) && (!allow_under)) dir = 0;
3759
3760         /* Aborted */
3761         if (!dir) return (FALSE);
3762
3763         /* Save desired direction */
3764         command_dir = dir;
3765
3766         /* Apply "confusion" */
3767         if (p_ptr->confused)
3768         {
3769                 /* Standard confusion */
3770                 if (randint0(100) < 75)
3771                 {
3772                         /* Random direction */
3773                         dir = ddd[randint0(8)];
3774                 }
3775         }
3776         else if (p_ptr->riding && with_steed)
3777         {
3778                 monster_type *m_ptr = &m_list[p_ptr->riding];
3779                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3780
3781                 if (MON_CONFUSED(m_ptr))
3782                 {
3783                         /* Standard confusion */
3784                         if (randint0(100) < 75)
3785                         {
3786                                 /* Random direction */
3787                                 dir = ddd[randint0(8)];
3788                         }
3789                 }
3790                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3791                 {
3792                         /* Random direction */
3793                         dir = ddd[randint0(8)];
3794                 }
3795                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3796                 {
3797                         /* Random direction */
3798                         dir = ddd[randint0(8)];
3799                 }
3800         }
3801
3802         /* Notice confusion */
3803         if (command_dir != dir)
3804         {
3805                 if (p_ptr->confused)
3806                 {
3807                         /* Warn the user */
3808                         msg_print(_("あなたは混乱している。", "You are confused."));
3809                 }
3810                 else
3811                 {
3812                         GAME_TEXT m_name[MAX_NLEN];
3813                         monster_type *m_ptr = &m_list[p_ptr->riding];
3814
3815                         monster_desc(m_name, m_ptr, 0);
3816                         if (MON_CONFUSED(m_ptr))
3817                         {
3818                                 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3819                         }
3820                         else
3821                         {
3822                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3823                         }
3824                 }
3825         }
3826
3827         /* Save direction */
3828         (*dp) = dir;
3829
3830         /*      repeat_push(dir); */
3831         repeat_push((COMMAND_CODE)command_dir);
3832
3833         /* Success */
3834         return (TRUE);
3835 }
3836
3837 /*
3838  * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
3839  * and place it into "command_dir", unless we already have one.
3840  *
3841  * This function should be used for all "repeatable" commands, such as
3842  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
3843  * as all commands which must reference a grid adjacent to the player,
3844  * and which may not reference the grid under the player.  Note that,
3845  * for example, it is no longer possible to "disarm" or "open" chests
3846  * in the same grid as the player.
3847  *
3848  * Direction "5" is illegal and will (cleanly) abort the command.
3849  *
3850  * This function tracks and uses the "global direction", and uses
3851  * that as the "desired direction", to which "confusion" is applied.
3852  */
3853 bool get_rep_dir(DIRECTION *dp, bool under)
3854 {
3855         DIRECTION dir;
3856         concptr prompt;
3857         COMMAND_CODE code;
3858
3859         (*dp) = 0;
3860
3861         /* Global direction */
3862         dir = command_dir;
3863
3864         if (repeat_pull(&code))
3865         {
3866                 dir = (DIRECTION)code;
3867 /*              return (TRUE); */
3868         }
3869         *dp = (DIRECTION)code;
3870
3871         if (under)
3872         {
3873                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3874         }
3875         else
3876         {
3877                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3878         }
3879         
3880         /* Get a direction */
3881         while (!dir)
3882         {
3883                 char ch;
3884
3885                 /* Get a command (or Cancel) */
3886                 if (!get_com(prompt, &ch, TRUE)) break;
3887
3888                 /* Look down */
3889                 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3890                 {
3891                         dir = 5;
3892                 }
3893                 else
3894                 {
3895                         /* Look up the direction */
3896                         dir = get_keymap_dir(ch);
3897
3898                         if (!dir) bell();
3899                 }
3900         }
3901
3902         /* Prevent weirdness */
3903         if ((dir == 5) && (!under)) dir = 0;
3904
3905         /* Aborted */
3906         if (!dir) return (FALSE);
3907
3908         /* Save desired direction */
3909         command_dir = dir;
3910
3911         /* Apply "confusion" */
3912         if (p_ptr->confused)
3913         {
3914                 /* Standard confusion */
3915                 if (randint0(100) < 75)
3916                 {
3917                         /* Random direction */
3918                         dir = ddd[randint0(8)];
3919                 }
3920         }
3921         else if (p_ptr->riding)
3922         {
3923                 monster_type *m_ptr = &m_list[p_ptr->riding];
3924                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3925
3926                 if (MON_CONFUSED(m_ptr))
3927                 {
3928                         /* Standard confusion */
3929                         if (randint0(100) < 75)
3930                         {
3931                                 /* Random direction */
3932                                 dir = ddd[randint0(8)];
3933                         }
3934                 }
3935                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3936                 {
3937                         /* Random direction */
3938                         dir = ddd[randint0(8)];
3939                 }
3940                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3941                 {
3942                         /* Random direction */
3943                         dir = ddd[randint0(8)];
3944                 }
3945         }
3946
3947         /* Notice confusion */
3948         if (command_dir != dir)
3949         {
3950                 if (p_ptr->confused)
3951                 {
3952                         /* Warn the user */
3953                         msg_print(_("あなたは混乱している。", "You are confused."));
3954                 }
3955                 else
3956                 {
3957                         GAME_TEXT m_name[MAX_NLEN];
3958                         monster_type *m_ptr = &m_list[p_ptr->riding];
3959
3960                         monster_desc(m_name, m_ptr, 0);
3961                         if (MON_CONFUSED(m_ptr))
3962                         {
3963                                 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3964                         }
3965                         else
3966                         {
3967                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3968                         }
3969                 }
3970         }
3971
3972         /* Save direction */
3973         (*dp) = dir;
3974
3975 /*      repeat_push(dir); */
3976         repeat_push((COMMAND_CODE)command_dir);
3977
3978         /* Success */
3979         return (TRUE);
3980 }
3981
3982 void gain_level_reward(int chosen_reward)
3983 {
3984         object_type *q_ptr;
3985         object_type forge;
3986         char        wrath_reason[32] = "";
3987         int         nasty_chance = 6;
3988         OBJECT_TYPE_VALUE dummy = 0;
3989         OBJECT_SUBTYPE_VALUE dummy2 = 0;
3990         int         type, effect;
3991         concptr        reward = NULL;
3992         GAME_TEXT o_name[MAX_NLEN];
3993
3994         int count = 0;
3995
3996         if (!chosen_reward)
3997         {
3998                 if (multi_rew) return;
3999                 else multi_rew = TRUE;
4000         }
4001
4002
4003         if (p_ptr->lev == 13) nasty_chance = 2;
4004         else if (!(p_ptr->lev % 13)) nasty_chance = 3;
4005         else if (!(p_ptr->lev % 14)) nasty_chance = 12;
4006
4007         if (one_in_(nasty_chance))
4008                 type = randint1(20); /* Allow the 'nasty' effects */
4009         else
4010                 type = randint1(15) + 5; /* Or disallow them */
4011
4012         if (type < 1) type = 1;
4013         if (type > 20) type = 20;
4014         type--;
4015
4016
4017         sprintf(wrath_reason, _("%sの怒り", "the Wrath of %s"), chaos_patrons[p_ptr->chaos_patron]);
4018
4019         effect = chaos_rewards[p_ptr->chaos_patron][type];
4020
4021         if (one_in_(6) && !chosen_reward)
4022         {
4023                 msg_format(_("%^sは褒美としてあなたを突然変異させた。", "%^s rewards you with a mutation!"), chaos_patrons[p_ptr->chaos_patron]);
4024                 (void)gain_random_mutation(0);
4025                 reward = _("変異した。", "mutation");
4026         }
4027         else
4028         {
4029         switch (chosen_reward ? chosen_reward : effect)
4030         {
4031
4032                 case REW_POLY_SLF:
4033
4034                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4035                         msg_print(_("「汝、新たなる姿を必要とせり!」", "'Thou needst a new form, mortal!'"));
4036
4037                         do_poly_self();
4038                         reward = _("変異した。", "polymorphing");
4039                         break;
4040
4041                 case REW_GAIN_EXP:
4042
4043                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4044                         msg_print(_("「汝は良く行いたり!続けよ!」", "'Well done, mortal! Lead on!'"));
4045
4046                         if (p_ptr->prace == RACE_ANDROID)
4047                         {
4048                                 msg_print(_("しかし何も起こらなかった。", "But, nothing happen."));
4049                         }
4050                         else if (p_ptr->exp < PY_MAX_EXP)
4051                         {
4052                                 s32b ee = (p_ptr->exp / 2) + 10;
4053                                 if (ee > 100000L) ee = 100000L;
4054                                 msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
4055
4056                                 gain_exp(ee);
4057                                 reward = _("経験値を得た", "experience");
4058                         }
4059                         break;
4060
4061                 case REW_LOSE_EXP:
4062
4063                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4064                         msg_print(_("「下僕よ、汝それに値せず。」", "'Thou didst not deserve that, slave.'"));
4065
4066                         if (p_ptr->prace == RACE_ANDROID)
4067                         {
4068                                 msg_print(_("しかし何も起こらなかった。", "But, nothing happen."));
4069                         }
4070                         else
4071                         {
4072                                 lose_exp(p_ptr->exp / 6);
4073                                 reward = _("経験値を失った。", "losing experience");
4074                         }
4075                         break;
4076
4077                 case REW_GOOD_OBJ:
4078 #ifdef JP
4079                         msg_format("%sの声がささやいた:",
4080                                 chaos_patrons[p_ptr->chaos_patron]);
4081 #else
4082                         msg_format("The voice of %s whispers:",
4083                                 chaos_patrons[p_ptr->chaos_patron]);
4084 #endif
4085
4086                         msg_print(_("「我が与えし物を賢明に使うべし。」", "'Use my gift wisely.'"));
4087
4088                         acquirement(p_ptr->y, p_ptr->x, 1, FALSE, FALSE, FALSE);
4089                         reward = _("上質なアイテムを手に入れた。", "a good item");
4090                         break;
4091
4092                 case REW_GREA_OBJ:
4093
4094                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4095                         msg_print(_("「我が与えし物を賢明に使うべし。」", "'Use my gift wisely.'"));
4096
4097                         acquirement(p_ptr->y, p_ptr->x, 1, TRUE, FALSE, FALSE);
4098                         reward = _("高級品のアイテムを手に入れた。", "an excellent item");
4099                         break;
4100
4101                 case REW_CHAOS_WP:
4102
4103                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4104                         msg_print(_("「汝の行いは貴き剣に値せり。」", "'Thy deed hath earned thee a worthy blade.'"));
4105                         q_ptr = &forge;
4106                         dummy = TV_SWORD;
4107                         switch (randint1(p_ptr->lev))
4108                         {
4109                                 case 0: case 1:
4110                                         dummy2 = SV_DAGGER;
4111                                         break;
4112                                 case 2: case 3:
4113                                         dummy2 = SV_MAIN_GAUCHE;
4114                                         break;
4115                                 case 4:
4116                                         dummy2 = SV_TANTO;
4117                                         break;
4118                                 case 5: case 6:
4119                                         dummy2 = SV_RAPIER;
4120                                         break;
4121                                 case 7: case 8:
4122                                         dummy2 = SV_SMALL_SWORD;
4123                                         break;
4124                                 case 9: case 10:
4125                                         dummy2 = SV_BASILLARD;
4126                                         break;
4127                                 case 11: case 12: case 13:
4128                                         dummy2 = SV_SHORT_SWORD;
4129                                         break;
4130                                 case 14: case 15:
4131                                         dummy2 = SV_SABRE;
4132                                         break;
4133                                 case 16: case 17:
4134                                         dummy2 = SV_CUTLASS;
4135                                         break;
4136                                 case 18:
4137                                         dummy2 = SV_WAKIZASHI;
4138                                         break;
4139                                 case 19:
4140                                         dummy2 = SV_KHOPESH;
4141                                         break;
4142                                 case 20:
4143                                         dummy2 = SV_TULWAR;
4144                                         break;
4145                                 case 21:
4146                                         dummy2 = SV_BROAD_SWORD;
4147                                         break;
4148                                 case 22: case 23:
4149                                         dummy2 = SV_LONG_SWORD;
4150                                         break;
4151                                 case 24: case 25:
4152                                         dummy2 = SV_SCIMITAR;
4153                                         break;
4154                                 case 26:
4155                                         dummy2 = SV_NINJATO;
4156                                         break;
4157                                 case 27:
4158                                         dummy2 = SV_KATANA;
4159                                         break;
4160                                 case 28: case 29:
4161                                         dummy2 = SV_BASTARD_SWORD;
4162                                         break;
4163                                 case 30:
4164                                         dummy2 = SV_GREAT_SCIMITAR;
4165                                         break;
4166                                 case 31:
4167                                         dummy2 = SV_CLAYMORE;
4168                                         break;
4169                                 case 32:
4170                                         dummy2 = SV_ESPADON;
4171                                         break;
4172                                 case 33:
4173                                         dummy2 = SV_TWO_HANDED_SWORD;
4174                                         break;
4175                                 case 34:
4176                                         dummy2 = SV_FLAMBERGE;
4177                                         break;
4178                                 case 35:
4179                                         dummy2 = SV_NO_DACHI;
4180                                         break;
4181                                 case 36:
4182                                         dummy2 = SV_EXECUTIONERS_SWORD;
4183                                         break;
4184                                 case 37:
4185                                         dummy2 = SV_ZWEIHANDER;
4186                                         break;
4187                                 case 38:
4188                                         dummy2 = SV_HAYABUSA;
4189                                         break;
4190                                 default:
4191                                         dummy2 = SV_BLADE_OF_CHAOS;
4192                         }
4193
4194                         object_prep(q_ptr, lookup_kind(dummy, dummy2));
4195                         q_ptr->to_h = 3 + randint1(dun_level) % 10;
4196                         q_ptr->to_d = 3 + randint1(dun_level) % 10;
4197                         one_resistance(q_ptr);
4198                         q_ptr->name2 = EGO_CHAOTIC;
4199                         (void)drop_near(q_ptr, -1, p_ptr->y, p_ptr->x);
4200                         reward = _("(混沌)の武器を手に入れた。", "chaos weapon");
4201                         break;
4202
4203                 case REW_GOOD_OBS:
4204
4205                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4206                         msg_print(_("「汝の行いは貴き報いに値せり。」", "'Thy deed hath earned thee a worthy reward.'"));
4207
4208                         acquirement(p_ptr->y, p_ptr->x, randint1(2) + 1, FALSE, FALSE, FALSE);
4209                         reward = _("上質なアイテムを手に入れた。", "good items");
4210                         break;
4211
4212                 case REW_GREA_OBS:
4213
4214                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4215                         msg_print(_("「下僕よ、汝の献身への我が惜しみ無き報いを見るがよい。」", "'Behold, mortal, how generously I reward thy loyalty.'"));
4216
4217                         acquirement(p_ptr->y, p_ptr->x, randint1(2) + 1, TRUE, FALSE, FALSE);
4218                         reward = _("高級品のアイテムを手に入れた。", "excellent items");
4219                         break;
4220
4221                 case REW_TY_CURSE:
4222 #ifdef JP
4223                         msg_format("%sの声が轟き渡った:", chaos_patrons[p_ptr->chaos_patron]);
4224 #else
4225                         msg_format("The voice of %s thunders:", chaos_patrons[p_ptr->chaos_patron]);
4226 #endif
4227
4228                         msg_print(_("「下僕よ、汝傲慢なり。」", "'Thou art growing arrogant, mortal.'"));
4229
4230                         (void)activate_ty_curse(FALSE, &count);
4231                         reward = _("禍々しい呪いをかけられた。", "cursing");
4232                         break;
4233
4234                 case REW_SUMMON_M:
4235
4236                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4237                         msg_print(_("「我が下僕たちよ、かの傲慢なる者を倒すべし!」", "'My pets, destroy the arrogant mortal!'"));
4238
4239                         for (dummy = 0; dummy < randint1(5) + 1; dummy++)
4240                         {
4241                                 (void)summon_specific(0, p_ptr->y, p_ptr->x, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
4242                         }
4243                         reward = _("モンスターを召喚された。", "summoning hostile monsters");
4244                         break;
4245
4246
4247                 case REW_H_SUMMON:
4248
4249                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4250                         msg_print(_("「汝、より強き敵を必要とせり!」", "'Thou needst worthier opponents!'"));
4251
4252                         activate_hi_summon(p_ptr->y, p_ptr->x, FALSE);
4253                         reward = _("モンスターを召喚された。", "summoning many hostile monsters");
4254                         break;
4255
4256
4257                 case REW_DO_HAVOC:
4258 #ifdef JP
4259                         msg_format("%sの声が響き渡った:",
4260                                 chaos_patrons[p_ptr->chaos_patron]);
4261 #else
4262                         msg_format("The voice of %s booms out:",
4263                                 chaos_patrons[p_ptr->chaos_patron]);
4264 #endif
4265
4266                         msg_print(_("「死と破壊こそ我が喜びなり!」", "'Death and destruction! This pleaseth me!'"));
4267
4268                         call_chaos();
4269                         reward = _("カオスの力が渦巻いた。", "calling chaos");
4270                         break;
4271
4272
4273                 case REW_GAIN_ABL:
4274 #ifdef JP
4275                         msg_format("%sの声が鳴り響いた:",
4276                                 chaos_patrons[p_ptr->chaos_patron]);
4277 #else
4278                         msg_format("The voice of %s rings out:",
4279                                 chaos_patrons[p_ptr->chaos_patron]);
4280 #endif
4281
4282                         msg_print(_("「留まるのだ、下僕よ。余が汝の肉体を鍛えん。」", "'Stay, mortal, and let me mold thee.'"));
4283
4284                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
4285                                 do_inc_stat(chaos_stats[p_ptr->chaos_patron]);
4286                         else
4287                                 do_inc_stat(randint0(6));
4288                         reward = _("能力値が上がった。", "increasing a stat");
4289                         break;
4290
4291
4292                 case REW_LOSE_ABL:
4293 #ifdef JP
4294                         msg_format("%sの声が響き渡った:",
4295                                 chaos_patrons[p_ptr->chaos_patron]);
4296 #else
4297                         msg_format("The voice of %s booms out:",
4298                                 chaos_patrons[p_ptr->chaos_patron]);
4299 #endif
4300
4301                         msg_print(_("「下僕よ、余は汝に飽みたり。」", "'I grow tired of thee, mortal.'"));
4302
4303                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
4304                                 do_dec_stat(chaos_stats[p_ptr->chaos_patron]);
4305                         else
4306                                 (void)do_dec_stat(randint0(6));
4307                         reward = _("能力値が下がった。", "decreasing a stat");
4308                         break;
4309
4310
4311                 case REW_RUIN_ABL:
4312
4313 #ifdef JP
4314                         msg_format("%sの声が轟き渡った:",
4315                                 chaos_patrons[p_ptr->chaos_patron]);
4316 #else
4317                         msg_format("The voice of %s thunders:",
4318                                 chaos_patrons[p_ptr->chaos_patron]);
4319 #endif
4320
4321                         msg_print(_("「汝、謙虚たることを学ぶべし!」", "'Thou needst a lesson in humility, mortal!'"));
4322                         msg_print(_("あなたは以前より弱くなった!", "You feel less powerful!"));
4323
4324                         for (dummy = 0; dummy < A_MAX; dummy++)
4325                         {
4326                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
4327                         }
4328                         reward = _("全能力値が下がった。", "decreasing all stats");
4329                         break;
4330
4331                 case REW_POLY_WND:
4332
4333                         msg_format(_("%sの力が触れるのを感じた。", "You feel the power of %s touch you."),
4334                                 chaos_patrons[p_ptr->chaos_patron]);
4335                         do_poly_wounds();
4336                         reward = _("傷が変化した。", "polymorphing wounds");
4337                         break;
4338
4339                 case REW_AUGM_ABL:
4340
4341                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4342
4343                         msg_print(_("「我がささやかなる賜物を受けとるがよい!」", "'Receive this modest gift from me!'"));
4344
4345                         for (dummy = 0; dummy < A_MAX; dummy++)
4346                         {
4347                                 (void)do_inc_stat(dummy);
4348                         }
4349                         reward = _("全能力値が上がった。", "increasing all stats");
4350                         break;
4351
4352                 case REW_HURT_LOT:
4353
4354                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4355                         msg_print(_("「苦しむがよい、無能な愚か者よ!」", "'Suffer, pathetic fool!'"));
4356
4357                         fire_ball(GF_DISINTEGRATE, 0, p_ptr->lev * 4, 4);
4358                         take_hit(DAMAGE_NOESCAPE, p_ptr->lev * 4, wrath_reason, -1);
4359                         reward = _("分解の球が発生した。", "generating disintegration ball");
4360                         break;
4361
4362                 case REW_HEAL_FUL:
4363
4364                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4365                         (void)restore_level();
4366                         (void)restore_all_status();
4367                         (void)true_healing(5000);
4368                         reward = _("体力が回復した。", "healing");
4369                         break;
4370
4371                 case REW_CURSE_WP:
4372
4373                         if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
4374                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4375                         msg_print(_("「汝、武器に頼ることなかれ。」", "'Thou reliest too much on thy weapon.'"));
4376
4377                         dummy = INVEN_RARM;
4378                         if (buki_motteruka(INVEN_LARM))
4379                         {
4380                                 dummy = INVEN_LARM;
4381                                 if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
4382                         }
4383                         object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
4384                         (void)curse_weapon(FALSE, dummy);
4385                         reward = format(_("%sが破壊された。", "destroying %s"), o_name);
4386                         break;
4387
4388                 case REW_CURSE_AR:
4389
4390                         if (!inventory[INVEN_BODY].k_idx) break;
4391                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4392                         msg_print(_("「汝、防具に頼ることなかれ。」", "'Thou reliest too much on thine equipment.'"));
4393
4394                         object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
4395                         (void)curse_armor();
4396                         reward = format(_("%sが破壊された。", "destroying %s"), o_name);
4397                         break;
4398                 case REW_PISS_OFF:
4399
4400                         msg_format(_("%sの声がささやいた:", "The voice of %s whispers:"), chaos_patrons[p_ptr->chaos_patron]);
4401                         msg_print(_("「我を怒りしめた罪を償うべし。」", "'Now thou shalt pay for annoying me.'"));
4402
4403                         switch (randint1(4))
4404                         {
4405                                 case 1:
4406                                         (void)activate_ty_curse(FALSE, &count);
4407                                         reward = _("禍々しい呪いをかけられた。", "cursing");
4408                                         break;
4409                                 case 2:
4410                                         activate_hi_summon(p_ptr->y, p_ptr->x, FALSE);
4411                                         reward = _("モンスターを召喚された。", "summoning hostile monsters");
4412                                         break;
4413                                 case 3:
4414                                         if (one_in_(2))
4415                                         {
4416                                                 if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
4417                                                 dummy = INVEN_RARM;
4418                                                 if (buki_motteruka(INVEN_LARM))
4419                                                 {
4420                                                         dummy = INVEN_LARM;
4421                                                         if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
4422                                                 }
4423                                                 object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
4424                                                 (void)curse_weapon(FALSE, dummy);
4425                                                 reward = format(_("%sが破壊された。", "destroying %s"), o_name);
4426                                         }
4427                                         else
4428                                         {
4429                                                 if (!inventory[INVEN_BODY].k_idx) break;
4430                                                 object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
4431                                                 (void)curse_armor();
4432                                                 reward = format(_("%sが破壊された。", "destroying %s"), o_name);
4433                                         }
4434                                         break;
4435                                 default:
4436                                         for (dummy = 0; dummy < A_MAX; dummy++)
4437                                         {
4438                                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
4439                                         }
4440                                         reward = _("全能力値が下がった。", "decreasing all stats");
4441                                         break;
4442                         }
4443                         break;
4444
4445                 case REW_WRATH:
4446
4447                         msg_format(_("%sの声が轟き渡った:", "The voice of %s thunders:"), chaos_patrons[p_ptr->chaos_patron]);
4448                         msg_print(_("「死ぬがよい、下僕よ!」", "'Die, mortal!'"));
4449
4450                         take_hit(DAMAGE_LOSELIFE, p_ptr->lev * 4, wrath_reason, -1);
4451                         for (dummy = 0; dummy < A_MAX; dummy++)
4452                         {
4453                                 (void)dec_stat(dummy, 10 + randint1(15), FALSE);
4454                         }
4455                         activate_hi_summon(p_ptr->y, p_ptr->x, FALSE);
4456                         (void)activate_ty_curse(FALSE, &count);
4457                         if (one_in_(2))
4458                         {
4459                                 dummy = 0;
4460
4461                                 if (buki_motteruka(INVEN_RARM))
4462                                 {
4463                                         dummy = INVEN_RARM;
4464                                         if (buki_motteruka(INVEN_LARM) && one_in_(2)) dummy = INVEN_LARM;
4465                                 }
4466                                 else if (buki_motteruka(INVEN_LARM)) dummy = INVEN_LARM;
4467
4468                                 if (dummy) (void)curse_weapon(FALSE, dummy);
4469                         }
4470                         if (one_in_(2)) (void)curse_armor();
4471                         break;
4472
4473                 case REW_DESTRUCT:
4474
4475                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4476                         msg_print(_("「死と破壊こそ我が喜びなり!」", "'Death and destruction! This pleaseth me!'"));
4477
4478                         (void)destroy_area(p_ptr->y, p_ptr->x, 25, FALSE);
4479                         reward = _("ダンジョンが*破壊*された。", "*destruct*ing dungeon");
4480                         break;
4481
4482                 case REW_GENOCIDE:
4483
4484                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4485                         msg_print(_("「我、汝の敵を抹殺せん!」", "'Let me relieve thee of thine oppressors!'"));
4486                         (void)symbol_genocide(0, FALSE);
4487                         reward = _("モンスターが抹殺された。", "genociding monsters");
4488                         break;
4489
4490                 case REW_MASS_GEN:
4491
4492                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4493                         msg_print(_("「我、汝の敵を抹殺せん!」", "'Let me relieve thee of thine oppressors!'"));
4494
4495                         (void)mass_genocide(0, FALSE);
4496                         reward = _("モンスターが抹殺された。", "genociding nearby monsters");
4497                         break;
4498
4499                 case REW_DISPEL_C:
4500
4501                         msg_format(_("%sの力が敵を攻撃するのを感じた!", "You can feel the power of %s assault your enemies!"), chaos_patrons[p_ptr->chaos_patron]);
4502                         (void)dispel_monsters(p_ptr->lev * 4);
4503                         break;
4504
4505                 case REW_IGNORE:
4506
4507                         msg_format(_("%sはあなたを無視した。", "%s ignores you."), chaos_patrons[p_ptr->chaos_patron]);
4508                         break;
4509
4510                 case REW_SER_DEMO:
4511
4512                         msg_format(_("%sは褒美として悪魔の使いをよこした!", "%s rewards you with a demonic servant!"),chaos_patrons[p_ptr->chaos_patron]);
4513
4514                         if (!summon_specific(-1, p_ptr->y, p_ptr->x, dun_level, SUMMON_DEMON, PM_FORCE_PET, '\0'))
4515                                 msg_print(_("何も現れなかった...", "Nobody ever turns up..."));
4516                         else
4517                                 reward = _("悪魔がペットになった。", "a demonic servant");
4518
4519                         break;
4520
4521                 case REW_SER_MONS:
4522                         msg_format(_("%sは褒美として使いをよこした!", "%s rewards you with a servant!"),chaos_patrons[p_ptr->chaos_patron]);
4523
4524                         if (!summon_specific(-1, p_ptr->y, p_ptr->x, dun_level, 0, PM_FORCE_PET, '\0'))
4525                                 msg_print(_("何も現れなかった...", "Nobody ever turns up..."));
4526                         else
4527                                 reward = _("モンスターがペットになった。", "a servant");
4528
4529                         break;
4530
4531                 case REW_SER_UNDE:
4532                         msg_format(_("%sは褒美としてアンデッドの使いをよこした。", "%s rewards you with an undead servant!"),chaos_patrons[p_ptr->chaos_patron]);
4533
4534                         if (!summon_specific(-1, p_ptr->y, p_ptr->x, dun_level, SUMMON_UNDEAD, PM_FORCE_PET, '\0'))
4535                                 msg_print(_("何も現れなかった...", "Nobody ever turns up..."));
4536                         else
4537                                 reward = _("アンデッドがペットになった。", "an undead servant");
4538
4539                         break;
4540
4541                 default:
4542                         msg_format(_("%sの声がどもった:", "The voice of %s stammers:"),
4543
4544                                 chaos_patrons[p_ptr->chaos_patron]);
4545                         msg_format(_("「あー、あー、答えは %d/%d。質問は何?」", "'Uh... uh... the answer's %d/%d, what's the question?'"), type, effect);
4546
4547         }
4548         }
4549         if (reward)
4550         {
4551                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format(_("パトロンの報酬で%s", "The patron rewards you with %s."), reward));
4552         }
4553 }
4554
4555
4556 /*
4557  * XAngband: determine if a given location is "interesting"
4558  * based on target_set_accept function.
4559  */
4560 static bool tgt_pt_accept(POSITION y, POSITION x)
4561 {
4562         cave_type *c_ptr;
4563
4564         /* Bounds */
4565         if (!(in_bounds(y, x))) return (FALSE);
4566
4567         /* Player grid is always interesting */
4568         if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
4569
4570         /* Handle hallucination */
4571         if (p_ptr->image) return (FALSE);
4572
4573         /* Examine the grid */
4574         c_ptr = &cave[y][x];
4575
4576         /* Interesting memorized features */
4577         if (c_ptr->info & (CAVE_MARK))
4578         {
4579                 /* Notice stairs */
4580                 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
4581                 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
4582
4583                 /* Notice quest features */
4584                 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
4585                 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
4586         }
4587
4588         return (FALSE);
4589 }
4590
4591
4592 /*
4593  * XAngband: Prepare the "temp" array for "tget_pt"
4594  * based on target_set_prepare funciton.
4595  */
4596 static void tgt_pt_prepare(void)
4597 {
4598         POSITION y, x;
4599
4600         /* Reset "temp" array */
4601         temp_n = 0;
4602
4603         if (!expand_list) return;
4604
4605         /* Scan the current panel */
4606         for (y = 1; y < cur_hgt; y++)
4607         {
4608                 for (x = 1; x < cur_wid; x++)
4609                 {
4610                         /* Require "interesting" contents */
4611                         if (!tgt_pt_accept(y, x)) continue;
4612
4613                         /* Save the location */
4614                         temp_x[temp_n] = x;
4615                         temp_y[temp_n] = y;
4616                         temp_n++;
4617                 }
4618         }
4619
4620         /* Target the nearest monster for shooting */
4621         ang_sort_comp = ang_sort_comp_distance;
4622         ang_sort_swap = ang_sort_swap_distance;
4623
4624         /* Sort the positions */
4625         ang_sort(temp_x, temp_y, temp_n);
4626 }
4627
4628 /*
4629  * old -- from PsiAngband.
4630  */
4631 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
4632 {
4633         char ch = 0;
4634         int d, n = 0;
4635         POSITION x, y;
4636         bool success = FALSE;
4637
4638         TERM_LEN wid, hgt;
4639
4640         get_screen_size(&wid, &hgt);
4641
4642         x = p_ptr->x;
4643         y = p_ptr->y;
4644
4645         if (expand_list) 
4646         {
4647                 tgt_pt_prepare();
4648         }
4649
4650         msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
4651         msg_flag = FALSE; /* prevents "-more-" message. */
4652
4653         while ((ch != ESCAPE) && !success)
4654         {
4655                 bool move_fast = FALSE;
4656
4657                 move_cursor_relative(y, x);
4658                 ch = inkey();
4659                 switch (ch)
4660                 {
4661                 case ESCAPE:
4662                         break;
4663                 case ' ':
4664                 case 't':
4665                 case '.':
4666                 case '5':
4667                 case '0':
4668                         /* illegal place */
4669                         if (player_bold(y, x)) ch = 0;
4670
4671                         /* okay place */
4672                         else success = TRUE;
4673
4674                         break;
4675
4676                 /* XAngband: Move cursor to stairs */
4677                 case '>':
4678                 case '<':
4679                         if (expand_list && temp_n)
4680                         {
4681                                 int dx, dy;
4682                                 int cx = (panel_col_min + panel_col_max) / 2;
4683                                 int cy = (panel_row_min + panel_row_max) / 2;
4684
4685                                 n++;
4686
4687                                 /* Skip stairs which have defferent distance */
4688                                 for (; n < temp_n; ++ n)
4689                                 {
4690                                         cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
4691
4692                                         if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
4693                                             cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
4694                                         {
4695                                                 /* Found */
4696                                                 break;
4697                                         }
4698                                 }
4699
4700                                 if (n == temp_n)        /* Loop out taget list */
4701                                 {
4702                                         n = 0;
4703                                         y = p_ptr->y;
4704                                         x = p_ptr->x;
4705                                         verify_panel(); /* Move cursor to player */
4706
4707                                         p_ptr->update |= (PU_MONSTERS);
4708
4709                                         p_ptr->redraw |= (PR_MAP);
4710
4711                                         p_ptr->window |= (PW_OVERHEAD);
4712                                         handle_stuff();
4713                                 }
4714                                 else    /* move cursor to next stair and change panel */
4715                                 {
4716                                         y = temp_y[n];
4717                                         x = temp_x[n];
4718
4719                                         dy = 2 * (y - cy) / hgt;
4720                                         dx = 2 * (x - cx) / wid;
4721                                         if (dy || dx) change_panel(dy, dx);
4722                                 }
4723                         }
4724                         break;
4725
4726                 default:
4727                         /* Look up the direction */
4728                         d = get_keymap_dir(ch);
4729
4730                         /* XTRA HACK MOVEFAST */
4731                         if (isupper(ch)) move_fast = TRUE;
4732
4733                         /* Handle "direction" */
4734                         if (d)
4735                         {
4736                                 int dx = ddx[d];
4737                                 int dy = ddy[d];
4738
4739                                 /* XTRA HACK MOVEFAST */
4740                                 if (move_fast)
4741                                 {
4742                                         int mag = MIN(wid / 2, hgt / 2);
4743                                         x += dx * mag;
4744                                         y += dy * mag;
4745                                 }
4746                                 else
4747                                 {
4748                                         x += dx;
4749                                         y += dy;
4750                                 }
4751
4752                                 /* Do not move horizontally if unnecessary */
4753                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
4754                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
4755                                 {
4756                                         dx = 0;
4757                                 }
4758
4759                                 /* Do not move vertically if unnecessary */
4760                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
4761                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
4762                                 {
4763                                         dy = 0;
4764                                 }
4765
4766                                 /* Apply the motion */
4767                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
4768                                          (x >= panel_col_min + wid) || (x < panel_col_min))
4769                                 {
4770                                         /* if (change_panel(dy, dx)) target_set_prepare(mode); */
4771                                         change_panel(dy, dx);
4772                                 }
4773
4774                                 /* Slide into legality */
4775                                 if (x >= cur_wid-1) x = cur_wid - 2;
4776                                 else if (x <= 0) x = 1;
4777
4778                                 /* Slide into legality */
4779                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
4780                                 else if (y <= 0) y = 1;
4781
4782                         }
4783                         break;
4784                 }
4785         }
4786
4787         /* Clear the top line */
4788         prt("", 0, 0);
4789
4790         /* Recenter the map around the player */
4791         verify_panel();
4792
4793         p_ptr->update |= (PU_MONSTERS);
4794
4795         p_ptr->redraw |= (PR_MAP);
4796
4797         p_ptr->window |= (PW_OVERHEAD);
4798         handle_stuff();
4799
4800         *x_ptr = x;
4801         *y_ptr = y;
4802         return success;
4803 }
4804
4805
4806 bool get_hack_dir(DIRECTION *dp)
4807 {
4808         DIRECTION dir;
4809         concptr    p;
4810         char    command;
4811
4812         (*dp) = 0;
4813
4814         /* Global direction */
4815         dir = 0;
4816
4817         /* (No auto-targeting) */
4818
4819         /* Ask until satisfied */
4820         while (!dir)
4821         {
4822                 /* Choose a prompt */
4823                 if (!target_okay())
4824                 {
4825                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
4826                 }
4827                 else
4828                 {
4829                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
4830                 }
4831
4832                 /* Get a command (or Cancel) */
4833                 if (!get_com(p, &command, TRUE)) break;
4834
4835                 if (use_menu)
4836                 {
4837                         if (command == '\r') command = 't';
4838                 }  
4839
4840                 /* Convert various keys to "standard" keys */
4841                 switch (command)
4842                 {
4843                         /* Use current target */
4844                         case 'T':
4845                         case 't':
4846                         case '.':
4847                         case '5':
4848                         case '0':
4849                         {
4850                                 dir = 5;
4851                                 break;
4852                         }
4853
4854                         /* Set new target */
4855                         case '*':
4856                         case ' ':
4857                         case '\r':
4858                         {
4859                                 if (target_set(TARGET_KILL)) dir = 5;
4860                                 break;
4861                         }
4862
4863                         default:
4864                         {
4865                                 /* Look up the direction */
4866                                 dir = get_keymap_dir(command);
4867
4868                                 break;
4869                         }
4870                 }
4871
4872                 /* Verify requested targets */
4873                 if ((dir == 5) && !target_okay()) dir = 0;
4874
4875                 /* Error */
4876                 if (!dir) bell();
4877         }
4878
4879         /* No direction */
4880         if (!dir) return (FALSE);
4881
4882         /* Save the direction */
4883         command_dir = dir;
4884
4885         /* Check for confusion */
4886         if (p_ptr->confused)
4887         {
4888                 /* Random direction */
4889                 dir = ddd[randint0(8)];
4890         }
4891
4892         /* Notice confusion */
4893         if (command_dir != dir)
4894         {
4895                 /* Warn the user */
4896                 msg_print(_("あなたは混乱している。", "You are confused."));
4897         }
4898
4899         /* Save direction */
4900         (*dp) = dir;
4901
4902         /* A "valid" direction was entered */
4903         return (TRUE);
4904 }
4905
4906
4907 /*!
4908  * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
4909  * @param sval 射撃武器のアイテム副分類ID 
4910  * @return 消費する基本エネルギー
4911  */
4912 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
4913 {
4914         ENERGY energy = 10000;
4915
4916         /* Analyze the launcher */
4917         switch (sval)
4918         {
4919                 /* Sling and ammo */
4920                 case SV_SLING:
4921                 {
4922                         energy = 8000;
4923                         break;
4924                 }
4925
4926                 /* Short Bow and Arrow */
4927                 case SV_SHORT_BOW:
4928                 {
4929                         energy = 10000;
4930                         break;
4931                 }
4932
4933                 /* Long Bow and Arrow */
4934                 case SV_LONG_BOW:
4935                 {
4936                         energy = 10000;
4937                         break;
4938                 }
4939
4940                 /* Bow of irresponsiblity and Arrow */
4941                 case SV_NAMAKE_BOW:
4942                 {
4943                         energy = 7777;
4944                         break;
4945                 }
4946
4947                 /* Light Crossbow and Bolt */
4948                 case SV_LIGHT_XBOW:
4949                 {
4950                         energy = 12000;
4951                         break;
4952                 }
4953
4954                 /* Heavy Crossbow and Bolt */
4955                 case SV_HEAVY_XBOW:
4956                 {
4957                         energy = 13333;
4958                         break;
4959                 }
4960         }
4961
4962         return (energy);
4963 }
4964
4965
4966 /*
4967  * Return bow tmul
4968  */
4969 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
4970 {
4971         int tmul = 0;
4972
4973         /* Analyze the launcher */
4974         switch (sval)
4975         {
4976                 /* Sling and ammo */
4977                 case SV_SLING:
4978                 {
4979                         tmul = 2;
4980                         break;
4981                 }
4982
4983                 /* Short Bow and Arrow */
4984                 case SV_SHORT_BOW:
4985                 {
4986                         tmul = 2;
4987                         break;
4988                 }
4989
4990                 /* Long Bow and Arrow */
4991                 case SV_LONG_BOW:
4992                 {
4993                         tmul = 3;
4994                         break;
4995                 }
4996
4997                 /* Bow of irresponsiblity and Arrow */
4998                 case SV_NAMAKE_BOW:
4999                 {
5000                         tmul = 3;
5001                         break;
5002                 }
5003
5004                 /* Light Crossbow and Bolt */
5005                 case SV_LIGHT_XBOW:
5006                 {
5007                         tmul = 3;
5008                         break;
5009                 }
5010
5011                 /* Heavy Crossbow and Bolt */
5012                 case SV_HEAVY_XBOW:
5013                 {
5014                         tmul = 4;
5015                         break;
5016                 }
5017         }
5018
5019         return (tmul);
5020 }
5021
5022
5023 /*
5024  * Display a rumor and apply its effects
5025  */
5026
5027 IDX rumor_num(char *zz, IDX max_idx)
5028 {
5029         if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
5030         return (IDX)atoi(zz);
5031 }
5032
5033 concptr rumor_bind_name(char *base, concptr fullname)
5034 {
5035         char *s, *v;
5036
5037         s = strstr(base, "{Name}");
5038         if (s)
5039         {
5040                 s[0] = '\0';
5041                 v = format("%s%s%s", base, fullname, (s + 6));
5042         }
5043         else
5044         {
5045                 v = base;
5046         }
5047
5048         return v;
5049 }
5050
5051 void display_rumor(bool ex)
5052 {
5053         errr err;
5054         int section = 0;
5055         char Rumor[1024];
5056
5057         if (ex)
5058         {
5059                 if (randint0(3) == 0) section = 1;
5060         }
5061
5062         err = _(get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10),
5063                         get_rnd_line("rumors.txt", section, Rumor));
5064         if (err) strcpy(Rumor, _("嘘の噂もある。", "Some rumors are wrong."));
5065
5066         err = TRUE;
5067
5068         if (strncmp(Rumor, "R:", 2) == 0)
5069         {
5070                 char *zz[4];
5071                 concptr rumor_msg = NULL;
5072                 concptr rumor_eff_format = NULL;
5073                 char fullname[1024] = "";
5074
5075                 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
5076                 {
5077                         if (strcmp(zz[0], "ARTIFACT") == 0)
5078                         {
5079                                 IDX a_idx, k_idx;
5080                                 object_type forge;
5081                                 object_type *q_ptr = &forge;
5082                                 artifact_type *a_ptr;
5083
5084                                 while (1)
5085                                 {
5086                                         a_idx = rumor_num(zz[1], max_a_idx);
5087
5088                                         a_ptr = &a_info[a_idx];
5089                                         if (a_ptr->name) break;
5090                                 }
5091
5092                                 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
5093                                 object_prep(q_ptr, k_idx);
5094                                 q_ptr->name1 = a_idx;
5095                                 q_ptr->ident = IDENT_STORE;
5096                                 object_desc(fullname, q_ptr, OD_NAME_ONLY);
5097                         }
5098                         else if  (strcmp(zz[0], "MONSTER") == 0)
5099                         {
5100                                 MONRACE_IDX r_idx;
5101                                 monster_race *r_ptr;
5102
5103                                 while(1)
5104                                 {
5105                                         r_idx = rumor_num(zz[1], max_r_idx);
5106                                         r_ptr = &r_info[r_idx];
5107                                         if (r_ptr->name) break;
5108                                 }
5109
5110                                 strcpy(fullname, r_name + r_ptr->name);
5111
5112                                 /* Remember this monster */
5113                                 if (!r_ptr->r_sights)
5114                                 {
5115                                         r_ptr->r_sights++;
5116                                 }
5117                         }
5118                         else if (strcmp(zz[0], "DUNGEON") == 0)
5119                         {
5120                                 DUNGEON_IDX d_idx;
5121                                 dungeon_info_type *d_ptr;
5122
5123                                 while (1)
5124                                 {
5125                                         d_idx = rumor_num(zz[1], max_d_idx);
5126                                         d_ptr = &d_info[d_idx];
5127                                         if (d_ptr->name) break;
5128                                 }
5129
5130                                 strcpy(fullname, d_name + d_ptr->name);
5131
5132                                 if (!max_dlv[d_idx])
5133                                 {
5134                                         max_dlv[d_idx] = d_ptr->mindepth;
5135                                         rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
5136                                 }
5137                         }
5138                         else if  (strcmp(zz[0], "TOWN") == 0)
5139                         {
5140                                 IDX t_idx;
5141                                 s32b visit;
5142
5143                                 while(1)
5144                                 {
5145                                         t_idx = rumor_num(zz[1], NO_TOWN);
5146                                         if (town[t_idx].name) break;
5147                                 }
5148
5149                                 strcpy(fullname, town[t_idx].name);
5150
5151                                 visit = (1L << (t_idx - 1));
5152                                 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
5153                                 {
5154                                         p_ptr->visit |= visit;
5155                                         rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
5156                                 }
5157                         }
5158
5159                         rumor_msg = rumor_bind_name(zz[2], fullname);
5160                         msg_print(rumor_msg);
5161                         if (rumor_eff_format)
5162                         {
5163                                 msg_print(NULL);
5164                                 msg_format(rumor_eff_format, fullname);
5165                         }
5166                         err = FALSE;
5167                 }
5168         /* error */
5169         if (err) msg_print(_("この情報は間違っている。", "This information is wrong."));
5170         }
5171                         else
5172         {
5173                 msg_format("%s", Rumor);
5174         }
5175 }