Skip to content

Commit

Permalink
Merge pull request #4557 from sikabane-works/merge/heng#3457
Browse files Browse the repository at this point in the history
変愚「静的警告の解消 その7」のマージ
  • Loading branch information
sikabane-works authored May 11, 2024
2 parents e250634 + 1c78231 commit 07c2d9d
Show file tree
Hide file tree
Showing 24 changed files with 297 additions and 429 deletions.
8 changes: 4 additions & 4 deletions src/autopick/autopick-describer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ static void describe_autpick_jp(char *buff, const autopick_type &entry, autopick
angband_strcat(tmp, describer->insc, MAX_INSCRIPTION);
angband_strcat(buff, format("に「%s」", tmp), MAX_INSCRIPTION + 6);

if (angband_strstr(describer->insc, "%%all")) {
if (str_find(describer->insc, "%%all")) {
strcat(buff, "(%%allは全能力を表す英字の記号で置換)");
} else if (angband_strstr(describer->insc, "%all")) {
} else if (str_find(describer->insc, "%all")) {
strcat(buff, "(%allは全能力を表す記号で置換)");
} else if (angband_strstr(describer->insc, "%%")) {
} else if (str_find(describer->insc, "%%")) {
strcat(buff, "(%%は追加能力を表す英字の記号で置換)");
} else if (angband_strstr(describer->insc, "%")) {
} else if (str_find(describer->insc, "%")) {
strcat(buff, "(%は追加能力を表す記号で置換)");
}

Expand Down
2 changes: 1 addition & 1 deletion src/autopick/autopick-matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ bool is_autopick_match(PlayerType *player_ptr, ItemEntity *o_ptr, const autopick
return false;
}
} else {
if (angband_strstr(item_name.data(), entry.name) == nullptr) {
if (!str_find(std::string(item_name), entry.name)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd-io/cmd-gameoption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ void do_cmd_options(PlayerType *player_ptr)
clear_from(18);
prt(format(_("現在ウェイト量(msec): %d", "Current Delay Factor(msec): %d"), delay_factor), 19, 0);
constexpr auto prompt = _("コマンド: ウェイト量(msec)", "Command: Delay Factor(msec)");
const auto new_delay_factor = input_value_int(prompt, 0, 1000, delay_factor);
const auto new_delay_factor = input_integer(prompt, 0, 1000, delay_factor);
if (new_delay_factor.has_value()) {
delay_factor = new_delay_factor.value();
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd-io/cmd-lore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ void do_cmd_query_symbol(PlayerType *player_ptr)
}

#ifdef JP
if (angband_strstr(temp2, temp) || angband_strstr(r_ref.name.data(), temp)) {
if (str_find(temp2, temp) || str_find(r_ref.name, temp)) {
#else
if (angband_strstr(temp2, temp)) {
if (str_find(temp2, temp)) {
#endif
who.push_back(r_ref.idx);
}
Expand Down
12 changes: 8 additions & 4 deletions src/cmd-visual/cmd-draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ void do_cmd_messages(int num_now)

// @details ダメ文字対策でstringを使わない.
const auto *str = msg;
while ((str = angband_strstr(str, shower)) != nullptr) {
while (true) {
str = angband_strstr(str, shower);
if (str == nullptr) {
break;
}

const auto len = shower.length();
term_putstr(str - msg, num_lines + 1 - j, len, TERM_YELLOW, shower);
str += len;
Expand Down Expand Up @@ -263,9 +268,8 @@ void do_cmd_messages(int num_now)
shower = finder_str;
for (int z = i + 1; z < n; z++) {
// @details ダメ文字対策でstringを使わない.
const auto msg_str = message_str(z);
const auto *msg = msg_str->data();
if (angband_strstr(msg, finder_str) != nullptr) {
const auto msg = message_str(z);
if (str_find(*msg, finder_str)) {
i = z;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd-visual/cmd-visuals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ template <typename T>
static std::optional<T> input_new_visual_id(int i, T initial_visual_id, int max)
{
if (iscntrl(i)) {
const auto new_visual_id = input_value_int("Input new number", 0, max - 1, initial_visual_id);
const auto new_visual_id = input_integer("Input new number", 0, max - 1, initial_visual_id);
if (!new_visual_id.has_value()) {
return std::nullopt;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/asking-player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ void pause_line(int row)
prt("", row, 0);
}

std::optional<int> input_value_int(std::string_view prompt, int min, int max, int initial_value)
std::optional<int> input_integer(std::string_view prompt, int min, int max, int initial_value)
{
std::stringstream ss;
char tmp_val[12] = "";
Expand Down
6 changes: 3 additions & 3 deletions src/core/asking-player.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ bool get_check_strict(PlayerType *player_ptr, std::string_view prompt, BIT_FLAGS
bool get_com(std::string_view prompt, char *command, bool z_escape);
QUANTITY get_quantity(std::optional<std::string_view> prompt_opt, QUANTITY max);
void pause_line(int row);
std::optional<int> input_value_int(std::string_view prompt, int min, int max, int initial_value = 0);
std::optional<int> input_integer(std::string_view prompt, int min, int max, int initial_value = 0);

template <typename T>
std::optional<T> input_value(std::string_view prompt, int min, int max, T initial_value = static_cast<T>(0))
std::optional<T> input_numerics(std::string_view prompt, int min, int max, T initial_value = static_cast<T>(0))
requires std::is_integral_v<T> || std::is_enum_v<T>
{
auto result = input_value_int(prompt, min, max, static_cast<int>(initial_value));
auto result = input_integer(prompt, min, max, static_cast<int>(initial_value));
if (!result.has_value()) {
return std::nullopt;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/show-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ bool show_file(PlayerType *player_ptr, bool show_version, std::string_view name_
char lc_buf[1024];
strcpy(lc_buf, str);
str_tolower(lc_buf);
if (!angband_strstr(lc_buf, find)) {
if (!str_find(lc_buf, find)) {
continue;
}
}
Expand Down
29 changes: 10 additions & 19 deletions src/floor/pattern-walk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,27 @@
#include "view/display-messages.h"
#include "world/world-movement-processor.h"
#include "world/world.h"
#include <algorithm>

/*!
* @brief パターン終点到達時のテレポート処理を行う
* @param player_ptr プレイヤーへの参照ポインタ
*/
void pattern_teleport(PlayerType *player_ptr)
{
DEPTH min_level = 0;
DEPTH max_level = 99;

auto min_level = 0;
auto max_level = 99;
auto current_level = static_cast<short>(player_ptr->current_floor_ptr->dun_level);
if (get_check(_("他の階にテレポートしますか?", "Teleport level? "))) {
char ppp[80];
char tmp_val[160];

if (ironman_downward) {
min_level = player_ptr->current_floor_ptr->dun_level;
min_level = current_level;
}

const auto &floor = *player_ptr->current_floor_ptr;
if (floor.dungeon_idx == DUNGEON_ANGBAND) {
if (floor.dun_level > 100) {
max_level = MAX_DEPTH - 1;
} else if (player_ptr->current_floor_ptr->dun_level == 100) {
} else if (current_level == 100) {
max_level = 100;
}
} else {
Expand All @@ -64,27 +62,20 @@ void pattern_teleport(PlayerType *player_ptr)
min_level = dungeon.mindepth;
}

strnfmt(ppp, sizeof(ppp), _("テレポート先:(%d-%d)", "Teleport to level (%d-%d): "), (int)min_level, (int)max_level);
strnfmt(tmp_val, sizeof(tmp_val), "%d", (int)player_ptr->current_floor_ptr->dun_level);
if (!get_string(ppp, tmp_val, 10)) {
constexpr auto prompt = _("テレポート先", "Teleport to level");
const auto input_level = input_numerics(prompt, min_level, max_level, current_level);
if (!input_level.has_value()) {
return;
}

command_arg = (COMMAND_ARG)atoi(tmp_val);
command_arg = input_level.value();
} else if (get_check(_("通常テレポート?", "Normal teleport? "))) {
teleport_player(player_ptr, 200, TELEPORT_SPONTANEOUS);
return;
} else {
return;
}

if (command_arg < min_level) {
command_arg = (COMMAND_ARG)min_level;
}
if (command_arg > max_level) {
command_arg = (COMMAND_ARG)max_level;
}

msg_format(_("%d 階にテレポートしました。", "You teleport to dungeon level %d."), command_arg);
if (autosave_l) {
do_cmd_save_game(player_ptr, true);
Expand Down
8 changes: 4 additions & 4 deletions src/io/record-play-movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ static struct {

/* リングバッファ構造体 */
static struct {
std::vector<char> buf;
int wptr;
int rptr;
int inlen;
std::vector<char> buf{};
int wptr = 0;
int rptr = 0;
int inlen = 0;
} ring;

/*
Expand Down
36 changes: 5 additions & 31 deletions src/market/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,6 @@ void update_gambling_monsters(PlayerType *player_ptr)
*/
bool monster_arena_comm(PlayerType *player_ptr)
{
PRICE maxbet;
PRICE wager;
char out_val[MAX_MONSTER_NAME], tmp_str[80];
concptr p;

if ((w_ptr->game_turn - w_ptr->arena_start_turn) > TURNS_PER_TICK * 250) {
update_gambling_monsters(player_ptr);
w_ptr->arena_start_turn = w_ptr->game_turn;
Expand Down Expand Up @@ -326,42 +321,21 @@ bool monster_arena_comm(PlayerType *player_ptr)
}
}

maxbet = player_ptr->lev * 200;

/* We can't bet more than we have */
auto maxbet = player_ptr->lev * 200;
maxbet = std::min(maxbet, player_ptr->au);

/* Get the wager */
strcpy(out_val, "");
sprintf(tmp_str, _("賭け金 (1-%ld)?", "Your wager (1-%ld) ? "), (long int)maxbet);

/*
* Use get_string() because we may need more than
* the int16_t value returned by get_quantity().
*/
if (!get_string(tmp_str, out_val, 32)) {
constexpr auto prompt = _("賭け金?", "Your wager? ");
const auto wager_opt = input_integer(prompt, 1, maxbet, 1);
if (!wager_opt.has_value()) {
screen_load();
return false;
}

for (p = out_val; *p == ' '; p++) {
;
}

wager = atol(p);
auto wager = wager_opt.value();
if (wager > player_ptr->au) {
msg_print(_("おい!金が足りないじゃないか!出ていけ!", "Hey! You don't have the gold - get out of here!"));

msg_print(nullptr);
screen_load();
return false;
} else if (wager > maxbet) {
msg_format(_("%ldゴールドだけ受けよう。残りは取っときな。", "I'll take %ld gold of that. Keep the rest."), (long int)maxbet);

wager = maxbet;
} else if (wager < 1) {
msg_print(_("OK、1ゴールドでいこう。", "Ok, we'll start with 1 gold."));
wager = 1;
}

msg_print(nullptr);
Expand Down
4 changes: 2 additions & 2 deletions src/market/building-monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ bool research_mon(PlayerType *player_ptr)
}

#ifdef JP
if (angband_strstr(temp2.data(), temp) || angband_strstr(monrace.name.data(), temp))
if (str_find(temp2, temp) || str_find(monrace.name, temp))
#else
if (angband_strstr(temp2.data(), temp))
if (str_find(temp2, temp))
#endif
who.push_back(monrace_id);
} else if (all || (monrace.d_char == sym)) {
Expand Down
Loading

0 comments on commit 07c2d9d

Please sign in to comment.