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.
18 #include "dungeon-file.h"
19 #include "object-curse.h"
20 #include "object-flavor.h"
22 #include "monsterrace-hook.h"
23 #include "objectkind-hook.h"
25 #include "spells-summon.h"
28 #include "floor-events.h"
29 #include "player-move.h"
30 #include "player-status.h"
31 #include "monster-status.h"
32 #include "view-mainwindow.h"
36 * @brief コンソール上におけるマップ表示の左上位置を返す /
37 * Calculates current boundaries Called below and from "do_cmd_locate()".
40 void panel_bounds_center(void)
44 get_screen_size(&wid, &hgt);
46 panel_row_max = panel_row_min + hgt - 1;
47 panel_row_prt = panel_row_min - 1;
48 panel_col_max = panel_col_min + wid - 1;
49 panel_col_prt = panel_col_min - 13;
53 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
57 * Handle a request to change the current panel
58 * Return TRUE if the panel was changed.
59 * Also used in do_cmd_locate
60 * @return 実際に再描画が必要だった場合TRUEを返す
62 static bool change_panel_xy(POSITION y, POSITION x)
64 POSITION dy = 0, dx = 0;
67 get_screen_size(&wid, &hgt);
69 if (y < panel_row_min) dy = -1;
70 if (y > panel_row_max) dy = 1;
71 if (x < panel_col_min) dx = -1;
72 if (x > panel_col_max) dx = 1;
74 if (!dy && !dx) return (FALSE);
76 return change_panel(dy, dx);
81 * @brief マップ描画のフォーカスを当てるべき座標を更新する
83 * Given an row (y) and col (x), this routine detects when a move
84 * off the screen has occurred and figures new borders. -RAK-
85 * "Update" forces a "full update" to take place.
86 * The map is reprinted if necessary, and "TRUE" is returned.
87 * @return 実際に再描画が必要だった場合TRUEを返す
89 void verify_panel(void)
91 POSITION y = p_ptr->y;
92 POSITION x = p_ptr->x;
100 get_screen_size(&wid, &hgt);
102 max_prow_min = current_floor_ptr->height - hgt;
103 max_pcol_min = current_floor_ptr->width - wid;
105 /* Bounds checking */
106 if (max_prow_min < 0) max_prow_min = 0;
107 if (max_pcol_min < 0) max_pcol_min = 0;
109 /* Center on player */
110 if (center_player && (center_running || !running))
112 /* Center vertically */
113 prow_min = y - hgt / 2;
114 if (prow_min < 0) prow_min = 0;
115 else if (prow_min > max_prow_min) prow_min = max_prow_min;
117 /* Center horizontally */
118 pcol_min = x - wid / 2;
119 if (pcol_min < 0) pcol_min = 0;
120 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
124 prow_min = panel_row_min;
125 pcol_min = panel_col_min;
127 /* Scroll screen when 2 grids from top/bottom edge */
128 if (y > panel_row_max - 2)
130 while (y > prow_min + hgt-1 - 2)
132 prow_min += (hgt / 2);
136 if (y < panel_row_min + 2)
138 while (y < prow_min + 2)
140 prow_min -= (hgt / 2);
144 if (prow_min > max_prow_min) prow_min = max_prow_min;
145 if (prow_min < 0) prow_min = 0;
147 /* Scroll screen when 4 grids from left/right edge */
148 if (x > panel_col_max - 4)
150 while (x > pcol_min + wid-1 - 4)
152 pcol_min += (wid / 2);
156 if (x < panel_col_min + 4)
158 while (x < pcol_min + 4)
160 pcol_min -= (wid / 2);
164 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
165 if (pcol_min < 0) pcol_min = 0;
168 /* Check for "no change" */
169 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
171 /* Save the new panel info */
172 panel_row_min = prow_min;
173 panel_col_min = pcol_min;
175 /* Hack -- optional disturb on "panel change" */
176 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
178 panel_bounds_center();
180 p_ptr->update |= (PU_MONSTERS);
181 p_ptr->redraw |= (PR_MAP);
182 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
186 /*** Targeting Code ***/
189 * Determine is a monster makes a reasonable target
191 * The concept of "targeting" was stolen from "Morgul" (?)
193 * The player can target any location, or any "target-able" monster.
195 * Currently, a monster is "target_able" if it is visible, and if
196 * the player can hit it with a projection, and the player is not
197 * hallucinating. This allows use of "use closest target" macros.
199 * Future versions may restrict the ability to target "trappers"
200 * and "mimics", but the semantics is a little bit weird.
202 bool target_able(MONSTER_IDX m_idx)
204 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
206 /* Monster must be alive */
207 if (!monster_is_valid(m_ptr)) return (FALSE);
209 /* Hack -- no targeting hallucinations */
210 if (p_ptr->image) return (FALSE);
212 /* Monster must be visible */
213 if (!m_ptr->ml) return (FALSE);
215 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
217 /* Monster must be projectable */
218 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
220 /* Hack -- Never target trappers */
221 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
231 * Update (if necessary) and verify (if possible) the target.
233 * We return TRUE if the target is "okay" and FALSE otherwise.
235 bool target_okay(void)
237 /* Accept stationary targets */
238 if (target_who < 0) return (TRUE);
240 /* Check moving targets */
243 /* Accept reasonable targets */
244 if (target_able(target_who))
246 monster_type *m_ptr = ¤t_floor_ptr->m_list[target_who];
248 /* Acquire monster location */
249 target_row = m_ptr->fy;
250 target_col = m_ptr->fx;
257 /* Assume no target */
263 * Hack -- help "select" a location (see below)
265 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
268 POSITION x2, y2, x3, y3, x4, y4;
269 POSITION_IDX b_i = -1, b_v = 9999;
272 /* Scan the locations */
273 for (i = 0; i < tmp_pos.n; i++)
279 /* Directed distance */
283 /* Verify quadrant */
284 if (dx && (x3 * dx <= 0)) continue;
285 if (dy && (y3 * dy <= 0)) continue;
290 /* Verify quadrant */
291 if (dy && !dx && (x4 > y4)) continue;
292 if (dx && !dy && (y4 > x4)) continue;
294 /* Approximate Double Distance */
295 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
297 /* Penalize location */
298 if ((b_i >= 0) && (v >= b_v)) continue;
306 * Hack -- determine if a given location is "interesting"
308 static bool target_set_accept(POSITION y, POSITION x)
311 OBJECT_IDX this_o_idx, next_o_idx = 0;
313 if (!(in_bounds(y, x))) return (FALSE);
315 /* Player grid is always interesting */
316 if (player_bold(y, x)) return (TRUE);
318 if (p_ptr->image) return (FALSE);
320 g_ptr = ¤t_floor_ptr->grid_array[y][x];
322 /* Visible monsters */
325 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
327 /* Visible monsters */
328 if (m_ptr->ml) return (TRUE);
331 /* Scan all objects in the grid */
332 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
335 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
336 next_o_idx = o_ptr->next_o_idx;
338 /* Memorized object */
339 if (o_ptr->marked & OM_FOUND) return (TRUE);
342 /* Interesting memorized features */
343 if (g_ptr->info & (CAVE_MARK))
345 /* Notice object features */
346 if (g_ptr->info & CAVE_OBJECT) return (TRUE);
348 /* Feature code (applying "mimic" field) */
349 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE)) return TRUE;
357 * Prepare the "temp" array for "target_set"
359 * Return the number of target_able monsters in the set.
361 static void target_set_prepare(BIT_FLAGS mode)
364 POSITION min_hgt, max_hgt, min_wid, max_wid;
366 if (mode & TARGET_KILL)
369 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
370 max_hgt = MIN((p_ptr->y + MAX_RANGE), current_floor_ptr->height - 1);
371 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
372 max_wid = MIN((p_ptr->x + MAX_RANGE), current_floor_ptr->width - 1);
374 else /* not targetting */
377 min_hgt = panel_row_min;
378 max_hgt = panel_row_max;
379 min_wid = panel_col_min;
380 max_wid = panel_col_max;
383 /* Reset "temp" array */
386 /* Scan the current panel */
387 for (y = min_hgt; y <= max_hgt; y++)
389 for (x = min_wid; x <= max_wid; x++)
393 /* Require "interesting" contents */
394 if (!target_set_accept(y, x)) continue;
396 g_ptr = ¤t_floor_ptr->grid_array[y][x];
398 /* Require target_able monsters for "TARGET_KILL" */
399 if ((mode & (TARGET_KILL)) && !target_able(g_ptr->m_idx)) continue;
401 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(¤t_floor_ptr->m_list[g_ptr->m_idx])) continue;
403 /* Save the location */
404 tmp_pos.x[tmp_pos.n] = x;
405 tmp_pos.y[tmp_pos.n] = y;
410 /* Set the sort hooks */
411 if (mode & (TARGET_KILL))
413 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
417 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_importance, ang_sort_swap_distance);
420 if (p_ptr->riding && target_pet && (tmp_pos.n > 1) && (mode & (TARGET_KILL)))
425 tmp_pos.y[0] = tmp_pos.y[1];
428 tmp_pos.x[0] = tmp_pos.x[1];
433 void target_set_prepare_look(void){
434 target_set_prepare(TARGET_LOOK);
439 * Evaluate number of kill needed to gain level
441 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
443 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
445 s32b exp_mon, exp_adv;
446 u32b exp_mon_frac, exp_adv_frac;
448 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
453 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
463 /* The monster's experience point (assuming average monster speed) */
464 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
466 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
469 /* Total experience value for next level */
470 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
472 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
474 /* Experience value need to get */
475 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
478 /* You need to kill at least one monster to get any experience */
479 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
480 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
482 /* Extract number of monsters needed */
483 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
485 /* If 999 or more monsters needed, only display "999". */
486 num = MIN(999, exp_adv_frac);
488 /* Display the number */
489 sprintf(buf,"%03ld", (long int)num);
493 bool show_gold_on_floor = FALSE;
496 * Examine a grid, return a keypress.
498 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
499 * indicates that the "space" key should scan through the contents
500 * of the grid, instead of simply returning immediately. This lets
501 * the "look" command get complete information, without making the
502 * "target" command annoying.
504 * The "info" argument contains the "commands" which should be shown
505 * inside the "[xxx]" text. This string must never be empty, or grids
506 * containing monsters will be displayed with an extra comma.
508 * Note that if a monster is in the grid, we update both the monster
509 * recall info and the health bar info to track that monster.
511 * Eventually, we may allow multiple objects per grid, or objects
512 * and terrain features in the same grid.
514 * This function must handle blindness/hallucination.
516 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
518 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
519 OBJECT_IDX this_o_idx, next_o_idx = 0;
520 concptr s1 = "", s2 = "", s3 = "", x_info = "";
525 char out_val[MAX_NLEN+80];
526 OBJECT_IDX floor_list[23];
527 ITEM_NUMBER floor_num = 0;
529 /* Scan all objects in the grid */
532 floor_num = scan_floor(floor_list, y, x, 0x02);
536 x_info = _("x物 ", "x,");
540 /* Hack -- under the player */
541 if (player_bold(y, x))
554 s1 = _("ターゲット:", "Target:");
557 /* Hack -- hallucination */
560 concptr name = _("何か奇妙な物", "something strange");
562 /* Display a message */
564 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
566 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
570 move_cursor_relative(y, x);
573 /* Stop on everything but "return" */
574 if ((query != '\r') && (query != '\n')) return query;
581 /* Actual monsters */
582 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
584 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
585 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
586 GAME_TEXT m_name[MAX_NLEN];
592 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
593 monster_race_track(m_ptr->ap_r_idx);
594 health_track(g_ptr->m_idx);
607 /* Recall on screen */
608 screen_roff(m_ptr->ap_r_idx, 0);
610 /* Hack -- Complete the prompt (again) */
611 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
618 /* Normal commands */
619 if (query != 'r') break;
624 /* Cleare recall text and repeat */
630 /* Describe, and prompt for recall */
631 evaluate_monster_exp(acount, m_ptr);
634 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);
636 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);
642 move_cursor_relative(y, x);
647 /* Normal commands */
648 if (query != 'r') break;
654 /* Always stop at "normal" keys */
655 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
657 /* Sometimes stop at "space" key */
658 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
660 /* Change the intro */
661 s1 = _("それは", "It is ");
663 /* Hack -- take account of gender */
664 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
665 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
667 /* Use a preposition */
676 /* Scan all objects being carried */
677 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
679 GAME_TEXT o_name[MAX_NLEN];
682 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
683 next_o_idx = o_ptr->next_o_idx;
685 /* Obtain an object description */
686 object_desc(o_name, o_ptr, 0);
689 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
691 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
695 move_cursor_relative(y, x);
698 /* Always stop at "normal" keys */
699 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
701 /* Sometimes stop at "space" key */
702 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
704 /* Change the intro */
705 s2 = _("をまた", "also carrying ");
708 /* Use a preposition */
725 GAME_TEXT o_name[MAX_NLEN];
728 o_ptr = ¤t_floor_ptr->o_list[floor_list[0]];
730 object_desc(o_name, o_ptr, 0);
733 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
735 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
739 move_cursor_relative(y, x);
748 /* Provide one cushion before item listing */
751 /* Display rough information about items */
753 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
755 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
759 move_cursor_relative(y, x);
764 /* No request for listing */
765 if (query != 'x' && query != ' ') return query;
769 /** Display list of items **/
771 /* Continue scrolling list if requested */
779 show_gold_on_floor = TRUE;
780 (void)show_floor(0, y, x, &min_width);
781 show_gold_on_floor = FALSE;
785 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
787 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
794 /* Exit unless 'Enter' */
795 if (query != '\n' && query != '\r')
800 /* Get the object being moved. */
801 o_idx = g_ptr->o_idx;
803 /* Only rotate a pile of two or more objects. */
804 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
806 /* Remove the first object from the list. */
807 excise_object_idx(o_idx);
809 /* Find end of the list. */
811 while (current_floor_ptr->o_list[i].next_o_idx)
812 i = current_floor_ptr->o_list[i].next_o_idx;
814 /* Add after the last object. */
815 current_floor_ptr->o_list[i].next_o_idx = o_idx;
817 /* Loop and re-display the list */
824 /* Scan all objects in the grid */
825 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
828 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
829 next_o_idx = o_ptr->next_o_idx;
831 if (o_ptr->marked & OM_FOUND)
833 GAME_TEXT o_name[MAX_NLEN];
838 /* Obtain an object description */
839 object_desc(o_name, o_ptr, 0);
842 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
844 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
848 move_cursor_relative(y, x);
851 /* Always stop at "normal" keys */
852 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
854 /* Sometimes stop at "space" key */
855 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
857 /* Change the intro */
858 s1 = _("それは", "It is ");
861 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
875 /* Feature code (applying "mimic" field) */
876 feat = get_feat_mimic(g_ptr);
878 /* Require knowledge about grid, or ability to see grid */
879 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
885 f_ptr = &f_info[feat];
887 /* Terrain feature if needed */
888 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
892 /* Hack -- special handling for quest entrances */
893 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
895 /* Set the quest number temporary */
896 IDX old_quest = p_ptr->inside_quest;
900 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
903 p_ptr->inside_quest = g_ptr->special;
905 /* Get the quest text */
906 init_flags = INIT_NAME_ONLY;
908 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
910 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
911 quest[g_ptr->special].name, quest[g_ptr->special].level);
913 /* Reset the old quest number */
914 p_ptr->inside_quest = old_quest;
917 /* Hack -- special handling for building doors */
918 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
920 name = building[f_ptr->subtype].name;
922 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
924 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
926 else if (have_flag(f_ptr->flags, FF_TOWN))
928 name = town_info[g_ptr->special].name;
930 else if (p_ptr->wild_mode && (feat == feat_floor))
932 name = _("道", "road");
936 name = f_name + f_ptr->name;
942 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
943 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
944 have_flag(f_ptr->flags, FF_TOWN)))
949 /* Hack -- special introduction for store & building doors -KMW- */
950 if (have_flag(f_ptr->flags, FF_STORE) ||
951 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
952 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
953 have_flag(f_ptr->flags, FF_ENTRANCE))
958 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
959 have_flag(f_ptr->flags, FF_TOWN) ||
960 have_flag(f_ptr->flags, FF_SHALLOW) ||
961 have_flag(f_ptr->flags, FF_DEEP))
967 /* Pick proper indefinite article */
968 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
972 /* Display a message */
976 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
977 else sprintf(f_idx_str, "%d", g_ptr->feat);
979 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]);
981 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);
986 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
988 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
992 move_cursor_relative(y, x);
995 /* Always stop at "normal" keys */
996 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
999 /* Stop on everything but "return" */
1000 if ((query != '\r') && (query != '\n')) return query;
1002 /* Repeat forever */
1008 * Handle "target" and "look".
1010 * Note that this code can be called from "get_aim_dir()".
1012 * All locations must be on the current panel. Consider the use of
1013 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1014 * some form of "scrolling" the map around the cursor.
1015 * That is, consider the possibility of "auto-scrolling" the screen
1016 * while the cursor moves around. This may require changes in the
1017 * "update_monster()" code to allow "visibility" even if off panel, and
1018 * may require dynamic recalculation of the "temp" grid set.
1020 * Hack -- targeting/observing an "outer border grid" may induce
1021 * problems, so this is not currently allowed.
1023 * The player can use the direction keys to move among "interesting"
1024 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1025 * move through the "interesting" grids in a sequential manner, or
1026 * can enter "location" mode, and use the direction keys to move one
1027 * grid at a time in any direction. The "t" (set target) command will
1028 * only target a monster (as opposed to a location) if the monster is
1029 * target_able and the "interesting" mode is being used.
1031 * The current grid is described using the "look" method above, and
1032 * a new command may be entered at any time, but note that if the
1033 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1034 * where "space" has no obvious meaning) then "space" will scan
1035 * through the description of the current grid until done, instead
1036 * of immediately jumping to the next "interesting" grid. This
1037 * allows the "target" command to retain its old semantics.
1039 * The "*", "+", and "-" keys may always be used to jump immediately
1040 * to the next (or previous) interesting grid, in the proper mode.
1042 * The "return" key may always be used to scan through a complete
1043 * grid description (forever).
1045 * This command will cancel any old target, even if used from
1046 * inside the "look" command.
1048 bool target_set(BIT_FLAGS mode)
1051 POSITION y = p_ptr->y;
1052 POSITION x = p_ptr->x;
1062 get_screen_size(&wid, &hgt);
1067 if (rogue_like_commands)
1076 /* Prepare the "temp" array */
1077 target_set_prepare(mode);
1079 /* Start near the player */
1085 /* Interesting grids */
1086 if (flag && tmp_pos.n)
1092 change_panel_xy(y, x);
1094 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1097 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1100 if (target_able(g_ptr->m_idx))
1102 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1105 /* Dis-allow target */
1108 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1114 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1115 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1116 strcat(info, cheatinfo);
1119 /* Describe and Prompt */
1121 query = target_set_aux(y, x, mode, info);
1125 /* Assume no "direction" */
1130 if (query == '\r') query = 't';
1148 if (target_able(g_ptr->m_idx))
1150 health_track(g_ptr->m_idx);
1151 target_who = g_ptr->m_idx;
1167 if (++m == tmp_pos.n)
1170 if (!expand_list) done = TRUE;
1180 if (!expand_list) done = TRUE;
1187 /* Recenter the map around the player */
1189 p_ptr->update |= (PU_MONSTERS);
1190 p_ptr->redraw |= (PR_MAP);
1191 p_ptr->window |= (PW_OVERHEAD);
1194 /* Recalculate interesting grids */
1195 target_set_prepare(mode);
1214 if(query == same_key)
1216 if (++m == tmp_pos.n)
1219 if (!expand_list) done = TRUE;
1224 /* Extract the action (if any) */
1225 d = get_keymap_dir(query);
1232 /* Hack -- move around */
1235 /* Modified to scroll to monster */
1236 POSITION y2 = panel_row_min;
1237 POSITION x2 = panel_col_min;
1239 /* Find a new monster */
1240 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
1242 /* Request to target past last interesting grid */
1243 while (flag && (i < 0))
1245 /* Note the change */
1246 if (change_panel(ddy[d], ddx[d]))
1248 int v = tmp_pos.y[m];
1249 int u = tmp_pos.x[m];
1251 /* Recalculate interesting grids */
1252 target_set_prepare(mode);
1254 /* Look at interesting grids */
1257 /* Find a new monster */
1258 i = target_pick(v, u, ddy[d], ddx[d]);
1264 /* Nothing interesting */
1267 POSITION dx = ddx[d];
1268 POSITION dy = ddy[d];
1270 /* Restore previous position */
1273 panel_bounds_center();
1275 p_ptr->update |= (PU_MONSTERS);
1276 p_ptr->redraw |= (PR_MAP);
1277 p_ptr->window |= (PW_OVERHEAD);
1280 /* Recalculate interesting grids */
1281 target_set_prepare(mode);
1283 /* Look at boring grids */
1290 /* Do not move horizontally if unnecessary */
1291 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1292 ((x > panel_col_min + wid / 2) && (dx < 0)))
1297 /* Do not move vertically if unnecessary */
1298 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1299 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1304 /* Apply the motion */
1305 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1306 (x >= panel_col_min+wid) || (x < panel_col_min))
1308 if (change_panel(dy, dx)) target_set_prepare(mode);
1311 /* Slide into legality */
1312 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1313 else if (x <= 0) x = 1;
1315 /* Slide into legality */
1316 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1317 else if (y <= 0) y = 1;
1326 /* Arbitrary grids */
1329 bool move_fast = FALSE;
1331 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1334 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1336 /* Default prompt */
1337 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1342 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1343 los(p_ptr->y, p_ptr->x, y, x),
1344 projectable(p_ptr->y, p_ptr->x, y, x));
1345 strcat(info, cheatinfo);
1348 /* Describe and Prompt (enable "TARGET_LOOK") */
1349 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1351 /* Assume no direction */
1356 if (query == '\r') query = 't';
1359 /* Analyze the keypress */
1383 /* Recenter the map around the player */
1385 p_ptr->update |= (PU_MONSTERS);
1386 p_ptr->redraw |= (PR_MAP);
1387 p_ptr->window |= (PW_OVERHEAD);
1390 /* Recalculate interesting grids */
1391 target_set_prepare(mode);
1413 /* Pick a nearby monster */
1414 for (i = 0; i < tmp_pos.n; i++)
1416 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1426 /* Nothing interesting */
1427 if (bd == 999) flag = FALSE;
1434 /* Extract the action (if any) */
1435 d = get_keymap_dir(query);
1437 /* XTRA HACK MOVEFAST */
1438 if (isupper(query)) move_fast = TRUE;
1445 /* Handle "direction" */
1448 POSITION dx = ddx[d];
1449 POSITION dy = ddy[d];
1451 /* XTRA HACK MOVEFAST */
1454 int mag = MIN(wid / 2, hgt / 2);
1464 /* Do not move horizontally if unnecessary */
1465 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1466 ((x > panel_col_min + wid / 2) && (dx < 0)))
1471 /* Do not move vertically if unnecessary */
1472 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1473 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1478 /* Apply the motion */
1479 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1480 (x >= panel_col_min + wid) || (x < panel_col_min))
1482 if (change_panel(dy, dx)) target_set_prepare(mode);
1485 /* Slide into legality */
1486 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1487 else if (x <= 0) x = 1;
1489 /* Slide into legality */
1490 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1491 else if (y <= 0) y = 1;
1499 /* Clear the top line */
1502 /* Recenter the map around the player */
1504 p_ptr->update |= (PU_MONSTERS);
1505 p_ptr->redraw |= (PR_MAP);
1506 p_ptr->window |= (PW_OVERHEAD);
1509 /* Failure to set target */
1510 if (!target_who) return (FALSE);
1518 * Get an "aiming direction" from the user.
1520 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1521 * "0" for "current target", and "-1" for "entry aborted".
1523 * Note that "Force Target", if set, will pre-empt user interaction,
1524 * if there is a usable target already set.
1526 * Note that confusion over-rides any (explicit?) user choice.
1528 bool get_aim_dir(DIRECTION *dp)
1537 /* Global direction */
1540 /* Hack -- auto-target if requested */
1541 if (use_old_target && target_okay()) dir = 5;
1543 if (repeat_pull(&code))
1548 if (!(code == 5 && !target_okay()))
1550 /* return (TRUE); */
1551 dir = (DIRECTION)code;
1554 *dp = (DIRECTION)code;
1556 /* Ask until satisfied */
1559 /* Choose a prompt */
1562 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1566 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
1569 /* Get a command (or Cancel) */
1570 if (!get_com(p, &command, TRUE)) break;
1574 if (command == '\r') command = 't';
1577 /* Convert various keys to "standard" keys */
1580 /* Use current target */
1591 /* Set new target */
1596 if (target_set(TARGET_KILL)) dir = 5;
1602 /* Extract the action (if any) */
1603 dir = get_keymap_dir(command);
1609 /* Verify requested targets */
1610 if ((dir == 5) && !target_okay()) dir = 0;
1619 project_length = 0; /* reset to default */
1623 /* Save the direction */
1626 /* Check for confusion */
1627 if (p_ptr->confused)
1629 /* Random direction */
1630 dir = ddd[randint0(8)];
1633 /* Notice confusion */
1634 if (command_dir != dir)
1637 msg_print(_("あなたは混乱している。", "You are confused."));
1640 /* Save direction */
1643 /* repeat_push(dir); */
1644 repeat_push((COMMAND_CODE)command_dir);
1646 /* A "valid" direction was entered */
1651 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
1659 /* Global direction */
1662 if (repeat_pull(&code))
1664 dir = (DIRECTION)code;
1665 /* return (TRUE); */
1667 *dp = (DIRECTION)code;
1671 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1675 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1678 /* Get a direction */
1683 /* Get a command (or Cancel) */
1684 if (!get_com(prompt, &ch, TRUE)) break;
1687 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1693 /* Look up the direction */
1694 dir = get_keymap_dir(ch);
1700 /* Prevent weirdness */
1701 if ((dir == 5) && (!allow_under)) dir = 0;
1704 if (!dir) return (FALSE);
1706 /* Save desired direction */
1709 /* Apply "confusion" */
1710 if (p_ptr->confused)
1712 /* Standard confusion */
1713 if (randint0(100) < 75)
1715 /* Random direction */
1716 dir = ddd[randint0(8)];
1719 else if (p_ptr->riding && with_steed)
1721 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1722 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1724 if (MON_CONFUSED(m_ptr))
1726 /* Standard confusion */
1727 if (randint0(100) < 75)
1729 /* Random direction */
1730 dir = ddd[randint0(8)];
1733 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1735 /* Random direction */
1736 dir = ddd[randint0(8)];
1738 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1740 /* Random direction */
1741 dir = ddd[randint0(8)];
1745 /* Notice confusion */
1746 if (command_dir != dir)
1748 if (p_ptr->confused)
1751 msg_print(_("あなたは混乱している。", "You are confused."));
1755 GAME_TEXT m_name[MAX_NLEN];
1756 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1758 monster_desc(m_name, m_ptr, 0);
1759 if (MON_CONFUSED(m_ptr))
1761 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1765 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1770 /* Save direction */
1773 /* repeat_push(dir); */
1774 repeat_push((COMMAND_CODE)command_dir);
1781 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
1782 * and place it into "command_dir", unless we already have one.
1784 * This function should be used for all "repeatable" commands, such as
1785 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
1786 * as all commands which must reference a grid adjacent to the player,
1787 * and which may not reference the grid under the player. Note that,
1788 * for example, it is no longer possible to "disarm" or "open" chests
1789 * in the same grid as the player.
1791 * Direction "5" is illegal and will (cleanly) abort the command.
1793 * This function tracks and uses the "global direction", and uses
1794 * that as the "desired direction", to which "confusion" is applied.
1796 bool get_rep_dir(DIRECTION *dp, bool under)
1804 /* Global direction */
1807 if (repeat_pull(&code))
1809 dir = (DIRECTION)code;
1810 /* return (TRUE); */
1812 *dp = (DIRECTION)code;
1816 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1820 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1823 /* Get a direction */
1828 /* Get a command (or Cancel) */
1829 if (!get_com(prompt, &ch, TRUE)) break;
1832 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1838 /* Look up the direction */
1839 dir = get_keymap_dir(ch);
1845 /* Prevent weirdness */
1846 if ((dir == 5) && (!under)) dir = 0;
1849 if (!dir) return (FALSE);
1851 /* Save desired direction */
1854 /* Apply "confusion" */
1855 if (p_ptr->confused)
1857 /* Standard confusion */
1858 if (randint0(100) < 75)
1860 /* Random direction */
1861 dir = ddd[randint0(8)];
1864 else if (p_ptr->riding)
1866 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1867 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1869 if (MON_CONFUSED(m_ptr))
1871 /* Standard confusion */
1872 if (randint0(100) < 75)
1874 /* Random direction */
1875 dir = ddd[randint0(8)];
1878 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1880 /* Random direction */
1881 dir = ddd[randint0(8)];
1883 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1885 /* Random direction */
1886 dir = ddd[randint0(8)];
1890 /* Notice confusion */
1891 if (command_dir != dir)
1893 if (p_ptr->confused)
1896 msg_print(_("あなたは混乱している。", "You are confused."));
1900 GAME_TEXT m_name[MAX_NLEN];
1901 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1903 monster_desc(m_name, m_ptr, 0);
1904 if (MON_CONFUSED(m_ptr))
1906 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1910 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1915 /* Save direction */
1918 /* repeat_push(dir); */
1919 repeat_push((COMMAND_CODE)command_dir);
1927 * XAngband: determine if a given location is "interesting"
1928 * based on target_set_accept function.
1930 static bool tgt_pt_accept(POSITION y, POSITION x)
1934 if (!(in_bounds(y, x))) return (FALSE);
1936 /* Player grid is always interesting */
1937 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
1939 if (p_ptr->image) return (FALSE);
1941 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1943 /* Interesting memorized features */
1944 if (g_ptr->info & (CAVE_MARK))
1947 if (cave_have_flag_grid(g_ptr, FF_LESS)) return (TRUE);
1948 if (cave_have_flag_grid(g_ptr, FF_MORE)) return (TRUE);
1950 /* Notice quest features */
1951 if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return (TRUE);
1952 if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return (TRUE);
1960 * XAngband: Prepare the "temp" array for "tget_pt"
1961 * based on target_set_prepare funciton.
1963 static void tgt_pt_prepare(void)
1967 /* Reset "temp" array */
1970 if (!expand_list) return;
1972 /* Scan the current panel */
1973 for (y = 1; y < current_floor_ptr->height; y++)
1975 for (x = 1; x < current_floor_ptr->width; x++)
1977 /* Require "interesting" contents */
1978 if (!tgt_pt_accept(y, x)) continue;
1980 /* Save the location */
1981 tmp_pos.x[tmp_pos.n] = x;
1982 tmp_pos.y[tmp_pos.n] = y;
1987 /* Sort the positions */
1988 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
1992 * old -- from PsiAngband.
1994 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
1999 bool success = FALSE;
2003 get_screen_size(&wid, &hgt);
2013 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2014 msg_flag = FALSE; /* prevents "-more-" message. */
2016 while ((ch != ESCAPE) && !success)
2018 bool move_fast = FALSE;
2020 move_cursor_relative(y, x);
2032 if (player_bold(y, x)) ch = 0;
2035 else success = TRUE;
2039 /* XAngband: Move cursor to stairs */
2042 if (expand_list && tmp_pos.n)
2045 int cx = (panel_col_min + panel_col_max) / 2;
2046 int cy = (panel_row_min + panel_row_max) / 2;
2050 /* Skip stairs which have defferent distance */
2051 for (; n < tmp_pos.n; ++ n)
2053 grid_type *g_ptr = ¤t_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
2055 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2056 cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2063 if (n == tmp_pos.n) /* Loop out taget list */
2068 verify_panel(); /* Move cursor to player */
2070 p_ptr->update |= (PU_MONSTERS);
2072 p_ptr->redraw |= (PR_MAP);
2074 p_ptr->window |= (PW_OVERHEAD);
2077 else /* move cursor to next stair and change panel */
2082 dy = 2 * (y - cy) / hgt;
2083 dx = 2 * (x - cx) / wid;
2084 if (dy || dx) change_panel(dy, dx);
2090 /* Look up the direction */
2091 d = get_keymap_dir(ch);
2093 /* XTRA HACK MOVEFAST */
2094 if (isupper(ch)) move_fast = TRUE;
2096 /* Handle "direction" */
2102 /* XTRA HACK MOVEFAST */
2105 int mag = MIN(wid / 2, hgt / 2);
2115 /* Do not move horizontally if unnecessary */
2116 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2117 ((x > panel_col_min + wid / 2) && (dx < 0)))
2122 /* Do not move vertically if unnecessary */
2123 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2124 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2129 /* Apply the motion */
2130 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2131 (x >= panel_col_min + wid) || (x < panel_col_min))
2133 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2134 change_panel(dy, dx);
2137 /* Slide into legality */
2138 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
2139 else if (x <= 0) x = 1;
2141 /* Slide into legality */
2142 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
2143 else if (y <= 0) y = 1;
2150 /* Clear the top line */
2153 /* Recenter the map around the player */
2156 p_ptr->update |= (PU_MONSTERS);
2158 p_ptr->redraw |= (PR_MAP);
2160 p_ptr->window |= (PW_OVERHEAD);
2169 bool get_hack_dir(DIRECTION *dp)
2177 /* Global direction */
2180 /* (No auto-targeting) */
2182 /* Ask until satisfied */
2185 /* Choose a prompt */
2188 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2192 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2195 /* Get a command (or Cancel) */
2196 if (!get_com(p, &command, TRUE)) break;
2200 if (command == '\r') command = 't';
2203 /* Convert various keys to "standard" keys */
2206 /* Use current target */
2217 /* Set new target */
2222 if (target_set(TARGET_KILL)) dir = 5;
2228 /* Look up the direction */
2229 dir = get_keymap_dir(command);
2235 /* Verify requested targets */
2236 if ((dir == 5) && !target_okay()) dir = 0;
2243 if (!dir) return (FALSE);
2245 /* Save the direction */
2248 /* Check for confusion */
2249 if (p_ptr->confused)
2251 /* Random direction */
2252 dir = ddd[randint0(8)];
2255 /* Notice confusion */
2256 if (command_dir != dir)
2259 msg_print(_("あなたは混乱している。", "You are confused."));
2262 /* Save direction */
2265 /* A "valid" direction was entered */