OSDN Git Service

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