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"
37 * @brief コンソール上におけるマップ表示の左上位置を返す /
38 * Calculates current boundaries Called below and from "do_cmd_locate()".
41 void panel_bounds_center(void)
45 get_screen_size(&wid, &hgt);
47 panel_row_max = panel_row_min + hgt - 1;
48 panel_row_prt = panel_row_min - 1;
49 panel_col_max = panel_col_min + wid - 1;
50 panel_col_prt = panel_col_min - 13;
54 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
58 * Handle a request to change the current panel
59 * Return TRUE if the panel was changed.
60 * Also used in do_cmd_locate
61 * @return 実際に再描画が必要だった場合TRUEを返す
63 static bool change_panel_xy(POSITION y, POSITION x)
65 POSITION dy = 0, dx = 0;
68 get_screen_size(&wid, &hgt);
70 if (y < panel_row_min) dy = -1;
71 if (y > panel_row_max) dy = 1;
72 if (x < panel_col_min) dx = -1;
73 if (x > panel_col_max) dx = 1;
75 if (!dy && !dx) return (FALSE);
77 return change_panel(dy, dx);
82 * @brief マップ描画のフォーカスを当てるべき座標を更新する
84 * Given an row (y) and col (x), this routine detects when a move
85 * off the screen has occurred and figures new borders. -RAK-
86 * "Update" forces a "full update" to take place.
87 * The map is reprinted if necessary, and "TRUE" is returned.
88 * @return 実際に再描画が必要だった場合TRUEを返す
90 void verify_panel(void)
92 POSITION y = p_ptr->y;
93 POSITION x = p_ptr->x;
101 get_screen_size(&wid, &hgt);
103 max_prow_min = current_floor_ptr->height - hgt;
104 max_pcol_min = current_floor_ptr->width - wid;
106 /* Bounds checking */
107 if (max_prow_min < 0) max_prow_min = 0;
108 if (max_pcol_min < 0) max_pcol_min = 0;
110 /* Center on player */
111 if (center_player && (center_running || !running))
113 /* Center vertically */
114 prow_min = y - hgt / 2;
115 if (prow_min < 0) prow_min = 0;
116 else if (prow_min > max_prow_min) prow_min = max_prow_min;
118 /* Center horizontally */
119 pcol_min = x - wid / 2;
120 if (pcol_min < 0) pcol_min = 0;
121 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
125 prow_min = panel_row_min;
126 pcol_min = panel_col_min;
128 /* Scroll screen when 2 grids from top/bottom edge */
129 if (y > panel_row_max - 2)
131 while (y > prow_min + hgt-1 - 2)
133 prow_min += (hgt / 2);
137 if (y < panel_row_min + 2)
139 while (y < prow_min + 2)
141 prow_min -= (hgt / 2);
145 if (prow_min > max_prow_min) prow_min = max_prow_min;
146 if (prow_min < 0) prow_min = 0;
148 /* Scroll screen when 4 grids from left/right edge */
149 if (x > panel_col_max - 4)
151 while (x > pcol_min + wid-1 - 4)
153 pcol_min += (wid / 2);
157 if (x < panel_col_min + 4)
159 while (x < pcol_min + 4)
161 pcol_min -= (wid / 2);
165 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
166 if (pcol_min < 0) pcol_min = 0;
169 /* Check for "no change" */
170 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
172 /* Save the new panel info */
173 panel_row_min = prow_min;
174 panel_col_min = pcol_min;
176 /* Hack -- optional disturb on "panel change" */
177 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
179 panel_bounds_center();
181 p_ptr->update |= (PU_MONSTERS);
182 p_ptr->redraw |= (PR_MAP);
183 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
187 /*** Targeting Code ***/
190 * Determine is a monster makes a reasonable target
192 * The concept of "targeting" was stolen from "Morgul" (?)
194 * The player can target any location, or any "target-able" monster.
196 * Currently, a monster is "target_able" if it is visible, and if
197 * the player can hit it with a projection, and the player is not
198 * hallucinating. This allows use of "use closest target" macros.
200 * Future versions may restrict the ability to target "trappers"
201 * and "mimics", but the semantics is a little bit weird.
203 bool target_able(MONSTER_IDX m_idx)
205 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
207 /* Monster must be alive */
208 if (!monster_is_valid(m_ptr)) return (FALSE);
210 /* Hack -- no targeting hallucinations */
211 if (p_ptr->image) return (FALSE);
213 /* Monster must be visible */
214 if (!m_ptr->ml) return (FALSE);
216 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
218 /* Monster must be projectable */
219 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
221 /* Hack -- Never target trappers */
222 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
232 * Update (if necessary) and verify (if possible) the target.
234 * We return TRUE if the target is "okay" and FALSE otherwise.
236 bool target_okay(void)
238 /* Accept stationary targets */
239 if (target_who < 0) return (TRUE);
241 /* Check moving targets */
244 /* Accept reasonable targets */
245 if (target_able(target_who))
247 monster_type *m_ptr = ¤t_floor_ptr->m_list[target_who];
249 /* Acquire monster location */
250 target_row = m_ptr->fy;
251 target_col = m_ptr->fx;
258 /* Assume no target */
264 * Hack -- help "select" a location (see below)
266 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
269 POSITION x2, y2, x3, y3, x4, y4;
270 POSITION_IDX b_i = -1, b_v = 9999;
273 /* Scan the locations */
274 for (i = 0; i < tmp_pos.n; i++)
280 /* Directed distance */
284 /* Verify quadrant */
285 if (dx && (x3 * dx <= 0)) continue;
286 if (dy && (y3 * dy <= 0)) continue;
291 /* Verify quadrant */
292 if (dy && !dx && (x4 > y4)) continue;
293 if (dx && !dy && (y4 > x4)) continue;
295 /* Approximate Double Distance */
296 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
298 /* Penalize location */
299 if ((b_i >= 0) && (v >= b_v)) continue;
307 * Hack -- determine if a given location is "interesting"
309 static bool target_set_accept(POSITION y, POSITION x)
312 OBJECT_IDX this_o_idx, next_o_idx = 0;
314 if (!(in_bounds(y, x))) return (FALSE);
316 /* Player grid is always interesting */
317 if (player_bold(y, x)) return (TRUE);
319 if (p_ptr->image) return (FALSE);
321 g_ptr = ¤t_floor_ptr->grid_array[y][x];
323 /* Visible monsters */
326 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
328 /* Visible monsters */
329 if (m_ptr->ml) return (TRUE);
332 /* Scan all objects in the grid */
333 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
336 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
337 next_o_idx = o_ptr->next_o_idx;
339 /* Memorized object */
340 if (o_ptr->marked & OM_FOUND) return (TRUE);
343 /* Interesting memorized features */
344 if (g_ptr->info & (CAVE_MARK))
346 /* Notice object features */
347 if (g_ptr->info & CAVE_OBJECT) return (TRUE);
349 /* Feature code (applying "mimic" field) */
350 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE)) return TRUE;
358 * Prepare the "temp" array for "target_set"
360 * Return the number of target_able monsters in the set.
362 static void target_set_prepare(BIT_FLAGS mode)
365 POSITION min_hgt, max_hgt, min_wid, max_wid;
367 if (mode & TARGET_KILL)
370 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
371 max_hgt = MIN((p_ptr->y + MAX_RANGE), current_floor_ptr->height - 1);
372 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
373 max_wid = MIN((p_ptr->x + MAX_RANGE), current_floor_ptr->width - 1);
375 else /* not targetting */
378 min_hgt = panel_row_min;
379 max_hgt = panel_row_max;
380 min_wid = panel_col_min;
381 max_wid = panel_col_max;
384 /* Reset "temp" array */
387 /* Scan the current panel */
388 for (y = min_hgt; y <= max_hgt; y++)
390 for (x = min_wid; x <= max_wid; x++)
394 /* Require "interesting" contents */
395 if (!target_set_accept(y, x)) continue;
397 g_ptr = ¤t_floor_ptr->grid_array[y][x];
399 /* Require target_able monsters for "TARGET_KILL" */
400 if ((mode & (TARGET_KILL)) && !target_able(g_ptr->m_idx)) continue;
402 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(¤t_floor_ptr->m_list[g_ptr->m_idx])) continue;
404 /* Save the location */
405 tmp_pos.x[tmp_pos.n] = x;
406 tmp_pos.y[tmp_pos.n] = y;
411 /* Set the sort hooks */
412 if (mode & (TARGET_KILL))
414 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
418 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_importance, ang_sort_swap_distance);
421 if (p_ptr->riding && target_pet && (tmp_pos.n > 1) && (mode & (TARGET_KILL)))
426 tmp_pos.y[0] = tmp_pos.y[1];
429 tmp_pos.x[0] = tmp_pos.x[1];
434 void target_set_prepare_look(void){
435 target_set_prepare(TARGET_LOOK);
440 * Evaluate number of kill needed to gain level
442 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
444 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
446 s32b exp_mon, exp_adv;
447 u32b exp_mon_frac, exp_adv_frac;
449 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
454 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
464 /* The monster's experience point (assuming average monster speed) */
465 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
467 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
470 /* Total experience value for next level */
471 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
473 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
475 /* Experience value need to get */
476 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
479 /* You need to kill at least one monster to get any experience */
480 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
481 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
483 /* Extract number of monsters needed */
484 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
486 /* If 999 or more monsters needed, only display "999". */
487 num = MIN(999, exp_adv_frac);
489 /* Display the number */
490 sprintf(buf,"%03ld", (long int)num);
494 bool show_gold_on_floor = FALSE;
497 * Examine a grid, return a keypress.
499 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
500 * indicates that the "space" key should scan through the contents
501 * of the grid, instead of simply returning immediately. This lets
502 * the "look" command get complete information, without making the
503 * "target" command annoying.
505 * The "info" argument contains the "commands" which should be shown
506 * inside the "[xxx]" text. This string must never be empty, or grids
507 * containing monsters will be displayed with an extra comma.
509 * Note that if a monster is in the grid, we update both the monster
510 * recall info and the health bar info to track that monster.
512 * Eventually, we may allow multiple objects per grid, or objects
513 * and terrain features in the same grid.
515 * This function must handle blindness/hallucination.
517 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
519 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
520 OBJECT_IDX this_o_idx, next_o_idx = 0;
521 concptr s1 = "", s2 = "", s3 = "", x_info = "";
526 char out_val[MAX_NLEN+80];
527 OBJECT_IDX floor_list[23];
528 ITEM_NUMBER floor_num = 0;
530 /* Scan all objects in the grid */
533 floor_num = scan_floor(floor_list, y, x, 0x02);
537 x_info = _("x物 ", "x,");
541 /* Hack -- under the player */
542 if (player_bold(y, x))
555 s1 = _("ターゲット:", "Target:");
558 /* Hack -- hallucination */
561 concptr name = _("何か奇妙な物", "something strange");
563 /* Display a message */
565 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
567 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
571 move_cursor_relative(y, x);
574 /* Stop on everything but "return" */
575 if ((query != '\r') && (query != '\n')) return query;
582 /* Actual monsters */
583 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
585 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
586 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
587 GAME_TEXT m_name[MAX_NLEN];
593 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
594 monster_race_track(m_ptr->ap_r_idx);
595 health_track(g_ptr->m_idx);
608 /* Recall on screen */
609 screen_roff(m_ptr->ap_r_idx, 0);
611 /* Hack -- Complete the prompt (again) */
612 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
619 /* Normal commands */
620 if (query != 'r') break;
625 /* Cleare recall text and repeat */
631 /* Describe, and prompt for recall */
632 evaluate_monster_exp(acount, m_ptr);
635 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);
637 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);
643 move_cursor_relative(y, x);
648 /* Normal commands */
649 if (query != 'r') break;
655 /* Always stop at "normal" keys */
656 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
658 /* Sometimes stop at "space" key */
659 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
661 /* Change the intro */
662 s1 = _("それは", "It is ");
664 /* Hack -- take account of gender */
665 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
666 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
668 /* Use a preposition */
677 /* Scan all objects being carried */
678 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
680 GAME_TEXT o_name[MAX_NLEN];
683 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
684 next_o_idx = o_ptr->next_o_idx;
686 /* Obtain an object description */
687 object_desc(o_name, o_ptr, 0);
690 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
692 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
696 move_cursor_relative(y, x);
699 /* Always stop at "normal" keys */
700 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
702 /* Sometimes stop at "space" key */
703 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
705 /* Change the intro */
706 s2 = _("をまた", "also carrying ");
709 /* Use a preposition */
726 GAME_TEXT o_name[MAX_NLEN];
729 o_ptr = ¤t_floor_ptr->o_list[floor_list[0]];
731 object_desc(o_name, o_ptr, 0);
734 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
736 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
740 move_cursor_relative(y, x);
749 /* Provide one cushion before item listing */
752 /* Display rough information about items */
754 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
756 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
760 move_cursor_relative(y, x);
765 /* No request for listing */
766 if (query != 'x' && query != ' ') return query;
770 /** Display list of items **/
772 /* Continue scrolling list if requested */
780 show_gold_on_floor = TRUE;
781 (void)show_floor(0, y, x, &min_width);
782 show_gold_on_floor = FALSE;
786 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
788 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
795 /* Exit unless 'Enter' */
796 if (query != '\n' && query != '\r')
801 /* Get the object being moved. */
802 o_idx = g_ptr->o_idx;
804 /* Only rotate a pile of two or more objects. */
805 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
807 /* Remove the first object from the list. */
808 excise_object_idx(o_idx);
810 /* Find end of the list. */
812 while (current_floor_ptr->o_list[i].next_o_idx)
813 i = current_floor_ptr->o_list[i].next_o_idx;
815 /* Add after the last object. */
816 current_floor_ptr->o_list[i].next_o_idx = o_idx;
818 /* Loop and re-display the list */
825 /* Scan all objects in the grid */
826 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
829 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
830 next_o_idx = o_ptr->next_o_idx;
832 if (o_ptr->marked & OM_FOUND)
834 GAME_TEXT o_name[MAX_NLEN];
839 /* Obtain an object description */
840 object_desc(o_name, o_ptr, 0);
843 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
845 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
849 move_cursor_relative(y, x);
852 /* Always stop at "normal" keys */
853 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
855 /* Sometimes stop at "space" key */
856 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
858 /* Change the intro */
859 s1 = _("それは", "It is ");
862 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
876 /* Feature code (applying "mimic" field) */
877 feat = get_feat_mimic(g_ptr);
879 /* Require knowledge about grid, or ability to see grid */
880 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
886 f_ptr = &f_info[feat];
888 /* Terrain feature if needed */
889 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
893 /* Hack -- special handling for quest entrances */
894 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
896 /* Set the quest number temporary */
897 IDX old_quest = p_ptr->inside_quest;
901 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
904 p_ptr->inside_quest = g_ptr->special;
906 /* Get the quest text */
907 init_flags = INIT_NAME_ONLY;
909 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
911 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
912 quest[g_ptr->special].name, quest[g_ptr->special].level);
914 /* Reset the old quest number */
915 p_ptr->inside_quest = old_quest;
918 /* Hack -- special handling for building doors */
919 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
921 name = building[f_ptr->subtype].name;
923 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
925 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
927 else if (have_flag(f_ptr->flags, FF_TOWN))
929 name = town_info[g_ptr->special].name;
931 else if (p_ptr->wild_mode && (feat == feat_floor))
933 name = _("道", "road");
937 name = f_name + f_ptr->name;
943 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
944 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
945 have_flag(f_ptr->flags, FF_TOWN)))
950 /* Hack -- special introduction for store & building doors -KMW- */
951 if (have_flag(f_ptr->flags, FF_STORE) ||
952 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
953 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
954 have_flag(f_ptr->flags, FF_ENTRANCE))
959 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
960 have_flag(f_ptr->flags, FF_TOWN) ||
961 have_flag(f_ptr->flags, FF_SHALLOW) ||
962 have_flag(f_ptr->flags, FF_DEEP))
968 /* Pick proper indefinite article */
969 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
973 /* Display a message */
977 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
978 else sprintf(f_idx_str, "%d", g_ptr->feat);
980 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]);
982 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);
987 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
989 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
993 move_cursor_relative(y, x);
996 /* Always stop at "normal" keys */
997 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
1000 /* Stop on everything but "return" */
1001 if ((query != '\r') && (query != '\n')) return query;
1003 /* Repeat forever */
1009 * Handle "target" and "look".
1011 * Note that this code can be called from "get_aim_dir()".
1013 * All locations must be on the current panel. Consider the use of
1014 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1015 * some form of "scrolling" the map around the cursor.
1016 * That is, consider the possibility of "auto-scrolling" the screen
1017 * while the cursor moves around. This may require changes in the
1018 * "update_monster()" code to allow "visibility" even if off panel, and
1019 * may require dynamic recalculation of the "temp" grid set.
1021 * Hack -- targeting/observing an "outer border grid" may induce
1022 * problems, so this is not currently allowed.
1024 * The player can use the direction keys to move among "interesting"
1025 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1026 * move through the "interesting" grids in a sequential manner, or
1027 * can enter "location" mode, and use the direction keys to move one
1028 * grid at a time in any direction. The "t" (set target) command will
1029 * only target a monster (as opposed to a location) if the monster is
1030 * target_able and the "interesting" mode is being used.
1032 * The current grid is described using the "look" method above, and
1033 * a new command may be entered at any time, but note that if the
1034 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1035 * where "space" has no obvious meaning) then "space" will scan
1036 * through the description of the current grid until done, instead
1037 * of immediately jumping to the next "interesting" grid. This
1038 * allows the "target" command to retain its old semantics.
1040 * The "*", "+", and "-" keys may always be used to jump immediately
1041 * to the next (or previous) interesting grid, in the proper mode.
1043 * The "return" key may always be used to scan through a complete
1044 * grid description (forever).
1046 * This command will cancel any old target, even if used from
1047 * inside the "look" command.
1049 bool target_set(BIT_FLAGS mode)
1052 POSITION y = p_ptr->y;
1053 POSITION x = p_ptr->x;
1063 get_screen_size(&wid, &hgt);
1068 if (rogue_like_commands)
1077 /* Prepare the "temp" array */
1078 target_set_prepare(mode);
1080 /* Start near the player */
1086 /* Interesting grids */
1087 if (flag && tmp_pos.n)
1093 change_panel_xy(y, x);
1095 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1098 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1101 if (target_able(g_ptr->m_idx))
1103 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1106 /* Dis-allow target */
1109 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1115 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1116 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1117 strcat(info, cheatinfo);
1120 /* Describe and Prompt */
1122 query = target_set_aux(y, x, mode, info);
1126 /* Assume no "direction" */
1131 if (query == '\r') query = 't';
1149 if (target_able(g_ptr->m_idx))
1151 health_track(g_ptr->m_idx);
1152 target_who = g_ptr->m_idx;
1168 if (++m == tmp_pos.n)
1171 if (!expand_list) done = TRUE;
1181 if (!expand_list) done = TRUE;
1188 /* Recenter the map around the player */
1190 p_ptr->update |= (PU_MONSTERS);
1191 p_ptr->redraw |= (PR_MAP);
1192 p_ptr->window |= (PW_OVERHEAD);
1195 /* Recalculate interesting grids */
1196 target_set_prepare(mode);
1215 if(query == same_key)
1217 if (++m == tmp_pos.n)
1220 if (!expand_list) done = TRUE;
1225 /* Extract the action (if any) */
1226 d = get_keymap_dir(query);
1233 /* Hack -- move around */
1236 /* Modified to scroll to monster */
1237 POSITION y2 = panel_row_min;
1238 POSITION x2 = panel_col_min;
1240 /* Find a new monster */
1241 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
1243 /* Request to target past last interesting grid */
1244 while (flag && (i < 0))
1246 /* Note the change */
1247 if (change_panel(ddy[d], ddx[d]))
1249 int v = tmp_pos.y[m];
1250 int u = tmp_pos.x[m];
1252 /* Recalculate interesting grids */
1253 target_set_prepare(mode);
1255 /* Look at interesting grids */
1258 /* Find a new monster */
1259 i = target_pick(v, u, ddy[d], ddx[d]);
1265 /* Nothing interesting */
1268 POSITION dx = ddx[d];
1269 POSITION dy = ddy[d];
1271 /* Restore previous position */
1274 panel_bounds_center();
1276 p_ptr->update |= (PU_MONSTERS);
1277 p_ptr->redraw |= (PR_MAP);
1278 p_ptr->window |= (PW_OVERHEAD);
1281 /* Recalculate interesting grids */
1282 target_set_prepare(mode);
1284 /* Look at boring grids */
1291 /* Do not move horizontally if unnecessary */
1292 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1293 ((x > panel_col_min + wid / 2) && (dx < 0)))
1298 /* Do not move vertically if unnecessary */
1299 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1300 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1305 /* Apply the motion */
1306 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1307 (x >= panel_col_min+wid) || (x < panel_col_min))
1309 if (change_panel(dy, dx)) target_set_prepare(mode);
1312 /* Slide into legality */
1313 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1314 else if (x <= 0) x = 1;
1316 /* Slide into legality */
1317 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1318 else if (y <= 0) y = 1;
1327 /* Arbitrary grids */
1330 bool move_fast = FALSE;
1332 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1335 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1337 /* Default prompt */
1338 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1343 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1344 los(p_ptr->y, p_ptr->x, y, x),
1345 projectable(p_ptr->y, p_ptr->x, y, x));
1346 strcat(info, cheatinfo);
1349 /* Describe and Prompt (enable "TARGET_LOOK") */
1350 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1352 /* Assume no direction */
1357 if (query == '\r') query = 't';
1360 /* Analyze the keypress */
1384 /* Recenter the map around the player */
1386 p_ptr->update |= (PU_MONSTERS);
1387 p_ptr->redraw |= (PR_MAP);
1388 p_ptr->window |= (PW_OVERHEAD);
1391 /* Recalculate interesting grids */
1392 target_set_prepare(mode);
1414 /* Pick a nearby monster */
1415 for (i = 0; i < tmp_pos.n; i++)
1417 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1427 /* Nothing interesting */
1428 if (bd == 999) flag = FALSE;
1435 /* Extract the action (if any) */
1436 d = get_keymap_dir(query);
1438 /* XTRA HACK MOVEFAST */
1439 if (isupper(query)) move_fast = TRUE;
1446 /* Handle "direction" */
1449 POSITION dx = ddx[d];
1450 POSITION dy = ddy[d];
1452 /* XTRA HACK MOVEFAST */
1455 int mag = MIN(wid / 2, hgt / 2);
1465 /* Do not move horizontally if unnecessary */
1466 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1467 ((x > panel_col_min + wid / 2) && (dx < 0)))
1472 /* Do not move vertically if unnecessary */
1473 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1474 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1479 /* Apply the motion */
1480 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1481 (x >= panel_col_min + wid) || (x < panel_col_min))
1483 if (change_panel(dy, dx)) target_set_prepare(mode);
1486 /* Slide into legality */
1487 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1488 else if (x <= 0) x = 1;
1490 /* Slide into legality */
1491 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1492 else if (y <= 0) y = 1;
1500 /* Clear the top line */
1503 /* Recenter the map around the player */
1505 p_ptr->update |= (PU_MONSTERS);
1506 p_ptr->redraw |= (PR_MAP);
1507 p_ptr->window |= (PW_OVERHEAD);
1510 /* Failure to set target */
1511 if (!target_who) return (FALSE);
1519 * Get an "aiming direction" from the user.
1521 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1522 * "0" for "current target", and "-1" for "entry aborted".
1524 * Note that "Force Target", if set, will pre-empt user interaction,
1525 * if there is a usable target already set.
1527 * Note that confusion over-rides any (explicit?) user choice.
1529 bool get_aim_dir(DIRECTION *dp)
1538 /* Global direction */
1541 /* Hack -- auto-target if requested */
1542 if (use_old_target && target_okay()) dir = 5;
1544 if (repeat_pull(&code))
1549 if (!(code == 5 && !target_okay()))
1551 /* return (TRUE); */
1552 dir = (DIRECTION)code;
1555 *dp = (DIRECTION)code;
1557 /* Ask until satisfied */
1560 /* Choose a prompt */
1563 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1567 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
1570 /* Get a command (or Cancel) */
1571 if (!get_com(p, &command, TRUE)) break;
1575 if (command == '\r') command = 't';
1578 /* Convert various keys to "standard" keys */
1581 /* Use current target */
1592 /* Set new target */
1597 if (target_set(TARGET_KILL)) dir = 5;
1603 /* Extract the action (if any) */
1604 dir = get_keymap_dir(command);
1610 /* Verify requested targets */
1611 if ((dir == 5) && !target_okay()) dir = 0;
1620 project_length = 0; /* reset to default */
1624 /* Save the direction */
1627 /* Check for confusion */
1628 if (p_ptr->confused)
1630 /* Random direction */
1631 dir = ddd[randint0(8)];
1634 /* Notice confusion */
1635 if (command_dir != dir)
1638 msg_print(_("あなたは混乱している。", "You are confused."));
1641 /* Save direction */
1644 /* repeat_push(dir); */
1645 repeat_push((COMMAND_CODE)command_dir);
1647 /* A "valid" direction was entered */
1652 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
1660 /* Global direction */
1663 if (repeat_pull(&code))
1665 dir = (DIRECTION)code;
1666 /* return (TRUE); */
1668 *dp = (DIRECTION)code;
1672 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1676 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1679 /* Get a direction */
1684 /* Get a command (or Cancel) */
1685 if (!get_com(prompt, &ch, TRUE)) break;
1688 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1694 /* Look up the direction */
1695 dir = get_keymap_dir(ch);
1701 /* Prevent weirdness */
1702 if ((dir == 5) && (!allow_under)) dir = 0;
1705 if (!dir) return (FALSE);
1707 /* Save desired direction */
1710 /* Apply "confusion" */
1711 if (p_ptr->confused)
1713 /* Standard confusion */
1714 if (randint0(100) < 75)
1716 /* Random direction */
1717 dir = ddd[randint0(8)];
1720 else if (p_ptr->riding && with_steed)
1722 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1723 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1725 if (MON_CONFUSED(m_ptr))
1727 /* Standard confusion */
1728 if (randint0(100) < 75)
1730 /* Random direction */
1731 dir = ddd[randint0(8)];
1734 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1736 /* Random direction */
1737 dir = ddd[randint0(8)];
1739 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1741 /* Random direction */
1742 dir = ddd[randint0(8)];
1746 /* Notice confusion */
1747 if (command_dir != dir)
1749 if (p_ptr->confused)
1752 msg_print(_("あなたは混乱している。", "You are confused."));
1756 GAME_TEXT m_name[MAX_NLEN];
1757 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1759 monster_desc(m_name, m_ptr, 0);
1760 if (MON_CONFUSED(m_ptr))
1762 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1766 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1771 /* Save direction */
1774 /* repeat_push(dir); */
1775 repeat_push((COMMAND_CODE)command_dir);
1782 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
1783 * and place it into "command_dir", unless we already have one.
1785 * This function should be used for all "repeatable" commands, such as
1786 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
1787 * as all commands which must reference a grid adjacent to the player,
1788 * and which may not reference the grid under the player. Note that,
1789 * for example, it is no longer possible to "disarm" or "open" chests
1790 * in the same grid as the player.
1792 * Direction "5" is illegal and will (cleanly) abort the command.
1794 * This function tracks and uses the "global direction", and uses
1795 * that as the "desired direction", to which "confusion" is applied.
1797 bool get_rep_dir(DIRECTION *dp, bool under)
1805 /* Global direction */
1808 if (repeat_pull(&code))
1810 dir = (DIRECTION)code;
1811 /* return (TRUE); */
1813 *dp = (DIRECTION)code;
1817 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1821 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1824 /* Get a direction */
1829 /* Get a command (or Cancel) */
1830 if (!get_com(prompt, &ch, TRUE)) break;
1833 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1839 /* Look up the direction */
1840 dir = get_keymap_dir(ch);
1846 /* Prevent weirdness */
1847 if ((dir == 5) && (!under)) dir = 0;
1850 if (!dir) return (FALSE);
1852 /* Save desired direction */
1855 /* Apply "confusion" */
1856 if (p_ptr->confused)
1858 /* Standard confusion */
1859 if (randint0(100) < 75)
1861 /* Random direction */
1862 dir = ddd[randint0(8)];
1865 else if (p_ptr->riding)
1867 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1868 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1870 if (MON_CONFUSED(m_ptr))
1872 /* Standard confusion */
1873 if (randint0(100) < 75)
1875 /* Random direction */
1876 dir = ddd[randint0(8)];
1879 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1881 /* Random direction */
1882 dir = ddd[randint0(8)];
1884 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1886 /* Random direction */
1887 dir = ddd[randint0(8)];
1891 /* Notice confusion */
1892 if (command_dir != dir)
1894 if (p_ptr->confused)
1897 msg_print(_("あなたは混乱している。", "You are confused."));
1901 GAME_TEXT m_name[MAX_NLEN];
1902 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1904 monster_desc(m_name, m_ptr, 0);
1905 if (MON_CONFUSED(m_ptr))
1907 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1911 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1916 /* Save direction */
1919 /* repeat_push(dir); */
1920 repeat_push((COMMAND_CODE)command_dir);
1928 * XAngband: determine if a given location is "interesting"
1929 * based on target_set_accept function.
1931 static bool tgt_pt_accept(POSITION y, POSITION x)
1935 if (!(in_bounds(y, x))) return (FALSE);
1937 /* Player grid is always interesting */
1938 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
1940 if (p_ptr->image) return (FALSE);
1942 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1944 /* Interesting memorized features */
1945 if (g_ptr->info & (CAVE_MARK))
1948 if (cave_have_flag_grid(g_ptr, FF_LESS)) return (TRUE);
1949 if (cave_have_flag_grid(g_ptr, FF_MORE)) return (TRUE);
1951 /* Notice quest features */
1952 if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return (TRUE);
1953 if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return (TRUE);
1961 * XAngband: Prepare the "temp" array for "tget_pt"
1962 * based on target_set_prepare funciton.
1964 static void tgt_pt_prepare(void)
1968 /* Reset "temp" array */
1971 if (!expand_list) return;
1973 /* Scan the current panel */
1974 for (y = 1; y < current_floor_ptr->height; y++)
1976 for (x = 1; x < current_floor_ptr->width; x++)
1978 /* Require "interesting" contents */
1979 if (!tgt_pt_accept(y, x)) continue;
1981 /* Save the location */
1982 tmp_pos.x[tmp_pos.n] = x;
1983 tmp_pos.y[tmp_pos.n] = y;
1988 /* Sort the positions */
1989 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
1993 * old -- from PsiAngband.
1995 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
2000 bool success = FALSE;
2004 get_screen_size(&wid, &hgt);
2014 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2015 msg_flag = FALSE; /* prevents "-more-" message. */
2017 while ((ch != ESCAPE) && !success)
2019 bool move_fast = FALSE;
2021 move_cursor_relative(y, x);
2033 if (player_bold(y, x)) ch = 0;
2036 else success = TRUE;
2040 /* XAngband: Move cursor to stairs */
2043 if (expand_list && tmp_pos.n)
2046 int cx = (panel_col_min + panel_col_max) / 2;
2047 int cy = (panel_row_min + panel_row_max) / 2;
2051 /* Skip stairs which have defferent distance */
2052 for (; n < tmp_pos.n; ++ n)
2054 grid_type *g_ptr = ¤t_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
2056 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2057 cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2064 if (n == tmp_pos.n) /* Loop out taget list */
2069 verify_panel(); /* Move cursor to player */
2071 p_ptr->update |= (PU_MONSTERS);
2073 p_ptr->redraw |= (PR_MAP);
2075 p_ptr->window |= (PW_OVERHEAD);
2078 else /* move cursor to next stair and change panel */
2083 dy = 2 * (y - cy) / hgt;
2084 dx = 2 * (x - cx) / wid;
2085 if (dy || dx) change_panel(dy, dx);
2091 /* Look up the direction */
2092 d = get_keymap_dir(ch);
2094 /* XTRA HACK MOVEFAST */
2095 if (isupper(ch)) move_fast = TRUE;
2097 /* Handle "direction" */
2103 /* XTRA HACK MOVEFAST */
2106 int mag = MIN(wid / 2, hgt / 2);
2116 /* Do not move horizontally if unnecessary */
2117 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2118 ((x > panel_col_min + wid / 2) && (dx < 0)))
2123 /* Do not move vertically if unnecessary */
2124 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2125 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2130 /* Apply the motion */
2131 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2132 (x >= panel_col_min + wid) || (x < panel_col_min))
2134 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2135 change_panel(dy, dx);
2138 /* Slide into legality */
2139 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
2140 else if (x <= 0) x = 1;
2142 /* Slide into legality */
2143 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
2144 else if (y <= 0) y = 1;
2151 /* Clear the top line */
2154 /* Recenter the map around the player */
2157 p_ptr->update |= (PU_MONSTERS);
2159 p_ptr->redraw |= (PR_MAP);
2161 p_ptr->window |= (PW_OVERHEAD);
2170 bool get_hack_dir(DIRECTION *dp)
2178 /* Global direction */
2181 /* (No auto-targeting) */
2183 /* Ask until satisfied */
2186 /* Choose a prompt */
2189 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2193 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2196 /* Get a command (or Cancel) */
2197 if (!get_com(p, &command, TRUE)) break;
2201 if (command == '\r') command = 't';
2204 /* Convert various keys to "standard" keys */
2207 /* Use current target */
2218 /* Set new target */
2223 if (target_set(TARGET_KILL)) dir = 5;
2229 /* Look up the direction */
2230 dir = get_keymap_dir(command);
2236 /* Verify requested targets */
2237 if ((dir == 5) && !target_okay()) dir = 0;
2244 if (!dir) return (FALSE);
2246 /* Save the direction */
2249 /* Check for confusion */
2250 if (p_ptr->confused)
2252 /* Random direction */
2253 dir = ddd[randint0(8)];
2256 /* Notice confusion */
2257 if (command_dir != dir)
2260 msg_print(_("あなたは混乱している。", "You are confused."));
2263 /* Save direction */
2266 /* A "valid" direction was entered */