#include <climits>
#include <algorithm>
+#include <iostream>
+#include <string>
+#include <sstream>
/*
* Get some string input at the cursor location.
(void)inkey();
prt("", row, 0);
}
+
+bool get_value(const char *text, int min, int max, int *value)
+{
+ std::stringstream st;
+ int val;
+ char tmp_val[10] = "";
+ st << text << "(" << min << "-" << max << "): ";
+ int digit = std::max(std::to_string(min).length(), std::to_string(max).length());
+ while (true) {
+ if (!get_string(st.str().c_str(), tmp_val, digit))
+ return false;
+
+ val = atoi(tmp_val);
+
+ if (min <= val && max >= val) {
+ break;
+ }
+ msg_format(_("%dから%dの間で指定して下さい。", "It must be between %d to %d."), min, max);
+ }
+ *value = val;
+ return true;
+}
void wiz_create_named_art(player_type *player_ptr, ARTIFACT_IDX a_idx)
{
if (a_idx <= 0) {
- char tmp[80] = "";
- sprintf(tmp, "Artifact ID (1-%d): ", max_a_idx - 1);
- char tmp_val[10] = "";
- if (!get_string(tmp, tmp_val, 3))
+ int val;
+ if (!get_value("ArtifactID", 1, a_info.size() - 1, &val)) {
return;
-
- a_idx = (ARTIFACT_IDX)atoi(tmp_val);
+ }
+ a_idx = static_cast<ARTIFACT_IDX>(val);
}
- if (a_idx <= 0 || a_idx >= max_a_idx) {
- msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), max_a_idx - 1);
- return;
- }
(void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
msg_print("Allocated.");
#include "spell/summon-types.h"
#include "system/floor-type-definition.h"
#include "system/player-type-definition.h"
+#include "system/monster-race-definition.h"
#include "target/grid-selector.h"
#include "target/target-checker.h"
#include "target/target-getter.h"
void wiz_summon_specific_enemy(player_type *player_ptr, MONRACE_IDX r_idx)
{
if (r_idx <= 0) {
- char tmp[80] = "";
- sprintf(tmp, "Monster ID (1-%d): ", max_r_idx - 1);
- char tmp_val[10] = "";
- if (!get_string(tmp, tmp_val, 4))
+ int val;
+ if(!get_value("MonsterID", 1, r_info.size() - 1, &val)) {
return;
-
- r_idx = (MONRACE_IDX)atoi(tmp_val);
- }
-
- if (r_idx <= 0 || r_idx >= max_r_idx) {
- msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), max_r_idx - 1);
- return;
+ }
+ r_idx = static_cast<MONRACE_IDX>(val);
}
(void)summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, r_idx, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
}
void wiz_summon_pet(player_type *player_ptr, MONRACE_IDX r_idx)
{
if (r_idx <= 0) {
- char tmp[80] = "";
- sprintf(tmp, "Monster ID (1-%d): ", max_r_idx - 1);
- char tmp_val[10] = "";
- if (!get_string(tmp, tmp_val, 4))
+ int val;
+ if (!get_value("MonsterID", 1, r_info.size() - 1, &val)) {
return;
-
- r_idx = (MONRACE_IDX)atoi(tmp_val);
- }
-
- if (r_idx <= 0 || r_idx >= max_r_idx) {
- msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), max_r_idx - 1);
- return;
+ }
+ r_idx = static_cast<MONRACE_IDX>(val);
}
-
(void)summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, r_idx, PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_FORCE_PET);
}