OSDN Git Service

Merge pull request #917 from Hourier/feature/Separate-Player-Type-Definition
[hengbandforosx/hengbandosx.git] / src / target / target-checker.cpp
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 "system/player-type-definition.h"
24 #include "target/target-preparation.h"
25 #include "target/target-types.h"
26 #include "window/main-window-util.h"
27
28 /* Targetting variables */
29 MONSTER_IDX target_who;
30 POSITION target_col;
31 POSITION target_row;
32
33 /*!
34  * @brief マップ描画のフォーカスを当てるべき座標を更新する
35  * @param creature_ptr プレーヤーへの参照ポインタ
36  * @details
37  * Given an row (y) and col (x), this routine detects when a move
38  * off the screen has occurred and figures new borders. -RAK-
39  * "Update" forces a "full update" to take place.
40  * The map is reprinted if necessary, and "TRUE" is returned.
41  * @return 実際に再描画が必要だった場合TRUEを返す
42  */
43 void verify_panel(player_type *creature_ptr)
44 {
45     POSITION y = creature_ptr->y;
46     POSITION x = creature_ptr->x;
47     TERM_LEN wid, hgt;
48     get_screen_size(&wid, &hgt);
49     int max_prow_min = creature_ptr->current_floor_ptr->height - hgt;
50     int max_pcol_min = creature_ptr->current_floor_ptr->width - wid;
51     if (max_prow_min < 0)
52         max_prow_min = 0;
53     if (max_pcol_min < 0)
54         max_pcol_min = 0;
55
56     int prow_min;
57     int pcol_min;
58     if (center_player && (center_running || !creature_ptr->running)) {
59         prow_min = y - hgt / 2;
60         if (prow_min < 0)
61             prow_min = 0;
62         else if (prow_min > max_prow_min)
63             prow_min = max_prow_min;
64
65         pcol_min = x - wid / 2;
66         if (pcol_min < 0)
67             pcol_min = 0;
68         else if (pcol_min > max_pcol_min)
69             pcol_min = max_pcol_min;
70     } else {
71         prow_min = panel_row_min;
72         pcol_min = panel_col_min;
73         if (y > panel_row_max - 2)
74             while (y > prow_min + hgt - 1 - 2)
75                 prow_min += (hgt / 2);
76
77         if (y < panel_row_min + 2)
78             while (y < prow_min + 2)
79                 prow_min -= (hgt / 2);
80
81         if (prow_min > max_prow_min)
82             prow_min = max_prow_min;
83
84         if (prow_min < 0)
85             prow_min = 0;
86
87         if (x > panel_col_max - 4)
88             while (x > pcol_min + wid - 1 - 4)
89                 pcol_min += (wid / 2);
90
91         if (x < panel_col_min + 4)
92             while (x < pcol_min + 4)
93                 pcol_min -= (wid / 2);
94
95         if (pcol_min > max_pcol_min)
96             pcol_min = max_pcol_min;
97
98         if (pcol_min < 0)
99             pcol_min = 0;
100     }
101
102     if ((prow_min == panel_row_min) && (pcol_min == panel_col_min))
103         return;
104
105     panel_row_min = prow_min;
106     panel_col_min = pcol_min;
107     if (disturb_panel && !center_player)
108         disturb(creature_ptr, FALSE, FALSE);
109
110     panel_bounds_center();
111     creature_ptr->update |= PU_MONSTERS;
112     creature_ptr->redraw |= PR_MAP;
113     creature_ptr->window_flags |= PW_OVERHEAD | PW_DUNGEON;
114 }
115
116 /*
117  * Update (if necessary) and verify (if possible) the target.
118  * We return TRUE if the target is "okay" and FALSE otherwise.
119  */
120 bool target_okay(player_type *creature_ptr)
121 {
122     if (target_who < 0)
123         return TRUE;
124
125     if (target_who <= 0)
126         return FALSE;
127
128     if (!target_able(creature_ptr, target_who))
129         return FALSE;
130
131     monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[target_who];
132     target_row = m_ptr->fy;
133     target_col = m_ptr->fx;
134     return TRUE;
135 }