OSDN Git Service

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