3 * @brief 雑多なその他の処理2 / effects of various "objects"
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.
16 #include "object-curse.h"
18 #include "monsterrace-hook.h"
19 #include "objectkind-hook.h"
21 #include "projection.h"
22 #include "spells-summon.h"
26 #define REWARD_CHANCE 10
30 * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
31 * Advance experience levels and print experience
34 void check_experience(void)
36 bool level_reward = FALSE;
37 bool level_mutation = FALSE;
38 bool level_inc_stat = FALSE;
39 bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
40 PLAYER_LEVEL old_lev = p_ptr->lev;
42 /* Hack -- lower limit */
43 if (p_ptr->exp < 0) p_ptr->exp = 0;
44 if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
45 if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
47 /* Hack -- upper limit */
48 if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
49 if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
50 if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
52 /* Hack -- maintain "max" experience */
53 if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
55 /* Hack -- maintain "max max" experience */
56 if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
58 /* Redraw experience */
59 p_ptr->redraw |= (PR_EXP);
63 /* Lose levels while possible */
64 while ((p_ptr->lev > 1) &&
65 (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
69 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
70 p_ptr->redraw |= (PR_LEV | PR_TITLE);
71 p_ptr->window |= (PW_PLAYER);
76 /* Gain levels while possible */
77 while ((p_ptr->lev < PY_MAX_LEVEL) &&
78 (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
83 /* Save the highest level */
84 if (p_ptr->lev > p_ptr->max_plv)
86 p_ptr->max_plv = p_ptr->lev;
88 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
89 (p_ptr->muta2 & MUT2_CHAOS_GIFT))
93 if (p_ptr->prace == RACE_BEASTMAN)
95 if (one_in_(5)) level_mutation = TRUE;
97 level_inc_stat = TRUE;
99 do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
104 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
106 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
107 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
108 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
118 if(!(p_ptr->max_plv % 10))
127 cnv_stat(p_ptr->stat_max[0], tmp);
128 prt(format(_(" a) 腕力 (現在値 %s)", " a) Str (cur %s)"), tmp), 2, 14);
129 cnv_stat(p_ptr->stat_max[1], tmp);
130 prt(format(_(" b) 知能 (現在値 %s)", " a) Int (cur %s)"), tmp), 3, 14);
131 cnv_stat(p_ptr->stat_max[2], tmp);
132 prt(format(_(" c) 賢さ (現在値 %s)", " a) Wis (cur %s)"), tmp), 4, 14);
133 cnv_stat(p_ptr->stat_max[3], tmp);
134 prt(format(_(" d) 器用 (現在値 %s)", " a) Dex (cur %s)"), tmp), 5, 14);
135 cnv_stat(p_ptr->stat_max[4], tmp);
136 prt(format(_(" e) 耐久 (現在値 %s)", " a) Con (cur %s)"), tmp), 6, 14);
137 cnv_stat(p_ptr->stat_max[5], tmp);
138 prt(format(_(" f) 魅力 (現在値 %s)", " a) Chr (cur %s)"), tmp), 7, 14);
141 prt(_(" どの能力値を上げますか?", " Which stat do you want to raise?"), 1, 14);
146 if ((choice >= 'a') && (choice <= 'f')) break;
148 for(n = 0; n < A_MAX; n++)
149 if (n != choice - 'a')
151 if (get_check(_("よろしいですか?", "Are you sure? "))) break;
153 do_inc_stat(choice - 'a');
156 else if(!(p_ptr->max_plv % 2))
157 do_inc_stat(randint0(6));
162 msg_print(_("あなたは変わった気がする...", "You feel different..."));
163 (void)gain_random_mutation(0);
164 level_mutation = FALSE;
168 * 報酬でレベルが上ると再帰的に check_experience() が
173 gain_level_reward(0);
174 level_reward = FALSE;
177 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
178 p_ptr->redraw |= (PR_LEV | PR_TITLE);
179 p_ptr->window |= (PW_PLAYER | PW_SPELL);
183 /* Load an autopick preference file */
184 if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
190 * @brief クエストを達成状態にする /
191 * @param quest_num 達成状態にしたいクエストのID
194 void complete_quest(QUEST_IDX quest_num)
196 quest_type* const q_ptr = &quest[quest_num];
200 case QUEST_TYPE_RANDOM:
201 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
204 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
208 q_ptr->status = QUEST_STATUS_COMPLETED;
209 q_ptr->complev = p_ptr->lev;
211 q_ptr->comptime = playtime;
213 if (!(q_ptr->flags & QUEST_FLAG_SILENT))
215 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
216 msg_print(_("クエストを達成した!", "You just completed your quest!"));
222 * @brief 現在フロアに残っている敵モンスターの数を返す /
223 * @return 現在の敵モンスターの数
225 static MONSTER_NUMBER count_all_hostile_monsters(void)
228 MONSTER_NUMBER number_mon = 0;
230 for (x = 0; x < cur_wid; ++ x)
232 for (y = 0; y < cur_hgt; ++ y)
234 MONSTER_IDX m_idx = cave[y][x].m_idx;
236 if (m_idx > 0 && is_hostile(&m_list[m_idx]))
247 * @brief 特定の敵を倒した際にクエスト達成処理 /
248 * Check for "Quest" completion when a quest monster is killed or charmed.
249 * @param m_ptr 撃破したモンスターの構造体参照ポインタ
252 void check_quest_completion(monster_type *m_ptr)
257 bool create_stairs = FALSE;
267 quest_num = p_ptr->inside_quest;
269 /* Search for an active quest on this dungeon level */
274 for (i = max_q_idx - 1; i > 0; i--)
276 quest_type* const q_ptr = &quest[i];
278 /* Quest is not active */
279 if (q_ptr->status != QUEST_STATUS_TAKEN)
282 /* Quest is not a dungeon quest */
283 if (q_ptr->flags & QUEST_FLAG_PRESET)
286 /* Quest is not on this level */
287 if ((q_ptr->level != dun_level) &&
288 (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
291 /* Not a "kill monster" quest */
292 if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
293 (q_ptr->type == QUEST_TYPE_FIND_EXIT))
296 /* Interesting quest */
297 if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
298 (q_ptr->type == QUEST_TYPE_TOWER) ||
299 (q_ptr->type == QUEST_TYPE_KILL_ALL))
302 /* Interesting quest */
303 if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
304 (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
305 (q_ptr->type == QUEST_TYPE_RANDOM)) &&
306 (q_ptr->r_idx == m_ptr->r_idx))
313 /* Handle the current quest */
314 if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
317 quest_type* const q_ptr = &quest[quest_num];
321 case QUEST_TYPE_KILL_NUMBER:
325 if (q_ptr->cur_num >= q_ptr->num_mon)
327 complete_quest(quest_num);
333 case QUEST_TYPE_KILL_ALL:
335 if (!is_hostile(m_ptr)) break;
337 if (count_all_hostile_monsters() == 1)
339 if (q_ptr->flags & QUEST_FLAG_SILENT)
341 q_ptr->status = QUEST_STATUS_FINISHED;
345 complete_quest(quest_num);
350 case QUEST_TYPE_KILL_LEVEL:
351 case QUEST_TYPE_RANDOM:
353 /* Only count valid monsters */
354 if (q_ptr->r_idx != m_ptr->r_idx)
359 if (q_ptr->cur_num >= q_ptr->max_num)
361 complete_quest(quest_num);
363 if (!(q_ptr->flags & QUEST_FLAG_PRESET))
365 create_stairs = TRUE;
366 p_ptr->inside_quest = 0;
369 /* Finish the two main quests without rewarding */
370 if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
372 q_ptr->status = QUEST_STATUS_FINISHED;
375 if (q_ptr->type == QUEST_TYPE_RANDOM)
378 q_ptr->status = QUEST_STATUS_FINISHED;
383 case QUEST_TYPE_KILL_ANY_LEVEL:
386 if (q_ptr->cur_num >= q_ptr->max_num)
388 complete_quest(quest_num);
393 case QUEST_TYPE_TOWER:
395 if (!is_hostile(m_ptr)) break;
397 if (count_all_hostile_monsters() == 1)
399 q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
401 if((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
402 (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
403 (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
406 complete_quest(QUEST_TOWER1);
414 /* Create a magical staircase */
420 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT) )
422 /* Pick a location */
423 scatter(&ny, &nx, y, x, 1, 0);
429 /* Explain the staircase */
430 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
432 /* Create stairs down */
433 cave_set_feat(y, x, feat_down_stair);
435 /* Remember to update everything */
436 p_ptr->update |= (PU_FLOW);
446 for (i = 0; i < (dun_level / 15)+1; i++)
451 /* Make a great object */
452 make_object(o_ptr, AM_GOOD | AM_GREAT);
453 (void)drop_near(o_ptr, -1, y, x);
459 * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
460 * Check for "Quest" completion when a quest monster is killed or charmed.
461 * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
464 void check_find_art_quest_completion(object_type *o_ptr)
467 /* Check if completed a quest */
468 for (i = 0; i < max_q_idx; i++)
470 if((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
471 (quest[i].status == QUEST_STATUS_TAKEN) &&
472 (quest[i].k_idx == o_ptr->name1))
481 * @brief モンスターを撃破した際の述語メッセージを返す /
482 * Return monster death string
483 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
484 * @return 撃破されたモンスターの述語
486 concptr extract_note_dies(MONRACE_IDX r_idx)
488 monster_race *r_ptr = &r_info[r_idx];
489 /* Some monsters get "destroyed" */
490 if (!monster_living(r_idx))
494 for (i = 0; i < 4; i++)
496 if (r_ptr->blow[i].method == RBM_EXPLODE)
498 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
501 return _("を倒した。", " is destroyed.");
504 /* Assume a default death */
505 return _("は死んだ。", " dies.");
510 * @brief モンスターに与えたダメージの修正処理 /
511 * Modify the physical damage done to the monster.
512 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
514 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
515 * @return 修正を行った結果のダメージ量
518 * (for example when it's invulnerable or shielded)
519 * ToDo: Accept a damage-type to calculate the modified damage from
520 * things like fire, frost, lightning, poison, ... attacks.
521 * "type" is not yet used and should be 0.
524 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
526 monster_race *r_ptr = &r_info[m_ptr->r_idx];
528 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
531 if ((dam == 0) && one_in_(3)) dam = 1;
534 if (MON_INVULNER(m_ptr))
538 if (!p_ptr->blind && is_seen(m_ptr))
540 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
543 else if (!one_in_(PENETRATE_INVULNERABILITY))
553 * @brief モンスターに与えたダメージを元に経験値を加算する /
554 * Calculate experience point to be get
555 * @param dam 与えたダメージ量
556 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
560 * Even the 64 bit operation is not big enough to avoid overflaw
561 * unless we carefully choose orders of multiplication and division.
562 * Get the coefficient first, and multiply (potentially huge) base
563 * experience point of a monster later.
566 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
568 monster_race *r_ptr = &r_info[m_ptr->r_idx];
575 if (!m_ptr->r_idx) return;
576 if (is_pet(m_ptr) || p_ptr->inside_battle) return;
579 * - Ratio of monster's level to player's level effects
580 * - Varying speed effects
581 * - Get a fraction in proportion of damage point
583 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
586 div_l = (p_ptr->max_plv+2) * SPEED_TO_ENERGY(r_ptr->speed);
588 /* Use (average maxhp * 2) as a denominator */
589 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
590 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
592 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
594 /* Special penalty in the wilderness */
595 if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
596 s64b_mul(&div_h, &div_l, 0, 5);
598 /* Do division first to prevent overflaw */
599 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
601 /* Special penalty for mutiply-monster */
602 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
604 int monnum_penarty = r_ptr->r_akills / 400;
605 if (monnum_penarty > 8) monnum_penarty = 8;
607 while (monnum_penarty--)
610 s64b_RSHIFT(new_exp, new_exp_frac, 2);
614 /* Special penalty for rest_and_shoot exp scum */
615 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
617 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
618 if (over_damage > 32) over_damage = 32;
620 while (over_damage--)
623 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
624 s64b_div(&new_exp, &new_exp_frac, 0, 10);
628 /* Finally multiply base experience point of the monster */
629 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
631 /* Gain experience */
632 gain_exp_64(new_exp, new_exp_frac);
637 * @brief モンスターのHPをダメージに応じて減算する /
638 * Decreases monsters hit points, handling monster death.
639 * @param dam 与えたダメージ量
640 * @param m_idx ダメージを与えたモンスターのID
641 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
642 * @param note モンスターが倒された際の特別なメッセージ述語
646 * We return TRUE if the monster has been killed (and deleted).
647 * We announce monster death (using an optional "death message"
648 * if given, and a otherwise a generic killed/destroyed message).
649 * Only "physical attacks" can induce the "You have slain" message.
650 * Missile and Spell attacks will induce the "dies" message, or
651 * various "specialized" messages. Note that "You have destroyed"
652 * and "is destroyed" are synonyms for "You have slain" and "dies".
653 * Hack -- unseen monsters yield "You have killed it." message.
654 * Added fear (DGK) and check whether to print fear messages -CWS
655 * Made name, sex, and capitalization generic -BEN-
656 * As always, the "ghost" processing is a total hack.
657 * Hack -- we "delay" fear messages by passing around a "fear" flag.
658 * Consider decreasing monster experience over time, say,
659 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
660 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
661 * monster worth more than subsequent monsters. This would also need
662 * to induce changes in the monster recall code.
665 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
667 monster_type *m_ptr = &m_list[m_idx];
668 monster_race *r_ptr = &r_info[m_ptr->r_idx];
669 monster_type exp_mon;
671 /* Innocent until proven otherwise */
672 bool innocent = TRUE, thief = FALSE;
676 (void)COPY(&exp_mon, m_ptr, monster_type);
678 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
680 get_exp_from_mon(expdam, &exp_mon);
682 /* Genocided by chaos patron */
683 if (!m_ptr->r_idx) m_idx = 0;
685 /* Redraw (later) if needed */
686 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
687 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
689 (void)set_monster_csleep(m_idx, 0);
691 /* Hack - Cancel any special player stealth magics. -LM- */
692 if (p_ptr->special_defense & NINJA_S_STEALTH)
694 set_superstealth(FALSE);
697 /* Genocided by chaos patron */
698 if (!m_idx) return TRUE;
701 m_ptr->dealt_damage += dam;
703 if(m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
707 msg_format( _("合計%d/%dのダメージを与えた。","You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
713 GAME_TEXT m_name[MAX_NLEN];
715 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
717 /* You might have unmasked Tanuki first time */
718 r_ptr = &r_info[m_ptr->r_idx];
719 m_ptr->ap_r_idx = m_ptr->r_idx;
720 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
723 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
725 /* You might have unmasked Chameleon first time */
726 r_ptr = real_r_ptr(m_ptr);
727 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
730 if (!(m_ptr->smart & SM_CLONED))
732 /* When the player kills a Unique, it stays dead */
733 if (r_ptr->flags1 & RF1_UNIQUE)
737 /* Mega-Hack -- Banor & Lupart */
738 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
740 r_info[MON_BANORLUPART].max_num = 0;
741 r_info[MON_BANORLUPART].r_pkills++;
742 r_info[MON_BANORLUPART].r_akills++;
743 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
745 else if (m_ptr->r_idx == MON_BANORLUPART)
747 r_info[MON_BANOR].max_num = 0;
748 r_info[MON_BANOR].r_pkills++;
749 r_info[MON_BANOR].r_akills++;
750 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
751 r_info[MON_LUPART].max_num = 0;
752 r_info[MON_LUPART].r_pkills++;
753 r_info[MON_LUPART].r_akills++;
754 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
758 /* When the player kills a Nazgul, it stays dead */
759 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
762 /* Count all monsters killed */
763 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
765 /* Recall even invisible uniques or winners */
766 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
768 /* Count kills this life */
769 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
770 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
772 /* Count kills in all lives */
773 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
774 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
776 /* Hack -- Auto-recall */
777 monster_race_track(m_ptr->ap_r_idx);
780 /* Extract monster name */
781 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
783 /* Don't kill Amberites */
784 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
786 int curses = 1 + randint1(3);
787 bool stop_ty = FALSE;
790 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
791 curse_equipment(100, 50);
795 stop_ty = activate_ty_curse(stop_ty, &count);
800 if (r_ptr->flags2 & RF2_CAN_SPEAK)
803 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
805 msg_format("%^s %s", m_name, line_got);
809 if (m_ptr->r_idx == MON_SERPENT)
811 screen_dump = make_screen_dump();
816 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
818 if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
820 chg_virtue(V_VALOUR, -1);
822 else if (r_ptr->level > dun_level)
824 if (randint1(10) <= (r_ptr->level - dun_level))
825 chg_virtue(V_VALOUR, 1);
827 if (r_ptr->level > 60)
829 chg_virtue(V_VALOUR, 1);
831 if (r_ptr->level >= 2 * (p_ptr->lev+1))
832 chg_virtue(V_VALOUR, 2);
835 if (r_ptr->flags1 & RF1_UNIQUE)
837 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
839 if (r_ptr->flags3 & RF3_GOOD)
841 chg_virtue(V_UNLIFE, 2);
842 chg_virtue(V_VITALITY, -2);
845 if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
848 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
850 chg_virtue(V_COMPASSION, -1);
853 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
854 chg_virtue(V_UNLIFE, 1);
856 if (r_ptr->d_char == 'A')
858 if (r_ptr->flags1 & RF1_UNIQUE)
859 chg_virtue(V_FAITH, -2);
860 else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
862 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
863 else chg_virtue(V_FAITH, 1);
866 else if (r_ptr->flags3 & RF3_DEMON)
868 if (r_ptr->flags1 & RF1_UNIQUE)
869 chg_virtue(V_FAITH, 2);
870 else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
871 chg_virtue(V_FAITH, 1);
874 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
875 chg_virtue(V_VITALITY, 2);
879 if (r_ptr->flags1 & RF1_UNIQUE)
881 chg_virtue(V_HONOUR, 10);
883 else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
885 chg_virtue(V_HONOUR, 1);
888 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
890 chg_virtue(V_VALOUR, -1);
893 for (i = 0; i < 4; i++)
895 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
897 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
898 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
900 thief = TRUE; /* Thief! */
903 /* The new law says it is illegal to live in the dungeon */
904 if (r_ptr->level != 0) innocent = FALSE;
908 if (r_ptr->flags1 & RF1_UNIQUE)
909 chg_virtue(V_JUSTICE, 3);
910 else if (1+((r_ptr->level) / 10 + (2 * dun_level)) >= randint1(100))
911 chg_virtue(V_JUSTICE, 1);
915 chg_virtue (V_JUSTICE, -1);
918 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)))
920 if (one_in_(4)) chg_virtue(V_NATURE, -1);
923 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
926 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
927 do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
933 /* Death by Missile/Spell attack */
936 msg_format("%^s%s", m_name, note);
939 /* Death by physical attack -- invisible monster */
943 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
944 msg_format("せっかくだから%sを殺した。", m_name);
946 msg_format("%sを殺した。", m_name);
948 msg_format("You have killed %s.", m_name);
953 /* Death by Physical attack -- non-living monster */
954 else if (!monster_living(m_ptr->r_idx))
956 bool explode = FALSE;
958 for (i = 0; i < 4; i++)
960 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
963 /* Special note at death */
965 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
969 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
970 msg_format("せっかくだから%sを倒した。", m_name);
972 msg_format("%sを倒した。", m_name);
974 msg_format("You have destroyed %s.", m_name);
979 /* Death by Physical attack -- living monster */
983 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
984 msg_format("せっかくだから%sを葬り去った。", m_name);
986 msg_format("%sを葬り去った。", m_name);
988 msg_format("You have slain %s.", m_name);
992 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
994 for (i = 0; i < MAX_KUBI; i++)
996 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
998 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1004 /* Generate treasure */
1005 monster_death(m_idx, TRUE);
1007 /* Mega hack : replace IKETA to BIKETAL */
1008 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1010 POSITION dummy_y = m_ptr->fy;
1011 POSITION dummy_x = m_ptr->fx;
1012 BIT_FLAGS mode = 0L;
1013 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1014 delete_monster_idx(m_idx);
1015 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1017 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1022 delete_monster_idx(m_idx);
1025 get_exp_from_mon((long)exp_mon.max_maxhp*2, &exp_mon);
1030 /* Monster is dead */
1037 /* Mega-Hack -- Pain cancels fear */
1038 if (MON_MONFEAR(m_ptr) && (dam > 0))
1041 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1048 /* Sometimes a monster gets scared by damage */
1049 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1051 /* Percentage of fully healthy */
1052 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1055 * Run (sometimes) if at 10% or less of max hit points,
1056 * or (usually) when hit for half its current hit points
1058 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1060 /* Hack -- note fear */
1063 /* Hack -- Add some timed fear */
1064 (void)set_monster_monfear(m_idx, (randint1(10) +
1065 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1066 20 : ((11 - percentage) * 5))));
1078 * @brief 現在のコンソール表示の縦横を返す。 /
1079 * Get term size and calculate screen size
1080 * @param wid_p コンソールの表示幅文字数を返す
1081 * @param hgt_p コンソールの表示行数を返す
1084 void get_screen_size(TERM_LEN *wid_p, TERM_LEN *hgt_p)
1086 Term_get_size(wid_p, hgt_p);
1087 *hgt_p -= ROW_MAP + 2;
1088 *wid_p -= COL_MAP + 2;
1089 if (use_bigtile) *wid_p /= 2;
1094 * @brief コンソール上におけるマップ表示の左上位置を返す /
1095 * Calculates current boundaries Called below and from "do_cmd_locate()".
1098 void panel_bounds_center(void)
1102 get_screen_size(&wid, &hgt);
1104 panel_row_max = panel_row_min + hgt - 1;
1105 panel_row_prt = panel_row_min - 1;
1106 panel_col_max = panel_col_min + wid - 1;
1107 panel_col_prt = panel_col_min - 13;
1112 * @brief コンソールのリサイズに合わせてマップを再描画する /
1113 * Map resizing whenever the main term changes size
1116 void resize_map(void)
1118 /* Only if the dungeon exists */
1119 if (!character_dungeon) return;
1121 /* Mega-Hack -- no panel yet */
1125 /* Reset the panels */
1126 panel_row_min = cur_hgt;
1127 panel_col_min = cur_wid;
1131 p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
1132 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
1133 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1134 p_ptr->update |= (PU_MONSTERS);
1135 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
1142 * Place the cursor on the player
1144 if (can_save) move_cursor_relative(p_ptr->y, p_ptr->x);
1150 * @brief コンソールを再描画する /
1151 * Redraw a term when it is resized
1154 void redraw_window(void)
1156 /* Only if the dungeon exists */
1157 if (!character_dungeon) return;
1159 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1160 p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
1168 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
1169 * @param dy 変更先のフロアY座標
1170 * @param dx 変更先のフロアX座標
1171 * Handle a request to change the current panel
1172 * Return TRUE if the panel was changed.
1173 * Also used in do_cmd_locate
1174 * @return 実際に再描画が必要だった場合TRUEを返す
1176 bool change_panel(POSITION dy, POSITION dx)
1181 get_screen_size(&wid, &hgt);
1183 /* Apply the motion */
1184 y = panel_row_min + dy * hgt / 2;
1185 x = panel_col_min + dx * wid / 2;
1187 /* Verify the row */
1188 if (y > cur_hgt - hgt) y = cur_hgt - hgt;
1191 /* Verify the col */
1192 if (x > cur_wid - wid) x = cur_wid - wid;
1195 /* Handle "changes" */
1196 if ((y != panel_row_min) || (x != panel_col_min))
1198 /* Save the new panel info */
1202 /* Recalculate the boundaries */
1203 panel_bounds_center();
1205 p_ptr->update |= (PU_MONSTERS);
1206 p_ptr->redraw |= (PR_MAP);
1218 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
1219 * @param y 変更先のフロアY座標
1220 * @param x 変更先のフロアX座標
1222 * Handle a request to change the current panel
1223 * Return TRUE if the panel was changed.
1224 * Also used in do_cmd_locate
1225 * @return 実際に再描画が必要だった場合TRUEを返す
1227 static bool change_panel_xy(POSITION y, POSITION x)
1229 POSITION dy = 0, dx = 0;
1232 get_screen_size(&wid, &hgt);
1234 if (y < panel_row_min) dy = -1;
1235 if (y > panel_row_max) dy = 1;
1236 if (x < panel_col_min) dx = -1;
1237 if (x > panel_col_max) dx = 1;
1239 if (!dy && !dx) return (FALSE);
1241 return change_panel(dy, dx);
1246 * @brief マップ描画のフォーカスを当てるべき座標を更新する
1248 * Given an row (y) and col (x), this routine detects when a move
1249 * off the screen has occurred and figures new borders. -RAK-
1250 * "Update" forces a "full update" to take place.
1251 * The map is reprinted if necessary, and "TRUE" is returned.
1252 * @return 実際に再描画が必要だった場合TRUEを返す
1254 void verify_panel(void)
1256 POSITION y = p_ptr->y;
1257 POSITION x = p_ptr->x;
1265 get_screen_size(&wid, &hgt);
1267 max_prow_min = cur_hgt - hgt;
1268 max_pcol_min = cur_wid - wid;
1270 /* Bounds checking */
1271 if (max_prow_min < 0) max_prow_min = 0;
1272 if (max_pcol_min < 0) max_pcol_min = 0;
1274 /* Center on player */
1275 if (center_player && (center_running || !running))
1277 /* Center vertically */
1278 prow_min = y - hgt / 2;
1279 if (prow_min < 0) prow_min = 0;
1280 else if (prow_min > max_prow_min) prow_min = max_prow_min;
1282 /* Center horizontally */
1283 pcol_min = x - wid / 2;
1284 if (pcol_min < 0) pcol_min = 0;
1285 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1289 prow_min = panel_row_min;
1290 pcol_min = panel_col_min;
1292 /* Scroll screen when 2 grids from top/bottom edge */
1293 if (y > panel_row_max - 2)
1295 while (y > prow_min + hgt-1 - 2)
1297 prow_min += (hgt / 2);
1301 if (y < panel_row_min + 2)
1303 while (y < prow_min + 2)
1305 prow_min -= (hgt / 2);
1309 if (prow_min > max_prow_min) prow_min = max_prow_min;
1310 if (prow_min < 0) prow_min = 0;
1312 /* Scroll screen when 4 grids from left/right edge */
1313 if (x > panel_col_max - 4)
1315 while (x > pcol_min + wid-1 - 4)
1317 pcol_min += (wid / 2);
1321 if (x < panel_col_min + 4)
1323 while (x < pcol_min + 4)
1325 pcol_min -= (wid / 2);
1329 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1330 if (pcol_min < 0) pcol_min = 0;
1333 /* Check for "no change" */
1334 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
1336 /* Save the new panel info */
1337 panel_row_min = prow_min;
1338 panel_col_min = pcol_min;
1340 /* Hack -- optional disturb on "panel change" */
1341 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
1343 /* Recalculate the boundaries */
1344 panel_bounds_center();
1346 p_ptr->update |= (PU_MONSTERS);
1347 p_ptr->redraw |= (PR_MAP);
1348 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1353 * Monster health description
1355 concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
1357 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1364 /* Determine if the monster is "living" */
1365 living = monster_living(m_ptr->ap_r_idx);
1367 /* Calculate a health "percentage" */
1368 perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
1370 /* Healthy monsters */
1371 if (m_ptr->hp >= m_ptr->maxhp)
1373 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
1376 else if (perc >= 60)
1378 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
1381 else if (perc >= 25)
1383 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
1386 else if (perc >= 10)
1388 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
1393 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
1396 /* Need attitude information? */
1399 /* Full information is not needed */
1402 else if (is_pet(m_ptr))
1404 attitude = _(", ペット", ", pet");
1406 else if (is_friendly(m_ptr))
1408 attitude = _(", 友好的", ", friendly");
1412 attitude = _("", "");
1415 /* Clone monster? */
1416 if (m_ptr->smart & SM_CLONED)
1425 /* Display monster's level --- idea borrowed from ToME */
1426 if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
1428 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
1432 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
1439 /*** Targeting Code ***/
1443 * Determine is a monster makes a reasonable target
1445 * The concept of "targeting" was stolen from "Morgul" (?)
1447 * The player can target any location, or any "target-able" monster.
1449 * Currently, a monster is "target_able" if it is visible, and if
1450 * the player can hit it with a projection, and the player is not
1451 * hallucinating. This allows use of "use closest target" macros.
1453 * Future versions may restrict the ability to target "trappers"
1454 * and "mimics", but the semantics is a little bit weird.
1456 bool target_able(MONSTER_IDX m_idx)
1458 monster_type *m_ptr = &m_list[m_idx];
1460 /* Monster must be alive */
1461 if (!m_ptr->r_idx) return (FALSE);
1463 /* Hack -- no targeting hallucinations */
1464 if (p_ptr->image) return (FALSE);
1466 /* Monster must be visible */
1467 if (!m_ptr->ml) return (FALSE);
1469 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
1471 /* Monster must be projectable */
1472 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
1474 /* Hack -- Never target trappers */
1475 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
1485 * Update (if necessary) and verify (if possible) the target.
1487 * We return TRUE if the target is "okay" and FALSE otherwise.
1489 bool target_okay(void)
1491 /* Accept stationary targets */
1492 if (target_who < 0) return (TRUE);
1494 /* Check moving targets */
1497 /* Accept reasonable targets */
1498 if (target_able(target_who))
1500 monster_type *m_ptr = &m_list[target_who];
1502 /* Acquire monster location */
1503 target_row = m_ptr->fy;
1504 target_col = m_ptr->fx;
1511 /* Assume no target */
1517 * Sorting hook -- comp function -- by "distance to player"
1519 * We use "u" and "v" to point to arrays of "x" and "y" positions,
1520 * and sort the arrays by double-distance to the player.
1522 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
1524 POSITION *x = (POSITION*)(u);
1525 POSITION *y = (POSITION*)(v);
1527 POSITION da, db, kx, ky;
1529 /* Absolute distance components */
1530 kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
1531 ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
1533 /* Approximate Double Distance to the first point */
1534 da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
1536 /* Absolute distance components */
1537 kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
1538 ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
1540 /* Approximate Double Distance to the first point */
1541 db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
1543 /* Compare the distances */
1549 * Sorting hook -- comp function -- by importance level of grids
1551 * We use "u" and "v" to point to arrays of "x" and "y" positions,
1552 * and sort the arrays by level of monster
1554 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
1556 POSITION *x = (POSITION*)(u);
1557 POSITION *y = (POSITION*)(v);
1558 cave_type *ca_ptr = &cave[y[a]][x[a]];
1559 cave_type *cb_ptr = &cave[y[b]][x[b]];
1560 monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
1561 monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
1562 monster_race *ap_ra_ptr, *ap_rb_ptr;
1564 /* The player grid */
1565 if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
1566 if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
1568 /* Extract monster race */
1569 if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
1570 else ap_ra_ptr = NULL;
1571 if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
1572 else ap_rb_ptr = NULL;
1574 if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
1575 if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
1577 /* Compare two monsters */
1578 if (ap_ra_ptr && ap_rb_ptr)
1580 /* Unique monsters first */
1581 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
1582 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
1584 /* Shadowers first (あやしい影) */
1585 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
1586 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
1588 /* Unknown monsters first */
1589 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
1590 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
1592 /* Higher level monsters first (if known) */
1593 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
1595 if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
1596 if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
1599 /* Sort by index if all conditions are same */
1600 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
1601 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
1604 /* An object get higher priority */
1605 if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
1606 if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
1608 /* Priority from the terrain */
1609 if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
1610 if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
1612 /* If all conditions are same, compare distance */
1613 return ang_sort_comp_distance(u, v, a, b);
1618 * Sorting hook -- swap function -- by "distance to player"
1620 * We use "u" and "v" to point to arrays of "x" and "y" positions,
1621 * and sort the arrays by distance to the player.
1623 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
1625 POSITION *x = (POSITION*)(u);
1626 POSITION *y = (POSITION*)(v);
1644 * Hack -- help "select" a location (see below)
1646 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
1649 POSITION x2, y2, x3, y3, x4, y4;
1650 POSITION_IDX b_i = -1, b_v = 9999;
1653 /* Scan the locations */
1654 for (i = 0; i < temp_n; i++)
1660 /* Directed distance */
1664 /* Verify quadrant */
1665 if (dx && (x3 * dx <= 0)) continue;
1666 if (dy && (y3 * dy <= 0)) continue;
1668 /* Absolute distance */
1672 /* Verify quadrant */
1673 if (dy && !dx && (x4 > y4)) continue;
1674 if (dx && !dy && (y4 > x4)) continue;
1676 /* Approximate Double Distance */
1677 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
1679 /* Penalize location */
1682 if ((b_i >= 0) && (v >= b_v)) continue;
1692 * Hack -- determine if a given location is "interesting"
1694 static bool target_set_accept(POSITION y, POSITION x)
1697 OBJECT_IDX this_o_idx, next_o_idx = 0;
1700 if (!(in_bounds(y, x))) return (FALSE);
1702 /* Player grid is always interesting */
1703 if (player_bold(y, x)) return (TRUE);
1705 /* Handle hallucination */
1706 if (p_ptr->image) return (FALSE);
1708 /* Examine the grid */
1709 c_ptr = &cave[y][x];
1711 /* Visible monsters */
1714 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1716 /* Visible monsters */
1717 if (m_ptr->ml) return (TRUE);
1720 /* Scan all objects in the grid */
1721 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1724 o_ptr = &o_list[this_o_idx];
1726 /* Acquire next object */
1727 next_o_idx = o_ptr->next_o_idx;
1729 /* Memorized object */
1730 if (o_ptr->marked & OM_FOUND) return (TRUE);
1733 /* Interesting memorized features */
1734 if (c_ptr->info & (CAVE_MARK))
1736 /* Notice object features */
1737 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
1739 /* Feature code (applying "mimic" field) */
1740 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
1748 * Prepare the "temp" array for "target_set"
1750 * Return the number of target_able monsters in the set.
1752 static void target_set_prepare(BIT_FLAGS mode)
1755 POSITION min_hgt, max_hgt, min_wid, max_wid;
1757 if (mode & TARGET_KILL)
1760 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
1761 max_hgt = MIN((p_ptr->y + MAX_RANGE), cur_hgt - 1);
1762 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
1763 max_wid = MIN((p_ptr->x + MAX_RANGE), cur_wid - 1);
1765 else /* not targetting */
1768 min_hgt = panel_row_min;
1769 max_hgt = panel_row_max;
1770 min_wid = panel_col_min;
1771 max_wid = panel_col_max;
1774 /* Reset "temp" array */
1777 /* Scan the current panel */
1778 for (y = min_hgt; y <= max_hgt; y++)
1780 for (x = min_wid; x <= max_wid; x++)
1784 /* Require "interesting" contents */
1785 if (!target_set_accept(y, x)) continue;
1787 c_ptr = &cave[y][x];
1789 /* Require target_able monsters for "TARGET_KILL" */
1790 if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
1792 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
1794 /* Save the location */
1801 /* Set the sort hooks */
1802 if (mode & (TARGET_KILL))
1804 /* Target the nearest monster for shooting */
1805 ang_sort_comp = ang_sort_comp_distance;
1806 ang_sort_swap = ang_sort_swap_distance;
1810 /* Look important grids first in Look command */
1811 ang_sort_comp = ang_sort_comp_importance;
1812 ang_sort_swap = ang_sort_swap_distance;
1815 /* Sort the positions */
1816 ang_sort(temp_x, temp_y, temp_n);
1818 if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
1823 temp_y[0] = temp_y[1];
1826 temp_x[0] = temp_x[1];
1831 void target_set_prepare_look(void){
1832 target_set_prepare(TARGET_LOOK);
1837 * Evaluate number of kill needed to gain level
1839 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
1841 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1843 s32b exp_mon, exp_adv;
1844 u32b exp_mon_frac, exp_adv_frac;
1846 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
1851 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
1861 /* The monster's experience point (assuming average monster speed) */
1862 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
1864 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
1867 /* Total experience value for next level */
1868 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
1870 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
1872 /* Experience value need to get */
1873 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
1876 /* You need to kill at least one monster to get any experience */
1877 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1878 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
1880 /* Extract number of monsters needed */
1881 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1883 /* If 999 or more monsters needed, only display "999". */
1884 num = MIN(999, exp_adv_frac);
1886 /* Display the number */
1887 sprintf(buf,"%03ld", (long int)num);
1891 bool show_gold_on_floor = FALSE;
1894 * Examine a grid, return a keypress.
1896 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
1897 * indicates that the "space" key should scan through the contents
1898 * of the grid, instead of simply returning immediately. This lets
1899 * the "look" command get complete information, without making the
1900 * "target" command annoying.
1902 * The "info" argument contains the "commands" which should be shown
1903 * inside the "[xxx]" text. This string must never be empty, or grids
1904 * containing monsters will be displayed with an extra comma.
1906 * Note that if a monster is in the grid, we update both the monster
1907 * recall info and the health bar info to track that monster.
1909 * Eventually, we may allow multiple objects per grid, or objects
1910 * and terrain features in the same grid.
1912 * This function must handle blindness/hallucination.
1914 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
1916 cave_type *c_ptr = &cave[y][x];
1917 OBJECT_IDX this_o_idx, next_o_idx = 0;
1918 concptr s1 = "", s2 = "", s3 = "", x_info = "";
1921 feature_type *f_ptr;
1922 char query = '\001';
1923 char out_val[MAX_NLEN+80];
1924 OBJECT_IDX floor_list[23];
1925 ITEM_NUMBER floor_num = 0;
1927 /* Scan all objects in the grid */
1930 floor_num = scan_floor(floor_list, y, x, 0x02);
1934 x_info = _("x物 ", "x,");
1938 /* Hack -- under the player */
1939 if (player_bold(y, x))
1952 s1 = _("ターゲット:", "Target:");
1955 /* Hack -- hallucination */
1958 concptr name = _("何か奇妙な物", "something strange");
1960 /* Display a message */
1962 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
1964 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1968 move_cursor_relative(y, x);
1971 /* Stop on everything but "return" */
1972 if ((query != '\r') && (query != '\n')) return query;
1974 /* Repeat forever */
1979 /* Actual monsters */
1980 if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1982 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1983 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1984 GAME_TEXT m_name[MAX_NLEN];
1985 bool recall = FALSE;
1990 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1991 monster_race_track(m_ptr->ap_r_idx);
1992 health_track(c_ptr->m_idx);
2005 /* Recall on screen */
2006 screen_roff(m_ptr->ap_r_idx, 0);
2008 /* Hack -- Complete the prompt (again) */
2009 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
2016 /* Normal commands */
2017 if (query != 'r') break;
2022 /* Cleare recall text and repeat */
2028 /* Describe, and prompt for recall */
2029 evaluate_monster_exp(acount, m_ptr);
2032 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);
2034 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);
2040 move_cursor_relative(y, x);
2045 /* Normal commands */
2046 if (query != 'r') break;
2052 /* Always stop at "normal" keys */
2053 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2055 /* Sometimes stop at "space" key */
2056 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2058 /* Change the intro */
2059 s1 = _("それは", "It is ");
2061 /* Hack -- take account of gender */
2062 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
2063 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
2065 /* Use a preposition */
2074 /* Scan all objects being carried */
2075 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
2077 GAME_TEXT o_name[MAX_NLEN];
2080 o_ptr = &o_list[this_o_idx];
2082 /* Acquire next object */
2083 next_o_idx = o_ptr->next_o_idx;
2085 /* Obtain an object description */
2086 object_desc(o_name, o_ptr, 0);
2089 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2091 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2095 move_cursor_relative(y, x);
2098 /* Always stop at "normal" keys */
2099 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2101 /* Sometimes stop at "space" key */
2102 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2104 /* Change the intro */
2105 s2 = _("をまた", "also carrying ");
2108 /* Use a preposition */
2125 GAME_TEXT o_name[MAX_NLEN];
2128 o_ptr = &o_list[floor_list[0]];
2130 object_desc(o_name, o_ptr, 0);
2133 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2135 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2139 move_cursor_relative(y, x);
2148 /* Provide one cushion before item listing */
2151 /* Display rough information about items */
2153 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
2155 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
2159 move_cursor_relative(y, x);
2164 /* No request for listing */
2165 if (query != 'x' && query != ' ') return query;
2169 /** Display list of items **/
2171 /* Continue scrolling list if requested */
2179 show_gold_on_floor = TRUE;
2180 (void)show_floor(0, y, x, &min_width);
2181 show_gold_on_floor = FALSE;
2185 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
2187 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
2194 /* Exit unless 'Enter' */
2195 if (query != '\n' && query != '\r')
2200 /* Get the object being moved. */
2201 o_idx = c_ptr->o_idx;
2203 /* Only rotate a pile of two or more objects. */
2204 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
2206 /* Remove the first object from the list. */
2207 excise_object_idx(o_idx);
2209 /* Find end of the list. */
2211 while (o_list[i].next_o_idx)
2212 i = o_list[i].next_o_idx;
2214 /* Add after the last object. */
2215 o_list[i].next_o_idx = o_idx;
2217 /* Loop and re-display the list */
2224 /* Scan all objects in the grid */
2225 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2228 o_ptr = &o_list[this_o_idx];
2230 /* Acquire next object */
2231 next_o_idx = o_ptr->next_o_idx;
2233 if (o_ptr->marked & OM_FOUND)
2235 GAME_TEXT o_name[MAX_NLEN];
2240 /* Obtain an object description */
2241 object_desc(o_name, o_ptr, 0);
2244 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2246 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2250 move_cursor_relative(y, x);
2253 /* Always stop at "normal" keys */
2254 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2256 /* Sometimes stop at "space" key */
2257 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
2259 /* Change the intro */
2260 s1 = _("それは", "It is ");
2263 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
2277 /* Feature code (applying "mimic" field) */
2278 feat = get_feat_mimic(c_ptr);
2280 /* Require knowledge about grid, or ability to see grid */
2281 if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
2283 /* Forget feature */
2287 f_ptr = &f_info[feat];
2289 /* Terrain feature if needed */
2290 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
2294 /* Hack -- special handling for quest entrances */
2295 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
2297 /* Set the quest number temporary */
2298 IDX old_quest = p_ptr->inside_quest;
2301 /* Clear the text */
2302 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
2303 quest_text_line = 0;
2305 p_ptr->inside_quest = c_ptr->special;
2307 /* Get the quest text */
2308 init_flags = INIT_NAME_ONLY;
2310 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
2312 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
2313 quest[c_ptr->special].name, quest[c_ptr->special].level);
2315 /* Reset the old quest number */
2316 p_ptr->inside_quest = old_quest;
2319 /* Hack -- special handling for building doors */
2320 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
2322 name = building[f_ptr->subtype].name;
2324 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
2326 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
2328 else if (have_flag(f_ptr->flags, FF_TOWN))
2330 name = town[c_ptr->special].name;
2332 else if (p_ptr->wild_mode && (feat == feat_floor))
2334 name = _("道", "road");
2338 name = f_name + f_ptr->name;
2344 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
2345 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
2346 have_flag(f_ptr->flags, FF_TOWN)))
2348 s2 = _("の中", "in ");
2351 /* Hack -- special introduction for store & building doors -KMW- */
2352 if (have_flag(f_ptr->flags, FF_STORE) ||
2353 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
2354 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
2355 have_flag(f_ptr->flags, FF_ENTRANCE))
2360 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
2361 have_flag(f_ptr->flags, FF_TOWN) ||
2362 have_flag(f_ptr->flags, FF_SHALLOW) ||
2363 have_flag(f_ptr->flags, FF_DEEP))
2369 /* Pick proper indefinite article */
2370 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
2374 /* Display a message */
2378 if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
2379 else sprintf(f_idx_str, "%d", c_ptr->feat);
2381 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]);
2383 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);
2388 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
2390 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
2394 move_cursor_relative(y, x);
2397 /* Always stop at "normal" keys */
2398 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
2401 /* Stop on everything but "return" */
2402 if ((query != '\r') && (query != '\n')) return query;
2404 /* Repeat forever */
2410 * Handle "target" and "look".
2412 * Note that this code can be called from "get_aim_dir()".
2414 * All locations must be on the current panel. Consider the use of
2415 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
2416 * some form of "scrolling" the map around the cursor.
2417 * That is, consider the possibility of "auto-scrolling" the screen
2418 * while the cursor moves around. This may require changes in the
2419 * "update_monster()" code to allow "visibility" even if off panel, and
2420 * may require dynamic recalculation of the "temp" grid set.
2422 * Hack -- targeting/observing an "outer border grid" may induce
2423 * problems, so this is not currently allowed.
2425 * The player can use the direction keys to move among "interesting"
2426 * grids in a heuristic manner, or the "space", "+", and "-" keys to
2427 * move through the "interesting" grids in a sequential manner, or
2428 * can enter "location" mode, and use the direction keys to move one
2429 * grid at a time in any direction. The "t" (set target) command will
2430 * only target a monster (as opposed to a location) if the monster is
2431 * target_able and the "interesting" mode is being used.
2433 * The current grid is described using the "look" method above, and
2434 * a new command may be entered at any time, but note that if the
2435 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
2436 * where "space" has no obvious meaning) then "space" will scan
2437 * through the description of the current grid until done, instead
2438 * of immediately jumping to the next "interesting" grid. This
2439 * allows the "target" command to retain its old semantics.
2441 * The "*", "+", and "-" keys may always be used to jump immediately
2442 * to the next (or previous) interesting grid, in the proper mode.
2444 * The "return" key may always be used to scan through a complete
2445 * grid description (forever).
2447 * This command will cancel any old target, even if used from
2448 * inside the "look" command.
2450 bool target_set(BIT_FLAGS mode)
2453 POSITION y = p_ptr->y;
2454 POSITION x = p_ptr->x;
2464 get_screen_size(&wid, &hgt);
2469 if (rogue_like_commands)
2478 /* Prepare the "temp" array */
2479 target_set_prepare(mode);
2481 /* Start near the player */
2487 /* Interesting grids */
2494 change_panel_xy(y, x);
2496 if (!(mode & TARGET_LOOK)) prt_path(y, x);
2499 c_ptr = &cave[y][x];
2502 if (target_able(c_ptr->m_idx))
2504 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
2507 /* Dis-allow target */
2510 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
2516 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
2517 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
2518 strcat(info, cheatinfo);
2521 /* Describe and Prompt */
2523 query = target_set_aux(y, x, mode, info);
2527 /* Assume no "direction" */
2532 if (query == '\r') query = 't';
2550 if (target_able(c_ptr->m_idx))
2552 health_track(c_ptr->m_idx);
2553 target_who = c_ptr->m_idx;
2572 if (!expand_list) done = TRUE;
2582 if (!expand_list) done = TRUE;
2589 /* Recenter the map around the player */
2591 p_ptr->update |= (PU_MONSTERS);
2592 p_ptr->redraw |= (PR_MAP);
2593 p_ptr->window |= (PW_OVERHEAD);
2596 /* Recalculate interesting grids */
2597 target_set_prepare(mode);
2616 if(query == same_key)
2621 if (!expand_list) done = TRUE;
2626 /* Extract the action (if any) */
2627 d = get_keymap_dir(query);
2634 /* Hack -- move around */
2637 /* Modified to scroll to monster */
2638 POSITION y2 = panel_row_min;
2639 POSITION x2 = panel_col_min;
2641 /* Find a new monster */
2642 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
2644 /* Request to target past last interesting grid */
2645 while (flag && (i < 0))
2647 /* Note the change */
2648 if (change_panel(ddy[d], ddx[d]))
2653 /* Recalculate interesting grids */
2654 target_set_prepare(mode);
2656 /* Look at interesting grids */
2659 /* Find a new monster */
2660 i = target_pick(v, u, ddy[d], ddx[d]);
2666 /* Nothing interesting */
2669 POSITION dx = ddx[d];
2670 POSITION dy = ddy[d];
2672 /* Restore previous position */
2675 panel_bounds_center();
2677 p_ptr->update |= (PU_MONSTERS);
2678 p_ptr->redraw |= (PR_MAP);
2679 p_ptr->window |= (PW_OVERHEAD);
2682 /* Recalculate interesting grids */
2683 target_set_prepare(mode);
2685 /* Look at boring grids */
2692 /* Do not move horizontally if unnecessary */
2693 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2694 ((x > panel_col_min + wid / 2) && (dx < 0)))
2699 /* Do not move vertically if unnecessary */
2700 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2701 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2706 /* Apply the motion */
2707 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
2708 (x >= panel_col_min+wid) || (x < panel_col_min))
2710 if (change_panel(dy, dx)) target_set_prepare(mode);
2713 /* Slide into legality */
2714 if (x >= cur_wid-1) x = cur_wid - 2;
2715 else if (x <= 0) x = 1;
2717 /* Slide into legality */
2718 if (y >= cur_hgt-1) y = cur_hgt- 2;
2719 else if (y <= 0) y = 1;
2728 /* Arbitrary grids */
2731 bool move_fast = FALSE;
2733 if (!(mode & TARGET_LOOK)) prt_path(y, x);
2736 c_ptr = &cave[y][x];
2738 /* Default prompt */
2739 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
2744 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
2745 los(p_ptr->y, p_ptr->x, y, x),
2746 projectable(p_ptr->y, p_ptr->x, y, x));
2747 strcat(info, cheatinfo);
2750 /* Describe and Prompt (enable "TARGET_LOOK") */
2751 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
2753 /* Assume no direction */
2758 if (query == '\r') query = 't';
2761 /* Analyze the keypress */
2785 /* Recenter the map around the player */
2787 p_ptr->update |= (PU_MONSTERS);
2788 p_ptr->redraw |= (PR_MAP);
2789 p_ptr->window |= (PW_OVERHEAD);
2792 /* Recalculate interesting grids */
2793 target_set_prepare(mode);
2815 /* Pick a nearby monster */
2816 for (i = 0; i < temp_n; i++)
2818 t = distance(y, x, temp_y[i], temp_x[i]);
2828 /* Nothing interesting */
2829 if (bd == 999) flag = FALSE;
2836 /* Extract the action (if any) */
2837 d = get_keymap_dir(query);
2839 /* XTRA HACK MOVEFAST */
2840 if (isupper(query)) move_fast = TRUE;
2847 /* Handle "direction" */
2850 POSITION dx = ddx[d];
2851 POSITION dy = ddy[d];
2853 /* XTRA HACK MOVEFAST */
2856 int mag = MIN(wid / 2, hgt / 2);
2866 /* Do not move horizontally if unnecessary */
2867 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2868 ((x > panel_col_min + wid / 2) && (dx < 0)))
2873 /* Do not move vertically if unnecessary */
2874 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2875 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2880 /* Apply the motion */
2881 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2882 (x >= panel_col_min + wid) || (x < panel_col_min))
2884 if (change_panel(dy, dx)) target_set_prepare(mode);
2887 /* Slide into legality */
2888 if (x >= cur_wid-1) x = cur_wid - 2;
2889 else if (x <= 0) x = 1;
2891 /* Slide into legality */
2892 if (y >= cur_hgt-1) y = cur_hgt- 2;
2893 else if (y <= 0) y = 1;
2901 /* Clear the top line */
2904 /* Recenter the map around the player */
2906 p_ptr->update |= (PU_MONSTERS);
2907 p_ptr->redraw |= (PR_MAP);
2908 p_ptr->window |= (PW_OVERHEAD);
2911 /* Failure to set target */
2912 if (!target_who) return (FALSE);
2920 * Get an "aiming direction" from the user.
2922 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
2923 * "0" for "current target", and "-1" for "entry aborted".
2925 * Note that "Force Target", if set, will pre-empt user interaction,
2926 * if there is a usable target already set.
2928 * Note that confusion over-rides any (explicit?) user choice.
2930 bool get_aim_dir(DIRECTION *dp)
2939 /* Global direction */
2942 /* Hack -- auto-target if requested */
2943 if (use_old_target && target_okay()) dir = 5;
2945 if (repeat_pull(&code))
2950 if (!(code == 5 && !target_okay()))
2952 /* return (TRUE); */
2953 dir = (DIRECTION)code;
2956 *dp = (DIRECTION)code;
2958 /* Ask until satisfied */
2961 /* Choose a prompt */
2964 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2968 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2971 /* Get a command (or Cancel) */
2972 if (!get_com(p, &command, TRUE)) break;
2976 if (command == '\r') command = 't';
2979 /* Convert various keys to "standard" keys */
2982 /* Use current target */
2993 /* Set new target */
2998 if (target_set(TARGET_KILL)) dir = 5;
3004 /* Extract the action (if any) */
3005 dir = get_keymap_dir(command);
3011 /* Verify requested targets */
3012 if ((dir == 5) && !target_okay()) dir = 0;
3021 project_length = 0; /* reset to default */
3025 /* Save the direction */
3028 /* Check for confusion */
3029 if (p_ptr->confused)
3031 /* Random direction */
3032 dir = ddd[randint0(8)];
3035 /* Notice confusion */
3036 if (command_dir != dir)
3039 msg_print(_("あなたは混乱している。", "You are confused."));
3042 /* Save direction */
3045 /* repeat_push(dir); */
3046 repeat_push((COMMAND_CODE)command_dir);
3048 /* A "valid" direction was entered */
3053 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
3061 /* Global direction */
3064 if (repeat_pull(&code))
3066 dir = (DIRECTION)code;
3067 /* return (TRUE); */
3069 *dp = (DIRECTION)code;
3073 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3077 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3080 /* Get a direction */
3085 /* Get a command (or Cancel) */
3086 if (!get_com(prompt, &ch, TRUE)) break;
3089 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3095 /* Look up the direction */
3096 dir = get_keymap_dir(ch);
3102 /* Prevent weirdness */
3103 if ((dir == 5) && (!allow_under)) dir = 0;
3106 if (!dir) return (FALSE);
3108 /* Save desired direction */
3111 /* Apply "confusion" */
3112 if (p_ptr->confused)
3114 /* Standard confusion */
3115 if (randint0(100) < 75)
3117 /* Random direction */
3118 dir = ddd[randint0(8)];
3121 else if (p_ptr->riding && with_steed)
3123 monster_type *m_ptr = &m_list[p_ptr->riding];
3124 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3126 if (MON_CONFUSED(m_ptr))
3128 /* Standard confusion */
3129 if (randint0(100) < 75)
3131 /* Random direction */
3132 dir = ddd[randint0(8)];
3135 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3137 /* Random direction */
3138 dir = ddd[randint0(8)];
3140 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3142 /* Random direction */
3143 dir = ddd[randint0(8)];
3147 /* Notice confusion */
3148 if (command_dir != dir)
3150 if (p_ptr->confused)
3153 msg_print(_("あなたは混乱している。", "You are confused."));
3157 GAME_TEXT m_name[MAX_NLEN];
3158 monster_type *m_ptr = &m_list[p_ptr->riding];
3160 monster_desc(m_name, m_ptr, 0);
3161 if (MON_CONFUSED(m_ptr))
3163 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3167 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3172 /* Save direction */
3175 /* repeat_push(dir); */
3176 repeat_push((COMMAND_CODE)command_dir);
3183 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
3184 * and place it into "command_dir", unless we already have one.
3186 * This function should be used for all "repeatable" commands, such as
3187 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
3188 * as all commands which must reference a grid adjacent to the player,
3189 * and which may not reference the grid under the player. Note that,
3190 * for example, it is no longer possible to "disarm" or "open" chests
3191 * in the same grid as the player.
3193 * Direction "5" is illegal and will (cleanly) abort the command.
3195 * This function tracks and uses the "global direction", and uses
3196 * that as the "desired direction", to which "confusion" is applied.
3198 bool get_rep_dir(DIRECTION *dp, bool under)
3206 /* Global direction */
3209 if (repeat_pull(&code))
3211 dir = (DIRECTION)code;
3212 /* return (TRUE); */
3214 *dp = (DIRECTION)code;
3218 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3222 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3225 /* Get a direction */
3230 /* Get a command (or Cancel) */
3231 if (!get_com(prompt, &ch, TRUE)) break;
3234 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3240 /* Look up the direction */
3241 dir = get_keymap_dir(ch);
3247 /* Prevent weirdness */
3248 if ((dir == 5) && (!under)) dir = 0;
3251 if (!dir) return (FALSE);
3253 /* Save desired direction */
3256 /* Apply "confusion" */
3257 if (p_ptr->confused)
3259 /* Standard confusion */
3260 if (randint0(100) < 75)
3262 /* Random direction */
3263 dir = ddd[randint0(8)];
3266 else if (p_ptr->riding)
3268 monster_type *m_ptr = &m_list[p_ptr->riding];
3269 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3271 if (MON_CONFUSED(m_ptr))
3273 /* Standard confusion */
3274 if (randint0(100) < 75)
3276 /* Random direction */
3277 dir = ddd[randint0(8)];
3280 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3282 /* Random direction */
3283 dir = ddd[randint0(8)];
3285 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3287 /* Random direction */
3288 dir = ddd[randint0(8)];
3292 /* Notice confusion */
3293 if (command_dir != dir)
3295 if (p_ptr->confused)
3298 msg_print(_("あなたは混乱している。", "You are confused."));
3302 GAME_TEXT m_name[MAX_NLEN];
3303 monster_type *m_ptr = &m_list[p_ptr->riding];
3305 monster_desc(m_name, m_ptr, 0);
3306 if (MON_CONFUSED(m_ptr))
3308 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3312 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3317 /* Save direction */
3320 /* repeat_push(dir); */
3321 repeat_push((COMMAND_CODE)command_dir);
3329 * XAngband: determine if a given location is "interesting"
3330 * based on target_set_accept function.
3332 static bool tgt_pt_accept(POSITION y, POSITION x)
3337 if (!(in_bounds(y, x))) return (FALSE);
3339 /* Player grid is always interesting */
3340 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
3342 /* Handle hallucination */
3343 if (p_ptr->image) return (FALSE);
3345 /* Examine the grid */
3346 c_ptr = &cave[y][x];
3348 /* Interesting memorized features */
3349 if (c_ptr->info & (CAVE_MARK))
3352 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
3353 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
3355 /* Notice quest features */
3356 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
3357 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
3365 * XAngband: Prepare the "temp" array for "tget_pt"
3366 * based on target_set_prepare funciton.
3368 static void tgt_pt_prepare(void)
3372 /* Reset "temp" array */
3375 if (!expand_list) return;
3377 /* Scan the current panel */
3378 for (y = 1; y < cur_hgt; y++)
3380 for (x = 1; x < cur_wid; x++)
3382 /* Require "interesting" contents */
3383 if (!tgt_pt_accept(y, x)) continue;
3385 /* Save the location */
3392 /* Target the nearest monster for shooting */
3393 ang_sort_comp = ang_sort_comp_distance;
3394 ang_sort_swap = ang_sort_swap_distance;
3396 /* Sort the positions */
3397 ang_sort(temp_x, temp_y, temp_n);
3401 * old -- from PsiAngband.
3403 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
3408 bool success = FALSE;
3412 get_screen_size(&wid, &hgt);
3422 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
3423 msg_flag = FALSE; /* prevents "-more-" message. */
3425 while ((ch != ESCAPE) && !success)
3427 bool move_fast = FALSE;
3429 move_cursor_relative(y, x);
3441 if (player_bold(y, x)) ch = 0;
3444 else success = TRUE;
3448 /* XAngband: Move cursor to stairs */
3451 if (expand_list && temp_n)
3454 int cx = (panel_col_min + panel_col_max) / 2;
3455 int cy = (panel_row_min + panel_row_max) / 2;
3459 /* Skip stairs which have defferent distance */
3460 for (; n < temp_n; ++ n)
3462 cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
3464 if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
3465 cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
3472 if (n == temp_n) /* Loop out taget list */
3477 verify_panel(); /* Move cursor to player */
3479 p_ptr->update |= (PU_MONSTERS);
3481 p_ptr->redraw |= (PR_MAP);
3483 p_ptr->window |= (PW_OVERHEAD);
3486 else /* move cursor to next stair and change panel */
3491 dy = 2 * (y - cy) / hgt;
3492 dx = 2 * (x - cx) / wid;
3493 if (dy || dx) change_panel(dy, dx);
3499 /* Look up the direction */
3500 d = get_keymap_dir(ch);
3502 /* XTRA HACK MOVEFAST */
3503 if (isupper(ch)) move_fast = TRUE;
3505 /* Handle "direction" */
3511 /* XTRA HACK MOVEFAST */
3514 int mag = MIN(wid / 2, hgt / 2);
3524 /* Do not move horizontally if unnecessary */
3525 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3526 ((x > panel_col_min + wid / 2) && (dx < 0)))
3531 /* Do not move vertically if unnecessary */
3532 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3533 ((y > panel_row_min + hgt / 2) && (dy < 0)))
3538 /* Apply the motion */
3539 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
3540 (x >= panel_col_min + wid) || (x < panel_col_min))
3542 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
3543 change_panel(dy, dx);
3546 /* Slide into legality */
3547 if (x >= cur_wid-1) x = cur_wid - 2;
3548 else if (x <= 0) x = 1;
3550 /* Slide into legality */
3551 if (y >= cur_hgt-1) y = cur_hgt- 2;
3552 else if (y <= 0) y = 1;
3559 /* Clear the top line */
3562 /* Recenter the map around the player */
3565 p_ptr->update |= (PU_MONSTERS);
3567 p_ptr->redraw |= (PR_MAP);
3569 p_ptr->window |= (PW_OVERHEAD);
3578 bool get_hack_dir(DIRECTION *dp)
3586 /* Global direction */
3589 /* (No auto-targeting) */
3591 /* Ask until satisfied */
3594 /* Choose a prompt */
3597 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
3601 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
3604 /* Get a command (or Cancel) */
3605 if (!get_com(p, &command, TRUE)) break;
3609 if (command == '\r') command = 't';
3612 /* Convert various keys to "standard" keys */
3615 /* Use current target */
3626 /* Set new target */
3631 if (target_set(TARGET_KILL)) dir = 5;
3637 /* Look up the direction */
3638 dir = get_keymap_dir(command);
3644 /* Verify requested targets */
3645 if ((dir == 5) && !target_okay()) dir = 0;
3652 if (!dir) return (FALSE);
3654 /* Save the direction */
3657 /* Check for confusion */
3658 if (p_ptr->confused)
3660 /* Random direction */
3661 dir = ddd[randint0(8)];
3664 /* Notice confusion */
3665 if (command_dir != dir)
3668 msg_print(_("あなたは混乱している。", "You are confused."));
3671 /* Save direction */
3674 /* A "valid" direction was entered */
3680 * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
3681 * @param sval 射撃武器のアイテム副分類ID
3682 * @return 消費する基本エネルギー
3684 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
3686 ENERGY energy = 10000;
3688 /* Analyze the launcher */
3691 /* Sling and ammo */
3698 /* Short Bow and Arrow */
3705 /* Long Bow and Arrow */
3712 /* Bow of irresponsiblity and Arrow */
3719 /* Light Crossbow and Bolt */
3726 /* Heavy Crossbow and Bolt */
3741 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
3745 /* Analyze the launcher */
3748 /* Sling and ammo */
3755 /* Short Bow and Arrow */
3762 /* Long Bow and Arrow */
3769 /* Bow of irresponsiblity and Arrow */
3776 /* Light Crossbow and Bolt */
3783 /* Heavy Crossbow and Bolt */
3796 * Display a rumor and apply its effects
3799 IDX rumor_num(char *zz, IDX max_idx)
3801 if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
3802 return (IDX)atoi(zz);
3805 concptr rumor_bind_name(char *base, concptr fullname)
3809 s = strstr(base, "{Name}");
3813 v = format("%s%s%s", base, fullname, (s + 6));
3823 void display_rumor(bool ex)
3831 if (randint0(3) == 0) section = 1;
3834 err = _(get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10),
3835 get_rnd_line("rumors.txt", section, Rumor));
3836 if (err) strcpy(Rumor, _("嘘の噂もある。", "Some rumors are wrong."));
3840 if (strncmp(Rumor, "R:", 2) == 0)
3843 concptr rumor_msg = NULL;
3844 concptr rumor_eff_format = NULL;
3845 char fullname[1024] = "";
3847 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
3849 if (strcmp(zz[0], "ARTIFACT") == 0)
3853 object_type *q_ptr = &forge;
3854 artifact_type *a_ptr;
3858 a_idx = rumor_num(zz[1], max_a_idx);
3860 a_ptr = &a_info[a_idx];
3861 if (a_ptr->name) break;
3864 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
3865 object_prep(q_ptr, k_idx);
3866 q_ptr->name1 = a_idx;
3867 q_ptr->ident = IDENT_STORE;
3868 object_desc(fullname, q_ptr, OD_NAME_ONLY);
3870 else if (strcmp(zz[0], "MONSTER") == 0)
3873 monster_race *r_ptr;
3877 r_idx = rumor_num(zz[1], max_r_idx);
3878 r_ptr = &r_info[r_idx];
3879 if (r_ptr->name) break;
3882 strcpy(fullname, r_name + r_ptr->name);
3884 /* Remember this monster */
3885 if (!r_ptr->r_sights)
3890 else if (strcmp(zz[0], "DUNGEON") == 0)
3893 dungeon_info_type *d_ptr;
3897 d_idx = rumor_num(zz[1], max_d_idx);
3898 d_ptr = &d_info[d_idx];
3899 if (d_ptr->name) break;
3902 strcpy(fullname, d_name + d_ptr->name);
3904 if (!max_dlv[d_idx])
3906 max_dlv[d_idx] = d_ptr->mindepth;
3907 rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
3910 else if (strcmp(zz[0], "TOWN") == 0)
3917 t_idx = rumor_num(zz[1], NO_TOWN);
3918 if (town[t_idx].name) break;
3921 strcpy(fullname, town[t_idx].name);
3923 visit = (1L << (t_idx - 1));
3924 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
3926 p_ptr->visit |= visit;
3927 rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
3931 rumor_msg = rumor_bind_name(zz[2], fullname);
3932 msg_print(rumor_msg);
3933 if (rumor_eff_format)
3936 msg_format(rumor_eff_format, fullname);
3941 if (err) msg_print(_("この情報は間違っている。", "This information is wrong."));
3945 msg_format("%s", Rumor);