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"
17 #include "object-flavor.h"
19 #include "monsterrace-hook.h"
20 #include "objectkind-hook.h"
22 #include "spells-summon.h"
25 #include "floor-events.h"
26 #include "player-move.h"
27 #include "player-status.h"
28 #include "monster-status.h"
31 * @brief コンソール上におけるマップ表示の左上位置を返す /
32 * Calculates current boundaries Called below and from "do_cmd_locate()".
35 void panel_bounds_center(void)
39 get_screen_size(&wid, &hgt);
41 panel_row_max = panel_row_min + hgt - 1;
42 panel_row_prt = panel_row_min - 1;
43 panel_col_max = panel_col_min + wid - 1;
44 panel_col_prt = panel_col_min - 13;
48 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
52 * Handle a request to change the current panel
53 * Return TRUE if the panel was changed.
54 * Also used in do_cmd_locate
55 * @return 実際に再描画が必要だった場合TRUEを返す
57 static bool change_panel_xy(POSITION y, POSITION x)
59 POSITION dy = 0, dx = 0;
62 get_screen_size(&wid, &hgt);
64 if (y < panel_row_min) dy = -1;
65 if (y > panel_row_max) dy = 1;
66 if (x < panel_col_min) dx = -1;
67 if (x > panel_col_max) dx = 1;
69 if (!dy && !dx) return (FALSE);
71 return change_panel(dy, dx);
76 * @brief マップ描画のフォーカスを当てるべき座標を更新する
78 * Given an row (y) and col (x), this routine detects when a move
79 * off the screen has occurred and figures new borders. -RAK-
80 * "Update" forces a "full update" to take place.
81 * The map is reprinted if necessary, and "TRUE" is returned.
82 * @return 実際に再描画が必要だった場合TRUEを返す
84 void verify_panel(void)
86 POSITION y = p_ptr->y;
87 POSITION x = p_ptr->x;
95 get_screen_size(&wid, &hgt);
97 max_prow_min = current_floor_ptr->height - hgt;
98 max_pcol_min = current_floor_ptr->width - wid;
100 /* Bounds checking */
101 if (max_prow_min < 0) max_prow_min = 0;
102 if (max_pcol_min < 0) max_pcol_min = 0;
104 /* Center on player */
105 if (center_player && (center_running || !running))
107 /* Center vertically */
108 prow_min = y - hgt / 2;
109 if (prow_min < 0) prow_min = 0;
110 else if (prow_min > max_prow_min) prow_min = max_prow_min;
112 /* Center horizontally */
113 pcol_min = x - wid / 2;
114 if (pcol_min < 0) pcol_min = 0;
115 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
119 prow_min = panel_row_min;
120 pcol_min = panel_col_min;
122 /* Scroll screen when 2 grids from top/bottom edge */
123 if (y > panel_row_max - 2)
125 while (y > prow_min + hgt-1 - 2)
127 prow_min += (hgt / 2);
131 if (y < panel_row_min + 2)
133 while (y < prow_min + 2)
135 prow_min -= (hgt / 2);
139 if (prow_min > max_prow_min) prow_min = max_prow_min;
140 if (prow_min < 0) prow_min = 0;
142 /* Scroll screen when 4 grids from left/right edge */
143 if (x > panel_col_max - 4)
145 while (x > pcol_min + wid-1 - 4)
147 pcol_min += (wid / 2);
151 if (x < panel_col_min + 4)
153 while (x < pcol_min + 4)
155 pcol_min -= (wid / 2);
159 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
160 if (pcol_min < 0) pcol_min = 0;
163 /* Check for "no change" */
164 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
166 /* Save the new panel info */
167 panel_row_min = prow_min;
168 panel_col_min = pcol_min;
170 /* Hack -- optional disturb on "panel change" */
171 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
173 panel_bounds_center();
175 p_ptr->update |= (PU_MONSTERS);
176 p_ptr->redraw |= (PR_MAP);
177 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
181 /*** Targeting Code ***/
184 * Determine is a monster makes a reasonable target
186 * The concept of "targeting" was stolen from "Morgul" (?)
188 * The player can target any location, or any "target-able" monster.
190 * Currently, a monster is "target_able" if it is visible, and if
191 * the player can hit it with a projection, and the player is not
192 * hallucinating. This allows use of "use closest target" macros.
194 * Future versions may restrict the ability to target "trappers"
195 * and "mimics", but the semantics is a little bit weird.
197 bool target_able(MONSTER_IDX m_idx)
199 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
201 /* Monster must be alive */
202 if (!monster_is_valid(m_ptr)) return (FALSE);
204 /* Hack -- no targeting hallucinations */
205 if (p_ptr->image) return (FALSE);
207 /* Monster must be visible */
208 if (!m_ptr->ml) return (FALSE);
210 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
212 /* Monster must be projectable */
213 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
215 /* Hack -- Never target trappers */
216 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
226 * Update (if necessary) and verify (if possible) the target.
228 * We return TRUE if the target is "okay" and FALSE otherwise.
230 bool target_okay(void)
232 /* Accept stationary targets */
233 if (target_who < 0) return (TRUE);
235 /* Check moving targets */
238 /* Accept reasonable targets */
239 if (target_able(target_who))
241 monster_type *m_ptr = ¤t_floor_ptr->m_list[target_who];
243 /* Acquire monster location */
244 target_row = m_ptr->fy;
245 target_col = m_ptr->fx;
252 /* Assume no target */
258 * Hack -- help "select" a location (see below)
260 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
263 POSITION x2, y2, x3, y3, x4, y4;
264 POSITION_IDX b_i = -1, b_v = 9999;
267 /* Scan the locations */
268 for (i = 0; i < tmp_pos.n; i++)
274 /* Directed distance */
278 /* Verify quadrant */
279 if (dx && (x3 * dx <= 0)) continue;
280 if (dy && (y3 * dy <= 0)) continue;
285 /* Verify quadrant */
286 if (dy && !dx && (x4 > y4)) continue;
287 if (dx && !dy && (y4 > x4)) continue;
289 /* Approximate Double Distance */
290 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
292 /* Penalize location */
293 if ((b_i >= 0) && (v >= b_v)) continue;
301 * Hack -- determine if a given location is "interesting"
303 static bool target_set_accept(POSITION y, POSITION x)
306 OBJECT_IDX this_o_idx, next_o_idx = 0;
308 if (!(in_bounds(y, x))) return (FALSE);
310 /* Player grid is always interesting */
311 if (player_bold(y, x)) return (TRUE);
313 if (p_ptr->image) return (FALSE);
315 g_ptr = ¤t_floor_ptr->grid_array[y][x];
317 /* Visible monsters */
320 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
322 /* Visible monsters */
323 if (m_ptr->ml) return (TRUE);
326 /* Scan all objects in the grid */
327 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
330 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
331 next_o_idx = o_ptr->next_o_idx;
333 /* Memorized object */
334 if (o_ptr->marked & OM_FOUND) return (TRUE);
337 /* Interesting memorized features */
338 if (g_ptr->info & (CAVE_MARK))
340 /* Notice object features */
341 if (g_ptr->info & CAVE_OBJECT) return (TRUE);
343 /* Feature code (applying "mimic" field) */
344 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE)) return TRUE;
352 * Prepare the "temp" array for "target_set"
354 * Return the number of target_able monsters in the set.
356 static void target_set_prepare(BIT_FLAGS mode)
359 POSITION min_hgt, max_hgt, min_wid, max_wid;
361 if (mode & TARGET_KILL)
364 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
365 max_hgt = MIN((p_ptr->y + MAX_RANGE), current_floor_ptr->height - 1);
366 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
367 max_wid = MIN((p_ptr->x + MAX_RANGE), current_floor_ptr->width - 1);
369 else /* not targetting */
372 min_hgt = panel_row_min;
373 max_hgt = panel_row_max;
374 min_wid = panel_col_min;
375 max_wid = panel_col_max;
378 /* Reset "temp" array */
381 /* Scan the current panel */
382 for (y = min_hgt; y <= max_hgt; y++)
384 for (x = min_wid; x <= max_wid; x++)
388 /* Require "interesting" contents */
389 if (!target_set_accept(y, x)) continue;
391 g_ptr = ¤t_floor_ptr->grid_array[y][x];
393 /* Require target_able monsters for "TARGET_KILL" */
394 if ((mode & (TARGET_KILL)) && !target_able(g_ptr->m_idx)) continue;
396 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(¤t_floor_ptr->m_list[g_ptr->m_idx])) continue;
398 /* Save the location */
399 tmp_pos.x[tmp_pos.n] = x;
400 tmp_pos.y[tmp_pos.n] = y;
405 /* Set the sort hooks */
406 if (mode & (TARGET_KILL))
408 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
412 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_importance, ang_sort_swap_distance);
415 if (p_ptr->riding && target_pet && (tmp_pos.n > 1) && (mode & (TARGET_KILL)))
420 tmp_pos.y[0] = tmp_pos.y[1];
423 tmp_pos.x[0] = tmp_pos.x[1];
428 void target_set_prepare_look(void){
429 target_set_prepare(TARGET_LOOK);
434 * Evaluate number of kill needed to gain level
436 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
438 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
440 s32b exp_mon, exp_adv;
441 u32b exp_mon_frac, exp_adv_frac;
443 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
448 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
458 /* The monster's experience point (assuming average monster speed) */
459 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
461 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
464 /* Total experience value for next level */
465 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
467 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
469 /* Experience value need to get */
470 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
473 /* You need to kill at least one monster to get any experience */
474 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
475 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
477 /* Extract number of monsters needed */
478 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
480 /* If 999 or more monsters needed, only display "999". */
481 num = MIN(999, exp_adv_frac);
483 /* Display the number */
484 sprintf(buf,"%03ld", (long int)num);
488 bool show_gold_on_floor = FALSE;
491 * Examine a grid, return a keypress.
493 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
494 * indicates that the "space" key should scan through the contents
495 * of the grid, instead of simply returning immediately. This lets
496 * the "look" command get complete information, without making the
497 * "target" command annoying.
499 * The "info" argument contains the "commands" which should be shown
500 * inside the "[xxx]" text. This string must never be empty, or grids
501 * containing monsters will be displayed with an extra comma.
503 * Note that if a monster is in the grid, we update both the monster
504 * recall info and the health bar info to track that monster.
506 * Eventually, we may allow multiple objects per grid, or objects
507 * and terrain features in the same grid.
509 * This function must handle blindness/hallucination.
511 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
513 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
514 OBJECT_IDX this_o_idx, next_o_idx = 0;
515 concptr s1 = "", s2 = "", s3 = "", x_info = "";
520 char out_val[MAX_NLEN+80];
521 OBJECT_IDX floor_list[23];
522 ITEM_NUMBER floor_num = 0;
524 /* Scan all objects in the grid */
527 floor_num = scan_floor(floor_list, y, x, 0x02);
531 x_info = _("x物 ", "x,");
535 /* Hack -- under the player */
536 if (player_bold(y, x))
549 s1 = _("ターゲット:", "Target:");
552 /* Hack -- hallucination */
555 concptr name = _("何か奇妙な物", "something strange");
557 /* Display a message */
559 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
561 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
565 move_cursor_relative(y, x);
568 /* Stop on everything but "return" */
569 if ((query != '\r') && (query != '\n')) return query;
576 /* Actual monsters */
577 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
579 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
580 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
581 GAME_TEXT m_name[MAX_NLEN];
587 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
588 monster_race_track(m_ptr->ap_r_idx);
589 health_track(g_ptr->m_idx);
602 /* Recall on screen */
603 screen_roff(m_ptr->ap_r_idx, 0);
605 /* Hack -- Complete the prompt (again) */
606 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
613 /* Normal commands */
614 if (query != 'r') break;
619 /* Cleare recall text and repeat */
625 /* Describe, and prompt for recall */
626 evaluate_monster_exp(acount, m_ptr);
629 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);
631 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);
637 move_cursor_relative(y, x);
642 /* Normal commands */
643 if (query != 'r') break;
649 /* Always stop at "normal" keys */
650 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
652 /* Sometimes stop at "space" key */
653 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
655 /* Change the intro */
656 s1 = _("それは", "It is ");
658 /* Hack -- take account of gender */
659 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
660 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
662 /* Use a preposition */
671 /* Scan all objects being carried */
672 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
674 GAME_TEXT o_name[MAX_NLEN];
677 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
678 next_o_idx = o_ptr->next_o_idx;
680 /* Obtain an object description */
681 object_desc(o_name, o_ptr, 0);
684 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
686 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
690 move_cursor_relative(y, x);
693 /* Always stop at "normal" keys */
694 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
696 /* Sometimes stop at "space" key */
697 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
699 /* Change the intro */
700 s2 = _("をまた", "also carrying ");
703 /* Use a preposition */
720 GAME_TEXT o_name[MAX_NLEN];
723 o_ptr = ¤t_floor_ptr->o_list[floor_list[0]];
725 object_desc(o_name, o_ptr, 0);
728 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
730 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
734 move_cursor_relative(y, x);
743 /* Provide one cushion before item listing */
746 /* Display rough information about items */
748 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
750 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
754 move_cursor_relative(y, x);
759 /* No request for listing */
760 if (query != 'x' && query != ' ') return query;
764 /** Display list of items **/
766 /* Continue scrolling list if requested */
774 show_gold_on_floor = TRUE;
775 (void)show_floor(0, y, x, &min_width);
776 show_gold_on_floor = FALSE;
780 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
782 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
789 /* Exit unless 'Enter' */
790 if (query != '\n' && query != '\r')
795 /* Get the object being moved. */
796 o_idx = g_ptr->o_idx;
798 /* Only rotate a pile of two or more objects. */
799 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
801 /* Remove the first object from the list. */
802 excise_object_idx(o_idx);
804 /* Find end of the list. */
806 while (current_floor_ptr->o_list[i].next_o_idx)
807 i = current_floor_ptr->o_list[i].next_o_idx;
809 /* Add after the last object. */
810 current_floor_ptr->o_list[i].next_o_idx = o_idx;
812 /* Loop and re-display the list */
819 /* Scan all objects in the grid */
820 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
823 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
824 next_o_idx = o_ptr->next_o_idx;
826 if (o_ptr->marked & OM_FOUND)
828 GAME_TEXT o_name[MAX_NLEN];
833 /* Obtain an object description */
834 object_desc(o_name, o_ptr, 0);
837 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
839 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
843 move_cursor_relative(y, x);
846 /* Always stop at "normal" keys */
847 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
849 /* Sometimes stop at "space" key */
850 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
852 /* Change the intro */
853 s1 = _("それは", "It is ");
856 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
870 /* Feature code (applying "mimic" field) */
871 feat = get_feat_mimic(g_ptr);
873 /* Require knowledge about grid, or ability to see grid */
874 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
880 f_ptr = &f_info[feat];
882 /* Terrain feature if needed */
883 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
887 /* Hack -- special handling for quest entrances */
888 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
890 /* Set the quest number temporary */
891 IDX old_quest = p_ptr->inside_quest;
895 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
898 p_ptr->inside_quest = g_ptr->special;
900 /* Get the quest text */
901 init_flags = INIT_NAME_ONLY;
903 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
905 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
906 quest[g_ptr->special].name, quest[g_ptr->special].level);
908 /* Reset the old quest number */
909 p_ptr->inside_quest = old_quest;
912 /* Hack -- special handling for building doors */
913 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
915 name = building[f_ptr->subtype].name;
917 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
919 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
921 else if (have_flag(f_ptr->flags, FF_TOWN))
923 name = town_info[g_ptr->special].name;
925 else if (p_ptr->wild_mode && (feat == feat_floor))
927 name = _("道", "road");
931 name = f_name + f_ptr->name;
937 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
938 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
939 have_flag(f_ptr->flags, FF_TOWN)))
944 /* Hack -- special introduction for store & building doors -KMW- */
945 if (have_flag(f_ptr->flags, FF_STORE) ||
946 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
947 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
948 have_flag(f_ptr->flags, FF_ENTRANCE))
953 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
954 have_flag(f_ptr->flags, FF_TOWN) ||
955 have_flag(f_ptr->flags, FF_SHALLOW) ||
956 have_flag(f_ptr->flags, FF_DEEP))
962 /* Pick proper indefinite article */
963 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
967 /* Display a message */
971 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
972 else sprintf(f_idx_str, "%d", g_ptr->feat);
974 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]);
976 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);
981 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
983 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
987 move_cursor_relative(y, x);
990 /* Always stop at "normal" keys */
991 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
994 /* Stop on everything but "return" */
995 if ((query != '\r') && (query != '\n')) return query;
1003 * Handle "target" and "look".
1005 * Note that this code can be called from "get_aim_dir()".
1007 * All locations must be on the current panel. Consider the use of
1008 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1009 * some form of "scrolling" the map around the cursor.
1010 * That is, consider the possibility of "auto-scrolling" the screen
1011 * while the cursor moves around. This may require changes in the
1012 * "update_monster()" code to allow "visibility" even if off panel, and
1013 * may require dynamic recalculation of the "temp" grid set.
1015 * Hack -- targeting/observing an "outer border grid" may induce
1016 * problems, so this is not currently allowed.
1018 * The player can use the direction keys to move among "interesting"
1019 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1020 * move through the "interesting" grids in a sequential manner, or
1021 * can enter "location" mode, and use the direction keys to move one
1022 * grid at a time in any direction. The "t" (set target) command will
1023 * only target a monster (as opposed to a location) if the monster is
1024 * target_able and the "interesting" mode is being used.
1026 * The current grid is described using the "look" method above, and
1027 * a new command may be entered at any time, but note that if the
1028 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1029 * where "space" has no obvious meaning) then "space" will scan
1030 * through the description of the current grid until done, instead
1031 * of immediately jumping to the next "interesting" grid. This
1032 * allows the "target" command to retain its old semantics.
1034 * The "*", "+", and "-" keys may always be used to jump immediately
1035 * to the next (or previous) interesting grid, in the proper mode.
1037 * The "return" key may always be used to scan through a complete
1038 * grid description (forever).
1040 * This command will cancel any old target, even if used from
1041 * inside the "look" command.
1043 bool target_set(BIT_FLAGS mode)
1046 POSITION y = p_ptr->y;
1047 POSITION x = p_ptr->x;
1057 get_screen_size(&wid, &hgt);
1062 if (rogue_like_commands)
1071 /* Prepare the "temp" array */
1072 target_set_prepare(mode);
1074 /* Start near the player */
1080 /* Interesting grids */
1081 if (flag && tmp_pos.n)
1087 change_panel_xy(y, x);
1089 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1092 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1095 if (target_able(g_ptr->m_idx))
1097 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1100 /* Dis-allow target */
1103 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1109 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1110 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1111 strcat(info, cheatinfo);
1114 /* Describe and Prompt */
1116 query = target_set_aux(y, x, mode, info);
1120 /* Assume no "direction" */
1125 if (query == '\r') query = 't';
1143 if (target_able(g_ptr->m_idx))
1145 health_track(g_ptr->m_idx);
1146 target_who = g_ptr->m_idx;
1162 if (++m == tmp_pos.n)
1165 if (!expand_list) done = TRUE;
1175 if (!expand_list) done = TRUE;
1182 /* Recenter the map around the player */
1184 p_ptr->update |= (PU_MONSTERS);
1185 p_ptr->redraw |= (PR_MAP);
1186 p_ptr->window |= (PW_OVERHEAD);
1189 /* Recalculate interesting grids */
1190 target_set_prepare(mode);
1209 if(query == same_key)
1211 if (++m == tmp_pos.n)
1214 if (!expand_list) done = TRUE;
1219 /* Extract the action (if any) */
1220 d = get_keymap_dir(query);
1227 /* Hack -- move around */
1230 /* Modified to scroll to monster */
1231 POSITION y2 = panel_row_min;
1232 POSITION x2 = panel_col_min;
1234 /* Find a new monster */
1235 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
1237 /* Request to target past last interesting grid */
1238 while (flag && (i < 0))
1240 /* Note the change */
1241 if (change_panel(ddy[d], ddx[d]))
1243 int v = tmp_pos.y[m];
1244 int u = tmp_pos.x[m];
1246 /* Recalculate interesting grids */
1247 target_set_prepare(mode);
1249 /* Look at interesting grids */
1252 /* Find a new monster */
1253 i = target_pick(v, u, ddy[d], ddx[d]);
1259 /* Nothing interesting */
1262 POSITION dx = ddx[d];
1263 POSITION dy = ddy[d];
1265 /* Restore previous position */
1268 panel_bounds_center();
1270 p_ptr->update |= (PU_MONSTERS);
1271 p_ptr->redraw |= (PR_MAP);
1272 p_ptr->window |= (PW_OVERHEAD);
1275 /* Recalculate interesting grids */
1276 target_set_prepare(mode);
1278 /* Look at boring grids */
1285 /* Do not move horizontally if unnecessary */
1286 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1287 ((x > panel_col_min + wid / 2) && (dx < 0)))
1292 /* Do not move vertically if unnecessary */
1293 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1294 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1299 /* Apply the motion */
1300 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1301 (x >= panel_col_min+wid) || (x < panel_col_min))
1303 if (change_panel(dy, dx)) target_set_prepare(mode);
1306 /* Slide into legality */
1307 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1308 else if (x <= 0) x = 1;
1310 /* Slide into legality */
1311 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1312 else if (y <= 0) y = 1;
1321 /* Arbitrary grids */
1324 bool move_fast = FALSE;
1326 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1329 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1331 /* Default prompt */
1332 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1337 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1338 los(p_ptr->y, p_ptr->x, y, x),
1339 projectable(p_ptr->y, p_ptr->x, y, x));
1340 strcat(info, cheatinfo);
1343 /* Describe and Prompt (enable "TARGET_LOOK") */
1344 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1346 /* Assume no direction */
1351 if (query == '\r') query = 't';
1354 /* Analyze the keypress */
1378 /* Recenter the map around the player */
1380 p_ptr->update |= (PU_MONSTERS);
1381 p_ptr->redraw |= (PR_MAP);
1382 p_ptr->window |= (PW_OVERHEAD);
1385 /* Recalculate interesting grids */
1386 target_set_prepare(mode);
1408 /* Pick a nearby monster */
1409 for (i = 0; i < tmp_pos.n; i++)
1411 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1421 /* Nothing interesting */
1422 if (bd == 999) flag = FALSE;
1429 /* Extract the action (if any) */
1430 d = get_keymap_dir(query);
1432 /* XTRA HACK MOVEFAST */
1433 if (isupper(query)) move_fast = TRUE;
1440 /* Handle "direction" */
1443 POSITION dx = ddx[d];
1444 POSITION dy = ddy[d];
1446 /* XTRA HACK MOVEFAST */
1449 int mag = MIN(wid / 2, hgt / 2);
1459 /* Do not move horizontally if unnecessary */
1460 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1461 ((x > panel_col_min + wid / 2) && (dx < 0)))
1466 /* Do not move vertically if unnecessary */
1467 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1468 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1473 /* Apply the motion */
1474 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1475 (x >= panel_col_min + wid) || (x < panel_col_min))
1477 if (change_panel(dy, dx)) target_set_prepare(mode);
1480 /* Slide into legality */
1481 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
1482 else if (x <= 0) x = 1;
1484 /* Slide into legality */
1485 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
1486 else if (y <= 0) y = 1;
1494 /* Clear the top line */
1497 /* Recenter the map around the player */
1499 p_ptr->update |= (PU_MONSTERS);
1500 p_ptr->redraw |= (PR_MAP);
1501 p_ptr->window |= (PW_OVERHEAD);
1504 /* Failure to set target */
1505 if (!target_who) return (FALSE);
1513 * Get an "aiming direction" from the user.
1515 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1516 * "0" for "current target", and "-1" for "entry aborted".
1518 * Note that "Force Target", if set, will pre-empt user interaction,
1519 * if there is a usable target already set.
1521 * Note that confusion over-rides any (explicit?) user choice.
1523 bool get_aim_dir(DIRECTION *dp)
1532 /* Global direction */
1535 /* Hack -- auto-target if requested */
1536 if (use_old_target && target_okay()) dir = 5;
1538 if (repeat_pull(&code))
1543 if (!(code == 5 && !target_okay()))
1545 /* return (TRUE); */
1546 dir = (DIRECTION)code;
1549 *dp = (DIRECTION)code;
1551 /* Ask until satisfied */
1554 /* Choose a prompt */
1557 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1561 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
1564 /* Get a command (or Cancel) */
1565 if (!get_com(p, &command, TRUE)) break;
1569 if (command == '\r') command = 't';
1572 /* Convert various keys to "standard" keys */
1575 /* Use current target */
1586 /* Set new target */
1591 if (target_set(TARGET_KILL)) dir = 5;
1597 /* Extract the action (if any) */
1598 dir = get_keymap_dir(command);
1604 /* Verify requested targets */
1605 if ((dir == 5) && !target_okay()) dir = 0;
1614 project_length = 0; /* reset to default */
1618 /* Save the direction */
1621 /* Check for confusion */
1622 if (p_ptr->confused)
1624 /* Random direction */
1625 dir = ddd[randint0(8)];
1628 /* Notice confusion */
1629 if (command_dir != dir)
1632 msg_print(_("あなたは混乱している。", "You are confused."));
1635 /* Save direction */
1638 /* repeat_push(dir); */
1639 repeat_push((COMMAND_CODE)command_dir);
1641 /* A "valid" direction was entered */
1646 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
1654 /* Global direction */
1657 if (repeat_pull(&code))
1659 dir = (DIRECTION)code;
1660 /* return (TRUE); */
1662 *dp = (DIRECTION)code;
1666 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1670 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1673 /* Get a direction */
1678 /* Get a command (or Cancel) */
1679 if (!get_com(prompt, &ch, TRUE)) break;
1682 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1688 /* Look up the direction */
1689 dir = get_keymap_dir(ch);
1695 /* Prevent weirdness */
1696 if ((dir == 5) && (!allow_under)) dir = 0;
1699 if (!dir) return (FALSE);
1701 /* Save desired direction */
1704 /* Apply "confusion" */
1705 if (p_ptr->confused)
1707 /* Standard confusion */
1708 if (randint0(100) < 75)
1710 /* Random direction */
1711 dir = ddd[randint0(8)];
1714 else if (p_ptr->riding && with_steed)
1716 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1717 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1719 if (MON_CONFUSED(m_ptr))
1721 /* Standard confusion */
1722 if (randint0(100) < 75)
1724 /* Random direction */
1725 dir = ddd[randint0(8)];
1728 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1730 /* Random direction */
1731 dir = ddd[randint0(8)];
1733 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1735 /* Random direction */
1736 dir = ddd[randint0(8)];
1740 /* Notice confusion */
1741 if (command_dir != dir)
1743 if (p_ptr->confused)
1746 msg_print(_("あなたは混乱している。", "You are confused."));
1750 GAME_TEXT m_name[MAX_NLEN];
1751 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1753 monster_desc(m_name, m_ptr, 0);
1754 if (MON_CONFUSED(m_ptr))
1756 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1760 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1765 /* Save direction */
1768 /* repeat_push(dir); */
1769 repeat_push((COMMAND_CODE)command_dir);
1776 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
1777 * and place it into "command_dir", unless we already have one.
1779 * This function should be used for all "repeatable" commands, such as
1780 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
1781 * as all commands which must reference a grid adjacent to the player,
1782 * and which may not reference the grid under the player. Note that,
1783 * for example, it is no longer possible to "disarm" or "open" chests
1784 * in the same grid as the player.
1786 * Direction "5" is illegal and will (cleanly) abort the command.
1788 * This function tracks and uses the "global direction", and uses
1789 * that as the "desired direction", to which "confusion" is applied.
1791 bool get_rep_dir(DIRECTION *dp, bool under)
1799 /* Global direction */
1802 if (repeat_pull(&code))
1804 dir = (DIRECTION)code;
1805 /* return (TRUE); */
1807 *dp = (DIRECTION)code;
1811 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1815 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1818 /* Get a direction */
1823 /* Get a command (or Cancel) */
1824 if (!get_com(prompt, &ch, TRUE)) break;
1827 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1833 /* Look up the direction */
1834 dir = get_keymap_dir(ch);
1840 /* Prevent weirdness */
1841 if ((dir == 5) && (!under)) dir = 0;
1844 if (!dir) return (FALSE);
1846 /* Save desired direction */
1849 /* Apply "confusion" */
1850 if (p_ptr->confused)
1852 /* Standard confusion */
1853 if (randint0(100) < 75)
1855 /* Random direction */
1856 dir = ddd[randint0(8)];
1859 else if (p_ptr->riding)
1861 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1862 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1864 if (MON_CONFUSED(m_ptr))
1866 /* Standard confusion */
1867 if (randint0(100) < 75)
1869 /* Random direction */
1870 dir = ddd[randint0(8)];
1873 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1875 /* Random direction */
1876 dir = ddd[randint0(8)];
1878 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1880 /* Random direction */
1881 dir = ddd[randint0(8)];
1885 /* Notice confusion */
1886 if (command_dir != dir)
1888 if (p_ptr->confused)
1891 msg_print(_("あなたは混乱している。", "You are confused."));
1895 GAME_TEXT m_name[MAX_NLEN];
1896 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
1898 monster_desc(m_name, m_ptr, 0);
1899 if (MON_CONFUSED(m_ptr))
1901 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
1905 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1910 /* Save direction */
1913 /* repeat_push(dir); */
1914 repeat_push((COMMAND_CODE)command_dir);
1922 * XAngband: determine if a given location is "interesting"
1923 * based on target_set_accept function.
1925 static bool tgt_pt_accept(POSITION y, POSITION x)
1929 if (!(in_bounds(y, x))) return (FALSE);
1931 /* Player grid is always interesting */
1932 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
1934 if (p_ptr->image) return (FALSE);
1936 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1938 /* Interesting memorized features */
1939 if (g_ptr->info & (CAVE_MARK))
1942 if (cave_have_flag_grid(g_ptr, FF_LESS)) return (TRUE);
1943 if (cave_have_flag_grid(g_ptr, FF_MORE)) return (TRUE);
1945 /* Notice quest features */
1946 if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return (TRUE);
1947 if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return (TRUE);
1955 * XAngband: Prepare the "temp" array for "tget_pt"
1956 * based on target_set_prepare funciton.
1958 static void tgt_pt_prepare(void)
1962 /* Reset "temp" array */
1965 if (!expand_list) return;
1967 /* Scan the current panel */
1968 for (y = 1; y < current_floor_ptr->height; y++)
1970 for (x = 1; x < current_floor_ptr->width; x++)
1972 /* Require "interesting" contents */
1973 if (!tgt_pt_accept(y, x)) continue;
1975 /* Save the location */
1976 tmp_pos.x[tmp_pos.n] = x;
1977 tmp_pos.y[tmp_pos.n] = y;
1982 /* Sort the positions */
1983 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
1987 * old -- from PsiAngband.
1989 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
1994 bool success = FALSE;
1998 get_screen_size(&wid, &hgt);
2008 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2009 msg_flag = FALSE; /* prevents "-more-" message. */
2011 while ((ch != ESCAPE) && !success)
2013 bool move_fast = FALSE;
2015 move_cursor_relative(y, x);
2027 if (player_bold(y, x)) ch = 0;
2030 else success = TRUE;
2034 /* XAngband: Move cursor to stairs */
2037 if (expand_list && tmp_pos.n)
2040 int cx = (panel_col_min + panel_col_max) / 2;
2041 int cy = (panel_row_min + panel_row_max) / 2;
2045 /* Skip stairs which have defferent distance */
2046 for (; n < tmp_pos.n; ++ n)
2048 grid_type *g_ptr = ¤t_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
2050 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2051 cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2058 if (n == tmp_pos.n) /* Loop out taget list */
2063 verify_panel(); /* Move cursor to player */
2065 p_ptr->update |= (PU_MONSTERS);
2067 p_ptr->redraw |= (PR_MAP);
2069 p_ptr->window |= (PW_OVERHEAD);
2072 else /* move cursor to next stair and change panel */
2077 dy = 2 * (y - cy) / hgt;
2078 dx = 2 * (x - cx) / wid;
2079 if (dy || dx) change_panel(dy, dx);
2085 /* Look up the direction */
2086 d = get_keymap_dir(ch);
2088 /* XTRA HACK MOVEFAST */
2089 if (isupper(ch)) move_fast = TRUE;
2091 /* Handle "direction" */
2097 /* XTRA HACK MOVEFAST */
2100 int mag = MIN(wid / 2, hgt / 2);
2110 /* Do not move horizontally if unnecessary */
2111 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2112 ((x > panel_col_min + wid / 2) && (dx < 0)))
2117 /* Do not move vertically if unnecessary */
2118 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2119 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2124 /* Apply the motion */
2125 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2126 (x >= panel_col_min + wid) || (x < panel_col_min))
2128 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2129 change_panel(dy, dx);
2132 /* Slide into legality */
2133 if (x >= current_floor_ptr->width-1) x = current_floor_ptr->width - 2;
2134 else if (x <= 0) x = 1;
2136 /* Slide into legality */
2137 if (y >= current_floor_ptr->height-1) y = current_floor_ptr->height- 2;
2138 else if (y <= 0) y = 1;
2145 /* Clear the top line */
2148 /* Recenter the map around the player */
2151 p_ptr->update |= (PU_MONSTERS);
2153 p_ptr->redraw |= (PR_MAP);
2155 p_ptr->window |= (PW_OVERHEAD);
2164 bool get_hack_dir(DIRECTION *dp)
2172 /* Global direction */
2175 /* (No auto-targeting) */
2177 /* Ask until satisfied */
2180 /* Choose a prompt */
2183 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2187 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2190 /* Get a command (or Cancel) */
2191 if (!get_com(p, &command, TRUE)) break;
2195 if (command == '\r') command = 't';
2198 /* Convert various keys to "standard" keys */
2201 /* Use current target */
2212 /* Set new target */
2217 if (target_set(TARGET_KILL)) dir = 5;
2223 /* Look up the direction */
2224 dir = get_keymap_dir(command);
2230 /* Verify requested targets */
2231 if ((dir == 5) && !target_okay()) dir = 0;
2238 if (!dir) return (FALSE);
2240 /* Save the direction */
2243 /* Check for confusion */
2244 if (p_ptr->confused)
2246 /* Random direction */
2247 dir = ddd[randint0(8)];
2250 /* Notice confusion */
2251 if (command_dir != dir)
2254 msg_print(_("あなたは混乱している。", "You are confused."));
2257 /* Save direction */
2260 /* A "valid" direction was entered */