OSDN Git Service

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