OSDN Git Service

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