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"
26 #include "player-move.h"
27 #include "monster-status.h"
29 #define REWARD_CHANCE 10
33 * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
34 * Advance experience levels and print experience
37 void check_experience(void)
39 bool level_reward = FALSE;
40 bool level_mutation = FALSE;
41 bool level_inc_stat = FALSE;
42 bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
43 PLAYER_LEVEL old_lev = p_ptr->lev;
45 /* Hack -- lower limit */
46 if (p_ptr->exp < 0) p_ptr->exp = 0;
47 if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
48 if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
50 /* Hack -- upper limit */
51 if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
52 if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
53 if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
55 /* Hack -- maintain "max" experience */
56 if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
58 /* Hack -- maintain "max max" experience */
59 if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
61 /* Redraw experience */
62 p_ptr->redraw |= (PR_EXP);
66 /* Lose levels while possible */
67 while ((p_ptr->lev > 1) &&
68 (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
72 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
73 p_ptr->redraw |= (PR_LEV | PR_TITLE);
74 p_ptr->window |= (PW_PLAYER);
79 /* Gain levels while possible */
80 while ((p_ptr->lev < PY_MAX_LEVEL) &&
81 (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
86 /* Save the highest level */
87 if (p_ptr->lev > p_ptr->max_plv)
89 p_ptr->max_plv = p_ptr->lev;
91 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
92 (p_ptr->muta2 & MUT2_CHAOS_GIFT))
96 if (p_ptr->prace == RACE_BEASTMAN)
98 if (one_in_(5)) level_mutation = TRUE;
100 level_inc_stat = TRUE;
102 do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
107 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
109 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
110 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
111 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
121 if(!(p_ptr->max_plv % 10))
130 cnv_stat(p_ptr->stat_max[0], tmp);
131 prt(format(_(" a) 腕力 (現在値 %s)", " a) Str (cur %s)"), tmp), 2, 14);
132 cnv_stat(p_ptr->stat_max[1], tmp);
133 prt(format(_(" b) 知能 (現在値 %s)", " a) Int (cur %s)"), tmp), 3, 14);
134 cnv_stat(p_ptr->stat_max[2], tmp);
135 prt(format(_(" c) 賢さ (現在値 %s)", " a) Wis (cur %s)"), tmp), 4, 14);
136 cnv_stat(p_ptr->stat_max[3], tmp);
137 prt(format(_(" d) 器用 (現在値 %s)", " a) Dex (cur %s)"), tmp), 5, 14);
138 cnv_stat(p_ptr->stat_max[4], tmp);
139 prt(format(_(" e) 耐久 (現在値 %s)", " a) Con (cur %s)"), tmp), 6, 14);
140 cnv_stat(p_ptr->stat_max[5], tmp);
141 prt(format(_(" f) 魅力 (現在値 %s)", " a) Chr (cur %s)"), tmp), 7, 14);
144 prt(_(" どの能力値を上げますか?", " Which stat do you want to raise?"), 1, 14);
149 if ((choice >= 'a') && (choice <= 'f')) break;
151 for(n = 0; n < A_MAX; n++)
152 if (n != choice - 'a')
154 if (get_check(_("よろしいですか?", "Are you sure? "))) break;
156 do_inc_stat(choice - 'a');
159 else if(!(p_ptr->max_plv % 2))
160 do_inc_stat(randint0(6));
165 msg_print(_("あなたは変わった気がする...", "You feel different..."));
166 (void)gain_mutation(p_ptr, 0);
167 level_mutation = FALSE;
171 * 報酬でレベルが上ると再帰的に check_experience() が
176 gain_level_reward(0);
177 level_reward = FALSE;
180 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
181 p_ptr->redraw |= (PR_LEV | PR_TITLE);
182 p_ptr->window |= (PW_PLAYER | PW_SPELL);
186 /* Load an autopick preference file */
187 if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
193 * @brief モンスターを撃破した際の述語メッセージを返す /
194 * Return monster death string
195 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
196 * @return 撃破されたモンスターの述語
198 concptr extract_note_dies(MONRACE_IDX r_idx)
200 monster_race *r_ptr = &r_info[r_idx];
201 /* Some monsters get "destroyed" */
202 if (!monster_living(r_idx))
206 for (i = 0; i < 4; i++)
208 if (r_ptr->blow[i].method == RBM_EXPLODE)
210 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
213 return _("を倒した。", " is destroyed.");
216 return _("は死んだ。", " dies.");
222 * @brief 現在のコンソール表示の縦横を返す。 /
223 * Get term size and calculate screen size
224 * @param wid_p コンソールの表示幅文字数を返す
225 * @param hgt_p コンソールの表示行数を返す
228 void get_screen_size(TERM_LEN *wid_p, TERM_LEN *hgt_p)
230 Term_get_size(wid_p, hgt_p);
231 *hgt_p -= ROW_MAP + 2;
232 *wid_p -= COL_MAP + 2;
233 if (use_bigtile) *wid_p /= 2;
238 * @brief コンソール上におけるマップ表示の左上位置を返す /
239 * Calculates current boundaries Called below and from "do_cmd_locate()".
242 void panel_bounds_center(void)
246 get_screen_size(&wid, &hgt);
248 panel_row_max = panel_row_min + hgt - 1;
249 panel_row_prt = panel_row_min - 1;
250 panel_col_max = panel_col_min + wid - 1;
251 panel_col_prt = panel_col_min - 13;
255 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
256 * @param y 変更先のフロアY座標
257 * @param x 変更先のフロアX座標
259 * Handle a request to change the current panel
260 * Return TRUE if the panel was changed.
261 * Also used in do_cmd_locate
262 * @return 実際に再描画が必要だった場合TRUEを返す
264 static bool change_panel_xy(POSITION y, POSITION x)
266 POSITION dy = 0, dx = 0;
269 get_screen_size(&wid, &hgt);
271 if (y < panel_row_min) dy = -1;
272 if (y > panel_row_max) dy = 1;
273 if (x < panel_col_min) dx = -1;
274 if (x > panel_col_max) dx = 1;
276 if (!dy && !dx) return (FALSE);
278 return change_panel(dy, dx);
283 * @brief マップ描画のフォーカスを当てるべき座標を更新する
285 * Given an row (y) and col (x), this routine detects when a move
286 * off the screen has occurred and figures new borders. -RAK-
287 * "Update" forces a "full update" to take place.
288 * The map is reprinted if necessary, and "TRUE" is returned.
289 * @return 実際に再描画が必要だった場合TRUEを返す
291 void verify_panel(void)
293 POSITION y = p_ptr->y;
294 POSITION x = p_ptr->x;
302 get_screen_size(&wid, &hgt);
304 max_prow_min = current_floor_ptr->height - hgt;
305 max_pcol_min = current_floor_ptr->width - wid;
307 /* Bounds checking */
308 if (max_prow_min < 0) max_prow_min = 0;
309 if (max_pcol_min < 0) max_pcol_min = 0;
311 /* Center on player */
312 if (center_player && (center_running || !running))
314 /* Center vertically */
315 prow_min = y - hgt / 2;
316 if (prow_min < 0) prow_min = 0;
317 else if (prow_min > max_prow_min) prow_min = max_prow_min;
319 /* Center horizontally */
320 pcol_min = x - wid / 2;
321 if (pcol_min < 0) pcol_min = 0;
322 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
326 prow_min = panel_row_min;
327 pcol_min = panel_col_min;
329 /* Scroll screen when 2 grids from top/bottom edge */
330 if (y > panel_row_max - 2)
332 while (y > prow_min + hgt-1 - 2)
334 prow_min += (hgt / 2);
338 if (y < panel_row_min + 2)
340 while (y < prow_min + 2)
342 prow_min -= (hgt / 2);
346 if (prow_min > max_prow_min) prow_min = max_prow_min;
347 if (prow_min < 0) prow_min = 0;
349 /* Scroll screen when 4 grids from left/right edge */
350 if (x > panel_col_max - 4)
352 while (x > pcol_min + wid-1 - 4)
354 pcol_min += (wid / 2);
358 if (x < panel_col_min + 4)
360 while (x < pcol_min + 4)
362 pcol_min -= (wid / 2);
366 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
367 if (pcol_min < 0) pcol_min = 0;
370 /* Check for "no change" */
371 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
373 /* Save the new panel info */
374 panel_row_min = prow_min;
375 panel_col_min = pcol_min;
377 /* Hack -- optional disturb on "panel change" */
378 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
380 /* Recalculate the boundaries */
381 panel_bounds_center();
383 p_ptr->update |= (PU_MONSTERS);
384 p_ptr->redraw |= (PR_MAP);
385 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
390 * Monster health description
392 concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
394 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
401 /* Determine if the monster is "living" */
402 living = monster_living(m_ptr->ap_r_idx);
404 /* Calculate a health "percentage" */
405 perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
407 /* Healthy monsters */
408 if (m_ptr->hp >= m_ptr->maxhp)
410 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
415 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
420 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
425 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
430 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
433 /* Need attitude information? */
436 /* Full information is not needed */
439 else if (is_pet(m_ptr))
441 attitude = _(", ペット", ", pet");
443 else if (is_friendly(m_ptr))
445 attitude = _(", 友好的", ", friendly");
449 attitude = _("", "");
453 if (m_ptr->smart & SM_CLONED)
462 /* Display monster's level --- idea borrowed from ToME */
463 if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
465 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
469 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
476 /*** Targeting Code ***/
480 * Determine is a monster makes a reasonable target
482 * The concept of "targeting" was stolen from "Morgul" (?)
484 * The player can target any location, or any "target-able" monster.
486 * Currently, a monster is "target_able" if it is visible, and if
487 * the player can hit it with a projection, and the player is not
488 * hallucinating. This allows use of "use closest target" macros.
490 * Future versions may restrict the ability to target "trappers"
491 * and "mimics", but the semantics is a little bit weird.
493 bool target_able(MONSTER_IDX m_idx)
495 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
497 /* Monster must be alive */
498 if (!monster_is_valid(m_ptr)) return (FALSE);
500 /* Hack -- no targeting hallucinations */
501 if (p_ptr->image) return (FALSE);
503 /* Monster must be visible */
504 if (!m_ptr->ml) return (FALSE);
506 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
508 /* Monster must be projectable */
509 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
511 /* Hack -- Never target trappers */
512 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
522 * Update (if necessary) and verify (if possible) the target.
524 * We return TRUE if the target is "okay" and FALSE otherwise.
526 bool target_okay(void)
528 /* Accept stationary targets */
529 if (target_who < 0) return (TRUE);
531 /* Check moving targets */
534 /* Accept reasonable targets */
535 if (target_able(target_who))
537 monster_type *m_ptr = ¤t_floor_ptr->m_list[target_who];
539 /* Acquire monster location */
540 target_row = m_ptr->fy;
541 target_col = m_ptr->fx;
548 /* Assume no target */
554 * Sorting hook -- comp function -- by "distance to player"
556 * We use "u" and "v" to point to arrays of "x" and "y" positions,
557 * and sort the arrays by double-distance to the player.
559 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
561 POSITION *x = (POSITION*)(u);
562 POSITION *y = (POSITION*)(v);
564 POSITION da, db, kx, ky;
566 /* Absolute distance components */
567 kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
568 ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
570 /* Approximate Double Distance to the first point */
571 da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
573 /* Absolute distance components */
574 kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
575 ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
577 /* Approximate Double Distance to the first point */
578 db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
580 /* Compare the distances */
586 * Sorting hook -- comp function -- by importance level of grids
588 * We use "u" and "v" to point to arrays of "x" and "y" positions,
589 * and sort the arrays by level of monster
591 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
593 POSITION *x = (POSITION*)(u);
594 POSITION *y = (POSITION*)(v);
595 grid_type *ca_ptr = ¤t_floor_ptr->grid_array[y[a]][x[a]];
596 grid_type *cb_ptr = ¤t_floor_ptr->grid_array[y[b]][x[b]];
597 monster_type *ma_ptr = ¤t_floor_ptr->m_list[ca_ptr->m_idx];
598 monster_type *mb_ptr = ¤t_floor_ptr->m_list[cb_ptr->m_idx];
599 monster_race *ap_ra_ptr, *ap_rb_ptr;
601 /* The player grid */
602 if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
603 if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
605 /* Extract monster race */
606 if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
607 else ap_ra_ptr = NULL;
608 if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
609 else ap_rb_ptr = NULL;
611 if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
612 if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
614 /* Compare two monsters */
615 if (ap_ra_ptr && ap_rb_ptr)
617 /* Unique monsters first */
618 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
619 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
621 /* Shadowers first (あやしい影) */
622 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
623 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
625 /* Unknown monsters first */
626 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
627 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
629 /* Higher level monsters first (if known) */
630 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
632 if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
633 if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
636 /* Sort by index if all conditions are same */
637 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
638 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
641 /* An object get higher priority */
642 if (current_floor_ptr->grid_array[y[a]][x[a]].o_idx && !current_floor_ptr->grid_array[y[b]][x[b]].o_idx) return TRUE;
643 if (!current_floor_ptr->grid_array[y[a]][x[a]].o_idx && current_floor_ptr->grid_array[y[b]][x[b]].o_idx) return FALSE;
645 /* Priority from the terrain */
646 if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
647 if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
649 /* If all conditions are same, compare distance */
650 return ang_sort_comp_distance(u, v, a, b);
655 * Sorting hook -- swap function -- by "distance to player"
657 * We use "u" and "v" to point to arrays of "x" and "y" positions,
658 * and sort the arrays by distance to the player.
660 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
662 POSITION *x = (POSITION*)(u);
663 POSITION *y = (POSITION*)(v);
681 * Hack -- help "select" a location (see below)
683 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
686 POSITION x2, y2, x3, y3, x4, y4;
687 POSITION_IDX b_i = -1, b_v = 9999;
690 /* Scan the locations */
691 for (i = 0; i < tmp_pos.n; i++)
697 /* Directed distance */
701 /* Verify quadrant */
702 if (dx && (x3 * dx <= 0)) continue;
703 if (dy && (y3 * dy <= 0)) continue;
705 /* Absolute distance */
709 /* Verify quadrant */
710 if (dy && !dx && (x4 > y4)) continue;
711 if (dx && !dy && (y4 > x4)) continue;
713 /* Approximate Double Distance */
714 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
716 /* Penalize location */
719 if ((b_i >= 0) && (v >= b_v)) continue;
729 * Hack -- determine if a given location is "interesting"
731 static bool target_set_accept(POSITION y, POSITION x)
734 OBJECT_IDX this_o_idx, next_o_idx = 0;
737 if (!(in_bounds(y, x))) return (FALSE);
739 /* Player grid is always interesting */
740 if (player_bold(y, x)) return (TRUE);
742 /* Handle hallucination */
743 if (p_ptr->image) return (FALSE);
745 /* Examine the grid */
746 g_ptr = ¤t_floor_ptr->grid_array[y][x];
748 /* Visible monsters */
751 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
753 /* Visible monsters */
754 if (m_ptr->ml) return (TRUE);
757 /* Scan all objects in the grid */
758 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
761 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
762 next_o_idx = o_ptr->next_o_idx;
764 /* Memorized object */
765 if (o_ptr->marked & OM_FOUND) return (TRUE);
768 /* Interesting memorized features */
769 if (g_ptr->info & (CAVE_MARK))
771 /* Notice object features */
772 if (g_ptr->info & CAVE_OBJECT) return (TRUE);
774 /* Feature code (applying "mimic" field) */
775 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE)) return TRUE;
783 * Prepare the "temp" array for "target_set"
785 * Return the number of target_able monsters in the set.
787 static void target_set_prepare(BIT_FLAGS mode)
790 POSITION min_hgt, max_hgt, min_wid, max_wid;
792 if (mode & TARGET_KILL)
795 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
796 max_hgt = MIN((p_ptr->y + MAX_RANGE), current_floor_ptr->height - 1);
797 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
798 max_wid = MIN((p_ptr->x + MAX_RANGE), current_floor_ptr->width - 1);
800 else /* not targetting */
803 min_hgt = panel_row_min;
804 max_hgt = panel_row_max;
805 min_wid = panel_col_min;
806 max_wid = panel_col_max;
809 /* Reset "temp" array */
812 /* Scan the current panel */
813 for (y = min_hgt; y <= max_hgt; y++)
815 for (x = min_wid; x <= max_wid; x++)
819 /* Require "interesting" contents */
820 if (!target_set_accept(y, x)) continue;
822 g_ptr = ¤t_floor_ptr->grid_array[y][x];
824 /* Require target_able monsters for "TARGET_KILL" */
825 if ((mode & (TARGET_KILL)) && !target_able(g_ptr->m_idx)) continue;
827 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(¤t_floor_ptr->m_list[g_ptr->m_idx])) continue;
829 /* Save the location */
830 tmp_pos.x[tmp_pos.n] = x;
831 tmp_pos.y[tmp_pos.n] = y;
836 /* Set the sort hooks */
837 if (mode & (TARGET_KILL))
839 /* Target the nearest monster for shooting */
840 ang_sort_comp = ang_sort_comp_distance;
841 ang_sort_swap = ang_sort_swap_distance;
845 /* Look important grids first in Look command */
846 ang_sort_comp = ang_sort_comp_importance;
847 ang_sort_swap = ang_sort_swap_distance;
850 /* Sort the positions */
851 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n);
853 if (p_ptr->riding && target_pet && (tmp_pos.n > 1) && (mode & (TARGET_KILL)))
858 tmp_pos.y[0] = tmp_pos.y[1];
861 tmp_pos.x[0] = tmp_pos.x[1];
866 void target_set_prepare_look(void){
867 target_set_prepare(TARGET_LOOK);
872 * Evaluate number of kill needed to gain level
874 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
876 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
878 s32b exp_mon, exp_adv;
879 u32b exp_mon_frac, exp_adv_frac;
881 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
886 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
896 /* The monster's experience point (assuming average monster speed) */
897 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
899 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
902 /* Total experience value for next level */
903 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
905 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
907 /* Experience value need to get */
908 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
911 /* You need to kill at least one monster to get any experience */
912 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
913 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
915 /* Extract number of monsters needed */
916 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
918 /* If 999 or more monsters needed, only display "999". */
919 num = MIN(999, exp_adv_frac);
921 /* Display the number */
922 sprintf(buf,"%03ld", (long int)num);
926 bool show_gold_on_floor = FALSE;
929 * Examine a grid, return a keypress.
931 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
932 * indicates that the "space" key should scan through the contents
933 * of the grid, instead of simply returning immediately. This lets
934 * the "look" command get complete information, without making the
935 * "target" command annoying.
937 * The "info" argument contains the "commands" which should be shown
938 * inside the "[xxx]" text. This string must never be empty, or grids
939 * containing monsters will be displayed with an extra comma.
941 * Note that if a monster is in the grid, we update both the monster
942 * recall info and the health bar info to track that monster.
944 * Eventually, we may allow multiple objects per grid, or objects
945 * and terrain features in the same grid.
947 * This function must handle blindness/hallucination.
949 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
951 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
952 OBJECT_IDX this_o_idx, next_o_idx = 0;
953 concptr s1 = "", s2 = "", s3 = "", x_info = "";
958 char out_val[MAX_NLEN+80];
959 OBJECT_IDX floor_list[23];
960 ITEM_NUMBER floor_num = 0;
962 /* Scan all objects in the grid */
965 floor_num = scan_floor(floor_list, y, x, 0x02);
969 x_info = _("x物 ", "x,");
973 /* Hack -- under the player */
974 if (player_bold(y, x))
987 s1 = _("ターゲット:", "Target:");
990 /* Hack -- hallucination */
993 concptr name = _("何か奇妙な物", "something strange");
995 /* Display a message */
997 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
999 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1003 move_cursor_relative(y, x);
1006 /* Stop on everything but "return" */
1007 if ((query != '\r') && (query != '\n')) return query;
1009 /* Repeat forever */
1014 /* Actual monsters */
1015 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
1017 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
1018 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1019 GAME_TEXT m_name[MAX_NLEN];
1020 bool recall = FALSE;
1025 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1026 monster_race_track(m_ptr->ap_r_idx);
1027 health_track(g_ptr->m_idx);
1040 /* Recall on screen */
1041 screen_roff(m_ptr->ap_r_idx, 0);
1043 /* Hack -- Complete the prompt (again) */
1044 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
1051 /* Normal commands */
1052 if (query != 'r') break;
1057 /* Cleare recall text and repeat */
1063 /* Describe, and prompt for recall */
1064 evaluate_monster_exp(acount, m_ptr);
1067 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);
1069 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);
1075 move_cursor_relative(y, x);
1080 /* Normal commands */
1081 if (query != 'r') break;
1087 /* Always stop at "normal" keys */
1088 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1090 /* Sometimes stop at "space" key */
1091 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1093 /* Change the intro */
1094 s1 = _("それは", "It is ");
1096 /* Hack -- take account of gender */
1097 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
1098 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
1100 /* Use a preposition */
1109 /* Scan all objects being carried */
1110 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
1112 GAME_TEXT o_name[MAX_NLEN];
1115 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1116 next_o_idx = o_ptr->next_o_idx;
1118 /* Obtain an object description */
1119 object_desc(o_name, o_ptr, 0);
1122 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1124 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1128 move_cursor_relative(y, x);
1131 /* Always stop at "normal" keys */
1132 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1134 /* Sometimes stop at "space" key */
1135 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1137 /* Change the intro */
1138 s2 = _("をまた", "also carrying ");
1141 /* Use a preposition */
1158 GAME_TEXT o_name[MAX_NLEN];
1161 o_ptr = ¤t_floor_ptr->o_list[floor_list[0]];
1163 object_desc(o_name, o_ptr, 0);
1166 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1168 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1172 move_cursor_relative(y, x);
1181 /* Provide one cushion before item listing */
1184 /* Display rough information about items */
1186 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
1188 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
1192 move_cursor_relative(y, x);
1197 /* No request for listing */
1198 if (query != 'x' && query != ' ') return query;
1202 /** Display list of items **/
1204 /* Continue scrolling list if requested */
1212 show_gold_on_floor = TRUE;
1213 (void)show_floor(0, y, x, &min_width);
1214 show_gold_on_floor = FALSE;
1218 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
1220 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
1227 /* Exit unless 'Enter' */
1228 if (query != '\n' && query != '\r')
1233 /* Get the object being moved. */
1234 o_idx = g_ptr->o_idx;
1236 /* Only rotate a pile of two or more objects. */
1237 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
1239 /* Remove the first object from the list. */
1240 excise_object_idx(o_idx);
1242 /* Find end of the list. */
1244 while (current_floor_ptr->o_list[i].next_o_idx)
1245 i = current_floor_ptr->o_list[i].next_o_idx;
1247 /* Add after the last object. */
1248 current_floor_ptr->o_list[i].next_o_idx = o_idx;
1250 /* Loop and re-display the list */
1257 /* Scan all objects in the grid */
1258 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1261 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1262 next_o_idx = o_ptr->next_o_idx;
1264 if (o_ptr->marked & OM_FOUND)
1266 GAME_TEXT o_name[MAX_NLEN];
1271 /* Obtain an object description */
1272 object_desc(o_name, o_ptr, 0);
1275 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1277 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1281 move_cursor_relative(y, x);
1284 /* Always stop at "normal" keys */
1285 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1287 /* Sometimes stop at "space" key */
1288 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
1290 /* Change the intro */
1291 s1 = _("それは", "It is ");
1294 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
1308 /* Feature code (applying "mimic" field) */
1309 feat = get_feat_mimic(g_ptr);
1311 /* Require knowledge about grid, or ability to see grid */
1312 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
1314 /* Forget feature */
1318 f_ptr = &f_info[feat];
1320 /* Terrain feature if needed */
1321 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
1325 /* Hack -- special handling for quest entrances */
1326 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
1328 /* Set the quest number temporary */
1329 IDX old_quest = p_ptr->inside_quest;
1332 /* Clear the text */
1333 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
1334 quest_text_line = 0;
1336 p_ptr->inside_quest = g_ptr->special;
1338 /* Get the quest text */
1339 init_flags = INIT_NAME_ONLY;
1341 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
1343 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
1344 quest[g_ptr->special].name, quest[g_ptr->special].level);
1346 /* Reset the old quest number */
1347 p_ptr->inside_quest = old_quest;
1350 /* Hack -- special handling for building doors */
1351 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
1353 name = building[f_ptr->subtype].name;
1355 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
1357 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
1359 else if (have_flag(f_ptr->flags, FF_TOWN))
1361 name = town_info[g_ptr->special].name;
1363 else if (p_ptr->wild_mode && (feat == feat_floor))
1365 name = _("道", "road");
1369 name = f_name + f_ptr->name;
1375 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
1376 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
1377 have_flag(f_ptr->flags, FF_TOWN)))
1379 s2 = _("の中", "in ");
1382 /* Hack -- special introduction for store & building doors -KMW- */
1383 if (have_flag(f_ptr->flags, FF_STORE) ||
1384 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
1385 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
1386 have_flag(f_ptr->flags, FF_ENTRANCE))
1391 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
1392 have_flag(f_ptr->flags, FF_TOWN) ||
1393 have_flag(f_ptr->flags, FF_SHALLOW) ||
1394 have_flag(f_ptr->flags, FF_DEEP))
1400 /* Pick proper indefinite article */
1401 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
1405 /* Display a message */
1409 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
1410 else sprintf(f_idx_str, "%d", g_ptr->feat);
1412 sprintf(out_val, "%s%s%s%s[%s] %x %s %d %d %d (%d,%d) %d", s1, name, s2, s3, info, (unsigned int)g_ptr->info, f_idx_str, g_ptr->dist, g_ptr->cost, g_ptr->when, (int)y, (int)x, travel.cost[y][x]);
1414 sprintf(out_val, "%s%s%s%s [%s] %x %s %d %d %d (%d,%d)", s1, s2, s3, name, info, g_ptr->info, f_idx_str, g_ptr->dist, g_ptr->cost, g_ptr->when, (int)y, (int)x);
1419 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
1421 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1425 move_cursor_relative(y, x);
1428 /* Always stop at "normal" keys */
1429 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
1432 /* Stop on everything but "return" */
1433 if ((query != '\r') && (query != '\n')) return query;
1435 /* Repeat forever */
1441 * Handle "target" and "look".
1443 * Note that this code can be called from "get_aim_dir()".
1445 * All locations must be on the current panel. Consider the use of
1446 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1447 * some form of "scrolling" the map around the cursor.
1448 * That is, consider the possibility of "auto-scrolling" the screen
1449 * while the cursor moves around. This may require changes in the
1450 * "update_monster()" code to allow "visibility" even if off panel, and
1451 * may require dynamic recalculation of the "temp" grid set.
1453 * Hack -- targeting/observing an "outer border grid" may induce
1454 * problems, so this is not currently allowed.
1456 * The player can use the direction keys to move among "interesting"
1457 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1458 * move through the "interesting" grids in a sequential manner, or
1459 * can enter "location" mode, and use the direction keys to move one
1460 * grid at a time in any direction. The "t" (set target) command will
1461 * only target a monster (as opposed to a location) if the monster is
1462 * target_able and the "interesting" mode is being used.
1464 * The current grid is described using the "look" method above, and
1465 * a new command may be entered at any time, but note that if the
1466 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1467 * where "space" has no obvious meaning) then "space" will scan
1468 * through the description of the current grid until done, instead
1469 * of immediately jumping to the next "interesting" grid. This
1470 * allows the "target" command to retain its old semantics.
1472 * The "*", "+", and "-" keys may always be used to jump immediately
1473 * to the next (or previous) interesting grid, in the proper mode.
1475 * The "return" key may always be used to scan through a complete
1476 * grid description (forever).
1478 * This command will cancel any old target, even if used from
1479 * inside the "look" command.
1481 bool target_set(BIT_FLAGS mode)
1484 POSITION y = p_ptr->y;
1485 POSITION x = p_ptr->x;
1495 get_screen_size(&wid, &hgt);
1500 if (rogue_like_commands)
1509 /* Prepare the "temp" array */
1510 target_set_prepare(mode);
1512 /* Start near the player */
1518 /* Interesting grids */
1519 if (flag && tmp_pos.n)
1525 change_panel_xy(y, x);
1527 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1530 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1533 if (target_able(g_ptr->m_idx))
1535 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1538 /* Dis-allow target */
1541 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1547 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1548 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1549 strcat(info, cheatinfo);
1552 /* Describe and Prompt */
1554 query = target_set_aux(y, x, mode, info);
1558 /* Assume no "direction" */
1563 if (query == '\r') query = 't';
1581 if (target_able(g_ptr->m_idx))
1583 health_track(g_ptr->m_idx);
1584 target_who = g_ptr->m_idx;
1600 if (++m == tmp_pos.n)
1603 if (!expand_list) done = TRUE;
1613 if (!expand_list) done = TRUE;
1620 /* Recenter the map around the player */
1622 p_ptr->update |= (PU_MONSTERS);
1623 p_ptr->redraw |= (PR_MAP);
1624 p_ptr->window |= (PW_OVERHEAD);
1627 /* Recalculate interesting grids */
1628 target_set_prepare(mode);
1647 if(query == same_key)
1649 if (++m == tmp_pos.n)
1652 if (!expand_list) done = TRUE;
1657 /* Extract the action (if any) */
1658 d = get_keymap_dir(query);
1665 /* Hack -- move around */
1668 /* Modified to scroll to monster */
1669 POSITION y2 = panel_row_min;
1670 POSITION x2 = panel_col_min;
1672 /* Find a new monster */
1673 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
1675 /* Request to target past last interesting grid */
1676 while (flag && (i < 0))
1678 /* Note the change */
1679 if (change_panel(ddy[d], ddx[d]))
1681 int v = tmp_pos.y[m];
1682 int u = tmp_pos.x[m];
1684 /* Recalculate interesting grids */
1685 target_set_prepare(mode);
1687 /* Look at interesting grids */
1690 /* Find a new monster */
1691 i = target_pick(v, u, ddy[d], ddx[d]);
1697 /* Nothing interesting */
1700 POSITION dx = ddx[d];
1701 POSITION dy = ddy[d];
1703 /* Restore previous position */
1706 panel_bounds_center();
1708 p_ptr->update |= (PU_MONSTERS);
1709 p_ptr->redraw |= (PR_MAP);
1710 p_ptr->window |= (PW_OVERHEAD);
1713 /* Recalculate interesting grids */
1714 target_set_prepare(mode);
1716 /* Look at boring grids */
1723 /* Do not move horizontally if unnecessary */
1724 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1725 ((x > panel_col_min + wid / 2) && (dx < 0)))
1730 /* Do not move vertically if unnecessary */
1731 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1732 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1737 /* Apply the motion */
1738 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1739 (x >= panel_col_min+wid) || (x < panel_col_min))
1741 if (change_panel(dy, dx)) target_set_prepare(mode);
1744 /* Slide into legality */
1745 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1746 else if (x <= 0) x = 1;
1748 /* Slide into legality */
1749 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1750 else if (y <= 0) y = 1;
1759 /* Arbitrary grids */
1762 bool move_fast = FALSE;
1764 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1767 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1769 /* Default prompt */
1770 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1775 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1776 los(p_ptr->y, p_ptr->x, y, x),
1777 projectable(p_ptr->y, p_ptr->x, y, x));
1778 strcat(info, cheatinfo);
1781 /* Describe and Prompt (enable "TARGET_LOOK") */
1782 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1784 /* Assume no direction */
1789 if (query == '\r') query = 't';
1792 /* Analyze the keypress */
1816 /* Recenter the map around the player */
1818 p_ptr->update |= (PU_MONSTERS);
1819 p_ptr->redraw |= (PR_MAP);
1820 p_ptr->window |= (PW_OVERHEAD);
1823 /* Recalculate interesting grids */
1824 target_set_prepare(mode);
1846 /* Pick a nearby monster */
1847 for (i = 0; i < tmp_pos.n; i++)
1849 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1859 /* Nothing interesting */
1860 if (bd == 999) flag = FALSE;
1867 /* Extract the action (if any) */
1868 d = get_keymap_dir(query);
1870 /* XTRA HACK MOVEFAST */
1871 if (isupper(query)) move_fast = TRUE;
1878 /* Handle "direction" */
1881 POSITION dx = ddx[d];
1882 POSITION dy = ddy[d];
1884 /* XTRA HACK MOVEFAST */
1887 int mag = MIN(wid / 2, hgt / 2);
1897 /* Do not move horizontally if unnecessary */
1898 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1899 ((x > panel_col_min + wid / 2) && (dx < 0)))
1904 /* Do not move vertically if unnecessary */
1905 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1906 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1911 /* Apply the motion */
1912 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1913 (x >= panel_col_min + wid) || (x < panel_col_min))
1915 if (change_panel(dy, dx)) target_set_prepare(mode);
1918 /* Slide into legality */
1919 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1920 else if (x <= 0) x = 1;
1922 /* Slide into legality */
1923 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1924 else if (y <= 0) y = 1;
1932 /* Clear the top line */
1935 /* Recenter the map around the player */
1937 p_ptr->update |= (PU_MONSTERS);
1938 p_ptr->redraw |= (PR_MAP);
1939 p_ptr->window |= (PW_OVERHEAD);
1942 /* Failure to set target */
1943 if (!target_who) return (FALSE);
1951 * Get an "aiming direction" from the user.
1953 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1954 * "0" for "current target", and "-1" for "entry aborted".
1956 * Note that "Force Target", if set, will pre-empt user interaction,
1957 * if there is a usable target already set.
1959 * Note that confusion over-rides any (explicit?) user choice.
1961 bool get_aim_dir(DIRECTION *dp)
1970 /* Global direction */
1973 /* Hack -- auto-target if requested */
1974 if (use_old_target && target_okay()) dir = 5;
1976 if (repeat_pull(&code))
1981 if (!(code == 5 && !target_okay()))
1983 /* return (TRUE); */
1984 dir = (DIRECTION)code;
1987 *dp = (DIRECTION)code;
1989 /* Ask until satisfied */
1992 /* Choose a prompt */
1995 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1999 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2002 /* Get a command (or Cancel) */
2003 if (!get_com(p, &command, TRUE)) break;
2007 if (command == '\r') command = 't';
2010 /* Convert various keys to "standard" keys */
2013 /* Use current target */
2024 /* Set new target */
2029 if (target_set(TARGET_KILL)) dir = 5;
2035 /* Extract the action (if any) */
2036 dir = get_keymap_dir(command);
2042 /* Verify requested targets */
2043 if ((dir == 5) && !target_okay()) dir = 0;
2052 project_length = 0; /* reset to default */
2056 /* Save the direction */
2059 /* Check for confusion */
2060 if (p_ptr->confused)
2062 /* Random direction */
2063 dir = ddd[randint0(8)];
2066 /* Notice confusion */
2067 if (command_dir != dir)
2070 msg_print(_("あなたは混乱している。", "You are confused."));
2073 /* Save direction */
2076 /* repeat_push(dir); */
2077 repeat_push((COMMAND_CODE)command_dir);
2079 /* A "valid" direction was entered */
2084 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
2092 /* Global direction */
2095 if (repeat_pull(&code))
2097 dir = (DIRECTION)code;
2098 /* return (TRUE); */
2100 *dp = (DIRECTION)code;
2104 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2108 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2111 /* Get a direction */
2116 /* Get a command (or Cancel) */
2117 if (!get_com(prompt, &ch, TRUE)) break;
2120 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2126 /* Look up the direction */
2127 dir = get_keymap_dir(ch);
2133 /* Prevent weirdness */
2134 if ((dir == 5) && (!allow_under)) dir = 0;
2137 if (!dir) return (FALSE);
2139 /* Save desired direction */
2142 /* Apply "confusion" */
2143 if (p_ptr->confused)
2145 /* Standard confusion */
2146 if (randint0(100) < 75)
2148 /* Random direction */
2149 dir = ddd[randint0(8)];
2152 else if (p_ptr->riding && with_steed)
2154 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2155 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2157 if (MON_CONFUSED(m_ptr))
2159 /* Standard confusion */
2160 if (randint0(100) < 75)
2162 /* Random direction */
2163 dir = ddd[randint0(8)];
2166 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2168 /* Random direction */
2169 dir = ddd[randint0(8)];
2171 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2173 /* Random direction */
2174 dir = ddd[randint0(8)];
2178 /* Notice confusion */
2179 if (command_dir != dir)
2181 if (p_ptr->confused)
2184 msg_print(_("あなたは混乱している。", "You are confused."));
2188 GAME_TEXT m_name[MAX_NLEN];
2189 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2191 monster_desc(m_name, m_ptr, 0);
2192 if (MON_CONFUSED(m_ptr))
2194 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2198 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2203 /* Save direction */
2206 /* repeat_push(dir); */
2207 repeat_push((COMMAND_CODE)command_dir);
2214 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
2215 * and place it into "command_dir", unless we already have one.
2217 * This function should be used for all "repeatable" commands, such as
2218 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
2219 * as all commands which must reference a grid adjacent to the player,
2220 * and which may not reference the grid under the player. Note that,
2221 * for example, it is no longer possible to "disarm" or "open" chests
2222 * in the same grid as the player.
2224 * Direction "5" is illegal and will (cleanly) abort the command.
2226 * This function tracks and uses the "global direction", and uses
2227 * that as the "desired direction", to which "confusion" is applied.
2229 bool get_rep_dir(DIRECTION *dp, bool under)
2237 /* Global direction */
2240 if (repeat_pull(&code))
2242 dir = (DIRECTION)code;
2243 /* return (TRUE); */
2245 *dp = (DIRECTION)code;
2249 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2253 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2256 /* Get a direction */
2261 /* Get a command (or Cancel) */
2262 if (!get_com(prompt, &ch, TRUE)) break;
2265 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2271 /* Look up the direction */
2272 dir = get_keymap_dir(ch);
2278 /* Prevent weirdness */
2279 if ((dir == 5) && (!under)) dir = 0;
2282 if (!dir) return (FALSE);
2284 /* Save desired direction */
2287 /* Apply "confusion" */
2288 if (p_ptr->confused)
2290 /* Standard confusion */
2291 if (randint0(100) < 75)
2293 /* Random direction */
2294 dir = ddd[randint0(8)];
2297 else if (p_ptr->riding)
2299 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2300 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2302 if (MON_CONFUSED(m_ptr))
2304 /* Standard confusion */
2305 if (randint0(100) < 75)
2307 /* Random direction */
2308 dir = ddd[randint0(8)];
2311 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2313 /* Random direction */
2314 dir = ddd[randint0(8)];
2316 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2318 /* Random direction */
2319 dir = ddd[randint0(8)];
2323 /* Notice confusion */
2324 if (command_dir != dir)
2326 if (p_ptr->confused)
2329 msg_print(_("あなたは混乱している。", "You are confused."));
2333 GAME_TEXT m_name[MAX_NLEN];
2334 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2336 monster_desc(m_name, m_ptr, 0);
2337 if (MON_CONFUSED(m_ptr))
2339 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2343 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2348 /* Save direction */
2351 /* repeat_push(dir); */
2352 repeat_push((COMMAND_CODE)command_dir);
2360 * XAngband: determine if a given location is "interesting"
2361 * based on target_set_accept function.
2363 static bool tgt_pt_accept(POSITION y, POSITION x)
2368 if (!(in_bounds(y, x))) return (FALSE);
2370 /* Player grid is always interesting */
2371 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
2373 /* Handle hallucination */
2374 if (p_ptr->image) return (FALSE);
2376 /* Examine the grid */
2377 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2379 /* Interesting memorized features */
2380 if (g_ptr->info & (CAVE_MARK))
2383 if (cave_have_flag_grid(g_ptr, FF_LESS)) return (TRUE);
2384 if (cave_have_flag_grid(g_ptr, FF_MORE)) return (TRUE);
2386 /* Notice quest features */
2387 if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return (TRUE);
2388 if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return (TRUE);
2396 * XAngband: Prepare the "temp" array for "tget_pt"
2397 * based on target_set_prepare funciton.
2399 static void tgt_pt_prepare(void)
2403 /* Reset "temp" array */
2406 if (!expand_list) return;
2408 /* Scan the current panel */
2409 for (y = 1; y < current_floor_ptr->height; y++)
2411 for (x = 1; x < current_floor_ptr->width; x++)
2413 /* Require "interesting" contents */
2414 if (!tgt_pt_accept(y, x)) continue;
2416 /* Save the location */
2417 tmp_pos.x[tmp_pos.n] = x;
2418 tmp_pos.y[tmp_pos.n] = y;
2423 /* Target the nearest monster for shooting */
2424 ang_sort_comp = ang_sort_comp_distance;
2425 ang_sort_swap = ang_sort_swap_distance;
2427 /* Sort the positions */
2428 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n);
2432 * old -- from PsiAngband.
2434 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
2439 bool success = FALSE;
2443 get_screen_size(&wid, &hgt);
2453 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2454 msg_flag = FALSE; /* prevents "-more-" message. */
2456 while ((ch != ESCAPE) && !success)
2458 bool move_fast = FALSE;
2460 move_cursor_relative(y, x);
2472 if (player_bold(y, x)) ch = 0;
2475 else success = TRUE;
2479 /* XAngband: Move cursor to stairs */
2482 if (expand_list && tmp_pos.n)
2485 int cx = (panel_col_min + panel_col_max) / 2;
2486 int cy = (panel_row_min + panel_row_max) / 2;
2490 /* Skip stairs which have defferent distance */
2491 for (; n < tmp_pos.n; ++ n)
2493 grid_type *g_ptr = ¤t_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
2495 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2496 cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2503 if (n == tmp_pos.n) /* Loop out taget list */
2508 verify_panel(); /* Move cursor to player */
2510 p_ptr->update |= (PU_MONSTERS);
2512 p_ptr->redraw |= (PR_MAP);
2514 p_ptr->window |= (PW_OVERHEAD);
2517 else /* move cursor to next stair and change panel */
2522 dy = 2 * (y - cy) / hgt;
2523 dx = 2 * (x - cx) / wid;
2524 if (dy || dx) change_panel(dy, dx);
2530 /* Look up the direction */
2531 d = get_keymap_dir(ch);
2533 /* XTRA HACK MOVEFAST */
2534 if (isupper(ch)) move_fast = TRUE;
2536 /* Handle "direction" */
2542 /* XTRA HACK MOVEFAST */
2545 int mag = MIN(wid / 2, hgt / 2);
2555 /* Do not move horizontally if unnecessary */
2556 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2557 ((x > panel_col_min + wid / 2) && (dx < 0)))
2562 /* Do not move vertically if unnecessary */
2563 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2564 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2569 /* Apply the motion */
2570 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2571 (x >= panel_col_min + wid) || (x < panel_col_min))
2573 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2574 change_panel(dy, dx);
2577 /* Slide into legality */
2578 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
2579 else if (x <= 0) x = 1;
2581 /* Slide into legality */
2582 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
2583 else if (y <= 0) y = 1;
2590 /* Clear the top line */
2593 /* Recenter the map around the player */
2596 p_ptr->update |= (PU_MONSTERS);
2598 p_ptr->redraw |= (PR_MAP);
2600 p_ptr->window |= (PW_OVERHEAD);
2609 bool get_hack_dir(DIRECTION *dp)
2617 /* Global direction */
2620 /* (No auto-targeting) */
2622 /* Ask until satisfied */
2625 /* Choose a prompt */
2628 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2632 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2635 /* Get a command (or Cancel) */
2636 if (!get_com(p, &command, TRUE)) break;
2640 if (command == '\r') command = 't';
2643 /* Convert various keys to "standard" keys */
2646 /* Use current target */
2657 /* Set new target */
2662 if (target_set(TARGET_KILL)) dir = 5;
2668 /* Look up the direction */
2669 dir = get_keymap_dir(command);
2675 /* Verify requested targets */
2676 if ((dir == 5) && !target_okay()) dir = 0;
2683 if (!dir) return (FALSE);
2685 /* Save the direction */
2688 /* Check for confusion */
2689 if (p_ptr->confused)
2691 /* Random direction */
2692 dir = ddd[randint0(8)];
2695 /* Notice confusion */
2696 if (command_dir != dir)
2699 msg_print(_("あなたは混乱している。", "You are confused."));
2702 /* Save direction */
2705 /* A "valid" direction was entered */