From 1ed3eafefbbf9af558b4fd4c0637212b80273016 Mon Sep 17 00:00:00 2001 From: mogami Date: Tue, 20 Jan 2004 14:22:35 +0000 Subject: [PATCH] =?utf8?q?look=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?utf8?q?=E3=81=A7=E3=82=B9=E3=83=9A=E3=83=BC=E3=82=B9=E3=82=AD=E3=83=BC?= =?utf8?q?=E3=82=92=E6=8A=BC=E3=81=99=E3=81=A8(1)=E3=83=A2=E3=83=B3?= =?utf8?q?=E3=82=B9=E3=82=BF=E3=83=BC(=E3=83=AC=E3=83=99=E3=83=AB=E3=81=AE?= =?utf8?q?=E9=AB=98=E3=81=84=E9=A0=86)=E3=80=81=20(2)=E3=82=A2=E3=82=A4?= =?utf8?q?=E3=83=86=E3=83=A0=E3=80=81(3)=E9=9A=8E=E6=AE=B5=E3=82=84?= =?utf8?q?=E3=83=89=E3=82=A2=E3=80=81=E3=81=AE=E9=A0=86=E7=95=AA=E3=81=AB?= =?utf8?q?=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?utf8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/xtra2.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/src/xtra2.c b/src/xtra2.c index bd2ff2033..57a09246e 100644 --- a/src/xtra2.c +++ b/src/xtra2.c @@ -2691,6 +2691,54 @@ bool target_okay(void) } +/* + * Examine importance level of the grid. + * + * Unknown unique monster -> 5000 + * Unique monster -> 4000 + level + * Unknown normal monster -> 3000 + * Shadower -> 2999 + * Normal monster -> 2000 + level + * Object -> 1000 + * Empty -> priotity of the terrain + */ +static int get_grid_importance(int y, int x) +{ + cave_type *c_ptr = &cave[y][x]; + + /* A monster */ + if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml) + { + monster_type *m_ptr = &m_list[c_ptr->m_idx]; + monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx]; + + /* Unique monster */ + if (ap_r_ptr->flags1 & RF1_UNIQUE) + { + /* Unknown unique monster */ + if (!ap_r_ptr->r_tkills) return 5000; + + /* Known unique monster */ + return 4000 + ap_r_ptr->level; + } + + /* ¤¢¤ä¤·¤¤±Æ (Shadower) */ + if (m_ptr->mflag2 & MFLAG2_KAGE) return 2999; + + /* Unknown monster */ + if (!ap_r_ptr->r_tkills) return 3000; + + /* Known normal monster */ + return 2000 + ap_r_ptr->level; + } + + /* Object */ + if (c_ptr->o_idx) return 1000; + + /* Empty floor or other terrain */ + return f_info[c_ptr->feat].priority; +} + /* * Sorting hook -- comp function -- by "distance to player" @@ -2725,6 +2773,27 @@ static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b) /* + * Sorting hook -- comp function -- by importance level of grids + * + * We use "u" and "v" to point to arrays of "x" and "y" positions, + * and sort the arrays by level of monster + */ +static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b) +{ + byte *x = (byte*)(u); + byte *y = (byte*)(v); + + int la = get_grid_importance(y[a], x[a]); + int lb = get_grid_importance(y[b], x[b]); + + if (la < lb) return FALSE; + if (la > lb) return TRUE; + + return ang_sort_comp_distance(u, v, a, b); +} + + +/* * Sorting hook -- swap function -- by "distance to player" * * We use "u" and "v" to point to arrays of "x" and "y" positions, @@ -2901,8 +2970,18 @@ static void target_set_prepare(int mode) } /* Set the sort hooks */ - ang_sort_comp = ang_sort_comp_distance; - ang_sort_swap = ang_sort_swap_distance; + if (mode & (TARGET_KILL)) + { + /* Target the nearest monster for shooting */ + ang_sort_comp = ang_sort_comp_distance; + ang_sort_swap = ang_sort_swap_distance; + } + else + { + /* Look important grids first in Look command */ + ang_sort_comp = ang_sort_comp_importance; + ang_sort_swap = ang_sort_swap_distance; + } /* Sort the positions */ ang_sort(temp_x, temp_y, temp_n); -- 2.11.0