From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 11 Jun 2023 07:25:22 +0000 (+0900) Subject: [Implement] #3409 フロア相応のモンスターをランダムに生成するデバッグコマンドを追加した X-Git-Tag: 3.0.0.85(Alpha)^2~1^2~1 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=bad734330af01161387f7d6153e8e1fa7fd26e4b;p=hengbandforosx%2Fhengbandosx.git [Implement] #3409 フロア相応のモンスターをランダムに生成するデバッグコマンドを追加した --- diff --git a/src/monster-floor/monster-generator.cpp b/src/monster-floor/monster-generator.cpp index 9a120ce64..d6c0ab7d9 100644 --- a/src/monster-floor/monster-generator.cpp +++ b/src/monster-floor/monster-generator.cpp @@ -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; } } diff --git a/src/monster-floor/monster-generator.h b/src/monster-floor/monster-generator.h index a10d6d938..330fd97b7 100644 --- a/src/monster-floor/monster-generator.h +++ b/src/monster-floor/monster-generator.h @@ -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); diff --git a/src/wizard/cmd-wizard.cpp b/src/wizard/cmd-wizard.cpp index 8e787526c..a5a345b6b 100644 --- a/src/wizard/cmd-wizard.cpp +++ b/src/wizard/cmd-wizard.cpp @@ -35,6 +35,7 @@ #include "wizard/wizard-special-process.h" #include "wizard/wizard-spells.h" #include "wizard/wizard-spoiler.h" +#include #include #include #include @@ -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(command_arg, 1, 999); + wiz_generate_random_monster(player_ptr, command_arg); + return true; + case 'S': + command_arg = std::clamp(command_arg, 1, 999); wiz_summon_random_monster(player_ptr, command_arg); return true; case 't': diff --git a/src/wizard/wizard-spells.cpp b/src/wizard/wizard-spells.cpp index 055d54727..e84c983cd 100644 --- a/src/wizard/wizard-spells.cpp +++ b/src/wizard/wizard-spells.cpp @@ -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 #include @@ -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; + } } } diff --git a/src/wizard/wizard-spells.h b/src/wizard/wizard-spells.h index 3da487c0b..a3e48bce2 100644 --- a/src/wizard/wizard-spells.h +++ b/src/wizard/wizard-spells.h @@ -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);