• R/O
  • HTTP
  • SSH
  • HTTPS

hengbandosx: 提交

The master and develop branches track hengband.

OS X development happens on the macos-1-6-2, macos-2-2-1, and macos-develop branches.


Commit MetaInfo

修订版5b9ff228d899e025f0bc722d04dea700289a6d23 (tree)
时间2022-09-17 17:26:44
作者Hourier <66951241+Hourier@user...>
CommiterGitHub

Log Message

Merge pull request #2646 from Hourier/Change-Strip-Name-Signature

strip_name() のシグネチャを変えた

更改概述

差异

--- a/src/cmd-visual/cmd-visuals.cpp
+++ b/src/cmd-visual/cmd-visuals.cpp
@@ -155,20 +155,25 @@ void do_cmd_visuals(PlayerType *player_ptr)
155155
156156 auto_dump_printf(auto_dump_stream, _("\n# アイテムの[色/文字]の設定\n\n", "\n# Object attr/char definitions\n\n"));
157157 for (const auto &k_ref : k_info) {
158- GAME_TEXT o_name[MAX_NLEN];
159158 if (k_ref.name.empty()) {
160159 continue;
161160 }
162161
162+ std::string o_name("");
163+ GAME_TEXT char_o_name[MAX_NLEN]{};
163164 if (!k_ref.flavor) {
164- strip_name(o_name, k_ref.idx);
165+ o_name = strip_name(k_ref.idx);
165166 } else {
166167 ObjectType dummy;
167168 dummy.prep(k_ref.idx);
168- describe_flavor(player_ptr, o_name, &dummy, OD_FORCE_FLAVOR);
169+ describe_flavor(player_ptr, char_o_name, &dummy, OD_FORCE_FLAVOR);
169170 }
170171
171- auto_dump_printf(auto_dump_stream, "# %s\n", o_name);
172+ if (o_name == "") {
173+ o_name = char_o_name;
174+ }
175+
176+ auto_dump_printf(auto_dump_stream, "# %s\n", o_name.data());
172177 auto_dump_printf(auto_dump_stream, "K:%d:0x%02X/0x%02X\n\n", (int)k_ref.idx, (byte)(k_ref.x_attr), (byte)(k_ref.x_char));
173178 }
174179
--- a/src/flavor/object-flavor.cpp
+++ b/src/flavor/object-flavor.cpp
@@ -42,6 +42,7 @@
4242 #include "util/string-processor.h"
4343 #include "world/world.h"
4444 #include <functional>
45+#include <sstream>
4546 #include <utility>
4647
4748 /*!
@@ -252,12 +253,12 @@ void flavor_init(void)
252253 * @param buf ベースアイテム格納先の参照ポインタ
253254 * @param k_idx ベースアイテムID
254255 */
255-void strip_name(char *buf, KIND_OBJECT_IDX k_idx)
256+std::string strip_name(KIND_OBJECT_IDX k_idx)
256257 {
257258 auto k_ptr = &k_info[k_idx];
258259 auto tok = str_split(k_ptr->name, ' ');
259- std::string name = "";
260- for (auto s : tok) {
260+ std::stringstream name;
261+ for (const auto &s : tok) {
261262 if (s == "" || s == "~" || s == "&" || s == "#") {
262263 continue;
263264 }
@@ -279,9 +280,9 @@ void strip_name(char *buf, KIND_OBJECT_IDX k_idx)
279280 endpos--;
280281 }
281282
282- name += s.substr(offset, endpos);
283+ name << s.substr(offset, endpos);
283284 }
284285
285- name += " ";
286- strcpy(buf, name.c_str());
286+ name << " ";
287+ return name.str();
287288 }
--- a/src/flavor/object-flavor.h
+++ b/src/flavor/object-flavor.h
@@ -1,10 +1,11 @@
11 #pragma once
22
33 #include "system/angband.h"
4+#include <string>
45
56 void get_table_name_aux(char *out_string);
67 void get_table_name(char *out_string);
78 void get_table_sindarin_aux(char *out_string);
89 void get_table_sindarin(char *out_string);
910 void flavor_init(void);
10-void strip_name(char *buf, KIND_OBJECT_IDX k_idx);
11+std::string strip_name(KIND_OBJECT_IDX k_idx);
--- a/src/knowledge/knowledge-experiences.cpp
+++ b/src/knowledge/knowledge-experiences.cpp
@@ -34,7 +34,6 @@ void do_cmd_knowledge_weapon_exp(PlayerType *player_ptr)
3434
3535 for (auto tval : { ItemKindType::SWORD, ItemKindType::POLEARM, ItemKindType::HAFTED, ItemKindType::DIGGING, ItemKindType::BOW }) {
3636 for (int num = 0; num < 64; num++) {
37- char tmp[30];
3837 for (const auto &k_ref : k_info) {
3938 if ((k_ref.tval != tval) || (k_ref.sval != num)) {
4039 continue;
@@ -45,8 +44,8 @@ void do_cmd_knowledge_weapon_exp(PlayerType *player_ptr)
4544
4645 SUB_EXP weapon_exp = player_ptr->weapon_exp[tval][num];
4746 SUB_EXP weapon_max = player_ptr->weapon_exp_max[tval][num];
48- strip_name(tmp, k_ref.idx);
49- fprintf(fff, "%-25s ", tmp);
47+ const auto tmp = strip_name(k_ref.idx);
48+ fprintf(fff, "%-25s ", tmp.data());
5049 if (show_actual_value) {
5150 fprintf(fff, "%4d/%4d ", weapon_exp, weapon_max);
5251 }
--- a/src/knowledge/knowledge-items.cpp
+++ b/src/knowledge/knowledge-items.cpp
@@ -179,7 +179,6 @@ static void display_object_list(int col, int row, int per_page, IDX object_idx[]
179179 {
180180 int i;
181181 for (i = 0; i < per_page && (object_idx[object_top + i] >= 0); i++) {
182- GAME_TEXT o_name[MAX_NLEN];
183182 TERM_COLOR a;
184183 object_kind *flavor_k_ptr;
185184 KIND_OBJECT_IDX k_idx = object_idx[object_top + i];
@@ -193,13 +192,9 @@ static void display_object_list(int col, int row, int per_page, IDX object_idx[]
193192 }
194193
195194 attr = ((i + object_top == object_cur) ? cursor : attr);
196- if (!k_ptr->flavor || (!visual_only && k_ptr->aware)) {
197- strip_name(o_name, k_idx);
198- } else {
199- strcpy(o_name, flavor_k_ptr->flavor_name.c_str());
200- }
201-
202- c_prt(attr, o_name, row + i, col);
195+ const auto is_flavor_only = (k_ptr->flavor != 0) && (visual_only || !k_ptr->aware);
196+ const auto o_name = is_flavor_only ? flavor_k_ptr->flavor_name : strip_name(k_idx);
197+ c_prt(attr, o_name.data(), row + i, col);
203198 if (per_page == 1) {
204199 c_prt(attr, format("%02x/%02x", flavor_k_ptr->x_attr, flavor_k_ptr->x_char), row + i, (w_ptr->wizard || visual_only) ? 64 : 68);
205200 }
--- a/src/wizard/wizard-special-process.cpp
+++ b/src/wizard/wizard-special-process.cpp
@@ -153,7 +153,6 @@ static KIND_OBJECT_IDX wiz_select_sval(const ItemKindType tval, concptr tval_des
153153 {
154154 auto num = 0;
155155 KIND_OBJECT_IDX choice[80]{};
156- char buf[160]{};
157156 char ch;
158157 for (const auto &k_ref : k_info) {
159158 if (num >= 80) {
@@ -167,9 +166,8 @@ static KIND_OBJECT_IDX wiz_select_sval(const ItemKindType tval, concptr tval_des
167166 auto row = 2 + (num % 20);
168167 auto col = _(30, 32) * (num / 20);
169168 ch = listsym[num];
170- strcpy(buf, " ");
171- strip_name(buf, k_ref.idx);
172- prt(format("[%c] %s", ch, buf), row, col);
169+ const auto buf = strip_name(k_ref.idx);
170+ prt(format("[%c] %s", ch, buf.c_str()), row, col);
173171 choice[num++] = k_ref.idx;
174172 }
175173
Show on old repository browser