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"
25 #define REWARD_CHANCE 10
29 * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
30 * Advance experience levels and print experience
33 void check_experience(void)
35 bool level_reward = FALSE;
36 bool level_mutation = FALSE;
37 bool level_inc_stat = FALSE;
38 bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
39 PLAYER_LEVEL old_lev = p_ptr->lev;
41 /* Hack -- lower limit */
42 if (p_ptr->exp < 0) p_ptr->exp = 0;
43 if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
44 if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
46 /* Hack -- upper limit */
47 if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
48 if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
49 if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
51 /* Hack -- maintain "max" experience */
52 if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
54 /* Hack -- maintain "max max" experience */
55 if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
57 /* Redraw experience */
58 p_ptr->redraw |= (PR_EXP);
62 /* Lose levels while possible */
63 while ((p_ptr->lev > 1) &&
64 (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
68 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
69 p_ptr->redraw |= (PR_LEV | PR_TITLE);
70 p_ptr->window |= (PW_PLAYER);
75 /* Gain levels while possible */
76 while ((p_ptr->lev < PY_MAX_LEVEL) &&
77 (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
82 /* Save the highest level */
83 if (p_ptr->lev > p_ptr->max_plv)
85 p_ptr->max_plv = p_ptr->lev;
87 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
88 (p_ptr->muta2 & MUT2_CHAOS_GIFT))
92 if (p_ptr->prace == RACE_BEASTMAN)
94 if (one_in_(5)) level_mutation = TRUE;
96 level_inc_stat = TRUE;
98 do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
103 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
105 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
106 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
107 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
117 if(!(p_ptr->max_plv % 10))
126 cnv_stat(p_ptr->stat_max[0], tmp);
127 prt(format(_(" a) 腕力 (現在値 %s)", " a) Str (cur %s)"), tmp), 2, 14);
128 cnv_stat(p_ptr->stat_max[1], tmp);
129 prt(format(_(" b) 知能 (現在値 %s)", " a) Int (cur %s)"), tmp), 3, 14);
130 cnv_stat(p_ptr->stat_max[2], tmp);
131 prt(format(_(" c) 賢さ (現在値 %s)", " a) Wis (cur %s)"), tmp), 4, 14);
132 cnv_stat(p_ptr->stat_max[3], tmp);
133 prt(format(_(" d) 器用 (現在値 %s)", " a) Dex (cur %s)"), tmp), 5, 14);
134 cnv_stat(p_ptr->stat_max[4], tmp);
135 prt(format(_(" e) 耐久 (現在値 %s)", " a) Con (cur %s)"), tmp), 6, 14);
136 cnv_stat(p_ptr->stat_max[5], tmp);
137 prt(format(_(" f) 魅力 (現在値 %s)", " a) Chr (cur %s)"), tmp), 7, 14);
140 prt(_(" どの能力値を上げますか?", " Which stat do you want to raise?"), 1, 14);
145 if ((choice >= 'a') && (choice <= 'f')) break;
147 for(n = 0; n < A_MAX; n++)
148 if (n != choice - 'a')
150 if (get_check(_("よろしいですか?", "Are you sure? "))) break;
152 do_inc_stat(choice - 'a');
155 else if(!(p_ptr->max_plv % 2))
156 do_inc_stat(randint0(6));
161 msg_print(_("あなたは変わった気がする...", "You feel different..."));
162 (void)gain_random_mutation(0);
163 level_mutation = FALSE;
167 * 報酬でレベルが上ると再帰的に check_experience() が
172 gain_level_reward(0);
173 level_reward = FALSE;
176 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
177 p_ptr->redraw |= (PR_LEV | PR_TITLE);
178 p_ptr->window |= (PW_PLAYER | PW_SPELL);
182 /* Load an autopick preference file */
183 if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
189 * @brief クエストを達成状態にする /
190 * @param quest_num 達成状態にしたいクエストのID
193 void complete_quest(QUEST_IDX quest_num)
195 quest_type* const q_ptr = &quest[quest_num];
199 case QUEST_TYPE_RANDOM:
200 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
203 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
207 q_ptr->status = QUEST_STATUS_COMPLETED;
208 q_ptr->complev = p_ptr->lev;
210 q_ptr->comptime = playtime;
212 if (!(q_ptr->flags & QUEST_FLAG_SILENT))
214 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
215 msg_print(_("クエストを達成した!", "You just completed your quest!"));
221 * @brief 現在フロアに残っている敵モンスターの数を返す /
222 * @return 現在の敵モンスターの数
224 static MONSTER_NUMBER count_all_hostile_monsters(void)
227 MONSTER_NUMBER number_mon = 0;
229 for (x = 0; x < cur_wid; ++ x)
231 for (y = 0; y < cur_hgt; ++ y)
233 MONSTER_IDX m_idx = cave[y][x].m_idx;
235 if (m_idx > 0 && is_hostile(&m_list[m_idx]))
246 * @brief 特定の敵を倒した際にクエスト達成処理 /
247 * Check for "Quest" completion when a quest monster is killed or charmed.
248 * @param m_ptr 撃破したモンスターの構造体参照ポインタ
251 void check_quest_completion(monster_type *m_ptr)
256 bool create_stairs = FALSE;
266 quest_num = p_ptr->inside_quest;
268 /* Search for an active quest on this dungeon level */
273 for (i = max_q_idx - 1; i > 0; i--)
275 quest_type* const q_ptr = &quest[i];
277 /* Quest is not active */
278 if (q_ptr->status != QUEST_STATUS_TAKEN)
281 /* Quest is not a dungeon quest */
282 if (q_ptr->flags & QUEST_FLAG_PRESET)
285 /* Quest is not on this level */
286 if ((q_ptr->level != dun_level) &&
287 (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
290 /* Not a "kill monster" quest */
291 if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
292 (q_ptr->type == QUEST_TYPE_FIND_EXIT))
295 /* Interesting quest */
296 if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
297 (q_ptr->type == QUEST_TYPE_TOWER) ||
298 (q_ptr->type == QUEST_TYPE_KILL_ALL))
301 /* Interesting quest */
302 if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
303 (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
304 (q_ptr->type == QUEST_TYPE_RANDOM)) &&
305 (q_ptr->r_idx == m_ptr->r_idx))
312 /* Handle the current quest */
313 if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
316 quest_type* const q_ptr = &quest[quest_num];
320 case QUEST_TYPE_KILL_NUMBER:
324 if (q_ptr->cur_num >= q_ptr->num_mon)
326 complete_quest(quest_num);
332 case QUEST_TYPE_KILL_ALL:
334 if (!is_hostile(m_ptr)) break;
336 if (count_all_hostile_monsters() == 1)
338 if (q_ptr->flags & QUEST_FLAG_SILENT)
340 q_ptr->status = QUEST_STATUS_FINISHED;
344 complete_quest(quest_num);
349 case QUEST_TYPE_KILL_LEVEL:
350 case QUEST_TYPE_RANDOM:
352 /* Only count valid monsters */
353 if (q_ptr->r_idx != m_ptr->r_idx)
358 if (q_ptr->cur_num >= q_ptr->max_num)
360 complete_quest(quest_num);
362 if (!(q_ptr->flags & QUEST_FLAG_PRESET))
364 create_stairs = TRUE;
365 p_ptr->inside_quest = 0;
368 /* Finish the two main quests without rewarding */
369 if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
371 q_ptr->status = QUEST_STATUS_FINISHED;
374 if (q_ptr->type == QUEST_TYPE_RANDOM)
377 q_ptr->status = QUEST_STATUS_FINISHED;
382 case QUEST_TYPE_KILL_ANY_LEVEL:
385 if (q_ptr->cur_num >= q_ptr->max_num)
387 complete_quest(quest_num);
392 case QUEST_TYPE_TOWER:
394 if (!is_hostile(m_ptr)) break;
396 if (count_all_hostile_monsters() == 1)
398 q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
400 if((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
401 (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
402 (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
405 complete_quest(QUEST_TOWER1);
413 /* Create a magical staircase */
419 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT) )
421 /* Pick a location */
422 scatter(&ny, &nx, y, x, 1, 0);
428 /* Explain the staircase */
429 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
431 /* Create stairs down */
432 cave_set_feat(y, x, feat_down_stair);
434 /* Remember to update everything */
435 p_ptr->update |= (PU_FLOW);
445 for (i = 0; i < (dun_level / 15)+1; i++)
450 /* Make a great object */
451 make_object(o_ptr, AM_GOOD | AM_GREAT);
452 (void)drop_near(o_ptr, -1, y, x);
458 * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
459 * Check for "Quest" completion when a quest monster is killed or charmed.
460 * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
463 void check_find_art_quest_completion(object_type *o_ptr)
466 /* Check if completed a quest */
467 for (i = 0; i < max_q_idx; i++)
469 if((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
470 (quest[i].status == QUEST_STATUS_TAKEN) &&
471 (quest[i].k_idx == o_ptr->name1))
480 * @brief モンスターを撃破した際の述語メッセージを返す /
481 * Return monster death string
482 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
483 * @return 撃破されたモンスターの述語
485 concptr extract_note_dies(MONRACE_IDX r_idx)
487 monster_race *r_ptr = &r_info[r_idx];
488 /* Some monsters get "destroyed" */
489 if (!monster_living(r_idx))
493 for (i = 0; i < 4; i++)
495 if (r_ptr->blow[i].method == RBM_EXPLODE)
497 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
500 return _("を倒した。", " is destroyed.");
503 /* Assume a default death */
504 return _("は死んだ。", " dies.");
509 * @brief モンスターに与えたダメージの修正処理 /
510 * Modify the physical damage done to the monster.
511 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
513 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
514 * @return 修正を行った結果のダメージ量
517 * (for example when it's invulnerable or shielded)
518 * ToDo: Accept a damage-type to calculate the modified damage from
519 * things like fire, frost, lightning, poison, ... attacks.
520 * "type" is not yet used and should be 0.
523 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
525 monster_race *r_ptr = &r_info[m_ptr->r_idx];
527 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
530 if ((dam == 0) && one_in_(3)) dam = 1;
533 if (MON_INVULNER(m_ptr))
537 if (!p_ptr->blind && is_seen(m_ptr))
539 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
542 else if (!one_in_(PENETRATE_INVULNERABILITY))
552 * @brief モンスターに与えたダメージを元に経験値を加算する /
553 * Calculate experience point to be get
554 * @param dam 与えたダメージ量
555 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
559 * Even the 64 bit operation is not big enough to avoid overflaw
560 * unless we carefully choose orders of multiplication and division.
561 * Get the coefficient first, and multiply (potentially huge) base
562 * experience point of a monster later.
565 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
567 monster_race *r_ptr = &r_info[m_ptr->r_idx];
574 if (!m_ptr->r_idx) return;
575 if (is_pet(m_ptr) || p_ptr->inside_battle) return;
578 * - Ratio of monster's level to player's level effects
579 * - Varying speed effects
580 * - Get a fraction in proportion of damage point
582 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
585 div_l = (p_ptr->max_plv+2) * SPEED_TO_ENERGY(r_ptr->speed);
587 /* Use (average maxhp * 2) as a denominator */
588 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
589 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
591 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
593 /* Special penalty in the wilderness */
594 if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
595 s64b_mul(&div_h, &div_l, 0, 5);
597 /* Do division first to prevent overflaw */
598 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
600 /* Special penalty for mutiply-monster */
601 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
603 int monnum_penarty = r_ptr->r_akills / 400;
604 if (monnum_penarty > 8) monnum_penarty = 8;
606 while (monnum_penarty--)
609 s64b_RSHIFT(new_exp, new_exp_frac, 2);
613 /* Special penalty for rest_and_shoot exp scum */
614 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
616 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
617 if (over_damage > 32) over_damage = 32;
619 while (over_damage--)
622 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
623 s64b_div(&new_exp, &new_exp_frac, 0, 10);
627 /* Finally multiply base experience point of the monster */
628 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
630 /* Gain experience */
631 gain_exp_64(new_exp, new_exp_frac);
636 * @brief モンスターのHPをダメージに応じて減算する /
637 * Decreases monsters hit points, handling monster death.
638 * @param dam 与えたダメージ量
639 * @param m_idx ダメージを与えたモンスターのID
640 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
641 * @param note モンスターが倒された際の特別なメッセージ述語
645 * We return TRUE if the monster has been killed (and deleted).
646 * We announce monster death (using an optional "death message"
647 * if given, and a otherwise a generic killed/destroyed message).
648 * Only "physical attacks" can induce the "You have slain" message.
649 * Missile and Spell attacks will induce the "dies" message, or
650 * various "specialized" messages. Note that "You have destroyed"
651 * and "is destroyed" are synonyms for "You have slain" and "dies".
652 * Hack -- unseen monsters yield "You have killed it." message.
653 * Added fear (DGK) and check whether to print fear messages -CWS
654 * Made name, sex, and capitalization generic -BEN-
655 * As always, the "ghost" processing is a total hack.
656 * Hack -- we "delay" fear messages by passing around a "fear" flag.
657 * Consider decreasing monster experience over time, say,
658 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
659 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
660 * monster worth more than subsequent monsters. This would also need
661 * to induce changes in the monster recall code.
664 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
666 monster_type *m_ptr = &m_list[m_idx];
667 monster_race *r_ptr = &r_info[m_ptr->r_idx];
668 monster_type exp_mon;
670 /* Innocent until proven otherwise */
671 bool innocent = TRUE, thief = FALSE;
675 (void)COPY(&exp_mon, m_ptr, monster_type);
677 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
679 get_exp_from_mon(expdam, &exp_mon);
681 /* Genocided by chaos patron */
682 if (!m_ptr->r_idx) m_idx = 0;
684 /* Redraw (later) if needed */
685 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
686 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
688 (void)set_monster_csleep(m_idx, 0);
690 /* Hack - Cancel any special player stealth magics. -LM- */
691 if (p_ptr->special_defense & NINJA_S_STEALTH)
693 set_superstealth(FALSE);
696 /* Genocided by chaos patron */
697 if (!m_idx) return TRUE;
700 m_ptr->dealt_damage += dam;
702 if(m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
706 msg_format( _("合計%d/%dのダメージを与えた。","You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
712 GAME_TEXT m_name[MAX_NLEN];
714 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
716 /* You might have unmasked Tanuki first time */
717 r_ptr = &r_info[m_ptr->r_idx];
718 m_ptr->ap_r_idx = m_ptr->r_idx;
719 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
722 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
724 /* You might have unmasked Chameleon first time */
725 r_ptr = real_r_ptr(m_ptr);
726 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
729 if (!(m_ptr->smart & SM_CLONED))
731 /* When the player kills a Unique, it stays dead */
732 if (r_ptr->flags1 & RF1_UNIQUE)
736 /* Mega-Hack -- Banor & Lupart */
737 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
739 r_info[MON_BANORLUPART].max_num = 0;
740 r_info[MON_BANORLUPART].r_pkills++;
741 r_info[MON_BANORLUPART].r_akills++;
742 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
744 else if (m_ptr->r_idx == MON_BANORLUPART)
746 r_info[MON_BANOR].max_num = 0;
747 r_info[MON_BANOR].r_pkills++;
748 r_info[MON_BANOR].r_akills++;
749 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
750 r_info[MON_LUPART].max_num = 0;
751 r_info[MON_LUPART].r_pkills++;
752 r_info[MON_LUPART].r_akills++;
753 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
757 /* When the player kills a Nazgul, it stays dead */
758 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
761 /* Count all monsters killed */
762 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
764 /* Recall even invisible uniques or winners */
765 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
767 /* Count kills this life */
768 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
769 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
771 /* Count kills in all lives */
772 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
773 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
775 /* Hack -- Auto-recall */
776 monster_race_track(m_ptr->ap_r_idx);
779 /* Extract monster name */
780 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
782 /* Don't kill Amberites */
783 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
785 int curses = 1 + randint1(3);
786 bool stop_ty = FALSE;
789 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
790 curse_equipment(100, 50);
794 stop_ty = activate_ty_curse(stop_ty, &count);
799 if (r_ptr->flags2 & RF2_CAN_SPEAK)
802 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
804 msg_format("%^s %s", m_name, line_got);
808 if (m_ptr->r_idx == MON_SERPENT)
810 screen_dump = make_screen_dump();
815 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
817 if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
819 chg_virtue(V_VALOUR, -1);
821 else if (r_ptr->level > dun_level)
823 if (randint1(10) <= (r_ptr->level - dun_level))
824 chg_virtue(V_VALOUR, 1);
826 if (r_ptr->level > 60)
828 chg_virtue(V_VALOUR, 1);
830 if (r_ptr->level >= 2 * (p_ptr->lev+1))
831 chg_virtue(V_VALOUR, 2);
834 if (r_ptr->flags1 & RF1_UNIQUE)
836 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
838 if (r_ptr->flags3 & RF3_GOOD)
840 chg_virtue(V_UNLIFE, 2);
841 chg_virtue(V_VITALITY, -2);
844 if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
847 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
849 chg_virtue(V_COMPASSION, -1);
852 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
853 chg_virtue(V_UNLIFE, 1);
855 if (r_ptr->d_char == 'A')
857 if (r_ptr->flags1 & RF1_UNIQUE)
858 chg_virtue(V_FAITH, -2);
859 else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
861 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
862 else chg_virtue(V_FAITH, 1);
865 else if (r_ptr->flags3 & RF3_DEMON)
867 if (r_ptr->flags1 & RF1_UNIQUE)
868 chg_virtue(V_FAITH, 2);
869 else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
870 chg_virtue(V_FAITH, 1);
873 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
874 chg_virtue(V_VITALITY, 2);
878 if (r_ptr->flags1 & RF1_UNIQUE)
880 chg_virtue(V_HONOUR, 10);
882 else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
884 chg_virtue(V_HONOUR, 1);
887 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
889 chg_virtue(V_VALOUR, -1);
892 for (i = 0; i < 4; i++)
894 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
896 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
897 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
899 thief = TRUE; /* Thief! */
902 /* The new law says it is illegal to live in the dungeon */
903 if (r_ptr->level != 0) innocent = FALSE;
907 if (r_ptr->flags1 & RF1_UNIQUE)
908 chg_virtue(V_JUSTICE, 3);
909 else if (1+((r_ptr->level) / 10 + (2 * dun_level)) >= randint1(100))
910 chg_virtue(V_JUSTICE, 1);
914 chg_virtue (V_JUSTICE, -1);
917 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)))
919 if (one_in_(4)) chg_virtue(V_NATURE, -1);
922 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
925 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
926 do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
932 /* Death by Missile/Spell attack */
935 msg_format("%^s%s", m_name, note);
938 /* Death by physical attack -- invisible monster */
942 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
943 msg_format("せっかくだから%sを殺した。", m_name);
945 msg_format("%sを殺した。", m_name);
947 msg_format("You have killed %s.", m_name);
952 /* Death by Physical attack -- non-living monster */
953 else if (!monster_living(m_ptr->r_idx))
955 bool explode = FALSE;
957 for (i = 0; i < 4; i++)
959 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
962 /* Special note at death */
964 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
968 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
969 msg_format("せっかくだから%sを倒した。", m_name);
971 msg_format("%sを倒した。", m_name);
973 msg_format("You have destroyed %s.", m_name);
978 /* Death by Physical attack -- living monster */
982 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
983 msg_format("せっかくだから%sを葬り去った。", m_name);
985 msg_format("%sを葬り去った。", m_name);
987 msg_format("You have slain %s.", m_name);
991 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
993 for (i = 0; i < MAX_KUBI; i++)
995 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
997 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1003 /* Generate treasure */
1004 monster_death(m_idx, TRUE);
1006 /* Mega hack : replace IKETA to BIKETAL */
1007 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1009 POSITION dummy_y = m_ptr->fy;
1010 POSITION dummy_x = m_ptr->fx;
1011 BIT_FLAGS mode = 0L;
1012 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1013 delete_monster_idx(m_idx);
1014 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1016 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1021 delete_monster_idx(m_idx);
1024 get_exp_from_mon((long)exp_mon.max_maxhp*2, &exp_mon);
1029 /* Monster is dead */
1036 /* Mega-Hack -- Pain cancels fear */
1037 if (MON_MONFEAR(m_ptr) && (dam > 0))
1040 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1047 /* Sometimes a monster gets scared by damage */
1048 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1050 /* Percentage of fully healthy */
1051 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1054 * Run (sometimes) if at 10% or less of max hit points,
1055 * or (usually) when hit for half its current hit points
1057 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1059 /* Hack -- note fear */
1062 /* Hack -- Add some timed fear */
1063 (void)set_monster_monfear(m_idx, (randint1(10) +
1064 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1065 20 : ((11 - percentage) * 5))));
1077 * @brief 現在のコンソール表示の縦横を返す。 /
1078 * Get term size and calculate screen size
1079 * @param wid_p コンソールの表示幅文字数を返す
1080 * @param hgt_p コンソールの表示行数を返す
1083 void get_screen_size(TERM_LEN *wid_p, TERM_LEN *hgt_p)
1085 Term_get_size(wid_p, hgt_p);
1086 *hgt_p -= ROW_MAP + 2;
1087 *wid_p -= COL_MAP + 2;
1088 if (use_bigtile) *wid_p /= 2;
1093 * @brief コンソール上におけるマップ表示の左上位置を返す /
1094 * Calculates current boundaries Called below and from "do_cmd_locate()".
1097 void panel_bounds_center(void)
1101 get_screen_size(&wid, &hgt);
1103 panel_row_max = panel_row_min + hgt - 1;
1104 panel_row_prt = panel_row_min - 1;
1105 panel_col_max = panel_col_min + wid - 1;
1106 panel_col_prt = panel_col_min - 13;
1111 * @brief コンソールのリサイズに合わせてマップを再描画する /
1112 * Map resizing whenever the main term changes size
1115 void resize_map(void)
1117 /* Only if the dungeon exists */
1118 if (!character_dungeon) return;
1120 /* Mega-Hack -- no panel yet */
1124 /* Reset the panels */
1125 panel_row_min = cur_hgt;
1126 panel_col_min = cur_wid;
1130 p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
1131 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
1132 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1133 p_ptr->update |= (PU_MONSTERS);
1134 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
1141 * Place the cursor on the player
1143 if (can_save) move_cursor_relative(p_ptr->y, p_ptr->x);
1149 * @brief コンソールを再描画する /
1150 * Redraw a term when it is resized
1153 void redraw_window(void)
1155 /* Only if the dungeon exists */
1156 if (!character_dungeon) return;
1158 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1159 p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
1167 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
1168 * @param dy 変更先のフロアY座標
1169 * @param dx 変更先のフロアX座標
1170 * Handle a request to change the current panel
1171 * Return TRUE if the panel was changed.
1172 * Also used in do_cmd_locate
1173 * @return 実際に再描画が必要だった場合TRUEを返す
1175 bool change_panel(POSITION dy, POSITION dx)
1180 get_screen_size(&wid, &hgt);
1182 /* Apply the motion */
1183 y = panel_row_min + dy * hgt / 2;
1184 x = panel_col_min + dx * wid / 2;
1186 /* Verify the row */
1187 if (y > cur_hgt - hgt) y = cur_hgt - hgt;
1190 /* Verify the col */
1191 if (x > cur_wid - wid) x = cur_wid - wid;
1194 /* Handle "changes" */
1195 if ((y != panel_row_min) || (x != panel_col_min))
1197 /* Save the new panel info */
1201 /* Recalculate the boundaries */
1202 panel_bounds_center();
1204 p_ptr->update |= (PU_MONSTERS);
1205 p_ptr->redraw |= (PR_MAP);
1217 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
1218 * @param y 変更先のフロアY座標
1219 * @param x 変更先のフロアX座標
1221 * Handle a request to change the current panel
1222 * Return TRUE if the panel was changed.
1223 * Also used in do_cmd_locate
1224 * @return 実際に再描画が必要だった場合TRUEを返す
1226 static bool change_panel_xy(POSITION y, POSITION x)
1228 POSITION dy = 0, dx = 0;
1231 get_screen_size(&wid, &hgt);
1233 if (y < panel_row_min) dy = -1;
1234 if (y > panel_row_max) dy = 1;
1235 if (x < panel_col_min) dx = -1;
1236 if (x > panel_col_max) dx = 1;
1238 if (!dy && !dx) return (FALSE);
1240 return change_panel(dy, dx);
1245 * @brief マップ描画のフォーカスを当てるべき座標を更新する
1247 * Given an row (y) and col (x), this routine detects when a move
1248 * off the screen has occurred and figures new borders. -RAK-
1249 * "Update" forces a "full update" to take place.
1250 * The map is reprinted if necessary, and "TRUE" is returned.
1251 * @return 実際に再描画が必要だった場合TRUEを返す
1253 void verify_panel(void)
1255 POSITION y = p_ptr->y;
1256 POSITION x = p_ptr->x;
1264 get_screen_size(&wid, &hgt);
1266 max_prow_min = cur_hgt - hgt;
1267 max_pcol_min = cur_wid - wid;
1269 /* Bounds checking */
1270 if (max_prow_min < 0) max_prow_min = 0;
1271 if (max_pcol_min < 0) max_pcol_min = 0;
1273 /* Center on player */
1274 if (center_player && (center_running || !running))
1276 /* Center vertically */
1277 prow_min = y - hgt / 2;
1278 if (prow_min < 0) prow_min = 0;
1279 else if (prow_min > max_prow_min) prow_min = max_prow_min;
1281 /* Center horizontally */
1282 pcol_min = x - wid / 2;
1283 if (pcol_min < 0) pcol_min = 0;
1284 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1288 prow_min = panel_row_min;
1289 pcol_min = panel_col_min;
1291 /* Scroll screen when 2 grids from top/bottom edge */
1292 if (y > panel_row_max - 2)
1294 while (y > prow_min + hgt-1 - 2)
1296 prow_min += (hgt / 2);
1300 if (y < panel_row_min + 2)
1302 while (y < prow_min + 2)
1304 prow_min -= (hgt / 2);
1308 if (prow_min > max_prow_min) prow_min = max_prow_min;
1309 if (prow_min < 0) prow_min = 0;
1311 /* Scroll screen when 4 grids from left/right edge */
1312 if (x > panel_col_max - 4)
1314 while (x > pcol_min + wid-1 - 4)
1316 pcol_min += (wid / 2);
1320 if (x < panel_col_min + 4)
1322 while (x < pcol_min + 4)
1324 pcol_min -= (wid / 2);
1328 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1329 if (pcol_min < 0) pcol_min = 0;
1332 /* Check for "no change" */
1333 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
1335 /* Save the new panel info */
1336 panel_row_min = prow_min;
1337 panel_col_min = pcol_min;
1339 /* Hack -- optional disturb on "panel change" */
1340 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
1342 /* Recalculate the boundaries */
1343 panel_bounds_center();
1345 p_ptr->update |= (PU_MONSTERS);
1346 p_ptr->redraw |= (PR_MAP);
1347 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1352 * Monster health description
1354 concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
1356 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1363 /* Determine if the monster is "living" */
1364 living = monster_living(m_ptr->ap_r_idx);
1366 /* Calculate a health "percentage" */
1367 perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
1369 /* Healthy monsters */
1370 if (m_ptr->hp >= m_ptr->maxhp)
1372 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
1375 else if (perc >= 60)
1377 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
1380 else if (perc >= 25)
1382 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
1385 else if (perc >= 10)
1387 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
1392 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
1395 /* Need attitude information? */
1398 /* Full information is not needed */
1401 else if (is_pet(m_ptr))
1403 attitude = _(", ペット", ", pet");
1405 else if (is_friendly(m_ptr))
1407 attitude = _(", 友好的", ", friendly");
1411 attitude = _("", "");
1414 /* Clone monster? */
1415 if (m_ptr->smart & SM_CLONED)
1424 /* Display monster's level --- idea borrowed from ToME */
1425 if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
1427 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
1431 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
1438 /*** Targeting Code ***/
1442 * Determine is a monster makes a reasonable target
1444 * The concept of "targeting" was stolen from "Morgul" (?)
1446 * The player can target any location, or any "target-able" monster.
1448 * Currently, a monster is "target_able" if it is visible, and if
1449 * the player can hit it with a projection, and the player is not
1450 * hallucinating. This allows use of "use closest target" macros.
1452 * Future versions may restrict the ability to target "trappers"
1453 * and "mimics", but the semantics is a little bit weird.
1455 bool target_able(MONSTER_IDX m_idx)
1457 monster_type *m_ptr = &m_list[m_idx];
1459 /* Monster must be alive */
1460 if (!m_ptr->r_idx) return (FALSE);
1462 /* Hack -- no targeting hallucinations */
1463 if (p_ptr->image) return (FALSE);
1465 /* Monster must be visible */
1466 if (!m_ptr->ml) return (FALSE);
1468 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
1470 /* Monster must be projectable */
1471 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
1473 /* Hack -- Never target trappers */
1474 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
1484 * Update (if necessary) and verify (if possible) the target.
1486 * We return TRUE if the target is "okay" and FALSE otherwise.
1488 bool target_okay(void)
1490 /* Accept stationary targets */
1491 if (target_who < 0) return (TRUE);
1493 /* Check moving targets */
1496 /* Accept reasonable targets */
1497 if (target_able(target_who))
1499 monster_type *m_ptr = &m_list[target_who];
1501 /* Acquire monster location */
1502 target_row = m_ptr->fy;
1503 target_col = m_ptr->fx;
1510 /* Assume no target */
1516 * Sorting hook -- comp function -- by "distance to player"
1518 * We use "u" and "v" to point to arrays of "x" and "y" positions,
1519 * and sort the arrays by double-distance to the player.
1521 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
1523 POSITION *x = (POSITION*)(u);
1524 POSITION *y = (POSITION*)(v);
1526 POSITION da, db, kx, ky;
1528 /* Absolute distance components */
1529 kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
1530 ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
1532 /* Approximate Double Distance to the first point */
1533 da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
1535 /* Absolute distance components */
1536 kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
1537 ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
1539 /* Approximate Double Distance to the first point */
1540 db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
1542 /* Compare the distances */
1548 * Sorting hook -- comp function -- by importance level of grids
1550 * We use "u" and "v" to point to arrays of "x" and "y" positions,
1551 * and sort the arrays by level of monster
1553 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
1555 POSITION *x = (POSITION*)(u);
1556 POSITION *y = (POSITION*)(v);
1557 cave_type *ca_ptr = &cave[y[a]][x[a]];
1558 cave_type *cb_ptr = &cave[y[b]][x[b]];
1559 monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
1560 monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
1561 monster_race *ap_ra_ptr, *ap_rb_ptr;
1563 /* The player grid */
1564 if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
1565 if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
1567 /* Extract monster race */
1568 if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
1569 else ap_ra_ptr = NULL;
1570 if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
1571 else ap_rb_ptr = NULL;
1573 if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
1574 if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
1576 /* Compare two monsters */
1577 if (ap_ra_ptr && ap_rb_ptr)
1579 /* Unique monsters first */
1580 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
1581 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
1583 /* Shadowers first (あやしい影) */
1584 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
1585 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
1587 /* Unknown monsters first */
1588 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
1589 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
1591 /* Higher level monsters first (if known) */
1592 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
1594 if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
1595 if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
1598 /* Sort by index if all conditions are same */
1599 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
1600 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
1603 /* An object get higher priority */
1604 if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
1605 if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
1607 /* Priority from the terrain */
1608 if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
1609 if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
1611 /* If all conditions are same, compare distance */
1612 return ang_sort_comp_distance(u, v, a, b);
1617 * Sorting hook -- swap function -- by "distance to player"
1619 * We use "u" and "v" to point to arrays of "x" and "y" positions,
1620 * and sort the arrays by distance to the player.
1622 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
1624 POSITION *x = (POSITION*)(u);
1625 POSITION *y = (POSITION*)(v);
1643 * Hack -- help "select" a location (see below)
1645 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
1648 POSITION x2, y2, x3, y3, x4, y4;
1649 POSITION_IDX b_i = -1, b_v = 9999;
1652 /* Scan the locations */
1653 for (i = 0; i < temp_n; i++)
1659 /* Directed distance */
1663 /* Verify quadrant */
1664 if (dx && (x3 * dx <= 0)) continue;
1665 if (dy && (y3 * dy <= 0)) continue;
1667 /* Absolute distance */
1671 /* Verify quadrant */
1672 if (dy && !dx && (x4 > y4)) continue;
1673 if (dx && !dy && (y4 > x4)) continue;
1675 /* Approximate Double Distance */
1676 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
1678 /* Penalize location */
1681 if ((b_i >= 0) && (v >= b_v)) continue;
1691 * Hack -- determine if a given location is "interesting"
1693 static bool target_set_accept(POSITION y, POSITION x)
1696 OBJECT_IDX this_o_idx, next_o_idx = 0;
1699 if (!(in_bounds(y, x))) return (FALSE);
1701 /* Player grid is always interesting */
1702 if (player_bold(y, x)) return (TRUE);
1704 /* Handle hallucination */
1705 if (p_ptr->image) return (FALSE);
1707 /* Examine the grid */
1708 c_ptr = &cave[y][x];
1710 /* Visible monsters */
1713 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1715 /* Visible monsters */
1716 if (m_ptr->ml) return (TRUE);
1719 /* Scan all objects in the grid */
1720 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1723 o_ptr = &o_list[this_o_idx];
1725 /* Acquire next object */
1726 next_o_idx = o_ptr->next_o_idx;
1728 /* Memorized object */
1729 if (o_ptr->marked & OM_FOUND) return (TRUE);
1732 /* Interesting memorized features */
1733 if (c_ptr->info & (CAVE_MARK))
1735 /* Notice object features */
1736 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
1738 /* Feature code (applying "mimic" field) */
1739 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
1747 * Prepare the "temp" array for "target_set"
1749 * Return the number of target_able monsters in the set.
1751 static void target_set_prepare(BIT_FLAGS mode)
1754 POSITION min_hgt, max_hgt, min_wid, max_wid;
1756 if (mode & TARGET_KILL)
1759 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
1760 max_hgt = MIN((p_ptr->y + MAX_RANGE), cur_hgt - 1);
1761 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
1762 max_wid = MIN((p_ptr->x + MAX_RANGE), cur_wid - 1);
1764 else /* not targetting */
1767 min_hgt = panel_row_min;
1768 max_hgt = panel_row_max;
1769 min_wid = panel_col_min;
1770 max_wid = panel_col_max;
1773 /* Reset "temp" array */
1776 /* Scan the current panel */
1777 for (y = min_hgt; y <= max_hgt; y++)
1779 for (x = min_wid; x <= max_wid; x++)
1783 /* Require "interesting" contents */
1784 if (!target_set_accept(y, x)) continue;
1786 c_ptr = &cave[y][x];
1788 /* Require target_able monsters for "TARGET_KILL" */
1789 if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
1791 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
1793 /* Save the location */
1800 /* Set the sort hooks */
1801 if (mode & (TARGET_KILL))
1803 /* Target the nearest monster for shooting */
1804 ang_sort_comp = ang_sort_comp_distance;
1805 ang_sort_swap = ang_sort_swap_distance;
1809 /* Look important grids first in Look command */
1810 ang_sort_comp = ang_sort_comp_importance;
1811 ang_sort_swap = ang_sort_swap_distance;
1814 /* Sort the positions */
1815 ang_sort(temp_x, temp_y, temp_n);
1817 if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
1822 temp_y[0] = temp_y[1];
1825 temp_x[0] = temp_x[1];
1830 void target_set_prepare_look(void){
1831 target_set_prepare(TARGET_LOOK);
1836 * Evaluate number of kill needed to gain level
1838 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
1840 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1842 s32b exp_mon, exp_adv;
1843 u32b exp_mon_frac, exp_adv_frac;
1845 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
1850 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
1860 /* The monster's experience point (assuming average monster speed) */
1861 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
1863 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
1866 /* Total experience value for next level */
1867 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
1869 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
1871 /* Experience value need to get */
1872 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
1875 /* You need to kill at least one monster to get any experience */
1876 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1877 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
1879 /* Extract number of monsters needed */
1880 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1882 /* If 999 or more monsters needed, only display "999". */
1883 num = MIN(999, exp_adv_frac);
1885 /* Display the number */
1886 sprintf(buf,"%03ld", (long int)num);
1890 bool show_gold_on_floor = FALSE;
1893 * Examine a grid, return a keypress.
1895 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
1896 * indicates that the "space" key should scan through the contents
1897 * of the grid, instead of simply returning immediately. This lets
1898 * the "look" command get complete information, without making the
1899 * "target" command annoying.
1901 * The "info" argument contains the "commands" which should be shown
1902 * inside the "[xxx]" text. This string must never be empty, or grids
1903 * containing monsters will be displayed with an extra comma.
1905 * Note that if a monster is in the grid, we update both the monster
1906 * recall info and the health bar info to track that monster.
1908 * Eventually, we may allow multiple objects per grid, or objects
1909 * and terrain features in the same grid.
1911 * This function must handle blindness/hallucination.
1913 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
1915 cave_type *c_ptr = &cave[y][x];
1916 OBJECT_IDX this_o_idx, next_o_idx = 0;
1917 concptr s1 = "", s2 = "", s3 = "", x_info = "";
1920 feature_type *f_ptr;
1921 char query = '\001';
1922 char out_val[MAX_NLEN+80];
1923 OBJECT_IDX floor_list[23];
1924 ITEM_NUMBER floor_num = 0;
1926 /* Scan all objects in the grid */
1929 floor_num = scan_floor(floor_list, y, x, 0x02);
1933 x_info = _("x物 ", "x,");
1937 /* Hack -- under the player */
1938 if (player_bold(y, x))
1951 s1 = _("ターゲット:", "Target:");
1954 /* Hack -- hallucination */
1957 concptr name = _("何か奇妙な物", "something strange");
1959 /* Display a message */
1961 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
1963 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1967 move_cursor_relative(y, x);
1970 /* Stop on everything but "return" */
1971 if ((query != '\r') && (query != '\n')) return query;
1973 /* Repeat forever */
1978 /* Actual monsters */
1979 if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1981 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1982 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1983 GAME_TEXT m_name[MAX_NLEN];
1984 bool recall = FALSE;
1989 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1990 monster_race_track(m_ptr->ap_r_idx);
1991 health_track(c_ptr->m_idx);
2004 /* Recall on screen */
2005 screen_roff(m_ptr->ap_r_idx, 0);
2007 /* Hack -- Complete the prompt (again) */
2008 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
2015 /* Normal commands */
2016 if (query != 'r') break;
2021 /* Cleare recall text and repeat */
2027 /* Describe, and prompt for recall */
2028 evaluate_monster_exp(acount, m_ptr);
2031 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);
2033 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);
2039 move_cursor_relative(y, x);
2044 /* Normal commands */
2045 if (query != 'r') break;
2051 /* Always stop at "normal" keys */
2052 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2054 /* Sometimes stop at "space" key */
2055 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2057 /* Change the intro */
2058 s1 = _("それは", "It is ");
2060 /* Hack -- take account of gender */
2061 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
2062 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
2064 /* Use a preposition */
2073 /* Scan all objects being carried */
2074 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
2076 GAME_TEXT o_name[MAX_NLEN];
2079 o_ptr = &o_list[this_o_idx];
2081 /* Acquire next object */
2082 next_o_idx = o_ptr->next_o_idx;
2084 /* Obtain an object description */
2085 object_desc(o_name, o_ptr, 0);
2088 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2090 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2094 move_cursor_relative(y, x);
2097 /* Always stop at "normal" keys */
2098 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2100 /* Sometimes stop at "space" key */
2101 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2103 /* Change the intro */
2104 s2 = _("をまた", "also carrying ");
2107 /* Use a preposition */
2124 GAME_TEXT o_name[MAX_NLEN];
2127 o_ptr = &o_list[floor_list[0]];
2129 object_desc(o_name, o_ptr, 0);
2132 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2134 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2138 move_cursor_relative(y, x);
2147 /* Provide one cushion before item listing */
2150 /* Display rough information about items */
2152 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
2154 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
2158 move_cursor_relative(y, x);
2163 /* No request for listing */
2164 if (query != 'x' && query != ' ') return query;
2168 /** Display list of items **/
2170 /* Continue scrolling list if requested */
2178 show_gold_on_floor = TRUE;
2179 (void)show_floor(0, y, x, &min_width);
2180 show_gold_on_floor = FALSE;
2184 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
2186 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
2193 /* Exit unless 'Enter' */
2194 if (query != '\n' && query != '\r')
2199 /* Get the object being moved. */
2200 o_idx = c_ptr->o_idx;
2202 /* Only rotate a pile of two or more objects. */
2203 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
2205 /* Remove the first object from the list. */
2206 excise_object_idx(o_idx);
2208 /* Find end of the list. */
2210 while (o_list[i].next_o_idx)
2211 i = o_list[i].next_o_idx;
2213 /* Add after the last object. */
2214 o_list[i].next_o_idx = o_idx;
2216 /* Loop and re-display the list */
2223 /* Scan all objects in the grid */
2224 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2227 o_ptr = &o_list[this_o_idx];
2229 /* Acquire next object */
2230 next_o_idx = o_ptr->next_o_idx;
2232 if (o_ptr->marked & OM_FOUND)
2234 GAME_TEXT o_name[MAX_NLEN];
2239 /* Obtain an object description */
2240 object_desc(o_name, o_ptr, 0);
2243 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2245 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2249 move_cursor_relative(y, x);
2252 /* Always stop at "normal" keys */
2253 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2255 /* Sometimes stop at "space" key */
2256 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
2258 /* Change the intro */
2259 s1 = _("それは", "It is ");
2262 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
2276 /* Feature code (applying "mimic" field) */
2277 feat = get_feat_mimic(c_ptr);
2279 /* Require knowledge about grid, or ability to see grid */
2280 if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
2282 /* Forget feature */
2286 f_ptr = &f_info[feat];
2288 /* Terrain feature if needed */
2289 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
2293 /* Hack -- special handling for quest entrances */
2294 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
2296 /* Set the quest number temporary */
2297 IDX old_quest = p_ptr->inside_quest;
2300 /* Clear the text */
2301 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
2302 quest_text_line = 0;
2304 p_ptr->inside_quest = c_ptr->special;
2306 /* Get the quest text */
2307 init_flags = INIT_NAME_ONLY;
2309 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
2311 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
2312 quest[c_ptr->special].name, quest[c_ptr->special].level);
2314 /* Reset the old quest number */
2315 p_ptr->inside_quest = old_quest;
2318 /* Hack -- special handling for building doors */
2319 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
2321 name = building[f_ptr->subtype].name;
2323 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
2325 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
2327 else if (have_flag(f_ptr->flags, FF_TOWN))
2329 name = town[c_ptr->special].name;
2331 else if (p_ptr->wild_mode && (feat == feat_floor))
2333 name = _("道", "road");
2337 name = f_name + f_ptr->name;
2343 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
2344 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
2345 have_flag(f_ptr->flags, FF_TOWN)))
2347 s2 = _("の中", "in ");
2350 /* Hack -- special introduction for store & building doors -KMW- */
2351 if (have_flag(f_ptr->flags, FF_STORE) ||
2352 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
2353 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
2354 have_flag(f_ptr->flags, FF_ENTRANCE))
2359 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
2360 have_flag(f_ptr->flags, FF_TOWN) ||
2361 have_flag(f_ptr->flags, FF_SHALLOW) ||
2362 have_flag(f_ptr->flags, FF_DEEP))
2368 /* Pick proper indefinite article */
2369 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
2373 /* Display a message */
2377 if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
2378 else sprintf(f_idx_str, "%d", c_ptr->feat);
2380 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]);
2382 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);
2387 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
2389 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
2393 move_cursor_relative(y, x);
2396 /* Always stop at "normal" keys */
2397 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
2400 /* Stop on everything but "return" */
2401 if ((query != '\r') && (query != '\n')) return query;
2403 /* Repeat forever */
2409 * Handle "target" and "look".
2411 * Note that this code can be called from "get_aim_dir()".
2413 * All locations must be on the current panel. Consider the use of
2414 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
2415 * some form of "scrolling" the map around the cursor.
2416 * That is, consider the possibility of "auto-scrolling" the screen
2417 * while the cursor moves around. This may require changes in the
2418 * "update_monster()" code to allow "visibility" even if off panel, and
2419 * may require dynamic recalculation of the "temp" grid set.
2421 * Hack -- targeting/observing an "outer border grid" may induce
2422 * problems, so this is not currently allowed.
2424 * The player can use the direction keys to move among "interesting"
2425 * grids in a heuristic manner, or the "space", "+", and "-" keys to
2426 * move through the "interesting" grids in a sequential manner, or
2427 * can enter "location" mode, and use the direction keys to move one
2428 * grid at a time in any direction. The "t" (set target) command will
2429 * only target a monster (as opposed to a location) if the monster is
2430 * target_able and the "interesting" mode is being used.
2432 * The current grid is described using the "look" method above, and
2433 * a new command may be entered at any time, but note that if the
2434 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
2435 * where "space" has no obvious meaning) then "space" will scan
2436 * through the description of the current grid until done, instead
2437 * of immediately jumping to the next "interesting" grid. This
2438 * allows the "target" command to retain its old semantics.
2440 * The "*", "+", and "-" keys may always be used to jump immediately
2441 * to the next (or previous) interesting grid, in the proper mode.
2443 * The "return" key may always be used to scan through a complete
2444 * grid description (forever).
2446 * This command will cancel any old target, even if used from
2447 * inside the "look" command.
2449 bool target_set(BIT_FLAGS mode)
2452 POSITION y = p_ptr->y;
2453 POSITION x = p_ptr->x;
2463 get_screen_size(&wid, &hgt);
2468 if (rogue_like_commands)
2477 /* Prepare the "temp" array */
2478 target_set_prepare(mode);
2480 /* Start near the player */
2486 /* Interesting grids */
2493 change_panel_xy(y, x);
2495 if (!(mode & TARGET_LOOK)) prt_path(y, x);
2498 c_ptr = &cave[y][x];
2501 if (target_able(c_ptr->m_idx))
2503 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
2506 /* Dis-allow target */
2509 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
2515 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
2516 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
2517 strcat(info, cheatinfo);
2520 /* Describe and Prompt */
2522 query = target_set_aux(y, x, mode, info);
2526 /* Assume no "direction" */
2531 if (query == '\r') query = 't';
2549 if (target_able(c_ptr->m_idx))
2551 health_track(c_ptr->m_idx);
2552 target_who = c_ptr->m_idx;
2571 if (!expand_list) done = TRUE;
2581 if (!expand_list) done = TRUE;
2588 /* Recenter the map around the player */
2590 p_ptr->update |= (PU_MONSTERS);
2591 p_ptr->redraw |= (PR_MAP);
2592 p_ptr->window |= (PW_OVERHEAD);
2595 /* Recalculate interesting grids */
2596 target_set_prepare(mode);
2615 if(query == same_key)
2620 if (!expand_list) done = TRUE;
2625 /* Extract the action (if any) */
2626 d = get_keymap_dir(query);
2633 /* Hack -- move around */
2636 /* Modified to scroll to monster */
2637 POSITION y2 = panel_row_min;
2638 POSITION x2 = panel_col_min;
2640 /* Find a new monster */
2641 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
2643 /* Request to target past last interesting grid */
2644 while (flag && (i < 0))
2646 /* Note the change */
2647 if (change_panel(ddy[d], ddx[d]))
2652 /* Recalculate interesting grids */
2653 target_set_prepare(mode);
2655 /* Look at interesting grids */
2658 /* Find a new monster */
2659 i = target_pick(v, u, ddy[d], ddx[d]);
2665 /* Nothing interesting */
2668 POSITION dx = ddx[d];
2669 POSITION dy = ddy[d];
2671 /* Restore previous position */
2674 panel_bounds_center();
2676 p_ptr->update |= (PU_MONSTERS);
2677 p_ptr->redraw |= (PR_MAP);
2678 p_ptr->window |= (PW_OVERHEAD);
2681 /* Recalculate interesting grids */
2682 target_set_prepare(mode);
2684 /* Look at boring grids */
2691 /* Do not move horizontally if unnecessary */
2692 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2693 ((x > panel_col_min + wid / 2) && (dx < 0)))
2698 /* Do not move vertically if unnecessary */
2699 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2700 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2705 /* Apply the motion */
2706 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
2707 (x >= panel_col_min+wid) || (x < panel_col_min))
2709 if (change_panel(dy, dx)) target_set_prepare(mode);
2712 /* Slide into legality */
2713 if (x >= cur_wid-1) x = cur_wid - 2;
2714 else if (x <= 0) x = 1;
2716 /* Slide into legality */
2717 if (y >= cur_hgt-1) y = cur_hgt- 2;
2718 else if (y <= 0) y = 1;
2727 /* Arbitrary grids */
2730 bool move_fast = FALSE;
2732 if (!(mode & TARGET_LOOK)) prt_path(y, x);
2735 c_ptr = &cave[y][x];
2737 /* Default prompt */
2738 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
2743 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
2744 los(p_ptr->y, p_ptr->x, y, x),
2745 projectable(p_ptr->y, p_ptr->x, y, x));
2746 strcat(info, cheatinfo);
2749 /* Describe and Prompt (enable "TARGET_LOOK") */
2750 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
2752 /* Assume no direction */
2757 if (query == '\r') query = 't';
2760 /* Analyze the keypress */
2784 /* Recenter the map around the player */
2786 p_ptr->update |= (PU_MONSTERS);
2787 p_ptr->redraw |= (PR_MAP);
2788 p_ptr->window |= (PW_OVERHEAD);
2791 /* Recalculate interesting grids */
2792 target_set_prepare(mode);
2814 /* Pick a nearby monster */
2815 for (i = 0; i < temp_n; i++)
2817 t = distance(y, x, temp_y[i], temp_x[i]);
2827 /* Nothing interesting */
2828 if (bd == 999) flag = FALSE;
2835 /* Extract the action (if any) */
2836 d = get_keymap_dir(query);
2838 /* XTRA HACK MOVEFAST */
2839 if (isupper(query)) move_fast = TRUE;
2846 /* Handle "direction" */
2849 POSITION dx = ddx[d];
2850 POSITION dy = ddy[d];
2852 /* XTRA HACK MOVEFAST */
2855 int mag = MIN(wid / 2, hgt / 2);
2865 /* Do not move horizontally if unnecessary */
2866 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2867 ((x > panel_col_min + wid / 2) && (dx < 0)))
2872 /* Do not move vertically if unnecessary */
2873 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2874 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2879 /* Apply the motion */
2880 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2881 (x >= panel_col_min + wid) || (x < panel_col_min))
2883 if (change_panel(dy, dx)) target_set_prepare(mode);
2886 /* Slide into legality */
2887 if (x >= cur_wid-1) x = cur_wid - 2;
2888 else if (x <= 0) x = 1;
2890 /* Slide into legality */
2891 if (y >= cur_hgt-1) y = cur_hgt- 2;
2892 else if (y <= 0) y = 1;
2900 /* Clear the top line */
2903 /* Recenter the map around the player */
2905 p_ptr->update |= (PU_MONSTERS);
2906 p_ptr->redraw |= (PR_MAP);
2907 p_ptr->window |= (PW_OVERHEAD);
2910 /* Failure to set target */
2911 if (!target_who) return (FALSE);
2919 * Get an "aiming direction" from the user.
2921 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
2922 * "0" for "current target", and "-1" for "entry aborted".
2924 * Note that "Force Target", if set, will pre-empt user interaction,
2925 * if there is a usable target already set.
2927 * Note that confusion over-rides any (explicit?) user choice.
2929 bool get_aim_dir(DIRECTION *dp)
2938 /* Global direction */
2941 /* Hack -- auto-target if requested */
2942 if (use_old_target && target_okay()) dir = 5;
2944 if (repeat_pull(&code))
2949 if (!(code == 5 && !target_okay()))
2951 /* return (TRUE); */
2952 dir = (DIRECTION)code;
2955 *dp = (DIRECTION)code;
2957 /* Ask until satisfied */
2960 /* Choose a prompt */
2963 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2967 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2970 /* Get a command (or Cancel) */
2971 if (!get_com(p, &command, TRUE)) break;
2975 if (command == '\r') command = 't';
2978 /* Convert various keys to "standard" keys */
2981 /* Use current target */
2992 /* Set new target */
2997 if (target_set(TARGET_KILL)) dir = 5;
3003 /* Extract the action (if any) */
3004 dir = get_keymap_dir(command);
3010 /* Verify requested targets */
3011 if ((dir == 5) && !target_okay()) dir = 0;
3020 project_length = 0; /* reset to default */
3024 /* Save the direction */
3027 /* Check for confusion */
3028 if (p_ptr->confused)
3030 /* Random direction */
3031 dir = ddd[randint0(8)];
3034 /* Notice confusion */
3035 if (command_dir != dir)
3038 msg_print(_("あなたは混乱している。", "You are confused."));
3041 /* Save direction */
3044 /* repeat_push(dir); */
3045 repeat_push((COMMAND_CODE)command_dir);
3047 /* A "valid" direction was entered */
3052 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
3060 /* Global direction */
3063 if (repeat_pull(&code))
3065 dir = (DIRECTION)code;
3066 /* return (TRUE); */
3068 *dp = (DIRECTION)code;
3072 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3076 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3079 /* Get a direction */
3084 /* Get a command (or Cancel) */
3085 if (!get_com(prompt, &ch, TRUE)) break;
3088 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3094 /* Look up the direction */
3095 dir = get_keymap_dir(ch);
3101 /* Prevent weirdness */
3102 if ((dir == 5) && (!allow_under)) dir = 0;
3105 if (!dir) return (FALSE);
3107 /* Save desired direction */
3110 /* Apply "confusion" */
3111 if (p_ptr->confused)
3113 /* Standard confusion */
3114 if (randint0(100) < 75)
3116 /* Random direction */
3117 dir = ddd[randint0(8)];
3120 else if (p_ptr->riding && with_steed)
3122 monster_type *m_ptr = &m_list[p_ptr->riding];
3123 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3125 if (MON_CONFUSED(m_ptr))
3127 /* Standard confusion */
3128 if (randint0(100) < 75)
3130 /* Random direction */
3131 dir = ddd[randint0(8)];
3134 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3136 /* Random direction */
3137 dir = ddd[randint0(8)];
3139 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3141 /* Random direction */
3142 dir = ddd[randint0(8)];
3146 /* Notice confusion */
3147 if (command_dir != dir)
3149 if (p_ptr->confused)
3152 msg_print(_("あなたは混乱している。", "You are confused."));
3156 GAME_TEXT m_name[MAX_NLEN];
3157 monster_type *m_ptr = &m_list[p_ptr->riding];
3159 monster_desc(m_name, m_ptr, 0);
3160 if (MON_CONFUSED(m_ptr))
3162 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3166 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3171 /* Save direction */
3174 /* repeat_push(dir); */
3175 repeat_push((COMMAND_CODE)command_dir);
3182 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
3183 * and place it into "command_dir", unless we already have one.
3185 * This function should be used for all "repeatable" commands, such as
3186 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
3187 * as all commands which must reference a grid adjacent to the player,
3188 * and which may not reference the grid under the player. Note that,
3189 * for example, it is no longer possible to "disarm" or "open" chests
3190 * in the same grid as the player.
3192 * Direction "5" is illegal and will (cleanly) abort the command.
3194 * This function tracks and uses the "global direction", and uses
3195 * that as the "desired direction", to which "confusion" is applied.
3197 bool get_rep_dir(DIRECTION *dp, bool under)
3205 /* Global direction */
3208 if (repeat_pull(&code))
3210 dir = (DIRECTION)code;
3211 /* return (TRUE); */
3213 *dp = (DIRECTION)code;
3217 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3221 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3224 /* Get a direction */
3229 /* Get a command (or Cancel) */
3230 if (!get_com(prompt, &ch, TRUE)) break;
3233 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3239 /* Look up the direction */
3240 dir = get_keymap_dir(ch);
3246 /* Prevent weirdness */
3247 if ((dir == 5) && (!under)) dir = 0;
3250 if (!dir) return (FALSE);
3252 /* Save desired direction */
3255 /* Apply "confusion" */
3256 if (p_ptr->confused)
3258 /* Standard confusion */
3259 if (randint0(100) < 75)
3261 /* Random direction */
3262 dir = ddd[randint0(8)];
3265 else if (p_ptr->riding)
3267 monster_type *m_ptr = &m_list[p_ptr->riding];
3268 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3270 if (MON_CONFUSED(m_ptr))
3272 /* Standard confusion */
3273 if (randint0(100) < 75)
3275 /* Random direction */
3276 dir = ddd[randint0(8)];
3279 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3281 /* Random direction */
3282 dir = ddd[randint0(8)];
3284 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3286 /* Random direction */
3287 dir = ddd[randint0(8)];
3291 /* Notice confusion */
3292 if (command_dir != dir)
3294 if (p_ptr->confused)
3297 msg_print(_("あなたは混乱している。", "You are confused."));
3301 GAME_TEXT m_name[MAX_NLEN];
3302 monster_type *m_ptr = &m_list[p_ptr->riding];
3304 monster_desc(m_name, m_ptr, 0);
3305 if (MON_CONFUSED(m_ptr))
3307 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3311 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3316 /* Save direction */
3319 /* repeat_push(dir); */
3320 repeat_push((COMMAND_CODE)command_dir);
3328 * XAngband: determine if a given location is "interesting"
3329 * based on target_set_accept function.
3331 static bool tgt_pt_accept(POSITION y, POSITION x)
3336 if (!(in_bounds(y, x))) return (FALSE);
3338 /* Player grid is always interesting */
3339 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
3341 /* Handle hallucination */
3342 if (p_ptr->image) return (FALSE);
3344 /* Examine the grid */
3345 c_ptr = &cave[y][x];
3347 /* Interesting memorized features */
3348 if (c_ptr->info & (CAVE_MARK))
3351 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
3352 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
3354 /* Notice quest features */
3355 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
3356 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
3364 * XAngband: Prepare the "temp" array for "tget_pt"
3365 * based on target_set_prepare funciton.
3367 static void tgt_pt_prepare(void)
3371 /* Reset "temp" array */
3374 if (!expand_list) return;
3376 /* Scan the current panel */
3377 for (y = 1; y < cur_hgt; y++)
3379 for (x = 1; x < cur_wid; x++)
3381 /* Require "interesting" contents */
3382 if (!tgt_pt_accept(y, x)) continue;
3384 /* Save the location */
3391 /* Target the nearest monster for shooting */
3392 ang_sort_comp = ang_sort_comp_distance;
3393 ang_sort_swap = ang_sort_swap_distance;
3395 /* Sort the positions */
3396 ang_sort(temp_x, temp_y, temp_n);
3400 * old -- from PsiAngband.
3402 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
3407 bool success = FALSE;
3411 get_screen_size(&wid, &hgt);
3421 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
3422 msg_flag = FALSE; /* prevents "-more-" message. */
3424 while ((ch != ESCAPE) && !success)
3426 bool move_fast = FALSE;
3428 move_cursor_relative(y, x);
3440 if (player_bold(y, x)) ch = 0;
3443 else success = TRUE;
3447 /* XAngband: Move cursor to stairs */
3450 if (expand_list && temp_n)
3453 int cx = (panel_col_min + panel_col_max) / 2;
3454 int cy = (panel_row_min + panel_row_max) / 2;
3458 /* Skip stairs which have defferent distance */
3459 for (; n < temp_n; ++ n)
3461 cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
3463 if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
3464 cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
3471 if (n == temp_n) /* Loop out taget list */
3476 verify_panel(); /* Move cursor to player */
3478 p_ptr->update |= (PU_MONSTERS);
3480 p_ptr->redraw |= (PR_MAP);
3482 p_ptr->window |= (PW_OVERHEAD);
3485 else /* move cursor to next stair and change panel */
3490 dy = 2 * (y - cy) / hgt;
3491 dx = 2 * (x - cx) / wid;
3492 if (dy || dx) change_panel(dy, dx);
3498 /* Look up the direction */
3499 d = get_keymap_dir(ch);
3501 /* XTRA HACK MOVEFAST */
3502 if (isupper(ch)) move_fast = TRUE;
3504 /* Handle "direction" */
3510 /* XTRA HACK MOVEFAST */
3513 int mag = MIN(wid / 2, hgt / 2);
3523 /* Do not move horizontally if unnecessary */
3524 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3525 ((x > panel_col_min + wid / 2) && (dx < 0)))
3530 /* Do not move vertically if unnecessary */
3531 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3532 ((y > panel_row_min + hgt / 2) && (dy < 0)))
3537 /* Apply the motion */
3538 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
3539 (x >= panel_col_min + wid) || (x < panel_col_min))
3541 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
3542 change_panel(dy, dx);
3545 /* Slide into legality */
3546 if (x >= cur_wid-1) x = cur_wid - 2;
3547 else if (x <= 0) x = 1;
3549 /* Slide into legality */
3550 if (y >= cur_hgt-1) y = cur_hgt- 2;
3551 else if (y <= 0) y = 1;
3558 /* Clear the top line */
3561 /* Recenter the map around the player */
3564 p_ptr->update |= (PU_MONSTERS);
3566 p_ptr->redraw |= (PR_MAP);
3568 p_ptr->window |= (PW_OVERHEAD);
3577 bool get_hack_dir(DIRECTION *dp)
3585 /* Global direction */
3588 /* (No auto-targeting) */
3590 /* Ask until satisfied */
3593 /* Choose a prompt */
3596 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
3600 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
3603 /* Get a command (or Cancel) */
3604 if (!get_com(p, &command, TRUE)) break;
3608 if (command == '\r') command = 't';
3611 /* Convert various keys to "standard" keys */
3614 /* Use current target */
3625 /* Set new target */
3630 if (target_set(TARGET_KILL)) dir = 5;
3636 /* Look up the direction */
3637 dir = get_keymap_dir(command);
3643 /* Verify requested targets */
3644 if ((dir == 5) && !target_okay()) dir = 0;
3651 if (!dir) return (FALSE);
3653 /* Save the direction */
3656 /* Check for confusion */
3657 if (p_ptr->confused)
3659 /* Random direction */
3660 dir = ddd[randint0(8)];
3663 /* Notice confusion */
3664 if (command_dir != dir)
3667 msg_print(_("あなたは混乱している。", "You are confused."));
3670 /* Save direction */
3673 /* A "valid" direction was entered */
3679 * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
3680 * @param sval 射撃武器のアイテム副分類ID
3681 * @return 消費する基本エネルギー
3683 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
3685 ENERGY energy = 10000;
3687 /* Analyze the launcher */
3690 /* Sling and ammo */
3697 /* Short Bow and Arrow */
3704 /* Long Bow and Arrow */
3711 /* Bow of irresponsiblity and Arrow */
3718 /* Light Crossbow and Bolt */
3725 /* Heavy Crossbow and Bolt */
3740 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
3744 /* Analyze the launcher */
3747 /* Sling and ammo */
3754 /* Short Bow and Arrow */
3761 /* Long Bow and Arrow */
3768 /* Bow of irresponsiblity and Arrow */
3775 /* Light Crossbow and Bolt */
3782 /* Heavy Crossbow and Bolt */
3795 * Display a rumor and apply its effects
3798 IDX rumor_num(char *zz, IDX max_idx)
3800 if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
3801 return (IDX)atoi(zz);
3804 concptr rumor_bind_name(char *base, concptr fullname)
3808 s = strstr(base, "{Name}");
3812 v = format("%s%s%s", base, fullname, (s + 6));
3822 void display_rumor(bool ex)
3830 if (randint0(3) == 0) section = 1;
3833 err = _(get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10),
3834 get_rnd_line("rumors.txt", section, Rumor));
3835 if (err) strcpy(Rumor, _("嘘の噂もある。", "Some rumors are wrong."));
3839 if (strncmp(Rumor, "R:", 2) == 0)
3842 concptr rumor_msg = NULL;
3843 concptr rumor_eff_format = NULL;
3844 char fullname[1024] = "";
3846 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
3848 if (strcmp(zz[0], "ARTIFACT") == 0)
3852 object_type *q_ptr = &forge;
3853 artifact_type *a_ptr;
3857 a_idx = rumor_num(zz[1], max_a_idx);
3859 a_ptr = &a_info[a_idx];
3860 if (a_ptr->name) break;
3863 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
3864 object_prep(q_ptr, k_idx);
3865 q_ptr->name1 = a_idx;
3866 q_ptr->ident = IDENT_STORE;
3867 object_desc(fullname, q_ptr, OD_NAME_ONLY);
3869 else if (strcmp(zz[0], "MONSTER") == 0)
3872 monster_race *r_ptr;
3876 r_idx = rumor_num(zz[1], max_r_idx);
3877 r_ptr = &r_info[r_idx];
3878 if (r_ptr->name) break;
3881 strcpy(fullname, r_name + r_ptr->name);
3883 /* Remember this monster */
3884 if (!r_ptr->r_sights)
3889 else if (strcmp(zz[0], "DUNGEON") == 0)
3892 dungeon_info_type *d_ptr;
3896 d_idx = rumor_num(zz[1], max_d_idx);
3897 d_ptr = &d_info[d_idx];
3898 if (d_ptr->name) break;
3901 strcpy(fullname, d_name + d_ptr->name);
3903 if (!max_dlv[d_idx])
3905 max_dlv[d_idx] = d_ptr->mindepth;
3906 rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
3909 else if (strcmp(zz[0], "TOWN") == 0)
3916 t_idx = rumor_num(zz[1], NO_TOWN);
3917 if (town[t_idx].name) break;
3920 strcpy(fullname, town[t_idx].name);
3922 visit = (1L << (t_idx - 1));
3923 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
3925 p_ptr->visit |= visit;
3926 rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
3930 rumor_msg = rumor_bind_name(zz[2], fullname);
3931 msg_print(rumor_msg);
3932 if (rumor_eff_format)
3935 msg_format(rumor_eff_format, fullname);
3940 if (err) msg_print(_("この情報は間違っている。", "This information is wrong."));
3944 msg_format("%s", Rumor);