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"
23 #include "floor-events.h"
24 #include "player-move.h"
25 #include "monster-status.h"
28 * @brief コンソール上におけるマップ表示の左上位置を返す /
29 * Calculates current boundaries Called below and from "do_cmd_locate()".
32 void panel_bounds_center(void)
36 get_screen_size(&wid, &hgt);
38 panel_row_max = panel_row_min + hgt - 1;
39 panel_row_prt = panel_row_min - 1;
40 panel_col_max = panel_col_min + wid - 1;
41 panel_col_prt = panel_col_min - 13;
45 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
49 * Handle a request to change the current panel
50 * Return TRUE if the panel was changed.
51 * Also used in do_cmd_locate
52 * @return 実際に再描画が必要だった場合TRUEを返す
54 static bool change_panel_xy(POSITION y, POSITION x)
56 POSITION dy = 0, dx = 0;
59 get_screen_size(&wid, &hgt);
61 if (y < panel_row_min) dy = -1;
62 if (y > panel_row_max) dy = 1;
63 if (x < panel_col_min) dx = -1;
64 if (x > panel_col_max) dx = 1;
66 if (!dy && !dx) return (FALSE);
68 return change_panel(dy, dx);
73 * @brief マップ描画のフォーカスを当てるべき座標を更新する
75 * Given an row (y) and col (x), this routine detects when a move
76 * off the screen has occurred and figures new borders. -RAK-
77 * "Update" forces a "full update" to take place.
78 * The map is reprinted if necessary, and "TRUE" is returned.
79 * @return 実際に再描画が必要だった場合TRUEを返す
81 void verify_panel(void)
83 POSITION y = p_ptr->y;
84 POSITION x = p_ptr->x;
92 get_screen_size(&wid, &hgt);
94 max_prow_min = current_floor_ptr->height - hgt;
95 max_pcol_min = current_floor_ptr->width - wid;
98 if (max_prow_min < 0) max_prow_min = 0;
99 if (max_pcol_min < 0) max_pcol_min = 0;
101 /* Center on player */
102 if (center_player && (center_running || !running))
104 /* Center vertically */
105 prow_min = y - hgt / 2;
106 if (prow_min < 0) prow_min = 0;
107 else if (prow_min > max_prow_min) prow_min = max_prow_min;
109 /* Center horizontally */
110 pcol_min = x - wid / 2;
111 if (pcol_min < 0) pcol_min = 0;
112 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
116 prow_min = panel_row_min;
117 pcol_min = panel_col_min;
119 /* Scroll screen when 2 grids from top/bottom edge */
120 if (y > panel_row_max - 2)
122 while (y > prow_min + hgt-1 - 2)
124 prow_min += (hgt / 2);
128 if (y < panel_row_min + 2)
130 while (y < prow_min + 2)
132 prow_min -= (hgt / 2);
136 if (prow_min > max_prow_min) prow_min = max_prow_min;
137 if (prow_min < 0) prow_min = 0;
139 /* Scroll screen when 4 grids from left/right edge */
140 if (x > panel_col_max - 4)
142 while (x > pcol_min + wid-1 - 4)
144 pcol_min += (wid / 2);
148 if (x < panel_col_min + 4)
150 while (x < pcol_min + 4)
152 pcol_min -= (wid / 2);
156 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
157 if (pcol_min < 0) pcol_min = 0;
160 /* Check for "no change" */
161 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
163 /* Save the new panel info */
164 panel_row_min = prow_min;
165 panel_col_min = pcol_min;
167 /* Hack -- optional disturb on "panel change" */
168 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
170 panel_bounds_center();
172 p_ptr->update |= (PU_MONSTERS);
173 p_ptr->redraw |= (PR_MAP);
174 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
178 /*** Targeting Code ***/
181 * Determine is a monster makes a reasonable target
183 * The concept of "targeting" was stolen from "Morgul" (?)
185 * The player can target any location, or any "target-able" monster.
187 * Currently, a monster is "target_able" if it is visible, and if
188 * the player can hit it with a projection, and the player is not
189 * hallucinating. This allows use of "use closest target" macros.
191 * Future versions may restrict the ability to target "trappers"
192 * and "mimics", but the semantics is a little bit weird.
194 bool target_able(MONSTER_IDX m_idx)
196 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
198 /* Monster must be alive */
199 if (!monster_is_valid(m_ptr)) return (FALSE);
201 /* Hack -- no targeting hallucinations */
202 if (p_ptr->image) return (FALSE);
204 /* Monster must be visible */
205 if (!m_ptr->ml) return (FALSE);
207 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
209 /* Monster must be projectable */
210 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
212 /* Hack -- Never target trappers */
213 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
223 * Update (if necessary) and verify (if possible) the target.
225 * We return TRUE if the target is "okay" and FALSE otherwise.
227 bool target_okay(void)
229 /* Accept stationary targets */
230 if (target_who < 0) return (TRUE);
232 /* Check moving targets */
235 /* Accept reasonable targets */
236 if (target_able(target_who))
238 monster_type *m_ptr = ¤t_floor_ptr->m_list[target_who];
240 /* Acquire monster location */
241 target_row = m_ptr->fy;
242 target_col = m_ptr->fx;
249 /* Assume no target */
255 * Hack -- help "select" a location (see below)
257 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
260 POSITION x2, y2, x3, y3, x4, y4;
261 POSITION_IDX b_i = -1, b_v = 9999;
264 /* Scan the locations */
265 for (i = 0; i < tmp_pos.n; i++)
271 /* Directed distance */
275 /* Verify quadrant */
276 if (dx && (x3 * dx <= 0)) continue;
277 if (dy && (y3 * dy <= 0)) continue;
282 /* Verify quadrant */
283 if (dy && !dx && (x4 > y4)) continue;
284 if (dx && !dy && (y4 > x4)) continue;
286 /* Approximate Double Distance */
287 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
289 /* Penalize location */
290 if ((b_i >= 0) && (v >= b_v)) continue;
298 * Hack -- determine if a given location is "interesting"
300 static bool target_set_accept(POSITION y, POSITION x)
303 OBJECT_IDX this_o_idx, next_o_idx = 0;
305 if (!(in_bounds(y, x))) return (FALSE);
307 /* Player grid is always interesting */
308 if (player_bold(y, x)) return (TRUE);
310 if (p_ptr->image) return (FALSE);
312 g_ptr = ¤t_floor_ptr->grid_array[y][x];
314 /* Visible monsters */
317 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
319 /* Visible monsters */
320 if (m_ptr->ml) return (TRUE);
323 /* Scan all objects in the grid */
324 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
327 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
328 next_o_idx = o_ptr->next_o_idx;
330 /* Memorized object */
331 if (o_ptr->marked & OM_FOUND) return (TRUE);
334 /* Interesting memorized features */
335 if (g_ptr->info & (CAVE_MARK))
337 /* Notice object features */
338 if (g_ptr->info & CAVE_OBJECT) return (TRUE);
340 /* Feature code (applying "mimic" field) */
341 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE)) return TRUE;
349 * Prepare the "temp" array for "target_set"
351 * Return the number of target_able monsters in the set.
353 static void target_set_prepare(BIT_FLAGS mode)
356 POSITION min_hgt, max_hgt, min_wid, max_wid;
358 if (mode & TARGET_KILL)
361 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
362 max_hgt = MIN((p_ptr->y + MAX_RANGE), current_floor_ptr->height - 1);
363 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
364 max_wid = MIN((p_ptr->x + MAX_RANGE), current_floor_ptr->width - 1);
366 else /* not targetting */
369 min_hgt = panel_row_min;
370 max_hgt = panel_row_max;
371 min_wid = panel_col_min;
372 max_wid = panel_col_max;
375 /* Reset "temp" array */
378 /* Scan the current panel */
379 for (y = min_hgt; y <= max_hgt; y++)
381 for (x = min_wid; x <= max_wid; x++)
385 /* Require "interesting" contents */
386 if (!target_set_accept(y, x)) continue;
388 g_ptr = ¤t_floor_ptr->grid_array[y][x];
390 /* Require target_able monsters for "TARGET_KILL" */
391 if ((mode & (TARGET_KILL)) && !target_able(g_ptr->m_idx)) continue;
393 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(¤t_floor_ptr->m_list[g_ptr->m_idx])) continue;
395 /* Save the location */
396 tmp_pos.x[tmp_pos.n] = x;
397 tmp_pos.y[tmp_pos.n] = y;
402 /* Set the sort hooks */
403 if (mode & (TARGET_KILL))
405 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
409 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_importance, ang_sort_swap_distance);
412 if (p_ptr->riding && target_pet && (tmp_pos.n > 1) && (mode & (TARGET_KILL)))
417 tmp_pos.y[0] = tmp_pos.y[1];
420 tmp_pos.x[0] = tmp_pos.x[1];
425 void target_set_prepare_look(void){
426 target_set_prepare(TARGET_LOOK);
431 * Evaluate number of kill needed to gain level
433 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
435 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
437 s32b exp_mon, exp_adv;
438 u32b exp_mon_frac, exp_adv_frac;
440 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
445 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
455 /* The monster's experience point (assuming average monster speed) */
456 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
458 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
461 /* Total experience value for next level */
462 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
464 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
466 /* Experience value need to get */
467 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
470 /* You need to kill at least one monster to get any experience */
471 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
472 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
474 /* Extract number of monsters needed */
475 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
477 /* If 999 or more monsters needed, only display "999". */
478 num = MIN(999, exp_adv_frac);
480 /* Display the number */
481 sprintf(buf,"%03ld", (long int)num);
485 bool show_gold_on_floor = FALSE;
488 * Examine a grid, return a keypress.
490 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
491 * indicates that the "space" key should scan through the contents
492 * of the grid, instead of simply returning immediately. This lets
493 * the "look" command get complete information, without making the
494 * "target" command annoying.
496 * The "info" argument contains the "commands" which should be shown
497 * inside the "[xxx]" text. This string must never be empty, or grids
498 * containing monsters will be displayed with an extra comma.
500 * Note that if a monster is in the grid, we update both the monster
501 * recall info and the health bar info to track that monster.
503 * Eventually, we may allow multiple objects per grid, or objects
504 * and terrain features in the same grid.
506 * This function must handle blindness/hallucination.
508 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
510 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
511 OBJECT_IDX this_o_idx, next_o_idx = 0;
512 concptr s1 = "", s2 = "", s3 = "", x_info = "";
517 char out_val[MAX_NLEN+80];
518 OBJECT_IDX floor_list[23];
519 ITEM_NUMBER floor_num = 0;
521 /* Scan all objects in the grid */
524 floor_num = scan_floor(floor_list, y, x, 0x02);
528 x_info = _("x物 ", "x,");
532 /* Hack -- under the player */
533 if (player_bold(y, x))
546 s1 = _("ターゲット:", "Target:");
549 /* Hack -- hallucination */
552 concptr name = _("何か奇妙な物", "something strange");
554 /* Display a message */
556 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
558 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
562 move_cursor_relative(y, x);
565 /* Stop on everything but "return" */
566 if ((query != '\r') && (query != '\n')) return query;
573 /* Actual monsters */
574 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
576 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
577 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
578 GAME_TEXT m_name[MAX_NLEN];
584 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
585 monster_race_track(m_ptr->ap_r_idx);
586 health_track(g_ptr->m_idx);
599 /* Recall on screen */
600 screen_roff(m_ptr->ap_r_idx, 0);
602 /* Hack -- Complete the prompt (again) */
603 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
610 /* Normal commands */
611 if (query != 'r') break;
616 /* Cleare recall text and repeat */
622 /* Describe, and prompt for recall */
623 evaluate_monster_exp(acount, m_ptr);
626 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);
628 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);
634 move_cursor_relative(y, x);
639 /* Normal commands */
640 if (query != 'r') break;
646 /* Always stop at "normal" keys */
647 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
649 /* Sometimes stop at "space" key */
650 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
652 /* Change the intro */
653 s1 = _("それは", "It is ");
655 /* Hack -- take account of gender */
656 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
657 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
659 /* Use a preposition */
668 /* Scan all objects being carried */
669 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
671 GAME_TEXT o_name[MAX_NLEN];
674 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
675 next_o_idx = o_ptr->next_o_idx;
677 /* Obtain an object description */
678 object_desc(o_name, o_ptr, 0);
681 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
683 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
687 move_cursor_relative(y, x);
690 /* Always stop at "normal" keys */
691 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
693 /* Sometimes stop at "space" key */
694 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
696 /* Change the intro */
697 s2 = _("をまた", "also carrying ");
700 /* Use a preposition */
717 GAME_TEXT o_name[MAX_NLEN];
720 o_ptr = ¤t_floor_ptr->o_list[floor_list[0]];
722 object_desc(o_name, o_ptr, 0);
725 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
727 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
731 move_cursor_relative(y, x);
740 /* Provide one cushion before item listing */
743 /* Display rough information about items */
745 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
747 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
751 move_cursor_relative(y, x);
756 /* No request for listing */
757 if (query != 'x' && query != ' ') return query;
761 /** Display list of items **/
763 /* Continue scrolling list if requested */
771 show_gold_on_floor = TRUE;
772 (void)show_floor(0, y, x, &min_width);
773 show_gold_on_floor = FALSE;
777 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
779 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
786 /* Exit unless 'Enter' */
787 if (query != '\n' && query != '\r')
792 /* Get the object being moved. */
793 o_idx = g_ptr->o_idx;
795 /* Only rotate a pile of two or more objects. */
796 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
798 /* Remove the first object from the list. */
799 excise_object_idx(o_idx);
801 /* Find end of the list. */
803 while (current_floor_ptr->o_list[i].next_o_idx)
804 i = current_floor_ptr->o_list[i].next_o_idx;
806 /* Add after the last object. */
807 current_floor_ptr->o_list[i].next_o_idx = o_idx;
809 /* Loop and re-display the list */
816 /* Scan all objects in the grid */
817 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
820 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
821 next_o_idx = o_ptr->next_o_idx;
823 if (o_ptr->marked & OM_FOUND)
825 GAME_TEXT o_name[MAX_NLEN];
830 /* Obtain an object description */
831 object_desc(o_name, o_ptr, 0);
834 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
836 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
840 move_cursor_relative(y, x);
843 /* Always stop at "normal" keys */
844 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
846 /* Sometimes stop at "space" key */
847 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
849 /* Change the intro */
850 s1 = _("それは", "It is ");
853 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
867 /* Feature code (applying "mimic" field) */
868 feat = get_feat_mimic(g_ptr);
870 /* Require knowledge about grid, or ability to see grid */
871 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
877 f_ptr = &f_info[feat];
879 /* Terrain feature if needed */
880 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
884 /* Hack -- special handling for quest entrances */
885 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
887 /* Set the quest number temporary */
888 IDX old_quest = p_ptr->inside_quest;
892 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
895 p_ptr->inside_quest = g_ptr->special;
897 /* Get the quest text */
898 init_flags = INIT_NAME_ONLY;
900 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
902 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
903 quest[g_ptr->special].name, quest[g_ptr->special].level);
905 /* Reset the old quest number */
906 p_ptr->inside_quest = old_quest;
909 /* Hack -- special handling for building doors */
910 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
912 name = building[f_ptr->subtype].name;
914 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
916 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
918 else if (have_flag(f_ptr->flags, FF_TOWN))
920 name = town_info[g_ptr->special].name;
922 else if (p_ptr->wild_mode && (feat == feat_floor))
924 name = _("道", "road");
928 name = f_name + f_ptr->name;
934 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
935 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
936 have_flag(f_ptr->flags, FF_TOWN)))
941 /* Hack -- special introduction for store & building doors -KMW- */
942 if (have_flag(f_ptr->flags, FF_STORE) ||
943 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
944 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
945 have_flag(f_ptr->flags, FF_ENTRANCE))
950 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
951 have_flag(f_ptr->flags, FF_TOWN) ||
952 have_flag(f_ptr->flags, FF_SHALLOW) ||
953 have_flag(f_ptr->flags, FF_DEEP))
959 /* Pick proper indefinite article */
960 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
964 /* Display a message */
968 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
969 else sprintf(f_idx_str, "%d", g_ptr->feat);
971 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]);
973 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);
978 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
980 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
984 move_cursor_relative(y, x);
987 /* Always stop at "normal" keys */
988 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
991 /* Stop on everything but "return" */
992 if ((query != '\r') && (query != '\n')) return query;
1000 * Handle "target" and "look".
1002 * Note that this code can be called from "get_aim_dir()".
1004 * All locations must be on the current panel. Consider the use of
1005 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1006 * some form of "scrolling" the map around the cursor.
1007 * That is, consider the possibility of "auto-scrolling" the screen
1008 * while the cursor moves around. This may require changes in the
1009 * "update_monster()" code to allow "visibility" even if off panel, and
1010 * may require dynamic recalculation of the "temp" grid set.
1012 * Hack -- targeting/observing an "outer border grid" may induce
1013 * problems, so this is not currently allowed.
1015 * The player can use the direction keys to move among "interesting"
1016 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1017 * move through the "interesting" grids in a sequential manner, or
1018 * can enter "location" mode, and use the direction keys to move one
1019 * grid at a time in any direction. The "t" (set target) command will
1020 * only target a monster (as opposed to a location) if the monster is
1021 * target_able and the "interesting" mode is being used.
1023 * The current grid is described using the "look" method above, and
1024 * a new command may be entered at any time, but note that if the
1025 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1026 * where "space" has no obvious meaning) then "space" will scan
1027 * through the description of the current grid until done, instead
1028 * of immediately jumping to the next "interesting" grid. This
1029 * allows the "target" command to retain its old semantics.
1031 * The "*", "+", and "-" keys may always be used to jump immediately
1032 * to the next (or previous) interesting grid, in the proper mode.
1034 * The "return" key may always be used to scan through a complete
1035 * grid description (forever).
1037 * This command will cancel any old target, even if used from
1038 * inside the "look" command.
1040 bool target_set(BIT_FLAGS mode)
1043 POSITION y = p_ptr->y;
1044 POSITION x = p_ptr->x;
1054 get_screen_size(&wid, &hgt);
1059 if (rogue_like_commands)
1068 /* Prepare the "temp" array */
1069 target_set_prepare(mode);
1071 /* Start near the player */
1077 /* Interesting grids */
1078 if (flag && tmp_pos.n)
1084 change_panel_xy(y, x);
1086 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1089 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1092 if (target_able(g_ptr->m_idx))
1094 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1097 /* Dis-allow target */
1100 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1106 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1107 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1108 strcat(info, cheatinfo);
1111 /* Describe and Prompt */
1113 query = target_set_aux(y, x, mode, info);
1117 /* Assume no "direction" */
1122 if (query == '\r') query = 't';
1140 if (target_able(g_ptr->m_idx))
1142 health_track(g_ptr->m_idx);
1143 target_who = g_ptr->m_idx;
1159 if (++m == tmp_pos.n)
1162 if (!expand_list) done = TRUE;
1172 if (!expand_list) done = TRUE;
1179 /* Recenter the map around the player */
1181 p_ptr->update |= (PU_MONSTERS);
1182 p_ptr->redraw |= (PR_MAP);
1183 p_ptr->window |= (PW_OVERHEAD);
1186 /* Recalculate interesting grids */
1187 target_set_prepare(mode);
1206 if(query == same_key)
1208 if (++m == tmp_pos.n)
1211 if (!expand_list) done = TRUE;
1216 /* Extract the action (if any) */
1217 d = get_keymap_dir(query);
1224 /* Hack -- move around */
1227 /* Modified to scroll to monster */
1228 POSITION y2 = panel_row_min;
1229 POSITION x2 = panel_col_min;
1231 /* Find a new monster */
1232 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
1234 /* Request to target past last interesting grid */
1235 while (flag && (i < 0))
1237 /* Note the change */
1238 if (change_panel(ddy[d], ddx[d]))
1240 int v = tmp_pos.y[m];
1241 int u = tmp_pos.x[m];
1243 /* Recalculate interesting grids */
1244 target_set_prepare(mode);
1246 /* Look at interesting grids */
1249 /* Find a new monster */
1250 i = target_pick(v, u, ddy[d], ddx[d]);
1256 /* Nothing interesting */
1259 POSITION dx = ddx[d];
1260 POSITION dy = ddy[d];
1262 /* Restore previous position */
1265 panel_bounds_center();
1267 p_ptr->update |= (PU_MONSTERS);
1268 p_ptr->redraw |= (PR_MAP);
1269 p_ptr->window |= (PW_OVERHEAD);
1272 /* Recalculate interesting grids */
1273 target_set_prepare(mode);
1275 /* Look at boring grids */
1282 /* Do not move horizontally if unnecessary */
1283 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1284 ((x > panel_col_min + wid / 2) && (dx < 0)))
1289 /* Do not move vertically if unnecessary */
1290 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1291 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1296 /* Apply the motion */
1297 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1298 (x >= panel_col_min+wid) || (x < panel_col_min))
1300 if (change_panel(dy, dx)) target_set_prepare(mode);
1303 /* Slide into legality */
1304 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1305 else if (x <= 0) x = 1;
1307 /* Slide into legality */
1308 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1309 else if (y <= 0) y = 1;
1318 /* Arbitrary grids */
1321 bool move_fast = FALSE;
1323 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1326 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1328 /* Default prompt */
1329 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1334 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1335 los(p_ptr->y, p_ptr->x, y, x),
1336 projectable(p_ptr->y, p_ptr->x, y, x));
1337 strcat(info, cheatinfo);
1340 /* Describe and Prompt (enable "TARGET_LOOK") */
1341 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1343 /* Assume no direction */
1348 if (query == '\r') query = 't';
1351 /* Analyze the keypress */
1375 /* Recenter the map around the player */
1377 p_ptr->update |= (PU_MONSTERS);
1378 p_ptr->redraw |= (PR_MAP);
1379 p_ptr->window |= (PW_OVERHEAD);
1382 /* Recalculate interesting grids */
1383 target_set_prepare(mode);
1405 /* Pick a nearby monster */
1406 for (i = 0; i < tmp_pos.n; i++)
1408 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1418 /* Nothing interesting */
1419 if (bd == 999) flag = FALSE;
1426 /* Extract the action (if any) */
1427 d = get_keymap_dir(query);
1429 /* XTRA HACK MOVEFAST */
1430 if (isupper(query)) move_fast = TRUE;
1437 /* Handle "direction" */
1440 POSITION dx = ddx[d];
1441 POSITION dy = ddy[d];
1443 /* XTRA HACK MOVEFAST */
1446 int mag = MIN(wid / 2, hgt / 2);
1456 /* Do not move horizontally if unnecessary */
1457 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1458 ((x > panel_col_min + wid / 2) && (dx < 0)))
1463 /* Do not move vertically if unnecessary */
1464 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1465 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1470 /* Apply the motion */
1471 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1472 (x >= panel_col_min + wid) || (x < panel_col_min))
1474 if (change_panel(dy, dx)) target_set_prepare(mode);
1477 /* Slide into legality */
1478 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1479 else if (x <= 0) x = 1;
1481 /* Slide into legality */
1482 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1483 else if (y <= 0) y = 1;
1491 /* Clear the top line */
1494 /* Recenter the map around the player */
1496 p_ptr->update |= (PU_MONSTERS);
1497 p_ptr->redraw |= (PR_MAP);
1498 p_ptr->window |= (PW_OVERHEAD);
1501 /* Failure to set target */
1502 if (!target_who) return (FALSE);
1510 * Get an "aiming direction" from the user.
1512 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1513 * "0" for "current target", and "-1" for "entry aborted".
1515 * Note that "Force Target", if set, will pre-empt user interaction,
1516 * if there is a usable target already set.
1518 * Note that confusion over-rides any (explicit?) user choice.
1520 bool get_aim_dir(DIRECTION *dp)
1529 /* Global direction */
1532 /* Hack -- auto-target if requested */
1533 if (use_old_target && target_okay()) dir = 5;
1535 if (repeat_pull(&code))
1540 if (!(code == 5 && !target_okay()))
1542 /* return (TRUE); */
1543 dir = (DIRECTION)code;
1546 *dp = (DIRECTION)code;
1548 /* Ask until satisfied */
1551 /* Choose a prompt */
1554 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1558 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
1561 /* Get a command (or Cancel) */
1562 if (!get_com(p, &command, TRUE)) break;
1566 if (command == '\r') command = 't';
1569 /* Convert various keys to "standard" keys */
1572 /* Use current target */
1583 /* Set new target */
1588 if (target_set(TARGET_KILL)) dir = 5;
1594 /* Extract the action (if any) */
1595 dir = get_keymap_dir(command);
1601 /* Verify requested targets */
1602 if ((dir == 5) && !target_okay()) dir = 0;
1611 project_length = 0; /* reset to default */
1615 /* Save the direction */
1618 /* Check for confusion */
1619 if (p_ptr->confused)
1621 /* Random direction */
1622 dir = ddd[randint0(8)];
1625 /* Notice confusion */
1626 if (command_dir != dir)
1629 msg_print(_("あなたは混乱している。", "You are confused."));
1632 /* Save direction */
1635 /* repeat_push(dir); */
1636 repeat_push((COMMAND_CODE)command_dir);
1638 /* A "valid" direction was entered */
1643 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
1651 /* Global direction */
1654 if (repeat_pull(&code))
1656 dir = (DIRECTION)code;
1657 /* return (TRUE); */
1659 *dp = (DIRECTION)code;
1663 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1667 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1670 /* Get a direction */
1675 /* Get a command (or Cancel) */
1676 if (!get_com(prompt, &ch, TRUE)) break;
1679 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1685 /* Look up the direction */
1686 dir = get_keymap_dir(ch);
1692 /* Prevent weirdness */
1693 if ((dir == 5) && (!allow_under)) dir = 0;
1696 if (!dir) return (FALSE);
1698 /* Save desired direction */
1701 /* Apply "confusion" */
1702 if (p_ptr->confused)
1704 /* Standard confusion */
1705 if (randint0(100) < 75)
1707 /* Random direction */
1708 dir = ddd[randint0(8)];
1711 else if (p_ptr->riding && with_steed)
1713 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1714 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1716 if (MON_CONFUSED(m_ptr))
1718 /* Standard confusion */
1719 if (randint0(100) < 75)
1721 /* Random direction */
1722 dir = ddd[randint0(8)];
1725 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1727 /* Random direction */
1728 dir = ddd[randint0(8)];
1730 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1732 /* Random direction */
1733 dir = ddd[randint0(8)];
1737 /* Notice confusion */
1738 if (command_dir != dir)
1740 if (p_ptr->confused)
1743 msg_print(_("あなたは混乱している。", "You are confused."));
1747 GAME_TEXT m_name[MAX_NLEN];
1748 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1750 monster_desc(m_name, m_ptr, 0);
1751 if (MON_CONFUSED(m_ptr))
1753 msg_format(_("%sは混乱している。", "%^s is confused."), m_name);
1757 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1762 /* Save direction */
1765 /* repeat_push(dir); */
1766 repeat_push((COMMAND_CODE)command_dir);
1773 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
1774 * and place it into "command_dir", unless we already have one.
1776 * This function should be used for all "repeatable" commands, such as
1777 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
1778 * as all commands which must reference a grid adjacent to the player,
1779 * and which may not reference the grid under the player. Note that,
1780 * for example, it is no longer possible to "disarm" or "open" chests
1781 * in the same grid as the player.
1783 * Direction "5" is illegal and will (cleanly) abort the command.
1785 * This function tracks and uses the "global direction", and uses
1786 * that as the "desired direction", to which "confusion" is applied.
1788 bool get_rep_dir(DIRECTION *dp, bool under)
1796 /* Global direction */
1799 if (repeat_pull(&code))
1801 dir = (DIRECTION)code;
1802 /* return (TRUE); */
1804 *dp = (DIRECTION)code;
1808 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1812 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1815 /* Get a direction */
1820 /* Get a command (or Cancel) */
1821 if (!get_com(prompt, &ch, TRUE)) break;
1824 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1830 /* Look up the direction */
1831 dir = get_keymap_dir(ch);
1837 /* Prevent weirdness */
1838 if ((dir == 5) && (!under)) dir = 0;
1841 if (!dir) return (FALSE);
1843 /* Save desired direction */
1846 /* Apply "confusion" */
1847 if (p_ptr->confused)
1849 /* Standard confusion */
1850 if (randint0(100) < 75)
1852 /* Random direction */
1853 dir = ddd[randint0(8)];
1856 else if (p_ptr->riding)
1858 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1859 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1861 if (MON_CONFUSED(m_ptr))
1863 /* Standard confusion */
1864 if (randint0(100) < 75)
1866 /* Random direction */
1867 dir = ddd[randint0(8)];
1870 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1872 /* Random direction */
1873 dir = ddd[randint0(8)];
1875 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1877 /* Random direction */
1878 dir = ddd[randint0(8)];
1882 /* Notice confusion */
1883 if (command_dir != dir)
1885 if (p_ptr->confused)
1888 msg_print(_("あなたは混乱している。", "You are confused."));
1892 GAME_TEXT m_name[MAX_NLEN];
1893 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1895 monster_desc(m_name, m_ptr, 0);
1896 if (MON_CONFUSED(m_ptr))
1898 msg_format(_("%sは混乱している。", "%^s is confused."), m_name);
1902 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1907 /* Save direction */
1910 /* repeat_push(dir); */
1911 repeat_push((COMMAND_CODE)command_dir);
1919 * XAngband: determine if a given location is "interesting"
1920 * based on target_set_accept function.
1922 static bool tgt_pt_accept(POSITION y, POSITION x)
1926 if (!(in_bounds(y, x))) return (FALSE);
1928 /* Player grid is always interesting */
1929 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
1931 if (p_ptr->image) return (FALSE);
1933 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1935 /* Interesting memorized features */
1936 if (g_ptr->info & (CAVE_MARK))
1939 if (cave_have_flag_grid(g_ptr, FF_LESS)) return (TRUE);
1940 if (cave_have_flag_grid(g_ptr, FF_MORE)) return (TRUE);
1942 /* Notice quest features */
1943 if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return (TRUE);
1944 if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return (TRUE);
1952 * XAngband: Prepare the "temp" array for "tget_pt"
1953 * based on target_set_prepare funciton.
1955 static void tgt_pt_prepare(void)
1959 /* Reset "temp" array */
1962 if (!expand_list) return;
1964 /* Scan the current panel */
1965 for (y = 1; y < current_floor_ptr->height; y++)
1967 for (x = 1; x < current_floor_ptr->width; x++)
1969 /* Require "interesting" contents */
1970 if (!tgt_pt_accept(y, x)) continue;
1972 /* Save the location */
1973 tmp_pos.x[tmp_pos.n] = x;
1974 tmp_pos.y[tmp_pos.n] = y;
1979 /* Sort the positions */
1980 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
1984 * old -- from PsiAngband.
1986 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
1991 bool success = FALSE;
1995 get_screen_size(&wid, &hgt);
2005 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2006 msg_flag = FALSE; /* prevents "-more-" message. */
2008 while ((ch != ESCAPE) && !success)
2010 bool move_fast = FALSE;
2012 move_cursor_relative(y, x);
2024 if (player_bold(y, x)) ch = 0;
2027 else success = TRUE;
2031 /* XAngband: Move cursor to stairs */
2034 if (expand_list && tmp_pos.n)
2037 int cx = (panel_col_min + panel_col_max) / 2;
2038 int cy = (panel_row_min + panel_row_max) / 2;
2042 /* Skip stairs which have defferent distance */
2043 for (; n < tmp_pos.n; ++ n)
2045 grid_type *g_ptr = ¤t_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
2047 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2048 cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2055 if (n == tmp_pos.n) /* Loop out taget list */
2060 verify_panel(); /* Move cursor to player */
2062 p_ptr->update |= (PU_MONSTERS);
2064 p_ptr->redraw |= (PR_MAP);
2066 p_ptr->window |= (PW_OVERHEAD);
2069 else /* move cursor to next stair and change panel */
2074 dy = 2 * (y - cy) / hgt;
2075 dx = 2 * (x - cx) / wid;
2076 if (dy || dx) change_panel(dy, dx);
2082 /* Look up the direction */
2083 d = get_keymap_dir(ch);
2085 /* XTRA HACK MOVEFAST */
2086 if (isupper(ch)) move_fast = TRUE;
2088 /* Handle "direction" */
2094 /* XTRA HACK MOVEFAST */
2097 int mag = MIN(wid / 2, hgt / 2);
2107 /* Do not move horizontally if unnecessary */
2108 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2109 ((x > panel_col_min + wid / 2) && (dx < 0)))
2114 /* Do not move vertically if unnecessary */
2115 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2116 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2121 /* Apply the motion */
2122 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2123 (x >= panel_col_min + wid) || (x < panel_col_min))
2125 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2126 change_panel(dy, dx);
2129 /* Slide into legality */
2130 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
2131 else if (x <= 0) x = 1;
2133 /* Slide into legality */
2134 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
2135 else if (y <= 0) y = 1;
2142 /* Clear the top line */
2145 /* Recenter the map around the player */
2148 p_ptr->update |= (PU_MONSTERS);
2150 p_ptr->redraw |= (PR_MAP);
2152 p_ptr->window |= (PW_OVERHEAD);
2161 bool get_hack_dir(DIRECTION *dp)
2169 /* Global direction */
2172 /* (No auto-targeting) */
2174 /* Ask until satisfied */
2177 /* Choose a prompt */
2180 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2184 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2187 /* Get a command (or Cancel) */
2188 if (!get_com(p, &command, TRUE)) break;
2192 if (command == '\r') command = 't';
2195 /* Convert various keys to "standard" keys */
2198 /* Use current target */
2209 /* Set new target */
2214 if (target_set(TARGET_KILL)) dir = 5;
2220 /* Look up the direction */
2221 dir = get_keymap_dir(command);
2227 /* Verify requested targets */
2228 if ((dir == 5) && !target_okay()) dir = 0;
2235 if (!dir) return (FALSE);
2237 /* Save the direction */
2240 /* Check for confusion */
2241 if (p_ptr->confused)
2243 /* Random direction */
2244 dir = ddd[randint0(8)];
2247 /* Notice confusion */
2248 if (command_dir != dir)
2251 msg_print(_("あなたは混乱している。", "You are confused."));
2254 /* Save direction */
2257 /* A "valid" direction was entered */