OSDN Git Service

[Refactor] #37353 gain_level_reward() を新規ファイル patron.c/h へ移動し、インクルード整理。 / Move gain_l...
[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 "monster.h"
18 #include "monsterrace-hook.h"
19 #include "objectkind-hook.h"
20 #include "sort.h"
21 #include "projection.h"
22 #include "spells-summon.h"
23 #include "patron.h"
24
25 #define REWARD_CHANCE 10
26
27
28 /*!
29  * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
30  * Advance experience levels and print experience
31  * @return なし
32  */
33 void check_experience(void)
34 {
35         bool level_reward = FALSE;
36         bool level_mutation = FALSE;
37         bool level_inc_stat = FALSE;
38         bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
39         PLAYER_LEVEL old_lev = p_ptr->lev;
40
41         /* Hack -- lower limit */
42         if (p_ptr->exp < 0) p_ptr->exp = 0;
43         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
44         if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
45
46         /* Hack -- upper limit */
47         if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
48         if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
49         if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
50
51         /* Hack -- maintain "max" experience */
52         if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
53
54         /* Hack -- maintain "max max" experience */
55         if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
56
57         /* Redraw experience */
58         p_ptr->redraw |= (PR_EXP);
59         handle_stuff();
60
61
62         /* Lose levels while possible */
63         while ((p_ptr->lev > 1) &&
64                (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
65         {
66                 /* Lose a level */
67                 p_ptr->lev--;
68                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
69                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
70                 p_ptr->window |= (PW_PLAYER);
71                 handle_stuff();
72         }
73
74
75         /* Gain levels while possible */
76         while ((p_ptr->lev < PY_MAX_LEVEL) &&
77                (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
78         {
79                 /* Gain a level */
80                 p_ptr->lev++;
81
82                 /* Save the highest level */
83                 if (p_ptr->lev > p_ptr->max_plv)
84                 {
85                         p_ptr->max_plv = p_ptr->lev;
86
87                         if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
88                             (p_ptr->muta2 & MUT2_CHAOS_GIFT))
89                         {
90                                 level_reward = TRUE;
91                         }
92                         if (p_ptr->prace == RACE_BEASTMAN)
93                         {
94                                 if (one_in_(5)) level_mutation = TRUE;
95                         }
96                         level_inc_stat = TRUE;
97
98                         do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
99                 }
100
101                 sound(SOUND_LEVEL);
102
103                 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
104
105                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
106                 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
107                 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
108
109                 /* HPとMPの上昇量を表示 */
110                 level_up = 1;
111                 handle_stuff();
112
113                 level_up = 0;
114
115                 if (level_inc_stat)
116                 {
117                         if(!(p_ptr->max_plv % 10))
118                         {
119                                 int choice;
120                                 screen_save();
121                                 while(1)
122                                 {
123                                         int n;
124                                         char tmp[32];
125
126                                         cnv_stat(p_ptr->stat_max[0], tmp);
127                                         prt(format(_("        a) 腕力 (現在値 %s)", "        a) Str (cur %s)"), tmp), 2, 14);
128                                         cnv_stat(p_ptr->stat_max[1], tmp);
129                                         prt(format(_("        b) 知能 (現在値 %s)", "        a) Int (cur %s)"), tmp), 3, 14);
130                                         cnv_stat(p_ptr->stat_max[2], tmp);
131                                         prt(format(_("        c) 賢さ (現在値 %s)", "        a) Wis (cur %s)"), tmp), 4, 14);
132                                         cnv_stat(p_ptr->stat_max[3], tmp);
133                                         prt(format(_("        d) 器用 (現在値 %s)", "        a) Dex (cur %s)"), tmp), 5, 14);
134                                         cnv_stat(p_ptr->stat_max[4], tmp);
135                                         prt(format(_("        e) 耐久 (現在値 %s)", "        a) Con (cur %s)"), tmp), 6, 14);
136                                         cnv_stat(p_ptr->stat_max[5], tmp);
137                                         prt(format(_("        f) 魅力 (現在値 %s)", "        a) Chr (cur %s)"), tmp), 7, 14);
138
139                                         prt("", 8, 14);
140                                         prt(_("        どの能力値を上げますか?", "        Which stat do you want to raise?"), 1, 14);
141
142                                         while(1)
143                                         {
144                                                 choice = inkey();
145                                                 if ((choice >= 'a') && (choice <= 'f')) break;
146                                         }
147                                         for(n = 0; n < A_MAX; n++)
148                                                 if (n != choice - 'a')
149                                                         prt("",n+2,14);
150                                         if (get_check(_("よろしいですか?", "Are you sure? "))) break;
151                                 }
152                                 do_inc_stat(choice - 'a');
153                                 screen_load();
154                         }
155                         else if(!(p_ptr->max_plv % 2))
156                                 do_inc_stat(randint0(6));
157                 }
158
159                 if (level_mutation)
160                 {
161                         msg_print(_("あなたは変わった気がする...", "You feel different..."));
162                         (void)gain_random_mutation(0);
163                         level_mutation = FALSE;
164                 }
165
166                 /*
167                  * 報酬でレベルが上ると再帰的に check_experience() が
168                  * 呼ばれるので順番を最後にする。
169                  */
170                 if (level_reward)
171                 {
172                         gain_level_reward(0);
173                         level_reward = FALSE;
174                 }
175
176                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
177                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
178                 p_ptr->window |= (PW_PLAYER | PW_SPELL);
179                 handle_stuff();
180         }
181
182         /* Load an autopick preference file */
183         if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
184 }
185
186
187
188 /*!
189  * @brief クエストを達成状態にする /
190  * @param quest_num 達成状態にしたいクエストのID
191  * @return なし
192  */
193 void complete_quest(QUEST_IDX quest_num)
194 {
195         quest_type* const q_ptr = &quest[quest_num];
196
197         switch (q_ptr->type)
198         {
199         case QUEST_TYPE_RANDOM:
200                 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
201                 break;
202         default:
203                 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
204                 break;
205         }
206
207         q_ptr->status = QUEST_STATUS_COMPLETED;
208         q_ptr->complev = p_ptr->lev;
209         update_playtime();
210         q_ptr->comptime = playtime;
211
212         if (!(q_ptr->flags & QUEST_FLAG_SILENT))
213         {
214                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
215                 msg_print(_("クエストを達成した!", "You just completed your quest!"));
216                 msg_print(NULL);
217         }
218 }
219
220 /*!
221  * @brief 現在フロアに残っている敵モンスターの数を返す /
222  * @return 現在の敵モンスターの数
223  */
224 static MONSTER_NUMBER count_all_hostile_monsters(void)
225 {
226         POSITION x, y;
227         MONSTER_NUMBER number_mon = 0;
228
229         for (x = 0; x < cur_wid; ++ x)
230         {
231                 for (y = 0; y < cur_hgt; ++ y)
232                 {
233                         MONSTER_IDX m_idx = cave[y][x].m_idx;
234
235                         if (m_idx > 0 && is_hostile(&m_list[m_idx]))
236                         {
237                                 ++number_mon;
238                         }
239                 }
240         }
241
242         return number_mon;
243 }
244
245 /*!
246  * @brief 特定の敵を倒した際にクエスト達成処理 /
247  * Check for "Quest" completion when a quest monster is killed or charmed.
248  * @param m_ptr 撃破したモンスターの構造体参照ポインタ
249  * @return なし
250  */
251 void check_quest_completion(monster_type *m_ptr)
252 {
253         POSITION y, x;
254         QUEST_IDX quest_num;
255
256         bool create_stairs = FALSE;
257         bool reward = FALSE;
258
259         object_type forge;
260         object_type *o_ptr;
261
262         y = m_ptr->fy;
263         x = m_ptr->fx;
264
265         /* Inside a quest */
266         quest_num = p_ptr->inside_quest;
267
268         /* Search for an active quest on this dungeon level */
269         if (!quest_num)
270         {
271                 QUEST_IDX i;
272
273                 for (i = max_q_idx - 1; i > 0; i--)
274                 {
275                         quest_type* const q_ptr = &quest[i];
276                         
277                         /* Quest is not active */
278                         if (q_ptr->status != QUEST_STATUS_TAKEN)
279                                 continue;
280
281                         /* Quest is not a dungeon quest */
282                         if (q_ptr->flags & QUEST_FLAG_PRESET)
283                                 continue;
284
285                         /* Quest is not on this level */
286                         if ((q_ptr->level != dun_level) &&
287                             (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
288                                 continue;
289
290                         /* Not a "kill monster" quest */
291                         if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
292                             (q_ptr->type == QUEST_TYPE_FIND_EXIT))
293                                 continue;
294
295                         /* Interesting quest */
296                         if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
297                             (q_ptr->type == QUEST_TYPE_TOWER) ||
298                             (q_ptr->type == QUEST_TYPE_KILL_ALL))
299                                 break;
300
301                         /* Interesting quest */
302                         if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
303                              (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
304                              (q_ptr->type == QUEST_TYPE_RANDOM)) &&
305                              (q_ptr->r_idx == m_ptr->r_idx))
306                                 break;
307                 }
308
309                 quest_num = i;
310         }
311
312         /* Handle the current quest */
313         if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
314         {
315                 /* Current quest */
316                 quest_type* const q_ptr = &quest[quest_num];
317
318                 switch (q_ptr->type)
319                 {
320                         case QUEST_TYPE_KILL_NUMBER:
321                         {
322                                 q_ptr->cur_num++;
323
324                                 if (q_ptr->cur_num >= q_ptr->num_mon)
325                                 {
326                                         complete_quest(quest_num);
327
328                                         q_ptr->cur_num = 0;
329                                 }
330                                 break;
331                         }
332                         case QUEST_TYPE_KILL_ALL:
333                         {
334                                 if (!is_hostile(m_ptr)) break;
335
336                                 if (count_all_hostile_monsters() == 1)
337                                 {
338                                         if (q_ptr->flags & QUEST_FLAG_SILENT)
339                                         {
340                                                 q_ptr->status = QUEST_STATUS_FINISHED;
341                                         }
342                                         else
343                                         {
344                                                 complete_quest(quest_num);
345                                         }
346                                 }
347                                 break;
348                         }
349                         case QUEST_TYPE_KILL_LEVEL:
350                         case QUEST_TYPE_RANDOM:
351                         {
352                                 /* Only count valid monsters */
353                                 if (q_ptr->r_idx != m_ptr->r_idx)
354                                         break;
355
356                                 q_ptr->cur_num++;
357
358                                 if (q_ptr->cur_num >= q_ptr->max_num)
359                                 {
360                                         complete_quest(quest_num);
361
362                                         if (!(q_ptr->flags & QUEST_FLAG_PRESET))
363                                         {
364                                                 create_stairs = TRUE;
365                                                 p_ptr->inside_quest = 0;
366                                         }
367
368                                         /* Finish the two main quests without rewarding */
369                                         if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
370                                         {
371                                                 q_ptr->status = QUEST_STATUS_FINISHED;
372                                         }
373
374                                         if (q_ptr->type == QUEST_TYPE_RANDOM)
375                                         {
376                                                 reward = TRUE;
377                                                 q_ptr->status = QUEST_STATUS_FINISHED;
378                                         }
379                                 }
380                                 break;
381                         }
382                         case QUEST_TYPE_KILL_ANY_LEVEL:
383                         {
384                                 q_ptr->cur_num++;
385                                 if (q_ptr->cur_num >= q_ptr->max_num)
386                                 {
387                                         complete_quest(quest_num);
388                                         q_ptr->cur_num = 0;
389                                 }
390                                 break;
391                         }
392                         case QUEST_TYPE_TOWER:
393                         {
394                                 if (!is_hostile(m_ptr)) break;
395
396                                 if (count_all_hostile_monsters() == 1)
397                                 {
398                                         q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
399
400                                         if((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
401                                            (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
402                                            (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
403                                         {
404
405                                                 complete_quest(QUEST_TOWER1);
406                                         }
407                                 }
408                                 break;
409                         }
410                 }
411         }
412
413         /* Create a magical staircase */
414         if (create_stairs)
415         {
416                 POSITION ny, nx;
417
418                 /* Stagger around */
419                 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT) )
420                 {
421                         /* Pick a location */
422                         scatter(&ny, &nx, y, x, 1, 0);
423
424                         /* Stagger */
425                         y = ny; x = nx;
426                 }
427
428                 /* Explain the staircase */
429                 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
430
431                 /* Create stairs down */
432                 cave_set_feat(y, x, feat_down_stair);
433
434                 /* Remember to update everything */
435                 p_ptr->update |= (PU_FLOW);
436         }
437
438         /*
439          * Drop quest reward
440          */
441         if (reward)
442         {
443                 int i;
444
445                 for (i = 0; i < (dun_level / 15)+1; i++)
446                 {
447                         o_ptr = &forge;
448                         object_wipe(o_ptr);
449
450                         /* Make a great object */
451                         make_object(o_ptr, AM_GOOD | AM_GREAT);
452                         (void)drop_near(o_ptr, -1, y, x);
453                 }
454         }
455 }
456
457 /*!
458  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
459  * Check for "Quest" completion when a quest monster is killed or charmed.
460  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
461  * @return なし
462  */
463 void check_find_art_quest_completion(object_type *o_ptr)
464 {
465         QUEST_IDX i;
466         /* Check if completed a quest */
467         for (i = 0; i < max_q_idx; i++)
468         {
469                 if((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
470                         (quest[i].status == QUEST_STATUS_TAKEN) &&
471                         (quest[i].k_idx == o_ptr->name1))
472                 {
473                         complete_quest(i);
474                 }
475         }
476 }
477
478
479 /*!
480  * @brief モンスターを撃破した際の述語メッセージを返す /
481  * Return monster death string
482  * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
483  * @return 撃破されたモンスターの述語
484  */
485 concptr extract_note_dies(MONRACE_IDX r_idx)
486 {
487         monster_race *r_ptr = &r_info[r_idx];
488         /* Some monsters get "destroyed" */
489         if (!monster_living(r_idx))
490         {
491                 int i;
492
493                 for (i = 0; i < 4; i++)
494                 {
495                         if (r_ptr->blow[i].method == RBM_EXPLODE)
496                         {
497                                 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
498                         }
499                 }
500                 return _("を倒した。", " is destroyed.");
501         }
502
503         /* Assume a default death */
504         return _("は死んだ。", " dies.");
505 }
506
507
508 /*!
509  * @brief モンスターに与えたダメージの修正処理 /
510  * Modify the physical damage done to the monster.
511  * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
512  * @param dam ダメージ基本値
513  * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
514  * @return 修正を行った結果のダメージ量
515  * @details
516  * <pre>
517  * (for example when it's invulnerable or shielded)
518  * ToDo: Accept a damage-type to calculate the modified damage from
519  * things like fire, frost, lightning, poison, ... attacks.
520  * "type" is not yet used and should be 0.
521  * </pre>
522  */
523 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
524 {
525         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
526
527         if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
528         {
529                 dam /= 100;
530                 if ((dam == 0) && one_in_(3)) dam = 1;
531         }
532
533         if (MON_INVULNER(m_ptr))
534         {
535                 if (is_psy_spear)
536                 {
537                         if (!p_ptr->blind && is_seen(m_ptr))
538                         {
539                                 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
540                         }
541                 }
542                 else if (!one_in_(PENETRATE_INVULNERABILITY))
543                 {
544                         return (0);
545                 }
546         }
547         return (dam);
548 }
549
550
551 /*!
552  * @brief モンスターに与えたダメージを元に経験値を加算する /
553  * Calculate experience point to be get
554  * @param dam 与えたダメージ量
555  * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
556  * @return なし
557  * @details
558  * <pre>
559  * Even the 64 bit operation is not big enough to avoid overflaw
560  * unless we carefully choose orders of multiplication and division.
561  * Get the coefficient first, and multiply (potentially huge) base
562  * experience point of a monster later.
563  * </pre>
564  */
565 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
566 {
567         monster_race *r_ptr = &r_info[m_ptr->r_idx];
568
569         s32b new_exp;
570         u32b new_exp_frac;
571         s32b div_h;
572         u32b div_l;
573
574         if (!m_ptr->r_idx) return;
575         if (is_pet(m_ptr) || p_ptr->inside_battle) return;
576
577         /*
578          * - Ratio of monster's level to player's level effects
579          * - Varying speed effects
580          * - Get a fraction in proportion of damage point
581          */
582         new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
583         new_exp_frac = 0;
584         div_h = 0L;
585         div_l = (p_ptr->max_plv+2) * SPEED_TO_ENERGY(r_ptr->speed);
586
587         /* Use (average maxhp * 2) as a denominator */
588         if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
589                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
590         else
591                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
592
593         /* Special penalty in the wilderness */
594         if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
595                 s64b_mul(&div_h, &div_l, 0, 5);
596
597         /* Do division first to prevent overflaw */
598         s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
599
600         /* Special penalty for mutiply-monster */
601         if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
602         {
603                 int monnum_penarty = r_ptr->r_akills / 400;
604                 if (monnum_penarty > 8) monnum_penarty = 8;
605
606                 while (monnum_penarty--)
607                 {
608                         /* Divide by 4 */
609                         s64b_RSHIFT(new_exp, new_exp_frac, 2);
610                 }
611         }
612         
613         /* Special penalty for rest_and_shoot exp scum */
614         if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
615         {
616                 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
617                 if (over_damage > 32) over_damage = 32;
618
619                 while (over_damage--)
620                 {
621                         /* 9/10 for once */
622                         s64b_mul(&new_exp, &new_exp_frac, 0, 9);
623                         s64b_div(&new_exp, &new_exp_frac, 0, 10);
624                 }
625         }
626
627         /* Finally multiply base experience point of the monster */
628         s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
629
630         /* Gain experience */
631         gain_exp_64(new_exp, new_exp_frac);
632 }
633
634
635 /*!
636  * @brief モンスターのHPをダメージに応じて減算する /
637  * Decreases monsters hit points, handling monster death.
638  * @param dam 与えたダメージ量
639  * @param m_idx ダメージを与えたモンスターのID
640  * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
641  * @param note モンスターが倒された際の特別なメッセージ述語
642  * @return なし
643  * @details
644  * <pre>
645  * We return TRUE if the monster has been killed (and deleted).
646  * We announce monster death (using an optional "death message"
647  * if given, and a otherwise a generic killed/destroyed message).
648  * Only "physical attacks" can induce the "You have slain" message.
649  * Missile and Spell attacks will induce the "dies" message, or
650  * various "specialized" messages.  Note that "You have destroyed"
651  * and "is destroyed" are synonyms for "You have slain" and "dies".
652  * Hack -- unseen monsters yield "You have killed it." message.
653  * Added fear (DGK) and check whether to print fear messages -CWS
654  * Made name, sex, and capitalization generic -BEN-
655  * As always, the "ghost" processing is a total hack.
656  * Hack -- we "delay" fear messages by passing around a "fear" flag.
657  * Consider decreasing monster experience over time, say,
658  * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
659  * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
660  * monster worth more than subsequent monsters.  This would also need
661  * to induce changes in the monster recall code.
662  * </pre>
663  */
664 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
665 {
666         monster_type *m_ptr = &m_list[m_idx];
667         monster_race *r_ptr = &r_info[m_ptr->r_idx];
668         monster_type exp_mon;
669
670         /* Innocent until proven otherwise */
671         bool innocent = TRUE, thief = FALSE;
672         int i;
673         HIT_POINT expdam;
674
675         (void)COPY(&exp_mon, m_ptr, monster_type);
676         
677         expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
678
679         get_exp_from_mon(expdam, &exp_mon);
680
681         /* Genocided by chaos patron */
682         if (!m_ptr->r_idx) m_idx = 0;
683         
684         /* Redraw (later) if needed */
685         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
686         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
687
688         (void)set_monster_csleep(m_idx, 0);
689
690         /* Hack - Cancel any special player stealth magics. -LM- */
691         if (p_ptr->special_defense & NINJA_S_STEALTH)
692         {
693                 set_superstealth(FALSE);
694         }
695
696         /* Genocided by chaos patron */
697         if (!m_idx) return TRUE;
698         
699         m_ptr->hp -= dam;
700         m_ptr->dealt_damage += dam;
701
702         if(m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
703
704         if (p_ptr->wizard)
705         {
706                 msg_format( _("合計%d/%dのダメージを与えた。","You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
707         }
708
709         /* It is dead now */
710         if (m_ptr->hp < 0)
711         {
712                 GAME_TEXT m_name[MAX_NLEN];
713
714                 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
715                 {
716                         /* You might have unmasked Tanuki first time */
717                         r_ptr = &r_info[m_ptr->r_idx];
718                         m_ptr->ap_r_idx = m_ptr->r_idx;
719                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
720                 }
721
722                 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
723                 {
724                         /* You might have unmasked Chameleon first time */
725                         r_ptr = real_r_ptr(m_ptr);
726                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
727                 }
728
729                 if (!(m_ptr->smart & SM_CLONED))
730                 {
731                         /* When the player kills a Unique, it stays dead */
732                         if (r_ptr->flags1 & RF1_UNIQUE)
733                         {
734                                 r_ptr->max_num = 0;
735
736                                 /* Mega-Hack -- Banor & Lupart */
737                                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
738                                 {
739                                         r_info[MON_BANORLUPART].max_num = 0;
740                                         r_info[MON_BANORLUPART].r_pkills++;
741                                         r_info[MON_BANORLUPART].r_akills++;
742                                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
743                                 }
744                                 else if (m_ptr->r_idx == MON_BANORLUPART)
745                                 {
746                                         r_info[MON_BANOR].max_num = 0;
747                                         r_info[MON_BANOR].r_pkills++;
748                                         r_info[MON_BANOR].r_akills++;
749                                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
750                                         r_info[MON_LUPART].max_num = 0;
751                                         r_info[MON_LUPART].r_pkills++;
752                                         r_info[MON_LUPART].r_akills++;
753                                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
754                                 }
755                         }
756
757                         /* When the player kills a Nazgul, it stays dead */
758                         else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
759                 }
760
761                 /* Count all monsters killed */
762                 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
763
764                 /* Recall even invisible uniques or winners */
765                 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
766                 {
767                         /* Count kills this life */
768                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
769                         else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
770
771                         /* Count kills in all lives */
772                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
773                         else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
774
775                         /* Hack -- Auto-recall */
776                         monster_race_track(m_ptr->ap_r_idx);
777                 }
778
779                 /* Extract monster name */
780                 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
781
782                 /* Don't kill Amberites */
783                 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
784                 {
785                         int curses = 1 + randint1(3);
786                         bool stop_ty = FALSE;
787                         int count = 0;
788
789                         msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
790                         curse_equipment(100, 50);
791
792                         do
793                         {
794                                 stop_ty = activate_ty_curse(stop_ty, &count);
795                         }
796                         while (--curses);
797                 }
798
799                 if (r_ptr->flags2 & RF2_CAN_SPEAK)
800                 {
801                         char line_got[1024];
802                         if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
803                         {
804                                 msg_format("%^s %s", m_name, line_got);
805                         }
806
807 #ifdef WORLD_SCORE
808                         if (m_ptr->r_idx == MON_SERPENT)
809                         {
810                                 screen_dump = make_screen_dump();
811                         }
812 #endif
813                 }
814
815                 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
816                 {
817                         if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
818                         {
819                                 chg_virtue(V_VALOUR, -1);
820                         }
821                         else if (r_ptr->level > dun_level)
822                         {
823                                 if (randint1(10) <= (r_ptr->level - dun_level))
824                                         chg_virtue(V_VALOUR, 1);
825                         }
826                         if (r_ptr->level > 60)
827                         {
828                                 chg_virtue(V_VALOUR, 1);
829                         }
830                         if (r_ptr->level >= 2 * (p_ptr->lev+1))
831                                 chg_virtue(V_VALOUR, 2);
832                 }
833
834                 if (r_ptr->flags1 & RF1_UNIQUE)
835                 {
836                         if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
837
838                         if (r_ptr->flags3 & RF3_GOOD)
839                         {
840                                 chg_virtue(V_UNLIFE, 2);
841                                 chg_virtue(V_VITALITY, -2);
842                         }
843
844                         if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
845                 }
846
847                 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
848                 {
849                         chg_virtue(V_COMPASSION, -1);
850                 }
851
852                 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
853                         chg_virtue(V_UNLIFE, 1);
854
855                 if (r_ptr->d_char == 'A')
856                 {
857                         if (r_ptr->flags1 & RF1_UNIQUE)
858                                 chg_virtue(V_FAITH, -2);
859                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
860                         {
861                                 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
862                                 else chg_virtue(V_FAITH, 1);
863                         }
864                 }
865                 else if (r_ptr->flags3 & RF3_DEMON)
866                 {
867                         if (r_ptr->flags1 & RF1_UNIQUE)
868                                 chg_virtue(V_FAITH, 2);
869                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
870                                 chg_virtue(V_FAITH, 1);
871                 }
872
873                 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
874                         chg_virtue(V_VITALITY, 2);
875
876                 if (r_ptr->r_deaths)
877                 {
878                         if (r_ptr->flags1 & RF1_UNIQUE)
879                         {
880                                 chg_virtue(V_HONOUR, 10);
881                         }
882                         else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
883                         {
884                                 chg_virtue(V_HONOUR, 1);
885                         }
886                 }
887                 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
888                 {
889                         chg_virtue(V_VALOUR, -1);
890                 }
891
892                 for (i = 0; i < 4; i++)
893                 {
894                         if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
895
896                         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
897                                 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
898
899                                 thief = TRUE; /* Thief! */
900                 }
901
902                 /* The new law says it is illegal to live in the dungeon */
903                 if (r_ptr->level != 0) innocent = FALSE;
904
905                 if (thief)
906                 {
907                         if (r_ptr->flags1 & RF1_UNIQUE)
908                                 chg_virtue(V_JUSTICE, 3);
909                         else if (1+((r_ptr->level) / 10 + (2 * dun_level)) >= randint1(100))
910                                 chg_virtue(V_JUSTICE, 1);
911                 }
912                 else if (innocent)
913                 {
914                         chg_virtue (V_JUSTICE, -1);
915                 }
916
917                 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)))
918                 {
919                         if (one_in_(4)) chg_virtue(V_NATURE, -1);
920                 }
921
922                 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
923                 {
924                         char note_buf[160];
925                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
926                         do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
927                 }
928
929                 /* Make a sound */
930                 sound(SOUND_KILL);
931
932                 /* Death by Missile/Spell attack */
933                 if (note)
934                 {
935                         msg_format("%^s%s", m_name, note);
936                 }
937
938                 /* Death by physical attack -- invisible monster */
939                 else if (!m_ptr->ml)
940                 {
941 #ifdef JP
942                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
943                                 msg_format("せっかくだから%sを殺した。", m_name);
944                         else
945                                 msg_format("%sを殺した。", m_name);
946 #else
947                                 msg_format("You have killed %s.", m_name);
948 #endif
949
950                 }
951
952                 /* Death by Physical attack -- non-living monster */
953                 else if (!monster_living(m_ptr->r_idx))
954                 {
955                         bool explode = FALSE;
956
957                         for (i = 0; i < 4; i++)
958                         {
959                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
960                         }
961
962                         /* Special note at death */
963                         if (explode)
964                                 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
965                         else
966                         {
967 #ifdef JP
968                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
969                                         msg_format("せっかくだから%sを倒した。", m_name);
970                                 else
971                                 msg_format("%sを倒した。", m_name);
972 #else
973                                 msg_format("You have destroyed %s.", m_name);
974 #endif
975                         }
976                 }
977
978                 /* Death by Physical attack -- living monster */
979                 else
980                 {
981 #ifdef JP
982                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
983                                 msg_format("せっかくだから%sを葬り去った。", m_name);
984                         else
985                                 msg_format("%sを葬り去った。", m_name);
986 #else
987                                 msg_format("You have slain %s.", m_name);
988 #endif
989
990                 }
991                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
992                 {
993                         for (i = 0; i < MAX_KUBI; i++)
994                         {
995                                 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
996                                 {
997                                         msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
998                                         break;
999                                 }
1000                         }
1001                 }
1002
1003                 /* Generate treasure */
1004                 monster_death(m_idx, TRUE);
1005
1006                 /* Mega hack : replace IKETA to BIKETAL */
1007                 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1008                 {
1009                         POSITION dummy_y = m_ptr->fy;
1010                         POSITION dummy_x = m_ptr->fx;
1011                         BIT_FLAGS mode = 0L;
1012                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1013                         delete_monster_idx(m_idx);
1014                         if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1015                         {
1016                                 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha!  *I* am Biketal!"));
1017                         }
1018                 }
1019                 else
1020                 {
1021                         delete_monster_idx(m_idx);
1022                 }
1023
1024                 get_exp_from_mon((long)exp_mon.max_maxhp*2, &exp_mon);
1025
1026                 /* Not afraid */
1027                 (*fear) = FALSE;
1028
1029                 /* Monster is dead */
1030                 return (TRUE);
1031         }
1032
1033
1034 #ifdef ALLOW_FEAR
1035
1036         /* Mega-Hack -- Pain cancels fear */
1037         if (MON_MONFEAR(m_ptr) && (dam > 0))
1038         {
1039                 /* Cure fear */
1040                 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1041                 {
1042                         /* No more fear */
1043                         (*fear) = FALSE;
1044                 }
1045         }
1046
1047         /* Sometimes a monster gets scared by damage */
1048         if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1049         {
1050                 /* Percentage of fully healthy */
1051                 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1052
1053                 /*
1054                  * Run (sometimes) if at 10% or less of max hit points,
1055                  * or (usually) when hit for half its current hit points
1056                  */
1057                 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1058                 {
1059                         /* Hack -- note fear */
1060                         (*fear) = TRUE;
1061
1062                         /* Hack -- Add some timed fear */
1063                         (void)set_monster_monfear(m_idx, (randint1(10) +
1064                                           (((dam >= m_ptr->hp) && (percentage > 7)) ?
1065                                            20 : ((11 - percentage) * 5))));
1066                 }
1067         }
1068
1069 #endif
1070
1071         /* Not dead yet */
1072         return (FALSE);
1073 }
1074
1075
1076 /*!
1077  * @brief 現在のコンソール表示の縦横を返す。 /
1078  * Get term size and calculate screen size
1079  * @param wid_p コンソールの表示幅文字数を返す
1080  * @param hgt_p コンソールの表示行数を返す
1081  * @return なし
1082  */
1083 void get_screen_size(TERM_LEN *wid_p, TERM_LEN *hgt_p)
1084 {
1085         Term_get_size(wid_p, hgt_p);
1086         *hgt_p -= ROW_MAP + 2;
1087         *wid_p -= COL_MAP + 2;
1088         if (use_bigtile) *wid_p /= 2;
1089 }
1090
1091
1092 /*!
1093  * @brief コンソール上におけるマップ表示の左上位置を返す /
1094  * Calculates current boundaries Called below and from "do_cmd_locate()".
1095  * @return なし
1096  */
1097 void panel_bounds_center(void)
1098 {
1099         TERM_LEN wid, hgt;
1100
1101         get_screen_size(&wid, &hgt);
1102
1103         panel_row_max = panel_row_min + hgt - 1;
1104         panel_row_prt = panel_row_min - 1;
1105         panel_col_max = panel_col_min + wid - 1;
1106         panel_col_prt = panel_col_min - 13;
1107 }
1108
1109
1110 /*!
1111  * @brief コンソールのリサイズに合わせてマップを再描画する /
1112  * Map resizing whenever the main term changes size
1113  * @return なし
1114  */
1115 void resize_map(void)
1116 {
1117         /* Only if the dungeon exists */
1118         if (!character_dungeon) return;
1119         
1120         /* Mega-Hack -- no panel yet */
1121         panel_row_max = 0;
1122         panel_col_max = 0;
1123
1124         /* Reset the panels */
1125         panel_row_min = cur_hgt;
1126         panel_col_min = cur_wid;
1127                                 
1128         verify_panel();
1129
1130         p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
1131         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
1132         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1133         p_ptr->update |= (PU_MONSTERS);
1134         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
1135
1136         handle_stuff();
1137         Term_redraw();
1138
1139         /*
1140          * Waiting command;
1141          * Place the cursor on the player
1142          */
1143         if (can_save) move_cursor_relative(p_ptr->y, p_ptr->x);
1144
1145         Term_fresh();
1146 }
1147
1148 /*!
1149  * @brief コンソールを再描画する /
1150  * Redraw a term when it is resized
1151  * @return なし
1152  */
1153 void redraw_window(void)
1154 {
1155         /* Only if the dungeon exists */
1156         if (!character_dungeon) return;
1157
1158         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1159         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
1160
1161         handle_stuff();
1162         Term_redraw();
1163 }
1164
1165
1166 /*!
1167  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
1168  * @param dy 変更先のフロアY座標
1169  * @param dx 変更先のフロアX座標
1170  * Handle a request to change the current panel
1171  * Return TRUE if the panel was changed.
1172  * Also used in do_cmd_locate
1173  * @return 実際に再描画が必要だった場合TRUEを返す
1174  */
1175 bool change_panel(POSITION dy, POSITION dx)
1176 {
1177         POSITION y, x;
1178         TERM_LEN wid, hgt;
1179
1180         get_screen_size(&wid, &hgt);
1181
1182         /* Apply the motion */
1183         y = panel_row_min + dy * hgt / 2;
1184         x = panel_col_min + dx * wid / 2;
1185
1186         /* Verify the row */
1187         if (y > cur_hgt - hgt) y = cur_hgt - hgt;
1188         if (y < 0) y = 0;
1189
1190         /* Verify the col */
1191         if (x > cur_wid - wid) x = cur_wid - wid;
1192         if (x < 0) x = 0;
1193
1194         /* Handle "changes" */
1195         if ((y != panel_row_min) || (x != panel_col_min))
1196         {
1197                 /* Save the new panel info */
1198                 panel_row_min = y;
1199                 panel_col_min = x;
1200
1201                 /* Recalculate the boundaries */
1202                 panel_bounds_center();
1203
1204                 p_ptr->update |= (PU_MONSTERS);
1205                 p_ptr->redraw |= (PR_MAP);
1206                 handle_stuff();
1207
1208                 /* Success */
1209                 return (TRUE);
1210         }
1211
1212         /* No change */
1213         return (FALSE);
1214 }
1215
1216 /*!
1217  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
1218  * @param y 変更先のフロアY座標
1219  * @param x 変更先のフロアX座標
1220  * @details
1221  * Handle a request to change the current panel
1222  * Return TRUE if the panel was changed.
1223  * Also used in do_cmd_locate
1224  * @return 実際に再描画が必要だった場合TRUEを返す
1225  */
1226 static bool change_panel_xy(POSITION y, POSITION x)
1227 {
1228         POSITION dy = 0, dx = 0;
1229         TERM_LEN wid, hgt;
1230
1231         get_screen_size(&wid, &hgt);
1232
1233         if (y < panel_row_min) dy = -1;
1234         if (y > panel_row_max) dy = 1;
1235         if (x < panel_col_min) dx = -1;
1236         if (x > panel_col_max) dx = 1;
1237
1238         if (!dy && !dx) return (FALSE);
1239
1240         return change_panel(dy, dx);
1241 }
1242
1243
1244 /*!
1245  * @brief マップ描画のフォーカスを当てるべき座標を更新する
1246  * @details
1247  * Given an row (y) and col (x), this routine detects when a move
1248  * off the screen has occurred and figures new borders. -RAK-
1249  * "Update" forces a "full update" to take place.
1250  * The map is reprinted if necessary, and "TRUE" is returned.
1251  * @return 実際に再描画が必要だった場合TRUEを返す
1252  */
1253 void verify_panel(void)
1254 {
1255         POSITION y = p_ptr->y;
1256         POSITION x = p_ptr->x;
1257         TERM_LEN wid, hgt;
1258
1259         int prow_min;
1260         int pcol_min;
1261         int max_prow_min;
1262         int max_pcol_min;
1263
1264         get_screen_size(&wid, &hgt);
1265
1266         max_prow_min = cur_hgt - hgt;
1267         max_pcol_min = cur_wid - wid;
1268
1269         /* Bounds checking */
1270         if (max_prow_min < 0) max_prow_min = 0;
1271         if (max_pcol_min < 0) max_pcol_min = 0;
1272
1273                 /* Center on player */
1274         if (center_player && (center_running || !running))
1275         {
1276                 /* Center vertically */
1277                 prow_min = y - hgt / 2;
1278                 if (prow_min < 0) prow_min = 0;
1279                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
1280
1281                 /* Center horizontally */
1282                 pcol_min = x - wid / 2;
1283                 if (pcol_min < 0) pcol_min = 0;
1284                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1285         }
1286         else
1287         {
1288                 prow_min = panel_row_min;
1289                 pcol_min = panel_col_min;
1290
1291                 /* Scroll screen when 2 grids from top/bottom edge */
1292                 if (y > panel_row_max - 2)
1293                 {
1294                         while (y > prow_min + hgt-1 - 2)
1295                         {
1296                                 prow_min += (hgt / 2);
1297                         }
1298                 }
1299
1300                 if (y < panel_row_min + 2)
1301                 {
1302                         while (y < prow_min + 2)
1303                         {
1304                                 prow_min -= (hgt / 2);
1305                         }
1306                 }
1307
1308                 if (prow_min > max_prow_min) prow_min = max_prow_min;
1309                 if (prow_min < 0) prow_min = 0;
1310
1311                 /* Scroll screen when 4 grids from left/right edge */
1312                 if (x > panel_col_max - 4)
1313                 {
1314                         while (x > pcol_min + wid-1 - 4)
1315                         {
1316                                 pcol_min += (wid / 2);
1317                         }
1318                 }
1319                 
1320                 if (x < panel_col_min + 4)
1321                 {
1322                         while (x < pcol_min + 4)
1323                         {
1324                                 pcol_min -= (wid / 2);
1325                         }
1326                 }
1327
1328                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1329                 if (pcol_min < 0) pcol_min = 0;
1330         }
1331
1332         /* Check for "no change" */
1333         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
1334
1335         /* Save the new panel info */
1336         panel_row_min = prow_min;
1337         panel_col_min = pcol_min;
1338
1339         /* Hack -- optional disturb on "panel change" */
1340         if (disturb_panel && !center_player) disturb(FALSE, FALSE);
1341
1342         /* Recalculate the boundaries */
1343         panel_bounds_center();
1344
1345         p_ptr->update |= (PU_MONSTERS);
1346         p_ptr->redraw |= (PR_MAP);
1347         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1348 }
1349
1350
1351 /*
1352  * Monster health description
1353  */
1354 concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
1355 {
1356         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1357         bool living;
1358         int perc;
1359         concptr desc;
1360         concptr attitude;
1361         concptr clone;
1362
1363         /* Determine if the monster is "living" */
1364         living = monster_living(m_ptr->ap_r_idx);
1365
1366         /* Calculate a health "percentage" */
1367         perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
1368
1369         /* Healthy monsters */
1370         if (m_ptr->hp >= m_ptr->maxhp)
1371         {
1372                 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
1373         }
1374
1375         else if (perc >= 60)
1376         {
1377                 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
1378         }
1379
1380         else if (perc >= 25)
1381         {
1382                 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
1383         }
1384
1385         else if (perc >= 10)
1386         {
1387                 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
1388         }
1389
1390         else 
1391         {
1392                 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
1393         }
1394
1395         /* Need attitude information? */
1396         if (!(mode & 0x01))
1397         {
1398                 /* Full information is not needed */
1399                 attitude = "";
1400         }
1401         else if (is_pet(m_ptr))
1402         {
1403                 attitude = _(", ペット", ", pet");
1404         }
1405         else if (is_friendly(m_ptr))
1406         {
1407                 attitude = _(", 友好的", ", friendly");
1408         }
1409         else
1410         {
1411                 attitude = _("", "");
1412         }
1413
1414         /* Clone monster? */
1415         if (m_ptr->smart & SM_CLONED)
1416         {
1417                 clone = ", clone";
1418         }
1419         else
1420         {
1421                 clone = "";
1422         }
1423
1424         /* Display monster's level --- idea borrowed from ToME */
1425         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
1426         {
1427                 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
1428         }
1429         else 
1430         {
1431                 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
1432         }
1433
1434 }
1435
1436
1437
1438 /*** Targeting Code ***/
1439
1440
1441 /*
1442  * Determine is a monster makes a reasonable target
1443  *
1444  * The concept of "targeting" was stolen from "Morgul" (?)
1445  *
1446  * The player can target any location, or any "target-able" monster.
1447  *
1448  * Currently, a monster is "target_able" if it is visible, and if
1449  * the player can hit it with a projection, and the player is not
1450  * hallucinating.  This allows use of "use closest target" macros.
1451  *
1452  * Future versions may restrict the ability to target "trappers"
1453  * and "mimics", but the semantics is a little bit weird.
1454  */
1455 bool target_able(MONSTER_IDX m_idx)
1456 {
1457         monster_type *m_ptr = &m_list[m_idx];
1458
1459         /* Monster must be alive */
1460         if (!m_ptr->r_idx) return (FALSE);
1461
1462         /* Hack -- no targeting hallucinations */
1463         if (p_ptr->image) return (FALSE);
1464
1465         /* Monster must be visible */
1466         if (!m_ptr->ml) return (FALSE);
1467
1468         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
1469
1470         /* Monster must be projectable */
1471         if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
1472
1473         /* Hack -- Never target trappers */
1474         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
1475
1476         /* Assume okay */
1477         return (TRUE);
1478 }
1479
1480
1481
1482
1483 /*
1484  * Update (if necessary) and verify (if possible) the target.
1485  *
1486  * We return TRUE if the target is "okay" and FALSE otherwise.
1487  */
1488 bool target_okay(void)
1489 {
1490         /* Accept stationary targets */
1491         if (target_who < 0) return (TRUE);
1492
1493         /* Check moving targets */
1494         if (target_who > 0)
1495         {
1496                 /* Accept reasonable targets */
1497                 if (target_able(target_who))
1498                 {
1499                         monster_type *m_ptr = &m_list[target_who];
1500
1501                         /* Acquire monster location */
1502                         target_row = m_ptr->fy;
1503                         target_col = m_ptr->fx;
1504
1505                         /* Good target */
1506                         return (TRUE);
1507                 }
1508         }
1509
1510         /* Assume no target */
1511         return (FALSE);
1512 }
1513
1514
1515 /*
1516  * Sorting hook -- comp function -- by "distance to player"
1517  *
1518  * We use "u" and "v" to point to arrays of "x" and "y" positions,
1519  * and sort the arrays by double-distance to the player.
1520  */
1521 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
1522 {
1523         POSITION *x = (POSITION*)(u);
1524         POSITION *y = (POSITION*)(v);
1525
1526         POSITION da, db, kx, ky;
1527
1528         /* Absolute distance components */
1529         kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
1530         ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
1531
1532         /* Approximate Double Distance to the first point */
1533         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
1534
1535         /* Absolute distance components */
1536         kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
1537         ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
1538
1539         /* Approximate Double Distance to the first point */
1540         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
1541
1542         /* Compare the distances */
1543         return (da <= db);
1544 }
1545
1546
1547 /*
1548  * Sorting hook -- comp function -- by importance level of grids
1549  *
1550  * We use "u" and "v" to point to arrays of "x" and "y" positions,
1551  * and sort the arrays by level of monster
1552  */
1553 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
1554 {
1555         POSITION *x = (POSITION*)(u);
1556         POSITION *y = (POSITION*)(v);
1557         cave_type *ca_ptr = &cave[y[a]][x[a]];
1558         cave_type *cb_ptr = &cave[y[b]][x[b]];
1559         monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
1560         monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
1561         monster_race *ap_ra_ptr, *ap_rb_ptr;
1562
1563         /* The player grid */
1564         if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
1565         if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
1566
1567         /* Extract monster race */
1568         if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
1569         else ap_ra_ptr = NULL;
1570         if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
1571         else ap_rb_ptr = NULL;
1572
1573         if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
1574         if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
1575
1576         /* Compare two monsters */
1577         if (ap_ra_ptr && ap_rb_ptr)
1578         {
1579                 /* Unique monsters first */
1580                 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
1581                 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
1582
1583                 /* Shadowers first (あやしい影) */
1584                 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
1585                 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
1586
1587                 /* Unknown monsters first */
1588                 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
1589                 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
1590
1591                 /* Higher level monsters first (if known) */
1592                 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
1593                 {
1594                         if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
1595                         if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
1596                 }
1597
1598                 /* Sort by index if all conditions are same */
1599                 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
1600                 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
1601         }
1602
1603         /* An object get higher priority */
1604         if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
1605         if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
1606
1607         /* Priority from the terrain */
1608         if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
1609         if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
1610
1611         /* If all conditions are same, compare distance */
1612         return ang_sort_comp_distance(u, v, a, b);
1613 }
1614
1615
1616 /*
1617  * Sorting hook -- swap function -- by "distance to player"
1618  *
1619  * We use "u" and "v" to point to arrays of "x" and "y" positions,
1620  * and sort the arrays by distance to the player.
1621  */
1622 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
1623 {
1624         POSITION *x = (POSITION*)(u);
1625         POSITION *y = (POSITION*)(v);
1626
1627         POSITION temp;
1628
1629         /* Swap "x" */
1630         temp = x[a];
1631         x[a] = x[b];
1632         x[b] = temp;
1633
1634         /* Swap "y" */
1635         temp = y[a];
1636         y[a] = y[b];
1637         y[b] = temp;
1638 }
1639
1640
1641
1642 /*
1643  * Hack -- help "select" a location (see below)
1644  */
1645 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
1646 {
1647         POSITION_IDX i, v;
1648         POSITION x2, y2, x3, y3, x4, y4;
1649         POSITION_IDX b_i = -1, b_v = 9999;
1650
1651
1652         /* Scan the locations */
1653         for (i = 0; i < temp_n; i++)
1654         {
1655                 /* Point 2 */
1656                 x2 = temp_x[i];
1657                 y2 = temp_y[i];
1658
1659                 /* Directed distance */
1660                 x3 = (x2 - x1);
1661                 y3 = (y2 - y1);
1662
1663                 /* Verify quadrant */
1664                 if (dx && (x3 * dx <= 0)) continue;
1665                 if (dy && (y3 * dy <= 0)) continue;
1666
1667                 /* Absolute distance */
1668                 x4 = ABS(x3);
1669                 y4 = ABS(y3);
1670
1671                 /* Verify quadrant */
1672                 if (dy && !dx && (x4 > y4)) continue;
1673                 if (dx && !dy && (y4 > x4)) continue;
1674
1675                 /* Approximate Double Distance */
1676                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
1677
1678                 /* Penalize location */
1679
1680                 /* Track best */
1681                 if ((b_i >= 0) && (v >= b_v)) continue;
1682
1683                 /* Track best */
1684                 b_i = i; b_v = v;
1685         }
1686         return (b_i);
1687 }
1688
1689
1690 /*
1691  * Hack -- determine if a given location is "interesting"
1692  */
1693 static bool target_set_accept(POSITION y, POSITION x)
1694 {
1695         cave_type *c_ptr;
1696         OBJECT_IDX this_o_idx, next_o_idx = 0;
1697
1698         /* Bounds */
1699         if (!(in_bounds(y, x))) return (FALSE);
1700
1701         /* Player grid is always interesting */
1702         if (player_bold(y, x)) return (TRUE);
1703
1704         /* Handle hallucination */
1705         if (p_ptr->image) return (FALSE);
1706
1707         /* Examine the grid */
1708         c_ptr = &cave[y][x];
1709
1710         /* Visible monsters */
1711         if (c_ptr->m_idx)
1712         {
1713                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1714
1715                 /* Visible monsters */
1716                 if (m_ptr->ml) return (TRUE);
1717         }
1718
1719         /* Scan all objects in the grid */
1720         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1721         {
1722                 object_type *o_ptr;
1723                 o_ptr = &o_list[this_o_idx];
1724
1725                 /* Acquire next object */
1726                 next_o_idx = o_ptr->next_o_idx;
1727
1728                 /* Memorized object */
1729                 if (o_ptr->marked & OM_FOUND) return (TRUE);
1730         }
1731
1732         /* Interesting memorized features */
1733         if (c_ptr->info & (CAVE_MARK))
1734         {
1735                 /* Notice object features */
1736                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
1737
1738                 /* Feature code (applying "mimic" field) */
1739                 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
1740         }
1741
1742         return (FALSE);
1743 }
1744
1745
1746 /*
1747  * Prepare the "temp" array for "target_set"
1748  *
1749  * Return the number of target_able monsters in the set.
1750  */
1751 static void target_set_prepare(BIT_FLAGS mode)
1752 {
1753         POSITION y, x;
1754         POSITION min_hgt, max_hgt, min_wid, max_wid;
1755
1756         if (mode & TARGET_KILL)
1757         {
1758                 /* Inner range */
1759                 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
1760                 max_hgt = MIN((p_ptr->y + MAX_RANGE), cur_hgt - 1);
1761                 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
1762                 max_wid = MIN((p_ptr->x + MAX_RANGE), cur_wid - 1);
1763         }
1764         else /* not targetting */
1765         {
1766                 /* Inner panel */
1767                 min_hgt = panel_row_min;
1768                 max_hgt = panel_row_max;
1769                 min_wid = panel_col_min;
1770                 max_wid = panel_col_max;
1771         }
1772
1773         /* Reset "temp" array */
1774         temp_n = 0;
1775
1776         /* Scan the current panel */
1777         for (y = min_hgt; y <= max_hgt; y++)
1778         {
1779                 for (x = min_wid; x <= max_wid; x++)
1780                 {
1781                         cave_type *c_ptr;
1782
1783                         /* Require "interesting" contents */
1784                         if (!target_set_accept(y, x)) continue;
1785
1786                         c_ptr = &cave[y][x];
1787
1788                         /* Require target_able monsters for "TARGET_KILL" */
1789                         if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
1790
1791                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
1792
1793                         /* Save the location */
1794                         temp_x[temp_n] = x;
1795                         temp_y[temp_n] = y;
1796                         temp_n++;
1797                 }
1798         }
1799
1800         /* Set the sort hooks */
1801         if (mode & (TARGET_KILL))
1802         {
1803                 /* Target the nearest monster for shooting */
1804                 ang_sort_comp = ang_sort_comp_distance;
1805                 ang_sort_swap = ang_sort_swap_distance;
1806         }
1807         else
1808         {
1809                 /* Look important grids first in Look command */
1810                 ang_sort_comp = ang_sort_comp_importance;
1811                 ang_sort_swap = ang_sort_swap_distance;
1812         }
1813
1814         /* Sort the positions */
1815         ang_sort(temp_x, temp_y, temp_n);
1816
1817         if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
1818         {
1819                 POSITION tmp;
1820
1821                 tmp = temp_y[0];
1822                 temp_y[0] = temp_y[1];
1823                 temp_y[1] = tmp;
1824                 tmp = temp_x[0];
1825                 temp_x[0] = temp_x[1];
1826                 temp_x[1] = tmp;
1827         }
1828 }
1829
1830 void target_set_prepare_look(void){
1831         target_set_prepare(TARGET_LOOK);
1832 }
1833
1834
1835 /*
1836  * Evaluate number of kill needed to gain level
1837  */
1838 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
1839 {
1840         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1841         u32b num;
1842         s32b exp_mon, exp_adv;
1843         u32b exp_mon_frac, exp_adv_frac;
1844
1845         if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
1846         {
1847                 sprintf(buf,"**");
1848                 return;
1849         }
1850         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
1851         {
1852                 if (!p_ptr->wizard)
1853                 {
1854                         sprintf(buf,"??");
1855                         return;
1856                 }
1857         }
1858
1859
1860         /* The monster's experience point (assuming average monster speed) */
1861         exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
1862         exp_mon_frac = 0;
1863         s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
1864
1865
1866         /* Total experience value for next level */
1867         exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
1868         exp_adv_frac = 0;
1869         s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
1870
1871         /* Experience value need to get */
1872         s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
1873
1874
1875         /* You need to kill at least one monster to get any experience */
1876         s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1877         s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
1878
1879         /* Extract number of monsters needed */
1880         s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1881
1882         /* If 999 or more monsters needed, only display "999". */
1883         num = MIN(999, exp_adv_frac);
1884
1885         /* Display the number */
1886         sprintf(buf,"%03ld", (long int)num);
1887 }
1888
1889
1890 bool show_gold_on_floor = FALSE;
1891
1892 /*
1893  * Examine a grid, return a keypress.
1894  *
1895  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
1896  * indicates that the "space" key should scan through the contents
1897  * of the grid, instead of simply returning immediately.  This lets
1898  * the "look" command get complete information, without making the
1899  * "target" command annoying.
1900  *
1901  * The "info" argument contains the "commands" which should be shown
1902  * inside the "[xxx]" text.  This string must never be empty, or grids
1903  * containing monsters will be displayed with an extra comma.
1904  *
1905  * Note that if a monster is in the grid, we update both the monster
1906  * recall info and the health bar info to track that monster.
1907  *
1908  * Eventually, we may allow multiple objects per grid, or objects
1909  * and terrain features in the same grid. 
1910  *
1911  * This function must handle blindness/hallucination.
1912  */
1913 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
1914 {
1915         cave_type *c_ptr = &cave[y][x];
1916         OBJECT_IDX this_o_idx, next_o_idx = 0;
1917         concptr s1 = "", s2 = "", s3 = "", x_info = "";
1918         bool boring = TRUE;
1919         FEAT_IDX feat;
1920         feature_type *f_ptr;
1921         char query = '\001';
1922         char out_val[MAX_NLEN+80];
1923         OBJECT_IDX floor_list[23];
1924         ITEM_NUMBER floor_num = 0;
1925
1926         /* Scan all objects in the grid */
1927         if (easy_floor)
1928         {
1929                 floor_num = scan_floor(floor_list, y, x, 0x02);
1930
1931                 if (floor_num)
1932                 {
1933                         x_info = _("x物 ", "x,");
1934                 }
1935         }
1936
1937         /* Hack -- under the player */
1938         if (player_bold(y, x))
1939         {
1940 #ifdef JP
1941                 s1 = "あなたは";
1942                 s2 = "の上";
1943                 s3 = "にいる";
1944 #else
1945                 s1 = "You are ";
1946                 s2 = "on ";
1947 #endif
1948         }
1949         else
1950         {
1951                 s1 = _("ターゲット:", "Target:");
1952         }
1953
1954         /* Hack -- hallucination */
1955         if (p_ptr->image)
1956         {
1957                 concptr name = _("何か奇妙な物", "something strange");
1958
1959                 /* Display a message */
1960 #ifdef JP
1961                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
1962 #else
1963                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1964 #endif
1965
1966                 prt(out_val, 0, 0);
1967                 move_cursor_relative(y, x);
1968                 query = inkey();
1969
1970                 /* Stop on everything but "return" */
1971                 if ((query != '\r') && (query != '\n')) return query;
1972
1973                 /* Repeat forever */
1974                 return 0;
1975         }
1976
1977
1978         /* Actual monsters */
1979         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1980         {
1981                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1982                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1983                 GAME_TEXT m_name[MAX_NLEN];
1984                 bool recall = FALSE;
1985
1986                 /* Not boring */
1987                 boring = FALSE;
1988
1989                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1990                 monster_race_track(m_ptr->ap_r_idx);
1991                 health_track(c_ptr->m_idx);
1992                 handle_stuff();
1993
1994                 /* Interact */
1995                 while (1)
1996                 {
1997                         char acount[10];
1998
1999                         /* Recall */
2000                         if (recall)
2001                         {
2002                                 screen_save();
2003
2004                                 /* Recall on screen */
2005                                 screen_roff(m_ptr->ap_r_idx, 0);
2006
2007                                 /* Hack -- Complete the prompt (again) */
2008                                 Term_addstr(-1, TERM_WHITE, format(_("  [r思 %s%s]", "  [r,%s%s]"), x_info, info));
2009
2010                                 /* Command */
2011                                 query = inkey();
2012
2013                                 screen_load();
2014
2015                                 /* Normal commands */
2016                                 if (query != 'r') break;
2017
2018                                 /* Toggle recall */
2019                                 recall = FALSE;
2020
2021                                 /* Cleare recall text and repeat */
2022                                 continue;
2023                         }
2024
2025                         /*** Normal ***/
2026
2027                         /* Describe, and prompt for recall */
2028                         evaluate_monster_exp(acount, m_ptr);
2029
2030 #ifdef JP
2031                         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);
2032 #else
2033                         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);
2034 #endif
2035
2036                         prt(out_val, 0, 0);
2037
2038                         /* Place cursor */
2039                         move_cursor_relative(y, x);
2040
2041                         /* Command */
2042                         query = inkey();
2043
2044                         /* Normal commands */
2045                         if (query != 'r') break;
2046
2047                         /* Toggle recall */
2048                         recall = TRUE;
2049                 }
2050
2051                 /* Always stop at "normal" keys */
2052                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2053
2054                 /* Sometimes stop at "space" key */
2055                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2056
2057                 /* Change the intro */
2058                 s1 = _("それは", "It is ");
2059
2060                 /* Hack -- take account of gender */
2061                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
2062                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
2063
2064                 /* Use a preposition */
2065 #ifdef JP
2066                 s2 = "を";
2067                 s3 = "持っている";
2068 #else
2069                 s2 = "carrying ";
2070 #endif
2071
2072
2073                 /* Scan all objects being carried */
2074                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
2075                 {
2076                         GAME_TEXT o_name[MAX_NLEN];
2077
2078                         object_type *o_ptr;
2079                         o_ptr = &o_list[this_o_idx];
2080
2081                         /* Acquire next object */
2082                         next_o_idx = o_ptr->next_o_idx;
2083
2084                         /* Obtain an object description */
2085                         object_desc(o_name, o_ptr, 0);
2086
2087 #ifdef JP
2088                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2089 #else
2090                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2091 #endif
2092
2093                         prt(out_val, 0, 0);
2094                         move_cursor_relative(y, x);
2095                         query = inkey();
2096
2097                         /* Always stop at "normal" keys */
2098                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2099
2100                         /* Sometimes stop at "space" key */
2101                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2102
2103                         /* Change the intro */
2104                         s2 = _("をまた", "also carrying ");
2105                 }
2106
2107                 /* Use a preposition */
2108 #ifdef JP
2109                 s2 = "の上";
2110                 s3 = "にいる";
2111 #else
2112                 s2 = "on ";
2113 #endif
2114         }
2115
2116         if (floor_num)
2117         {
2118                 int min_width = 0;
2119
2120                 while (1)
2121                 {
2122                         if (floor_num == 1)
2123                         {
2124                                 GAME_TEXT o_name[MAX_NLEN];
2125
2126                                 object_type *o_ptr;
2127                                 o_ptr = &o_list[floor_list[0]];
2128
2129                                 object_desc(o_name, o_ptr, 0);
2130
2131 #ifdef JP
2132                                 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2133 #else
2134                                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2135 #endif
2136
2137                                 prt(out_val, 0, 0);
2138                                 move_cursor_relative(y, x);
2139
2140                                 /* Command */
2141                                 query = inkey();
2142
2143                                 /* End this grid */
2144                                 return query;
2145                         }
2146
2147                         /* Provide one cushion before item listing  */
2148                         if (boring)
2149                         {
2150                                 /* Display rough information about items */
2151 #ifdef JP
2152                                 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
2153 #else
2154                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
2155 #endif
2156
2157                                 prt(out_val, 0, 0);
2158                                 move_cursor_relative(y, x);
2159
2160                                 /* Command */
2161                                 query = inkey();
2162
2163                                 /* No request for listing */
2164                                 if (query != 'x' && query != ' ') return query;
2165                         }
2166
2167
2168                         /** Display list of items **/
2169
2170                         /* Continue scrolling list if requested */
2171                         while (1)
2172                         {
2173                                 int i;
2174                                 OBJECT_IDX o_idx;
2175                                 screen_save();
2176
2177                                 /* Display */
2178                                 show_gold_on_floor = TRUE;
2179                                 (void)show_floor(0, y, x, &min_width);
2180                                 show_gold_on_floor = FALSE;
2181
2182                                 /* Prompt */
2183 #ifdef JP
2184                                 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
2185 #else
2186                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
2187 #endif
2188                                 prt(out_val, 0, 0);
2189
2190                                 query = inkey();
2191                                 screen_load();
2192
2193                                 /* Exit unless 'Enter' */
2194                                 if (query != '\n' && query != '\r')
2195                                 {
2196                                         return query;
2197                                 }
2198
2199                                 /* Get the object being moved. */
2200                                 o_idx = c_ptr->o_idx;
2201  
2202                                 /* Only rotate a pile of two or more objects. */
2203                                 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
2204
2205                                 /* Remove the first object from the list. */
2206                                 excise_object_idx(o_idx);
2207
2208                                 /* Find end of the list. */
2209                                 i = c_ptr->o_idx;
2210                                 while (o_list[i].next_o_idx)
2211                                         i = o_list[i].next_o_idx;
2212
2213                                 /* Add after the last object. */
2214                                 o_list[i].next_o_idx = o_idx;
2215
2216                                 /* Loop and re-display the list */
2217                         }
2218                 }
2219
2220                 /* NOTREACHED */
2221         }
2222
2223         /* Scan all objects in the grid */
2224         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2225         {
2226                 object_type *o_ptr;
2227                 o_ptr = &o_list[this_o_idx];
2228
2229                 /* Acquire next object */
2230                 next_o_idx = o_ptr->next_o_idx;
2231
2232                 if (o_ptr->marked & OM_FOUND)
2233                 {
2234                         GAME_TEXT o_name[MAX_NLEN];
2235
2236                         /* Not boring */
2237                         boring = FALSE;
2238
2239                         /* Obtain an object description */
2240                         object_desc(o_name, o_ptr, 0);
2241
2242 #ifdef JP
2243                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2244 #else
2245                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2246 #endif
2247
2248                         prt(out_val, 0, 0);
2249                         move_cursor_relative(y, x);
2250                         query = inkey();
2251
2252                         /* Always stop at "normal" keys */
2253                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2254
2255                         /* Sometimes stop at "space" key */
2256                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
2257
2258                         /* Change the intro */
2259                         s1 = _("それは", "It is ");
2260
2261                         /* Plurals */
2262                         if (o_ptr->number != 1) s1 = _("それらは", "They are ");
2263
2264                         /* Preposition */
2265 #ifdef JP
2266                         s2 = "の上";
2267                         s3 = "に見える";
2268 #else
2269                         s2 = "on ";
2270 #endif
2271
2272                 }
2273         }
2274
2275
2276         /* Feature code (applying "mimic" field) */
2277         feat = get_feat_mimic(c_ptr);
2278
2279         /* Require knowledge about grid, or ability to see grid */
2280         if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
2281         {
2282                 /* Forget feature */
2283                 feat = feat_none;
2284         }
2285
2286         f_ptr = &f_info[feat];
2287
2288         /* Terrain feature if needed */
2289         if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
2290         {
2291                 concptr name;
2292
2293                 /* Hack -- special handling for quest entrances */
2294                 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
2295                 {
2296                         /* Set the quest number temporary */
2297                         IDX old_quest = p_ptr->inside_quest;
2298                         int j;
2299
2300                         /* Clear the text */
2301                         for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
2302                         quest_text_line = 0;
2303
2304                         p_ptr->inside_quest = c_ptr->special;
2305
2306                         /* Get the quest text */
2307                         init_flags = INIT_NAME_ONLY;
2308
2309                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
2310
2311                         name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"), 
2312                                                 quest[c_ptr->special].name, quest[c_ptr->special].level);
2313
2314                         /* Reset the old quest number */
2315                         p_ptr->inside_quest = old_quest;
2316                 }
2317
2318                 /* Hack -- special handling for building doors */
2319                 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
2320                 {
2321                         name = building[f_ptr->subtype].name;
2322                 }
2323                 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
2324                 {
2325                         name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
2326                 }
2327                 else if (have_flag(f_ptr->flags, FF_TOWN))
2328                 {
2329                         name = town[c_ptr->special].name;
2330                 }
2331                 else if (p_ptr->wild_mode && (feat == feat_floor))
2332                 {
2333                         name = _("道", "road");
2334                 }
2335                 else
2336                 {
2337                         name = f_name + f_ptr->name;
2338                 }
2339
2340
2341                 /* Pick a prefix */
2342                 if (*s2 &&
2343                     ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
2344                      (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
2345                      have_flag(f_ptr->flags, FF_TOWN)))
2346                 {
2347                         s2 = _("の中", "in ");
2348                 }
2349
2350                 /* Hack -- special introduction for store & building doors -KMW- */
2351                 if (have_flag(f_ptr->flags, FF_STORE) ||
2352                     have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
2353                     (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
2354                     have_flag(f_ptr->flags, FF_ENTRANCE))
2355                 {
2356                         s2 = _("の入口", "");
2357                 }
2358 #ifndef JP
2359                 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
2360                          have_flag(f_ptr->flags, FF_TOWN) ||
2361                          have_flag(f_ptr->flags, FF_SHALLOW) ||
2362                          have_flag(f_ptr->flags, FF_DEEP))
2363                 {
2364                         s3 ="";
2365                 }
2366                 else
2367                 {
2368                         /* Pick proper indefinite article */
2369                         s3 = (is_a_vowel(name[0])) ? "an " : "a ";
2370                 }
2371 #endif
2372
2373                 /* Display a message */
2374                 if (p_ptr->wizard)
2375                 {
2376                         char f_idx_str[32];
2377                         if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
2378                         else sprintf(f_idx_str, "%d", c_ptr->feat);
2379 #ifdef JP
2380                         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]);
2381 #else
2382                         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);
2383 #endif
2384                 }
2385                 else
2386 #ifdef JP
2387                         sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
2388 #else
2389                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
2390 #endif
2391
2392                 prt(out_val, 0, 0);
2393                 move_cursor_relative(y, x);
2394                 query = inkey();
2395
2396                 /* Always stop at "normal" keys */
2397                 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
2398         }
2399
2400         /* Stop on everything but "return" */
2401         if ((query != '\r') && (query != '\n')) return query;
2402
2403         /* Repeat forever */
2404         return 0;
2405 }
2406
2407
2408 /*
2409  * Handle "target" and "look".
2410  *
2411  * Note that this code can be called from "get_aim_dir()".
2412  *
2413  * All locations must be on the current panel.  Consider the use of
2414  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
2415  * some form of "scrolling" the map around the cursor.  
2416  * That is, consider the possibility of "auto-scrolling" the screen
2417  * while the cursor moves around.  This may require changes in the
2418  * "update_monster()" code to allow "visibility" even if off panel, and
2419  * may require dynamic recalculation of the "temp" grid set.
2420  *
2421  * Hack -- targeting/observing an "outer border grid" may induce
2422  * problems, so this is not currently allowed.
2423  *
2424  * The player can use the direction keys to move among "interesting"
2425  * grids in a heuristic manner, or the "space", "+", and "-" keys to
2426  * move through the "interesting" grids in a sequential manner, or
2427  * can enter "location" mode, and use the direction keys to move one
2428  * grid at a time in any direction.  The "t" (set target) command will
2429  * only target a monster (as opposed to a location) if the monster is
2430  * target_able and the "interesting" mode is being used.
2431  *
2432  * The current grid is described using the "look" method above, and
2433  * a new command may be entered at any time, but note that if the
2434  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
2435  * where "space" has no obvious meaning) then "space" will scan
2436  * through the description of the current grid until done, instead
2437  * of immediately jumping to the next "interesting" grid.  This
2438  * allows the "target" command to retain its old semantics.
2439  *
2440  * The "*", "+", and "-" keys may always be used to jump immediately
2441  * to the next (or previous) interesting grid, in the proper mode.
2442  *
2443  * The "return" key may always be used to scan through a complete
2444  * grid description (forever).
2445  *
2446  * This command will cancel any old target, even if used from
2447  * inside the "look" command.
2448  */
2449 bool target_set(BIT_FLAGS mode)
2450 {
2451         int i, d, m, t, bd;
2452         POSITION y = p_ptr->y;
2453         POSITION x = p_ptr->x;
2454
2455         bool done = FALSE;
2456         bool flag = TRUE;
2457         char query;
2458         char info[80];
2459         char same_key;
2460         cave_type *c_ptr;
2461         TERM_LEN wid, hgt;
2462         
2463         get_screen_size(&wid, &hgt);
2464
2465         /* Cancel target */
2466         target_who = 0;
2467
2468         if (rogue_like_commands)
2469         {
2470                 same_key = 'x';
2471         }
2472         else
2473         {
2474                 same_key = 'l';
2475         }
2476
2477         /* Prepare the "temp" array */
2478         target_set_prepare(mode);
2479
2480         /* Start near the player */
2481         m = 0;
2482
2483         /* Interact */
2484         while (!done)
2485         {
2486                 /* Interesting grids */
2487                 if (flag && temp_n)
2488                 {
2489                         y = temp_y[m];
2490                         x = temp_x[m];
2491
2492                         /* Set forcus */
2493                         change_panel_xy(y, x);
2494
2495                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
2496
2497                         /* Access */
2498                         c_ptr = &cave[y][x];
2499
2500                         /* Allow target */
2501                         if (target_able(c_ptr->m_idx))
2502                         {
2503                                 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
2504                         }
2505
2506                         /* Dis-allow target */
2507                         else
2508                         {
2509                                 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
2510                         }
2511
2512                         if (cheat_sight)
2513                         {
2514                                 char cheatinfo[30];
2515                                 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
2516                                         los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
2517                                 strcat(info, cheatinfo);
2518                         }
2519                         
2520                         /* Describe and Prompt */
2521                         while (TRUE){
2522                                 query = target_set_aux(y, x, mode, info);
2523                                 if(query)break;
2524                         }
2525
2526                         /* Assume no "direction" */
2527                         d = 0;
2528
2529                         if (use_menu)
2530                         {
2531                                 if (query == '\r') query = 't';
2532                         }  
2533
2534                         /* Analyze */
2535                         switch (query)
2536                         {
2537                                 case ESCAPE:
2538                                 case 'q':
2539                                 {
2540                                         done = TRUE;
2541                                         break;
2542                                 }
2543
2544                                 case 't':
2545                                 case '.':
2546                                 case '5':
2547                                 case '0':
2548                                 {
2549                                         if (target_able(c_ptr->m_idx))
2550                                         {
2551                                                 health_track(c_ptr->m_idx);
2552                                                 target_who = c_ptr->m_idx;
2553                                                 target_row = y;
2554                                                 target_col = x;
2555                                                 done = TRUE;
2556                                         }
2557                                         else
2558                                         {
2559                                                 bell();
2560                                         }
2561                                         break;
2562                                 }
2563
2564                                 case ' ':
2565                                 case '*':
2566                                 case '+':
2567                                 {
2568                                         if (++m == temp_n)
2569                                         {
2570                                                 m = 0;
2571                                                 if (!expand_list) done = TRUE;
2572                                         }
2573                                         break;
2574                                 }
2575
2576                                 case '-':
2577                                 {
2578                                         if (m-- == 0)
2579                                         {
2580                                                 m = temp_n - 1;
2581                                                 if (!expand_list) done = TRUE;
2582                                         }
2583                                         break;
2584                                 }
2585
2586                                 case 'p':
2587                                 {
2588                                         /* Recenter the map around the player */
2589                                         verify_panel();
2590                                         p_ptr->update |= (PU_MONSTERS);
2591                                         p_ptr->redraw |= (PR_MAP);
2592                                         p_ptr->window |= (PW_OVERHEAD);
2593                                         handle_stuff();
2594
2595                                         /* Recalculate interesting grids */
2596                                         target_set_prepare(mode);
2597
2598                                         y = p_ptr->y;
2599                                         x = p_ptr->x;
2600                                 }
2601
2602                                 case 'o':
2603                                 {
2604                                         flag = FALSE;
2605                                         break;
2606                                 }
2607
2608                                 case 'm':
2609                                 {
2610                                         break;
2611                                 }
2612
2613                                 default:
2614                                 {
2615                                         if(query == same_key)
2616                                         {
2617                                                 if (++m == temp_n)
2618                                                 {
2619                                                         m = 0;
2620                                                         if (!expand_list) done = TRUE;
2621                                                 }
2622                                         }
2623                                         else
2624                                         {
2625                                                 /* Extract the action (if any) */
2626                                                 d = get_keymap_dir(query);
2627
2628                                                 if (!d) bell();
2629                                                 break;
2630                                         }
2631                                 }
2632                         }
2633                         /* Hack -- move around */
2634                         if (d)
2635                         {
2636                                 /* Modified to scroll to monster */
2637                                 POSITION y2 = panel_row_min;
2638                                 POSITION x2 = panel_col_min;
2639
2640                                 /* Find a new monster */
2641                                 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
2642
2643                                 /* Request to target past last interesting grid */
2644                                 while (flag && (i < 0))
2645                                 {
2646                                         /* Note the change */
2647                                         if (change_panel(ddy[d], ddx[d]))
2648                                         {
2649                                                 int v = temp_y[m];
2650                                                 int u = temp_x[m];
2651
2652                                                 /* Recalculate interesting grids */
2653                                                 target_set_prepare(mode);
2654
2655                                                 /* Look at interesting grids */
2656                                                 flag = TRUE;
2657
2658                                                 /* Find a new monster */
2659                                                 i = target_pick(v, u, ddy[d], ddx[d]);
2660
2661                                                 /* Use that grid */
2662                                                 if (i >= 0) m = i;
2663                                         }
2664
2665                                         /* Nothing interesting */
2666                                         else
2667                                         {
2668                                                 POSITION dx = ddx[d];
2669                                                 POSITION dy = ddy[d];
2670
2671                                                 /* Restore previous position */
2672                                                 panel_row_min = y2;
2673                                                 panel_col_min = x2;
2674                                                 panel_bounds_center();
2675
2676                                                 p_ptr->update |= (PU_MONSTERS);
2677                                                 p_ptr->redraw |= (PR_MAP);
2678                                                 p_ptr->window |= (PW_OVERHEAD);
2679                                                 handle_stuff();
2680
2681                                                 /* Recalculate interesting grids */
2682                                                 target_set_prepare(mode);
2683
2684                                                 /* Look at boring grids */
2685                                                 flag = FALSE;
2686
2687                                                 /* Move */
2688                                                 x += dx;
2689                                                 y += dy;
2690
2691                                                 /* Do not move horizontally if unnecessary */
2692                                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2693                                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
2694                                                 {
2695                                                         dx = 0;
2696                                                 }
2697
2698                                                 /* Do not move vertically if unnecessary */
2699                                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2700                                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
2701                                                 {
2702                                                         dy = 0;
2703                                                 }
2704
2705                                                 /* Apply the motion */
2706                                                 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
2707                                                     (x >= panel_col_min+wid) || (x < panel_col_min))
2708                                                 {
2709                                                         if (change_panel(dy, dx)) target_set_prepare(mode);
2710                                                 }
2711
2712                                                 /* Slide into legality */
2713                                                 if (x >= cur_wid-1) x = cur_wid - 2;
2714                                                 else if (x <= 0) x = 1;
2715
2716                                                 /* Slide into legality */
2717                                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
2718                                                 else if (y <= 0) y = 1;
2719                                         }
2720                                 }
2721
2722                                 /* Use that grid */
2723                                 m = i;
2724                         }
2725                 }
2726
2727                 /* Arbitrary grids */
2728                 else
2729                 {
2730                         bool move_fast = FALSE;
2731
2732                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
2733
2734                         /* Access */
2735                         c_ptr = &cave[y][x];
2736
2737                         /* Default prompt */
2738                         strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
2739
2740                         if (cheat_sight)
2741                         {
2742                                 char cheatinfo[30];
2743                                 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
2744                                         los(p_ptr->y, p_ptr->x, y, x),
2745                                         projectable(p_ptr->y, p_ptr->x, y, x));
2746                                 strcat(info, cheatinfo);
2747                         }
2748
2749                         /* Describe and Prompt (enable "TARGET_LOOK") */
2750                         while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
2751
2752                         /* Assume no direction */
2753                         d = 0;
2754
2755                         if (use_menu)
2756                         {
2757                                 if (query == '\r') query = 't';
2758                         }  
2759
2760                         /* Analyze the keypress */
2761                         switch (query)
2762                         {
2763                                 case ESCAPE:
2764                                 case 'q':
2765                                 {
2766                                         done = TRUE;
2767                                         break;
2768                                 }
2769
2770                                 case 't':
2771                                 case '.':
2772                                 case '5':
2773                                 case '0':
2774                                 {
2775                                         target_who = -1;
2776                                         target_row = y;
2777                                         target_col = x;
2778                                         done = TRUE;
2779                                         break;
2780                                 }
2781
2782                                 case 'p':
2783                                 {
2784                                         /* Recenter the map around the player */
2785                                         verify_panel();
2786                                         p_ptr->update |= (PU_MONSTERS);
2787                                         p_ptr->redraw |= (PR_MAP);
2788                                         p_ptr->window |= (PW_OVERHEAD);
2789                                         handle_stuff();
2790
2791                                         /* Recalculate interesting grids */
2792                                         target_set_prepare(mode);
2793
2794                                         y = p_ptr->y;
2795                                         x = p_ptr->x;
2796                                 }
2797
2798                                 case 'o':
2799                                 {
2800                                         break;
2801                                 }
2802
2803                                 case ' ':
2804                                 case '*':
2805                                 case '+':
2806                                 case '-':
2807                                 case 'm':
2808                                 {
2809                                         flag = TRUE;
2810
2811                                         m = 0;
2812                                         bd = 999;
2813
2814                                         /* Pick a nearby monster */
2815                                         for (i = 0; i < temp_n; i++)
2816                                         {
2817                                                 t = distance(y, x, temp_y[i], temp_x[i]);
2818
2819                                                 /* Pick closest */
2820                                                 if (t < bd)
2821                                                 {
2822                                                         m = i;
2823                                                         bd = t;
2824                                                 }
2825                                         }
2826
2827                                         /* Nothing interesting */
2828                                         if (bd == 999) flag = FALSE;
2829
2830                                         break;
2831                                 }
2832
2833                                 default:
2834                                 {
2835                                         /* Extract the action (if any) */
2836                                         d = get_keymap_dir(query);
2837
2838                                         /* XTRA HACK MOVEFAST */
2839                                         if (isupper(query)) move_fast = TRUE;
2840
2841                                         if (!d) bell();
2842                                         break;
2843                                 }
2844                         }
2845
2846                         /* Handle "direction" */
2847                         if (d)
2848                         {
2849                                 POSITION dx = ddx[d];
2850                                 POSITION dy = ddy[d];
2851
2852                                 /* XTRA HACK MOVEFAST */
2853                                 if (move_fast)
2854                                 {
2855                                         int mag = MIN(wid / 2, hgt / 2);
2856                                         x += dx * mag;
2857                                         y += dy * mag;
2858                                 }
2859                                 else
2860                                 {
2861                                         x += dx;
2862                                         y += dy;
2863                                 }
2864
2865                                 /* Do not move horizontally if unnecessary */
2866                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2867                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
2868                                 {
2869                                         dx = 0;
2870                                 }
2871
2872                                 /* Do not move vertically if unnecessary */
2873                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2874                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
2875                                 {
2876                                         dy = 0;
2877                                 }
2878
2879                                 /* Apply the motion */
2880                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2881                                          (x >= panel_col_min + wid) || (x < panel_col_min))
2882                                 {
2883                                         if (change_panel(dy, dx)) target_set_prepare(mode);
2884                                 }
2885
2886                                 /* Slide into legality */
2887                                 if (x >= cur_wid-1) x = cur_wid - 2;
2888                                 else if (x <= 0) x = 1;
2889
2890                                 /* Slide into legality */
2891                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
2892                                 else if (y <= 0) y = 1;
2893                         }
2894                 }
2895         }
2896
2897         /* Forget */
2898         temp_n = 0;
2899
2900         /* Clear the top line */
2901         prt("", 0, 0);
2902
2903         /* Recenter the map around the player */
2904         verify_panel();
2905         p_ptr->update |= (PU_MONSTERS);
2906         p_ptr->redraw |= (PR_MAP);
2907         p_ptr->window |= (PW_OVERHEAD);
2908         handle_stuff();
2909
2910         /* Failure to set target */
2911         if (!target_who) return (FALSE);
2912
2913         /* Success */
2914         return (TRUE);
2915 }
2916
2917
2918 /*
2919  * Get an "aiming direction" from the user.
2920  *
2921  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
2922  * "0" for "current target", and "-1" for "entry aborted".
2923  *
2924  * Note that "Force Target", if set, will pre-empt user interaction,
2925  * if there is a usable target already set.
2926  *
2927  * Note that confusion over-rides any (explicit?) user choice.
2928  */
2929 bool get_aim_dir(DIRECTION *dp)
2930 {
2931         DIRECTION dir;
2932         char    command;
2933         concptr p;
2934         COMMAND_CODE code;
2935
2936         (*dp) = 0;
2937
2938         /* Global direction */
2939         dir = command_dir;
2940
2941         /* Hack -- auto-target if requested */
2942         if (use_old_target && target_okay()) dir = 5;
2943
2944         if (repeat_pull(&code))
2945         {
2946                 /* Confusion? */
2947
2948                 /* Verify */
2949                 if (!(code == 5 && !target_okay()))
2950                 {
2951 /*                      return (TRUE); */
2952                         dir = (DIRECTION)code;
2953                 }
2954         }
2955         *dp = (DIRECTION)code;
2956
2957         /* Ask until satisfied */
2958         while (!dir)
2959         {
2960                 /* Choose a prompt */
2961                 if (!target_okay())
2962                 {
2963                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2964                 }
2965                 else
2966                 {
2967                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2968                 }
2969
2970                 /* Get a command (or Cancel) */
2971                 if (!get_com(p, &command, TRUE)) break;
2972
2973                 if (use_menu)
2974                 {
2975                         if (command == '\r') command = 't';
2976                 }  
2977
2978                 /* Convert various keys to "standard" keys */
2979                 switch (command)
2980                 {
2981                         /* Use current target */
2982                         case 'T':
2983                         case 't':
2984                         case '.':
2985                         case '5':
2986                         case '0':
2987                         {
2988                                 dir = 5;
2989                                 break;
2990                         }
2991
2992                         /* Set new target */
2993                         case '*':
2994                         case ' ':
2995                         case '\r':
2996                         {
2997                                 if (target_set(TARGET_KILL)) dir = 5;
2998                                 break;
2999                         }
3000
3001                         default:
3002                         {
3003                                 /* Extract the action (if any) */
3004                                 dir = get_keymap_dir(command);
3005
3006                                 break;
3007                         }
3008                 }
3009
3010                 /* Verify requested targets */
3011                 if ((dir == 5) && !target_okay()) dir = 0;
3012
3013                 /* Error */
3014                 if (!dir) bell();
3015         }
3016
3017         /* No direction */
3018         if (!dir)
3019         {
3020                 project_length = 0; /* reset to default */
3021                 return (FALSE);
3022         }
3023
3024         /* Save the direction */
3025         command_dir = dir;
3026
3027         /* Check for confusion */
3028         if (p_ptr->confused)
3029         {
3030                 /* Random direction */
3031                 dir = ddd[randint0(8)];
3032         }
3033
3034         /* Notice confusion */
3035         if (command_dir != dir)
3036         {
3037                 /* Warn the user */
3038                 msg_print(_("あなたは混乱している。", "You are confused."));
3039         }
3040
3041         /* Save direction */
3042         (*dp) = dir;
3043
3044 /*      repeat_push(dir); */
3045         repeat_push((COMMAND_CODE)command_dir);
3046
3047         /* A "valid" direction was entered */
3048         return (TRUE);
3049 }
3050
3051
3052 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
3053 {
3054         DIRECTION dir;
3055         concptr prompt;
3056         COMMAND_CODE code;
3057
3058         (*dp) = 0;
3059
3060         /* Global direction */
3061         dir = command_dir;
3062
3063         if (repeat_pull(&code))
3064         {
3065                 dir = (DIRECTION)code;
3066                 /*              return (TRUE); */
3067         }
3068         *dp = (DIRECTION)code;
3069
3070         if (allow_under)
3071         {
3072                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3073         }
3074         else
3075         {
3076                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3077         }
3078
3079         /* Get a direction */
3080         while (!dir)
3081         {
3082                 char ch;
3083
3084                 /* Get a command (or Cancel) */
3085                 if (!get_com(prompt, &ch, TRUE)) break;
3086
3087                 /* Look down */
3088                 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3089                 {
3090                         dir = 5;
3091                 }
3092                 else
3093                 {
3094                         /* Look up the direction */
3095                         dir = get_keymap_dir(ch);
3096
3097                         if (!dir) bell();
3098                 }
3099         }
3100
3101         /* Prevent weirdness */
3102         if ((dir == 5) && (!allow_under)) dir = 0;
3103
3104         /* Aborted */
3105         if (!dir) return (FALSE);
3106
3107         /* Save desired direction */
3108         command_dir = dir;
3109
3110         /* Apply "confusion" */
3111         if (p_ptr->confused)
3112         {
3113                 /* Standard confusion */
3114                 if (randint0(100) < 75)
3115                 {
3116                         /* Random direction */
3117                         dir = ddd[randint0(8)];
3118                 }
3119         }
3120         else if (p_ptr->riding && with_steed)
3121         {
3122                 monster_type *m_ptr = &m_list[p_ptr->riding];
3123                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3124
3125                 if (MON_CONFUSED(m_ptr))
3126                 {
3127                         /* Standard confusion */
3128                         if (randint0(100) < 75)
3129                         {
3130                                 /* Random direction */
3131                                 dir = ddd[randint0(8)];
3132                         }
3133                 }
3134                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3135                 {
3136                         /* Random direction */
3137                         dir = ddd[randint0(8)];
3138                 }
3139                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3140                 {
3141                         /* Random direction */
3142                         dir = ddd[randint0(8)];
3143                 }
3144         }
3145
3146         /* Notice confusion */
3147         if (command_dir != dir)
3148         {
3149                 if (p_ptr->confused)
3150                 {
3151                         /* Warn the user */
3152                         msg_print(_("あなたは混乱している。", "You are confused."));
3153                 }
3154                 else
3155                 {
3156                         GAME_TEXT m_name[MAX_NLEN];
3157                         monster_type *m_ptr = &m_list[p_ptr->riding];
3158
3159                         monster_desc(m_name, m_ptr, 0);
3160                         if (MON_CONFUSED(m_ptr))
3161                         {
3162                                 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3163                         }
3164                         else
3165                         {
3166                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3167                         }
3168                 }
3169         }
3170
3171         /* Save direction */
3172         (*dp) = dir;
3173
3174         /*      repeat_push(dir); */
3175         repeat_push((COMMAND_CODE)command_dir);
3176
3177         /* Success */
3178         return (TRUE);
3179 }
3180
3181 /*
3182  * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
3183  * and place it into "command_dir", unless we already have one.
3184  *
3185  * This function should be used for all "repeatable" commands, such as
3186  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
3187  * as all commands which must reference a grid adjacent to the player,
3188  * and which may not reference the grid under the player.  Note that,
3189  * for example, it is no longer possible to "disarm" or "open" chests
3190  * in the same grid as the player.
3191  *
3192  * Direction "5" is illegal and will (cleanly) abort the command.
3193  *
3194  * This function tracks and uses the "global direction", and uses
3195  * that as the "desired direction", to which "confusion" is applied.
3196  */
3197 bool get_rep_dir(DIRECTION *dp, bool under)
3198 {
3199         DIRECTION dir;
3200         concptr prompt;
3201         COMMAND_CODE code;
3202
3203         (*dp) = 0;
3204
3205         /* Global direction */
3206         dir = command_dir;
3207
3208         if (repeat_pull(&code))
3209         {
3210                 dir = (DIRECTION)code;
3211 /*              return (TRUE); */
3212         }
3213         *dp = (DIRECTION)code;
3214
3215         if (under)
3216         {
3217                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3218         }
3219         else
3220         {
3221                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3222         }
3223         
3224         /* Get a direction */
3225         while (!dir)
3226         {
3227                 char ch;
3228
3229                 /* Get a command (or Cancel) */
3230                 if (!get_com(prompt, &ch, TRUE)) break;
3231
3232                 /* Look down */
3233                 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3234                 {
3235                         dir = 5;
3236                 }
3237                 else
3238                 {
3239                         /* Look up the direction */
3240                         dir = get_keymap_dir(ch);
3241
3242                         if (!dir) bell();
3243                 }
3244         }
3245
3246         /* Prevent weirdness */
3247         if ((dir == 5) && (!under)) dir = 0;
3248
3249         /* Aborted */
3250         if (!dir) return (FALSE);
3251
3252         /* Save desired direction */
3253         command_dir = dir;
3254
3255         /* Apply "confusion" */
3256         if (p_ptr->confused)
3257         {
3258                 /* Standard confusion */
3259                 if (randint0(100) < 75)
3260                 {
3261                         /* Random direction */
3262                         dir = ddd[randint0(8)];
3263                 }
3264         }
3265         else if (p_ptr->riding)
3266         {
3267                 monster_type *m_ptr = &m_list[p_ptr->riding];
3268                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3269
3270                 if (MON_CONFUSED(m_ptr))
3271                 {
3272                         /* Standard confusion */
3273                         if (randint0(100) < 75)
3274                         {
3275                                 /* Random direction */
3276                                 dir = ddd[randint0(8)];
3277                         }
3278                 }
3279                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3280                 {
3281                         /* Random direction */
3282                         dir = ddd[randint0(8)];
3283                 }
3284                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3285                 {
3286                         /* Random direction */
3287                         dir = ddd[randint0(8)];
3288                 }
3289         }
3290
3291         /* Notice confusion */
3292         if (command_dir != dir)
3293         {
3294                 if (p_ptr->confused)
3295                 {
3296                         /* Warn the user */
3297                         msg_print(_("あなたは混乱している。", "You are confused."));
3298                 }
3299                 else
3300                 {
3301                         GAME_TEXT m_name[MAX_NLEN];
3302                         monster_type *m_ptr = &m_list[p_ptr->riding];
3303
3304                         monster_desc(m_name, m_ptr, 0);
3305                         if (MON_CONFUSED(m_ptr))
3306                         {
3307                                 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3308                         }
3309                         else
3310                         {
3311                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3312                         }
3313                 }
3314         }
3315
3316         /* Save direction */
3317         (*dp) = dir;
3318
3319 /*      repeat_push(dir); */
3320         repeat_push((COMMAND_CODE)command_dir);
3321
3322         /* Success */
3323         return (TRUE);
3324 }
3325
3326
3327 /*
3328  * XAngband: determine if a given location is "interesting"
3329  * based on target_set_accept function.
3330  */
3331 static bool tgt_pt_accept(POSITION y, POSITION x)
3332 {
3333         cave_type *c_ptr;
3334
3335         /* Bounds */
3336         if (!(in_bounds(y, x))) return (FALSE);
3337
3338         /* Player grid is always interesting */
3339         if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
3340
3341         /* Handle hallucination */
3342         if (p_ptr->image) return (FALSE);
3343
3344         /* Examine the grid */
3345         c_ptr = &cave[y][x];
3346
3347         /* Interesting memorized features */
3348         if (c_ptr->info & (CAVE_MARK))
3349         {
3350                 /* Notice stairs */
3351                 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
3352                 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
3353
3354                 /* Notice quest features */
3355                 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
3356                 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
3357         }
3358
3359         return (FALSE);
3360 }
3361
3362
3363 /*
3364  * XAngband: Prepare the "temp" array for "tget_pt"
3365  * based on target_set_prepare funciton.
3366  */
3367 static void tgt_pt_prepare(void)
3368 {
3369         POSITION y, x;
3370
3371         /* Reset "temp" array */
3372         temp_n = 0;
3373
3374         if (!expand_list) return;
3375
3376         /* Scan the current panel */
3377         for (y = 1; y < cur_hgt; y++)
3378         {
3379                 for (x = 1; x < cur_wid; x++)
3380                 {
3381                         /* Require "interesting" contents */
3382                         if (!tgt_pt_accept(y, x)) continue;
3383
3384                         /* Save the location */
3385                         temp_x[temp_n] = x;
3386                         temp_y[temp_n] = y;
3387                         temp_n++;
3388                 }
3389         }
3390
3391         /* Target the nearest monster for shooting */
3392         ang_sort_comp = ang_sort_comp_distance;
3393         ang_sort_swap = ang_sort_swap_distance;
3394
3395         /* Sort the positions */
3396         ang_sort(temp_x, temp_y, temp_n);
3397 }
3398
3399 /*
3400  * old -- from PsiAngband.
3401  */
3402 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
3403 {
3404         char ch = 0;
3405         int d, n = 0;
3406         POSITION x, y;
3407         bool success = FALSE;
3408
3409         TERM_LEN wid, hgt;
3410
3411         get_screen_size(&wid, &hgt);
3412
3413         x = p_ptr->x;
3414         y = p_ptr->y;
3415
3416         if (expand_list) 
3417         {
3418                 tgt_pt_prepare();
3419         }
3420
3421         msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
3422         msg_flag = FALSE; /* prevents "-more-" message. */
3423
3424         while ((ch != ESCAPE) && !success)
3425         {
3426                 bool move_fast = FALSE;
3427
3428                 move_cursor_relative(y, x);
3429                 ch = inkey();
3430                 switch (ch)
3431                 {
3432                 case ESCAPE:
3433                         break;
3434                 case ' ':
3435                 case 't':
3436                 case '.':
3437                 case '5':
3438                 case '0':
3439                         /* illegal place */
3440                         if (player_bold(y, x)) ch = 0;
3441
3442                         /* okay place */
3443                         else success = TRUE;
3444
3445                         break;
3446
3447                 /* XAngband: Move cursor to stairs */
3448                 case '>':
3449                 case '<':
3450                         if (expand_list && temp_n)
3451                         {
3452                                 int dx, dy;
3453                                 int cx = (panel_col_min + panel_col_max) / 2;
3454                                 int cy = (panel_row_min + panel_row_max) / 2;
3455
3456                                 n++;
3457
3458                                 /* Skip stairs which have defferent distance */
3459                                 for (; n < temp_n; ++ n)
3460                                 {
3461                                         cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
3462
3463                                         if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
3464                                             cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
3465                                         {
3466                                                 /* Found */
3467                                                 break;
3468                                         }
3469                                 }
3470
3471                                 if (n == temp_n)        /* Loop out taget list */
3472                                 {
3473                                         n = 0;
3474                                         y = p_ptr->y;
3475                                         x = p_ptr->x;
3476                                         verify_panel(); /* Move cursor to player */
3477
3478                                         p_ptr->update |= (PU_MONSTERS);
3479
3480                                         p_ptr->redraw |= (PR_MAP);
3481
3482                                         p_ptr->window |= (PW_OVERHEAD);
3483                                         handle_stuff();
3484                                 }
3485                                 else    /* move cursor to next stair and change panel */
3486                                 {
3487                                         y = temp_y[n];
3488                                         x = temp_x[n];
3489
3490                                         dy = 2 * (y - cy) / hgt;
3491                                         dx = 2 * (x - cx) / wid;
3492                                         if (dy || dx) change_panel(dy, dx);
3493                                 }
3494                         }
3495                         break;
3496
3497                 default:
3498                         /* Look up the direction */
3499                         d = get_keymap_dir(ch);
3500
3501                         /* XTRA HACK MOVEFAST */
3502                         if (isupper(ch)) move_fast = TRUE;
3503
3504                         /* Handle "direction" */
3505                         if (d)
3506                         {
3507                                 int dx = ddx[d];
3508                                 int dy = ddy[d];
3509
3510                                 /* XTRA HACK MOVEFAST */
3511                                 if (move_fast)
3512                                 {
3513                                         int mag = MIN(wid / 2, hgt / 2);
3514                                         x += dx * mag;
3515                                         y += dy * mag;
3516                                 }
3517                                 else
3518                                 {
3519                                         x += dx;
3520                                         y += dy;
3521                                 }
3522
3523                                 /* Do not move horizontally if unnecessary */
3524                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3525                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
3526                                 {
3527                                         dx = 0;
3528                                 }
3529
3530                                 /* Do not move vertically if unnecessary */
3531                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3532                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
3533                                 {
3534                                         dy = 0;
3535                                 }
3536
3537                                 /* Apply the motion */
3538                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
3539                                          (x >= panel_col_min + wid) || (x < panel_col_min))
3540                                 {
3541                                         /* if (change_panel(dy, dx)) target_set_prepare(mode); */
3542                                         change_panel(dy, dx);
3543                                 }
3544
3545                                 /* Slide into legality */
3546                                 if (x >= cur_wid-1) x = cur_wid - 2;
3547                                 else if (x <= 0) x = 1;
3548
3549                                 /* Slide into legality */
3550                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
3551                                 else if (y <= 0) y = 1;
3552
3553                         }
3554                         break;
3555                 }
3556         }
3557
3558         /* Clear the top line */
3559         prt("", 0, 0);
3560
3561         /* Recenter the map around the player */
3562         verify_panel();
3563
3564         p_ptr->update |= (PU_MONSTERS);
3565
3566         p_ptr->redraw |= (PR_MAP);
3567
3568         p_ptr->window |= (PW_OVERHEAD);
3569         handle_stuff();
3570
3571         *x_ptr = x;
3572         *y_ptr = y;
3573         return success;
3574 }
3575
3576
3577 bool get_hack_dir(DIRECTION *dp)
3578 {
3579         DIRECTION dir;
3580         concptr    p;
3581         char    command;
3582
3583         (*dp) = 0;
3584
3585         /* Global direction */
3586         dir = 0;
3587
3588         /* (No auto-targeting) */
3589
3590         /* Ask until satisfied */
3591         while (!dir)
3592         {
3593                 /* Choose a prompt */
3594                 if (!target_okay())
3595                 {
3596                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
3597                 }
3598                 else
3599                 {
3600                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
3601                 }
3602
3603                 /* Get a command (or Cancel) */
3604                 if (!get_com(p, &command, TRUE)) break;
3605
3606                 if (use_menu)
3607                 {
3608                         if (command == '\r') command = 't';
3609                 }  
3610
3611                 /* Convert various keys to "standard" keys */
3612                 switch (command)
3613                 {
3614                         /* Use current target */
3615                         case 'T':
3616                         case 't':
3617                         case '.':
3618                         case '5':
3619                         case '0':
3620                         {
3621                                 dir = 5;
3622                                 break;
3623                         }
3624
3625                         /* Set new target */
3626                         case '*':
3627                         case ' ':
3628                         case '\r':
3629                         {
3630                                 if (target_set(TARGET_KILL)) dir = 5;
3631                                 break;
3632                         }
3633
3634                         default:
3635                         {
3636                                 /* Look up the direction */
3637                                 dir = get_keymap_dir(command);
3638
3639                                 break;
3640                         }
3641                 }
3642
3643                 /* Verify requested targets */
3644                 if ((dir == 5) && !target_okay()) dir = 0;
3645
3646                 /* Error */
3647                 if (!dir) bell();
3648         }
3649
3650         /* No direction */
3651         if (!dir) return (FALSE);
3652
3653         /* Save the direction */
3654         command_dir = dir;
3655
3656         /* Check for confusion */
3657         if (p_ptr->confused)
3658         {
3659                 /* Random direction */
3660                 dir = ddd[randint0(8)];
3661         }
3662
3663         /* Notice confusion */
3664         if (command_dir != dir)
3665         {
3666                 /* Warn the user */
3667                 msg_print(_("あなたは混乱している。", "You are confused."));
3668         }
3669
3670         /* Save direction */
3671         (*dp) = dir;
3672
3673         /* A "valid" direction was entered */
3674         return (TRUE);
3675 }
3676
3677
3678 /*!
3679  * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
3680  * @param sval 射撃武器のアイテム副分類ID 
3681  * @return 消費する基本エネルギー
3682  */
3683 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
3684 {
3685         ENERGY energy = 10000;
3686
3687         /* Analyze the launcher */
3688         switch (sval)
3689         {
3690                 /* Sling and ammo */
3691                 case SV_SLING:
3692                 {
3693                         energy = 8000;
3694                         break;
3695                 }
3696
3697                 /* Short Bow and Arrow */
3698                 case SV_SHORT_BOW:
3699                 {
3700                         energy = 10000;
3701                         break;
3702                 }
3703
3704                 /* Long Bow and Arrow */
3705                 case SV_LONG_BOW:
3706                 {
3707                         energy = 10000;
3708                         break;
3709                 }
3710
3711                 /* Bow of irresponsiblity and Arrow */
3712                 case SV_NAMAKE_BOW:
3713                 {
3714                         energy = 7777;
3715                         break;
3716                 }
3717
3718                 /* Light Crossbow and Bolt */
3719                 case SV_LIGHT_XBOW:
3720                 {
3721                         energy = 12000;
3722                         break;
3723                 }
3724
3725                 /* Heavy Crossbow and Bolt */
3726                 case SV_HEAVY_XBOW:
3727                 {
3728                         energy = 13333;
3729                         break;
3730                 }
3731         }
3732
3733         return (energy);
3734 }
3735
3736
3737 /*
3738  * Return bow tmul
3739  */
3740 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
3741 {
3742         int tmul = 0;
3743
3744         /* Analyze the launcher */
3745         switch (sval)
3746         {
3747                 /* Sling and ammo */
3748                 case SV_SLING:
3749                 {
3750                         tmul = 2;
3751                         break;
3752                 }
3753
3754                 /* Short Bow and Arrow */
3755                 case SV_SHORT_BOW:
3756                 {
3757                         tmul = 2;
3758                         break;
3759                 }
3760
3761                 /* Long Bow and Arrow */
3762                 case SV_LONG_BOW:
3763                 {
3764                         tmul = 3;
3765                         break;
3766                 }
3767
3768                 /* Bow of irresponsiblity and Arrow */
3769                 case SV_NAMAKE_BOW:
3770                 {
3771                         tmul = 3;
3772                         break;
3773                 }
3774
3775                 /* Light Crossbow and Bolt */
3776                 case SV_LIGHT_XBOW:
3777                 {
3778                         tmul = 3;
3779                         break;
3780                 }
3781
3782                 /* Heavy Crossbow and Bolt */
3783                 case SV_HEAVY_XBOW:
3784                 {
3785                         tmul = 4;
3786                         break;
3787                 }
3788         }
3789
3790         return (tmul);
3791 }
3792
3793
3794 /*
3795  * Display a rumor and apply its effects
3796  */
3797
3798 IDX rumor_num(char *zz, IDX max_idx)
3799 {
3800         if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
3801         return (IDX)atoi(zz);
3802 }
3803
3804 concptr rumor_bind_name(char *base, concptr fullname)
3805 {
3806         char *s, *v;
3807
3808         s = strstr(base, "{Name}");
3809         if (s)
3810         {
3811                 s[0] = '\0';
3812                 v = format("%s%s%s", base, fullname, (s + 6));
3813         }
3814         else
3815         {
3816                 v = base;
3817         }
3818
3819         return v;
3820 }
3821
3822 void display_rumor(bool ex)
3823 {
3824         errr err;
3825         int section = 0;
3826         char Rumor[1024];
3827
3828         if (ex)
3829         {
3830                 if (randint0(3) == 0) section = 1;
3831         }
3832
3833         err = _(get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10),
3834                         get_rnd_line("rumors.txt", section, Rumor));
3835         if (err) strcpy(Rumor, _("嘘の噂もある。", "Some rumors are wrong."));
3836
3837         err = TRUE;
3838
3839         if (strncmp(Rumor, "R:", 2) == 0)
3840         {
3841                 char *zz[4];
3842                 concptr rumor_msg = NULL;
3843                 concptr rumor_eff_format = NULL;
3844                 char fullname[1024] = "";
3845
3846                 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
3847                 {
3848                         if (strcmp(zz[0], "ARTIFACT") == 0)
3849                         {
3850                                 IDX a_idx, k_idx;
3851                                 object_type forge;
3852                                 object_type *q_ptr = &forge;
3853                                 artifact_type *a_ptr;
3854
3855                                 while (1)
3856                                 {
3857                                         a_idx = rumor_num(zz[1], max_a_idx);
3858
3859                                         a_ptr = &a_info[a_idx];
3860                                         if (a_ptr->name) break;
3861                                 }
3862
3863                                 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
3864                                 object_prep(q_ptr, k_idx);
3865                                 q_ptr->name1 = a_idx;
3866                                 q_ptr->ident = IDENT_STORE;
3867                                 object_desc(fullname, q_ptr, OD_NAME_ONLY);
3868                         }
3869                         else if  (strcmp(zz[0], "MONSTER") == 0)
3870                         {
3871                                 MONRACE_IDX r_idx;
3872                                 monster_race *r_ptr;
3873
3874                                 while(1)
3875                                 {
3876                                         r_idx = rumor_num(zz[1], max_r_idx);
3877                                         r_ptr = &r_info[r_idx];
3878                                         if (r_ptr->name) break;
3879                                 }
3880
3881                                 strcpy(fullname, r_name + r_ptr->name);
3882
3883                                 /* Remember this monster */
3884                                 if (!r_ptr->r_sights)
3885                                 {
3886                                         r_ptr->r_sights++;
3887                                 }
3888                         }
3889                         else if (strcmp(zz[0], "DUNGEON") == 0)
3890                         {
3891                                 DUNGEON_IDX d_idx;
3892                                 dungeon_info_type *d_ptr;
3893
3894                                 while (1)
3895                                 {
3896                                         d_idx = rumor_num(zz[1], max_d_idx);
3897                                         d_ptr = &d_info[d_idx];
3898                                         if (d_ptr->name) break;
3899                                 }
3900
3901                                 strcpy(fullname, d_name + d_ptr->name);
3902
3903                                 if (!max_dlv[d_idx])
3904                                 {
3905                                         max_dlv[d_idx] = d_ptr->mindepth;
3906                                         rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
3907                                 }
3908                         }
3909                         else if  (strcmp(zz[0], "TOWN") == 0)
3910                         {
3911                                 IDX t_idx;
3912                                 s32b visit;
3913
3914                                 while(1)
3915                                 {
3916                                         t_idx = rumor_num(zz[1], NO_TOWN);
3917                                         if (town[t_idx].name) break;
3918                                 }
3919
3920                                 strcpy(fullname, town[t_idx].name);
3921
3922                                 visit = (1L << (t_idx - 1));
3923                                 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
3924                                 {
3925                                         p_ptr->visit |= visit;
3926                                         rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
3927                                 }
3928                         }
3929
3930                         rumor_msg = rumor_bind_name(zz[2], fullname);
3931                         msg_print(rumor_msg);
3932                         if (rumor_eff_format)
3933                         {
3934                                 msg_print(NULL);
3935                                 msg_format(rumor_eff_format, fullname);
3936                         }
3937                         err = FALSE;
3938                 }
3939         /* error */
3940         if (err) msg_print(_("この情報は間違っている。", "This information is wrong."));
3941         }
3942                         else
3943         {
3944                 msg_format("%s", Rumor);
3945         }
3946 }