OSDN Git Service

[Refactor] #40572 Separated quest-monster-placer.c/h
authorHourier <hourier@users.sourceforge.jp>
Tue, 4 Aug 2020 11:36:37 +0000 (20:36 +0900)
committerHourier <hourier@users.sourceforge.jp>
Tue, 4 Aug 2020 11:36:37 +0000 (20:36 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/dungeon/quest-monster-placer.c [new file with mode: 0644]
src/dungeon/quest-monster-placer.h [new file with mode: 0644]
src/floor/cave-generator.c
src/floor/floor-generator.c
src/floor/floor-generator.h
src/floor/floor-save.c

index 3983bf4..ed08e2e 100644 (file)
     <ClCompile Include="..\..\src\core\status-reseter.c" />\r
     <ClCompile Include="..\..\src\core\visuals-reseter.c" />\r
     <ClCompile Include="..\..\src\core\window-redrawer.c" />\r
+    <ClCompile Include="..\..\src\dungeon\quest-monster-placer.c" />\r
     <ClCompile Include="..\..\src\flavor\flag-inscriptions-table.c" />\r
     <ClCompile Include="..\..\src\flavor\flavor-describer.c" />\r
     <ClCompile Include="..\..\src\flavor\flavor-util.c" />\r
     <ClInclude Include="..\..\src\core\visuals-reseter.h" />\r
     <ClInclude Include="..\..\src\core\window-redrawer.h" />\r
     <ClInclude Include="..\..\src\dungeon\dungeon-flag-types.h" />\r
+    <ClInclude Include="..\..\src\dungeon\quest-monster-placer.h" />\r
     <ClInclude Include="..\..\src\flavor\flag-inscriptions-table.h" />\r
     <ClInclude Include="..\..\src\flavor\flavor-describer.h" />\r
     <ClInclude Include="..\..\src\flavor\flavor-util.h" />\r
index dbefbdb..29d9e29 100644 (file)
     <ClCompile Include="..\..\src\floor\tunnel-generator.c">
       <Filter>floor</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\dungeon\quest-monster-placer.c">
+      <Filter>dungeon</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\combat\shoot.h">
     <ClInclude Include="..\..\src\floor\tunnel-generator.h">
       <Filter>floor</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\dungeon\quest-monster-placer.h">
+      <Filter>dungeon</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index e39cead..ac2d18f 100644 (file)
@@ -166,10 +166,11 @@ hengband_SOURCES = \
        core/visuals-reseter.c core/visuals-reseter.h \
        core/window-redrawer.c core/window-redrawer.h \
        \
-       dungeon/dungeon-flag-types.h \
        dungeon/dungeon.c dungeon/dungeon.h \
+       dungeon/dungeon-flag-types.h \
        dungeon/dungeon-processor.c dungeon/dungeon-processor.h \
        dungeon/quest.h dungeon/quest.c \
+       dungeon/quest-monster-placer.c dungeon/quest-monster-placer.h \
        \
        effect/effect-feature.c effect/effect-feature.h \
        effect/effect-item.c effect/effect-item.h \
diff --git a/src/dungeon/quest-monster-placer.c b/src/dungeon/quest-monster-placer.c
new file mode 100644 (file)
index 0000000..73d6e8c
--- /dev/null
@@ -0,0 +1,81 @@
+#include "dungeon/quest-monster-placer.h"
+#include "dungeon/quest.h"
+#include "floor/floor-generator-util.h"
+#include "grid/feature.h"
+#include "grid/grid.h"
+#include "monster-floor/monster-generator.h"
+#include "monster-floor/place-monster-types.h"
+#include "monster-race/monster-race.h"
+#include "monster-race/race-flags1.h"
+#include "monster/monster-info.h"
+#include "system/floor-type-definition.h"
+#include "util/bit-flags-calculator.h"
+
+/*!
+ * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
+ * @param creature_ptr プレーヤーへの参照ポインタ
+ * @return 成功したならばTRUEを返す
+ */
+bool place_quest_monsters(player_type *creature_ptr)
+{
+    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+    for (int i = 0; i < max_q_idx; i++) {
+        monster_race *r_ptr;
+        BIT_FLAGS mode;
+        if (quest[i].status != QUEST_STATUS_TAKEN || (quest[i].type != QUEST_TYPE_KILL_LEVEL && quest[i].type != QUEST_TYPE_RANDOM)
+            || quest[i].level != floor_ptr->dun_level || creature_ptr->dungeon_idx != quest[i].dungeon || (quest[i].flags & QUEST_FLAG_PRESET)) {
+            continue;
+        }
+
+        r_ptr = &r_info[quest[i].r_idx];
+        if ((r_ptr->flags1 & RF1_UNIQUE) && (r_ptr->cur_num >= r_ptr->max_num))
+            continue;
+
+        mode = PM_NO_KAGE | PM_NO_PET;
+        if (!(r_ptr->flags1 & RF1_FRIENDS))
+            mode |= PM_ALLOW_GROUP;
+
+        for (int j = 0; j < (quest[i].max_num - quest[i].cur_num); j++) {
+            int k;
+            for (k = 0; k < SAFE_MAX_ATTEMPTS; k++) {
+                POSITION x = 0;
+                POSITION y = 0;
+                int l;
+                for (l = SAFE_MAX_ATTEMPTS; l > 0; l--) {
+                    grid_type *g_ptr;
+                    feature_type *f_ptr;
+                    y = randint0(floor_ptr->height);
+                    x = randint0(floor_ptr->width);
+                    g_ptr = &floor_ptr->grid_array[y][x];
+                    f_ptr = &f_info[g_ptr->feat];
+                    if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY))
+                        continue;
+
+                    if (!monster_can_enter(creature_ptr, y, x, r_ptr, 0))
+                        continue;
+
+                    if (distance(y, x, creature_ptr->y, creature_ptr->x) < 10)
+                        continue;
+
+                    if (g_ptr->info & CAVE_ICKY)
+                        continue;
+                    else
+                        break;
+                }
+
+                if (l == 0)
+                    return FALSE;
+
+                if (place_monster_aux(creature_ptr, 0, y, x, quest[i].r_idx, mode))
+                    break;
+                else
+                    continue;
+            }
+
+            if (k == SAFE_MAX_ATTEMPTS)
+                return FALSE;
+        }
+    }
+
+    return TRUE;
+}
diff --git a/src/dungeon/quest-monster-placer.h b/src/dungeon/quest-monster-placer.h
new file mode 100644 (file)
index 0000000..a4781bf
--- /dev/null
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "system/angband.h"
+
+bool place_quest_monsters(player_type *creature_ptr);
index ef30d75..247ade7 100644 (file)
@@ -1,11 +1,11 @@
 #include "floor/cave-generator.h"
 #include "dungeon/dungeon-flag-types.h"
 #include "dungeon/dungeon.h"
+#include "dungeon/quest-monster-placer.h"
 #include "dungeon/quest.h"
 #include "floor/cave.h"
 #include "floor/dungeon-tunnel-util.h"
 #include "floor/floor-allocation-types.h"
-#include "floor/floor-generator.h" // todo place_quest_monsters() が相互依存している、このファイルからの依存性を消す.
 #include "floor/floor-streams.h"
 #include "floor/tunnel-generator.h"
 #include "floor/floor.h"
index 3aaf528..d03b78f 100644 (file)
 #include "world/world.h"
 
 /*!
- * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
- * @param creature_ptr プレーヤーへの参照ポインタ
- * @return 成功したならばTRUEを返す
- */
-bool place_quest_monsters(player_type *creature_ptr)
-{
-    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
-    for (int i = 0; i < max_q_idx; i++) {
-        monster_race *r_ptr;
-        BIT_FLAGS mode;
-        if (quest[i].status != QUEST_STATUS_TAKEN || (quest[i].type != QUEST_TYPE_KILL_LEVEL && quest[i].type != QUEST_TYPE_RANDOM)
-            || quest[i].level != floor_ptr->dun_level || creature_ptr->dungeon_idx != quest[i].dungeon || (quest[i].flags & QUEST_FLAG_PRESET)) {
-            continue;
-        }
-
-        r_ptr = &r_info[quest[i].r_idx];
-        if ((r_ptr->flags1 & RF1_UNIQUE) && (r_ptr->cur_num >= r_ptr->max_num))
-            continue;
-
-        mode = (PM_NO_KAGE | PM_NO_PET);
-        if (!(r_ptr->flags1 & RF1_FRIENDS))
-            mode |= PM_ALLOW_GROUP;
-
-        for (int j = 0; j < (quest[i].max_num - quest[i].cur_num); j++) {
-            int k;
-            for (k = 0; k < SAFE_MAX_ATTEMPTS; k++) {
-                POSITION x = 0;
-                POSITION y = 0;
-                int l;
-                for (l = SAFE_MAX_ATTEMPTS; l > 0; l--) {
-                    grid_type *g_ptr;
-                    feature_type *f_ptr;
-                    y = randint0(floor_ptr->height);
-                    x = randint0(floor_ptr->width);
-                    g_ptr = &floor_ptr->grid_array[y][x];
-                    f_ptr = &f_info[g_ptr->feat];
-                    if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY))
-                        continue;
-
-                    if (!monster_can_enter(creature_ptr, y, x, r_ptr, 0))
-                        continue;
-
-                    if (distance(y, x, creature_ptr->y, creature_ptr->x) < 10)
-                        continue;
-
-                    if (g_ptr->info & CAVE_ICKY)
-                        continue;
-                    else
-                        break;
-                }
-
-                if (l == 0)
-                    return FALSE;
-
-                if (place_monster_aux(creature_ptr, 0, y, x, quest[i].r_idx, mode))
-                    break;
-                else
-                    continue;
-            }
-
-            if (k == SAFE_MAX_ATTEMPTS)
-                return FALSE;
-        }
-    }
-
-    return TRUE;
-}
-
-/*!
  * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
  * @param player_ptr プレーヤーへの参照ポインタ
  * @return なし
index 3b57ae0..efe1b37 100644 (file)
@@ -2,7 +2,6 @@
 
 #include "system/angband.h"
 
-bool place_quest_monsters(player_type *creature_ptr);
 void wipe_generate_random_floor_flags(floor_type *floor_ptr);
 void clear_cave(player_type *player_ptr);
 void generate_floor(player_type *player_ptr);
index f6ea5f2..a22f5a1 100644 (file)
@@ -14,6 +14,7 @@
 #include "cmd-building/cmd-building.h"
 #include "cmd-io/cmd-dump.h"
 #include "core/asking-player.h"
+#include "dungeon/quest-monster-placer.h"
 #include "dungeon/dungeon.h"
 #include "dungeon/quest.h"
 #include "floor/cave.h"