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"
28 #define REWARD_CHANCE 10
32 * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
33 * Advance experience levels and print experience
36 void check_experience(void)
38 bool level_reward = FALSE;
39 bool level_mutation = FALSE;
40 bool level_inc_stat = FALSE;
41 bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
42 PLAYER_LEVEL old_lev = p_ptr->lev;
44 /* Hack -- lower limit */
45 if (p_ptr->exp < 0) p_ptr->exp = 0;
46 if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
47 if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
49 /* Hack -- upper limit */
50 if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
51 if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
52 if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
54 /* Hack -- maintain "max" experience */
55 if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
57 /* Hack -- maintain "max max" experience */
58 if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
60 /* Redraw experience */
61 p_ptr->redraw |= (PR_EXP);
65 /* Lose levels while possible */
66 while ((p_ptr->lev > 1) &&
67 (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
71 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
72 p_ptr->redraw |= (PR_LEV | PR_TITLE);
73 p_ptr->window |= (PW_PLAYER);
78 /* Gain levels while possible */
79 while ((p_ptr->lev < PY_MAX_LEVEL) &&
80 (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
85 /* Save the highest level */
86 if (p_ptr->lev > p_ptr->max_plv)
88 p_ptr->max_plv = p_ptr->lev;
90 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
91 (p_ptr->muta2 & MUT2_CHAOS_GIFT))
95 if (p_ptr->prace == RACE_BEASTMAN)
97 if (one_in_(5)) level_mutation = TRUE;
99 level_inc_stat = TRUE;
101 do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
106 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
108 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
109 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
110 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
120 if(!(p_ptr->max_plv % 10))
129 cnv_stat(p_ptr->stat_max[0], tmp);
130 prt(format(_(" a) 腕力 (現在値 %s)", " a) Str (cur %s)"), tmp), 2, 14);
131 cnv_stat(p_ptr->stat_max[1], tmp);
132 prt(format(_(" b) 知能 (現在値 %s)", " a) Int (cur %s)"), tmp), 3, 14);
133 cnv_stat(p_ptr->stat_max[2], tmp);
134 prt(format(_(" c) 賢さ (現在値 %s)", " a) Wis (cur %s)"), tmp), 4, 14);
135 cnv_stat(p_ptr->stat_max[3], tmp);
136 prt(format(_(" d) 器用 (現在値 %s)", " a) Dex (cur %s)"), tmp), 5, 14);
137 cnv_stat(p_ptr->stat_max[4], tmp);
138 prt(format(_(" e) 耐久 (現在値 %s)", " a) Con (cur %s)"), tmp), 6, 14);
139 cnv_stat(p_ptr->stat_max[5], tmp);
140 prt(format(_(" f) 魅力 (現在値 %s)", " a) Chr (cur %s)"), tmp), 7, 14);
143 prt(_(" どの能力値を上げますか?", " Which stat do you want to raise?"), 1, 14);
148 if ((choice >= 'a') && (choice <= 'f')) break;
150 for(n = 0; n < A_MAX; n++)
151 if (n != choice - 'a')
153 if (get_check(_("よろしいですか?", "Are you sure? "))) break;
155 do_inc_stat(choice - 'a');
158 else if(!(p_ptr->max_plv % 2))
159 do_inc_stat(randint0(6));
164 msg_print(_("あなたは変わった気がする...", "You feel different..."));
165 (void)gain_mutation(p_ptr, 0);
166 level_mutation = FALSE;
170 * 報酬でレベルが上ると再帰的に check_experience() が
175 gain_level_reward(0);
176 level_reward = FALSE;
179 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
180 p_ptr->redraw |= (PR_LEV | PR_TITLE);
181 p_ptr->window |= (PW_PLAYER | PW_SPELL);
185 /* Load an autopick preference file */
186 if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
192 * @brief モンスターを撃破した際の述語メッセージを返す /
193 * Return monster death string
194 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
195 * @return 撃破されたモンスターの述語
197 concptr extract_note_dies(MONRACE_IDX r_idx)
199 monster_race *r_ptr = &r_info[r_idx];
200 /* Some monsters get "destroyed" */
201 if (!monster_living(r_idx))
205 for (i = 0; i < 4; i++)
207 if (r_ptr->blow[i].method == RBM_EXPLODE)
209 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
212 return _("を倒した。", " is destroyed.");
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;
254 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
255 * @param y 変更先のフロアY座標
256 * @param x 変更先のフロアX座標
258 * Handle a request to change the current panel
259 * Return TRUE if the panel was changed.
260 * Also used in do_cmd_locate
261 * @return 実際に再描画が必要だった場合TRUEを返す
263 static bool change_panel_xy(POSITION y, POSITION x)
265 POSITION dy = 0, dx = 0;
268 get_screen_size(&wid, &hgt);
270 if (y < panel_row_min) dy = -1;
271 if (y > panel_row_max) dy = 1;
272 if (x < panel_col_min) dx = -1;
273 if (x > panel_col_max) dx = 1;
275 if (!dy && !dx) return (FALSE);
277 return change_panel(dy, dx);
282 * @brief マップ描画のフォーカスを当てるべき座標を更新する
284 * Given an row (y) and col (x), this routine detects when a move
285 * off the screen has occurred and figures new borders. -RAK-
286 * "Update" forces a "full update" to take place.
287 * The map is reprinted if necessary, and "TRUE" is returned.
288 * @return 実際に再描画が必要だった場合TRUEを返す
290 void verify_panel(void)
292 POSITION y = p_ptr->y;
293 POSITION x = p_ptr->x;
301 get_screen_size(&wid, &hgt);
303 max_prow_min = current_floor_ptr->height - hgt;
304 max_pcol_min = current_floor_ptr->width - wid;
306 /* Bounds checking */
307 if (max_prow_min < 0) max_prow_min = 0;
308 if (max_pcol_min < 0) max_pcol_min = 0;
310 /* Center on player */
311 if (center_player && (center_running || !running))
313 /* Center vertically */
314 prow_min = y - hgt / 2;
315 if (prow_min < 0) prow_min = 0;
316 else if (prow_min > max_prow_min) prow_min = max_prow_min;
318 /* Center horizontally */
319 pcol_min = x - wid / 2;
320 if (pcol_min < 0) pcol_min = 0;
321 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
325 prow_min = panel_row_min;
326 pcol_min = panel_col_min;
328 /* Scroll screen when 2 grids from top/bottom edge */
329 if (y > panel_row_max - 2)
331 while (y > prow_min + hgt-1 - 2)
333 prow_min += (hgt / 2);
337 if (y < panel_row_min + 2)
339 while (y < prow_min + 2)
341 prow_min -= (hgt / 2);
345 if (prow_min > max_prow_min) prow_min = max_prow_min;
346 if (prow_min < 0) prow_min = 0;
348 /* Scroll screen when 4 grids from left/right edge */
349 if (x > panel_col_max - 4)
351 while (x > pcol_min + wid-1 - 4)
353 pcol_min += (wid / 2);
357 if (x < panel_col_min + 4)
359 while (x < pcol_min + 4)
361 pcol_min -= (wid / 2);
365 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
366 if (pcol_min < 0) pcol_min = 0;
369 /* Check for "no change" */
370 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
372 /* Save the new panel info */
373 panel_row_min = prow_min;
374 panel_col_min = pcol_min;
376 /* Hack -- optional disturb on "panel change" */
377 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
379 /* Recalculate the boundaries */
380 panel_bounds_center();
382 p_ptr->update |= (PU_MONSTERS);
383 p_ptr->redraw |= (PR_MAP);
384 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
389 * Monster health description
391 concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
393 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
400 /* Determine if the monster is "living" */
401 living = monster_living(m_ptr->ap_r_idx);
403 /* Calculate a health "percentage" */
404 perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
406 /* Healthy monsters */
407 if (m_ptr->hp >= m_ptr->maxhp)
409 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
414 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
419 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
424 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
429 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
432 /* Need attitude information? */
435 /* Full information is not needed */
438 else if (is_pet(m_ptr))
440 attitude = _(", ペット", ", pet");
442 else if (is_friendly(m_ptr))
444 attitude = _(", 友好的", ", friendly");
448 attitude = _("", "");
452 if (m_ptr->smart & SM_CLONED)
461 /* Display monster's level --- idea borrowed from ToME */
462 if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
464 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
468 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
475 /*** Targeting Code ***/
479 * Determine is a monster makes a reasonable target
481 * The concept of "targeting" was stolen from "Morgul" (?)
483 * The player can target any location, or any "target-able" monster.
485 * Currently, a monster is "target_able" if it is visible, and if
486 * the player can hit it with a projection, and the player is not
487 * hallucinating. This allows use of "use closest target" macros.
489 * Future versions may restrict the ability to target "trappers"
490 * and "mimics", but the semantics is a little bit weird.
492 bool target_able(MONSTER_IDX m_idx)
494 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
496 /* Monster must be alive */
497 if (!m_ptr->r_idx) return (FALSE);
499 /* Hack -- no targeting hallucinations */
500 if (p_ptr->image) return (FALSE);
502 /* Monster must be visible */
503 if (!m_ptr->ml) return (FALSE);
505 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
507 /* Monster must be projectable */
508 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
510 /* Hack -- Never target trappers */
511 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
521 * Update (if necessary) and verify (if possible) the target.
523 * We return TRUE if the target is "okay" and FALSE otherwise.
525 bool target_okay(void)
527 /* Accept stationary targets */
528 if (target_who < 0) return (TRUE);
530 /* Check moving targets */
533 /* Accept reasonable targets */
534 if (target_able(target_who))
536 monster_type *m_ptr = ¤t_floor_ptr->m_list[target_who];
538 /* Acquire monster location */
539 target_row = m_ptr->fy;
540 target_col = m_ptr->fx;
547 /* Assume no target */
553 * Sorting hook -- comp function -- by "distance to player"
555 * We use "u" and "v" to point to arrays of "x" and "y" positions,
556 * and sort the arrays by double-distance to the player.
558 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
560 POSITION *x = (POSITION*)(u);
561 POSITION *y = (POSITION*)(v);
563 POSITION da, db, kx, ky;
565 /* Absolute distance components */
566 kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
567 ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
569 /* Approximate Double Distance to the first point */
570 da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
572 /* Absolute distance components */
573 kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
574 ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
576 /* Approximate Double Distance to the first point */
577 db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
579 /* Compare the distances */
585 * Sorting hook -- comp function -- by importance level of grids
587 * We use "u" and "v" to point to arrays of "x" and "y" positions,
588 * and sort the arrays by level of monster
590 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
592 POSITION *x = (POSITION*)(u);
593 POSITION *y = (POSITION*)(v);
594 grid_type *ca_ptr = ¤t_floor_ptr->grid_array[y[a]][x[a]];
595 grid_type *cb_ptr = ¤t_floor_ptr->grid_array[y[b]][x[b]];
596 monster_type *ma_ptr = ¤t_floor_ptr->m_list[ca_ptr->m_idx];
597 monster_type *mb_ptr = ¤t_floor_ptr->m_list[cb_ptr->m_idx];
598 monster_race *ap_ra_ptr, *ap_rb_ptr;
600 /* The player grid */
601 if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
602 if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
604 /* Extract monster race */
605 if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
606 else ap_ra_ptr = NULL;
607 if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
608 else ap_rb_ptr = NULL;
610 if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
611 if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
613 /* Compare two monsters */
614 if (ap_ra_ptr && ap_rb_ptr)
616 /* Unique monsters first */
617 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
618 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
620 /* Shadowers first (あやしい影) */
621 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
622 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
624 /* Unknown monsters first */
625 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
626 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
628 /* Higher level monsters first (if known) */
629 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
631 if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
632 if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
635 /* Sort by index if all conditions are same */
636 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
637 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
640 /* An object get higher priority */
641 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;
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 FALSE;
644 /* Priority from the terrain */
645 if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
646 if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
648 /* If all conditions are same, compare distance */
649 return ang_sort_comp_distance(u, v, a, b);
654 * Sorting hook -- swap function -- by "distance to player"
656 * We use "u" and "v" to point to arrays of "x" and "y" positions,
657 * and sort the arrays by distance to the player.
659 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
661 POSITION *x = (POSITION*)(u);
662 POSITION *y = (POSITION*)(v);
680 * Hack -- help "select" a location (see below)
682 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
685 POSITION x2, y2, x3, y3, x4, y4;
686 POSITION_IDX b_i = -1, b_v = 9999;
689 /* Scan the locations */
690 for (i = 0; i < tmp_pos.n; i++)
696 /* Directed distance */
700 /* Verify quadrant */
701 if (dx && (x3 * dx <= 0)) continue;
702 if (dy && (y3 * dy <= 0)) continue;
704 /* Absolute distance */
708 /* Verify quadrant */
709 if (dy && !dx && (x4 > y4)) continue;
710 if (dx && !dy && (y4 > x4)) continue;
712 /* Approximate Double Distance */
713 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
715 /* Penalize location */
718 if ((b_i >= 0) && (v >= b_v)) continue;
728 * Hack -- determine if a given location is "interesting"
730 static bool target_set_accept(POSITION y, POSITION x)
733 OBJECT_IDX this_o_idx, next_o_idx = 0;
736 if (!(in_bounds(y, x))) return (FALSE);
738 /* Player grid is always interesting */
739 if (player_bold(y, x)) return (TRUE);
741 /* Handle hallucination */
742 if (p_ptr->image) return (FALSE);
744 /* Examine the grid */
745 g_ptr = ¤t_floor_ptr->grid_array[y][x];
747 /* Visible monsters */
750 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
752 /* Visible monsters */
753 if (m_ptr->ml) return (TRUE);
756 /* Scan all objects in the grid */
757 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
760 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
761 next_o_idx = o_ptr->next_o_idx;
763 /* Memorized object */
764 if (o_ptr->marked & OM_FOUND) return (TRUE);
767 /* Interesting memorized features */
768 if (g_ptr->info & (CAVE_MARK))
770 /* Notice object features */
771 if (g_ptr->info & CAVE_OBJECT) return (TRUE);
773 /* Feature code (applying "mimic" field) */
774 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE)) return TRUE;
782 * Prepare the "temp" array for "target_set"
784 * Return the number of target_able monsters in the set.
786 static void target_set_prepare(BIT_FLAGS mode)
789 POSITION min_hgt, max_hgt, min_wid, max_wid;
791 if (mode & TARGET_KILL)
794 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
795 max_hgt = MIN((p_ptr->y + MAX_RANGE), current_floor_ptr->height - 1);
796 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
797 max_wid = MIN((p_ptr->x + MAX_RANGE), current_floor_ptr->width - 1);
799 else /* not targetting */
802 min_hgt = panel_row_min;
803 max_hgt = panel_row_max;
804 min_wid = panel_col_min;
805 max_wid = panel_col_max;
808 /* Reset "temp" array */
811 /* Scan the current panel */
812 for (y = min_hgt; y <= max_hgt; y++)
814 for (x = min_wid; x <= max_wid; x++)
818 /* Require "interesting" contents */
819 if (!target_set_accept(y, x)) continue;
821 g_ptr = ¤t_floor_ptr->grid_array[y][x];
823 /* Require target_able monsters for "TARGET_KILL" */
824 if ((mode & (TARGET_KILL)) && !target_able(g_ptr->m_idx)) continue;
826 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(¤t_floor_ptr->m_list[g_ptr->m_idx])) continue;
828 /* Save the location */
829 tmp_pos.x[tmp_pos.n] = x;
830 tmp_pos.y[tmp_pos.n] = y;
835 /* Set the sort hooks */
836 if (mode & (TARGET_KILL))
838 /* Target the nearest monster for shooting */
839 ang_sort_comp = ang_sort_comp_distance;
840 ang_sort_swap = ang_sort_swap_distance;
844 /* Look important grids first in Look command */
845 ang_sort_comp = ang_sort_comp_importance;
846 ang_sort_swap = ang_sort_swap_distance;
849 /* Sort the positions */
850 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n);
852 if (p_ptr->riding && target_pet && (tmp_pos.n > 1) && (mode & (TARGET_KILL)))
857 tmp_pos.y[0] = tmp_pos.y[1];
860 tmp_pos.x[0] = tmp_pos.x[1];
865 void target_set_prepare_look(void){
866 target_set_prepare(TARGET_LOOK);
871 * Evaluate number of kill needed to gain level
873 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
875 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
877 s32b exp_mon, exp_adv;
878 u32b exp_mon_frac, exp_adv_frac;
880 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
885 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
895 /* The monster's experience point (assuming average monster speed) */
896 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
898 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
901 /* Total experience value for next level */
902 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
904 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
906 /* Experience value need to get */
907 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
910 /* You need to kill at least one monster to get any experience */
911 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
912 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
914 /* Extract number of monsters needed */
915 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
917 /* If 999 or more monsters needed, only display "999". */
918 num = MIN(999, exp_adv_frac);
920 /* Display the number */
921 sprintf(buf,"%03ld", (long int)num);
925 bool show_gold_on_floor = FALSE;
928 * Examine a grid, return a keypress.
930 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
931 * indicates that the "space" key should scan through the contents
932 * of the grid, instead of simply returning immediately. This lets
933 * the "look" command get complete information, without making the
934 * "target" command annoying.
936 * The "info" argument contains the "commands" which should be shown
937 * inside the "[xxx]" text. This string must never be empty, or grids
938 * containing monsters will be displayed with an extra comma.
940 * Note that if a monster is in the grid, we update both the monster
941 * recall info and the health bar info to track that monster.
943 * Eventually, we may allow multiple objects per grid, or objects
944 * and terrain features in the same grid.
946 * This function must handle blindness/hallucination.
948 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
950 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
951 OBJECT_IDX this_o_idx, next_o_idx = 0;
952 concptr s1 = "", s2 = "", s3 = "", x_info = "";
957 char out_val[MAX_NLEN+80];
958 OBJECT_IDX floor_list[23];
959 ITEM_NUMBER floor_num = 0;
961 /* Scan all objects in the grid */
964 floor_num = scan_floor(floor_list, y, x, 0x02);
968 x_info = _("x物 ", "x,");
972 /* Hack -- under the player */
973 if (player_bold(y, x))
986 s1 = _("ターゲット:", "Target:");
989 /* Hack -- hallucination */
992 concptr name = _("何か奇妙な物", "something strange");
994 /* Display a message */
996 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
998 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1002 move_cursor_relative(y, x);
1005 /* Stop on everything but "return" */
1006 if ((query != '\r') && (query != '\n')) return query;
1008 /* Repeat forever */
1013 /* Actual monsters */
1014 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
1016 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
1017 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1018 GAME_TEXT m_name[MAX_NLEN];
1019 bool recall = FALSE;
1024 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1025 monster_race_track(m_ptr->ap_r_idx);
1026 health_track(g_ptr->m_idx);
1039 /* Recall on screen */
1040 screen_roff(m_ptr->ap_r_idx, 0);
1042 /* Hack -- Complete the prompt (again) */
1043 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
1050 /* Normal commands */
1051 if (query != 'r') break;
1056 /* Cleare recall text and repeat */
1062 /* Describe, and prompt for recall */
1063 evaluate_monster_exp(acount, m_ptr);
1066 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);
1068 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);
1074 move_cursor_relative(y, x);
1079 /* Normal commands */
1080 if (query != 'r') break;
1086 /* Always stop at "normal" keys */
1087 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1089 /* Sometimes stop at "space" key */
1090 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1092 /* Change the intro */
1093 s1 = _("それは", "It is ");
1095 /* Hack -- take account of gender */
1096 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
1097 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
1099 /* Use a preposition */
1108 /* Scan all objects being carried */
1109 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
1111 GAME_TEXT o_name[MAX_NLEN];
1114 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1115 next_o_idx = o_ptr->next_o_idx;
1117 /* Obtain an object description */
1118 object_desc(o_name, o_ptr, 0);
1121 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1123 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1127 move_cursor_relative(y, x);
1130 /* Always stop at "normal" keys */
1131 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1133 /* Sometimes stop at "space" key */
1134 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1136 /* Change the intro */
1137 s2 = _("をまた", "also carrying ");
1140 /* Use a preposition */
1157 GAME_TEXT o_name[MAX_NLEN];
1160 o_ptr = ¤t_floor_ptr->o_list[floor_list[0]];
1162 object_desc(o_name, o_ptr, 0);
1165 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1167 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1171 move_cursor_relative(y, x);
1180 /* Provide one cushion before item listing */
1183 /* Display rough information about items */
1185 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
1187 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
1191 move_cursor_relative(y, x);
1196 /* No request for listing */
1197 if (query != 'x' && query != ' ') return query;
1201 /** Display list of items **/
1203 /* Continue scrolling list if requested */
1211 show_gold_on_floor = TRUE;
1212 (void)show_floor(0, y, x, &min_width);
1213 show_gold_on_floor = FALSE;
1217 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
1219 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
1226 /* Exit unless 'Enter' */
1227 if (query != '\n' && query != '\r')
1232 /* Get the object being moved. */
1233 o_idx = g_ptr->o_idx;
1235 /* Only rotate a pile of two or more objects. */
1236 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
1238 /* Remove the first object from the list. */
1239 excise_object_idx(o_idx);
1241 /* Find end of the list. */
1243 while (current_floor_ptr->o_list[i].next_o_idx)
1244 i = current_floor_ptr->o_list[i].next_o_idx;
1246 /* Add after the last object. */
1247 current_floor_ptr->o_list[i].next_o_idx = o_idx;
1249 /* Loop and re-display the list */
1256 /* Scan all objects in the grid */
1257 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1260 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1261 next_o_idx = o_ptr->next_o_idx;
1263 if (o_ptr->marked & OM_FOUND)
1265 GAME_TEXT o_name[MAX_NLEN];
1270 /* Obtain an object description */
1271 object_desc(o_name, o_ptr, 0);
1274 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1276 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1280 move_cursor_relative(y, x);
1283 /* Always stop at "normal" keys */
1284 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1286 /* Sometimes stop at "space" key */
1287 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
1289 /* Change the intro */
1290 s1 = _("それは", "It is ");
1293 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
1307 /* Feature code (applying "mimic" field) */
1308 feat = get_feat_mimic(g_ptr);
1310 /* Require knowledge about grid, or ability to see grid */
1311 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
1313 /* Forget feature */
1317 f_ptr = &f_info[feat];
1319 /* Terrain feature if needed */
1320 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
1324 /* Hack -- special handling for quest entrances */
1325 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
1327 /* Set the quest number temporary */
1328 IDX old_quest = p_ptr->inside_quest;
1331 /* Clear the text */
1332 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
1333 quest_text_line = 0;
1335 p_ptr->inside_quest = g_ptr->special;
1337 /* Get the quest text */
1338 init_flags = INIT_NAME_ONLY;
1340 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
1342 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
1343 quest[g_ptr->special].name, quest[g_ptr->special].level);
1345 /* Reset the old quest number */
1346 p_ptr->inside_quest = old_quest;
1349 /* Hack -- special handling for building doors */
1350 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
1352 name = building[f_ptr->subtype].name;
1354 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
1356 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
1358 else if (have_flag(f_ptr->flags, FF_TOWN))
1360 name = town_info[g_ptr->special].name;
1362 else if (p_ptr->wild_mode && (feat == feat_floor))
1364 name = _("道", "road");
1368 name = f_name + f_ptr->name;
1374 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
1375 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
1376 have_flag(f_ptr->flags, FF_TOWN)))
1378 s2 = _("の中", "in ");
1381 /* Hack -- special introduction for store & building doors -KMW- */
1382 if (have_flag(f_ptr->flags, FF_STORE) ||
1383 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
1384 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
1385 have_flag(f_ptr->flags, FF_ENTRANCE))
1390 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
1391 have_flag(f_ptr->flags, FF_TOWN) ||
1392 have_flag(f_ptr->flags, FF_SHALLOW) ||
1393 have_flag(f_ptr->flags, FF_DEEP))
1399 /* Pick proper indefinite article */
1400 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
1404 /* Display a message */
1408 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
1409 else sprintf(f_idx_str, "%d", g_ptr->feat);
1411 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]);
1413 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);
1418 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
1420 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1424 move_cursor_relative(y, x);
1427 /* Always stop at "normal" keys */
1428 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
1431 /* Stop on everything but "return" */
1432 if ((query != '\r') && (query != '\n')) return query;
1434 /* Repeat forever */
1440 * Handle "target" and "look".
1442 * Note that this code can be called from "get_aim_dir()".
1444 * All locations must be on the current panel. Consider the use of
1445 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1446 * some form of "scrolling" the map around the cursor.
1447 * That is, consider the possibility of "auto-scrolling" the screen
1448 * while the cursor moves around. This may require changes in the
1449 * "update_monster()" code to allow "visibility" even if off panel, and
1450 * may require dynamic recalculation of the "temp" grid set.
1452 * Hack -- targeting/observing an "outer border grid" may induce
1453 * problems, so this is not currently allowed.
1455 * The player can use the direction keys to move among "interesting"
1456 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1457 * move through the "interesting" grids in a sequential manner, or
1458 * can enter "location" mode, and use the direction keys to move one
1459 * grid at a time in any direction. The "t" (set target) command will
1460 * only target a monster (as opposed to a location) if the monster is
1461 * target_able and the "interesting" mode is being used.
1463 * The current grid is described using the "look" method above, and
1464 * a new command may be entered at any time, but note that if the
1465 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1466 * where "space" has no obvious meaning) then "space" will scan
1467 * through the description of the current grid until done, instead
1468 * of immediately jumping to the next "interesting" grid. This
1469 * allows the "target" command to retain its old semantics.
1471 * The "*", "+", and "-" keys may always be used to jump immediately
1472 * to the next (or previous) interesting grid, in the proper mode.
1474 * The "return" key may always be used to scan through a complete
1475 * grid description (forever).
1477 * This command will cancel any old target, even if used from
1478 * inside the "look" command.
1480 bool target_set(BIT_FLAGS mode)
1483 POSITION y = p_ptr->y;
1484 POSITION x = p_ptr->x;
1494 get_screen_size(&wid, &hgt);
1499 if (rogue_like_commands)
1508 /* Prepare the "temp" array */
1509 target_set_prepare(mode);
1511 /* Start near the player */
1517 /* Interesting grids */
1518 if (flag && tmp_pos.n)
1524 change_panel_xy(y, x);
1526 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1529 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1532 if (target_able(g_ptr->m_idx))
1534 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1537 /* Dis-allow target */
1540 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1546 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1547 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1548 strcat(info, cheatinfo);
1551 /* Describe and Prompt */
1553 query = target_set_aux(y, x, mode, info);
1557 /* Assume no "direction" */
1562 if (query == '\r') query = 't';
1580 if (target_able(g_ptr->m_idx))
1582 health_track(g_ptr->m_idx);
1583 target_who = g_ptr->m_idx;
1599 if (++m == tmp_pos.n)
1602 if (!expand_list) done = TRUE;
1612 if (!expand_list) done = TRUE;
1619 /* Recenter the map around the player */
1621 p_ptr->update |= (PU_MONSTERS);
1622 p_ptr->redraw |= (PR_MAP);
1623 p_ptr->window |= (PW_OVERHEAD);
1626 /* Recalculate interesting grids */
1627 target_set_prepare(mode);
1646 if(query == same_key)
1648 if (++m == tmp_pos.n)
1651 if (!expand_list) done = TRUE;
1656 /* Extract the action (if any) */
1657 d = get_keymap_dir(query);
1664 /* Hack -- move around */
1667 /* Modified to scroll to monster */
1668 POSITION y2 = panel_row_min;
1669 POSITION x2 = panel_col_min;
1671 /* Find a new monster */
1672 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
1674 /* Request to target past last interesting grid */
1675 while (flag && (i < 0))
1677 /* Note the change */
1678 if (change_panel(ddy[d], ddx[d]))
1680 int v = tmp_pos.y[m];
1681 int u = tmp_pos.x[m];
1683 /* Recalculate interesting grids */
1684 target_set_prepare(mode);
1686 /* Look at interesting grids */
1689 /* Find a new monster */
1690 i = target_pick(v, u, ddy[d], ddx[d]);
1696 /* Nothing interesting */
1699 POSITION dx = ddx[d];
1700 POSITION dy = ddy[d];
1702 /* Restore previous position */
1705 panel_bounds_center();
1707 p_ptr->update |= (PU_MONSTERS);
1708 p_ptr->redraw |= (PR_MAP);
1709 p_ptr->window |= (PW_OVERHEAD);
1712 /* Recalculate interesting grids */
1713 target_set_prepare(mode);
1715 /* Look at boring grids */
1722 /* Do not move horizontally if unnecessary */
1723 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1724 ((x > panel_col_min + wid / 2) && (dx < 0)))
1729 /* Do not move vertically if unnecessary */
1730 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1731 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1736 /* Apply the motion */
1737 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1738 (x >= panel_col_min+wid) || (x < panel_col_min))
1740 if (change_panel(dy, dx)) target_set_prepare(mode);
1743 /* Slide into legality */
1744 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1745 else if (x <= 0) x = 1;
1747 /* Slide into legality */
1748 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1749 else if (y <= 0) y = 1;
1758 /* Arbitrary grids */
1761 bool move_fast = FALSE;
1763 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1766 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1768 /* Default prompt */
1769 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1774 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1775 los(p_ptr->y, p_ptr->x, y, x),
1776 projectable(p_ptr->y, p_ptr->x, y, x));
1777 strcat(info, cheatinfo);
1780 /* Describe and Prompt (enable "TARGET_LOOK") */
1781 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1783 /* Assume no direction */
1788 if (query == '\r') query = 't';
1791 /* Analyze the keypress */
1815 /* Recenter the map around the player */
1817 p_ptr->update |= (PU_MONSTERS);
1818 p_ptr->redraw |= (PR_MAP);
1819 p_ptr->window |= (PW_OVERHEAD);
1822 /* Recalculate interesting grids */
1823 target_set_prepare(mode);
1845 /* Pick a nearby monster */
1846 for (i = 0; i < tmp_pos.n; i++)
1848 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1858 /* Nothing interesting */
1859 if (bd == 999) flag = FALSE;
1866 /* Extract the action (if any) */
1867 d = get_keymap_dir(query);
1869 /* XTRA HACK MOVEFAST */
1870 if (isupper(query)) move_fast = TRUE;
1877 /* Handle "direction" */
1880 POSITION dx = ddx[d];
1881 POSITION dy = ddy[d];
1883 /* XTRA HACK MOVEFAST */
1886 int mag = MIN(wid / 2, hgt / 2);
1896 /* Do not move horizontally if unnecessary */
1897 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1898 ((x > panel_col_min + wid / 2) && (dx < 0)))
1903 /* Do not move vertically if unnecessary */
1904 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1905 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1910 /* Apply the motion */
1911 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1912 (x >= panel_col_min + wid) || (x < panel_col_min))
1914 if (change_panel(dy, dx)) target_set_prepare(mode);
1917 /* Slide into legality */
1918 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1919 else if (x <= 0) x = 1;
1921 /* Slide into legality */
1922 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1923 else if (y <= 0) y = 1;
1931 /* Clear the top line */
1934 /* Recenter the map around the player */
1936 p_ptr->update |= (PU_MONSTERS);
1937 p_ptr->redraw |= (PR_MAP);
1938 p_ptr->window |= (PW_OVERHEAD);
1941 /* Failure to set target */
1942 if (!target_who) return (FALSE);
1950 * Get an "aiming direction" from the user.
1952 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1953 * "0" for "current target", and "-1" for "entry aborted".
1955 * Note that "Force Target", if set, will pre-empt user interaction,
1956 * if there is a usable target already set.
1958 * Note that confusion over-rides any (explicit?) user choice.
1960 bool get_aim_dir(DIRECTION *dp)
1969 /* Global direction */
1972 /* Hack -- auto-target if requested */
1973 if (use_old_target && target_okay()) dir = 5;
1975 if (repeat_pull(&code))
1980 if (!(code == 5 && !target_okay()))
1982 /* return (TRUE); */
1983 dir = (DIRECTION)code;
1986 *dp = (DIRECTION)code;
1988 /* Ask until satisfied */
1991 /* Choose a prompt */
1994 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1998 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2001 /* Get a command (or Cancel) */
2002 if (!get_com(p, &command, TRUE)) break;
2006 if (command == '\r') command = 't';
2009 /* Convert various keys to "standard" keys */
2012 /* Use current target */
2023 /* Set new target */
2028 if (target_set(TARGET_KILL)) dir = 5;
2034 /* Extract the action (if any) */
2035 dir = get_keymap_dir(command);
2041 /* Verify requested targets */
2042 if ((dir == 5) && !target_okay()) dir = 0;
2051 project_length = 0; /* reset to default */
2055 /* Save the direction */
2058 /* Check for confusion */
2059 if (p_ptr->confused)
2061 /* Random direction */
2062 dir = ddd[randint0(8)];
2065 /* Notice confusion */
2066 if (command_dir != dir)
2069 msg_print(_("あなたは混乱している。", "You are confused."));
2072 /* Save direction */
2075 /* repeat_push(dir); */
2076 repeat_push((COMMAND_CODE)command_dir);
2078 /* A "valid" direction was entered */
2083 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
2091 /* Global direction */
2094 if (repeat_pull(&code))
2096 dir = (DIRECTION)code;
2097 /* return (TRUE); */
2099 *dp = (DIRECTION)code;
2103 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2107 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2110 /* Get a direction */
2115 /* Get a command (or Cancel) */
2116 if (!get_com(prompt, &ch, TRUE)) break;
2119 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2125 /* Look up the direction */
2126 dir = get_keymap_dir(ch);
2132 /* Prevent weirdness */
2133 if ((dir == 5) && (!allow_under)) dir = 0;
2136 if (!dir) return (FALSE);
2138 /* Save desired direction */
2141 /* Apply "confusion" */
2142 if (p_ptr->confused)
2144 /* Standard confusion */
2145 if (randint0(100) < 75)
2147 /* Random direction */
2148 dir = ddd[randint0(8)];
2151 else if (p_ptr->riding && with_steed)
2153 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2154 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2156 if (MON_CONFUSED(m_ptr))
2158 /* Standard confusion */
2159 if (randint0(100) < 75)
2161 /* Random direction */
2162 dir = ddd[randint0(8)];
2165 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2167 /* Random direction */
2168 dir = ddd[randint0(8)];
2170 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2172 /* Random direction */
2173 dir = ddd[randint0(8)];
2177 /* Notice confusion */
2178 if (command_dir != dir)
2180 if (p_ptr->confused)
2183 msg_print(_("あなたは混乱している。", "You are confused."));
2187 GAME_TEXT m_name[MAX_NLEN];
2188 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2190 monster_desc(m_name, m_ptr, 0);
2191 if (MON_CONFUSED(m_ptr))
2193 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2197 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2202 /* Save direction */
2205 /* repeat_push(dir); */
2206 repeat_push((COMMAND_CODE)command_dir);
2213 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
2214 * and place it into "command_dir", unless we already have one.
2216 * This function should be used for all "repeatable" commands, such as
2217 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
2218 * as all commands which must reference a grid adjacent to the player,
2219 * and which may not reference the grid under the player. Note that,
2220 * for example, it is no longer possible to "disarm" or "open" chests
2221 * in the same grid as the player.
2223 * Direction "5" is illegal and will (cleanly) abort the command.
2225 * This function tracks and uses the "global direction", and uses
2226 * that as the "desired direction", to which "confusion" is applied.
2228 bool get_rep_dir(DIRECTION *dp, bool under)
2236 /* Global direction */
2239 if (repeat_pull(&code))
2241 dir = (DIRECTION)code;
2242 /* return (TRUE); */
2244 *dp = (DIRECTION)code;
2248 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2252 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2255 /* Get a direction */
2260 /* Get a command (or Cancel) */
2261 if (!get_com(prompt, &ch, TRUE)) break;
2264 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2270 /* Look up the direction */
2271 dir = get_keymap_dir(ch);
2277 /* Prevent weirdness */
2278 if ((dir == 5) && (!under)) dir = 0;
2281 if (!dir) return (FALSE);
2283 /* Save desired direction */
2286 /* Apply "confusion" */
2287 if (p_ptr->confused)
2289 /* Standard confusion */
2290 if (randint0(100) < 75)
2292 /* Random direction */
2293 dir = ddd[randint0(8)];
2296 else if (p_ptr->riding)
2298 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2299 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2301 if (MON_CONFUSED(m_ptr))
2303 /* Standard confusion */
2304 if (randint0(100) < 75)
2306 /* Random direction */
2307 dir = ddd[randint0(8)];
2310 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2312 /* Random direction */
2313 dir = ddd[randint0(8)];
2315 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2317 /* Random direction */
2318 dir = ddd[randint0(8)];
2322 /* Notice confusion */
2323 if (command_dir != dir)
2325 if (p_ptr->confused)
2328 msg_print(_("あなたは混乱している。", "You are confused."));
2332 GAME_TEXT m_name[MAX_NLEN];
2333 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2335 monster_desc(m_name, m_ptr, 0);
2336 if (MON_CONFUSED(m_ptr))
2338 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2342 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2347 /* Save direction */
2350 /* repeat_push(dir); */
2351 repeat_push((COMMAND_CODE)command_dir);
2359 * XAngband: determine if a given location is "interesting"
2360 * based on target_set_accept function.
2362 static bool tgt_pt_accept(POSITION y, POSITION x)
2367 if (!(in_bounds(y, x))) return (FALSE);
2369 /* Player grid is always interesting */
2370 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
2372 /* Handle hallucination */
2373 if (p_ptr->image) return (FALSE);
2375 /* Examine the grid */
2376 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2378 /* Interesting memorized features */
2379 if (g_ptr->info & (CAVE_MARK))
2382 if (cave_have_flag_grid(g_ptr, FF_LESS)) return (TRUE);
2383 if (cave_have_flag_grid(g_ptr, FF_MORE)) return (TRUE);
2385 /* Notice quest features */
2386 if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return (TRUE);
2387 if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return (TRUE);
2395 * XAngband: Prepare the "temp" array for "tget_pt"
2396 * based on target_set_prepare funciton.
2398 static void tgt_pt_prepare(void)
2402 /* Reset "temp" array */
2405 if (!expand_list) return;
2407 /* Scan the current panel */
2408 for (y = 1; y < current_floor_ptr->height; y++)
2410 for (x = 1; x < current_floor_ptr->width; x++)
2412 /* Require "interesting" contents */
2413 if (!tgt_pt_accept(y, x)) continue;
2415 /* Save the location */
2416 tmp_pos.x[tmp_pos.n] = x;
2417 tmp_pos.y[tmp_pos.n] = y;
2422 /* Target the nearest monster for shooting */
2423 ang_sort_comp = ang_sort_comp_distance;
2424 ang_sort_swap = ang_sort_swap_distance;
2426 /* Sort the positions */
2427 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n);
2431 * old -- from PsiAngband.
2433 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
2438 bool success = FALSE;
2442 get_screen_size(&wid, &hgt);
2452 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2453 msg_flag = FALSE; /* prevents "-more-" message. */
2455 while ((ch != ESCAPE) && !success)
2457 bool move_fast = FALSE;
2459 move_cursor_relative(y, x);
2471 if (player_bold(y, x)) ch = 0;
2474 else success = TRUE;
2478 /* XAngband: Move cursor to stairs */
2481 if (expand_list && tmp_pos.n)
2484 int cx = (panel_col_min + panel_col_max) / 2;
2485 int cy = (panel_row_min + panel_row_max) / 2;
2489 /* Skip stairs which have defferent distance */
2490 for (; n < tmp_pos.n; ++ n)
2492 grid_type *g_ptr = ¤t_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
2494 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2495 cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2502 if (n == tmp_pos.n) /* Loop out taget list */
2507 verify_panel(); /* Move cursor to player */
2509 p_ptr->update |= (PU_MONSTERS);
2511 p_ptr->redraw |= (PR_MAP);
2513 p_ptr->window |= (PW_OVERHEAD);
2516 else /* move cursor to next stair and change panel */
2521 dy = 2 * (y - cy) / hgt;
2522 dx = 2 * (x - cx) / wid;
2523 if (dy || dx) change_panel(dy, dx);
2529 /* Look up the direction */
2530 d = get_keymap_dir(ch);
2532 /* XTRA HACK MOVEFAST */
2533 if (isupper(ch)) move_fast = TRUE;
2535 /* Handle "direction" */
2541 /* XTRA HACK MOVEFAST */
2544 int mag = MIN(wid / 2, hgt / 2);
2554 /* Do not move horizontally if unnecessary */
2555 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2556 ((x > panel_col_min + wid / 2) && (dx < 0)))
2561 /* Do not move vertically if unnecessary */
2562 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2563 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2568 /* Apply the motion */
2569 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2570 (x >= panel_col_min + wid) || (x < panel_col_min))
2572 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2573 change_panel(dy, dx);
2576 /* Slide into legality */
2577 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
2578 else if (x <= 0) x = 1;
2580 /* Slide into legality */
2581 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
2582 else if (y <= 0) y = 1;
2589 /* Clear the top line */
2592 /* Recenter the map around the player */
2595 p_ptr->update |= (PU_MONSTERS);
2597 p_ptr->redraw |= (PR_MAP);
2599 p_ptr->window |= (PW_OVERHEAD);
2608 bool get_hack_dir(DIRECTION *dp)
2616 /* Global direction */
2619 /* (No auto-targeting) */
2621 /* Ask until satisfied */
2624 /* Choose a prompt */
2627 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2631 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2634 /* Get a command (or Cancel) */
2635 if (!get_com(p, &command, TRUE)) break;
2639 if (command == '\r') command = 't';
2642 /* Convert various keys to "standard" keys */
2645 /* Use current target */
2656 /* Set new target */
2661 if (target_set(TARGET_KILL)) dir = 5;
2667 /* Look up the direction */
2668 dir = get_keymap_dir(command);
2674 /* Verify requested targets */
2675 if ((dir == 5) && !target_okay()) dir = 0;
2682 if (!dir) return (FALSE);
2684 /* Save the direction */
2687 /* Check for confusion */
2688 if (p_ptr->confused)
2690 /* Random direction */
2691 dir = ddd[randint0(8)];
2694 /* Notice confusion */
2695 if (command_dir != dir)
2698 msg_print(_("あなたは混乱している。", "You are confused."));
2701 /* Save direction */
2704 /* A "valid" direction was entered */