OSDN Git Service

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