OSDN Git Service

[Refactor] 連想配列 quest を quest_map に改名
[hengbandforosx/hengbandosx.git] / src / wizard / wizard-game-modifier.cpp
index c00579b..fb3dac7 100644 (file)
 #include "util/int-char-converter.h"
 #include "view/display-messages.h"
 #include "wizard/wizard-special-process.h"
+#include <array>
+#include <sstream>
 #include <string>
+#include <tuple>
 #include <vector>
-#include <sstream>
 
-void wiz_enter_quest(player_type *creature_ptr);
-void wiz_complete_quest(player_type *creature_ptr);
-void wiz_restore_monster_max_num();
+void wiz_enter_quest(PlayerType *player_ptr);
+void wiz_complete_quest(PlayerType *player_ptr);
+void wiz_restore_monster_max_num(MONRACE_IDX r_idx);
 
 /*!
  * @brief ゲーム設定コマンド一覧表
  */
-std::vector<std::vector<std::string>> wizard_game_modifier_menu_table = {
-    { "t", _("プレイ時間変更", "Modify played time") },
-    { "q", _("現在のクエストを完了", "Complete current quest") },
-    { "Q", _("クエストに突入", "Enter quest") },
-    { "u", _("ユニーク/ナズグルの生存数を復元", "Restore living info of unique/nazgul") },
-    { "g", _("モンスター闘技場出場者更新", "Update gambling monster") },
+constexpr std::array wizard_game_modifier_menu_table = {
+    std::make_tuple('t', _("プレイ時間変更", "Modify played time")),
+    std::make_tuple('q', _("現在のクエストを完了", "Complete current quest")),
+    std::make_tuple('Q', _("クエストに突入", "Enter quest")),
+    std::make_tuple('u', _("ユニーク/ナズグルの生存数を復元", "Restore living info of unique/nazgul")),
+    std::make_tuple('g', _("モンスター闘技場出場者更新", "Update gambling monster")),
 };
 
 /*!
  * @brief ゲーム設定コマンドの一覧を表示する
- * @return なし
  */
 void display_wizard_game_modifier_menu()
 {
-    for (int y = 1; y < 6; y++)
+    for (auto y = 1U; y <= wizard_game_modifier_menu_table.size(); y++) {
         term_erase(14, y, 64);
+    }
 
     int r = 1;
     int c = 15;
-    int sz = wizard_game_modifier_menu_table.size();
-    for (int i = 0; i < sz; i++) {
+    for (const auto &[symbol, desc] : wizard_game_modifier_menu_table) {
         std::stringstream ss;
-        ss << wizard_game_modifier_menu_table[i][0] << ") " << wizard_game_modifier_menu_table[i][1];
+        ss << symbol << ") " << desc;
         put_str(ss.str().c_str(), r++, c);
     }
 }
 
 /*!
  * @brief ゲーム設定コマンドの入力を受け付ける
- * @param creature_ptr プレイヤーの情報へのポインタ
- * @return なし
+ * @param player_ptr プレイヤーの情報へのポインタ
  */
-void wizard_game_modifier(player_type *creature_ptr)
+void wizard_game_modifier(PlayerType *player_ptr)
 {
     screen_save();
     display_wizard_game_modifier_menu();
 
     char cmd;
-    get_com("Player Command: ", &cmd, FALSE);
+    get_com("Player Command: ", &cmd, false);
     screen_load();
 
     switch (cmd) {
@@ -81,16 +81,16 @@ void wizard_game_modifier(player_type *creature_ptr)
     case '\r':
         break;
     case 'g':
-        update_gambling_monsters(creature_ptr);
+        update_gambling_monsters(player_ptr);
         break;
     case 'q':
-        wiz_complete_quest(creature_ptr);
+        wiz_complete_quest(player_ptr);
         break;
     case 'Q':
-        wiz_enter_quest(creature_ptr);
+        wiz_enter_quest(player_ptr);
         break;
     case 'u':
-        wiz_restore_monster_max_num();
+        wiz_restore_monster_max_num(command_arg);
         break;
     case 't':
         set_gametime();
@@ -101,9 +101,8 @@ void wizard_game_modifier(player_type *creature_ptr)
 /*!
  * @brief 指定したクエストに突入する
  * @param プレイヤーの情報へのポインタ
- * @return なし
  */
-void wiz_enter_quest(player_type* creature_ptr)
+void wiz_enter_quest(PlayerType *player_ptr)
 {
     char ppp[30];
     char tmp_val[5];
@@ -111,68 +110,70 @@ void wiz_enter_quest(player_type* creature_ptr)
     sprintf(ppp, "QuestID (0-%d):", max_q_idx - 1);
     sprintf(tmp_val, "%d", 0);
 
-    if (!get_string(ppp, tmp_val, 3))
+    if (!get_string(ppp, tmp_val, 3)) {
         return;
+    }
 
     tmp_int = atoi(tmp_val);
-    if ((tmp_int < 0) || (tmp_int >= max_q_idx))
+    if ((tmp_int < 0) || (tmp_int >= max_q_idx)) {
         return;
+    }
+
+    auto q_idx = i2enum<QuestId>(tmp_int);
 
-    creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)tmp_int;
-    parse_fixed_map(creature_ptr, "q_info.txt", 0, 0, 0, 0);
-    quest[tmp_int].status = QUEST_STATUS_TAKEN;
-    creature_ptr->current_floor_ptr->inside_quest = 0;
+    init_flags = i2enum<init_flags_type>(INIT_SHOW_TEXT | INIT_ASSIGN);
+    player_ptr->current_floor_ptr->quest_number = q_idx;
+    parse_fixed_map(player_ptr, "q_info.txt", 0, 0, 0, 0);
+    quest_map[q_idx].status = QuestStatusType::TAKEN;
+    if (quest_map[q_idx].dungeon == 0) {
+        exe_enter_quest(player_ptr, q_idx);
+    }
 }
 
 /*!
  * @brief 指定したクエストを完了させる
  * @param プレイヤーの情報へのポインタ
- * @return なし
  */
-void wiz_complete_quest(player_type *creature_ptr)
+void wiz_complete_quest(PlayerType *player_ptr)
 {
-    if (!creature_ptr->current_floor_ptr->inside_quest) {
+    if (!inside_quest(player_ptr->current_floor_ptr->quest_number)) {
         msg_print("No current quest");
-        msg_print(NULL);
+        msg_print(nullptr);
         return;
     }
 
-    if (quest[creature_ptr->current_floor_ptr->inside_quest].status == QUEST_STATUS_TAKEN)
-        complete_quest(creature_ptr, creature_ptr->current_floor_ptr->inside_quest);
+    if (quest_map[player_ptr->current_floor_ptr->quest_number].status == QuestStatusType::TAKEN) {
+        complete_quest(player_ptr, player_ptr->current_floor_ptr->quest_number);
+    }
 }
 
-void wiz_restore_monster_max_num()
+void wiz_restore_monster_max_num(MONRACE_IDX r_idx)
 {
-    MONRACE_IDX r_idx = command_arg;
     if (r_idx <= 0) {
-        std::stringstream ss;
-        ss << "Monster race (1-" << max_r_idx << "): ";
-
-        char tmp_val[160] = "\0";
-        if (!get_string(ss.str().c_str(), tmp_val, 5))
-            return;
-
-        r_idx = (MONRACE_IDX)atoi(tmp_val);
-        if (r_idx <= 0 || r_idx >= max_r_idx)
+        int val;
+        if (!get_value("MonsterID", 1, r_info.size() - 1, &val)) {
             return;
+        }
+        r_idx = static_cast<MONRACE_IDX>(val);
     }
 
-    monster_race *r_ptr = &r_info[r_idx];
+    auto *r_ptr = &r_info[r_idx];
     if (r_ptr->name.empty()) {
         msg_print("そのモンスターは存在しません。");
-        msg_print(NULL);
+        msg_print(nullptr);
         return;
     }
 
-    MONSTER_NUMBER n = 0;
-    if (any_bits(r_ptr->flags1, RF1_UNIQUE))
+    auto n = 0;
+    if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) {
         n = 1;
-    else if (any_bits(r_ptr->flags7, RF7_NAZGUL))
+    } else if (any_bits(r_ptr->flags7, RF7_NAZGUL)) {
         n = MAX_NAZGUL_NUM;
+    }
 
     if (n == 0) {
         msg_print("出現数に制限がないモンスターです。");
-        msg_print(NULL);
+        msg_print(nullptr);
         return;
     }
 
@@ -183,5 +184,5 @@ void wiz_restore_monster_max_num()
     std::stringstream ss;
     ss << r_ptr->name << _("の出現数を復元しました。", " can appear again now.");
     msg_print(ss.str().c_str());
-    msg_print(NULL);
+    msg_print(nullptr);
 }