OSDN Git Service

[Implement] #3409 フロア相応のモンスターをランダムに生成するデバッグコマンドを追加した
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 11 Jun 2023 07:25:22 +0000 (16:25 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 11 Jun 2023 12:52:11 +0000 (21:52 +0900)
src/monster-floor/monster-generator.cpp
src/monster-floor/monster-generator.h
src/wizard/cmd-wizard.cpp
src/wizard/wizard-spells.cpp
src/wizard/wizard-spells.h

index 9a120ce..d6c0ab7 100644 (file)
@@ -509,23 +509,22 @@ bool alloc_guardian(PlayerType *player_ptr, bool def_val)
 
 /*!
  * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
- * @param dis プレイヤーから離れるべき最距離
+ * @param dis プレイヤーから離れるべき最距離
  * @param mode 生成オプション
+ * @param summon_specific 特定モンスター種別を生成するための関数ポインタ
+ * @param max_dis プレイヤーから離れるべき最大距離 (デバッグ用)
  * @return 生成に成功したらtrue
- * @details
- * Place the monster at least "dis" distance from the player.
- * Use "slp" to choose the initial "sleep" status
- * Use "floor_ptr->monster_level" for the monster level
  */
-bool alloc_monster(PlayerType *player_ptr, POSITION dis, BIT_FLAGS mode, summon_specific_pf summon_specific)
+bool alloc_monster(PlayerType *player_ptr, int min_dis, BIT_FLAGS mode, summon_specific_pf summon_specific, int max_dis)
 {
     if (alloc_guardian(player_ptr, false)) {
         return true;
     }
 
     auto *floor_ptr = player_ptr->current_floor_ptr;
-    POSITION y = 0, x = 0;
-    int attempts_left = 10000;
+    auto y = 0;
+    auto x = 0;
+    auto attempts_left = 10000;
     while (attempts_left--) {
         y = randint0(floor_ptr->height);
         x = randint0(floor_ptr->width);
@@ -540,7 +539,8 @@ bool alloc_monster(PlayerType *player_ptr, POSITION dis, BIT_FLAGS mode, summon_
             }
         }
 
-        if (distance(y, x, player_ptr->y, player_ptr->x) > dis) {
+        const auto dist = distance(y, x, player_ptr->y, player_ptr->x);
+        if ((min_dis < dist) && (dist <= max_dis)) {
             break;
         }
     }
index a10d6d9..330fd97 100644 (file)
@@ -13,4 +13,4 @@ bool place_specific_monster(PlayerType *player_ptr, MONSTER_IDX who, POSITION y,
 bool place_random_monster(PlayerType *player_ptr, POSITION y, POSITION x, BIT_FLAGS mode);
 bool alloc_horde(PlayerType *player_ptr, POSITION y, POSITION x, summon_specific_pf summon_specific);
 bool alloc_guardian(PlayerType *player_ptr, bool def_val);
-bool alloc_monster(PlayerType *player_ptr, POSITION dis, BIT_FLAGS mode, summon_specific_pf summon_specific);
+bool alloc_monster(PlayerType *player_ptr, int min_dis, BIT_FLAGS mode, summon_specific_pf summon_specific, int max_dis = 65535);
index 8e78752..a5a345b 100644 (file)
@@ -35,6 +35,7 @@
 #include "wizard/wizard-special-process.h"
 #include "wizard/wizard-spells.h"
 #include "wizard/wizard-spoiler.h"
+#include <algorithm>
 #include <sstream>
 #include <string>
 #include <tuple>
@@ -70,7 +71,8 @@ constexpr std::array debug_menu_table = {
     std::make_tuple('p', _("ショート・テレポート", "Phase door")),
     std::make_tuple('P', _("プレイヤー設定変更メニュー", "Modify player configurations")),
     std::make_tuple('r', _("カオスパトロンの報酬", "Get reward of chaos patron")),
-    std::make_tuple('s', _("フロア相当のモンスター召喚", "Summon monster which be in target depth")),
+    std::make_tuple('s', _("フロア相当のモンスター生成", "Generate monster which be in target depth")),
+    std::make_tuple('S', _("フロア相当のモンスター召喚", "Summon monster which be in target depth")),
     std::make_tuple('t', _("テレポート", "Teleport self")),
     std::make_tuple('u', _("啓蒙(忍者以外)", "Wiz-lite all floor except Ninja")),
     std::make_tuple('w', _("啓蒙(忍者配慮)", "Wiz-lite all floor")),
@@ -217,10 +219,11 @@ bool exe_cmd_debug(PlayerType *player_ptr, char cmd)
         patron_list[player_ptr->chaos_patron].gain_level_reward(player_ptr, command_arg);
         return true;
     case 's':
-        if (command_arg <= 0) {
-            command_arg = 1;
-        }
-
+        command_arg = std::clamp<short>(command_arg, 1, 999);
+        wiz_generate_random_monster(player_ptr, command_arg);
+        return true;
+    case 'S':
+        command_arg = std::clamp<short>(command_arg, 1, 999);
         wiz_summon_random_monster(player_ptr, command_arg);
         return true;
     case 't':
index 055d547..e84c983 100644 (file)
@@ -41,6 +41,7 @@
 #include "util/enum-converter.h"
 #include "util/flag-group.h"
 #include "view/display-messages.h"
+#include "wizard/wizard-messages.h"
 #include <string_view>
 #include <vector>
 
@@ -181,15 +182,39 @@ void wiz_fillup_all_smith_essences(PlayerType *player_ptr)
 }
 
 /*!
- * @brief 現在のフロアに合ったモンスターをランダムに召喚する /
- * Summon some creatures
+ * @brief 現在のフロアに合ったモンスターをランダムに生成する
  * @param player_ptr プレイヤーへの参照ポインタ
  * @param num 生成処理回数
+ * @details 半径5マス以内に生成する。生成場所がなかったらキャンセル。
+ */
+void wiz_generate_random_monster(PlayerType *player_ptr, int num)
+{
+    constexpr auto flags = PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_QUEST;
+    for (auto i = 0; i < num; i++) {
+        if (!alloc_monster(player_ptr, 0, flags, summon_specific, 5)) {
+            msg_print_wizard(player_ptr, 1, "Monster isn't generated correctly...");
+            return;
+        }
+    }
+}
+
+/*!
+ * @brief 現在のフロアに合ったモンスターをランダムに召喚する
+ * @param player_ptr プレイヤーへの参照ポインタ
+ * @param num 生成処理回数
+ * @details 現在のレベル+5F からランダムに選定する。生成場所がなかったらキャンセル。
  */
 void wiz_summon_random_monster(PlayerType *player_ptr, int num)
 {
-    for (int i = 0; i < num; i++) {
-        (void)summon_specific(player_ptr, 0, player_ptr->y, player_ptr->x, player_ptr->current_floor_ptr->dun_level, SUMMON_NONE, PM_ALLOW_GROUP | PM_ALLOW_UNIQUE);
+    const auto level = player_ptr->current_floor_ptr->dun_level;
+    constexpr auto flags = PM_ALLOW_GROUP | PM_ALLOW_UNIQUE;
+    const auto y = player_ptr->y;
+    const auto x = player_ptr->x;
+    for (auto i = 0; i < num; i++) {
+        if (!summon_specific(player_ptr, 0, y, x, level, SUMMON_NONE, flags)) {
+            msg_print_wizard(player_ptr, 1, "Monster isn't summoned correctly...");
+            return;
+        }
     }
 }
 
index 3da487c..a3e48bc 100644 (file)
@@ -42,6 +42,7 @@ void wiz_summon_horde(PlayerType *player_ptr);
 void wiz_teleport_back(PlayerType *player_ptr);
 void wiz_learn_blue_magic_all(PlayerType *player_ptr);
 void wiz_fillup_all_smith_essences(PlayerType *player_ptr);
+void wiz_generate_random_monster(PlayerType *player_ptr, int num);
 void wiz_summon_random_monster(PlayerType *player_ptr, int num);
 void wiz_summon_specific_monster(PlayerType *player_ptr, MonsterRaceId r_idx);
 void wiz_summon_pet(PlayerType *player_ptr, MonsterRaceId r_idx);