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.
リビジョン | 549a7cc999b21a75b9da49ce926b4fbd33184261 (tree) |
---|---|
日時 | 2021-09-20 15:39:13 |
作者 | Habu <habu1010+github@gmai...> |
コミッター | GitHub |
Merge pull request #1570 from habu1010/feature/refactor-defeat-temporary-cmake-buffer
[Refactor] C_MAKEによる一時的バッファをstd::vectorで置き換える
@@ -188,22 +188,17 @@ static bool activate_whistle(player_type *player_ptr, ae_type *ae_ptr) | ||
188 | 188 | (void)SpellHex(player_ptr).stop_all_spells(); |
189 | 189 | } |
190 | 190 | |
191 | - MONSTER_IDX pet_ctr; | |
192 | - MONSTER_IDX *who; | |
193 | - int max_pet = 0; | |
194 | - C_MAKE(who, w_ptr->max_m_idx, MONSTER_IDX); | |
195 | - for (pet_ctr = player_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--) | |
191 | + std::vector<MONSTER_IDX> who; | |
192 | + for (MONSTER_IDX pet_ctr = player_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--) | |
196 | 193 | if (is_pet(&player_ptr->current_floor_ptr->m_list[pet_ctr]) && (player_ptr->riding != pet_ctr)) |
197 | - who[max_pet++] = pet_ctr; | |
194 | + who.push_back(pet_ctr); | |
198 | 195 | |
199 | 196 | uint16_t dummy_why; |
200 | - ang_sort(player_ptr, who, &dummy_why, max_pet, ang_sort_comp_pet, ang_sort_swap_hook); | |
201 | - for (MONSTER_IDX i = 0; i < max_pet; i++) { | |
202 | - pet_ctr = who[i]; | |
197 | + ang_sort(player_ptr, who.data(), &dummy_why, who.size(), ang_sort_comp_pet, ang_sort_swap_hook); | |
198 | + for (auto pet_ctr : who) { | |
203 | 199 | teleport_monster_to(player_ptr, pet_ctr, player_ptr->y, player_ptr->x, 100, TELEPORT_PASSIVE); |
204 | 200 | } |
205 | 201 | |
206 | - C_KILL(who, w_ptr->max_m_idx, MONSTER_IDX); | |
207 | 202 | ae_ptr->o_ptr->timeout = 100 + randint1(100); |
208 | 203 | return true; |
209 | 204 | } |
@@ -72,13 +72,9 @@ void do_cmd_pet_dismiss(player_type *player_ptr) | ||
72 | 72 | { |
73 | 73 | monster_type *m_ptr; |
74 | 74 | bool all_pets = false; |
75 | - MONSTER_IDX pet_ctr; | |
76 | - int i; | |
77 | 75 | int Dismissed = 0; |
78 | 76 | |
79 | - MONSTER_IDX *who; | |
80 | 77 | uint16_t dummy_why; |
81 | - int max_pet = 0; | |
82 | 78 | bool cu, cv; |
83 | 79 | |
84 | 80 | cu = Term->scr->cu; |
@@ -87,23 +83,23 @@ void do_cmd_pet_dismiss(player_type *player_ptr) | ||
87 | 83 | Term->scr->cv = 1; |
88 | 84 | |
89 | 85 | /* Allocate the "who" array */ |
90 | - C_MAKE(who, w_ptr->max_m_idx, MONSTER_IDX); | |
86 | + std::vector<MONSTER_IDX> who; | |
91 | 87 | |
92 | 88 | /* Process the monsters (backwards) */ |
93 | - for (pet_ctr = player_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--) { | |
89 | + for (MONSTER_IDX pet_ctr = player_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--) { | |
94 | 90 | if (is_pet(&player_ptr->current_floor_ptr->m_list[pet_ctr])) |
95 | - who[max_pet++] = pet_ctr; | |
91 | + who.push_back(pet_ctr); | |
96 | 92 | } |
97 | 93 | |
98 | - ang_sort(player_ptr, who, &dummy_why, max_pet, ang_sort_comp_pet_dismiss, ang_sort_swap_hook); | |
94 | + ang_sort(player_ptr, who.data(), &dummy_why, who.size(), ang_sort_comp_pet_dismiss, ang_sort_swap_hook); | |
99 | 95 | |
100 | 96 | /* Process the monsters (backwards) */ |
101 | - for (i = 0; i < max_pet; i++) { | |
97 | + for (auto i = 0U; i < who.size(); i++) { | |
102 | 98 | bool delete_this; |
103 | 99 | GAME_TEXT friend_name[MAX_NLEN]; |
104 | 100 | bool kakunin; |
105 | 101 | |
106 | - pet_ctr = who[i]; | |
102 | + auto pet_ctr = who[i]; | |
107 | 103 | m_ptr = &player_ptr->current_floor_ptr->m_list[pet_ctr]; |
108 | 104 | |
109 | 105 | delete_this = false; |
@@ -115,7 +111,7 @@ void do_cmd_pet_dismiss(player_type *player_ptr) | ||
115 | 111 | health_track(player_ptr, pet_ctr); |
116 | 112 | handle_stuff(player_ptr); |
117 | 113 | |
118 | - msg_format(_("%sを放しますか? [Yes/No/Unnamed (%d体)]", "Dismiss %s? [Yes/No/Unnamed (%d remain)]"), friend_name, max_pet - i); | |
114 | + msg_format(_("%sを放しますか? [Yes/No/Unnamed (%d体)]", "Dismiss %s? [Yes/No/Unnamed (%d remain)]"), friend_name, who.size() - i); | |
119 | 115 | |
120 | 116 | if (m_ptr->ml) |
121 | 117 | move_cursor_relative(m_ptr->fy, m_ptr->fx); |
@@ -178,8 +174,6 @@ void do_cmd_pet_dismiss(player_type *player_ptr) | ||
178 | 174 | Term->scr->cv = cv; |
179 | 175 | term_fresh(); |
180 | 176 | |
181 | - C_KILL(who, w_ptr->max_m_idx, MONSTER_IDX); | |
182 | - | |
183 | 177 | #ifdef JP |
184 | 178 | msg_format("%d 体のペットを放しました。", Dismissed); |
185 | 179 | #else |
@@ -36,9 +36,6 @@ | ||
36 | 36 | */ |
37 | 37 | void do_cmd_query_symbol(player_type *player_ptr) |
38 | 38 | { |
39 | - MONRACE_IDX i; | |
40 | - int n; | |
41 | - MONRACE_IDX r_idx; | |
42 | 39 | char sym, query; |
43 | 40 | char buf[256]; |
44 | 41 |
@@ -51,15 +48,15 @@ void do_cmd_query_symbol(player_type *player_ptr) | ||
51 | 48 | bool recall = false; |
52 | 49 | |
53 | 50 | uint16_t why = 0; |
54 | - MONRACE_IDX *who; | |
55 | 51 | |
56 | 52 | if (!get_com(_("知りたい文字を入力して下さい(記号 or ^A全,^Uユ,^N非ユ,^R乗馬,^M名前): ", |
57 | 53 | "Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): "), |
58 | 54 | &sym, false)) |
59 | 55 | return; |
60 | 56 | |
61 | - for (i = 0; ident_info[i]; ++i) { | |
62 | - if (sym == ident_info[i][0]) | |
57 | + int ident_i; | |
58 | + for (ident_i = 0; ident_info[ident_i]; ++ident_i) { | |
59 | + if (sym == ident_info[ident_i][0]) | |
63 | 60 | break; |
64 | 61 | } |
65 | 62 |
@@ -82,15 +79,14 @@ void do_cmd_query_symbol(player_type *player_ptr) | ||
82 | 79 | return; |
83 | 80 | } |
84 | 81 | sprintf(buf, _("名前:%sにマッチ", "Monsters' names with \"%s\""), temp); |
85 | - } else if (ident_info[i]) { | |
86 | - sprintf(buf, "%c - %s.", sym, ident_info[i] + 2); | |
82 | + } else if (ident_info[ident_i]) { | |
83 | + sprintf(buf, "%c - %s.", sym, ident_info[ident_i] + 2); | |
87 | 84 | } else { |
88 | 85 | sprintf(buf, "%c - %s", sym, _("無効な文字", "Unknown Symbol")); |
89 | 86 | } |
90 | 87 | |
91 | 88 | prt(buf, 0, 0); |
92 | - C_MAKE(who, max_r_idx, MONRACE_IDX); | |
93 | - n = 0; | |
89 | + std::vector<MONRACE_IDX> who; | |
94 | 90 | for (const auto &r_ref : r_info) { |
95 | 91 | if (!cheat_know && !r_ref.r_sights) |
96 | 92 | continue; |
@@ -133,15 +129,14 @@ void do_cmd_query_symbol(player_type *player_ptr) | ||
133 | 129 | #else |
134 | 130 | if (angband_strstr(temp2, temp)) |
135 | 131 | #endif |
136 | - who[n++] = i; | |
132 | + who.push_back(r_ref.idx); | |
137 | 133 | } |
138 | 134 | |
139 | 135 | else if (all || (r_ref.d_char == sym)) |
140 | - who[n++] = i; | |
136 | + who.push_back(r_ref.idx); | |
141 | 137 | } |
142 | 138 | |
143 | - if (!n) { | |
144 | - C_KILL(who, max_r_idx, MONRACE_IDX); | |
139 | + if (who.empty()) { | |
145 | 140 | return; |
146 | 141 | } |
147 | 142 |
@@ -149,24 +144,23 @@ void do_cmd_query_symbol(player_type *player_ptr) | ||
149 | 144 | query = inkey(); |
150 | 145 | prt(buf, 0, 0); |
151 | 146 | why = 2; |
152 | - ang_sort(player_ptr, who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook); | |
147 | + ang_sort(player_ptr, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook); | |
153 | 148 | if (query == 'k') { |
154 | 149 | why = 4; |
155 | 150 | query = 'y'; |
156 | 151 | } |
157 | 152 | |
158 | 153 | if (query != 'y') { |
159 | - C_KILL(who, max_r_idx, MONRACE_IDX); | |
160 | 154 | return; |
161 | 155 | } |
162 | 156 | |
163 | 157 | if (why == 4) { |
164 | - ang_sort(player_ptr, who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook); | |
158 | + ang_sort(player_ptr, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook); | |
165 | 159 | } |
166 | 160 | |
167 | - i = n - 1; | |
161 | + auto i = who.size() - 1; | |
168 | 162 | while (true) { |
169 | - r_idx = who[i]; | |
163 | + auto r_idx = who[i]; | |
170 | 164 | monster_race_track(player_ptr, r_idx); |
171 | 165 | handle_stuff(player_ptr); |
172 | 166 | while (true) { |
@@ -191,20 +185,19 @@ void do_cmd_query_symbol(player_type *player_ptr) | ||
191 | 185 | break; |
192 | 186 | |
193 | 187 | if (query == '-') { |
194 | - if (++i == n) { | |
188 | + if (++i == who.size()) { | |
195 | 189 | i = 0; |
196 | 190 | if (!expand_list) |
197 | 191 | break; |
198 | 192 | } |
199 | 193 | } else { |
200 | 194 | if (i-- == 0) { |
201 | - i = n - 1; | |
195 | + i = who.size() - 1; | |
202 | 196 | if (!expand_list) |
203 | 197 | break; |
204 | 198 | } |
205 | 199 | } |
206 | 200 | } |
207 | 201 | |
208 | - C_KILL(who, max_r_idx, MONRACE_IDX); | |
209 | 202 | prt(buf, 0, 0); |
210 | 203 | } |
@@ -32,8 +32,6 @@ DEPTH *max_dlv; | ||
32 | 32 | DUNGEON_IDX choose_dungeon(concptr note, POSITION y, POSITION x) |
33 | 33 | { |
34 | 34 | DUNGEON_IDX select_dungeon; |
35 | - int num = 0; | |
36 | - DUNGEON_IDX *dun; | |
37 | 35 | |
38 | 36 | /* Hack -- No need to choose dungeon in some case */ |
39 | 37 | if (lite_town || vanilla_town || ironman_downward) { |
@@ -46,8 +44,7 @@ DUNGEON_IDX choose_dungeon(concptr note, POSITION y, POSITION x) | ||
46 | 44 | } |
47 | 45 | } |
48 | 46 | |
49 | - /* Allocate the "dun" array */ | |
50 | - C_MAKE(dun, w_ptr->max_d_idx, DUNGEON_IDX); | |
47 | + std::vector<DUNGEON_IDX> dun; | |
51 | 48 | |
52 | 49 | screen_save(); |
53 | 50 | for (const auto &d_ref : d_info) { |
@@ -65,26 +62,23 @@ DUNGEON_IDX choose_dungeon(concptr note, POSITION y, POSITION x) | ||
65 | 62 | seiha = true; |
66 | 63 | |
67 | 64 | sprintf(buf, _(" %c) %c%-12s : 最大 %d 階", " %c) %c%-16s : Max level %d"), |
68 | - 'a' + num, seiha ? '!' : ' ', d_ref.name.c_str(), (int)max_dlv[d_ref.idx]); | |
69 | - prt(buf, y + num, x); | |
70 | - dun[num++] = d_ref.idx; | |
65 | + static_cast<char>('a' + dun.size()), seiha ? '!' : ' ', d_ref.name.c_str(), (int)max_dlv[d_ref.idx]); | |
66 | + prt(buf, y + dun.size(), x); | |
67 | + dun.push_back(d_ref.idx); | |
71 | 68 | } |
72 | 69 | |
73 | - if (!num) { | |
70 | + if (dun.empty()) { | |
74 | 71 | prt(_(" 選べるダンジョンがない。", " No dungeon is available."), y, x); |
75 | 72 | } |
76 | 73 | |
77 | 74 | prt(format(_("どのダンジョン%sしますか:", "Which dungeon do you %s?: "), note), 0, 0); |
78 | 75 | while (true) { |
79 | 76 | auto i = inkey(); |
80 | - if ((i == ESCAPE) || !num) { | |
81 | - /* Free the "dun" array */ | |
82 | - C_KILL(dun, w_ptr->max_d_idx, DUNGEON_IDX); | |
83 | - | |
77 | + if ((i == ESCAPE) || dun.empty()) { | |
84 | 78 | screen_load(); |
85 | 79 | return 0; |
86 | 80 | } |
87 | - if (i >= 'a' && i < ('a' + num)) { | |
81 | + if (i >= 'a' && i < static_cast<char>('a' + dun.size())) { | |
88 | 82 | select_dungeon = dun[i - 'a']; |
89 | 83 | break; |
90 | 84 | } else |
@@ -92,9 +86,6 @@ DUNGEON_IDX choose_dungeon(concptr note, POSITION y, POSITION x) | ||
92 | 86 | } |
93 | 87 | screen_load(); |
94 | 88 | |
95 | - /* Free the "dun" array */ | |
96 | - C_KILL(dun, w_ptr->max_d_idx, DUNGEON_IDX); | |
97 | - | |
98 | 89 | return select_dungeon; |
99 | 90 | } |
100 | 91 |
@@ -191,9 +191,7 @@ void get_table_sindarin(char *out_string) | ||
191 | 191 | */ |
192 | 192 | static void shuffle_flavors(tval_type tval) |
193 | 193 | { |
194 | - KIND_OBJECT_IDX *k_idx_list; | |
195 | - KIND_OBJECT_IDX k_idx_list_num = 0; | |
196 | - C_MAKE(k_idx_list, max_k_idx, KIND_OBJECT_IDX); | |
194 | + std::vector<KIND_OBJECT_IDX> k_idx_list; | |
197 | 195 | for (const auto &k_ref : k_info) { |
198 | 196 | if (k_ref.tval != tval) |
199 | 197 | continue; |
@@ -204,19 +202,14 @@ static void shuffle_flavors(tval_type tval) | ||
204 | 202 | if (k_ref.flags.has(TR_FIXED_FLAVOR)) |
205 | 203 | continue; |
206 | 204 | |
207 | - k_idx_list[k_idx_list_num] = k_ref.idx; | |
208 | - k_idx_list_num++; | |
205 | + k_idx_list.push_back(k_ref.idx); | |
209 | 206 | } |
210 | 207 | |
211 | - for (KIND_OBJECT_IDX i = 0; i < k_idx_list_num; i++) { | |
212 | - object_kind *k1_ptr = &k_info[k_idx_list[i]]; | |
213 | - object_kind *k2_ptr = &k_info[k_idx_list[randint0(k_idx_list_num)]]; | |
214 | - int16_t tmp = k1_ptr->flavor; | |
215 | - k1_ptr->flavor = k2_ptr->flavor; | |
216 | - k2_ptr->flavor = tmp; | |
208 | + for (auto k_idx : k_idx_list) { | |
209 | + object_kind *k1_ptr = &k_info[k_idx]; | |
210 | + object_kind *k2_ptr = &k_info[k_idx_list[randint0(k_idx_list.size())]]; | |
211 | + std::swap(k1_ptr->flavor, k2_ptr->flavor); | |
217 | 212 | } |
218 | - | |
219 | - C_KILL(k_idx_list, max_k_idx, int16_t); | |
220 | 213 | } |
221 | 214 | |
222 | 215 | /*! |
@@ -47,6 +47,8 @@ | ||
47 | 47 | #include "view/display-messages.h" |
48 | 48 | #include "world/world.h" |
49 | 49 | |
50 | +#include <numeric> | |
51 | + | |
50 | 52 | /*! |
51 | 53 | * @brief プレイヤーのペット情報をファイルにダンプする |
52 | 54 | * @param player_ptr プレイヤーへの参照ポインタ |
@@ -110,21 +112,17 @@ static void dump_aux_pet(player_type *player_ptr, FILE *fff) | ||
110 | 112 | static void dump_aux_quest(player_type *player_ptr, FILE *fff) |
111 | 113 | { |
112 | 114 | fprintf(fff, _("\n\n [クエスト情報]\n", "\n\n [Quest Information]\n")); |
113 | - QUEST_IDX *quest_num; | |
114 | - C_MAKE(quest_num, max_q_idx, QUEST_IDX); | |
115 | + std::vector<QUEST_IDX> quest_num(max_q_idx); | |
115 | 116 | |
116 | - for (QUEST_IDX i = 1; i < max_q_idx; i++) | |
117 | - quest_num[i] = i; | |
117 | + std::iota(quest_num.begin(), quest_num.end(), static_cast<QUEST_IDX>(0)); | |
118 | 118 | int dummy; |
119 | - ang_sort(player_ptr, quest_num, &dummy, max_q_idx, ang_sort_comp_quest_num, ang_sort_swap_quest_num); | |
119 | + ang_sort(player_ptr, quest_num.data(), &dummy, quest_num.size(), ang_sort_comp_quest_num, ang_sort_swap_quest_num); | |
120 | 120 | |
121 | 121 | fputc('\n', fff); |
122 | - do_cmd_knowledge_quests_completed(player_ptr, fff, quest_num); | |
122 | + do_cmd_knowledge_quests_completed(player_ptr, fff, quest_num.data()); | |
123 | 123 | fputc('\n', fff); |
124 | - do_cmd_knowledge_quests_failed(player_ptr, fff, quest_num); | |
124 | + do_cmd_knowledge_quests_failed(player_ptr, fff, quest_num.data()); | |
125 | 125 | fputc('\n', fff); |
126 | - | |
127 | - C_KILL(quest_num, max_q_idx, QUEST_IDX); | |
128 | 126 | } |
129 | 127 | |
130 | 128 | /*! |
@@ -288,12 +286,10 @@ static void dump_aux_monsters(player_type *player_ptr, FILE *fff) | ||
288 | 286 | fprintf(fff, _("\n [倒したモンスター]\n\n", "\n [Defeated Monsters]\n\n")); |
289 | 287 | |
290 | 288 | /* Allocate the "who" array */ |
291 | - MONRACE_IDX *who; | |
292 | 289 | uint16_t why = 2; |
293 | - C_MAKE(who, max_r_idx, MONRACE_IDX); | |
290 | + std::vector<MONRACE_IDX> who; | |
294 | 291 | |
295 | 292 | /* Count monster kills */ |
296 | - long uniq_total = 0; | |
297 | 293 | long norm_total = 0; |
298 | 294 | for (const auto &r_ref : r_info) { |
299 | 295 | /* Ignore unused index */ |
@@ -306,7 +302,7 @@ static void dump_aux_monsters(player_type *player_ptr, FILE *fff) | ||
306 | 302 | norm_total++; |
307 | 303 | |
308 | 304 | /* Add a unique monster to the list */ |
309 | - who[uniq_total++] = r_ref.idx; | |
305 | + who.push_back(r_ref.idx); | |
310 | 306 | } |
311 | 307 | |
312 | 308 | continue; |
@@ -320,10 +316,10 @@ static void dump_aux_monsters(player_type *player_ptr, FILE *fff) | ||
320 | 316 | /* No monsters is defeated */ |
321 | 317 | if (norm_total < 1) { |
322 | 318 | fprintf(fff, _("まだ敵を倒していません。\n", "You have defeated no enemies yet.\n")); |
323 | - C_KILL(who, max_r_idx, int16_t); | |
324 | 319 | return; |
325 | 320 | } |
326 | 321 | |
322 | + const long uniq_total = who.size(); | |
327 | 323 | /* Defeated more than one normal monsters */ |
328 | 324 | if (uniq_total == 0) { |
329 | 325 | #ifdef JP |
@@ -331,7 +327,6 @@ static void dump_aux_monsters(player_type *player_ptr, FILE *fff) | ||
331 | 327 | #else |
332 | 328 | fprintf(fff, "You have defeated %ld %s.\n", norm_total, norm_total == 1 ? "enemy" : "enemies"); |
333 | 329 | #endif |
334 | - C_KILL(who, max_r_idx, int16_t); | |
335 | 330 | return; |
336 | 331 | } |
337 | 332 |
@@ -344,12 +339,12 @@ static void dump_aux_monsters(player_type *player_ptr, FILE *fff) | ||
344 | 339 | #endif |
345 | 340 | |
346 | 341 | /* Sort the array by dungeon depth of monsters */ |
347 | - ang_sort(player_ptr, who, &why, uniq_total, ang_sort_comp_hook, ang_sort_swap_hook); | |
342 | + ang_sort(player_ptr, who.data(), &why, uniq_total, ang_sort_comp_hook, ang_sort_swap_hook); | |
348 | 343 | fprintf(fff, _("\n《上位%ld体のユニーク・モンスター》\n", "\n< Unique monsters top %ld >\n"), MIN(uniq_total, 10)); |
349 | 344 | |
350 | 345 | char buf[80]; |
351 | - for (MONRACE_IDX k = uniq_total - 1; k >= 0 && k >= uniq_total - 10; k--) { | |
352 | - monster_race *r_ptr = &r_info[who[k]]; | |
346 | + for (auto it = who.rbegin(); it != who.rend() && std::distance(who.rbegin(), it) < 10; it++) { | |
347 | + monster_race *r_ptr = &r_info[*it]; | |
353 | 348 | if (r_ptr->defeat_level && r_ptr->defeat_time) |
354 | 349 | sprintf(buf, _(" - レベル%2d - %d:%02d:%02d", " - level %2d - %d:%02d:%02d"), r_ptr->defeat_level, r_ptr->defeat_time / (60 * 60), |
355 | 350 | (r_ptr->defeat_time / 60) % 60, r_ptr->defeat_time % 60); |
@@ -358,8 +353,6 @@ static void dump_aux_monsters(player_type *player_ptr, FILE *fff) | ||
358 | 353 | |
359 | 354 | fprintf(fff, _(" %-40s (レベル%3d)%s\n", " %-40s (level %3d)%s\n"), r_ptr->name.c_str(), (int)r_ptr->level, buf); |
360 | 355 | } |
361 | - | |
362 | - C_KILL(who, max_r_idx, int16_t); | |
363 | 356 | } |
364 | 357 | |
365 | 358 | /*! |
@@ -102,8 +102,7 @@ void do_cmd_knowledge_features(bool *need_redraw, bool visual_only, IDX direct_f | ||
102 | 102 | TERM_LEN wid, hgt; |
103 | 103 | term_get_size(&wid, &hgt); |
104 | 104 | |
105 | - FEAT_IDX *feat_idx; | |
106 | - C_MAKE(feat_idx, max_f_idx, FEAT_IDX); | |
105 | + std::vector<FEAT_IDX> feat_idx(f_info.size()); | |
107 | 106 | |
108 | 107 | concptr feature_group_text[] = { "terrains", nullptr }; |
109 | 108 | int len; |
@@ -121,7 +120,7 @@ void do_cmd_knowledge_features(bool *need_redraw, bool visual_only, IDX direct_f | ||
121 | 120 | if (len > max) |
122 | 121 | max = len; |
123 | 122 | |
124 | - if (collect_features(feat_idx, 0x01)) { | |
123 | + if (collect_features(feat_idx.data(), 0x01)) { | |
125 | 124 | grp_idx[grp_cnt++] = i; |
126 | 125 | } |
127 | 126 | } |
@@ -198,7 +197,7 @@ void do_cmd_knowledge_features(bool *need_redraw, bool visual_only, IDX direct_f | ||
198 | 197 | display_group_list(0, 6, max, browser_rows, grp_idx, feature_group_text, grp_cur, grp_top); |
199 | 198 | if (old_grp_cur != grp_cur) { |
200 | 199 | old_grp_cur = grp_cur; |
201 | - feat_cnt = collect_features(feat_idx, 0x00); | |
200 | + feat_cnt = collect_features(feat_idx.data(), 0x00); | |
202 | 201 | } |
203 | 202 | |
204 | 203 | while (feat_cur < feat_top) |
@@ -208,10 +207,10 @@ void do_cmd_knowledge_features(bool *need_redraw, bool visual_only, IDX direct_f | ||
208 | 207 | } |
209 | 208 | |
210 | 209 | if (!visual_list) { |
211 | - display_feature_list(max + 3, 6, browser_rows, feat_idx, feat_cur, feat_top, visual_only, F_LIT_STANDARD); | |
210 | + display_feature_list(max + 3, 6, browser_rows, feat_idx.data(), feat_cur, feat_top, visual_only, F_LIT_STANDARD); | |
212 | 211 | } else { |
213 | 212 | feat_top = feat_cur; |
214 | - display_feature_list(max + 3, 6, 1, feat_idx, feat_cur, feat_top, visual_only, *lighting_level); | |
213 | + display_feature_list(max + 3, 6, 1, feat_idx.data(), feat_cur, feat_top, visual_only, *lighting_level); | |
215 | 214 | display_visual_list(max + 3, 7, browser_rows - 1, wid - (max + 3), attr_top, char_left); |
216 | 215 | } |
217 | 216 |
@@ -334,8 +333,6 @@ void do_cmd_knowledge_features(bool *need_redraw, bool visual_only, IDX direct_f | ||
334 | 333 | } |
335 | 334 | } |
336 | 335 | } |
337 | - | |
338 | - C_KILL(feat_idx, max_f_idx, FEAT_IDX); | |
339 | 336 | } |
340 | 337 | |
341 | 338 | /* |
@@ -46,10 +46,8 @@ void do_cmd_knowledge_artifacts(player_type *player_ptr) | ||
46 | 46 | if (!open_temporary_file(&fff, file_name)) |
47 | 47 | return; |
48 | 48 | |
49 | - ARTIFACT_IDX *who; | |
50 | - C_MAKE(who, max_a_idx, ARTIFACT_IDX); | |
51 | - bool *okay; | |
52 | - C_MAKE(okay, max_a_idx, bool); | |
49 | + //! @note 一般的に std::vector<bool> は使用を避けるべきとされているが、ここの用途では問題ない | |
50 | + std::vector<bool> okay(a_info.size()); | |
53 | 51 | |
54 | 52 | for (const auto &a_ref : a_info) { |
55 | 53 | okay[a_ref.idx] = false; |
@@ -89,16 +87,16 @@ void do_cmd_knowledge_artifacts(player_type *player_ptr) | ||
89 | 87 | okay[o_ptr->name1] = false; |
90 | 88 | } |
91 | 89 | |
92 | - int n = 0; | |
90 | + std::vector<ARTIFACT_IDX> whats; | |
93 | 91 | for (const auto &a_ref : a_info) { |
94 | 92 | if (okay[a_ref.idx]) |
95 | - who[n++] = a_ref.idx; | |
93 | + whats.push_back(a_ref.idx); | |
96 | 94 | } |
97 | 95 | |
98 | 96 | uint16_t why = 3; |
99 | - ang_sort(player_ptr, who, &why, n, ang_sort_art_comp, ang_sort_art_swap); | |
100 | - for (ARTIFACT_IDX k = 0; k < n; k++) { | |
101 | - artifact_type *a_ptr = &a_info[who[k]]; | |
97 | + ang_sort(player_ptr, whats.data(), &why, whats.size(), ang_sort_art_comp, ang_sort_art_swap); | |
98 | + for (auto a_idx : whats) { | |
99 | + artifact_type *a_ptr = &a_info[a_idx]; | |
102 | 100 | GAME_TEXT base_name[MAX_NLEN]; |
103 | 101 | strcpy(base_name, _("未知の伝説のアイテム", "Unknown Artifact")); |
104 | 102 | ARTIFACT_IDX z = lookup_kind(a_ptr->tval, a_ptr->sval); |
@@ -107,7 +105,7 @@ void do_cmd_knowledge_artifacts(player_type *player_ptr) | ||
107 | 105 | object_type *q_ptr; |
108 | 106 | q_ptr = &forge; |
109 | 107 | q_ptr->prep(z); |
110 | - q_ptr->name1 = who[k]; | |
108 | + q_ptr->name1 = a_idx; | |
111 | 109 | q_ptr->ident |= IDENT_STORE; |
112 | 110 | describe_flavor(player_ptr, base_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); |
113 | 111 | } |
@@ -115,8 +113,6 @@ void do_cmd_knowledge_artifacts(player_type *player_ptr) | ||
115 | 113 | fprintf(fff, _(" %s\n", " The %s\n"), base_name); |
116 | 114 | } |
117 | 115 | |
118 | - C_KILL(who, max_a_idx, ARTIFACT_IDX); | |
119 | - C_KILL(okay, max_a_idx, bool); | |
120 | 116 | angband_fclose(fff); |
121 | 117 | (void)show_file(player_ptr, true, file_name, _("既知の伝説のアイテム", "Artifacts Seen"), 0, 0); |
122 | 118 | fd_kill(file_name); |
@@ -245,7 +241,6 @@ void do_cmd_knowledge_objects(player_type *player_ptr, bool *need_redraw, bool v | ||
245 | 241 | KIND_OBJECT_IDX object_old, object_top; |
246 | 242 | KIND_OBJECT_IDX grp_idx[100]; |
247 | 243 | int object_cnt; |
248 | - OBJECT_IDX *object_idx; | |
249 | 244 | |
250 | 245 | bool visual_list = false; |
251 | 246 | TERM_COLOR attr_top = 0; |
@@ -256,7 +251,7 @@ void do_cmd_knowledge_objects(player_type *player_ptr, bool *need_redraw, bool v | ||
256 | 251 | term_get_size(&wid, &hgt); |
257 | 252 | |
258 | 253 | int browser_rows = hgt - 8; |
259 | - C_MAKE(object_idx, max_k_idx, KIND_OBJECT_IDX); | |
254 | + std::vector<KIND_OBJECT_IDX> object_idx(k_info.size()); | |
260 | 255 | |
261 | 256 | int len; |
262 | 257 | int max = 0; |
@@ -268,7 +263,7 @@ void do_cmd_knowledge_objects(player_type *player_ptr, bool *need_redraw, bool v | ||
268 | 263 | if (len > max) |
269 | 264 | max = len; |
270 | 265 | |
271 | - if (collect_objects(i, object_idx, mode)) { | |
266 | + if (collect_objects(i, object_idx.data(), mode)) { | |
272 | 267 | grp_idx[grp_cnt++] = i; |
273 | 268 | } |
274 | 269 | } |
@@ -348,7 +343,7 @@ void do_cmd_knowledge_objects(player_type *player_ptr, bool *need_redraw, bool v | ||
348 | 343 | display_group_list(0, 6, max, browser_rows, grp_idx, object_group_text, grp_cur, grp_top); |
349 | 344 | if (old_grp_cur != grp_cur) { |
350 | 345 | old_grp_cur = grp_cur; |
351 | - object_cnt = collect_objects(grp_idx[grp_cur], object_idx, mode); | |
346 | + object_cnt = collect_objects(grp_idx[grp_cur], object_idx.data(), mode); | |
352 | 347 | } |
353 | 348 | |
354 | 349 | while (object_cur < object_top) |
@@ -358,10 +353,10 @@ void do_cmd_knowledge_objects(player_type *player_ptr, bool *need_redraw, bool v | ||
358 | 353 | } |
359 | 354 | |
360 | 355 | if (!visual_list) { |
361 | - display_object_list(max + 3, 6, browser_rows, object_idx, object_cur, object_top, visual_only); | |
356 | + display_object_list(max + 3, 6, browser_rows, object_idx.data(), object_cur, object_top, visual_only); | |
362 | 357 | } else { |
363 | 358 | object_top = object_cur; |
364 | - display_object_list(max + 3, 6, 1, object_idx, object_cur, object_top, visual_only); | |
359 | + display_object_list(max + 3, 6, 1, object_idx.data(), object_cur, object_top, visual_only); | |
365 | 360 | display_visual_list(max + 3, 7, browser_rows - 1, wid - (max + 3), attr_top, char_left); |
366 | 361 | } |
367 | 362 |
@@ -438,6 +433,4 @@ void do_cmd_knowledge_objects(player_type *player_ptr, bool *need_redraw, bool v | ||
438 | 433 | } |
439 | 434 | } |
440 | 435 | } |
441 | - | |
442 | - C_KILL(object_idx, max_k_idx, KIND_OBJECT_IDX); | |
443 | 436 | } |
@@ -289,8 +289,7 @@ void do_cmd_knowledge_monsters(player_type *player_ptr, bool *need_redraw, bool | ||
289 | 289 | { |
290 | 290 | TERM_LEN wid, hgt; |
291 | 291 | term_get_size(&wid, &hgt); |
292 | - IDX *mon_idx; | |
293 | - C_MAKE(mon_idx, max_r_idx, MONRACE_IDX); | |
292 | + std::vector<MONRACE_IDX> mon_idx(r_info.size()); | |
294 | 293 | |
295 | 294 | int max = 0; |
296 | 295 | IDX grp_cnt = 0; |
@@ -309,7 +308,7 @@ void do_cmd_knowledge_monsters(player_type *player_ptr, bool *need_redraw, bool | ||
309 | 308 | if (len > max) |
310 | 309 | max = len; |
311 | 310 | |
312 | - if ((monster_group_char[i] == ((char *)-1L)) || collect_monsters(player_ptr, i, mon_idx, mode)) { | |
311 | + if ((monster_group_char[i] == ((char *)-1L)) || collect_monsters(player_ptr, i, mon_idx.data(), mode)) { | |
313 | 312 | grp_idx[grp_cnt++] = i; |
314 | 313 | } |
315 | 314 | } |
@@ -369,7 +368,7 @@ void do_cmd_knowledge_monsters(player_type *player_ptr, bool *need_redraw, bool | ||
369 | 368 | display_group_list(0, 6, max, browser_rows, grp_idx, monster_group_text, grp_cur, grp_top); |
370 | 369 | if (old_grp_cur != grp_cur) { |
371 | 370 | old_grp_cur = grp_cur; |
372 | - mon_cnt = collect_monsters(player_ptr, grp_idx[grp_cur], mon_idx, mode); | |
371 | + mon_cnt = collect_monsters(player_ptr, grp_idx[grp_cur], mon_idx.data(), mode); | |
373 | 372 | } |
374 | 373 | |
375 | 374 | while (mon_cur < mon_top) |
@@ -379,10 +378,10 @@ void do_cmd_knowledge_monsters(player_type *player_ptr, bool *need_redraw, bool | ||
379 | 378 | } |
380 | 379 | |
381 | 380 | if (!visual_list) { |
382 | - display_monster_list(max + 3, 6, browser_rows, mon_idx, mon_cur, mon_top, visual_only); | |
381 | + display_monster_list(max + 3, 6, browser_rows, mon_idx.data(), mon_cur, mon_top, visual_only); | |
383 | 382 | } else { |
384 | 383 | mon_top = mon_cur; |
385 | - display_monster_list(max + 3, 6, 1, mon_idx, mon_cur, mon_top, visual_only); | |
384 | + display_monster_list(max + 3, 6, 1, mon_idx.data(), mon_cur, mon_top, visual_only); | |
386 | 385 | display_visual_list(max + 3, 7, browser_rows - 1, wid - (max + 3), attr_top, char_left); |
387 | 386 | } |
388 | 387 |
@@ -456,8 +455,6 @@ void do_cmd_knowledge_monsters(player_type *player_ptr, bool *need_redraw, bool | ||
456 | 455 | } |
457 | 456 | } |
458 | 457 | } |
459 | - | |
460 | - C_KILL(mon_idx, max_r_idx, MONRACE_IDX); | |
461 | 458 | } |
462 | 459 | |
463 | 460 | /* |
@@ -25,6 +25,8 @@ | ||
25 | 25 | #include "util/sort.h" |
26 | 26 | #include "world/world.h" |
27 | 27 | |
28 | +#include <numeric> | |
29 | + | |
28 | 30 | /*! |
29 | 31 | * @brief Check on the status of an active quest |
30 | 32 | * @param player_ptr プレイヤーへの参照ポインタ |
@@ -292,20 +294,17 @@ void do_cmd_knowledge_quests(player_type *player_ptr) | ||
292 | 294 | if (!open_temporary_file(&fff, file_name)) |
293 | 295 | return; |
294 | 296 | |
295 | - IDX *quest_num; | |
296 | - C_MAKE(quest_num, max_q_idx, QUEST_IDX); | |
297 | - | |
298 | - for (IDX i = 1; i < max_q_idx; i++) | |
299 | - quest_num[i] = i; | |
297 | + std::vector<QUEST_IDX> quest_num(max_q_idx); | |
298 | + std::iota(quest_num.begin(), quest_num.end(), static_cast<QUEST_IDX>(0)); | |
300 | 299 | |
301 | 300 | int dummy; |
302 | - ang_sort(player_ptr, quest_num, &dummy, max_q_idx, ang_sort_comp_quest_num, ang_sort_swap_quest_num); | |
301 | + ang_sort(player_ptr, quest_num.data(), &dummy, quest_num.size(), ang_sort_comp_quest_num, ang_sort_swap_quest_num); | |
303 | 302 | |
304 | 303 | do_cmd_knowledge_quests_current(player_ptr, fff); |
305 | 304 | fputc('\n', fff); |
306 | - do_cmd_knowledge_quests_completed(player_ptr, fff, quest_num); | |
305 | + do_cmd_knowledge_quests_completed(player_ptr, fff, quest_num.data()); | |
307 | 306 | fputc('\n', fff); |
308 | - do_cmd_knowledge_quests_failed(player_ptr, fff, quest_num); | |
307 | + do_cmd_knowledge_quests_failed(player_ptr, fff, quest_num.data()); | |
309 | 308 | if (w_ptr->wizard) { |
310 | 309 | fputc('\n', fff); |
311 | 310 | do_cmd_knowledge_quests_wiz_random(fff); |
@@ -314,5 +313,4 @@ void do_cmd_knowledge_quests(player_type *player_ptr) | ||
314 | 313 | angband_fclose(fff); |
315 | 314 | (void)show_file(player_ptr, true, file_name, _("クエスト達成状況", "Quest status"), 0, 0); |
316 | 315 | fd_kill(file_name); |
317 | - C_KILL(quest_num, max_q_idx, QUEST_IDX); | |
318 | 316 | } |
@@ -18,13 +18,12 @@ | ||
18 | 18 | typedef struct unique_list_type { |
19 | 19 | bool is_alive; |
20 | 20 | uint16_t why; |
21 | - IDX *who; | |
21 | + std::vector<MONRACE_IDX> who; | |
22 | 22 | int num_uniques[10]; |
23 | 23 | int num_uniques_surface; |
24 | 24 | int num_uniques_over100; |
25 | 25 | int num_uniques_total; |
26 | 26 | int max_lev; |
27 | - int n; | |
28 | 27 | } unique_list_type; |
29 | 28 | |
30 | 29 | unique_list_type *initialize_unique_lsit_type(unique_list_type *unique_list_ptr, bool is_alive) |
@@ -35,7 +34,6 @@ unique_list_type *initialize_unique_lsit_type(unique_list_type *unique_list_ptr, | ||
35 | 34 | unique_list_ptr->num_uniques_over100 = 0; |
36 | 35 | unique_list_ptr->num_uniques_total = 0; |
37 | 36 | unique_list_ptr->max_lev = -1; |
38 | - unique_list_ptr->n = 0; | |
39 | 37 | for (IDX i = 0; i < 10; i++) |
40 | 38 | unique_list_ptr->num_uniques[i] = 0; |
41 | 39 |
@@ -111,8 +109,8 @@ static void display_uniques(unique_list_type *unique_list_ptr, FILE *fff) | ||
111 | 109 | } |
112 | 110 | |
113 | 111 | char buf[80]; |
114 | - for (int k = 0; k < unique_list_ptr->n; k++) { | |
115 | - monster_race *r_ptr = &r_info[unique_list_ptr->who[k]]; | |
112 | + for (auto r_idx : unique_list_ptr->who) { | |
113 | + monster_race *r_ptr = &r_info[r_idx]; | |
116 | 114 | |
117 | 115 | if (r_ptr->defeat_level && r_ptr->defeat_time) |
118 | 116 | sprintf(buf, _(" - レベル%2d - %d:%02d:%02d", " - level %2d - %d:%02d:%02d"), r_ptr->defeat_level, r_ptr->defeat_time / (60 * 60), |
@@ -138,7 +136,6 @@ void do_cmd_knowledge_uniques(player_type *player_ptr, bool is_alive) | ||
138 | 136 | if (!open_temporary_file(&fff, file_name)) |
139 | 137 | return; |
140 | 138 | |
141 | - C_MAKE(unique_list_ptr->who, max_r_idx, MONRACE_IDX); | |
142 | 139 | for (auto &r_ref : r_info) { |
143 | 140 | if (r_ref.idx == 0) { |
144 | 141 | continue; |
@@ -157,12 +154,11 @@ void do_cmd_knowledge_uniques(player_type *player_ptr, bool is_alive) | ||
157 | 154 | } else |
158 | 155 | unique_list_ptr->num_uniques_surface++; |
159 | 156 | |
160 | - unique_list_ptr->who[unique_list_ptr->n++] = r_ref.idx; | |
157 | + unique_list_ptr->who.push_back(r_ref.idx); | |
161 | 158 | } |
162 | 159 | |
163 | - ang_sort(player_ptr, unique_list_ptr->who, &unique_list_ptr->why, unique_list_ptr->n, ang_sort_comp_hook, ang_sort_swap_hook); | |
160 | + ang_sort(player_ptr, unique_list_ptr->who.data(), &unique_list_ptr->why, unique_list_ptr->who.size(), ang_sort_comp_hook, ang_sort_swap_hook); | |
164 | 161 | display_uniques(unique_list_ptr, fff); |
165 | - C_KILL(unique_list_ptr->who, max_r_idx, int16_t); | |
166 | 162 | angband_fclose(fff); |
167 | 163 | concptr title_desc |
168 | 164 | = unique_list_ptr->is_alive ? _("まだ生きているユニーク・モンスター", "Alive Uniques") : _("もう撃破したユニーク・モンスター", "Dead Uniques"); |
@@ -44,7 +44,6 @@ | ||
44 | 44 | */ |
45 | 45 | errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr) |
46 | 46 | { |
47 | - grid_template_type *templates; | |
48 | 47 | floor_type *floor_ptr = player_ptr->current_floor_ptr; |
49 | 48 | clear_cave(player_ptr); |
50 | 49 | player_ptr->x = player_ptr->y = 0; |
@@ -111,24 +110,23 @@ errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr) | ||
111 | 110 | |
112 | 111 | uint16_t limit; |
113 | 112 | rd_u16b(&limit); |
114 | - C_MAKE(templates, limit, grid_template_type); | |
113 | + std::vector<grid_template_type> templates(limit); | |
115 | 114 | |
116 | - for (int i = 0; i < limit; i++) { | |
117 | - grid_template_type *ct_ptr = &templates[i]; | |
115 | + for (auto &ct_ref : templates) { | |
118 | 116 | rd_u16b(&tmp16u); |
119 | - ct_ptr->info = (BIT_FLAGS)tmp16u; | |
117 | + ct_ref.info = (BIT_FLAGS)tmp16u; | |
120 | 118 | if (h_older_than(1, 7, 0, 2)) { |
121 | 119 | byte tmp8u; |
122 | 120 | rd_byte(&tmp8u); |
123 | - ct_ptr->feat = (int16_t)tmp8u; | |
121 | + ct_ref.feat = (int16_t)tmp8u; | |
124 | 122 | rd_byte(&tmp8u); |
125 | - ct_ptr->mimic = (int16_t)tmp8u; | |
123 | + ct_ref.mimic = (int16_t)tmp8u; | |
126 | 124 | } else { |
127 | - rd_s16b(&ct_ptr->feat); | |
128 | - rd_s16b(&ct_ptr->mimic); | |
125 | + rd_s16b(&ct_ref.feat); | |
126 | + rd_s16b(&ct_ref.mimic); | |
129 | 127 | } |
130 | 128 | |
131 | - rd_s16b(&ct_ptr->special); | |
129 | + rd_s16b(&ct_ref.special); | |
132 | 130 | } |
133 | 131 | |
134 | 132 | POSITION ymax = floor_ptr->height; |
@@ -180,7 +178,6 @@ errr rd_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr) | ||
180 | 178 | } |
181 | 179 | } |
182 | 180 | |
183 | - C_KILL(templates, limit, grid_template_type); | |
184 | 181 | rd_u16b(&limit); |
185 | 182 | if (limit > w_ptr->max_o_idx) |
186 | 183 | return 151; |
@@ -240,12 +240,10 @@ static errr exe_reading_savefile(player_type *player_ptr) | ||
240 | 240 | rd_u16b(&player_ptr->pet_extra_flags); |
241 | 241 | |
242 | 242 | if (!h_older_than(1, 0, 9)) { |
243 | - char *buf; | |
244 | - C_MAKE(buf, SCREEN_BUF_MAX_SIZE, char); | |
245 | - rd_string(buf, SCREEN_BUF_MAX_SIZE); | |
243 | + std::vector<char> buf(SCREEN_BUF_MAX_SIZE); | |
244 | + rd_string(buf.data(), SCREEN_BUF_MAX_SIZE); | |
246 | 245 | if (buf[0]) |
247 | - screen_dump = string_make(buf); | |
248 | - C_KILL(buf, SCREEN_BUF_MAX_SIZE, char); | |
246 | + screen_dump = string_make(buf.data()); | |
249 | 247 | } |
250 | 248 | |
251 | 249 | errr restore_dungeon_result = restore_dungeon(player_ptr); |
@@ -164,11 +164,10 @@ void sjis2euc(char *str) | ||
164 | 164 | { |
165 | 165 | int i; |
166 | 166 | unsigned char c1, c2; |
167 | - unsigned char *tmp; | |
168 | 167 | |
169 | 168 | int len = strlen(str); |
170 | 169 | |
171 | - C_MAKE(tmp, len + 1, byte); | |
170 | + std::vector<char> tmp(len + 1); | |
172 | 171 | |
173 | 172 | for (i = 0; i < len; i++) { |
174 | 173 | c1 = str[i]; |
@@ -188,9 +187,7 @@ void sjis2euc(char *str) | ||
188 | 187 | tmp[i] = c1; |
189 | 188 | } |
190 | 189 | tmp[len] = 0; |
191 | - strcpy(str, (char *)tmp); | |
192 | - | |
193 | - C_KILL(tmp, len + 1, byte); | |
190 | + strcpy(str, tmp.data()); | |
194 | 191 | } |
195 | 192 | |
196 | 193 | /*! |
@@ -202,11 +199,10 @@ void euc2sjis(char *str) | ||
202 | 199 | { |
203 | 200 | int i; |
204 | 201 | unsigned char c1, c2; |
205 | - unsigned char *tmp; | |
206 | 202 | |
207 | 203 | int len = strlen(str); |
208 | 204 | |
209 | - C_MAKE(tmp, len + 1, byte); | |
205 | + std::vector<char> tmp(len + 1); | |
210 | 206 | |
211 | 207 | for (i = 0; i < len; i++) { |
212 | 208 | c1 = str[i]; |
@@ -227,9 +223,7 @@ void euc2sjis(char *str) | ||
227 | 223 | tmp[i] = c1; |
228 | 224 | } |
229 | 225 | tmp[len] = 0; |
230 | - strcpy(str, (char *)tmp); | |
231 | - | |
232 | - C_KILL(tmp, len + 1, byte); | |
226 | + strcpy(str, tmp.data()); | |
233 | 227 | } |
234 | 228 | |
235 | 229 | /*! |
@@ -481,24 +475,20 @@ static bool utf8_to_sys(char *utf8_str, char *sys_str_buffer, size_t sys_str_buf | ||
481 | 475 | |
482 | 476 | #elif defined(SJIS) && defined(WINDOWS) |
483 | 477 | |
484 | - LPWSTR utf16buf; | |
485 | 478 | int input_len = strlen(utf8_str) + 1; /* include termination character */ |
486 | 479 | |
487 | - C_MAKE(utf16buf, input_len, WCHAR); | |
480 | + std::vector<WCHAR> utf16buf(input_len); | |
488 | 481 | |
489 | 482 | /* UTF-8 -> UTF-16 */ |
490 | - if (MultiByteToWideChar(CP_UTF8, 0, utf8_str, input_len, utf16buf, input_len) == 0) { | |
491 | - C_KILL(utf16buf, input_len, WCHAR); | |
483 | + if (MultiByteToWideChar(CP_UTF8, 0, utf8_str, input_len, utf16buf.data(), input_len) == 0) { | |
492 | 484 | return false; |
493 | 485 | } |
494 | 486 | |
495 | 487 | /* UTF-8 -> SJIS(CP932) */ |
496 | - if (WideCharToMultiByte(932, 0, utf16buf, -1, sys_str_buffer, sys_str_buflen, nullptr, nullptr) == 0) { | |
497 | - C_KILL(utf16buf, input_len, WCHAR); | |
488 | + if (WideCharToMultiByte(932, 0, utf16buf.data(), -1, sys_str_buffer, sys_str_buflen, nullptr, nullptr) == 0) { | |
498 | 489 | return false; |
499 | 490 | } |
500 | 491 | |
501 | - C_KILL(utf16buf, input_len, WCHAR); | |
502 | 492 | return true; |
503 | 493 | |
504 | 494 | #endif |
@@ -517,14 +507,12 @@ void guess_convert_to_system_encoding(char *strbuf, int buflen) | ||
517 | 507 | return; |
518 | 508 | |
519 | 509 | if (is_utf8_str(strbuf)) { |
520 | - char *work; | |
521 | - C_MAKE(work, buflen, char); | |
522 | - angband_strcpy(work, strbuf, buflen); | |
523 | - if (!utf8_to_sys(work, strbuf, buflen)) { | |
510 | + std::vector<char> work(buflen); | |
511 | + angband_strcpy(work.data(), strbuf, buflen); | |
512 | + if (!utf8_to_sys(work.data(), strbuf, buflen)) { | |
524 | 513 | msg_print("警告:文字コードの変換に失敗しました"); |
525 | 514 | msg_print(nullptr); |
526 | 515 | } |
527 | - C_KILL(work, buflen, char); | |
528 | 516 | } |
529 | 517 | } |
530 | 518 |
@@ -159,9 +159,7 @@ errr init_object_alloc(void) | ||
159 | 159 | */ |
160 | 160 | errr init_alloc(void) |
161 | 161 | { |
162 | - monster_race *r_ptr; | |
163 | - tag_type *elements; | |
164 | - C_MAKE(elements, max_r_idx, tag_type); | |
162 | + std::vector<tag_type> elements(r_info.size()); | |
165 | 163 | for (const auto &r_ref : r_info) { |
166 | 164 | if (r_ref.idx > 0) { |
167 | 165 | elements[r_ref.idx].tag = r_ref.level; |
@@ -169,11 +167,11 @@ errr init_alloc(void) | ||
169 | 167 | } |
170 | 168 | } |
171 | 169 | |
172 | - tag_sort(elements, max_r_idx); | |
170 | + tag_sort(elements.data(), elements.size()); | |
173 | 171 | alloc_race_size = max_r_idx; |
174 | 172 | C_MAKE(alloc_race_table, alloc_race_size, alloc_entry); |
175 | 173 | for (int i = 1; i < max_r_idx; i++) { |
176 | - r_ptr = &r_info[elements[i].index]; | |
174 | + auto r_ptr = &r_info[elements[i].index]; | |
177 | 175 | if (r_ptr->rarity == 0) |
178 | 176 | continue; |
179 | 177 |
@@ -185,7 +183,6 @@ errr init_alloc(void) | ||
185 | 183 | alloc_race_table[i].prob2 = (PROB)p; |
186 | 184 | } |
187 | 185 | |
188 | - C_KILL(elements, max_r_idx, tag_type); | |
189 | 186 | (void)init_object_alloc(); |
190 | 187 | return 0; |
191 | 188 | } |
@@ -28,15 +28,12 @@ bool research_mon(player_type *player_ptr) | ||
28 | 28 | bool notpicked; |
29 | 29 | bool recall = false; |
30 | 30 | uint16_t why = 0; |
31 | - MONSTER_IDX *who; | |
32 | 31 | |
33 | 32 | bool all = false; |
34 | 33 | bool uniq = false; |
35 | 34 | bool norm = false; |
36 | 35 | char temp[MAX_MONSTER_NAME] = ""; |
37 | 36 | |
38 | - static int old_sym = '\0'; | |
39 | - static IDX old_i = 0; | |
40 | 37 | screen_save(); |
41 | 38 | |
42 | 39 | char sym; |
@@ -49,9 +46,9 @@ bool research_mon(player_type *player_ptr) | ||
49 | 46 | return false; |
50 | 47 | } |
51 | 48 | |
52 | - IDX i; | |
53 | - for (i = 0; ident_info[i]; ++i) { | |
54 | - if (sym == ident_info[i][0]) | |
49 | + IDX ident_i; | |
50 | + for (ident_i = 0; ident_info[ident_i]; ++ident_i) { | |
51 | + if (sym == ident_info[ident_i][0]) | |
55 | 52 | break; |
56 | 53 | } |
57 | 54 |
@@ -75,8 +72,8 @@ bool research_mon(player_type *player_ptr) | ||
75 | 72 | } |
76 | 73 | |
77 | 74 | sprintf(buf, _("名前:%sにマッチ", "Monsters' names with \"%s\""), temp); |
78 | - } else if (ident_info[i]) { | |
79 | - sprintf(buf, "%c - %s.", sym, ident_info[i] + 2); | |
75 | + } else if (ident_info[ident_i]) { | |
76 | + sprintf(buf, "%c - %s.", sym, ident_info[ident_i] + 2); | |
80 | 77 | } else { |
81 | 78 | sprintf(buf, "%c - %s", sym, _("無効な文字", "Unknown Symbol")); |
82 | 79 | } |
@@ -85,10 +82,9 @@ bool research_mon(player_type *player_ptr) | ||
85 | 82 | prt(buf, 16, 10); |
86 | 83 | |
87 | 84 | /* Allocate the "who" array */ |
88 | - C_MAKE(who, max_r_idx, MONRACE_IDX); | |
85 | + std::vector<MONRACE_IDX> who; | |
89 | 86 | |
90 | 87 | /* Collect matching monsters */ |
91 | - int n = 0; | |
92 | 88 | for (const auto &r_ref : r_info) { |
93 | 89 | /* Empty monster */ |
94 | 90 | if (r_ref.idx == 0 || r_ref.name.empty()) |
@@ -132,14 +128,13 @@ bool research_mon(player_type *player_ptr) | ||
132 | 128 | #else |
133 | 129 | if (angband_strstr(temp2, temp)) |
134 | 130 | #endif |
135 | - who[n++] = i; | |
131 | + who.push_back(r_ref.idx); | |
136 | 132 | } else if (all || (r_ref.d_char == sym)) { |
137 | - who[n++] = i; | |
133 | + who.push_back(r_ref.idx); | |
138 | 134 | } |
139 | 135 | } |
140 | 136 | |
141 | - if (n == 0) { | |
142 | - C_KILL(who, max_r_idx, MONRACE_IDX); | |
137 | + if (who.empty()) { | |
143 | 138 | screen_load(); |
144 | 139 | |
145 | 140 | return false; |
@@ -149,18 +144,20 @@ bool research_mon(player_type *player_ptr) | ||
149 | 144 | char query = 'y'; |
150 | 145 | |
151 | 146 | if (why) { |
152 | - ang_sort(player_ptr, who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook); | |
147 | + ang_sort(player_ptr, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook); | |
153 | 148 | } |
154 | 149 | |
155 | - if (old_sym == sym && old_i < n) | |
150 | + uint i; | |
151 | + static int old_sym = '\0'; | |
152 | + static uint old_i = 0; | |
153 | + if (old_sym == sym && old_i < who.size()) | |
156 | 154 | i = old_i; |
157 | 155 | else |
158 | - i = n - 1; | |
156 | + i = who.size() - 1; | |
159 | 157 | |
160 | 158 | notpicked = true; |
161 | - MONRACE_IDX r_idx; | |
162 | 159 | while (notpicked) { |
163 | - r_idx = who[i]; | |
160 | + auto r_idx = who[i]; | |
164 | 161 | roff_top(r_idx); |
165 | 162 | term_addstr(-1, TERM_WHITE, _(" ['r'思い出, ' 'で続行, ESC]", " [(r)ecall, ESC, space to continue]")); |
166 | 163 | while (true) { |
@@ -185,7 +182,7 @@ bool research_mon(player_type *player_ptr) | ||
185 | 182 | break; |
186 | 183 | |
187 | 184 | if (query == '-') { |
188 | - if (++i == n) { | |
185 | + if (++i == who.size()) { | |
189 | 186 | i = 0; |
190 | 187 | if (!expand_list) |
191 | 188 | break; |
@@ -195,13 +192,12 @@ bool research_mon(player_type *player_ptr) | ||
195 | 192 | } |
196 | 193 | |
197 | 194 | if (i-- == 0) { |
198 | - i = n - 1; | |
195 | + i = who.size() - 1; | |
199 | 196 | if (!expand_list) |
200 | 197 | break; |
201 | 198 | } |
202 | 199 | } |
203 | 200 | |
204 | - C_KILL(who, max_r_idx, MONRACE_IDX); | |
205 | 201 | screen_load(); |
206 | 202 | return !notpicked; |
207 | 203 | } |
@@ -15,23 +15,18 @@ | ||
15 | 15 | |
16 | 16 | #include <algorithm> |
17 | 17 | |
18 | -static ugbldg_type *ugbldg; | |
19 | - | |
20 | 18 | /* |
21 | 19 | * Precalculate buildings' location of underground arcade |
22 | 20 | */ |
23 | -static bool precalc_ugarcade(int town_hgt, int town_wid, int n) | |
21 | +static bool precalc_ugarcade(int town_hgt, int town_wid, int n, std::vector<ugbldg_type>& ugbldg) | |
24 | 22 | { |
25 | 23 | POSITION i, y, x, center_y, center_x; |
26 | 24 | int tmp, attempt = 10000; |
27 | 25 | POSITION max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT; |
28 | 26 | POSITION max_bldg_wid = 5 * town_wid / MAX_TOWN_WID; |
29 | 27 | ugbldg_type *cur_ugbldg; |
30 | - bool **ugarcade_used, abort; | |
31 | - C_MAKE(ugarcade_used, town_hgt, bool *); | |
32 | - C_MAKE(*ugarcade_used, town_hgt * town_wid, bool); | |
33 | - for (y = 1; y < town_hgt; y++) | |
34 | - ugarcade_used[y] = *ugarcade_used + y * town_wid; | |
28 | + std::vector<std::vector<bool>> ugarcade_used(town_hgt, std::vector<bool>(town_wid)); | |
29 | + bool abort; | |
35 | 30 | |
36 | 31 | for (i = 0; i < n; i++) { |
37 | 32 | cur_ugbldg = &ugbldg[i]; |
@@ -69,8 +64,6 @@ static bool precalc_ugarcade(int town_hgt, int town_wid, int n) | ||
69 | 64 | } |
70 | 65 | } |
71 | 66 | |
72 | - C_KILL(*ugarcade_used, town_hgt * town_wid, bool); | |
73 | - C_KILL(ugarcade_used, town_hgt, bool *); | |
74 | 67 | return i == n; |
75 | 68 | } |
76 | 69 |
@@ -106,11 +99,11 @@ static void generate_fill_perm_bold(player_type *player_ptr, POSITION y1, POSITI | ||
106 | 99 | * @note |
107 | 100 | * Note: ltcy and ltcx indicate "left top corner". |
108 | 101 | */ |
109 | -static void build_stores(player_type *player_ptr, POSITION ltcy, POSITION ltcx, int stores[], int n) | |
102 | +static void build_stores(player_type *player_ptr, POSITION ltcy, POSITION ltcx, int stores[], int n, const std::vector<ugbldg_type>& ugbldg) | |
110 | 103 | { |
111 | 104 | int i; |
112 | 105 | POSITION y, x; |
113 | - ugbldg_type *cur_ugbldg; | |
106 | + const ugbldg_type *cur_ugbldg; | |
114 | 107 | |
115 | 108 | for (i = 0; i < n; i++) { |
116 | 109 | cur_ugbldg = &ugbldg[i]; |
@@ -192,22 +185,19 @@ bool build_type16(player_type *player_ptr, dun_data_type *dd_ptr) | ||
192 | 185 | if (!n) |
193 | 186 | return false; |
194 | 187 | |
195 | - C_MAKE(ugbldg, n, ugbldg_type); | |
196 | - if (!precalc_ugarcade(town_hgt, town_wid, n)) { | |
197 | - C_KILL(ugbldg, n, ugbldg_type); | |
188 | + std::vector<ugbldg_type> ugbldg(n); | |
189 | + if (!precalc_ugarcade(town_hgt, town_wid, n, ugbldg)) { | |
198 | 190 | return false; |
199 | 191 | } |
200 | 192 | |
201 | 193 | if (!find_space(player_ptr, dd_ptr, &yval, &xval, town_hgt + 4, town_wid + 4)) { |
202 | - C_KILL(ugbldg, n, ugbldg_type); | |
203 | 194 | return false; |
204 | 195 | } |
205 | 196 | |
206 | 197 | y1 = yval - (town_hgt / 2); |
207 | 198 | x1 = xval - (town_wid / 2); |
208 | 199 | generate_room_floor(player_ptr, y1 + town_hgt / 3, x1 + town_wid / 3, y1 + town_hgt * 2 / 3, x1 + town_wid * 2 / 3, false); |
209 | - build_stores(player_ptr, y1, x1, stores, n); | |
200 | + build_stores(player_ptr, y1, x1, stores, n, ugbldg); | |
210 | 201 | msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("地下街を生成しました", "Underground arcade was generated.")); |
211 | - C_KILL(ugbldg, n, ugbldg_type); | |
212 | 202 | return true; |
213 | 203 | } |
@@ -130,11 +130,8 @@ void build_maze_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITIO | ||
130 | 130 | int n = dy + 1; |
131 | 131 | int num_vertices = m * n; |
132 | 132 | |
133 | - int *visited; | |
134 | - C_MAKE(visited, num_vertices, int); | |
135 | - r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited); | |
133 | + std::vector<int> visited(num_vertices); | |
134 | + r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited.data()); | |
136 | 135 | if (is_vault) |
137 | 136 | fill_treasure(player_ptr, x1, x2, y1, y2, randint1(5)); |
138 | - | |
139 | - C_KILL(visited, num_vertices, int); | |
140 | 137 | } |
@@ -938,7 +938,6 @@ static void build_mini_c_vault(player_type *player_ptr, POSITION x0, POSITION y0 | ||
938 | 938 | POSITION dy, dx; |
939 | 939 | POSITION y1, x1, y2, x2, y, x, total; |
940 | 940 | int m, n, num_vertices; |
941 | - int *visited; | |
942 | 941 | |
943 | 942 | msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault.")); |
944 | 943 |
@@ -1006,10 +1005,10 @@ static void build_mini_c_vault(player_type *player_ptr, POSITION x0, POSITION y0 | ||
1006 | 1005 | num_vertices = m * n; |
1007 | 1006 | |
1008 | 1007 | /* initialize array of visited vertices */ |
1009 | - C_MAKE(visited, num_vertices, int); | |
1008 | + std::vector<int> visited(num_vertices); | |
1010 | 1009 | |
1011 | 1010 | /* traverse the graph to create a spannng tree, pick a random root */ |
1012 | - r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited); | |
1011 | + r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited.data()); | |
1013 | 1012 | |
1014 | 1013 | /* Make it look like a checker board vault */ |
1015 | 1014 | for (x = x1; x <= x2; x++) { |
@@ -1037,8 +1036,6 @@ static void build_mini_c_vault(player_type *player_ptr, POSITION x0, POSITION y0 | ||
1037 | 1036 | |
1038 | 1037 | /* Fill with monsters and treasure, highest difficulty */ |
1039 | 1038 | fill_treasure(player_ptr, x1, x2, y1, y2, 10); |
1040 | - | |
1041 | - C_KILL(visited, num_vertices, int); | |
1042 | 1039 | } |
1043 | 1040 | |
1044 | 1041 | /* Build a castle */ |
@@ -57,17 +57,12 @@ void wr_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr) | ||
57 | 57 | * 515 will be "0xff" "0xff" "0x03" |
58 | 58 | */ |
59 | 59 | |
60 | - /* Fake max number */ | |
61 | - uint16_t max_num_temp = 255; | |
62 | - | |
63 | - grid_template_type *templates; | |
64 | - C_MAKE(templates, max_num_temp, grid_template_type); | |
65 | - uint16_t num_temp = 0; | |
60 | + std::vector<grid_template_type> templates; | |
66 | 61 | for (int y = 0; y < floor_ptr->height; y++) { |
67 | 62 | for (int x = 0; x < floor_ptr->width; x++) { |
68 | 63 | grid_type *g_ptr = &floor_ptr->grid_array[y][x]; |
69 | - int i; | |
70 | - for (i = 0; i < num_temp; i++) { | |
64 | + uint i; | |
65 | + for (i = 0; i < templates.size(); i++) { | |
71 | 66 | if (templates[i].info == g_ptr->info && templates[i].feat == g_ptr->feat && templates[i].mimic == g_ptr->mimic |
72 | 67 | && templates[i].special == g_ptr->special) { |
73 | 68 | templates[i].occurrence++; |
@@ -75,37 +70,23 @@ void wr_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr) | ||
75 | 70 | } |
76 | 71 | } |
77 | 72 | |
78 | - if (i < num_temp) | |
73 | + if (i < templates.size()) | |
79 | 74 | continue; |
80 | 75 | |
81 | - if (num_temp >= max_num_temp) { | |
82 | - grid_template_type *old_template = templates; | |
83 | - C_MAKE(templates, max_num_temp + 255, grid_template_type); | |
84 | - (void)C_COPY(templates, old_template, max_num_temp, grid_template_type); | |
85 | - C_KILL(old_template, max_num_temp, grid_template_type); | |
86 | - max_num_temp += 255; | |
87 | - } | |
88 | - | |
89 | - templates[num_temp].info = g_ptr->info; | |
90 | - templates[num_temp].feat = g_ptr->feat; | |
91 | - templates[num_temp].mimic = g_ptr->mimic; | |
92 | - templates[num_temp].special = g_ptr->special; | |
93 | - templates[num_temp].occurrence = 1; | |
94 | - num_temp++; | |
76 | + templates.push_back({g_ptr->info, g_ptr->feat, g_ptr->mimic, g_ptr->special, 1}); | |
95 | 77 | } |
96 | 78 | } |
97 | 79 | |
98 | 80 | int dummy_why; |
99 | - ang_sort(player_ptr, templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp); | |
81 | + ang_sort(player_ptr, templates.data(), &dummy_why, templates.size(), ang_sort_comp_cave_temp, ang_sort_swap_cave_temp); | |
100 | 82 | |
101 | 83 | /*** Dump templates ***/ |
102 | - wr_u16b(num_temp); | |
103 | - for (int i = 0; i < num_temp; i++) { | |
104 | - grid_template_type *ct_ptr = &templates[i]; | |
105 | - wr_u16b((uint16_t)ct_ptr->info); | |
106 | - wr_s16b(ct_ptr->feat); | |
107 | - wr_s16b(ct_ptr->mimic); | |
108 | - wr_s16b(ct_ptr->special); | |
84 | + wr_u16b(static_cast<uint16_t>(templates.size())); | |
85 | + for (const auto &ct_ref : templates) { | |
86 | + wr_u16b(static_cast<uint16_t>(ct_ref.info)); | |
87 | + wr_s16b(ct_ref.feat); | |
88 | + wr_s16b(ct_ref.mimic); | |
89 | + wr_s16b(ct_ref.special); | |
109 | 90 | } |
110 | 91 | |
111 | 92 | byte count = 0; |
@@ -113,8 +94,8 @@ void wr_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr) | ||
113 | 94 | for (int y = 0; y < floor_ptr->height; y++) { |
114 | 95 | for (int x = 0; x < floor_ptr->width; x++) { |
115 | 96 | grid_type *g_ptr = &floor_ptr->grid_array[y][x]; |
116 | - int i; | |
117 | - for (i = 0; i < num_temp; i++) { | |
97 | + uint i; | |
98 | + for (i = 0; i < templates.size(); i++) { | |
118 | 99 | if (templates[i].info == g_ptr->info && templates[i].feat == g_ptr->feat && templates[i].mimic == g_ptr->mimic |
119 | 100 | && templates[i].special == g_ptr->special) |
120 | 101 | break; |
@@ -148,8 +129,6 @@ void wr_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr) | ||
148 | 129 | wr_byte((byte)prev_u16b); |
149 | 130 | } |
150 | 131 | |
151 | - C_KILL(templates, max_num_temp, grid_template_type); | |
152 | - | |
153 | 132 | /*** Dump objects ***/ |
154 | 133 | wr_u16b(floor_ptr->o_max); |
155 | 134 | for (int i = 1; i < floor_ptr->o_max; i++) { |
@@ -648,38 +648,30 @@ uint vstrnfmt(char *buf, uint max, concptr fmt, va_list vp) | ||
648 | 648 | */ |
649 | 649 | char *vformat(concptr fmt, va_list vp) |
650 | 650 | { |
651 | - static char *format_buf = nullptr; | |
652 | - static ulong format_len = 0; | |
653 | - | |
654 | 651 | /* Initial allocation */ |
655 | - if (!format_buf) { | |
656 | - format_len = 1024; | |
657 | - C_MAKE(format_buf, format_len, char); | |
658 | - } | |
652 | + static std::vector<char> format_buf(1024); | |
659 | 653 | |
660 | 654 | /* Null format yields last result */ |
661 | 655 | if (!fmt) |
662 | - return (format_buf); | |
656 | + return format_buf.data(); | |
663 | 657 | |
664 | 658 | /* Keep going until successful */ |
665 | 659 | while (true) { |
666 | 660 | uint len; |
667 | 661 | |
668 | 662 | /* Build the string */ |
669 | - len = vstrnfmt(format_buf, format_len, fmt, vp); | |
663 | + len = vstrnfmt(format_buf.data(), format_buf.size(), fmt, vp); | |
670 | 664 | |
671 | 665 | /* Success */ |
672 | - if (len < format_len - 1) | |
666 | + if (len < format_buf.size() - 1) | |
673 | 667 | break; |
674 | 668 | |
675 | 669 | /* Grow the buffer */ |
676 | - C_KILL(format_buf, format_len, char); | |
677 | - format_len = format_len * 2; | |
678 | - C_MAKE(format_buf, format_len, char); | |
670 | + format_buf.resize(format_buf.size() * 2); | |
679 | 671 | } |
680 | 672 | |
681 | 673 | /* Return the new buffer */ |
682 | - return (format_buf); | |
674 | + return format_buf.data(); | |
683 | 675 | } |
684 | 676 | |
685 | 677 | /* |
@@ -76,7 +76,6 @@ spoiler_output_status spoil_mon_desc(concptr fname, std::function<bool(const mon | ||
76 | 76 | { |
77 | 77 | player_type dummy; |
78 | 78 | uint16_t why = 2; |
79 | - MONRACE_IDX *who; | |
80 | 79 | char buf[1024]; |
81 | 80 | char nam[MAX_MONSTER_NAME + 10]; // ユニークには[U] が付くので少し伸ばす |
82 | 81 | char lev[80]; |
@@ -94,7 +93,6 @@ spoiler_output_status spoil_mon_desc(concptr fname, std::function<bool(const mon | ||
94 | 93 | char title[200]; |
95 | 94 | put_version(title); |
96 | 95 | |
97 | - C_MAKE(who, max_r_idx, MONRACE_IDX); | |
98 | 96 | fprintf(spoiler_file, "Monster Spoilers for %s\n", title); |
99 | 97 | fprintf(spoiler_file, "------------------------------------------\n\n"); |
100 | 98 | fprintf(spoiler_file, "%-45.45s%4s %4s %4s %7s %7s %19.19s\n", "Name", "Lev", "Rar", "Spd", "Hp", "Ac", "Visual Info"); |
@@ -104,15 +102,15 @@ spoiler_output_status spoil_mon_desc(concptr fname, std::function<bool(const mon | ||
104 | 102 | "----------", |
105 | 103 | "---", "---", "---", "-----", "-----", "-------------------"); |
106 | 104 | |
107 | - int n = 0; | |
105 | + std::vector<MONRACE_IDX> who; | |
108 | 106 | for (const auto &r_ref : r_info) { |
109 | 107 | if (r_ref.idx > 0 && !r_ref.name.empty()) |
110 | - who[n++] = r_ref.idx; | |
108 | + who.push_back(r_ref.idx); | |
111 | 109 | } |
112 | 110 | |
113 | - ang_sort(&dummy, who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook); | |
114 | - for (auto i = 0; i < n; i++) { | |
115 | - monster_race *r_ptr = &r_info[who[i]]; | |
111 | + ang_sort(&dummy, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook); | |
112 | + for (auto r_idx : who) { | |
113 | + monster_race *r_ptr = &r_info[r_idx]; | |
116 | 114 | concptr name = r_ptr->name.c_str(); |
117 | 115 | if (filter_monster && !filter_monster(r_ptr)) { |
118 | 116 | continue; |
@@ -161,7 +159,6 @@ spoiler_output_status spoil_mon_desc(concptr fname, std::function<bool(const mon | ||
161 | 159 | } |
162 | 160 | |
163 | 161 | fprintf(spoiler_file, "\n"); |
164 | - C_KILL(who, max_r_idx, int16_t); | |
165 | 162 | return ferror(spoiler_file) || angband_fclose(spoiler_file) ? spoiler_output_status::SPOILER_OUTPUT_FAIL_FCLOSE |
166 | 163 | : spoiler_output_status::SPOILER_OUTPUT_SUCCESS; |
167 | 164 | } |
@@ -199,18 +196,16 @@ spoiler_output_status spoil_mon_info(concptr fname) | ||
199 | 196 | spoil_out(buf); |
200 | 197 | spoil_out("------------------------------------------\n\n"); |
201 | 198 | |
202 | - MONRACE_IDX *who; | |
203 | - C_MAKE(who, max_r_idx, MONRACE_IDX); | |
204 | - int n = 0; | |
199 | + std::vector<MONRACE_IDX> who; | |
205 | 200 | for (const auto &r_ref : r_info) { |
206 | 201 | if (r_ref.idx > 0 && !r_ref.name.empty()) |
207 | - who[n++] = r_ref.idx; | |
202 | + who.push_back(r_ref.idx); | |
208 | 203 | } |
209 | 204 | |
210 | 205 | uint16_t why = 2; |
211 | - ang_sort(&dummy, who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook); | |
212 | - for (int i = 0; i < n; i++) { | |
213 | - monster_race *r_ptr = &r_info[who[i]]; | |
206 | + ang_sort(&dummy, who.data(), &why, who.size(), ang_sort_comp_hook, ang_sort_swap_hook); | |
207 | + for (auto r_idx : who) { | |
208 | + monster_race *r_ptr = &r_info[r_idx]; | |
214 | 209 | BIT_FLAGS flags1 = r_ptr->flags1; |
215 | 210 | if (any_bits(flags1, RF1_UNIQUE)) { |
216 | 211 | spoil_out("[U] "); |
@@ -225,7 +220,7 @@ spoiler_output_status spoil_mon_info(concptr fname) | ||
225 | 220 | spoil_out(buf); |
226 | 221 | sprintf(buf, "=== "); |
227 | 222 | spoil_out(buf); |
228 | - sprintf(buf, "Num:%d ", who[i]); | |
223 | + sprintf(buf, "Num:%d ", r_idx); | |
229 | 224 | spoil_out(buf); |
230 | 225 | sprintf(buf, "Lev:%d ", (int)r_ptr->level); |
231 | 226 | spoil_out(buf); |
@@ -249,11 +244,10 @@ spoiler_output_status spoil_mon_info(concptr fname) | ||
249 | 244 | spoil_out(buf); |
250 | 245 | sprintf(buf, "Exp:%ld\n", (long)(r_ptr->mexp)); |
251 | 246 | spoil_out(buf); |
252 | - output_monster_spoiler(who[i], roff_func); | |
247 | + output_monster_spoiler(r_idx, roff_func); | |
253 | 248 | spoil_out(nullptr); |
254 | 249 | } |
255 | 250 | |
256 | - C_KILL(who, max_r_idx, int16_t); | |
257 | 251 | return ferror(spoiler_file) || angband_fclose(spoiler_file) ? spoiler_output_status::SPOILER_OUTPUT_FAIL_FCLOSE |
258 | 252 | : spoiler_output_status::SPOILER_OUTPUT_SUCCESS; |
259 | 253 | } |
@@ -596,11 +596,7 @@ void wiz_dump_options(void) | ||
596 | 596 | return; |
597 | 597 | } |
598 | 598 | |
599 | - int **exist; | |
600 | - C_MAKE(exist, NUM_O_SET, int *); | |
601 | - C_MAKE(*exist, NUM_O_BIT * NUM_O_SET, int); | |
602 | - for (int i = 1; i < NUM_O_SET; i++) | |
603 | - exist[i] = *exist + i * NUM_O_BIT; | |
599 | + std::vector<std::vector<int>> exist(NUM_O_SET, std::vector<int>(NUM_O_BIT)); | |
604 | 600 | |
605 | 601 | for (int i = 0; option_info[i].o_desc; i++) { |
606 | 602 | const option_type *ot_ptr = &option_info[i]; |
@@ -626,8 +622,6 @@ void wiz_dump_options(void) | ||
626 | 622 | fputc('\n', fff); |
627 | 623 | } |
628 | 624 | |
629 | - C_KILL(*exist, NUM_O_BIT * NUM_O_SET, int); | |
630 | - C_KILL(exist, NUM_O_SET, int *); | |
631 | 625 | angband_fclose(fff); |
632 | 626 | msg_format(_("オプションbit使用状況をファイル %s に書き出しました。", "Option bits usage dump saved to file %s."), buf); |
633 | 627 | } |