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 "spells-summon.h"
22 #include "floor-events.h"
23 #include "player-move.h"
24 #include "monster-status.h"
27 * @brief コンソール上におけるマップ表示の左上位置を返す /
28 * Calculates current boundaries Called below and from "do_cmd_locate()".
31 void panel_bounds_center(void)
35 get_screen_size(&wid, &hgt);
37 panel_row_max = panel_row_min + hgt - 1;
38 panel_row_prt = panel_row_min - 1;
39 panel_col_max = panel_col_min + wid - 1;
40 panel_col_prt = panel_col_min - 13;
44 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
48 * Handle a request to change the current panel
49 * Return TRUE if the panel was changed.
50 * Also used in do_cmd_locate
51 * @return 実際に再描画が必要だった場合TRUEを返す
53 static bool change_panel_xy(POSITION y, POSITION x)
55 POSITION dy = 0, dx = 0;
58 get_screen_size(&wid, &hgt);
60 if (y < panel_row_min) dy = -1;
61 if (y > panel_row_max) dy = 1;
62 if (x < panel_col_min) dx = -1;
63 if (x > panel_col_max) dx = 1;
65 if (!dy && !dx) return (FALSE);
67 return change_panel(dy, dx);
72 * @brief マップ描画のフォーカスを当てるべき座標を更新する
74 * Given an row (y) and col (x), this routine detects when a move
75 * off the screen has occurred and figures new borders. -RAK-
76 * "Update" forces a "full update" to take place.
77 * The map is reprinted if necessary, and "TRUE" is returned.
78 * @return 実際に再描画が必要だった場合TRUEを返す
80 void verify_panel(void)
82 POSITION y = p_ptr->y;
83 POSITION x = p_ptr->x;
91 get_screen_size(&wid, &hgt);
93 max_prow_min = current_floor_ptr->height - hgt;
94 max_pcol_min = current_floor_ptr->width - wid;
97 if (max_prow_min < 0) max_prow_min = 0;
98 if (max_pcol_min < 0) max_pcol_min = 0;
100 /* Center on player */
101 if (center_player && (center_running || !running))
103 /* Center vertically */
104 prow_min = y - hgt / 2;
105 if (prow_min < 0) prow_min = 0;
106 else if (prow_min > max_prow_min) prow_min = max_prow_min;
108 /* Center horizontally */
109 pcol_min = x - wid / 2;
110 if (pcol_min < 0) pcol_min = 0;
111 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
115 prow_min = panel_row_min;
116 pcol_min = panel_col_min;
118 /* Scroll screen when 2 grids from top/bottom edge */
119 if (y > panel_row_max - 2)
121 while (y > prow_min + hgt-1 - 2)
123 prow_min += (hgt / 2);
127 if (y < panel_row_min + 2)
129 while (y < prow_min + 2)
131 prow_min -= (hgt / 2);
135 if (prow_min > max_prow_min) prow_min = max_prow_min;
136 if (prow_min < 0) prow_min = 0;
138 /* Scroll screen when 4 grids from left/right edge */
139 if (x > panel_col_max - 4)
141 while (x > pcol_min + wid-1 - 4)
143 pcol_min += (wid / 2);
147 if (x < panel_col_min + 4)
149 while (x < pcol_min + 4)
151 pcol_min -= (wid / 2);
155 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
156 if (pcol_min < 0) pcol_min = 0;
159 /* Check for "no change" */
160 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
162 /* Save the new panel info */
163 panel_row_min = prow_min;
164 panel_col_min = pcol_min;
166 /* Hack -- optional disturb on "panel change" */
167 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
169 panel_bounds_center();
171 p_ptr->update |= (PU_MONSTERS);
172 p_ptr->redraw |= (PR_MAP);
173 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
177 /*** Targeting Code ***/
180 * Determine is a monster makes a reasonable target
182 * The concept of "targeting" was stolen from "Morgul" (?)
184 * The player can target any location, or any "target-able" monster.
186 * Currently, a monster is "target_able" if it is visible, and if
187 * the player can hit it with a projection, and the player is not
188 * hallucinating. This allows use of "use closest target" macros.
190 * Future versions may restrict the ability to target "trappers"
191 * and "mimics", but the semantics is a little bit weird.
193 bool target_able(MONSTER_IDX m_idx)
195 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
197 /* Monster must be alive */
198 if (!monster_is_valid(m_ptr)) return (FALSE);
200 /* Hack -- no targeting hallucinations */
201 if (p_ptr->image) return (FALSE);
203 /* Monster must be visible */
204 if (!m_ptr->ml) return (FALSE);
206 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
208 /* Monster must be projectable */
209 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
211 /* Hack -- Never target trappers */
212 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
222 * Update (if necessary) and verify (if possible) the target.
224 * We return TRUE if the target is "okay" and FALSE otherwise.
226 bool target_okay(void)
228 /* Accept stationary targets */
229 if (target_who < 0) return (TRUE);
231 /* Check moving targets */
234 /* Accept reasonable targets */
235 if (target_able(target_who))
237 monster_type *m_ptr = ¤t_floor_ptr->m_list[target_who];
239 /* Acquire monster location */
240 target_row = m_ptr->fy;
241 target_col = m_ptr->fx;
248 /* Assume no target */
254 * Hack -- help "select" a location (see below)
256 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
259 POSITION x2, y2, x3, y3, x4, y4;
260 POSITION_IDX b_i = -1, b_v = 9999;
263 /* Scan the locations */
264 for (i = 0; i < tmp_pos.n; i++)
270 /* Directed distance */
274 /* Verify quadrant */
275 if (dx && (x3 * dx <= 0)) continue;
276 if (dy && (y3 * dy <= 0)) continue;
281 /* Verify quadrant */
282 if (dy && !dx && (x4 > y4)) continue;
283 if (dx && !dy && (y4 > x4)) continue;
285 /* Approximate Double Distance */
286 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
288 /* Penalize location */
289 if ((b_i >= 0) && (v >= b_v)) continue;
297 * Hack -- determine if a given location is "interesting"
299 static bool target_set_accept(POSITION y, POSITION x)
302 OBJECT_IDX this_o_idx, next_o_idx = 0;
304 if (!(in_bounds(y, x))) return (FALSE);
306 /* Player grid is always interesting */
307 if (player_bold(y, x)) return (TRUE);
309 if (p_ptr->image) return (FALSE);
311 g_ptr = ¤t_floor_ptr->grid_array[y][x];
313 /* Visible monsters */
316 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
318 /* Visible monsters */
319 if (m_ptr->ml) return (TRUE);
322 /* Scan all objects in the grid */
323 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
326 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
327 next_o_idx = o_ptr->next_o_idx;
329 /* Memorized object */
330 if (o_ptr->marked & OM_FOUND) return (TRUE);
333 /* Interesting memorized features */
334 if (g_ptr->info & (CAVE_MARK))
336 /* Notice object features */
337 if (g_ptr->info & CAVE_OBJECT) return (TRUE);
339 /* Feature code (applying "mimic" field) */
340 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE)) return TRUE;
348 * Prepare the "temp" array for "target_set"
350 * Return the number of target_able monsters in the set.
352 static void target_set_prepare(BIT_FLAGS mode)
355 POSITION min_hgt, max_hgt, min_wid, max_wid;
357 if (mode & TARGET_KILL)
360 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
361 max_hgt = MIN((p_ptr->y + MAX_RANGE), current_floor_ptr->height - 1);
362 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
363 max_wid = MIN((p_ptr->x + MAX_RANGE), current_floor_ptr->width - 1);
365 else /* not targetting */
368 min_hgt = panel_row_min;
369 max_hgt = panel_row_max;
370 min_wid = panel_col_min;
371 max_wid = panel_col_max;
374 /* Reset "temp" array */
377 /* Scan the current panel */
378 for (y = min_hgt; y <= max_hgt; y++)
380 for (x = min_wid; x <= max_wid; x++)
384 /* Require "interesting" contents */
385 if (!target_set_accept(y, x)) continue;
387 g_ptr = ¤t_floor_ptr->grid_array[y][x];
389 /* Require target_able monsters for "TARGET_KILL" */
390 if ((mode & (TARGET_KILL)) && !target_able(g_ptr->m_idx)) continue;
392 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(¤t_floor_ptr->m_list[g_ptr->m_idx])) continue;
394 /* Save the location */
395 tmp_pos.x[tmp_pos.n] = x;
396 tmp_pos.y[tmp_pos.n] = y;
401 /* Set the sort hooks */
402 if (mode & (TARGET_KILL))
404 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
408 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_importance, ang_sort_swap_distance);
411 if (p_ptr->riding && target_pet && (tmp_pos.n > 1) && (mode & (TARGET_KILL)))
416 tmp_pos.y[0] = tmp_pos.y[1];
419 tmp_pos.x[0] = tmp_pos.x[1];
424 void target_set_prepare_look(void){
425 target_set_prepare(TARGET_LOOK);
430 * Evaluate number of kill needed to gain level
432 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
434 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
436 s32b exp_mon, exp_adv;
437 u32b exp_mon_frac, exp_adv_frac;
439 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
444 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
454 /* The monster's experience point (assuming average monster speed) */
455 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
457 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
460 /* Total experience value for next level */
461 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
463 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
465 /* Experience value need to get */
466 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
469 /* You need to kill at least one monster to get any experience */
470 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
471 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
473 /* Extract number of monsters needed */
474 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
476 /* If 999 or more monsters needed, only display "999". */
477 num = MIN(999, exp_adv_frac);
479 /* Display the number */
480 sprintf(buf,"%03ld", (long int)num);
484 bool show_gold_on_floor = FALSE;
487 * Examine a grid, return a keypress.
489 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
490 * indicates that the "space" key should scan through the contents
491 * of the grid, instead of simply returning immediately. This lets
492 * the "look" command get complete information, without making the
493 * "target" command annoying.
495 * The "info" argument contains the "commands" which should be shown
496 * inside the "[xxx]" text. This string must never be empty, or grids
497 * containing monsters will be displayed with an extra comma.
499 * Note that if a monster is in the grid, we update both the monster
500 * recall info and the health bar info to track that monster.
502 * Eventually, we may allow multiple objects per grid, or objects
503 * and terrain features in the same grid.
505 * This function must handle blindness/hallucination.
507 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
509 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
510 OBJECT_IDX this_o_idx, next_o_idx = 0;
511 concptr s1 = "", s2 = "", s3 = "", x_info = "";
516 char out_val[MAX_NLEN+80];
517 OBJECT_IDX floor_list[23];
518 ITEM_NUMBER floor_num = 0;
520 /* Scan all objects in the grid */
523 floor_num = scan_floor(floor_list, y, x, 0x02);
527 x_info = _("x物 ", "x,");
531 /* Hack -- under the player */
532 if (player_bold(y, x))
545 s1 = _("ターゲット:", "Target:");
548 /* Hack -- hallucination */
551 concptr name = _("何か奇妙な物", "something strange");
553 /* Display a message */
555 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
557 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
561 move_cursor_relative(y, x);
564 /* Stop on everything but "return" */
565 if ((query != '\r') && (query != '\n')) return query;
572 /* Actual monsters */
573 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
575 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
576 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
577 GAME_TEXT m_name[MAX_NLEN];
583 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
584 monster_race_track(m_ptr->ap_r_idx);
585 health_track(g_ptr->m_idx);
598 /* Recall on screen */
599 screen_roff(m_ptr->ap_r_idx, 0);
601 /* Hack -- Complete the prompt (again) */
602 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
609 /* Normal commands */
610 if (query != 'r') break;
615 /* Cleare recall text and repeat */
621 /* Describe, and prompt for recall */
622 evaluate_monster_exp(acount, m_ptr);
625 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);
627 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);
633 move_cursor_relative(y, x);
638 /* Normal commands */
639 if (query != 'r') break;
645 /* Always stop at "normal" keys */
646 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
648 /* Sometimes stop at "space" key */
649 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
651 /* Change the intro */
652 s1 = _("それは", "It is ");
654 /* Hack -- take account of gender */
655 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
656 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
658 /* Use a preposition */
667 /* Scan all objects being carried */
668 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
670 GAME_TEXT o_name[MAX_NLEN];
673 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
674 next_o_idx = o_ptr->next_o_idx;
676 /* Obtain an object description */
677 object_desc(o_name, o_ptr, 0);
680 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
682 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
686 move_cursor_relative(y, x);
689 /* Always stop at "normal" keys */
690 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
692 /* Sometimes stop at "space" key */
693 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
695 /* Change the intro */
696 s2 = _("をまた", "also carrying ");
699 /* Use a preposition */
716 GAME_TEXT o_name[MAX_NLEN];
719 o_ptr = ¤t_floor_ptr->o_list[floor_list[0]];
721 object_desc(o_name, o_ptr, 0);
724 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
726 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
730 move_cursor_relative(y, x);
739 /* Provide one cushion before item listing */
742 /* Display rough information about items */
744 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
746 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
750 move_cursor_relative(y, x);
755 /* No request for listing */
756 if (query != 'x' && query != ' ') return query;
760 /** Display list of items **/
762 /* Continue scrolling list if requested */
770 show_gold_on_floor = TRUE;
771 (void)show_floor(0, y, x, &min_width);
772 show_gold_on_floor = FALSE;
776 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
778 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
785 /* Exit unless 'Enter' */
786 if (query != '\n' && query != '\r')
791 /* Get the object being moved. */
792 o_idx = g_ptr->o_idx;
794 /* Only rotate a pile of two or more objects. */
795 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
797 /* Remove the first object from the list. */
798 excise_object_idx(o_idx);
800 /* Find end of the list. */
802 while (current_floor_ptr->o_list[i].next_o_idx)
803 i = current_floor_ptr->o_list[i].next_o_idx;
805 /* Add after the last object. */
806 current_floor_ptr->o_list[i].next_o_idx = o_idx;
808 /* Loop and re-display the list */
815 /* Scan all objects in the grid */
816 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
819 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
820 next_o_idx = o_ptr->next_o_idx;
822 if (o_ptr->marked & OM_FOUND)
824 GAME_TEXT o_name[MAX_NLEN];
829 /* Obtain an object description */
830 object_desc(o_name, o_ptr, 0);
833 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
835 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
839 move_cursor_relative(y, x);
842 /* Always stop at "normal" keys */
843 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
845 /* Sometimes stop at "space" key */
846 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
848 /* Change the intro */
849 s1 = _("それは", "It is ");
852 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
866 /* Feature code (applying "mimic" field) */
867 feat = get_feat_mimic(g_ptr);
869 /* Require knowledge about grid, or ability to see grid */
870 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
876 f_ptr = &f_info[feat];
878 /* Terrain feature if needed */
879 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
883 /* Hack -- special handling for quest entrances */
884 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
886 /* Set the quest number temporary */
887 IDX old_quest = p_ptr->inside_quest;
891 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
894 p_ptr->inside_quest = g_ptr->special;
896 /* Get the quest text */
897 init_flags = INIT_NAME_ONLY;
899 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
901 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
902 quest[g_ptr->special].name, quest[g_ptr->special].level);
904 /* Reset the old quest number */
905 p_ptr->inside_quest = old_quest;
908 /* Hack -- special handling for building doors */
909 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
911 name = building[f_ptr->subtype].name;
913 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
915 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
917 else if (have_flag(f_ptr->flags, FF_TOWN))
919 name = town_info[g_ptr->special].name;
921 else if (p_ptr->wild_mode && (feat == feat_floor))
923 name = _("道", "road");
927 name = f_name + f_ptr->name;
933 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
934 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
935 have_flag(f_ptr->flags, FF_TOWN)))
940 /* Hack -- special introduction for store & building doors -KMW- */
941 if (have_flag(f_ptr->flags, FF_STORE) ||
942 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
943 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
944 have_flag(f_ptr->flags, FF_ENTRANCE))
949 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
950 have_flag(f_ptr->flags, FF_TOWN) ||
951 have_flag(f_ptr->flags, FF_SHALLOW) ||
952 have_flag(f_ptr->flags, FF_DEEP))
958 /* Pick proper indefinite article */
959 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
963 /* Display a message */
967 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
968 else sprintf(f_idx_str, "%d", g_ptr->feat);
970 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]);
972 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);
977 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
979 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
983 move_cursor_relative(y, x);
986 /* Always stop at "normal" keys */
987 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
990 /* Stop on everything but "return" */
991 if ((query != '\r') && (query != '\n')) return query;
999 * Handle "target" and "look".
1001 * Note that this code can be called from "get_aim_dir()".
1003 * All locations must be on the current panel. Consider the use of
1004 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1005 * some form of "scrolling" the map around the cursor.
1006 * That is, consider the possibility of "auto-scrolling" the screen
1007 * while the cursor moves around. This may require changes in the
1008 * "update_monster()" code to allow "visibility" even if off panel, and
1009 * may require dynamic recalculation of the "temp" grid set.
1011 * Hack -- targeting/observing an "outer border grid" may induce
1012 * problems, so this is not currently allowed.
1014 * The player can use the direction keys to move among "interesting"
1015 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1016 * move through the "interesting" grids in a sequential manner, or
1017 * can enter "location" mode, and use the direction keys to move one
1018 * grid at a time in any direction. The "t" (set target) command will
1019 * only target a monster (as opposed to a location) if the monster is
1020 * target_able and the "interesting" mode is being used.
1022 * The current grid is described using the "look" method above, and
1023 * a new command may be entered at any time, but note that if the
1024 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1025 * where "space" has no obvious meaning) then "space" will scan
1026 * through the description of the current grid until done, instead
1027 * of immediately jumping to the next "interesting" grid. This
1028 * allows the "target" command to retain its old semantics.
1030 * The "*", "+", and "-" keys may always be used to jump immediately
1031 * to the next (or previous) interesting grid, in the proper mode.
1033 * The "return" key may always be used to scan through a complete
1034 * grid description (forever).
1036 * This command will cancel any old target, even if used from
1037 * inside the "look" command.
1039 bool target_set(BIT_FLAGS mode)
1042 POSITION y = p_ptr->y;
1043 POSITION x = p_ptr->x;
1053 get_screen_size(&wid, &hgt);
1058 if (rogue_like_commands)
1067 /* Prepare the "temp" array */
1068 target_set_prepare(mode);
1070 /* Start near the player */
1076 /* Interesting grids */
1077 if (flag && tmp_pos.n)
1083 change_panel_xy(y, x);
1085 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1088 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1091 if (target_able(g_ptr->m_idx))
1093 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1096 /* Dis-allow target */
1099 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1105 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1106 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1107 strcat(info, cheatinfo);
1110 /* Describe and Prompt */
1112 query = target_set_aux(y, x, mode, info);
1116 /* Assume no "direction" */
1121 if (query == '\r') query = 't';
1139 if (target_able(g_ptr->m_idx))
1141 health_track(g_ptr->m_idx);
1142 target_who = g_ptr->m_idx;
1158 if (++m == tmp_pos.n)
1161 if (!expand_list) done = TRUE;
1171 if (!expand_list) done = TRUE;
1178 /* Recenter the map around the player */
1180 p_ptr->update |= (PU_MONSTERS);
1181 p_ptr->redraw |= (PR_MAP);
1182 p_ptr->window |= (PW_OVERHEAD);
1185 /* Recalculate interesting grids */
1186 target_set_prepare(mode);
1205 if(query == same_key)
1207 if (++m == tmp_pos.n)
1210 if (!expand_list) done = TRUE;
1215 /* Extract the action (if any) */
1216 d = get_keymap_dir(query);
1223 /* Hack -- move around */
1226 /* Modified to scroll to monster */
1227 POSITION y2 = panel_row_min;
1228 POSITION x2 = panel_col_min;
1230 /* Find a new monster */
1231 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
1233 /* Request to target past last interesting grid */
1234 while (flag && (i < 0))
1236 /* Note the change */
1237 if (change_panel(ddy[d], ddx[d]))
1239 int v = tmp_pos.y[m];
1240 int u = tmp_pos.x[m];
1242 /* Recalculate interesting grids */
1243 target_set_prepare(mode);
1245 /* Look at interesting grids */
1248 /* Find a new monster */
1249 i = target_pick(v, u, ddy[d], ddx[d]);
1255 /* Nothing interesting */
1258 POSITION dx = ddx[d];
1259 POSITION dy = ddy[d];
1261 /* Restore previous position */
1264 panel_bounds_center();
1266 p_ptr->update |= (PU_MONSTERS);
1267 p_ptr->redraw |= (PR_MAP);
1268 p_ptr->window |= (PW_OVERHEAD);
1271 /* Recalculate interesting grids */
1272 target_set_prepare(mode);
1274 /* Look at boring grids */
1281 /* Do not move horizontally if unnecessary */
1282 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1283 ((x > panel_col_min + wid / 2) && (dx < 0)))
1288 /* Do not move vertically if unnecessary */
1289 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1290 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1295 /* Apply the motion */
1296 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1297 (x >= panel_col_min+wid) || (x < panel_col_min))
1299 if (change_panel(dy, dx)) target_set_prepare(mode);
1302 /* Slide into legality */
1303 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1304 else if (x <= 0) x = 1;
1306 /* Slide into legality */
1307 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1308 else if (y <= 0) y = 1;
1317 /* Arbitrary grids */
1320 bool move_fast = FALSE;
1322 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1325 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1327 /* Default prompt */
1328 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1333 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1334 los(p_ptr->y, p_ptr->x, y, x),
1335 projectable(p_ptr->y, p_ptr->x, y, x));
1336 strcat(info, cheatinfo);
1339 /* Describe and Prompt (enable "TARGET_LOOK") */
1340 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1342 /* Assume no direction */
1347 if (query == '\r') query = 't';
1350 /* Analyze the keypress */
1374 /* Recenter the map around the player */
1376 p_ptr->update |= (PU_MONSTERS);
1377 p_ptr->redraw |= (PR_MAP);
1378 p_ptr->window |= (PW_OVERHEAD);
1381 /* Recalculate interesting grids */
1382 target_set_prepare(mode);
1404 /* Pick a nearby monster */
1405 for (i = 0; i < tmp_pos.n; i++)
1407 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1417 /* Nothing interesting */
1418 if (bd == 999) flag = FALSE;
1425 /* Extract the action (if any) */
1426 d = get_keymap_dir(query);
1428 /* XTRA HACK MOVEFAST */
1429 if (isupper(query)) move_fast = TRUE;
1436 /* Handle "direction" */
1439 POSITION dx = ddx[d];
1440 POSITION dy = ddy[d];
1442 /* XTRA HACK MOVEFAST */
1445 int mag = MIN(wid / 2, hgt / 2);
1455 /* Do not move horizontally if unnecessary */
1456 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1457 ((x > panel_col_min + wid / 2) && (dx < 0)))
1462 /* Do not move vertically if unnecessary */
1463 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1464 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1469 /* Apply the motion */
1470 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1471 (x >= panel_col_min + wid) || (x < panel_col_min))
1473 if (change_panel(dy, dx)) target_set_prepare(mode);
1476 /* Slide into legality */
1477 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1478 else if (x <= 0) x = 1;
1480 /* Slide into legality */
1481 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1482 else if (y <= 0) y = 1;
1490 /* Clear the top line */
1493 /* Recenter the map around the player */
1495 p_ptr->update |= (PU_MONSTERS);
1496 p_ptr->redraw |= (PR_MAP);
1497 p_ptr->window |= (PW_OVERHEAD);
1500 /* Failure to set target */
1501 if (!target_who) return (FALSE);
1509 * Get an "aiming direction" from the user.
1511 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1512 * "0" for "current target", and "-1" for "entry aborted".
1514 * Note that "Force Target", if set, will pre-empt user interaction,
1515 * if there is a usable target already set.
1517 * Note that confusion over-rides any (explicit?) user choice.
1519 bool get_aim_dir(DIRECTION *dp)
1528 /* Global direction */
1531 /* Hack -- auto-target if requested */
1532 if (use_old_target && target_okay()) dir = 5;
1534 if (repeat_pull(&code))
1539 if (!(code == 5 && !target_okay()))
1541 /* return (TRUE); */
1542 dir = (DIRECTION)code;
1545 *dp = (DIRECTION)code;
1547 /* Ask until satisfied */
1550 /* Choose a prompt */
1553 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1557 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
1560 /* Get a command (or Cancel) */
1561 if (!get_com(p, &command, TRUE)) break;
1565 if (command == '\r') command = 't';
1568 /* Convert various keys to "standard" keys */
1571 /* Use current target */
1582 /* Set new target */
1587 if (target_set(TARGET_KILL)) dir = 5;
1593 /* Extract the action (if any) */
1594 dir = get_keymap_dir(command);
1600 /* Verify requested targets */
1601 if ((dir == 5) && !target_okay()) dir = 0;
1610 project_length = 0; /* reset to default */
1614 /* Save the direction */
1617 /* Check for confusion */
1618 if (p_ptr->confused)
1620 /* Random direction */
1621 dir = ddd[randint0(8)];
1624 /* Notice confusion */
1625 if (command_dir != dir)
1628 msg_print(_("あなたは混乱している。", "You are confused."));
1631 /* Save direction */
1634 /* repeat_push(dir); */
1635 repeat_push((COMMAND_CODE)command_dir);
1637 /* A "valid" direction was entered */
1642 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
1650 /* Global direction */
1653 if (repeat_pull(&code))
1655 dir = (DIRECTION)code;
1656 /* return (TRUE); */
1658 *dp = (DIRECTION)code;
1662 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1666 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1669 /* Get a direction */
1674 /* Get a command (or Cancel) */
1675 if (!get_com(prompt, &ch, TRUE)) break;
1678 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1684 /* Look up the direction */
1685 dir = get_keymap_dir(ch);
1691 /* Prevent weirdness */
1692 if ((dir == 5) && (!allow_under)) dir = 0;
1695 if (!dir) return (FALSE);
1697 /* Save desired direction */
1700 /* Apply "confusion" */
1701 if (p_ptr->confused)
1703 /* Standard confusion */
1704 if (randint0(100) < 75)
1706 /* Random direction */
1707 dir = ddd[randint0(8)];
1710 else if (p_ptr->riding && with_steed)
1712 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1713 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1715 if (MON_CONFUSED(m_ptr))
1717 /* Standard confusion */
1718 if (randint0(100) < 75)
1720 /* Random direction */
1721 dir = ddd[randint0(8)];
1724 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1726 /* Random direction */
1727 dir = ddd[randint0(8)];
1729 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1731 /* Random direction */
1732 dir = ddd[randint0(8)];
1736 /* Notice confusion */
1737 if (command_dir != dir)
1739 if (p_ptr->confused)
1742 msg_print(_("あなたは混乱している。", "You are confused."));
1746 GAME_TEXT m_name[MAX_NLEN];
1747 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1749 monster_desc(m_name, m_ptr, 0);
1750 if (MON_CONFUSED(m_ptr))
1752 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1756 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1761 /* Save direction */
1764 /* repeat_push(dir); */
1765 repeat_push((COMMAND_CODE)command_dir);
1772 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
1773 * and place it into "command_dir", unless we already have one.
1775 * This function should be used for all "repeatable" commands, such as
1776 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
1777 * as all commands which must reference a grid adjacent to the player,
1778 * and which may not reference the grid under the player. Note that,
1779 * for example, it is no longer possible to "disarm" or "open" chests
1780 * in the same grid as the player.
1782 * Direction "5" is illegal and will (cleanly) abort the command.
1784 * This function tracks and uses the "global direction", and uses
1785 * that as the "desired direction", to which "confusion" is applied.
1787 bool get_rep_dir(DIRECTION *dp, bool under)
1795 /* Global direction */
1798 if (repeat_pull(&code))
1800 dir = (DIRECTION)code;
1801 /* return (TRUE); */
1803 *dp = (DIRECTION)code;
1807 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1811 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1814 /* Get a direction */
1819 /* Get a command (or Cancel) */
1820 if (!get_com(prompt, &ch, TRUE)) break;
1823 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1829 /* Look up the direction */
1830 dir = get_keymap_dir(ch);
1836 /* Prevent weirdness */
1837 if ((dir == 5) && (!under)) dir = 0;
1840 if (!dir) return (FALSE);
1842 /* Save desired direction */
1845 /* Apply "confusion" */
1846 if (p_ptr->confused)
1848 /* Standard confusion */
1849 if (randint0(100) < 75)
1851 /* Random direction */
1852 dir = ddd[randint0(8)];
1855 else if (p_ptr->riding)
1857 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1858 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1860 if (MON_CONFUSED(m_ptr))
1862 /* Standard confusion */
1863 if (randint0(100) < 75)
1865 /* Random direction */
1866 dir = ddd[randint0(8)];
1869 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1871 /* Random direction */
1872 dir = ddd[randint0(8)];
1874 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1876 /* Random direction */
1877 dir = ddd[randint0(8)];
1881 /* Notice confusion */
1882 if (command_dir != dir)
1884 if (p_ptr->confused)
1887 msg_print(_("あなたは混乱している。", "You are confused."));
1891 GAME_TEXT m_name[MAX_NLEN];
1892 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1894 monster_desc(m_name, m_ptr, 0);
1895 if (MON_CONFUSED(m_ptr))
1897 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1901 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1906 /* Save direction */
1909 /* repeat_push(dir); */
1910 repeat_push((COMMAND_CODE)command_dir);
1918 * XAngband: determine if a given location is "interesting"
1919 * based on target_set_accept function.
1921 static bool tgt_pt_accept(POSITION y, POSITION x)
1925 if (!(in_bounds(y, x))) return (FALSE);
1927 /* Player grid is always interesting */
1928 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
1930 if (p_ptr->image) return (FALSE);
1932 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1934 /* Interesting memorized features */
1935 if (g_ptr->info & (CAVE_MARK))
1938 if (cave_have_flag_grid(g_ptr, FF_LESS)) return (TRUE);
1939 if (cave_have_flag_grid(g_ptr, FF_MORE)) return (TRUE);
1941 /* Notice quest features */
1942 if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return (TRUE);
1943 if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return (TRUE);
1951 * XAngband: Prepare the "temp" array for "tget_pt"
1952 * based on target_set_prepare funciton.
1954 static void tgt_pt_prepare(void)
1958 /* Reset "temp" array */
1961 if (!expand_list) return;
1963 /* Scan the current panel */
1964 for (y = 1; y < current_floor_ptr->height; y++)
1966 for (x = 1; x < current_floor_ptr->width; x++)
1968 /* Require "interesting" contents */
1969 if (!tgt_pt_accept(y, x)) continue;
1971 /* Save the location */
1972 tmp_pos.x[tmp_pos.n] = x;
1973 tmp_pos.y[tmp_pos.n] = y;
1978 /* Sort the positions */
1979 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
1983 * old -- from PsiAngband.
1985 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
1990 bool success = FALSE;
1994 get_screen_size(&wid, &hgt);
2004 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2005 msg_flag = FALSE; /* prevents "-more-" message. */
2007 while ((ch != ESCAPE) && !success)
2009 bool move_fast = FALSE;
2011 move_cursor_relative(y, x);
2023 if (player_bold(y, x)) ch = 0;
2026 else success = TRUE;
2030 /* XAngband: Move cursor to stairs */
2033 if (expand_list && tmp_pos.n)
2036 int cx = (panel_col_min + panel_col_max) / 2;
2037 int cy = (panel_row_min + panel_row_max) / 2;
2041 /* Skip stairs which have defferent distance */
2042 for (; n < tmp_pos.n; ++ n)
2044 grid_type *g_ptr = ¤t_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
2046 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2047 cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2054 if (n == tmp_pos.n) /* Loop out taget list */
2059 verify_panel(); /* Move cursor to player */
2061 p_ptr->update |= (PU_MONSTERS);
2063 p_ptr->redraw |= (PR_MAP);
2065 p_ptr->window |= (PW_OVERHEAD);
2068 else /* move cursor to next stair and change panel */
2073 dy = 2 * (y - cy) / hgt;
2074 dx = 2 * (x - cx) / wid;
2075 if (dy || dx) change_panel(dy, dx);
2081 /* Look up the direction */
2082 d = get_keymap_dir(ch);
2084 /* XTRA HACK MOVEFAST */
2085 if (isupper(ch)) move_fast = TRUE;
2087 /* Handle "direction" */
2093 /* XTRA HACK MOVEFAST */
2096 int mag = MIN(wid / 2, hgt / 2);
2106 /* Do not move horizontally if unnecessary */
2107 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2108 ((x > panel_col_min + wid / 2) && (dx < 0)))
2113 /* Do not move vertically if unnecessary */
2114 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2115 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2120 /* Apply the motion */
2121 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2122 (x >= panel_col_min + wid) || (x < panel_col_min))
2124 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2125 change_panel(dy, dx);
2128 /* Slide into legality */
2129 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
2130 else if (x <= 0) x = 1;
2132 /* Slide into legality */
2133 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
2134 else if (y <= 0) y = 1;
2141 /* Clear the top line */
2144 /* Recenter the map around the player */
2147 p_ptr->update |= (PU_MONSTERS);
2149 p_ptr->redraw |= (PR_MAP);
2151 p_ptr->window |= (PW_OVERHEAD);
2160 bool get_hack_dir(DIRECTION *dp)
2168 /* Global direction */
2171 /* (No auto-targeting) */
2173 /* Ask until satisfied */
2176 /* Choose a prompt */
2179 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2183 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2186 /* Get a command (or Cancel) */
2187 if (!get_com(p, &command, TRUE)) break;
2191 if (command == '\r') command = 't';
2194 /* Convert various keys to "standard" keys */
2197 /* Use current target */
2208 /* Set new target */
2213 if (target_set(TARGET_KILL)) dir = 5;
2219 /* Look up the direction */
2220 dir = get_keymap_dir(command);
2226 /* Verify requested targets */
2227 if ((dir == 5) && !target_okay()) dir = 0;
2234 if (!dir) return (FALSE);
2236 /* Save the direction */
2239 /* Check for confusion */
2240 if (p_ptr->confused)
2242 /* Random direction */
2243 dir = ddd[randint0(8)];
2246 /* Notice confusion */
2247 if (command_dir != dir)
2250 msg_print(_("あなたは混乱している。", "You are confused."));
2253 /* Save direction */
2256 /* A "valid" direction was entered */