OSDN Git Service

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