OSDN Git Service

[Refactor] #40571 Separated grid-selector.c/h from targeting.c/h
authorHourier <hourier@users.sourceforge.jp>
Sat, 25 Jul 2020 03:23:08 +0000 (12:23 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 25 Jul 2020 03:23:08 +0000 (12:23 +0900)
14 files changed:
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/cmd-action/cmd-travel.c
src/mind/mind-mirror-master.c
src/realm/realm-hex.c
src/realm/realm-hissatsu.c
src/spell-kind/spells-teleport.c
src/target/grid-selector.c [new file with mode: 0644]
src/target/grid-selector.h [new file with mode: 0644]
src/target/targeting.c
src/target/targeting.h
src/wizard/wizard-special-process.c
src/wizard/wizard-spells.c

index 37c9bbf..a478e1e 100644 (file)
     <ClCompile Include="..\..\src\store\sell-order.c" />\r
     <ClCompile Include="..\..\src\store\service-checker.c" />\r
     <ClCompile Include="..\..\src\system\dungeon-data-definition.c" />\r
+    <ClCompile Include="..\..\src\target\grid-selector.c" />\r
     <ClCompile Include="..\..\src\target\target-describer.c" />\r
     <ClCompile Include="..\..\src\target\target-preparation.c" />\r
     <ClCompile Include="..\..\src\view\display-inventory.c" />\r
     <ClInclude Include="..\..\src\system\alloc-entries.h" />\r
     <ClInclude Include="..\..\src\system\dungeon-data-definition.h" />\r
     <ClInclude Include="..\..\src\system\floor-type-definition.h" />\r
+    <ClInclude Include="..\..\src\target\grid-selector.h" />\r
     <ClInclude Include="..\..\src\target\target-describer.h" />\r
     <ClInclude Include="..\..\src\target\target-preparation.h" />\r
     <ClInclude Include="..\..\src\target\target-types.h" />\r
index 92da5cb..2f59350 100644 (file)
     <ClCompile Include="..\..\src\target\target-preparation.c">
       <Filter>target</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\target\grid-selector.c">
+      <Filter>target</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\combat\shoot.h">
     <ClInclude Include="..\..\src\target\target-preparation.h">
       <Filter>target</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\target\grid-selector.h">
+      <Filter>target</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 2a7bcf4..b1357e7 100644 (file)
@@ -730,6 +730,7 @@ hengband_SOURCES = \
        system/system-variables.c system/system-variables.h \
        system/gamevalue.h \
        \
+       target/grid-selector.c target/grid-selector.h \
        target/target-describer.c target/target-describer.h \
        target/target-preparation.c target/target-preparation.h \
        target/target-types.h \
index 3eb7ba6..b55e146 100644 (file)
@@ -6,7 +6,7 @@
 #include "grid/grid.h"
 #include "player/player-move.h"
 #include "system/floor-type-definition.h"
-#include "target/targeting.h"
+#include "target/grid-selector.h"
 #include "view/display-messages.h"
 #include "util/bit-flags-calculator.h"
 
index 24e09f5..9a8be5d 100644 (file)
@@ -21,8 +21,8 @@
 #include "spell/process-effect.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
+#include "target/grid-selector.h"
 #include "target/target-preparation.h"
-#include "target/targeting.h"
 #include "term/gameterm.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
index bcffcf7..838add8 100644 (file)
@@ -55,6 +55,7 @@
 #include "spell/technic-info-table.h"
 #include "status/action-setter.h"
 #include "system/floor-type-definition.h"
+#include "target/grid-selector.h"
 #include "target/targeting.h"
 #include "term/screen-processor.h"
 #include "util/bit-flags-calculator.h"
index b793d13..73b685f 100644 (file)
@@ -42,6 +42,7 @@
 #include "spell/technic-info-table.h"
 #include "status/bad-status-setter.h"
 #include "system/floor-type-definition.h"
+#include "target/grid-selector.h"
 #include "target/targeting.h"
 #include "term/screen-processor.h"
 #include "util/bit-flags-calculator.h"
index 1735b33..53380fa 100644 (file)
@@ -32,6 +32,7 @@
 #include "spell-kind/spells-launcher.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
+#include "target/grid-selector.h"
 #include "target/targeting.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
diff --git a/src/target/grid-selector.c b/src/target/grid-selector.c
new file mode 100644 (file)
index 0000000..10a0171
--- /dev/null
@@ -0,0 +1,199 @@
+#include "target/grid-selector.h"
+#include "core/player-redraw-types.h"
+#include "core/player-update-types.h"
+#include "core/window-redrawer.h"
+#include "core/stuff-handler.h"
+#include "floor/cave.h"
+#include "game-option/game-play-options.h"
+#include "game-option/keymap-directory-getter.h"
+#include "grid/feature-flag-types.h"
+#include "grid/grid.h"
+#include "io/cursor.h"
+#include "io/input-key-acceptor.h"
+#include "io/screen-util.h"
+#include "system/floor-type-definition.h"
+#include "target/targeting.h"
+#include "term/screen-processor.h"
+#include "util/int-char-converter.h"
+#include "util/sort.h"
+#include "view/display-messages.h"
+#include "window/main-window-util.h"
+
+/*
+ * XAngband: determine if a given location is "interesting"
+ * based on target_set_accept function.
+ */
+static bool tgt_pt_accept(player_type *creature_ptr, POSITION y, POSITION x)
+{
+    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+    if (!(in_bounds(floor_ptr, y, x)))
+        return FALSE;
+
+    if ((y == creature_ptr->y) && (x == creature_ptr->x))
+        return TRUE;
+
+    if (creature_ptr->image)
+        return FALSE;
+
+    grid_type *g_ptr;
+    g_ptr = &floor_ptr->grid_array[y][x];
+    if (!(g_ptr->info & (CAVE_MARK)))
+        return FALSE;
+
+    if (cave_have_flag_grid(g_ptr, FF_LESS) || cave_have_flag_grid(g_ptr, FF_MORE) || cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)
+        || cave_have_flag_grid(g_ptr, FF_QUEST_EXIT))
+        return TRUE;
+
+    return FALSE;
+}
+
+/*
+ * XAngband: Prepare the "temp" array for "tget_pt"
+ * based on target_set_prepare funciton.
+ */
+static void tgt_pt_prepare(player_type *creature_ptr)
+{
+    tmp_pos.n = 0;
+    if (!expand_list)
+        return;
+
+    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+    for (POSITION y = 1; y < floor_ptr->height; y++) {
+        for (POSITION x = 1; x < floor_ptr->width; x++) {
+            if (!tgt_pt_accept(creature_ptr, y, x))
+                continue;
+
+            tmp_pos.x[tmp_pos.n] = x;
+            tmp_pos.y[tmp_pos.n] = y;
+            tmp_pos.n++;
+        }
+    }
+
+    ang_sort(creature_ptr, tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
+}
+
+/*
+ * old -- from PsiAngband.
+ */
+bool tgt_pt(player_type *creature_ptr, POSITION *x_ptr, POSITION *y_ptr)
+{
+    TERM_LEN wid, hgt;
+    get_screen_size(&wid, &hgt);
+
+    POSITION x = creature_ptr->x;
+    POSITION y = creature_ptr->y;
+    if (expand_list)
+        tgt_pt_prepare(creature_ptr);
+
+    msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
+    msg_flag = FALSE;
+
+    char ch = 0;
+    int n = 0;
+    bool success = FALSE;
+    while ((ch != ESCAPE) && !success) {
+        bool move_fast = FALSE;
+        move_cursor_relative(y, x);
+        ch = inkey();
+        switch (ch) {
+        case ESCAPE:
+            break;
+        case ' ':
+        case 't':
+        case '.':
+        case '5':
+        case '0':
+            if (player_bold(creature_ptr, y, x))
+                ch = 0;
+            else
+                success = TRUE;
+
+            break;
+        case '>':
+        case '<': {
+            if (!expand_list || !tmp_pos.n)
+                break;
+
+            int dx, dy;
+            int cx = (panel_col_min + panel_col_max) / 2;
+            int cy = (panel_row_min + panel_row_max) / 2;
+            n++;
+            for (; n < tmp_pos.n; ++n) {
+                grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
+                if (cave_have_flag_grid(g_ptr, FF_STAIRS) && cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
+                    break;
+            }
+
+            if (n == tmp_pos.n) {
+                n = 0;
+                y = creature_ptr->y;
+                x = creature_ptr->x;
+                verify_panel(creature_ptr);
+                creature_ptr->update |= PU_MONSTERS;
+                creature_ptr->redraw |= PR_MAP;
+                creature_ptr->window |= PW_OVERHEAD;
+                handle_stuff(creature_ptr);
+            } else {
+                y = tmp_pos.y[n];
+                x = tmp_pos.x[n];
+                dy = 2 * (y - cy) / hgt;
+                dx = 2 * (x - cx) / wid;
+                if (dy || dx)
+                    change_panel(creature_ptr, dy, dx);
+            }
+
+            break;
+        }
+        default: {
+            int d = get_keymap_dir(ch);
+            if (isupper(ch))
+                move_fast = TRUE;
+
+            if (d == 0)
+                break;
+
+            int dx = ddx[d];
+            int dy = ddy[d];
+            if (move_fast) {
+                int mag = MIN(wid / 2, hgt / 2);
+                x += dx * mag;
+                y += dy * mag;
+            } else {
+                x += dx;
+                y += dy;
+            }
+
+            if (((x < panel_col_min + wid / 2) && (dx > 0)) || ((x > panel_col_min + wid / 2) && (dx < 0)))
+                dx = 0;
+
+            if (((y < panel_row_min + hgt / 2) && (dy > 0)) || ((y > panel_row_min + hgt / 2) && (dy < 0)))
+                dy = 0;
+
+            if ((y >= panel_row_min + hgt) || (y < panel_row_min) || (x >= panel_col_min + wid) || (x < panel_col_min))
+                change_panel(creature_ptr, dy, dx);
+
+            if (x >= creature_ptr->current_floor_ptr->width - 1)
+                x = creature_ptr->current_floor_ptr->width - 2;
+            else if (x <= 0)
+                x = 1;
+
+            if (y >= creature_ptr->current_floor_ptr->height - 1)
+                y = creature_ptr->current_floor_ptr->height - 2;
+            else if (y <= 0)
+                y = 1;
+
+            break;
+        }
+        }
+    }
+
+    prt("", 0, 0);
+    verify_panel(creature_ptr);
+    creature_ptr->update |= PU_MONSTERS;
+    creature_ptr->redraw |= PR_MAP;
+    creature_ptr->window |= PW_OVERHEAD;
+    handle_stuff(creature_ptr);
+    *x_ptr = x;
+    *y_ptr = y;
+    return success;
+}
diff --git a/src/target/grid-selector.h b/src/target/grid-selector.h
new file mode 100644 (file)
index 0000000..3df9eae
--- /dev/null
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "system/angband.h"
+
+bool tgt_pt(player_type *creature_ptr, POSITION *x, POSITION *y);
index 04f5aa8..a6956ed 100644 (file)
@@ -797,182 +797,3 @@ bool get_rep_dir(player_type *creature_ptr, DIRECTION *dp, bool under)
     repeat_push((COMMAND_CODE)command_dir);
     return TRUE;
 }
-
-/*
- * XAngband: determine if a given location is "interesting"
- * based on target_set_accept function.
- */
-static bool tgt_pt_accept(player_type *creature_ptr, POSITION y, POSITION x)
-{
-    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
-    if (!(in_bounds(floor_ptr, y, x)))
-        return FALSE;
-
-    if ((y == creature_ptr->y) && (x == creature_ptr->x))
-        return TRUE;
-
-    if (creature_ptr->image)
-        return FALSE;
-
-    grid_type *g_ptr;
-    g_ptr = &floor_ptr->grid_array[y][x];
-    if (!(g_ptr->info & (CAVE_MARK)))
-        return FALSE;
-
-    if (cave_have_flag_grid(g_ptr, FF_LESS) || cave_have_flag_grid(g_ptr, FF_MORE) || cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)
-        || cave_have_flag_grid(g_ptr, FF_QUEST_EXIT))
-        return TRUE;
-
-    return FALSE;
-}
-
-/*
- * XAngband: Prepare the "temp" array for "tget_pt"
- * based on target_set_prepare funciton.
- */
-static void tgt_pt_prepare(player_type *creature_ptr)
-{
-    tmp_pos.n = 0;
-    if (!expand_list)
-        return;
-
-    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
-    for (POSITION y = 1; y < floor_ptr->height; y++) {
-        for (POSITION x = 1; x < floor_ptr->width; x++) {
-            if (!tgt_pt_accept(creature_ptr, y, x))
-                continue;
-
-            tmp_pos.x[tmp_pos.n] = x;
-            tmp_pos.y[tmp_pos.n] = y;
-            tmp_pos.n++;
-        }
-    }
-
-    ang_sort(creature_ptr, tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
-}
-
-/*
- * old -- from PsiAngband.
- */
-bool tgt_pt(player_type *creature_ptr, POSITION *x_ptr, POSITION *y_ptr)
-{
-    TERM_LEN wid, hgt;
-    get_screen_size(&wid, &hgt);
-
-    POSITION x = creature_ptr->x;
-    POSITION y = creature_ptr->y;
-    if (expand_list)
-        tgt_pt_prepare(creature_ptr);
-
-    msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
-    msg_flag = FALSE;
-
-    char ch = 0;
-    int n = 0;
-    bool success = FALSE;
-    while ((ch != ESCAPE) && !success) {
-        bool move_fast = FALSE;
-        move_cursor_relative(y, x);
-        ch = inkey();
-        switch (ch) {
-        case ESCAPE:
-            break;
-        case ' ':
-        case 't':
-        case '.':
-        case '5':
-        case '0':
-            if (player_bold(creature_ptr, y, x))
-                ch = 0;
-            else
-                success = TRUE;
-
-            break;
-        case '>':
-        case '<': {
-            if (!expand_list || !tmp_pos.n)
-                break;
-
-            int dx, dy;
-            int cx = (panel_col_min + panel_col_max) / 2;
-            int cy = (panel_row_min + panel_row_max) / 2;
-            n++;
-            for (; n < tmp_pos.n; ++n) {
-                grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
-                if (cave_have_flag_grid(g_ptr, FF_STAIRS) && cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
-                    break;
-            }
-
-            if (n == tmp_pos.n) {
-                n = 0;
-                y = creature_ptr->y;
-                x = creature_ptr->x;
-                verify_panel(creature_ptr);
-                creature_ptr->update |= PU_MONSTERS;
-                creature_ptr->redraw |= PR_MAP;
-                creature_ptr->window |= PW_OVERHEAD;
-                handle_stuff(creature_ptr);
-            } else {
-                y = tmp_pos.y[n];
-                x = tmp_pos.x[n];
-                dy = 2 * (y - cy) / hgt;
-                dx = 2 * (x - cx) / wid;
-                if (dy || dx)
-                    change_panel(creature_ptr, dy, dx);
-            }
-
-            break;
-        }
-        default: {
-            int d = get_keymap_dir(ch);
-            if (isupper(ch))
-                move_fast = TRUE;
-
-            if (d == 0)
-                break;
-
-            int dx = ddx[d];
-            int dy = ddy[d];
-            if (move_fast) {
-                int mag = MIN(wid / 2, hgt / 2);
-                x += dx * mag;
-                y += dy * mag;
-            } else {
-                x += dx;
-                y += dy;
-            }
-
-            if (((x < panel_col_min + wid / 2) && (dx > 0)) || ((x > panel_col_min + wid / 2) && (dx < 0)))
-                dx = 0;
-
-            if (((y < panel_row_min + hgt / 2) && (dy > 0)) || ((y > panel_row_min + hgt / 2) && (dy < 0)))
-                dy = 0;
-
-            if ((y >= panel_row_min + hgt) || (y < panel_row_min) || (x >= panel_col_min + wid) || (x < panel_col_min))
-                change_panel(creature_ptr, dy, dx);
-
-            if (x >= creature_ptr->current_floor_ptr->width - 1)
-                x = creature_ptr->current_floor_ptr->width - 2;
-            else if (x <= 0)
-                x = 1;
-
-            if (y >= creature_ptr->current_floor_ptr->height - 1)
-                y = creature_ptr->current_floor_ptr->height - 2;
-            else if (y <= 0)
-                y = 1;
-
-            break;
-        }
-        }
-    }
-
-    prt("", 0, 0);
-    verify_panel(creature_ptr);
-    creature_ptr->update |= (PU_MONSTERS);
-    creature_ptr->redraw |= (PR_MAP);
-    creature_ptr->window |= (PW_OVERHEAD);
-    handle_stuff(creature_ptr);
-    *x_ptr = x;
-    *y_ptr = y;
-    return success;
-}
index 859b1d4..b022d9f 100644 (file)
@@ -14,4 +14,3 @@ bool target_okay(player_type *creature_ptr);
 bool get_aim_dir(player_type *creature_ptr, DIRECTION *dp);
 bool get_direction(player_type *creature_ptr, DIRECTION *dp, bool allow_under, bool with_steed);
 bool get_rep_dir(player_type *creature_ptr, DIRECTION *dp, bool under);
-bool tgt_pt(player_type *creature_ptr, POSITION *x, POSITION *y);
index b1a312c..dae708c 100644 (file)
@@ -80,7 +80,7 @@
 #include "system/angband-version.h"
 #include "system/artifact-type-definition.h"
 #include "system/floor-type-definition.h"
-#include "target/targeting.h"
+#include "target/grid-selector.h"
 #include "term/screen-processor.h"
 #include "term/term-color-types.h"
 #include "util/angband-files.h"
index 61e0552..9a0faa9 100644 (file)
@@ -17,6 +17,7 @@
 #include "spell-realm/spells-chaos.h"
 #include "spell/spells-status.h"
 #include "system/floor-type-definition.h"
+#include "target/grid-selector.h"
 #include "target/targeting.h"
 #include "view/display-messages.h"