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"
25 #include "floor-events.h"
27 #define REWARD_CHANCE 10
31 * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
32 * Advance experience levels and print experience
35 void check_experience(void)
37 bool level_reward = FALSE;
38 bool level_mutation = FALSE;
39 bool level_inc_stat = FALSE;
40 bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
41 PLAYER_LEVEL old_lev = p_ptr->lev;
43 /* Hack -- lower limit */
44 if (p_ptr->exp < 0) p_ptr->exp = 0;
45 if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
46 if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
48 /* Hack -- upper limit */
49 if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
50 if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
51 if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
53 /* Hack -- maintain "max" experience */
54 if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
56 /* Hack -- maintain "max max" experience */
57 if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
59 /* Redraw experience */
60 p_ptr->redraw |= (PR_EXP);
64 /* Lose levels while possible */
65 while ((p_ptr->lev > 1) &&
66 (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
70 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
71 p_ptr->redraw |= (PR_LEV | PR_TITLE);
72 p_ptr->window |= (PW_PLAYER);
77 /* Gain levels while possible */
78 while ((p_ptr->lev < PY_MAX_LEVEL) &&
79 (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
84 /* Save the highest level */
85 if (p_ptr->lev > p_ptr->max_plv)
87 p_ptr->max_plv = p_ptr->lev;
89 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
90 (p_ptr->muta2 & MUT2_CHAOS_GIFT))
94 if (p_ptr->prace == RACE_BEASTMAN)
96 if (one_in_(5)) level_mutation = TRUE;
98 level_inc_stat = TRUE;
100 do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
105 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
107 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
108 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
109 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
119 if(!(p_ptr->max_plv % 10))
128 cnv_stat(p_ptr->stat_max[0], tmp);
129 prt(format(_(" a) 腕力 (現在値 %s)", " a) Str (cur %s)"), tmp), 2, 14);
130 cnv_stat(p_ptr->stat_max[1], tmp);
131 prt(format(_(" b) 知能 (現在値 %s)", " a) Int (cur %s)"), tmp), 3, 14);
132 cnv_stat(p_ptr->stat_max[2], tmp);
133 prt(format(_(" c) 賢さ (現在値 %s)", " a) Wis (cur %s)"), tmp), 4, 14);
134 cnv_stat(p_ptr->stat_max[3], tmp);
135 prt(format(_(" d) 器用 (現在値 %s)", " a) Dex (cur %s)"), tmp), 5, 14);
136 cnv_stat(p_ptr->stat_max[4], tmp);
137 prt(format(_(" e) 耐久 (現在値 %s)", " a) Con (cur %s)"), tmp), 6, 14);
138 cnv_stat(p_ptr->stat_max[5], tmp);
139 prt(format(_(" f) 魅力 (現在値 %s)", " a) Chr (cur %s)"), tmp), 7, 14);
142 prt(_(" どの能力値を上げますか?", " Which stat do you want to raise?"), 1, 14);
147 if ((choice >= 'a') && (choice <= 'f')) break;
149 for(n = 0; n < A_MAX; n++)
150 if (n != choice - 'a')
152 if (get_check(_("よろしいですか?", "Are you sure? "))) break;
154 do_inc_stat(choice - 'a');
157 else if(!(p_ptr->max_plv % 2))
158 do_inc_stat(randint0(6));
163 msg_print(_("あなたは変わった気がする...", "You feel different..."));
164 (void)gain_random_mutation(0);
165 level_mutation = FALSE;
169 * 報酬でレベルが上ると再帰的に check_experience() が
174 gain_level_reward(0);
175 level_reward = FALSE;
178 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
179 p_ptr->redraw |= (PR_LEV | PR_TITLE);
180 p_ptr->window |= (PW_PLAYER | PW_SPELL);
184 /* Load an autopick preference file */
185 if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
191 * @brief モンスターを撃破した際の述語メッセージを返す /
192 * Return monster death string
193 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
194 * @return 撃破されたモンスターの述語
196 concptr extract_note_dies(MONRACE_IDX r_idx)
198 monster_race *r_ptr = &r_info[r_idx];
199 /* Some monsters get "destroyed" */
200 if (!monster_living(r_idx))
204 for (i = 0; i < 4; i++)
206 if (r_ptr->blow[i].method == RBM_EXPLODE)
208 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
211 return _("を倒した。", " is destroyed.");
214 /* Assume a default death */
215 return _("は死んだ。", " dies.");
220 * @brief モンスターに与えたダメージの修正処理 /
221 * Modify the physical damage done to the monster.
222 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
224 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
225 * @return 修正を行った結果のダメージ量
228 * (for example when it's invulnerable or shielded)
229 * ToDo: Accept a damage-type to calculate the modified damage from
230 * things like fire, frost, lightning, poison, ... attacks.
231 * "type" is not yet used and should be 0.
234 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
236 monster_race *r_ptr = &r_info[m_ptr->r_idx];
238 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
241 if ((dam == 0) && one_in_(3)) dam = 1;
244 if (MON_INVULNER(m_ptr))
248 if (!p_ptr->blind && is_seen(m_ptr))
250 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
253 else if (!one_in_(PENETRATE_INVULNERABILITY))
265 * @brief 現在のコンソール表示の縦横を返す。 /
266 * Get term size and calculate screen size
267 * @param wid_p コンソールの表示幅文字数を返す
268 * @param hgt_p コンソールの表示行数を返す
271 void get_screen_size(TERM_LEN *wid_p, TERM_LEN *hgt_p)
273 Term_get_size(wid_p, hgt_p);
274 *hgt_p -= ROW_MAP + 2;
275 *wid_p -= COL_MAP + 2;
276 if (use_bigtile) *wid_p /= 2;
281 * @brief コンソール上におけるマップ表示の左上位置を返す /
282 * Calculates current boundaries Called below and from "do_cmd_locate()".
285 void panel_bounds_center(void)
289 get_screen_size(&wid, &hgt);
291 panel_row_max = panel_row_min + hgt - 1;
292 panel_row_prt = panel_row_min - 1;
293 panel_col_max = panel_col_min + wid - 1;
294 panel_col_prt = panel_col_min - 13;
299 * @brief コンソールのリサイズに合わせてマップを再描画する /
300 * Map resizing whenever the main term changes size
303 void resize_map(void)
305 /* Only if the dungeon exists */
306 if (!character_dungeon) return;
308 /* Mega-Hack -- no panel yet */
312 /* Reset the panels */
313 panel_row_min = cur_hgt;
314 panel_col_min = cur_wid;
318 p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
319 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
320 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
321 p_ptr->update |= (PU_MONSTERS);
322 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
329 * Place the cursor on the player
331 if (can_save) move_cursor_relative(p_ptr->y, p_ptr->x);
337 * @brief コンソールを再描画する /
338 * Redraw a term when it is resized
341 void redraw_window(void)
343 /* Only if the dungeon exists */
344 if (!character_dungeon) return;
346 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
347 p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
355 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
356 * @param dy 変更先のフロアY座標
357 * @param dx 変更先のフロアX座標
358 * Handle a request to change the current panel
359 * Return TRUE if the panel was changed.
360 * Also used in do_cmd_locate
361 * @return 実際に再描画が必要だった場合TRUEを返す
363 bool change_panel(POSITION dy, POSITION dx)
368 get_screen_size(&wid, &hgt);
370 /* Apply the motion */
371 y = panel_row_min + dy * hgt / 2;
372 x = panel_col_min + dx * wid / 2;
375 if (y > cur_hgt - hgt) y = cur_hgt - hgt;
379 if (x > cur_wid - wid) x = cur_wid - wid;
382 /* Handle "changes" */
383 if ((y != panel_row_min) || (x != panel_col_min))
385 /* Save the new panel info */
389 /* Recalculate the boundaries */
390 panel_bounds_center();
392 p_ptr->update |= (PU_MONSTERS);
393 p_ptr->redraw |= (PR_MAP);
405 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
406 * @param y 変更先のフロアY座標
407 * @param x 変更先のフロアX座標
409 * Handle a request to change the current panel
410 * Return TRUE if the panel was changed.
411 * Also used in do_cmd_locate
412 * @return 実際に再描画が必要だった場合TRUEを返す
414 static bool change_panel_xy(POSITION y, POSITION x)
416 POSITION dy = 0, dx = 0;
419 get_screen_size(&wid, &hgt);
421 if (y < panel_row_min) dy = -1;
422 if (y > panel_row_max) dy = 1;
423 if (x < panel_col_min) dx = -1;
424 if (x > panel_col_max) dx = 1;
426 if (!dy && !dx) return (FALSE);
428 return change_panel(dy, dx);
433 * @brief マップ描画のフォーカスを当てるべき座標を更新する
435 * Given an row (y) and col (x), this routine detects when a move
436 * off the screen has occurred and figures new borders. -RAK-
437 * "Update" forces a "full update" to take place.
438 * The map is reprinted if necessary, and "TRUE" is returned.
439 * @return 実際に再描画が必要だった場合TRUEを返す
441 void verify_panel(void)
443 POSITION y = p_ptr->y;
444 POSITION x = p_ptr->x;
452 get_screen_size(&wid, &hgt);
454 max_prow_min = cur_hgt - hgt;
455 max_pcol_min = cur_wid - wid;
457 /* Bounds checking */
458 if (max_prow_min < 0) max_prow_min = 0;
459 if (max_pcol_min < 0) max_pcol_min = 0;
461 /* Center on player */
462 if (center_player && (center_running || !running))
464 /* Center vertically */
465 prow_min = y - hgt / 2;
466 if (prow_min < 0) prow_min = 0;
467 else if (prow_min > max_prow_min) prow_min = max_prow_min;
469 /* Center horizontally */
470 pcol_min = x - wid / 2;
471 if (pcol_min < 0) pcol_min = 0;
472 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
476 prow_min = panel_row_min;
477 pcol_min = panel_col_min;
479 /* Scroll screen when 2 grids from top/bottom edge */
480 if (y > panel_row_max - 2)
482 while (y > prow_min + hgt-1 - 2)
484 prow_min += (hgt / 2);
488 if (y < panel_row_min + 2)
490 while (y < prow_min + 2)
492 prow_min -= (hgt / 2);
496 if (prow_min > max_prow_min) prow_min = max_prow_min;
497 if (prow_min < 0) prow_min = 0;
499 /* Scroll screen when 4 grids from left/right edge */
500 if (x > panel_col_max - 4)
502 while (x > pcol_min + wid-1 - 4)
504 pcol_min += (wid / 2);
508 if (x < panel_col_min + 4)
510 while (x < pcol_min + 4)
512 pcol_min -= (wid / 2);
516 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
517 if (pcol_min < 0) pcol_min = 0;
520 /* Check for "no change" */
521 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
523 /* Save the new panel info */
524 panel_row_min = prow_min;
525 panel_col_min = pcol_min;
527 /* Hack -- optional disturb on "panel change" */
528 if (disturb_panel && !center_player) disturb(FALSE, FALSE);
530 /* Recalculate the boundaries */
531 panel_bounds_center();
533 p_ptr->update |= (PU_MONSTERS);
534 p_ptr->redraw |= (PR_MAP);
535 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
540 * Monster health description
542 concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
544 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
551 /* Determine if the monster is "living" */
552 living = monster_living(m_ptr->ap_r_idx);
554 /* Calculate a health "percentage" */
555 perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
557 /* Healthy monsters */
558 if (m_ptr->hp >= m_ptr->maxhp)
560 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
565 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
570 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
575 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
580 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
583 /* Need attitude information? */
586 /* Full information is not needed */
589 else if (is_pet(m_ptr))
591 attitude = _(", ペット", ", pet");
593 else if (is_friendly(m_ptr))
595 attitude = _(", 友好的", ", friendly");
599 attitude = _("", "");
603 if (m_ptr->smart & SM_CLONED)
612 /* Display monster's level --- idea borrowed from ToME */
613 if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
615 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
619 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
626 /*** Targeting Code ***/
630 * Determine is a monster makes a reasonable target
632 * The concept of "targeting" was stolen from "Morgul" (?)
634 * The player can target any location, or any "target-able" monster.
636 * Currently, a monster is "target_able" if it is visible, and if
637 * the player can hit it with a projection, and the player is not
638 * hallucinating. This allows use of "use closest target" macros.
640 * Future versions may restrict the ability to target "trappers"
641 * and "mimics", but the semantics is a little bit weird.
643 bool target_able(MONSTER_IDX m_idx)
645 monster_type *m_ptr = &m_list[m_idx];
647 /* Monster must be alive */
648 if (!m_ptr->r_idx) return (FALSE);
650 /* Hack -- no targeting hallucinations */
651 if (p_ptr->image) return (FALSE);
653 /* Monster must be visible */
654 if (!m_ptr->ml) return (FALSE);
656 if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
658 /* Monster must be projectable */
659 if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
661 /* Hack -- Never target trappers */
662 /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
672 * Update (if necessary) and verify (if possible) the target.
674 * We return TRUE if the target is "okay" and FALSE otherwise.
676 bool target_okay(void)
678 /* Accept stationary targets */
679 if (target_who < 0) return (TRUE);
681 /* Check moving targets */
684 /* Accept reasonable targets */
685 if (target_able(target_who))
687 monster_type *m_ptr = &m_list[target_who];
689 /* Acquire monster location */
690 target_row = m_ptr->fy;
691 target_col = m_ptr->fx;
698 /* Assume no target */
704 * Sorting hook -- comp function -- by "distance to player"
706 * We use "u" and "v" to point to arrays of "x" and "y" positions,
707 * and sort the arrays by double-distance to the player.
709 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
711 POSITION *x = (POSITION*)(u);
712 POSITION *y = (POSITION*)(v);
714 POSITION da, db, kx, ky;
716 /* Absolute distance components */
717 kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
718 ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
720 /* Approximate Double Distance to the first point */
721 da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
723 /* Absolute distance components */
724 kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
725 ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
727 /* Approximate Double Distance to the first point */
728 db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
730 /* Compare the distances */
736 * Sorting hook -- comp function -- by importance level of grids
738 * We use "u" and "v" to point to arrays of "x" and "y" positions,
739 * and sort the arrays by level of monster
741 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
743 POSITION *x = (POSITION*)(u);
744 POSITION *y = (POSITION*)(v);
745 cave_type *ca_ptr = &cave[y[a]][x[a]];
746 cave_type *cb_ptr = &cave[y[b]][x[b]];
747 monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
748 monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
749 monster_race *ap_ra_ptr, *ap_rb_ptr;
751 /* The player grid */
752 if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
753 if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
755 /* Extract monster race */
756 if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
757 else ap_ra_ptr = NULL;
758 if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
759 else ap_rb_ptr = NULL;
761 if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
762 if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
764 /* Compare two monsters */
765 if (ap_ra_ptr && ap_rb_ptr)
767 /* Unique monsters first */
768 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
769 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
771 /* Shadowers first (あやしい影) */
772 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
773 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
775 /* Unknown monsters first */
776 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
777 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
779 /* Higher level monsters first (if known) */
780 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
782 if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
783 if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
786 /* Sort by index if all conditions are same */
787 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
788 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
791 /* An object get higher priority */
792 if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
793 if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
795 /* Priority from the terrain */
796 if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
797 if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
799 /* If all conditions are same, compare distance */
800 return ang_sort_comp_distance(u, v, a, b);
805 * Sorting hook -- swap function -- by "distance to player"
807 * We use "u" and "v" to point to arrays of "x" and "y" positions,
808 * and sort the arrays by distance to the player.
810 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
812 POSITION *x = (POSITION*)(u);
813 POSITION *y = (POSITION*)(v);
831 * Hack -- help "select" a location (see below)
833 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
836 POSITION x2, y2, x3, y3, x4, y4;
837 POSITION_IDX b_i = -1, b_v = 9999;
840 /* Scan the locations */
841 for (i = 0; i < temp_n; i++)
847 /* Directed distance */
851 /* Verify quadrant */
852 if (dx && (x3 * dx <= 0)) continue;
853 if (dy && (y3 * dy <= 0)) continue;
855 /* Absolute distance */
859 /* Verify quadrant */
860 if (dy && !dx && (x4 > y4)) continue;
861 if (dx && !dy && (y4 > x4)) continue;
863 /* Approximate Double Distance */
864 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
866 /* Penalize location */
869 if ((b_i >= 0) && (v >= b_v)) continue;
879 * Hack -- determine if a given location is "interesting"
881 static bool target_set_accept(POSITION y, POSITION x)
884 OBJECT_IDX this_o_idx, next_o_idx = 0;
887 if (!(in_bounds(y, x))) return (FALSE);
889 /* Player grid is always interesting */
890 if (player_bold(y, x)) return (TRUE);
892 /* Handle hallucination */
893 if (p_ptr->image) return (FALSE);
895 /* Examine the grid */
898 /* Visible monsters */
901 monster_type *m_ptr = &m_list[c_ptr->m_idx];
903 /* Visible monsters */
904 if (m_ptr->ml) return (TRUE);
907 /* Scan all objects in the grid */
908 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
911 o_ptr = &o_list[this_o_idx];
913 /* Acquire next object */
914 next_o_idx = o_ptr->next_o_idx;
916 /* Memorized object */
917 if (o_ptr->marked & OM_FOUND) return (TRUE);
920 /* Interesting memorized features */
921 if (c_ptr->info & (CAVE_MARK))
923 /* Notice object features */
924 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
926 /* Feature code (applying "mimic" field) */
927 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
935 * Prepare the "temp" array for "target_set"
937 * Return the number of target_able monsters in the set.
939 static void target_set_prepare(BIT_FLAGS mode)
942 POSITION min_hgt, max_hgt, min_wid, max_wid;
944 if (mode & TARGET_KILL)
947 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
948 max_hgt = MIN((p_ptr->y + MAX_RANGE), cur_hgt - 1);
949 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
950 max_wid = MIN((p_ptr->x + MAX_RANGE), cur_wid - 1);
952 else /* not targetting */
955 min_hgt = panel_row_min;
956 max_hgt = panel_row_max;
957 min_wid = panel_col_min;
958 max_wid = panel_col_max;
961 /* Reset "temp" array */
964 /* Scan the current panel */
965 for (y = min_hgt; y <= max_hgt; y++)
967 for (x = min_wid; x <= max_wid; x++)
971 /* Require "interesting" contents */
972 if (!target_set_accept(y, x)) continue;
976 /* Require target_able monsters for "TARGET_KILL" */
977 if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
979 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
981 /* Save the location */
988 /* Set the sort hooks */
989 if (mode & (TARGET_KILL))
991 /* Target the nearest monster for shooting */
992 ang_sort_comp = ang_sort_comp_distance;
993 ang_sort_swap = ang_sort_swap_distance;
997 /* Look important grids first in Look command */
998 ang_sort_comp = ang_sort_comp_importance;
999 ang_sort_swap = ang_sort_swap_distance;
1002 /* Sort the positions */
1003 ang_sort(temp_x, temp_y, temp_n);
1005 if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
1010 temp_y[0] = temp_y[1];
1013 temp_x[0] = temp_x[1];
1018 void target_set_prepare_look(void){
1019 target_set_prepare(TARGET_LOOK);
1024 * Evaluate number of kill needed to gain level
1026 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
1028 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1030 s32b exp_mon, exp_adv;
1031 u32b exp_mon_frac, exp_adv_frac;
1033 if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
1038 else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
1048 /* The monster's experience point (assuming average monster speed) */
1049 exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
1051 s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
1054 /* Total experience value for next level */
1055 exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
1057 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
1059 /* Experience value need to get */
1060 s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
1063 /* You need to kill at least one monster to get any experience */
1064 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1065 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
1067 /* Extract number of monsters needed */
1068 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1070 /* If 999 or more monsters needed, only display "999". */
1071 num = MIN(999, exp_adv_frac);
1073 /* Display the number */
1074 sprintf(buf,"%03ld", (long int)num);
1078 bool show_gold_on_floor = FALSE;
1081 * Examine a grid, return a keypress.
1083 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
1084 * indicates that the "space" key should scan through the contents
1085 * of the grid, instead of simply returning immediately. This lets
1086 * the "look" command get complete information, without making the
1087 * "target" command annoying.
1089 * The "info" argument contains the "commands" which should be shown
1090 * inside the "[xxx]" text. This string must never be empty, or grids
1091 * containing monsters will be displayed with an extra comma.
1093 * Note that if a monster is in the grid, we update both the monster
1094 * recall info and the health bar info to track that monster.
1096 * Eventually, we may allow multiple objects per grid, or objects
1097 * and terrain features in the same grid.
1099 * This function must handle blindness/hallucination.
1101 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
1103 cave_type *c_ptr = &cave[y][x];
1104 OBJECT_IDX this_o_idx, next_o_idx = 0;
1105 concptr s1 = "", s2 = "", s3 = "", x_info = "";
1108 feature_type *f_ptr;
1109 char query = '\001';
1110 char out_val[MAX_NLEN+80];
1111 OBJECT_IDX floor_list[23];
1112 ITEM_NUMBER floor_num = 0;
1114 /* Scan all objects in the grid */
1117 floor_num = scan_floor(floor_list, y, x, 0x02);
1121 x_info = _("x物 ", "x,");
1125 /* Hack -- under the player */
1126 if (player_bold(y, x))
1139 s1 = _("ターゲット:", "Target:");
1142 /* Hack -- hallucination */
1145 concptr name = _("何か奇妙な物", "something strange");
1147 /* Display a message */
1149 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
1151 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1155 move_cursor_relative(y, x);
1158 /* Stop on everything but "return" */
1159 if ((query != '\r') && (query != '\n')) return query;
1161 /* Repeat forever */
1166 /* Actual monsters */
1167 if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1169 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1170 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1171 GAME_TEXT m_name[MAX_NLEN];
1172 bool recall = FALSE;
1177 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1178 monster_race_track(m_ptr->ap_r_idx);
1179 health_track(c_ptr->m_idx);
1192 /* Recall on screen */
1193 screen_roff(m_ptr->ap_r_idx, 0);
1195 /* Hack -- Complete the prompt (again) */
1196 Term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
1203 /* Normal commands */
1204 if (query != 'r') break;
1209 /* Cleare recall text and repeat */
1215 /* Describe, and prompt for recall */
1216 evaluate_monster_exp(acount, m_ptr);
1219 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);
1221 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);
1227 move_cursor_relative(y, x);
1232 /* Normal commands */
1233 if (query != 'r') break;
1239 /* Always stop at "normal" keys */
1240 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1242 /* Sometimes stop at "space" key */
1243 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1245 /* Change the intro */
1246 s1 = _("それは", "It is ");
1248 /* Hack -- take account of gender */
1249 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
1250 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
1252 /* Use a preposition */
1261 /* Scan all objects being carried */
1262 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
1264 GAME_TEXT o_name[MAX_NLEN];
1267 o_ptr = &o_list[this_o_idx];
1269 /* Acquire next object */
1270 next_o_idx = o_ptr->next_o_idx;
1272 /* Obtain an object description */
1273 object_desc(o_name, o_ptr, 0);
1276 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1278 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1282 move_cursor_relative(y, x);
1285 /* Always stop at "normal" keys */
1286 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1288 /* Sometimes stop at "space" key */
1289 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
1291 /* Change the intro */
1292 s2 = _("をまた", "also carrying ");
1295 /* Use a preposition */
1312 GAME_TEXT o_name[MAX_NLEN];
1315 o_ptr = &o_list[floor_list[0]];
1317 object_desc(o_name, o_ptr, 0);
1320 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1322 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1326 move_cursor_relative(y, x);
1335 /* Provide one cushion before item listing */
1338 /* Display rough information about items */
1340 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
1342 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
1346 move_cursor_relative(y, x);
1351 /* No request for listing */
1352 if (query != 'x' && query != ' ') return query;
1356 /** Display list of items **/
1358 /* Continue scrolling list if requested */
1366 show_gold_on_floor = TRUE;
1367 (void)show_floor(0, y, x, &min_width);
1368 show_gold_on_floor = FALSE;
1372 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
1374 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
1381 /* Exit unless 'Enter' */
1382 if (query != '\n' && query != '\r')
1387 /* Get the object being moved. */
1388 o_idx = c_ptr->o_idx;
1390 /* Only rotate a pile of two or more objects. */
1391 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
1393 /* Remove the first object from the list. */
1394 excise_object_idx(o_idx);
1396 /* Find end of the list. */
1398 while (o_list[i].next_o_idx)
1399 i = o_list[i].next_o_idx;
1401 /* Add after the last object. */
1402 o_list[i].next_o_idx = o_idx;
1404 /* Loop and re-display the list */
1411 /* Scan all objects in the grid */
1412 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1415 o_ptr = &o_list[this_o_idx];
1417 /* Acquire next object */
1418 next_o_idx = o_ptr->next_o_idx;
1420 if (o_ptr->marked & OM_FOUND)
1422 GAME_TEXT o_name[MAX_NLEN];
1427 /* Obtain an object description */
1428 object_desc(o_name, o_ptr, 0);
1431 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
1433 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
1437 move_cursor_relative(y, x);
1440 /* Always stop at "normal" keys */
1441 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
1443 /* Sometimes stop at "space" key */
1444 if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
1446 /* Change the intro */
1447 s1 = _("それは", "It is ");
1450 if (o_ptr->number != 1) s1 = _("それらは", "They are ");
1464 /* Feature code (applying "mimic" field) */
1465 feat = get_feat_mimic(c_ptr);
1467 /* Require knowledge about grid, or ability to see grid */
1468 if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
1470 /* Forget feature */
1474 f_ptr = &f_info[feat];
1476 /* Terrain feature if needed */
1477 if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
1481 /* Hack -- special handling for quest entrances */
1482 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
1484 /* Set the quest number temporary */
1485 IDX old_quest = p_ptr->inside_quest;
1488 /* Clear the text */
1489 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
1490 quest_text_line = 0;
1492 p_ptr->inside_quest = c_ptr->special;
1494 /* Get the quest text */
1495 init_flags = INIT_NAME_ONLY;
1497 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
1499 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
1500 quest[c_ptr->special].name, quest[c_ptr->special].level);
1502 /* Reset the old quest number */
1503 p_ptr->inside_quest = old_quest;
1506 /* Hack -- special handling for building doors */
1507 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
1509 name = building[f_ptr->subtype].name;
1511 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
1513 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
1515 else if (have_flag(f_ptr->flags, FF_TOWN))
1517 name = town[c_ptr->special].name;
1519 else if (p_ptr->wild_mode && (feat == feat_floor))
1521 name = _("道", "road");
1525 name = f_name + f_ptr->name;
1531 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
1532 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
1533 have_flag(f_ptr->flags, FF_TOWN)))
1535 s2 = _("の中", "in ");
1538 /* Hack -- special introduction for store & building doors -KMW- */
1539 if (have_flag(f_ptr->flags, FF_STORE) ||
1540 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
1541 (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
1542 have_flag(f_ptr->flags, FF_ENTRANCE))
1547 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
1548 have_flag(f_ptr->flags, FF_TOWN) ||
1549 have_flag(f_ptr->flags, FF_SHALLOW) ||
1550 have_flag(f_ptr->flags, FF_DEEP))
1556 /* Pick proper indefinite article */
1557 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
1561 /* Display a message */
1565 if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
1566 else sprintf(f_idx_str, "%d", c_ptr->feat);
1568 sprintf(out_val, "%s%s%s%s[%s] %x %s %d %d %d (%d,%d) %d", s1, name, s2, s3, info, (unsigned int)c_ptr->info, f_idx_str, c_ptr->dist, c_ptr->cost, c_ptr->when, (int)y, (int)x, travel.cost[y][x]);
1570 sprintf(out_val, "%s%s%s%s [%s] %x %s %d %d %d (%d,%d)", s1, s2, s3, name, info, c_ptr->info, f_idx_str, c_ptr->dist, c_ptr->cost, c_ptr->when, (int)y, (int)x);
1575 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
1577 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1581 move_cursor_relative(y, x);
1584 /* Always stop at "normal" keys */
1585 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
1588 /* Stop on everything but "return" */
1589 if ((query != '\r') && (query != '\n')) return query;
1591 /* Repeat forever */
1597 * Handle "target" and "look".
1599 * Note that this code can be called from "get_aim_dir()".
1601 * All locations must be on the current panel. Consider the use of
1602 * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1603 * some form of "scrolling" the map around the cursor.
1604 * That is, consider the possibility of "auto-scrolling" the screen
1605 * while the cursor moves around. This may require changes in the
1606 * "update_monster()" code to allow "visibility" even if off panel, and
1607 * may require dynamic recalculation of the "temp" grid set.
1609 * Hack -- targeting/observing an "outer border grid" may induce
1610 * problems, so this is not currently allowed.
1612 * The player can use the direction keys to move among "interesting"
1613 * grids in a heuristic manner, or the "space", "+", and "-" keys to
1614 * move through the "interesting" grids in a sequential manner, or
1615 * can enter "location" mode, and use the direction keys to move one
1616 * grid at a time in any direction. The "t" (set target) command will
1617 * only target a monster (as opposed to a location) if the monster is
1618 * target_able and the "interesting" mode is being used.
1620 * The current grid is described using the "look" method above, and
1621 * a new command may be entered at any time, but note that if the
1622 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1623 * where "space" has no obvious meaning) then "space" will scan
1624 * through the description of the current grid until done, instead
1625 * of immediately jumping to the next "interesting" grid. This
1626 * allows the "target" command to retain its old semantics.
1628 * The "*", "+", and "-" keys may always be used to jump immediately
1629 * to the next (or previous) interesting grid, in the proper mode.
1631 * The "return" key may always be used to scan through a complete
1632 * grid description (forever).
1634 * This command will cancel any old target, even if used from
1635 * inside the "look" command.
1637 bool target_set(BIT_FLAGS mode)
1640 POSITION y = p_ptr->y;
1641 POSITION x = p_ptr->x;
1651 get_screen_size(&wid, &hgt);
1656 if (rogue_like_commands)
1665 /* Prepare the "temp" array */
1666 target_set_prepare(mode);
1668 /* Start near the player */
1674 /* Interesting grids */
1681 change_panel_xy(y, x);
1683 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1686 c_ptr = &cave[y][x];
1689 if (target_able(c_ptr->m_idx))
1691 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1694 /* Dis-allow target */
1697 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1703 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1704 los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
1705 strcat(info, cheatinfo);
1708 /* Describe and Prompt */
1710 query = target_set_aux(y, x, mode, info);
1714 /* Assume no "direction" */
1719 if (query == '\r') query = 't';
1737 if (target_able(c_ptr->m_idx))
1739 health_track(c_ptr->m_idx);
1740 target_who = c_ptr->m_idx;
1759 if (!expand_list) done = TRUE;
1769 if (!expand_list) done = TRUE;
1776 /* Recenter the map around the player */
1778 p_ptr->update |= (PU_MONSTERS);
1779 p_ptr->redraw |= (PR_MAP);
1780 p_ptr->window |= (PW_OVERHEAD);
1783 /* Recalculate interesting grids */
1784 target_set_prepare(mode);
1803 if(query == same_key)
1808 if (!expand_list) done = TRUE;
1813 /* Extract the action (if any) */
1814 d = get_keymap_dir(query);
1821 /* Hack -- move around */
1824 /* Modified to scroll to monster */
1825 POSITION y2 = panel_row_min;
1826 POSITION x2 = panel_col_min;
1828 /* Find a new monster */
1829 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
1831 /* Request to target past last interesting grid */
1832 while (flag && (i < 0))
1834 /* Note the change */
1835 if (change_panel(ddy[d], ddx[d]))
1840 /* Recalculate interesting grids */
1841 target_set_prepare(mode);
1843 /* Look at interesting grids */
1846 /* Find a new monster */
1847 i = target_pick(v, u, ddy[d], ddx[d]);
1853 /* Nothing interesting */
1856 POSITION dx = ddx[d];
1857 POSITION dy = ddy[d];
1859 /* Restore previous position */
1862 panel_bounds_center();
1864 p_ptr->update |= (PU_MONSTERS);
1865 p_ptr->redraw |= (PR_MAP);
1866 p_ptr->window |= (PW_OVERHEAD);
1869 /* Recalculate interesting grids */
1870 target_set_prepare(mode);
1872 /* Look at boring grids */
1879 /* Do not move horizontally if unnecessary */
1880 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1881 ((x > panel_col_min + wid / 2) && (dx < 0)))
1886 /* Do not move vertically if unnecessary */
1887 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1888 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1893 /* Apply the motion */
1894 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
1895 (x >= panel_col_min+wid) || (x < panel_col_min))
1897 if (change_panel(dy, dx)) target_set_prepare(mode);
1900 /* Slide into legality */
1901 if (x >= cur_wid-1) x = cur_wid - 2;
1902 else if (x <= 0) x = 1;
1904 /* Slide into legality */
1905 if (y >= cur_hgt-1) y = cur_hgt- 2;
1906 else if (y <= 0) y = 1;
1915 /* Arbitrary grids */
1918 bool move_fast = FALSE;
1920 if (!(mode & TARGET_LOOK)) prt_path(y, x);
1923 c_ptr = &cave[y][x];
1925 /* Default prompt */
1926 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1931 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1932 los(p_ptr->y, p_ptr->x, y, x),
1933 projectable(p_ptr->y, p_ptr->x, y, x));
1934 strcat(info, cheatinfo);
1937 /* Describe and Prompt (enable "TARGET_LOOK") */
1938 while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
1940 /* Assume no direction */
1945 if (query == '\r') query = 't';
1948 /* Analyze the keypress */
1972 /* Recenter the map around the player */
1974 p_ptr->update |= (PU_MONSTERS);
1975 p_ptr->redraw |= (PR_MAP);
1976 p_ptr->window |= (PW_OVERHEAD);
1979 /* Recalculate interesting grids */
1980 target_set_prepare(mode);
2002 /* Pick a nearby monster */
2003 for (i = 0; i < temp_n; i++)
2005 t = distance(y, x, temp_y[i], temp_x[i]);
2015 /* Nothing interesting */
2016 if (bd == 999) flag = FALSE;
2023 /* Extract the action (if any) */
2024 d = get_keymap_dir(query);
2026 /* XTRA HACK MOVEFAST */
2027 if (isupper(query)) move_fast = TRUE;
2034 /* Handle "direction" */
2037 POSITION dx = ddx[d];
2038 POSITION dy = ddy[d];
2040 /* XTRA HACK MOVEFAST */
2043 int mag = MIN(wid / 2, hgt / 2);
2053 /* Do not move horizontally if unnecessary */
2054 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2055 ((x > panel_col_min + wid / 2) && (dx < 0)))
2060 /* Do not move vertically if unnecessary */
2061 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2062 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2067 /* Apply the motion */
2068 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2069 (x >= panel_col_min + wid) || (x < panel_col_min))
2071 if (change_panel(dy, dx)) target_set_prepare(mode);
2074 /* Slide into legality */
2075 if (x >= cur_wid-1) x = cur_wid - 2;
2076 else if (x <= 0) x = 1;
2078 /* Slide into legality */
2079 if (y >= cur_hgt-1) y = cur_hgt- 2;
2080 else if (y <= 0) y = 1;
2088 /* Clear the top line */
2091 /* Recenter the map around the player */
2093 p_ptr->update |= (PU_MONSTERS);
2094 p_ptr->redraw |= (PR_MAP);
2095 p_ptr->window |= (PW_OVERHEAD);
2098 /* Failure to set target */
2099 if (!target_who) return (FALSE);
2107 * Get an "aiming direction" from the user.
2109 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
2110 * "0" for "current target", and "-1" for "entry aborted".
2112 * Note that "Force Target", if set, will pre-empt user interaction,
2113 * if there is a usable target already set.
2115 * Note that confusion over-rides any (explicit?) user choice.
2117 bool get_aim_dir(DIRECTION *dp)
2126 /* Global direction */
2129 /* Hack -- auto-target if requested */
2130 if (use_old_target && target_okay()) dir = 5;
2132 if (repeat_pull(&code))
2137 if (!(code == 5 && !target_okay()))
2139 /* return (TRUE); */
2140 dir = (DIRECTION)code;
2143 *dp = (DIRECTION)code;
2145 /* Ask until satisfied */
2148 /* Choose a prompt */
2151 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2155 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2158 /* Get a command (or Cancel) */
2159 if (!get_com(p, &command, TRUE)) break;
2163 if (command == '\r') command = 't';
2166 /* Convert various keys to "standard" keys */
2169 /* Use current target */
2180 /* Set new target */
2185 if (target_set(TARGET_KILL)) dir = 5;
2191 /* Extract the action (if any) */
2192 dir = get_keymap_dir(command);
2198 /* Verify requested targets */
2199 if ((dir == 5) && !target_okay()) dir = 0;
2208 project_length = 0; /* reset to default */
2212 /* Save the direction */
2215 /* Check for confusion */
2216 if (p_ptr->confused)
2218 /* Random direction */
2219 dir = ddd[randint0(8)];
2222 /* Notice confusion */
2223 if (command_dir != dir)
2226 msg_print(_("あなたは混乱している。", "You are confused."));
2229 /* Save direction */
2232 /* repeat_push(dir); */
2233 repeat_push((COMMAND_CODE)command_dir);
2235 /* A "valid" direction was entered */
2240 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
2248 /* Global direction */
2251 if (repeat_pull(&code))
2253 dir = (DIRECTION)code;
2254 /* return (TRUE); */
2256 *dp = (DIRECTION)code;
2260 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2264 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2267 /* Get a direction */
2272 /* Get a command (or Cancel) */
2273 if (!get_com(prompt, &ch, TRUE)) break;
2276 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2282 /* Look up the direction */
2283 dir = get_keymap_dir(ch);
2289 /* Prevent weirdness */
2290 if ((dir == 5) && (!allow_under)) dir = 0;
2293 if (!dir) return (FALSE);
2295 /* Save desired direction */
2298 /* Apply "confusion" */
2299 if (p_ptr->confused)
2301 /* Standard confusion */
2302 if (randint0(100) < 75)
2304 /* Random direction */
2305 dir = ddd[randint0(8)];
2308 else if (p_ptr->riding && with_steed)
2310 monster_type *m_ptr = &m_list[p_ptr->riding];
2311 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2313 if (MON_CONFUSED(m_ptr))
2315 /* Standard confusion */
2316 if (randint0(100) < 75)
2318 /* Random direction */
2319 dir = ddd[randint0(8)];
2322 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2324 /* Random direction */
2325 dir = ddd[randint0(8)];
2327 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2329 /* Random direction */
2330 dir = ddd[randint0(8)];
2334 /* Notice confusion */
2335 if (command_dir != dir)
2337 if (p_ptr->confused)
2340 msg_print(_("あなたは混乱している。", "You are confused."));
2344 GAME_TEXT m_name[MAX_NLEN];
2345 monster_type *m_ptr = &m_list[p_ptr->riding];
2347 monster_desc(m_name, m_ptr, 0);
2348 if (MON_CONFUSED(m_ptr))
2350 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2354 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2359 /* Save direction */
2362 /* repeat_push(dir); */
2363 repeat_push((COMMAND_CODE)command_dir);
2370 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
2371 * and place it into "command_dir", unless we already have one.
2373 * This function should be used for all "repeatable" commands, such as
2374 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
2375 * as all commands which must reference a grid adjacent to the player,
2376 * and which may not reference the grid under the player. Note that,
2377 * for example, it is no longer possible to "disarm" or "open" chests
2378 * in the same grid as the player.
2380 * Direction "5" is illegal and will (cleanly) abort the command.
2382 * This function tracks and uses the "global direction", and uses
2383 * that as the "desired direction", to which "confusion" is applied.
2385 bool get_rep_dir(DIRECTION *dp, bool under)
2393 /* Global direction */
2396 if (repeat_pull(&code))
2398 dir = (DIRECTION)code;
2399 /* return (TRUE); */
2401 *dp = (DIRECTION)code;
2405 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
2409 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
2412 /* Get a direction */
2417 /* Get a command (or Cancel) */
2418 if (!get_com(prompt, &ch, TRUE)) break;
2421 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
2427 /* Look up the direction */
2428 dir = get_keymap_dir(ch);
2434 /* Prevent weirdness */
2435 if ((dir == 5) && (!under)) dir = 0;
2438 if (!dir) return (FALSE);
2440 /* Save desired direction */
2443 /* Apply "confusion" */
2444 if (p_ptr->confused)
2446 /* Standard confusion */
2447 if (randint0(100) < 75)
2449 /* Random direction */
2450 dir = ddd[randint0(8)];
2453 else if (p_ptr->riding)
2455 monster_type *m_ptr = &m_list[p_ptr->riding];
2456 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2458 if (MON_CONFUSED(m_ptr))
2460 /* Standard confusion */
2461 if (randint0(100) < 75)
2463 /* Random direction */
2464 dir = ddd[randint0(8)];
2467 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
2469 /* Random direction */
2470 dir = ddd[randint0(8)];
2472 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
2474 /* Random direction */
2475 dir = ddd[randint0(8)];
2479 /* Notice confusion */
2480 if (command_dir != dir)
2482 if (p_ptr->confused)
2485 msg_print(_("あなたは混乱している。", "You are confused."));
2489 GAME_TEXT m_name[MAX_NLEN];
2490 monster_type *m_ptr = &m_list[p_ptr->riding];
2492 monster_desc(m_name, m_ptr, 0);
2493 if (MON_CONFUSED(m_ptr))
2495 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
2499 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
2504 /* Save direction */
2507 /* repeat_push(dir); */
2508 repeat_push((COMMAND_CODE)command_dir);
2516 * XAngband: determine if a given location is "interesting"
2517 * based on target_set_accept function.
2519 static bool tgt_pt_accept(POSITION y, POSITION x)
2524 if (!(in_bounds(y, x))) return (FALSE);
2526 /* Player grid is always interesting */
2527 if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
2529 /* Handle hallucination */
2530 if (p_ptr->image) return (FALSE);
2532 /* Examine the grid */
2533 c_ptr = &cave[y][x];
2535 /* Interesting memorized features */
2536 if (c_ptr->info & (CAVE_MARK))
2539 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
2540 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
2542 /* Notice quest features */
2543 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
2544 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
2552 * XAngband: Prepare the "temp" array for "tget_pt"
2553 * based on target_set_prepare funciton.
2555 static void tgt_pt_prepare(void)
2559 /* Reset "temp" array */
2562 if (!expand_list) return;
2564 /* Scan the current panel */
2565 for (y = 1; y < cur_hgt; y++)
2567 for (x = 1; x < cur_wid; x++)
2569 /* Require "interesting" contents */
2570 if (!tgt_pt_accept(y, x)) continue;
2572 /* Save the location */
2579 /* Target the nearest monster for shooting */
2580 ang_sort_comp = ang_sort_comp_distance;
2581 ang_sort_swap = ang_sort_swap_distance;
2583 /* Sort the positions */
2584 ang_sort(temp_x, temp_y, temp_n);
2588 * old -- from PsiAngband.
2590 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
2595 bool success = FALSE;
2599 get_screen_size(&wid, &hgt);
2609 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
2610 msg_flag = FALSE; /* prevents "-more-" message. */
2612 while ((ch != ESCAPE) && !success)
2614 bool move_fast = FALSE;
2616 move_cursor_relative(y, x);
2628 if (player_bold(y, x)) ch = 0;
2631 else success = TRUE;
2635 /* XAngband: Move cursor to stairs */
2638 if (expand_list && temp_n)
2641 int cx = (panel_col_min + panel_col_max) / 2;
2642 int cy = (panel_row_min + panel_row_max) / 2;
2646 /* Skip stairs which have defferent distance */
2647 for (; n < temp_n; ++ n)
2649 cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
2651 if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
2652 cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
2659 if (n == temp_n) /* Loop out taget list */
2664 verify_panel(); /* Move cursor to player */
2666 p_ptr->update |= (PU_MONSTERS);
2668 p_ptr->redraw |= (PR_MAP);
2670 p_ptr->window |= (PW_OVERHEAD);
2673 else /* move cursor to next stair and change panel */
2678 dy = 2 * (y - cy) / hgt;
2679 dx = 2 * (x - cx) / wid;
2680 if (dy || dx) change_panel(dy, dx);
2686 /* Look up the direction */
2687 d = get_keymap_dir(ch);
2689 /* XTRA HACK MOVEFAST */
2690 if (isupper(ch)) move_fast = TRUE;
2692 /* Handle "direction" */
2698 /* XTRA HACK MOVEFAST */
2701 int mag = MIN(wid / 2, hgt / 2);
2711 /* Do not move horizontally if unnecessary */
2712 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2713 ((x > panel_col_min + wid / 2) && (dx < 0)))
2718 /* Do not move vertically if unnecessary */
2719 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2720 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2725 /* Apply the motion */
2726 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2727 (x >= panel_col_min + wid) || (x < panel_col_min))
2729 /* if (change_panel(dy, dx)) target_set_prepare(mode); */
2730 change_panel(dy, dx);
2733 /* Slide into legality */
2734 if (x >= cur_wid-1) x = cur_wid - 2;
2735 else if (x <= 0) x = 1;
2737 /* Slide into legality */
2738 if (y >= cur_hgt-1) y = cur_hgt- 2;
2739 else if (y <= 0) y = 1;
2746 /* Clear the top line */
2749 /* Recenter the map around the player */
2752 p_ptr->update |= (PU_MONSTERS);
2754 p_ptr->redraw |= (PR_MAP);
2756 p_ptr->window |= (PW_OVERHEAD);
2765 bool get_hack_dir(DIRECTION *dp)
2773 /* Global direction */
2776 /* (No auto-targeting) */
2778 /* Ask until satisfied */
2781 /* Choose a prompt */
2784 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2788 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2791 /* Get a command (or Cancel) */
2792 if (!get_com(p, &command, TRUE)) break;
2796 if (command == '\r') command = 't';
2799 /* Convert various keys to "standard" keys */
2802 /* Use current target */
2813 /* Set new target */
2818 if (target_set(TARGET_KILL)) dir = 5;
2824 /* Look up the direction */
2825 dir = get_keymap_dir(command);
2831 /* Verify requested targets */
2832 if ((dir == 5) && !target_okay()) dir = 0;
2839 if (!dir) return (FALSE);
2841 /* Save the direction */
2844 /* Check for confusion */
2845 if (p_ptr->confused)
2847 /* Random direction */
2848 dir = ddd[randint0(8)];
2851 /* Notice confusion */
2852 if (command_dir != dir)
2855 msg_print(_("あなたは混乱している。", "You are confused."));
2858 /* Save direction */
2861 /* A "valid" direction was entered */
2867 * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
2868 * @param sval 射撃武器のアイテム副分類ID
2869 * @return 消費する基本エネルギー
2871 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
2873 ENERGY energy = 10000;
2875 /* Analyze the launcher */
2878 /* Sling and ammo */
2885 /* Short Bow and Arrow */
2892 /* Long Bow and Arrow */
2899 /* Bow of irresponsiblity and Arrow */
2906 /* Light Crossbow and Bolt */
2913 /* Heavy Crossbow and Bolt */
2928 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
2932 /* Analyze the launcher */
2935 /* Sling and ammo */
2942 /* Short Bow and Arrow */
2949 /* Long Bow and Arrow */
2956 /* Bow of irresponsiblity and Arrow */
2963 /* Light Crossbow and Bolt */
2970 /* Heavy Crossbow and Bolt */
2983 * Display a rumor and apply its effects
2986 IDX rumor_num(char *zz, IDX max_idx)
2988 if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
2989 return (IDX)atoi(zz);
2992 concptr rumor_bind_name(char *base, concptr fullname)
2996 s = strstr(base, "{Name}");
3000 v = format("%s%s%s", base, fullname, (s + 6));
3010 void display_rumor(bool ex)
3018 if (randint0(3) == 0) section = 1;
3021 err = _(get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10),
3022 get_rnd_line("rumors.txt", section, Rumor));
3023 if (err) strcpy(Rumor, _("嘘の噂もある。", "Some rumors are wrong."));
3027 if (strncmp(Rumor, "R:", 2) == 0)
3030 concptr rumor_msg = NULL;
3031 concptr rumor_eff_format = NULL;
3032 char fullname[1024] = "";
3034 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
3036 if (strcmp(zz[0], "ARTIFACT") == 0)
3040 object_type *q_ptr = &forge;
3041 artifact_type *a_ptr;
3045 a_idx = rumor_num(zz[1], max_a_idx);
3047 a_ptr = &a_info[a_idx];
3048 if (a_ptr->name) break;
3051 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
3052 object_prep(q_ptr, k_idx);
3053 q_ptr->name1 = a_idx;
3054 q_ptr->ident = IDENT_STORE;
3055 object_desc(fullname, q_ptr, OD_NAME_ONLY);
3057 else if (strcmp(zz[0], "MONSTER") == 0)
3060 monster_race *r_ptr;
3064 r_idx = rumor_num(zz[1], max_r_idx);
3065 r_ptr = &r_info[r_idx];
3066 if (r_ptr->name) break;
3069 strcpy(fullname, r_name + r_ptr->name);
3071 /* Remember this monster */
3072 if (!r_ptr->r_sights)
3077 else if (strcmp(zz[0], "DUNGEON") == 0)
3080 dungeon_info_type *d_ptr;
3084 d_idx = rumor_num(zz[1], max_d_idx);
3085 d_ptr = &d_info[d_idx];
3086 if (d_ptr->name) break;
3089 strcpy(fullname, d_name + d_ptr->name);
3091 if (!max_dlv[d_idx])
3093 max_dlv[d_idx] = d_ptr->mindepth;
3094 rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
3097 else if (strcmp(zz[0], "TOWN") == 0)
3104 t_idx = rumor_num(zz[1], NO_TOWN);
3105 if (town[t_idx].name) break;
3108 strcpy(fullname, town[t_idx].name);
3110 visit = (1L << (t_idx - 1));
3111 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
3113 p_ptr->visit |= visit;
3114 rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
3118 rumor_msg = rumor_bind_name(zz[2], fullname);
3119 msg_print(rumor_msg);
3120 if (rumor_eff_format)
3123 msg_format(rumor_eff_format, fullname);
3128 if (err) msg_print(_("この情報は間違っている。", "This information is wrong."));
3132 msg_format("%s", Rumor);