OSDN Git Service

[Implement] get_value()が参照代入値ポインタの入力前値をデフォルト値にするよう仕様追加。
authorDeskull <61610939+sikabane-works@users.noreply.github.com>
Wed, 13 Oct 2021 12:43:59 +0000 (21:43 +0900)
committerDeskull <61610939+sikabane-works@users.noreply.github.com>
Sat, 16 Oct 2021 01:07:51 +0000 (10:07 +0900)
 * モンスターのデフォルト生成IDを1に。

src/core/asking-player.cpp
src/wizard/wizard-spells.cpp

index 4c489ce..af30ce2 100644 (file)
@@ -19,6 +19,7 @@
 #include <iostream>
 #include <string>
 #include <sstream>
+#include <charconv>
 
 /*
  * Get some string input at the cursor location.
@@ -422,7 +423,8 @@ bool get_value(const char *text, int min, int max, int *value)
 {
     std::stringstream st;
     int val;
-    char tmp_val[10] = "";
+    char tmp_val[12] = "";
+    std::to_chars(std::begin(tmp_val), std::end(tmp_val) - 1, *value);
     st << text << "(" << min << "-" << max << "): ";
     int digit = std::max(std::to_string(min).length(), std::to_string(max).length());
     while (true) {
index d68fc44..e92cb49 100644 (file)
@@ -192,7 +192,7 @@ void wiz_summon_random_enemy(player_type *player_ptr, int num)
 void wiz_summon_specific_enemy(player_type *player_ptr, MONRACE_IDX r_idx)
 {
     if (r_idx <= 0) {
-        int val;
+        int val = 1;
         if(!get_value("MonsterID", 1, r_info.size() - 1, &val)) {
             return;
         }
@@ -211,7 +211,7 @@ void wiz_summon_specific_enemy(player_type *player_ptr, MONRACE_IDX r_idx)
 void wiz_summon_pet(player_type *player_ptr, MONRACE_IDX r_idx)
 {
     if (r_idx <= 0) {
-        int val;
+        int val = 1;
         if (!get_value("MonsterID", 1, r_info.size() - 1, &val)) {
             return;
         }