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 < temp_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];
762 /* Acquire next object */
763 next_o_idx = o_ptr->next_o_idx;
765 /* Memorized object */
766 if (o_ptr->marked & OM_FOUND) return (TRUE);
769 /* Interesting memorized features */
770 if (g_ptr->info & (CAVE_MARK))
772 /* Notice object features */
773 if (g_ptr->info & CAVE_OBJECT) return (TRUE);
775 /* Feature code (applying "mimic" field) */
776 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE)) return TRUE;
784 * Prepare the "temp" array for "target_set"
786 * Return the number of target_able monsters in the set.
788 static void target_set_prepare(BIT_FLAGS mode)
791 POSITION min_hgt, max_hgt, min_wid, max_wid;
793 if (mode & TARGET_KILL)
796 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
797 max_hgt = MIN((p_ptr->y + MAX_RANGE), current_floor_ptr->height - 1);
798 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
799 max_wid = MIN((p_ptr->x + MAX_RANGE), current_floor_ptr->width - 1);
801 else /* not targetting */
804 min_hgt = panel_row_min;
805 max_hgt = panel_row_max;
806 min_wid = panel_col_min;
807 max_wid = panel_col_max;
810 /* Reset "temp" array */
813 /* Scan the current panel */
814 for (y = min_hgt; y <= max_hgt; y++)
816 for (x = min_wid; x <= max_wid; x++)
820 /* Require "interesting" contents */
821 if (!target_set_accept(y, x)) continue;
823 g_ptr = ¤t_floor_ptr->grid_array[y][x];
825 /* Require target_able monsters for "TARGET_KILL" */
826 if ((mode & (TARGET_KILL)) && !target_able(g_ptr->m_idx)) continue;
828 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(¤t_floor_ptr->m_list[g_ptr->m_idx])) continue;
830 /* Save the location */
837 /* Set the sort hooks */
838 if (mode & (TARGET_KILL))
840 /* Target the nearest monster for shooting */
841 ang_sort_comp = ang_sort_comp_distance;
842 ang_sort_swap = ang_sort_swap_distance;
846 /* Look important grids first in Look command */
847 ang_sort_comp = ang_sort_comp_importance;
848 ang_sort_swap = ang_sort_swap_distance;
851 /* Sort the positions */
852 ang_sort(temp_x, temp_y, temp_n);
854 if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
859 temp_y[0] = temp_y[1];
862 temp_x[0] = temp_x[1];
867 void target_set_prepare_look(void){
868 target_set_prepare(TARGET_LOOK);
873 * Evaluate number of kill needed to gain level
875 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
877 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
879 s32b exp_mon, exp_adv;
880 u32b exp_mon_frac, exp_adv_frac;
882 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
887 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
897 /* The monster's experience point (assuming average monster speed) */
898 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
900 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
903 /* Total experience value for next level */
904 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
906 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
908 /* Experience value need to get */
909 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
912 /* You need to kill at least one monster to get any experience */
913 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
914 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
916 /* Extract number of monsters needed */
917 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
919 /* If 999 or more monsters needed, only display "999". */
920 num = MIN(999, exp_adv_frac);
922 /* Display the number */
923 sprintf(buf,"%03ld", (long int)num);
927 bool show_gold_on_floor = FALSE;
930 * Examine a grid, return a keypress.
932 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
933 * indicates that the "space" key should scan through the contents
934 * of the grid, instead of simply returning immediately. This lets
935 * the "look" command get complete information, without making the
936 * "target" command annoying.
938 * The "info" argument contains the "commands" which should be shown
939 * inside the "[xxx]" text. This string must never be empty, or grids
940 * containing monsters will be displayed with an extra comma.
942 * Note that if a monster is in the grid, we update both the monster
943 * recall info and the health bar info to track that monster.
945 * Eventually, we may allow multiple objects per grid, or objects
946 * and terrain features in the same grid.
948 * This function must handle blindness/hallucination.
950 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
952 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
953 OBJECT_IDX this_o_idx, next_o_idx = 0;
954 concptr s1 = "", s2 = "", s3 = "", x_info = "";
959 char out_val[MAX_NLEN+80];
960 OBJECT_IDX floor_list[23];
961 ITEM_NUMBER floor_num = 0;
963 /* Scan all objects in the grid */
966 floor_num = scan_floor(floor_list, y, x, 0x02);
970 x_info = _("x物 ", "x,");
974 /* Hack -- under the player */
975 if (player_bold(y, x))
988 s1 = _("ターゲット:", "Target:");
991 /* Hack -- hallucination */
994 concptr name = _("何か奇妙な物", "something strange");
996 /* Display a message */
998 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
1000 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1004 move_cursor_relative(y, x);
1007 /* Stop on everything but "return" */
1008 if ((query != '\r') && (query != '\n')) return query;
1010 /* Repeat forever */
1015 /* Actual monsters */
1016 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
1018 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
1019 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1020 GAME_TEXT m_name[MAX_NLEN];
1021 bool recall = FALSE;
1026 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1027 monster_race_track(m_ptr->ap_r_idx);
1028 health_track(g_ptr->m_idx);
1041 /* Recall on screen */
1042 screen_roff(m_ptr->ap_r_idx, 0);
1044 /* Hack -- Complete the prompt (again) */
1045 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
1052 /* Normal commands */
1053 if (query != 'r') break;
1058 /* Cleare recall text and repeat */
1064 /* Describe, and prompt for recall */
1065 evaluate_monster_exp(acount, m_ptr);
1068 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);
1070 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);
1076 move_cursor_relative(y, x);
1081 /* Normal commands */
1082 if (query != 'r') break;
1088 /* Always stop at "normal" keys */
1089 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1091 /* Sometimes stop at "space" key */
1092 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1094 /* Change the intro */
1095 s1 = _("それは", "It is ");
1097 /* Hack -- take account of gender */
1098 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
1099 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
1101 /* Use a preposition */
1110 /* Scan all objects being carried */
1111 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
1113 GAME_TEXT o_name[MAX_NLEN];
1116 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1118 /* Acquire next object */
1119 next_o_idx = o_ptr->next_o_idx;
1121 /* Obtain an object description */
1122 object_desc(o_name, o_ptr, 0);
1125 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1127 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1131 move_cursor_relative(y, x);
1134 /* Always stop at "normal" keys */
1135 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1137 /* Sometimes stop at "space" key */
1138 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1140 /* Change the intro */
1141 s2 = _("をまた", "also carrying ");
1144 /* Use a preposition */
1161 GAME_TEXT o_name[MAX_NLEN];
1164 o_ptr = ¤t_floor_ptr->o_list[floor_list[0]];
1166 object_desc(o_name, o_ptr, 0);
1169 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1171 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1175 move_cursor_relative(y, x);
1184 /* Provide one cushion before item listing */
1187 /* Display rough information about items */
1189 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
1191 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
1195 move_cursor_relative(y, x);
1200 /* No request for listing */
1201 if (query != 'x' && query != ' ') return query;
1205 /** Display list of items **/
1207 /* Continue scrolling list if requested */
1215 show_gold_on_floor = TRUE;
1216 (void)show_floor(0, y, x, &min_width);
1217 show_gold_on_floor = FALSE;
1221 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
1223 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
1230 /* Exit unless 'Enter' */
1231 if (query != '\n' && query != '\r')
1236 /* Get the object being moved. */
1237 o_idx = g_ptr->o_idx;
1239 /* Only rotate a pile of two or more objects. */
1240 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
1242 /* Remove the first object from the list. */
1243 excise_object_idx(o_idx);
1245 /* Find end of the list. */
1247 while (current_floor_ptr->o_list[i].next_o_idx)
1248 i = current_floor_ptr->o_list[i].next_o_idx;
1250 /* Add after the last object. */
1251 current_floor_ptr->o_list[i].next_o_idx = o_idx;
1253 /* Loop and re-display the list */
1260 /* Scan all objects in the grid */
1261 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1264 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1266 /* Acquire next object */
1267 next_o_idx = o_ptr->next_o_idx;
1269 if (o_ptr->marked & OM_FOUND)
1271 GAME_TEXT o_name[MAX_NLEN];
1276 /* Obtain an object description */
1277 object_desc(o_name, o_ptr, 0);
1280 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1282 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1286 move_cursor_relative(y, x);
1289 /* Always stop at "normal" keys */
1290 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1292 /* Sometimes stop at "space" key */
1293 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
1295 /* Change the intro */
1296 s1 = _("それは", "It is ");
1299 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
1313 /* Feature code (applying "mimic" field) */
1314 feat = get_feat_mimic(g_ptr);
1316 /* Require knowledge about grid, or ability to see grid */
1317 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
1319 /* Forget feature */
1323 f_ptr = &f_info[feat];
1325 /* Terrain feature if needed */
1326 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
1330 /* Hack -- special handling for quest entrances */
1331 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
1333 /* Set the quest number temporary */
1334 IDX old_quest = p_ptr->inside_quest;
1337 /* Clear the text */
1338 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
1339 quest_text_line = 0;
1341 p_ptr->inside_quest = g_ptr->special;
1343 /* Get the quest text */
1344 init_flags = INIT_NAME_ONLY;
1346 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
1348 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
1349 quest[g_ptr->special].name, quest[g_ptr->special].level);
1351 /* Reset the old quest number */
1352 p_ptr->inside_quest = old_quest;
1355 /* Hack -- special handling for building doors */
1356 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
1358 name = building[f_ptr->subtype].name;
1360 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
1362 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
1364 else if (have_flag(f_ptr->flags, FF_TOWN))
1366 name = town_info[g_ptr->special].name;
1368 else if (p_ptr->wild_mode && (feat == feat_floor))
1370 name = _("道", "road");
1374 name = f_name + f_ptr->name;
1380 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
1381 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
1382 have_flag(f_ptr->flags, FF_TOWN)))
1384 s2 = _("の中", "in ");
1387 /* Hack -- special introduction for store & building doors -KMW- */
1388 if (have_flag(f_ptr->flags, FF_STORE) ||
1389 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
1390 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
1391 have_flag(f_ptr->flags, FF_ENTRANCE))
1396 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
1397 have_flag(f_ptr->flags, FF_TOWN) ||
1398 have_flag(f_ptr->flags, FF_SHALLOW) ||
1399 have_flag(f_ptr->flags, FF_DEEP))
1405 /* Pick proper indefinite article */
1406 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
1410 /* Display a message */
1414 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
1415 else sprintf(f_idx_str, "%d", g_ptr->feat);
1417 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]);
1419 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);
1424 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
1426 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1430 move_cursor_relative(y, x);
1433 /* Always stop at "normal" keys */
1434 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
1437 /* Stop on everything but "return" */
1438 if ((query != '\r') && (query != '\n')) return query;
1440 /* Repeat forever */
1446 * Handle "target" and "look".
1448 * Note that this code can be called from "get_aim_dir()".
1450 * All locations must be on the current panel. Consider the use of
1451 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1452 * some form of "scrolling" the map around the cursor.
1453 * That is, consider the possibility of "auto-scrolling" the screen
1454 * while the cursor moves around. This may require changes in the
1455 * "update_monster()" code to allow "visibility" even if off panel, and
1456 * may require dynamic recalculation of the "temp" grid set.
1458 * Hack -- targeting/observing an "outer border grid" may induce
1459 * problems, so this is not currently allowed.
1461 * The player can use the direction keys to move among "interesting"
1462 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1463 * move through the "interesting" grids in a sequential manner, or
1464 * can enter "location" mode, and use the direction keys to move one
1465 * grid at a time in any direction. The "t" (set target) command will
1466 * only target a monster (as opposed to a location) if the monster is
1467 * target_able and the "interesting" mode is being used.
1469 * The current grid is described using the "look" method above, and
1470 * a new command may be entered at any time, but note that if the
1471 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1472 * where "space" has no obvious meaning) then "space" will scan
1473 * through the description of the current grid until done, instead
1474 * of immediately jumping to the next "interesting" grid. This
1475 * allows the "target" command to retain its old semantics.
1477 * The "*", "+", and "-" keys may always be used to jump immediately
1478 * to the next (or previous) interesting grid, in the proper mode.
1480 * The "return" key may always be used to scan through a complete
1481 * grid description (forever).
1483 * This command will cancel any old target, even if used from
1484 * inside the "look" command.
1486 bool target_set(BIT_FLAGS mode)
1489 POSITION y = p_ptr->y;
1490 POSITION x = p_ptr->x;
1500 get_screen_size(&wid, &hgt);
1505 if (rogue_like_commands)
1514 /* Prepare the "temp" array */
1515 target_set_prepare(mode);
1517 /* Start near the player */
1523 /* Interesting grids */
1530 change_panel_xy(y, x);
1532 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1535 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1538 if (target_able(g_ptr->m_idx))
1540 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1543 /* Dis-allow target */
1546 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1552 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1553 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1554 strcat(info, cheatinfo);
1557 /* Describe and Prompt */
1559 query = target_set_aux(y, x, mode, info);
1563 /* Assume no "direction" */
1568 if (query == '\r') query = 't';
1586 if (target_able(g_ptr->m_idx))
1588 health_track(g_ptr->m_idx);
1589 target_who = g_ptr->m_idx;
1608 if (!expand_list) done = TRUE;
1618 if (!expand_list) done = TRUE;
1625 /* Recenter the map around the player */
1627 p_ptr->update |= (PU_MONSTERS);
1628 p_ptr->redraw |= (PR_MAP);
1629 p_ptr->window |= (PW_OVERHEAD);
1632 /* Recalculate interesting grids */
1633 target_set_prepare(mode);
1652 if(query == same_key)
1657 if (!expand_list) done = TRUE;
1662 /* Extract the action (if any) */
1663 d = get_keymap_dir(query);
1670 /* Hack -- move around */
1673 /* Modified to scroll to monster */
1674 POSITION y2 = panel_row_min;
1675 POSITION x2 = panel_col_min;
1677 /* Find a new monster */
1678 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
1680 /* Request to target past last interesting grid */
1681 while (flag && (i < 0))
1683 /* Note the change */
1684 if (change_panel(ddy[d], ddx[d]))
1689 /* Recalculate interesting grids */
1690 target_set_prepare(mode);
1692 /* Look at interesting grids */
1695 /* Find a new monster */
1696 i = target_pick(v, u, ddy[d], ddx[d]);
1702 /* Nothing interesting */
1705 POSITION dx = ddx[d];
1706 POSITION dy = ddy[d];
1708 /* Restore previous position */
1711 panel_bounds_center();
1713 p_ptr->update |= (PU_MONSTERS);
1714 p_ptr->redraw |= (PR_MAP);
1715 p_ptr->window |= (PW_OVERHEAD);
1718 /* Recalculate interesting grids */
1719 target_set_prepare(mode);
1721 /* Look at boring grids */
1728 /* Do not move horizontally if unnecessary */
1729 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1730 ((x > panel_col_min + wid / 2) && (dx < 0)))
1735 /* Do not move vertically if unnecessary */
1736 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1737 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1742 /* Apply the motion */
1743 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1744 (x >= panel_col_min+wid) || (x < panel_col_min))
1746 if (change_panel(dy, dx)) target_set_prepare(mode);
1749 /* Slide into legality */
1750 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1751 else if (x <= 0) x = 1;
1753 /* Slide into legality */
1754 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1755 else if (y <= 0) y = 1;
1764 /* Arbitrary grids */
1767 bool move_fast = FALSE;
1769 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1772 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1774 /* Default prompt */
1775 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1780 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1781 los(p_ptr->y, p_ptr->x, y, x),
1782 projectable(p_ptr->y, p_ptr->x, y, x));
1783 strcat(info, cheatinfo);
1786 /* Describe and Prompt (enable "TARGET_LOOK") */
1787 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1789 /* Assume no direction */
1794 if (query == '\r') query = 't';
1797 /* Analyze the keypress */
1821 /* Recenter the map around the player */
1823 p_ptr->update |= (PU_MONSTERS);
1824 p_ptr->redraw |= (PR_MAP);
1825 p_ptr->window |= (PW_OVERHEAD);
1828 /* Recalculate interesting grids */
1829 target_set_prepare(mode);
1851 /* Pick a nearby monster */
1852 for (i = 0; i < temp_n; i++)
1854 t = distance(y, x, temp_y[i], temp_x[i]);
1864 /* Nothing interesting */
1865 if (bd == 999) flag = FALSE;
1872 /* Extract the action (if any) */
1873 d = get_keymap_dir(query);
1875 /* XTRA HACK MOVEFAST */
1876 if (isupper(query)) move_fast = TRUE;
1883 /* Handle "direction" */
1886 POSITION dx = ddx[d];
1887 POSITION dy = ddy[d];
1889 /* XTRA HACK MOVEFAST */
1892 int mag = MIN(wid / 2, hgt / 2);
1902 /* Do not move horizontally if unnecessary */
1903 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1904 ((x > panel_col_min + wid / 2) && (dx < 0)))
1909 /* Do not move vertically if unnecessary */
1910 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1911 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1916 /* Apply the motion */
1917 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1918 (x >= panel_col_min + wid) || (x < panel_col_min))
1920 if (change_panel(dy, dx)) target_set_prepare(mode);
1923 /* Slide into legality */
1924 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1925 else if (x <= 0) x = 1;
1927 /* Slide into legality */
1928 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1929 else if (y <= 0) y = 1;
1937 /* Clear the top line */
1940 /* Recenter the map around the player */
1942 p_ptr->update |= (PU_MONSTERS);
1943 p_ptr->redraw |= (PR_MAP);
1944 p_ptr->window |= (PW_OVERHEAD);
1947 /* Failure to set target */
1948 if (!target_who) return (FALSE);
1956 * Get an "aiming direction" from the user.
1958 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1959 * "0" for "current target", and "-1" for "entry aborted".
1961 * Note that "Force Target", if set, will pre-empt user interaction,
1962 * if there is a usable target already set.
1964 * Note that confusion over-rides any (explicit?) user choice.
1966 bool get_aim_dir(DIRECTION *dp)
1975 /* Global direction */
1978 /* Hack -- auto-target if requested */
1979 if (use_old_target && target_okay()) dir = 5;
1981 if (repeat_pull(&code))
1986 if (!(code == 5 && !target_okay()))
1988 /* return (TRUE); */
1989 dir = (DIRECTION)code;
1992 *dp = (DIRECTION)code;
1994 /* Ask until satisfied */
1997 /* Choose a prompt */
2000 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2004 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2007 /* Get a command (or Cancel) */
2008 if (!get_com(p, &command, TRUE)) break;
2012 if (command == '\r') command = 't';
2015 /* Convert various keys to "standard" keys */
2018 /* Use current target */
2029 /* Set new target */
2034 if (target_set(TARGET_KILL)) dir = 5;
2040 /* Extract the action (if any) */
2041 dir = get_keymap_dir(command);
2047 /* Verify requested targets */
2048 if ((dir == 5) && !target_okay()) dir = 0;
2057 project_length = 0; /* reset to default */
2061 /* Save the direction */
2064 /* Check for confusion */
2065 if (p_ptr->confused)
2067 /* Random direction */
2068 dir = ddd[randint0(8)];
2071 /* Notice confusion */
2072 if (command_dir != dir)
2075 msg_print(_("あなたは混乱している。", "You are confused."));
2078 /* Save direction */
2081 /* repeat_push(dir); */
2082 repeat_push((COMMAND_CODE)command_dir);
2084 /* A "valid" direction was entered */
2089 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
2097 /* Global direction */
2100 if (repeat_pull(&code))
2102 dir = (DIRECTION)code;
2103 /* return (TRUE); */
2105 *dp = (DIRECTION)code;
2109 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2113 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2116 /* Get a direction */
2121 /* Get a command (or Cancel) */
2122 if (!get_com(prompt, &ch, TRUE)) break;
2125 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2131 /* Look up the direction */
2132 dir = get_keymap_dir(ch);
2138 /* Prevent weirdness */
2139 if ((dir == 5) && (!allow_under)) dir = 0;
2142 if (!dir) return (FALSE);
2144 /* Save desired direction */
2147 /* Apply "confusion" */
2148 if (p_ptr->confused)
2150 /* Standard confusion */
2151 if (randint0(100) < 75)
2153 /* Random direction */
2154 dir = ddd[randint0(8)];
2157 else if (p_ptr->riding && with_steed)
2159 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2160 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2162 if (MON_CONFUSED(m_ptr))
2164 /* Standard confusion */
2165 if (randint0(100) < 75)
2167 /* Random direction */
2168 dir = ddd[randint0(8)];
2171 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2173 /* Random direction */
2174 dir = ddd[randint0(8)];
2176 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2178 /* Random direction */
2179 dir = ddd[randint0(8)];
2183 /* Notice confusion */
2184 if (command_dir != dir)
2186 if (p_ptr->confused)
2189 msg_print(_("あなたは混乱している。", "You are confused."));
2193 GAME_TEXT m_name[MAX_NLEN];
2194 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2196 monster_desc(m_name, m_ptr, 0);
2197 if (MON_CONFUSED(m_ptr))
2199 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2203 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2208 /* Save direction */
2211 /* repeat_push(dir); */
2212 repeat_push((COMMAND_CODE)command_dir);
2219 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
2220 * and place it into "command_dir", unless we already have one.
2222 * This function should be used for all "repeatable" commands, such as
2223 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
2224 * as all commands which must reference a grid adjacent to the player,
2225 * and which may not reference the grid under the player. Note that,
2226 * for example, it is no longer possible to "disarm" or "open" chests
2227 * in the same grid as the player.
2229 * Direction "5" is illegal and will (cleanly) abort the command.
2231 * This function tracks and uses the "global direction", and uses
2232 * that as the "desired direction", to which "confusion" is applied.
2234 bool get_rep_dir(DIRECTION *dp, bool under)
2242 /* Global direction */
2245 if (repeat_pull(&code))
2247 dir = (DIRECTION)code;
2248 /* return (TRUE); */
2250 *dp = (DIRECTION)code;
2254 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2258 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2261 /* Get a direction */
2266 /* Get a command (or Cancel) */
2267 if (!get_com(prompt, &ch, TRUE)) break;
2270 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2276 /* Look up the direction */
2277 dir = get_keymap_dir(ch);
2283 /* Prevent weirdness */
2284 if ((dir == 5) && (!under)) dir = 0;
2287 if (!dir) return (FALSE);
2289 /* Save desired direction */
2292 /* Apply "confusion" */
2293 if (p_ptr->confused)
2295 /* Standard confusion */
2296 if (randint0(100) < 75)
2298 /* Random direction */
2299 dir = ddd[randint0(8)];
2302 else if (p_ptr->riding)
2304 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2305 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2307 if (MON_CONFUSED(m_ptr))
2309 /* Standard confusion */
2310 if (randint0(100) < 75)
2312 /* Random direction */
2313 dir = ddd[randint0(8)];
2316 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2318 /* Random direction */
2319 dir = ddd[randint0(8)];
2321 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2323 /* Random direction */
2324 dir = ddd[randint0(8)];
2328 /* Notice confusion */
2329 if (command_dir != dir)
2331 if (p_ptr->confused)
2334 msg_print(_("あなたは混乱している。", "You are confused."));
2338 GAME_TEXT m_name[MAX_NLEN];
2339 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
2341 monster_desc(m_name, m_ptr, 0);
2342 if (MON_CONFUSED(m_ptr))
2344 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2348 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2353 /* Save direction */
2356 /* repeat_push(dir); */
2357 repeat_push((COMMAND_CODE)command_dir);
2365 * XAngband: determine if a given location is "interesting"
2366 * based on target_set_accept function.
2368 static bool tgt_pt_accept(POSITION y, POSITION x)
2373 if (!(in_bounds(y, x))) return (FALSE);
2375 /* Player grid is always interesting */
2376 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
2378 /* Handle hallucination */
2379 if (p_ptr->image) return (FALSE);
2381 /* Examine the grid */
2382 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2384 /* Interesting memorized features */
2385 if (g_ptr->info & (CAVE_MARK))
2388 if (cave_have_flag_grid(g_ptr, FF_LESS)) return (TRUE);
2389 if (cave_have_flag_grid(g_ptr, FF_MORE)) return (TRUE);
2391 /* Notice quest features */
2392 if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return (TRUE);
2393 if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return (TRUE);
2401 * XAngband: Prepare the "temp" array for "tget_pt"
2402 * based on target_set_prepare funciton.
2404 static void tgt_pt_prepare(void)
2408 /* Reset "temp" array */
2411 if (!expand_list) return;
2413 /* Scan the current panel */
2414 for (y = 1; y < current_floor_ptr->height; y++)
2416 for (x = 1; x < current_floor_ptr->width; x++)
2418 /* Require "interesting" contents */
2419 if (!tgt_pt_accept(y, x)) continue;
2421 /* Save the location */
2428 /* Target the nearest monster for shooting */
2429 ang_sort_comp = ang_sort_comp_distance;
2430 ang_sort_swap = ang_sort_swap_distance;
2432 /* Sort the positions */
2433 ang_sort(temp_x, temp_y, temp_n);
2437 * old -- from PsiAngband.
2439 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
2444 bool success = FALSE;
2448 get_screen_size(&wid, &hgt);
2458 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2459 msg_flag = FALSE; /* prevents "-more-" message. */
2461 while ((ch != ESCAPE) && !success)
2463 bool move_fast = FALSE;
2465 move_cursor_relative(y, x);
2477 if (player_bold(y, x)) ch = 0;
2480 else success = TRUE;
2484 /* XAngband: Move cursor to stairs */
2487 if (expand_list && temp_n)
2490 int cx = (panel_col_min + panel_col_max) / 2;
2491 int cy = (panel_row_min + panel_row_max) / 2;
2495 /* Skip stairs which have defferent distance */
2496 for (; n < temp_n; ++ n)
2498 grid_type *g_ptr = ¤t_floor_ptr->grid_array[temp_y[n]][temp_x[n]];
2500 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2501 cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2508 if (n == temp_n) /* Loop out taget list */
2513 verify_panel(); /* Move cursor to player */
2515 p_ptr->update |= (PU_MONSTERS);
2517 p_ptr->redraw |= (PR_MAP);
2519 p_ptr->window |= (PW_OVERHEAD);
2522 else /* move cursor to next stair and change panel */
2527 dy = 2 * (y - cy) / hgt;
2528 dx = 2 * (x - cx) / wid;
2529 if (dy || dx) change_panel(dy, dx);
2535 /* Look up the direction */
2536 d = get_keymap_dir(ch);
2538 /* XTRA HACK MOVEFAST */
2539 if (isupper(ch)) move_fast = TRUE;
2541 /* Handle "direction" */
2547 /* XTRA HACK MOVEFAST */
2550 int mag = MIN(wid / 2, hgt / 2);
2560 /* Do not move horizontally if unnecessary */
2561 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2562 ((x > panel_col_min + wid / 2) && (dx < 0)))
2567 /* Do not move vertically if unnecessary */
2568 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2569 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2574 /* Apply the motion */
2575 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2576 (x >= panel_col_min + wid) || (x < panel_col_min))
2578 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2579 change_panel(dy, dx);
2582 /* Slide into legality */
2583 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
2584 else if (x <= 0) x = 1;
2586 /* Slide into legality */
2587 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
2588 else if (y <= 0) y = 1;
2595 /* Clear the top line */
2598 /* Recenter the map around the player */
2601 p_ptr->update |= (PU_MONSTERS);
2603 p_ptr->redraw |= (PR_MAP);
2605 p_ptr->window |= (PW_OVERHEAD);
2614 bool get_hack_dir(DIRECTION *dp)
2622 /* Global direction */
2625 /* (No auto-targeting) */
2627 /* Ask until satisfied */
2630 /* Choose a prompt */
2633 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2637 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2640 /* Get a command (or Cancel) */
2641 if (!get_com(p, &command, TRUE)) break;
2645 if (command == '\r') command = 't';
2648 /* Convert various keys to "standard" keys */
2651 /* Use current target */
2662 /* Set new target */
2667 if (target_set(TARGET_KILL)) dir = 5;
2673 /* Look up the direction */
2674 dir = get_keymap_dir(command);
2680 /* Verify requested targets */
2681 if ((dir == 5) && !target_okay()) dir = 0;
2688 if (!dir) return (FALSE);
2690 /* Save the direction */
2693 /* Check for confusion */
2694 if (p_ptr->confused)
2696 /* Random direction */
2697 dir = ddd[randint0(8)];
2700 /* Notice confusion */
2701 if (command_dir != dir)
2704 msg_print(_("あなたは混乱している。", "You are confused."));
2707 /* Save direction */
2710 /* A "valid" direction was entered */