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 #include "floor-events.h"
27 #define REWARD_CHANCE 10
31 * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
32 * Advance experience levels and print experience
35 void check_experience(void)
37 bool level_reward = FALSE;
38 bool level_mutation = FALSE;
39 bool level_inc_stat = FALSE;
40 bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
41 PLAYER_LEVEL old_lev = p_ptr->lev;
43 /* Hack -- lower limit */
44 if (p_ptr->exp < 0) p_ptr->exp = 0;
45 if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
46 if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
48 /* Hack -- upper limit */
49 if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
50 if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
51 if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
53 /* Hack -- maintain "max" experience */
54 if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
56 /* Hack -- maintain "max max" experience */
57 if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
59 /* Redraw experience */
60 p_ptr->redraw |= (PR_EXP);
64 /* Lose levels while possible */
65 while ((p_ptr->lev > 1) &&
66 (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
70 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
71 p_ptr->redraw |= (PR_LEV | PR_TITLE);
72 p_ptr->window |= (PW_PLAYER);
77 /* Gain levels while possible */
78 while ((p_ptr->lev < PY_MAX_LEVEL) &&
79 (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
84 /* Save the highest level */
85 if (p_ptr->lev > p_ptr->max_plv)
87 p_ptr->max_plv = p_ptr->lev;
89 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
90 (p_ptr->muta2 & MUT2_CHAOS_GIFT))
94 if (p_ptr->prace == RACE_BEASTMAN)
96 if (one_in_(5)) level_mutation = TRUE;
98 level_inc_stat = TRUE;
100 do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
105 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
107 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
108 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
109 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
119 if(!(p_ptr->max_plv % 10))
128 cnv_stat(p_ptr->stat_max[0], tmp);
129 prt(format(_(" a) 腕力 (現在値 %s)", " a) Str (cur %s)"), tmp), 2, 14);
130 cnv_stat(p_ptr->stat_max[1], tmp);
131 prt(format(_(" b) 知能 (現在値 %s)", " a) Int (cur %s)"), tmp), 3, 14);
132 cnv_stat(p_ptr->stat_max[2], tmp);
133 prt(format(_(" c) 賢さ (現在値 %s)", " a) Wis (cur %s)"), tmp), 4, 14);
134 cnv_stat(p_ptr->stat_max[3], tmp);
135 prt(format(_(" d) 器用 (現在値 %s)", " a) Dex (cur %s)"), tmp), 5, 14);
136 cnv_stat(p_ptr->stat_max[4], tmp);
137 prt(format(_(" e) 耐久 (現在値 %s)", " a) Con (cur %s)"), tmp), 6, 14);
138 cnv_stat(p_ptr->stat_max[5], tmp);
139 prt(format(_(" f) 魅力 (現在値 %s)", " a) Chr (cur %s)"), tmp), 7, 14);
142 prt(_(" どの能力値を上げますか?", " Which stat do you want to raise?"), 1, 14);
147 if ((choice >= 'a') && (choice <= 'f')) break;
149 for(n = 0; n < A_MAX; n++)
150 if (n != choice - 'a')
152 if (get_check(_("よろしいですか?", "Are you sure? "))) break;
154 do_inc_stat(choice - 'a');
157 else if(!(p_ptr->max_plv % 2))
158 do_inc_stat(randint0(6));
163 msg_print(_("あなたは変わった気がする...", "You feel different..."));
164 (void)gain_random_mutation(0);
165 level_mutation = FALSE;
169 * 報酬でレベルが上ると再帰的に check_experience() が
174 gain_level_reward(0);
175 level_reward = FALSE;
178 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
179 p_ptr->redraw |= (PR_LEV | PR_TITLE);
180 p_ptr->window |= (PW_PLAYER | PW_SPELL);
184 /* Load an autopick preference file */
185 if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
191 * @brief モンスターを撃破した際の述語メッセージを返す /
192 * Return monster death string
193 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
194 * @return 撃破されたモンスターの述語
196 concptr extract_note_dies(MONRACE_IDX r_idx)
198 monster_race *r_ptr = &r_info[r_idx];
199 /* Some monsters get "destroyed" */
200 if (!monster_living(r_idx))
204 for (i = 0; i < 4; i++)
206 if (r_ptr->blow[i].method == RBM_EXPLODE)
208 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
211 return _("を倒した。", " is destroyed.");
214 /* Assume a default death */
215 return _("は死んだ。", " dies.");
221 * @brief 現在のコンソール表示の縦横を返す。 /
222 * Get term size and calculate screen size
223 * @param wid_p コンソールの表示幅文字数を返す
224 * @param hgt_p コンソールの表示行数を返す
227 void get_screen_size(TERM_LEN *wid_p, TERM_LEN *hgt_p)
229 Term_get_size(wid_p, hgt_p);
230 *hgt_p -= ROW_MAP + 2;
231 *wid_p -= COL_MAP + 2;
232 if (use_bigtile) *wid_p /= 2;
237 * @brief コンソール上におけるマップ表示の左上位置を返す /
238 * Calculates current boundaries Called below and from "do_cmd_locate()".
241 void panel_bounds_center(void)
245 get_screen_size(&wid, &hgt);
247 panel_row_max = panel_row_min + hgt - 1;
248 panel_row_prt = panel_row_min - 1;
249 panel_col_max = panel_col_min + wid - 1;
250 panel_col_prt = panel_col_min - 13;
255 * @brief コンソールのリサイズに合わせてマップを再描画する /
256 * Map resizing whenever the main term changes size
259 void resize_map(void)
261 /* Only if the dungeon exists */
262 if (!character_dungeon) return;
264 /* Mega-Hack -- no panel yet */
268 /* Reset the panels */
269 panel_row_min = cur_hgt;
270 panel_col_min = cur_wid;
274 p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
275 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
276 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
277 p_ptr->update |= (PU_MONSTERS);
278 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
285 * Place the cursor on the player
287 if (can_save) move_cursor_relative(p_ptr->y, p_ptr->x);
293 * @brief コンソールを再描画する /
294 * Redraw a term when it is resized
297 void redraw_window(void)
299 /* Only if the dungeon exists */
300 if (!character_dungeon) return;
302 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
303 p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
311 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
312 * @param dy 変更先のフロアY座標
313 * @param dx 変更先のフロアX座標
314 * Handle a request to change the current panel
315 * Return TRUE if the panel was changed.
316 * Also used in do_cmd_locate
317 * @return 実際に再描画が必要だった場合TRUEを返す
319 bool change_panel(POSITION dy, POSITION dx)
324 get_screen_size(&wid, &hgt);
326 /* Apply the motion */
327 y = panel_row_min + dy * hgt / 2;
328 x = panel_col_min + dx * wid / 2;
331 if (y > cur_hgt - hgt) y = cur_hgt - hgt;
335 if (x > cur_wid - wid) x = cur_wid - wid;
338 /* Handle "changes" */
339 if ((y != panel_row_min) || (x != panel_col_min))
341 /* Save the new panel info */
345 /* Recalculate the boundaries */
346 panel_bounds_center();
348 p_ptr->update |= (PU_MONSTERS);
349 p_ptr->redraw |= (PR_MAP);
361 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
362 * @param y 変更先のフロアY座標
363 * @param x 変更先のフロアX座標
365 * Handle a request to change the current panel
366 * Return TRUE if the panel was changed.
367 * Also used in do_cmd_locate
368 * @return 実際に再描画が必要だった場合TRUEを返す
370 static bool change_panel_xy(POSITION y, POSITION x)
372 POSITION dy = 0, dx = 0;
375 get_screen_size(&wid, &hgt);
377 if (y < panel_row_min) dy = -1;
378 if (y > panel_row_max) dy = 1;
379 if (x < panel_col_min) dx = -1;
380 if (x > panel_col_max) dx = 1;
382 if (!dy && !dx) return (FALSE);
384 return change_panel(dy, dx);
389 * @brief マップ描画のフォーカスを当てるべき座標を更新する
391 * Given an row (y) and col (x), this routine detects when a move
392 * off the screen has occurred and figures new borders. -RAK-
393 * "Update" forces a "full update" to take place.
394 * The map is reprinted if necessary, and "TRUE" is returned.
395 * @return 実際に再描画が必要だった場合TRUEを返す
397 void verify_panel(void)
399 POSITION y = p_ptr->y;
400 POSITION x = p_ptr->x;
408 get_screen_size(&wid, &hgt);
410 max_prow_min = cur_hgt - hgt;
411 max_pcol_min = cur_wid - wid;
413 /* Bounds checking */
414 if (max_prow_min < 0) max_prow_min = 0;
415 if (max_pcol_min < 0) max_pcol_min = 0;
417 /* Center on player */
418 if (center_player && (center_running || !running))
420 /* Center vertically */
421 prow_min = y - hgt / 2;
422 if (prow_min < 0) prow_min = 0;
423 else if (prow_min > max_prow_min) prow_min = max_prow_min;
425 /* Center horizontally */
426 pcol_min = x - wid / 2;
427 if (pcol_min < 0) pcol_min = 0;
428 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
432 prow_min = panel_row_min;
433 pcol_min = panel_col_min;
435 /* Scroll screen when 2 grids from top/bottom edge */
436 if (y > panel_row_max - 2)
438 while (y > prow_min + hgt-1 - 2)
440 prow_min += (hgt / 2);
444 if (y < panel_row_min + 2)
446 while (y < prow_min + 2)
448 prow_min -= (hgt / 2);
452 if (prow_min > max_prow_min) prow_min = max_prow_min;
453 if (prow_min < 0) prow_min = 0;
455 /* Scroll screen when 4 grids from left/right edge */
456 if (x > panel_col_max - 4)
458 while (x > pcol_min + wid-1 - 4)
460 pcol_min += (wid / 2);
464 if (x < panel_col_min + 4)
466 while (x < pcol_min + 4)
468 pcol_min -= (wid / 2);
472 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
473 if (pcol_min < 0) pcol_min = 0;
476 /* Check for "no change" */
477 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
479 /* Save the new panel info */
480 panel_row_min = prow_min;
481 panel_col_min = pcol_min;
483 /* Hack -- optional disturb on "panel change" */
484 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
486 /* Recalculate the boundaries */
487 panel_bounds_center();
489 p_ptr->update |= (PU_MONSTERS);
490 p_ptr->redraw |= (PR_MAP);
491 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
496 * Monster health description
498 concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
500 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
507 /* Determine if the monster is "living" */
508 living = monster_living(m_ptr->ap_r_idx);
510 /* Calculate a health "percentage" */
511 perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
513 /* Healthy monsters */
514 if (m_ptr->hp >= m_ptr->maxhp)
516 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
521 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
526 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
531 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
536 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
539 /* Need attitude information? */
542 /* Full information is not needed */
545 else if (is_pet(m_ptr))
547 attitude = _(", ペット", ", pet");
549 else if (is_friendly(m_ptr))
551 attitude = _(", 友好的", ", friendly");
555 attitude = _("", "");
559 if (m_ptr->smart & SM_CLONED)
568 /* Display monster's level --- idea borrowed from ToME */
569 if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
571 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
575 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
582 /*** Targeting Code ***/
586 * Determine is a monster makes a reasonable target
588 * The concept of "targeting" was stolen from "Morgul" (?)
590 * The player can target any location, or any "target-able" monster.
592 * Currently, a monster is "target_able" if it is visible, and if
593 * the player can hit it with a projection, and the player is not
594 * hallucinating. This allows use of "use closest target" macros.
596 * Future versions may restrict the ability to target "trappers"
597 * and "mimics", but the semantics is a little bit weird.
599 bool target_able(MONSTER_IDX m_idx)
601 monster_type *m_ptr = &m_list[m_idx];
603 /* Monster must be alive */
604 if (!m_ptr->r_idx) return (FALSE);
606 /* Hack -- no targeting hallucinations */
607 if (p_ptr->image) return (FALSE);
609 /* Monster must be visible */
610 if (!m_ptr->ml) return (FALSE);
612 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
614 /* Monster must be projectable */
615 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
617 /* Hack -- Never target trappers */
618 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
628 * Update (if necessary) and verify (if possible) the target.
630 * We return TRUE if the target is "okay" and FALSE otherwise.
632 bool target_okay(void)
634 /* Accept stationary targets */
635 if (target_who < 0) return (TRUE);
637 /* Check moving targets */
640 /* Accept reasonable targets */
641 if (target_able(target_who))
643 monster_type *m_ptr = &m_list[target_who];
645 /* Acquire monster location */
646 target_row = m_ptr->fy;
647 target_col = m_ptr->fx;
654 /* Assume no target */
660 * Sorting hook -- comp function -- by "distance to player"
662 * We use "u" and "v" to point to arrays of "x" and "y" positions,
663 * and sort the arrays by double-distance to the player.
665 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
667 POSITION *x = (POSITION*)(u);
668 POSITION *y = (POSITION*)(v);
670 POSITION da, db, kx, ky;
672 /* Absolute distance components */
673 kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
674 ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
676 /* Approximate Double Distance to the first point */
677 da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
679 /* Absolute distance components */
680 kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
681 ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
683 /* Approximate Double Distance to the first point */
684 db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
686 /* Compare the distances */
692 * Sorting hook -- comp function -- by importance level of grids
694 * We use "u" and "v" to point to arrays of "x" and "y" positions,
695 * and sort the arrays by level of monster
697 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
699 POSITION *x = (POSITION*)(u);
700 POSITION *y = (POSITION*)(v);
701 cave_type *ca_ptr = &cave[y[a]][x[a]];
702 cave_type *cb_ptr = &cave[y[b]][x[b]];
703 monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
704 monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
705 monster_race *ap_ra_ptr, *ap_rb_ptr;
707 /* The player grid */
708 if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
709 if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
711 /* Extract monster race */
712 if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
713 else ap_ra_ptr = NULL;
714 if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
715 else ap_rb_ptr = NULL;
717 if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
718 if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
720 /* Compare two monsters */
721 if (ap_ra_ptr && ap_rb_ptr)
723 /* Unique monsters first */
724 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
725 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
727 /* Shadowers first (あやしい影) */
728 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
729 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
731 /* Unknown monsters first */
732 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
733 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
735 /* Higher level monsters first (if known) */
736 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
738 if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
739 if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
742 /* Sort by index if all conditions are same */
743 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
744 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
747 /* An object get higher priority */
748 if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
749 if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
751 /* Priority from the terrain */
752 if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
753 if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
755 /* If all conditions are same, compare distance */
756 return ang_sort_comp_distance(u, v, a, b);
761 * Sorting hook -- swap function -- by "distance to player"
763 * We use "u" and "v" to point to arrays of "x" and "y" positions,
764 * and sort the arrays by distance to the player.
766 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
768 POSITION *x = (POSITION*)(u);
769 POSITION *y = (POSITION*)(v);
787 * Hack -- help "select" a location (see below)
789 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
792 POSITION x2, y2, x3, y3, x4, y4;
793 POSITION_IDX b_i = -1, b_v = 9999;
796 /* Scan the locations */
797 for (i = 0; i < temp_n; i++)
803 /* Directed distance */
807 /* Verify quadrant */
808 if (dx && (x3 * dx <= 0)) continue;
809 if (dy && (y3 * dy <= 0)) continue;
811 /* Absolute distance */
815 /* Verify quadrant */
816 if (dy && !dx && (x4 > y4)) continue;
817 if (dx && !dy && (y4 > x4)) continue;
819 /* Approximate Double Distance */
820 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
822 /* Penalize location */
825 if ((b_i >= 0) && (v >= b_v)) continue;
835 * Hack -- determine if a given location is "interesting"
837 static bool target_set_accept(POSITION y, POSITION x)
840 OBJECT_IDX this_o_idx, next_o_idx = 0;
843 if (!(in_bounds(y, x))) return (FALSE);
845 /* Player grid is always interesting */
846 if (player_bold(y, x)) return (TRUE);
848 /* Handle hallucination */
849 if (p_ptr->image) return (FALSE);
851 /* Examine the grid */
854 /* Visible monsters */
857 monster_type *m_ptr = &m_list[c_ptr->m_idx];
859 /* Visible monsters */
860 if (m_ptr->ml) return (TRUE);
863 /* Scan all objects in the grid */
864 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
867 o_ptr = &o_list[this_o_idx];
869 /* Acquire next object */
870 next_o_idx = o_ptr->next_o_idx;
872 /* Memorized object */
873 if (o_ptr->marked & OM_FOUND) return (TRUE);
876 /* Interesting memorized features */
877 if (c_ptr->info & (CAVE_MARK))
879 /* Notice object features */
880 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
882 /* Feature code (applying "mimic" field) */
883 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
891 * Prepare the "temp" array for "target_set"
893 * Return the number of target_able monsters in the set.
895 static void target_set_prepare(BIT_FLAGS mode)
898 POSITION min_hgt, max_hgt, min_wid, max_wid;
900 if (mode & TARGET_KILL)
903 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
904 max_hgt = MIN((p_ptr->y + MAX_RANGE), cur_hgt - 1);
905 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
906 max_wid = MIN((p_ptr->x + MAX_RANGE), cur_wid - 1);
908 else /* not targetting */
911 min_hgt = panel_row_min;
912 max_hgt = panel_row_max;
913 min_wid = panel_col_min;
914 max_wid = panel_col_max;
917 /* Reset "temp" array */
920 /* Scan the current panel */
921 for (y = min_hgt; y <= max_hgt; y++)
923 for (x = min_wid; x <= max_wid; x++)
927 /* Require "interesting" contents */
928 if (!target_set_accept(y, x)) continue;
932 /* Require target_able monsters for "TARGET_KILL" */
933 if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
935 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
937 /* Save the location */
944 /* Set the sort hooks */
945 if (mode & (TARGET_KILL))
947 /* Target the nearest monster for shooting */
948 ang_sort_comp = ang_sort_comp_distance;
949 ang_sort_swap = ang_sort_swap_distance;
953 /* Look important grids first in Look command */
954 ang_sort_comp = ang_sort_comp_importance;
955 ang_sort_swap = ang_sort_swap_distance;
958 /* Sort the positions */
959 ang_sort(temp_x, temp_y, temp_n);
961 if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
966 temp_y[0] = temp_y[1];
969 temp_x[0] = temp_x[1];
974 void target_set_prepare_look(void){
975 target_set_prepare(TARGET_LOOK);
980 * Evaluate number of kill needed to gain level
982 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
984 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
986 s32b exp_mon, exp_adv;
987 u32b exp_mon_frac, exp_adv_frac;
989 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
994 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
1004 /* The monster's experience point (assuming average monster speed) */
1005 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
1007 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
1010 /* Total experience value for next level */
1011 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
1013 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
1015 /* Experience value need to get */
1016 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
1019 /* You need to kill at least one monster to get any experience */
1020 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1021 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
1023 /* Extract number of monsters needed */
1024 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1026 /* If 999 or more monsters needed, only display "999". */
1027 num = MIN(999, exp_adv_frac);
1029 /* Display the number */
1030 sprintf(buf,"%03ld", (long int)num);
1034 bool show_gold_on_floor = FALSE;
1037 * Examine a grid, return a keypress.
1039 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
1040 * indicates that the "space" key should scan through the contents
1041 * of the grid, instead of simply returning immediately. This lets
1042 * the "look" command get complete information, without making the
1043 * "target" command annoying.
1045 * The "info" argument contains the "commands" which should be shown
1046 * inside the "[xxx]" text. This string must never be empty, or grids
1047 * containing monsters will be displayed with an extra comma.
1049 * Note that if a monster is in the grid, we update both the monster
1050 * recall info and the health bar info to track that monster.
1052 * Eventually, we may allow multiple objects per grid, or objects
1053 * and terrain features in the same grid.
1055 * This function must handle blindness/hallucination.
1057 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
1059 cave_type *c_ptr = &cave[y][x];
1060 OBJECT_IDX this_o_idx, next_o_idx = 0;
1061 concptr s1 = "", s2 = "", s3 = "", x_info = "";
1064 feature_type *f_ptr;
1065 char query = '\001';
1066 char out_val[MAX_NLEN+80];
1067 OBJECT_IDX floor_list[23];
1068 ITEM_NUMBER floor_num = 0;
1070 /* Scan all objects in the grid */
1073 floor_num = scan_floor(floor_list, y, x, 0x02);
1077 x_info = _("x物 ", "x,");
1081 /* Hack -- under the player */
1082 if (player_bold(y, x))
1095 s1 = _("ターゲット:", "Target:");
1098 /* Hack -- hallucination */
1101 concptr name = _("何か奇妙な物", "something strange");
1103 /* Display a message */
1105 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
1107 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1111 move_cursor_relative(y, x);
1114 /* Stop on everything but "return" */
1115 if ((query != '\r') && (query != '\n')) return query;
1117 /* Repeat forever */
1122 /* Actual monsters */
1123 if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1125 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1126 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1127 GAME_TEXT m_name[MAX_NLEN];
1128 bool recall = FALSE;
1133 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1134 monster_race_track(m_ptr->ap_r_idx);
1135 health_track(c_ptr->m_idx);
1148 /* Recall on screen */
1149 screen_roff(m_ptr->ap_r_idx, 0);
1151 /* Hack -- Complete the prompt (again) */
1152 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
1159 /* Normal commands */
1160 if (query != 'r') break;
1165 /* Cleare recall text and repeat */
1171 /* Describe, and prompt for recall */
1172 evaluate_monster_exp(acount, m_ptr);
1175 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);
1177 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);
1183 move_cursor_relative(y, x);
1188 /* Normal commands */
1189 if (query != 'r') break;
1195 /* Always stop at "normal" keys */
1196 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1198 /* Sometimes stop at "space" key */
1199 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1201 /* Change the intro */
1202 s1 = _("それは", "It is ");
1204 /* Hack -- take account of gender */
1205 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
1206 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
1208 /* Use a preposition */
1217 /* Scan all objects being carried */
1218 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
1220 GAME_TEXT o_name[MAX_NLEN];
1223 o_ptr = &o_list[this_o_idx];
1225 /* Acquire next object */
1226 next_o_idx = o_ptr->next_o_idx;
1228 /* Obtain an object description */
1229 object_desc(o_name, o_ptr, 0);
1232 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1234 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1238 move_cursor_relative(y, x);
1241 /* Always stop at "normal" keys */
1242 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1244 /* Sometimes stop at "space" key */
1245 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1247 /* Change the intro */
1248 s2 = _("をまた", "also carrying ");
1251 /* Use a preposition */
1268 GAME_TEXT o_name[MAX_NLEN];
1271 o_ptr = &o_list[floor_list[0]];
1273 object_desc(o_name, o_ptr, 0);
1276 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1278 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1282 move_cursor_relative(y, x);
1291 /* Provide one cushion before item listing */
1294 /* Display rough information about items */
1296 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
1298 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
1302 move_cursor_relative(y, x);
1307 /* No request for listing */
1308 if (query != 'x' && query != ' ') return query;
1312 /** Display list of items **/
1314 /* Continue scrolling list if requested */
1322 show_gold_on_floor = TRUE;
1323 (void)show_floor(0, y, x, &min_width);
1324 show_gold_on_floor = FALSE;
1328 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
1330 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
1337 /* Exit unless 'Enter' */
1338 if (query != '\n' && query != '\r')
1343 /* Get the object being moved. */
1344 o_idx = c_ptr->o_idx;
1346 /* Only rotate a pile of two or more objects. */
1347 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
1349 /* Remove the first object from the list. */
1350 excise_object_idx(o_idx);
1352 /* Find end of the list. */
1354 while (o_list[i].next_o_idx)
1355 i = o_list[i].next_o_idx;
1357 /* Add after the last object. */
1358 o_list[i].next_o_idx = o_idx;
1360 /* Loop and re-display the list */
1367 /* Scan all objects in the grid */
1368 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1371 o_ptr = &o_list[this_o_idx];
1373 /* Acquire next object */
1374 next_o_idx = o_ptr->next_o_idx;
1376 if (o_ptr->marked & OM_FOUND)
1378 GAME_TEXT o_name[MAX_NLEN];
1383 /* Obtain an object description */
1384 object_desc(o_name, o_ptr, 0);
1387 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1389 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1393 move_cursor_relative(y, x);
1396 /* Always stop at "normal" keys */
1397 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1399 /* Sometimes stop at "space" key */
1400 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
1402 /* Change the intro */
1403 s1 = _("それは", "It is ");
1406 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
1420 /* Feature code (applying "mimic" field) */
1421 feat = get_feat_mimic(c_ptr);
1423 /* Require knowledge about grid, or ability to see grid */
1424 if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
1426 /* Forget feature */
1430 f_ptr = &f_info[feat];
1432 /* Terrain feature if needed */
1433 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
1437 /* Hack -- special handling for quest entrances */
1438 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
1440 /* Set the quest number temporary */
1441 IDX old_quest = p_ptr->inside_quest;
1444 /* Clear the text */
1445 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
1446 quest_text_line = 0;
1448 p_ptr->inside_quest = c_ptr->special;
1450 /* Get the quest text */
1451 init_flags = INIT_NAME_ONLY;
1453 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
1455 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
1456 quest[c_ptr->special].name, quest[c_ptr->special].level);
1458 /* Reset the old quest number */
1459 p_ptr->inside_quest = old_quest;
1462 /* Hack -- special handling for building doors */
1463 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
1465 name = building[f_ptr->subtype].name;
1467 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
1469 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
1471 else if (have_flag(f_ptr->flags, FF_TOWN))
1473 name = town[c_ptr->special].name;
1475 else if (p_ptr->wild_mode && (feat == feat_floor))
1477 name = _("道", "road");
1481 name = f_name + f_ptr->name;
1487 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
1488 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
1489 have_flag(f_ptr->flags, FF_TOWN)))
1491 s2 = _("の中", "in ");
1494 /* Hack -- special introduction for store & building doors -KMW- */
1495 if (have_flag(f_ptr->flags, FF_STORE) ||
1496 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
1497 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
1498 have_flag(f_ptr->flags, FF_ENTRANCE))
1503 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
1504 have_flag(f_ptr->flags, FF_TOWN) ||
1505 have_flag(f_ptr->flags, FF_SHALLOW) ||
1506 have_flag(f_ptr->flags, FF_DEEP))
1512 /* Pick proper indefinite article */
1513 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
1517 /* Display a message */
1521 if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
1522 else sprintf(f_idx_str, "%d", c_ptr->feat);
1524 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]);
1526 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);
1531 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
1533 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1537 move_cursor_relative(y, x);
1540 /* Always stop at "normal" keys */
1541 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
1544 /* Stop on everything but "return" */
1545 if ((query != '\r') && (query != '\n')) return query;
1547 /* Repeat forever */
1553 * Handle "target" and "look".
1555 * Note that this code can be called from "get_aim_dir()".
1557 * All locations must be on the current panel. Consider the use of
1558 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1559 * some form of "scrolling" the map around the cursor.
1560 * That is, consider the possibility of "auto-scrolling" the screen
1561 * while the cursor moves around. This may require changes in the
1562 * "update_monster()" code to allow "visibility" even if off panel, and
1563 * may require dynamic recalculation of the "temp" grid set.
1565 * Hack -- targeting/observing an "outer border grid" may induce
1566 * problems, so this is not currently allowed.
1568 * The player can use the direction keys to move among "interesting"
1569 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1570 * move through the "interesting" grids in a sequential manner, or
1571 * can enter "location" mode, and use the direction keys to move one
1572 * grid at a time in any direction. The "t" (set target) command will
1573 * only target a monster (as opposed to a location) if the monster is
1574 * target_able and the "interesting" mode is being used.
1576 * The current grid is described using the "look" method above, and
1577 * a new command may be entered at any time, but note that if the
1578 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1579 * where "space" has no obvious meaning) then "space" will scan
1580 * through the description of the current grid until done, instead
1581 * of immediately jumping to the next "interesting" grid. This
1582 * allows the "target" command to retain its old semantics.
1584 * The "*", "+", and "-" keys may always be used to jump immediately
1585 * to the next (or previous) interesting grid, in the proper mode.
1587 * The "return" key may always be used to scan through a complete
1588 * grid description (forever).
1590 * This command will cancel any old target, even if used from
1591 * inside the "look" command.
1593 bool target_set(BIT_FLAGS mode)
1596 POSITION y = p_ptr->y;
1597 POSITION x = p_ptr->x;
1607 get_screen_size(&wid, &hgt);
1612 if (rogue_like_commands)
1621 /* Prepare the "temp" array */
1622 target_set_prepare(mode);
1624 /* Start near the player */
1630 /* Interesting grids */
1637 change_panel_xy(y, x);
1639 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1642 c_ptr = &cave[y][x];
1645 if (target_able(c_ptr->m_idx))
1647 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1650 /* Dis-allow target */
1653 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1659 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1660 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1661 strcat(info, cheatinfo);
1664 /* Describe and Prompt */
1666 query = target_set_aux(y, x, mode, info);
1670 /* Assume no "direction" */
1675 if (query == '\r') query = 't';
1693 if (target_able(c_ptr->m_idx))
1695 health_track(c_ptr->m_idx);
1696 target_who = c_ptr->m_idx;
1715 if (!expand_list) done = TRUE;
1725 if (!expand_list) done = TRUE;
1732 /* Recenter the map around the player */
1734 p_ptr->update |= (PU_MONSTERS);
1735 p_ptr->redraw |= (PR_MAP);
1736 p_ptr->window |= (PW_OVERHEAD);
1739 /* Recalculate interesting grids */
1740 target_set_prepare(mode);
1759 if(query == same_key)
1764 if (!expand_list) done = TRUE;
1769 /* Extract the action (if any) */
1770 d = get_keymap_dir(query);
1777 /* Hack -- move around */
1780 /* Modified to scroll to monster */
1781 POSITION y2 = panel_row_min;
1782 POSITION x2 = panel_col_min;
1784 /* Find a new monster */
1785 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
1787 /* Request to target past last interesting grid */
1788 while (flag && (i < 0))
1790 /* Note the change */
1791 if (change_panel(ddy[d], ddx[d]))
1796 /* Recalculate interesting grids */
1797 target_set_prepare(mode);
1799 /* Look at interesting grids */
1802 /* Find a new monster */
1803 i = target_pick(v, u, ddy[d], ddx[d]);
1809 /* Nothing interesting */
1812 POSITION dx = ddx[d];
1813 POSITION dy = ddy[d];
1815 /* Restore previous position */
1818 panel_bounds_center();
1820 p_ptr->update |= (PU_MONSTERS);
1821 p_ptr->redraw |= (PR_MAP);
1822 p_ptr->window |= (PW_OVERHEAD);
1825 /* Recalculate interesting grids */
1826 target_set_prepare(mode);
1828 /* Look at boring grids */
1835 /* Do not move horizontally if unnecessary */
1836 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1837 ((x > panel_col_min + wid / 2) && (dx < 0)))
1842 /* Do not move vertically if unnecessary */
1843 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1844 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1849 /* Apply the motion */
1850 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1851 (x >= panel_col_min+wid) || (x < panel_col_min))
1853 if (change_panel(dy, dx)) target_set_prepare(mode);
1856 /* Slide into legality */
1857 if (x >= cur_wid-1) x = cur_wid - 2;
1858 else if (x <= 0) x = 1;
1860 /* Slide into legality */
1861 if (y >= cur_hgt-1) y = cur_hgt- 2;
1862 else if (y <= 0) y = 1;
1871 /* Arbitrary grids */
1874 bool move_fast = FALSE;
1876 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1879 c_ptr = &cave[y][x];
1881 /* Default prompt */
1882 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1887 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1888 los(p_ptr->y, p_ptr->x, y, x),
1889 projectable(p_ptr->y, p_ptr->x, y, x));
1890 strcat(info, cheatinfo);
1893 /* Describe and Prompt (enable "TARGET_LOOK") */
1894 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1896 /* Assume no direction */
1901 if (query == '\r') query = 't';
1904 /* Analyze the keypress */
1928 /* Recenter the map around the player */
1930 p_ptr->update |= (PU_MONSTERS);
1931 p_ptr->redraw |= (PR_MAP);
1932 p_ptr->window |= (PW_OVERHEAD);
1935 /* Recalculate interesting grids */
1936 target_set_prepare(mode);
1958 /* Pick a nearby monster */
1959 for (i = 0; i < temp_n; i++)
1961 t = distance(y, x, temp_y[i], temp_x[i]);
1971 /* Nothing interesting */
1972 if (bd == 999) flag = FALSE;
1979 /* Extract the action (if any) */
1980 d = get_keymap_dir(query);
1982 /* XTRA HACK MOVEFAST */
1983 if (isupper(query)) move_fast = TRUE;
1990 /* Handle "direction" */
1993 POSITION dx = ddx[d];
1994 POSITION dy = ddy[d];
1996 /* XTRA HACK MOVEFAST */
1999 int mag = MIN(wid / 2, hgt / 2);
2009 /* Do not move horizontally if unnecessary */
2010 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2011 ((x > panel_col_min + wid / 2) && (dx < 0)))
2016 /* Do not move vertically if unnecessary */
2017 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2018 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2023 /* Apply the motion */
2024 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2025 (x >= panel_col_min + wid) || (x < panel_col_min))
2027 if (change_panel(dy, dx)) target_set_prepare(mode);
2030 /* Slide into legality */
2031 if (x >= cur_wid-1) x = cur_wid - 2;
2032 else if (x <= 0) x = 1;
2034 /* Slide into legality */
2035 if (y >= cur_hgt-1) y = cur_hgt- 2;
2036 else if (y <= 0) y = 1;
2044 /* Clear the top line */
2047 /* Recenter the map around the player */
2049 p_ptr->update |= (PU_MONSTERS);
2050 p_ptr->redraw |= (PR_MAP);
2051 p_ptr->window |= (PW_OVERHEAD);
2054 /* Failure to set target */
2055 if (!target_who) return (FALSE);
2063 * Get an "aiming direction" from the user.
2065 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
2066 * "0" for "current target", and "-1" for "entry aborted".
2068 * Note that "Force Target", if set, will pre-empt user interaction,
2069 * if there is a usable target already set.
2071 * Note that confusion over-rides any (explicit?) user choice.
2073 bool get_aim_dir(DIRECTION *dp)
2082 /* Global direction */
2085 /* Hack -- auto-target if requested */
2086 if (use_old_target && target_okay()) dir = 5;
2088 if (repeat_pull(&code))
2093 if (!(code == 5 && !target_okay()))
2095 /* return (TRUE); */
2096 dir = (DIRECTION)code;
2099 *dp = (DIRECTION)code;
2101 /* Ask until satisfied */
2104 /* Choose a prompt */
2107 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2111 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2114 /* Get a command (or Cancel) */
2115 if (!get_com(p, &command, TRUE)) break;
2119 if (command == '\r') command = 't';
2122 /* Convert various keys to "standard" keys */
2125 /* Use current target */
2136 /* Set new target */
2141 if (target_set(TARGET_KILL)) dir = 5;
2147 /* Extract the action (if any) */
2148 dir = get_keymap_dir(command);
2154 /* Verify requested targets */
2155 if ((dir == 5) && !target_okay()) dir = 0;
2164 project_length = 0; /* reset to default */
2168 /* Save the direction */
2171 /* Check for confusion */
2172 if (p_ptr->confused)
2174 /* Random direction */
2175 dir = ddd[randint0(8)];
2178 /* Notice confusion */
2179 if (command_dir != dir)
2182 msg_print(_("あなたは混乱している。", "You are confused."));
2185 /* Save direction */
2188 /* repeat_push(dir); */
2189 repeat_push((COMMAND_CODE)command_dir);
2191 /* A "valid" direction was entered */
2196 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
2204 /* Global direction */
2207 if (repeat_pull(&code))
2209 dir = (DIRECTION)code;
2210 /* return (TRUE); */
2212 *dp = (DIRECTION)code;
2216 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2220 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2223 /* Get a direction */
2228 /* Get a command (or Cancel) */
2229 if (!get_com(prompt, &ch, TRUE)) break;
2232 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2238 /* Look up the direction */
2239 dir = get_keymap_dir(ch);
2245 /* Prevent weirdness */
2246 if ((dir == 5) && (!allow_under)) dir = 0;
2249 if (!dir) return (FALSE);
2251 /* Save desired direction */
2254 /* Apply "confusion" */
2255 if (p_ptr->confused)
2257 /* Standard confusion */
2258 if (randint0(100) < 75)
2260 /* Random direction */
2261 dir = ddd[randint0(8)];
2264 else if (p_ptr->riding && with_steed)
2266 monster_type *m_ptr = &m_list[p_ptr->riding];
2267 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2269 if (MON_CONFUSED(m_ptr))
2271 /* Standard confusion */
2272 if (randint0(100) < 75)
2274 /* Random direction */
2275 dir = ddd[randint0(8)];
2278 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2280 /* Random direction */
2281 dir = ddd[randint0(8)];
2283 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2285 /* Random direction */
2286 dir = ddd[randint0(8)];
2290 /* Notice confusion */
2291 if (command_dir != dir)
2293 if (p_ptr->confused)
2296 msg_print(_("あなたは混乱している。", "You are confused."));
2300 GAME_TEXT m_name[MAX_NLEN];
2301 monster_type *m_ptr = &m_list[p_ptr->riding];
2303 monster_desc(m_name, m_ptr, 0);
2304 if (MON_CONFUSED(m_ptr))
2306 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2310 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2315 /* Save direction */
2318 /* repeat_push(dir); */
2319 repeat_push((COMMAND_CODE)command_dir);
2326 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
2327 * and place it into "command_dir", unless we already have one.
2329 * This function should be used for all "repeatable" commands, such as
2330 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
2331 * as all commands which must reference a grid adjacent to the player,
2332 * and which may not reference the grid under the player. Note that,
2333 * for example, it is no longer possible to "disarm" or "open" chests
2334 * in the same grid as the player.
2336 * Direction "5" is illegal and will (cleanly) abort the command.
2338 * This function tracks and uses the "global direction", and uses
2339 * that as the "desired direction", to which "confusion" is applied.
2341 bool get_rep_dir(DIRECTION *dp, bool under)
2349 /* Global direction */
2352 if (repeat_pull(&code))
2354 dir = (DIRECTION)code;
2355 /* return (TRUE); */
2357 *dp = (DIRECTION)code;
2361 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2365 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2368 /* Get a direction */
2373 /* Get a command (or Cancel) */
2374 if (!get_com(prompt, &ch, TRUE)) break;
2377 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2383 /* Look up the direction */
2384 dir = get_keymap_dir(ch);
2390 /* Prevent weirdness */
2391 if ((dir == 5) && (!under)) dir = 0;
2394 if (!dir) return (FALSE);
2396 /* Save desired direction */
2399 /* Apply "confusion" */
2400 if (p_ptr->confused)
2402 /* Standard confusion */
2403 if (randint0(100) < 75)
2405 /* Random direction */
2406 dir = ddd[randint0(8)];
2409 else if (p_ptr->riding)
2411 monster_type *m_ptr = &m_list[p_ptr->riding];
2412 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2414 if (MON_CONFUSED(m_ptr))
2416 /* Standard confusion */
2417 if (randint0(100) < 75)
2419 /* Random direction */
2420 dir = ddd[randint0(8)];
2423 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2425 /* Random direction */
2426 dir = ddd[randint0(8)];
2428 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2430 /* Random direction */
2431 dir = ddd[randint0(8)];
2435 /* Notice confusion */
2436 if (command_dir != dir)
2438 if (p_ptr->confused)
2441 msg_print(_("あなたは混乱している。", "You are confused."));
2445 GAME_TEXT m_name[MAX_NLEN];
2446 monster_type *m_ptr = &m_list[p_ptr->riding];
2448 monster_desc(m_name, m_ptr, 0);
2449 if (MON_CONFUSED(m_ptr))
2451 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2455 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2460 /* Save direction */
2463 /* repeat_push(dir); */
2464 repeat_push((COMMAND_CODE)command_dir);
2472 * XAngband: determine if a given location is "interesting"
2473 * based on target_set_accept function.
2475 static bool tgt_pt_accept(POSITION y, POSITION x)
2480 if (!(in_bounds(y, x))) return (FALSE);
2482 /* Player grid is always interesting */
2483 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
2485 /* Handle hallucination */
2486 if (p_ptr->image) return (FALSE);
2488 /* Examine the grid */
2489 c_ptr = &cave[y][x];
2491 /* Interesting memorized features */
2492 if (c_ptr->info & (CAVE_MARK))
2495 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
2496 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
2498 /* Notice quest features */
2499 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
2500 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
2508 * XAngband: Prepare the "temp" array for "tget_pt"
2509 * based on target_set_prepare funciton.
2511 static void tgt_pt_prepare(void)
2515 /* Reset "temp" array */
2518 if (!expand_list) return;
2520 /* Scan the current panel */
2521 for (y = 1; y < cur_hgt; y++)
2523 for (x = 1; x < cur_wid; x++)
2525 /* Require "interesting" contents */
2526 if (!tgt_pt_accept(y, x)) continue;
2528 /* Save the location */
2535 /* Target the nearest monster for shooting */
2536 ang_sort_comp = ang_sort_comp_distance;
2537 ang_sort_swap = ang_sort_swap_distance;
2539 /* Sort the positions */
2540 ang_sort(temp_x, temp_y, temp_n);
2544 * old -- from PsiAngband.
2546 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
2551 bool success = FALSE;
2555 get_screen_size(&wid, &hgt);
2565 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2566 msg_flag = FALSE; /* prevents "-more-" message. */
2568 while ((ch != ESCAPE) && !success)
2570 bool move_fast = FALSE;
2572 move_cursor_relative(y, x);
2584 if (player_bold(y, x)) ch = 0;
2587 else success = TRUE;
2591 /* XAngband: Move cursor to stairs */
2594 if (expand_list && temp_n)
2597 int cx = (panel_col_min + panel_col_max) / 2;
2598 int cy = (panel_row_min + panel_row_max) / 2;
2602 /* Skip stairs which have defferent distance */
2603 for (; n < temp_n; ++ n)
2605 cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
2607 if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
2608 cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
2615 if (n == temp_n) /* Loop out taget list */
2620 verify_panel(); /* Move cursor to player */
2622 p_ptr->update |= (PU_MONSTERS);
2624 p_ptr->redraw |= (PR_MAP);
2626 p_ptr->window |= (PW_OVERHEAD);
2629 else /* move cursor to next stair and change panel */
2634 dy = 2 * (y - cy) / hgt;
2635 dx = 2 * (x - cx) / wid;
2636 if (dy || dx) change_panel(dy, dx);
2642 /* Look up the direction */
2643 d = get_keymap_dir(ch);
2645 /* XTRA HACK MOVEFAST */
2646 if (isupper(ch)) move_fast = TRUE;
2648 /* Handle "direction" */
2654 /* XTRA HACK MOVEFAST */
2657 int mag = MIN(wid / 2, hgt / 2);
2667 /* Do not move horizontally if unnecessary */
2668 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2669 ((x > panel_col_min + wid / 2) && (dx < 0)))
2674 /* Do not move vertically if unnecessary */
2675 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2676 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2681 /* Apply the motion */
2682 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2683 (x >= panel_col_min + wid) || (x < panel_col_min))
2685 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2686 change_panel(dy, dx);
2689 /* Slide into legality */
2690 if (x >= cur_wid-1) x = cur_wid - 2;
2691 else if (x <= 0) x = 1;
2693 /* Slide into legality */
2694 if (y >= cur_hgt-1) y = cur_hgt- 2;
2695 else if (y <= 0) y = 1;
2702 /* Clear the top line */
2705 /* Recenter the map around the player */
2708 p_ptr->update |= (PU_MONSTERS);
2710 p_ptr->redraw |= (PR_MAP);
2712 p_ptr->window |= (PW_OVERHEAD);
2721 bool get_hack_dir(DIRECTION *dp)
2729 /* Global direction */
2732 /* (No auto-targeting) */
2734 /* Ask until satisfied */
2737 /* Choose a prompt */
2740 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2744 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2747 /* Get a command (or Cancel) */
2748 if (!get_com(p, &command, TRUE)) break;
2752 if (command == '\r') command = 't';
2755 /* Convert various keys to "standard" keys */
2758 /* Use current target */
2769 /* Set new target */
2774 if (target_set(TARGET_KILL)) dir = 5;
2780 /* Look up the direction */
2781 dir = get_keymap_dir(command);
2787 /* Verify requested targets */
2788 if ((dir == 5) && !target_okay()) dir = 0;
2795 if (!dir) return (FALSE);
2797 /* Save the direction */
2800 /* Check for confusion */
2801 if (p_ptr->confused)
2803 /* Random direction */
2804 dir = ddd[randint0(8)];
2807 /* Notice confusion */
2808 if (command_dir != dir)
2811 msg_print(_("あなたは混乱している。", "You are confused."));
2814 /* Save direction */
2817 /* A "valid" direction was entered */
2823 * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
2824 * @param sval 射撃武器のアイテム副分類ID
2825 * @return 消費する基本エネルギー
2827 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
2829 ENERGY energy = 10000;
2831 /* Analyze the launcher */
2834 /* Sling and ammo */
2841 /* Short Bow and Arrow */
2848 /* Long Bow and Arrow */
2855 /* Bow of irresponsiblity and Arrow */
2862 /* Light Crossbow and Bolt */
2869 /* Heavy Crossbow and Bolt */
2884 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
2888 /* Analyze the launcher */
2891 /* Sling and ammo */
2898 /* Short Bow and Arrow */
2905 /* Long Bow and Arrow */
2912 /* Bow of irresponsiblity and Arrow */
2919 /* Light Crossbow and Bolt */
2926 /* Heavy Crossbow and Bolt */
2939 * Display a rumor and apply its effects
2942 IDX rumor_num(char *zz, IDX max_idx)
2944 if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
2945 return (IDX)atoi(zz);
2948 concptr rumor_bind_name(char *base, concptr fullname)
2952 s = strstr(base, "{Name}");
2956 v = format("%s%s%s", base, fullname, (s + 6));
2966 void display_rumor(bool ex)
2974 if (randint0(3) == 0) section = 1;
2977 err = _(get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10),
2978 get_rnd_line("rumors.txt", section, Rumor));
2979 if (err) strcpy(Rumor, _("嘘の噂もある。", "Some rumors are wrong."));
2983 if (strncmp(Rumor, "R:", 2) == 0)
2986 concptr rumor_msg = NULL;
2987 concptr rumor_eff_format = NULL;
2988 char fullname[1024] = "";
2990 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
2992 if (strcmp(zz[0], "ARTIFACT") == 0)
2996 object_type *q_ptr = &forge;
2997 artifact_type *a_ptr;
3001 a_idx = rumor_num(zz[1], max_a_idx);
3003 a_ptr = &a_info[a_idx];
3004 if (a_ptr->name) break;
3007 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
3008 object_prep(q_ptr, k_idx);
3009 q_ptr->name1 = a_idx;
3010 q_ptr->ident = IDENT_STORE;
3011 object_desc(fullname, q_ptr, OD_NAME_ONLY);
3013 else if (strcmp(zz[0], "MONSTER") == 0)
3016 monster_race *r_ptr;
3020 r_idx = rumor_num(zz[1], max_r_idx);
3021 r_ptr = &r_info[r_idx];
3022 if (r_ptr->name) break;
3025 strcpy(fullname, r_name + r_ptr->name);
3027 /* Remember this monster */
3028 if (!r_ptr->r_sights)
3033 else if (strcmp(zz[0], "DUNGEON") == 0)
3036 dungeon_info_type *d_ptr;
3040 d_idx = rumor_num(zz[1], max_d_idx);
3041 d_ptr = &d_info[d_idx];
3042 if (d_ptr->name) break;
3045 strcpy(fullname, d_name + d_ptr->name);
3047 if (!max_dlv[d_idx])
3049 max_dlv[d_idx] = d_ptr->mindepth;
3050 rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
3053 else if (strcmp(zz[0], "TOWN") == 0)
3060 t_idx = rumor_num(zz[1], NO_TOWN);
3061 if (town[t_idx].name) break;
3064 strcpy(fullname, town[t_idx].name);
3066 visit = (1L << (t_idx - 1));
3067 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
3069 p_ptr->visit |= visit;
3070 rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
3074 rumor_msg = rumor_bind_name(zz[2], fullname);
3075 msg_print(rumor_msg);
3076 if (rumor_eff_format)
3079 msg_format(rumor_eff_format, fullname);
3084 if (err) msg_print(_("この情報は間違っている。", "This information is wrong."));
3088 msg_format("%s", Rumor);