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 /* Target the nearest monster for shooting */
406 ang_sort_comp = ang_sort_comp_distance;
407 ang_sort_swap = ang_sort_swap_distance;
411 /* Look important grids first in Look command */
412 ang_sort_comp = ang_sort_comp_importance;
413 ang_sort_swap = ang_sort_swap_distance;
416 /* Sort the positions */
417 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n);
419 if (p_ptr->riding && target_pet && (tmp_pos.n > 1) && (mode & (TARGET_KILL)))
424 tmp_pos.y[0] = tmp_pos.y[1];
427 tmp_pos.x[0] = tmp_pos.x[1];
432 void target_set_prepare_look(void){
433 target_set_prepare(TARGET_LOOK);
438 * Evaluate number of kill needed to gain level
440 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
442 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
444 s32b exp_mon, exp_adv;
445 u32b exp_mon_frac, exp_adv_frac;
447 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
452 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
462 /* The monster's experience point (assuming average monster speed) */
463 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
465 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
468 /* Total experience value for next level */
469 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
471 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
473 /* Experience value need to get */
474 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
477 /* You need to kill at least one monster to get any experience */
478 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
479 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
481 /* Extract number of monsters needed */
482 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
484 /* If 999 or more monsters needed, only display "999". */
485 num = MIN(999, exp_adv_frac);
487 /* Display the number */
488 sprintf(buf,"%03ld", (long int)num);
492 bool show_gold_on_floor = FALSE;
495 * Examine a grid, return a keypress.
497 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
498 * indicates that the "space" key should scan through the contents
499 * of the grid, instead of simply returning immediately. This lets
500 * the "look" command get complete information, without making the
501 * "target" command annoying.
503 * The "info" argument contains the "commands" which should be shown
504 * inside the "[xxx]" text. This string must never be empty, or grids
505 * containing monsters will be displayed with an extra comma.
507 * Note that if a monster is in the grid, we update both the monster
508 * recall info and the health bar info to track that monster.
510 * Eventually, we may allow multiple objects per grid, or objects
511 * and terrain features in the same grid.
513 * This function must handle blindness/hallucination.
515 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
517 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
518 OBJECT_IDX this_o_idx, next_o_idx = 0;
519 concptr s1 = "", s2 = "", s3 = "", x_info = "";
524 char out_val[MAX_NLEN+80];
525 OBJECT_IDX floor_list[23];
526 ITEM_NUMBER floor_num = 0;
528 /* Scan all objects in the grid */
531 floor_num = scan_floor(floor_list, y, x, 0x02);
535 x_info = _("x物 ", "x,");
539 /* Hack -- under the player */
540 if (player_bold(y, x))
553 s1 = _("ターゲット:", "Target:");
556 /* Hack -- hallucination */
559 concptr name = _("何か奇妙な物", "something strange");
561 /* Display a message */
563 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
565 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
569 move_cursor_relative(y, x);
572 /* Stop on everything but "return" */
573 if ((query != '\r') && (query != '\n')) return query;
580 /* Actual monsters */
581 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
583 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
584 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
585 GAME_TEXT m_name[MAX_NLEN];
591 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
592 monster_race_track(m_ptr->ap_r_idx);
593 health_track(g_ptr->m_idx);
606 /* Recall on screen */
607 screen_roff(m_ptr->ap_r_idx, 0);
609 /* Hack -- Complete the prompt (again) */
610 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
617 /* Normal commands */
618 if (query != 'r') break;
623 /* Cleare recall text and repeat */
629 /* Describe, and prompt for recall */
630 evaluate_monster_exp(acount, m_ptr);
633 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);
635 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);
641 move_cursor_relative(y, x);
646 /* Normal commands */
647 if (query != 'r') break;
653 /* Always stop at "normal" keys */
654 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
656 /* Sometimes stop at "space" key */
657 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
659 /* Change the intro */
660 s1 = _("それは", "It is ");
662 /* Hack -- take account of gender */
663 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
664 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
666 /* Use a preposition */
675 /* Scan all objects being carried */
676 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
678 GAME_TEXT o_name[MAX_NLEN];
681 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
682 next_o_idx = o_ptr->next_o_idx;
684 /* Obtain an object description */
685 object_desc(o_name, o_ptr, 0);
688 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
690 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
694 move_cursor_relative(y, x);
697 /* Always stop at "normal" keys */
698 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
700 /* Sometimes stop at "space" key */
701 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
703 /* Change the intro */
704 s2 = _("をまた", "also carrying ");
707 /* Use a preposition */
724 GAME_TEXT o_name[MAX_NLEN];
727 o_ptr = ¤t_floor_ptr->o_list[floor_list[0]];
729 object_desc(o_name, o_ptr, 0);
732 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
734 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
738 move_cursor_relative(y, x);
747 /* Provide one cushion before item listing */
750 /* Display rough information about items */
752 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
754 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
758 move_cursor_relative(y, x);
763 /* No request for listing */
764 if (query != 'x' && query != ' ') return query;
768 /** Display list of items **/
770 /* Continue scrolling list if requested */
778 show_gold_on_floor = TRUE;
779 (void)show_floor(0, y, x, &min_width);
780 show_gold_on_floor = FALSE;
784 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
786 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
793 /* Exit unless 'Enter' */
794 if (query != '\n' && query != '\r')
799 /* Get the object being moved. */
800 o_idx = g_ptr->o_idx;
802 /* Only rotate a pile of two or more objects. */
803 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
805 /* Remove the first object from the list. */
806 excise_object_idx(o_idx);
808 /* Find end of the list. */
810 while (current_floor_ptr->o_list[i].next_o_idx)
811 i = current_floor_ptr->o_list[i].next_o_idx;
813 /* Add after the last object. */
814 current_floor_ptr->o_list[i].next_o_idx = o_idx;
816 /* Loop and re-display the list */
823 /* Scan all objects in the grid */
824 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
827 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
828 next_o_idx = o_ptr->next_o_idx;
830 if (o_ptr->marked & OM_FOUND)
832 GAME_TEXT o_name[MAX_NLEN];
837 /* Obtain an object description */
838 object_desc(o_name, o_ptr, 0);
841 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
843 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
847 move_cursor_relative(y, x);
850 /* Always stop at "normal" keys */
851 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
853 /* Sometimes stop at "space" key */
854 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
856 /* Change the intro */
857 s1 = _("それは", "It is ");
860 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
874 /* Feature code (applying "mimic" field) */
875 feat = get_feat_mimic(g_ptr);
877 /* Require knowledge about grid, or ability to see grid */
878 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
884 f_ptr = &f_info[feat];
886 /* Terrain feature if needed */
887 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
891 /* Hack -- special handling for quest entrances */
892 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
894 /* Set the quest number temporary */
895 IDX old_quest = p_ptr->inside_quest;
899 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
902 p_ptr->inside_quest = g_ptr->special;
904 /* Get the quest text */
905 init_flags = INIT_NAME_ONLY;
907 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
909 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
910 quest[g_ptr->special].name, quest[g_ptr->special].level);
912 /* Reset the old quest number */
913 p_ptr->inside_quest = old_quest;
916 /* Hack -- special handling for building doors */
917 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
919 name = building[f_ptr->subtype].name;
921 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
923 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
925 else if (have_flag(f_ptr->flags, FF_TOWN))
927 name = town_info[g_ptr->special].name;
929 else if (p_ptr->wild_mode && (feat == feat_floor))
931 name = _("道", "road");
935 name = f_name + f_ptr->name;
941 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
942 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
943 have_flag(f_ptr->flags, FF_TOWN)))
948 /* Hack -- special introduction for store & building doors -KMW- */
949 if (have_flag(f_ptr->flags, FF_STORE) ||
950 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
951 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
952 have_flag(f_ptr->flags, FF_ENTRANCE))
957 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
958 have_flag(f_ptr->flags, FF_TOWN) ||
959 have_flag(f_ptr->flags, FF_SHALLOW) ||
960 have_flag(f_ptr->flags, FF_DEEP))
966 /* Pick proper indefinite article */
967 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
971 /* Display a message */
975 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
976 else sprintf(f_idx_str, "%d", g_ptr->feat);
978 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]);
980 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);
985 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
987 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
991 move_cursor_relative(y, x);
994 /* Always stop at "normal" keys */
995 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
998 /* Stop on everything but "return" */
999 if ((query != '\r') && (query != '\n')) return query;
1001 /* Repeat forever */
1007 * Handle "target" and "look".
1009 * Note that this code can be called from "get_aim_dir()".
1011 * All locations must be on the current panel. Consider the use of
1012 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1013 * some form of "scrolling" the map around the cursor.
1014 * That is, consider the possibility of "auto-scrolling" the screen
1015 * while the cursor moves around. This may require changes in the
1016 * "update_monster()" code to allow "visibility" even if off panel, and
1017 * may require dynamic recalculation of the "temp" grid set.
1019 * Hack -- targeting/observing an "outer border grid" may induce
1020 * problems, so this is not currently allowed.
1022 * The player can use the direction keys to move among "interesting"
1023 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1024 * move through the "interesting" grids in a sequential manner, or
1025 * can enter "location" mode, and use the direction keys to move one
1026 * grid at a time in any direction. The "t" (set target) command will
1027 * only target a monster (as opposed to a location) if the monster is
1028 * target_able and the "interesting" mode is being used.
1030 * The current grid is described using the "look" method above, and
1031 * a new command may be entered at any time, but note that if the
1032 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1033 * where "space" has no obvious meaning) then "space" will scan
1034 * through the description of the current grid until done, instead
1035 * of immediately jumping to the next "interesting" grid. This
1036 * allows the "target" command to retain its old semantics.
1038 * The "*", "+", and "-" keys may always be used to jump immediately
1039 * to the next (or previous) interesting grid, in the proper mode.
1041 * The "return" key may always be used to scan through a complete
1042 * grid description (forever).
1044 * This command will cancel any old target, even if used from
1045 * inside the "look" command.
1047 bool target_set(BIT_FLAGS mode)
1050 POSITION y = p_ptr->y;
1051 POSITION x = p_ptr->x;
1061 get_screen_size(&wid, &hgt);
1066 if (rogue_like_commands)
1075 /* Prepare the "temp" array */
1076 target_set_prepare(mode);
1078 /* Start near the player */
1084 /* Interesting grids */
1085 if (flag && tmp_pos.n)
1091 change_panel_xy(y, x);
1093 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1096 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1099 if (target_able(g_ptr->m_idx))
1101 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1104 /* Dis-allow target */
1107 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1113 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1114 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1115 strcat(info, cheatinfo);
1118 /* Describe and Prompt */
1120 query = target_set_aux(y, x, mode, info);
1124 /* Assume no "direction" */
1129 if (query == '\r') query = 't';
1147 if (target_able(g_ptr->m_idx))
1149 health_track(g_ptr->m_idx);
1150 target_who = g_ptr->m_idx;
1166 if (++m == tmp_pos.n)
1169 if (!expand_list) done = TRUE;
1179 if (!expand_list) done = TRUE;
1186 /* Recenter the map around the player */
1188 p_ptr->update |= (PU_MONSTERS);
1189 p_ptr->redraw |= (PR_MAP);
1190 p_ptr->window |= (PW_OVERHEAD);
1193 /* Recalculate interesting grids */
1194 target_set_prepare(mode);
1213 if(query == same_key)
1215 if (++m == tmp_pos.n)
1218 if (!expand_list) done = TRUE;
1223 /* Extract the action (if any) */
1224 d = get_keymap_dir(query);
1231 /* Hack -- move around */
1234 /* Modified to scroll to monster */
1235 POSITION y2 = panel_row_min;
1236 POSITION x2 = panel_col_min;
1238 /* Find a new monster */
1239 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
1241 /* Request to target past last interesting grid */
1242 while (flag && (i < 0))
1244 /* Note the change */
1245 if (change_panel(ddy[d], ddx[d]))
1247 int v = tmp_pos.y[m];
1248 int u = tmp_pos.x[m];
1250 /* Recalculate interesting grids */
1251 target_set_prepare(mode);
1253 /* Look at interesting grids */
1256 /* Find a new monster */
1257 i = target_pick(v, u, ddy[d], ddx[d]);
1263 /* Nothing interesting */
1266 POSITION dx = ddx[d];
1267 POSITION dy = ddy[d];
1269 /* Restore previous position */
1272 panel_bounds_center();
1274 p_ptr->update |= (PU_MONSTERS);
1275 p_ptr->redraw |= (PR_MAP);
1276 p_ptr->window |= (PW_OVERHEAD);
1279 /* Recalculate interesting grids */
1280 target_set_prepare(mode);
1282 /* Look at boring grids */
1289 /* Do not move horizontally if unnecessary */
1290 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1291 ((x > panel_col_min + wid / 2) && (dx < 0)))
1296 /* Do not move vertically if unnecessary */
1297 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1298 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1303 /* Apply the motion */
1304 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1305 (x >= panel_col_min+wid) || (x < panel_col_min))
1307 if (change_panel(dy, dx)) target_set_prepare(mode);
1310 /* Slide into legality */
1311 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1312 else if (x <= 0) x = 1;
1314 /* Slide into legality */
1315 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1316 else if (y <= 0) y = 1;
1325 /* Arbitrary grids */
1328 bool move_fast = FALSE;
1330 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1333 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1335 /* Default prompt */
1336 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1341 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1342 los(p_ptr->y, p_ptr->x, y, x),
1343 projectable(p_ptr->y, p_ptr->x, y, x));
1344 strcat(info, cheatinfo);
1347 /* Describe and Prompt (enable "TARGET_LOOK") */
1348 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1350 /* Assume no direction */
1355 if (query == '\r') query = 't';
1358 /* Analyze the keypress */
1382 /* Recenter the map around the player */
1384 p_ptr->update |= (PU_MONSTERS);
1385 p_ptr->redraw |= (PR_MAP);
1386 p_ptr->window |= (PW_OVERHEAD);
1389 /* Recalculate interesting grids */
1390 target_set_prepare(mode);
1412 /* Pick a nearby monster */
1413 for (i = 0; i < tmp_pos.n; i++)
1415 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1425 /* Nothing interesting */
1426 if (bd == 999) flag = FALSE;
1433 /* Extract the action (if any) */
1434 d = get_keymap_dir(query);
1436 /* XTRA HACK MOVEFAST */
1437 if (isupper(query)) move_fast = TRUE;
1444 /* Handle "direction" */
1447 POSITION dx = ddx[d];
1448 POSITION dy = ddy[d];
1450 /* XTRA HACK MOVEFAST */
1453 int mag = MIN(wid / 2, hgt / 2);
1463 /* Do not move horizontally if unnecessary */
1464 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1465 ((x > panel_col_min + wid / 2) && (dx < 0)))
1470 /* Do not move vertically if unnecessary */
1471 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1472 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1477 /* Apply the motion */
1478 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1479 (x >= panel_col_min + wid) || (x < panel_col_min))
1481 if (change_panel(dy, dx)) target_set_prepare(mode);
1484 /* Slide into legality */
1485 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1486 else if (x <= 0) x = 1;
1488 /* Slide into legality */
1489 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1490 else if (y <= 0) y = 1;
1498 /* Clear the top line */
1501 /* Recenter the map around the player */
1503 p_ptr->update |= (PU_MONSTERS);
1504 p_ptr->redraw |= (PR_MAP);
1505 p_ptr->window |= (PW_OVERHEAD);
1508 /* Failure to set target */
1509 if (!target_who) return (FALSE);
1517 * Get an "aiming direction" from the user.
1519 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1520 * "0" for "current target", and "-1" for "entry aborted".
1522 * Note that "Force Target", if set, will pre-empt user interaction,
1523 * if there is a usable target already set.
1525 * Note that confusion over-rides any (explicit?) user choice.
1527 bool get_aim_dir(DIRECTION *dp)
1536 /* Global direction */
1539 /* Hack -- auto-target if requested */
1540 if (use_old_target && target_okay()) dir = 5;
1542 if (repeat_pull(&code))
1547 if (!(code == 5 && !target_okay()))
1549 /* return (TRUE); */
1550 dir = (DIRECTION)code;
1553 *dp = (DIRECTION)code;
1555 /* Ask until satisfied */
1558 /* Choose a prompt */
1561 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1565 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
1568 /* Get a command (or Cancel) */
1569 if (!get_com(p, &command, TRUE)) break;
1573 if (command == '\r') command = 't';
1576 /* Convert various keys to "standard" keys */
1579 /* Use current target */
1590 /* Set new target */
1595 if (target_set(TARGET_KILL)) dir = 5;
1601 /* Extract the action (if any) */
1602 dir = get_keymap_dir(command);
1608 /* Verify requested targets */
1609 if ((dir == 5) && !target_okay()) dir = 0;
1618 project_length = 0; /* reset to default */
1622 /* Save the direction */
1625 /* Check for confusion */
1626 if (p_ptr->confused)
1628 /* Random direction */
1629 dir = ddd[randint0(8)];
1632 /* Notice confusion */
1633 if (command_dir != dir)
1636 msg_print(_("あなたは混乱している。", "You are confused."));
1639 /* Save direction */
1642 /* repeat_push(dir); */
1643 repeat_push((COMMAND_CODE)command_dir);
1645 /* A "valid" direction was entered */
1650 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
1658 /* Global direction */
1661 if (repeat_pull(&code))
1663 dir = (DIRECTION)code;
1664 /* return (TRUE); */
1666 *dp = (DIRECTION)code;
1670 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1674 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1677 /* Get a direction */
1682 /* Get a command (or Cancel) */
1683 if (!get_com(prompt, &ch, TRUE)) break;
1686 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1692 /* Look up the direction */
1693 dir = get_keymap_dir(ch);
1699 /* Prevent weirdness */
1700 if ((dir == 5) && (!allow_under)) dir = 0;
1703 if (!dir) return (FALSE);
1705 /* Save desired direction */
1708 /* Apply "confusion" */
1709 if (p_ptr->confused)
1711 /* Standard confusion */
1712 if (randint0(100) < 75)
1714 /* Random direction */
1715 dir = ddd[randint0(8)];
1718 else if (p_ptr->riding && with_steed)
1720 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1721 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1723 if (MON_CONFUSED(m_ptr))
1725 /* Standard confusion */
1726 if (randint0(100) < 75)
1728 /* Random direction */
1729 dir = ddd[randint0(8)];
1732 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1734 /* Random direction */
1735 dir = ddd[randint0(8)];
1737 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1739 /* Random direction */
1740 dir = ddd[randint0(8)];
1744 /* Notice confusion */
1745 if (command_dir != dir)
1747 if (p_ptr->confused)
1750 msg_print(_("あなたは混乱している。", "You are confused."));
1754 GAME_TEXT m_name[MAX_NLEN];
1755 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1757 monster_desc(m_name, m_ptr, 0);
1758 if (MON_CONFUSED(m_ptr))
1760 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1764 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1769 /* Save direction */
1772 /* repeat_push(dir); */
1773 repeat_push((COMMAND_CODE)command_dir);
1780 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
1781 * and place it into "command_dir", unless we already have one.
1783 * This function should be used for all "repeatable" commands, such as
1784 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
1785 * as all commands which must reference a grid adjacent to the player,
1786 * and which may not reference the grid under the player. Note that,
1787 * for example, it is no longer possible to "disarm" or "open" chests
1788 * in the same grid as the player.
1790 * Direction "5" is illegal and will (cleanly) abort the command.
1792 * This function tracks and uses the "global direction", and uses
1793 * that as the "desired direction", to which "confusion" is applied.
1795 bool get_rep_dir(DIRECTION *dp, bool under)
1803 /* Global direction */
1806 if (repeat_pull(&code))
1808 dir = (DIRECTION)code;
1809 /* return (TRUE); */
1811 *dp = (DIRECTION)code;
1815 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1819 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1822 /* Get a direction */
1827 /* Get a command (or Cancel) */
1828 if (!get_com(prompt, &ch, TRUE)) break;
1831 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1837 /* Look up the direction */
1838 dir = get_keymap_dir(ch);
1844 /* Prevent weirdness */
1845 if ((dir == 5) && (!under)) dir = 0;
1848 if (!dir) return (FALSE);
1850 /* Save desired direction */
1853 /* Apply "confusion" */
1854 if (p_ptr->confused)
1856 /* Standard confusion */
1857 if (randint0(100) < 75)
1859 /* Random direction */
1860 dir = ddd[randint0(8)];
1863 else if (p_ptr->riding)
1865 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1866 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1868 if (MON_CONFUSED(m_ptr))
1870 /* Standard confusion */
1871 if (randint0(100) < 75)
1873 /* Random direction */
1874 dir = ddd[randint0(8)];
1877 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1879 /* Random direction */
1880 dir = ddd[randint0(8)];
1882 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1884 /* Random direction */
1885 dir = ddd[randint0(8)];
1889 /* Notice confusion */
1890 if (command_dir != dir)
1892 if (p_ptr->confused)
1895 msg_print(_("あなたは混乱している。", "You are confused."));
1899 GAME_TEXT m_name[MAX_NLEN];
1900 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1902 monster_desc(m_name, m_ptr, 0);
1903 if (MON_CONFUSED(m_ptr))
1905 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1909 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1914 /* Save direction */
1917 /* repeat_push(dir); */
1918 repeat_push((COMMAND_CODE)command_dir);
1926 * XAngband: determine if a given location is "interesting"
1927 * based on target_set_accept function.
1929 static bool tgt_pt_accept(POSITION y, POSITION x)
1933 if (!(in_bounds(y, x))) return (FALSE);
1935 /* Player grid is always interesting */
1936 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
1938 if (p_ptr->image) return (FALSE);
1940 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1942 /* Interesting memorized features */
1943 if (g_ptr->info & (CAVE_MARK))
1946 if (cave_have_flag_grid(g_ptr, FF_LESS)) return (TRUE);
1947 if (cave_have_flag_grid(g_ptr, FF_MORE)) return (TRUE);
1949 /* Notice quest features */
1950 if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return (TRUE);
1951 if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return (TRUE);
1959 * XAngband: Prepare the "temp" array for "tget_pt"
1960 * based on target_set_prepare funciton.
1962 static void tgt_pt_prepare(void)
1966 /* Reset "temp" array */
1969 if (!expand_list) return;
1971 /* Scan the current panel */
1972 for (y = 1; y < current_floor_ptr->height; y++)
1974 for (x = 1; x < current_floor_ptr->width; x++)
1976 /* Require "interesting" contents */
1977 if (!tgt_pt_accept(y, x)) continue;
1979 /* Save the location */
1980 tmp_pos.x[tmp_pos.n] = x;
1981 tmp_pos.y[tmp_pos.n] = y;
1986 /* Target the nearest monster for shooting */
1987 ang_sort_comp = ang_sort_comp_distance;
1988 ang_sort_swap = ang_sort_swap_distance;
1990 /* Sort the positions */
1991 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n);
1995 * old -- from PsiAngband.
1997 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
2002 bool success = FALSE;
2006 get_screen_size(&wid, &hgt);
2016 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2017 msg_flag = FALSE; /* prevents "-more-" message. */
2019 while ((ch != ESCAPE) && !success)
2021 bool move_fast = FALSE;
2023 move_cursor_relative(y, x);
2035 if (player_bold(y, x)) ch = 0;
2038 else success = TRUE;
2042 /* XAngband: Move cursor to stairs */
2045 if (expand_list && tmp_pos.n)
2048 int cx = (panel_col_min + panel_col_max) / 2;
2049 int cy = (panel_row_min + panel_row_max) / 2;
2053 /* Skip stairs which have defferent distance */
2054 for (; n < tmp_pos.n; ++ n)
2056 grid_type *g_ptr = ¤t_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
2058 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2059 cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2066 if (n == tmp_pos.n) /* Loop out taget list */
2071 verify_panel(); /* Move cursor to player */
2073 p_ptr->update |= (PU_MONSTERS);
2075 p_ptr->redraw |= (PR_MAP);
2077 p_ptr->window |= (PW_OVERHEAD);
2080 else /* move cursor to next stair and change panel */
2085 dy = 2 * (y - cy) / hgt;
2086 dx = 2 * (x - cx) / wid;
2087 if (dy || dx) change_panel(dy, dx);
2093 /* Look up the direction */
2094 d = get_keymap_dir(ch);
2096 /* XTRA HACK MOVEFAST */
2097 if (isupper(ch)) move_fast = TRUE;
2099 /* Handle "direction" */
2105 /* XTRA HACK MOVEFAST */
2108 int mag = MIN(wid / 2, hgt / 2);
2118 /* Do not move horizontally if unnecessary */
2119 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2120 ((x > panel_col_min + wid / 2) && (dx < 0)))
2125 /* Do not move vertically if unnecessary */
2126 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2127 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2132 /* Apply the motion */
2133 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2134 (x >= panel_col_min + wid) || (x < panel_col_min))
2136 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2137 change_panel(dy, dx);
2140 /* Slide into legality */
2141 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
2142 else if (x <= 0) x = 1;
2144 /* Slide into legality */
2145 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
2146 else if (y <= 0) y = 1;
2153 /* Clear the top line */
2156 /* Recenter the map around the player */
2159 p_ptr->update |= (PU_MONSTERS);
2161 p_ptr->redraw |= (PR_MAP);
2163 p_ptr->window |= (PW_OVERHEAD);
2172 bool get_hack_dir(DIRECTION *dp)
2180 /* Global direction */
2183 /* (No auto-targeting) */
2185 /* Ask until satisfied */
2188 /* Choose a prompt */
2191 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2195 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2198 /* Get a command (or Cancel) */
2199 if (!get_com(p, &command, TRUE)) break;
2203 if (command == '\r') command = 't';
2206 /* Convert various keys to "standard" keys */
2209 /* Use current target */
2220 /* Set new target */
2225 if (target_set(TARGET_KILL)) dir = 5;
2231 /* Look up the direction */
2232 dir = get_keymap_dir(command);
2238 /* Verify requested targets */
2239 if ((dir == 5) && !target_okay()) dir = 0;
2246 if (!dir) return (FALSE);
2248 /* Save the direction */
2251 /* Check for confusion */
2252 if (p_ptr->confused)
2254 /* Random direction */
2255 dir = ddd[randint0(8)];
2258 /* Notice confusion */
2259 if (command_dir != dir)
2262 msg_print(_("あなたは混乱している。", "You are confused."));
2265 /* Save direction */
2268 /* A "valid" direction was entered */