OSDN Git Service

Merge remote-tracking branch 'remotes/hengbandosx/english-_ptr-in-message' into featu...
[hengband/hengband.git] / src / target / target-checker.c
1 /*!
2  * @brief 雑多なその他の処理2 / effects of various "objects"
3  * @date 2014/02/06
4  * @author
5  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke\n
6  * This software may be copied and distributed for educational, research, and\n
7  * not for profit purposes provided that this copyright and statement are\n
8  * included in all such copies.\n
9  * 2014 Deskull rearranged comment for Doxygen.
10  */
11
12 #include "target/target-checker.h"
13 #include "core/player-redraw-types.h"
14 #include "core/player-update-types.h"
15 #include "core/window-redrawer.h"
16 #include "core/disturbance.h"
17 #include "game-option/disturbance-options.h"
18 #include "game-option/map-screen-options.h"
19 #include "io/cursor.h"
20 #include "io/screen-util.h"
21 #include "system/floor-type-definition.h"
22 #include "system/monster-type-definition.h"
23 #include "target/target-preparation.h"
24 #include "target/target-types.h"
25 #include "window/main-window-util.h"
26
27 /* Targetting variables */
28 MONSTER_IDX target_who;
29 POSITION target_col;
30 POSITION target_row;
31
32 /*!
33  * @brief マップ描画のフォーカスを当てるべき座標を更新する
34  * @param creature_ptr プレーヤーへの参照ポインタ
35  * @details
36  * Given an row (y) and col (x), this routine detects when a move
37  * off the screen has occurred and figures new borders. -RAK-
38  * "Update" forces a "full update" to take place.
39  * The map is reprinted if necessary, and "TRUE" is returned.
40  * @return 実際に再描画が必要だった場合TRUEを返す
41  */
42 void verify_panel(player_type *creature_ptr)
43 {
44     POSITION y = creature_ptr->y;
45     POSITION x = creature_ptr->x;
46     TERM_LEN wid, hgt;
47     get_screen_size(&wid, &hgt);
48     int max_prow_min = creature_ptr->current_floor_ptr->height - hgt;
49     int max_pcol_min = creature_ptr->current_floor_ptr->width - wid;
50     if (max_prow_min < 0)
51         max_prow_min = 0;
52     if (max_pcol_min < 0)
53         max_pcol_min = 0;
54
55     int prow_min;
56     int pcol_min;
57     if (center_player && (center_running || !creature_ptr->running)) {
58         prow_min = y - hgt / 2;
59         if (prow_min < 0)
60             prow_min = 0;
61         else if (prow_min > max_prow_min)
62             prow_min = max_prow_min;
63
64         pcol_min = x - wid / 2;
65         if (pcol_min < 0)
66             pcol_min = 0;
67         else if (pcol_min > max_pcol_min)
68             pcol_min = max_pcol_min;
69     } else {
70         prow_min = panel_row_min;
71         pcol_min = panel_col_min;
72         if (y > panel_row_max - 2)
73             while (y > prow_min + hgt - 1 - 2)
74                 prow_min += (hgt / 2);
75
76         if (y < panel_row_min + 2)
77             while (y < prow_min + 2)
78                 prow_min -= (hgt / 2);
79
80         if (prow_min > max_prow_min)
81             prow_min = max_prow_min;
82
83         if (prow_min < 0)
84             prow_min = 0;
85
86         if (x > panel_col_max - 4)
87             while (x > pcol_min + wid - 1 - 4)
88                 pcol_min += (wid / 2);
89
90         if (x < panel_col_min + 4)
91             while (x < pcol_min + 4)
92                 pcol_min -= (wid / 2);
93
94         if (pcol_min > max_pcol_min)
95             pcol_min = max_pcol_min;
96
97         if (pcol_min < 0)
98             pcol_min = 0;
99     }
100
101     if ((prow_min == panel_row_min) && (pcol_min == panel_col_min))
102         return;
103
104     panel_row_min = prow_min;
105     panel_col_min = pcol_min;
106     if (disturb_panel && !center_player)
107         disturb(creature_ptr, FALSE, FALSE);
108
109     panel_bounds_center();
110     creature_ptr->update |= PU_MONSTERS;
111     creature_ptr->redraw |= PR_MAP;
112     creature_ptr->window |= PW_OVERHEAD | PW_DUNGEON;
113 }
114
115 /*
116  * Update (if necessary) and verify (if possible) the target.
117  * We return TRUE if the target is "okay" and FALSE otherwise.
118  */
119 bool target_okay(player_type *creature_ptr)
120 {
121     if (target_who < 0)
122         return TRUE;
123
124     if (target_who <= 0)
125         return FALSE;
126
127     if (!target_able(creature_ptr, target_who))
128         return FALSE;
129
130     monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[target_who];
131     target_row = m_ptr->fy;
132     target_col = m_ptr->fx;
133     return TRUE;
134 }