OSDN Git Service

0e6bdd3efa58529cdd19516fc54bc3e3e09f2a8b
[hengband/hengband.git] / src / knowledge / knowledge-uniques.c
1 /*!
2  * @brief 既知/存命のユニークを表示する
3  * @date 2020/04/23
4  * @author Hourier
5  */
6
7 #include "system/angband.h"
8 #include "knowledge-items.h"
9 #include "cmd/dump-util.h"
10 #include "sort.h"
11 #include "core/show-file.h"
12
13 /*
14  * Display known uniques
15  * With "XTRA HACK UNIQHIST" (Originally from XAngband)
16  */
17 void do_cmd_knowledge_uniques(player_type *creature_ptr)
18 {
19         u16b why = 2;
20         IDX *who;
21         int n_alive[10];
22         int n_alive_surface = 0;
23         int n_alive_over100 = 0;
24         int n_alive_total = 0;
25         int max_lev = -1;
26         for (IDX i = 0; i < 10; i++)
27                 n_alive[i] = 0;
28
29         FILE *fff = NULL;
30         GAME_TEXT file_name[FILE_NAME_SIZE];
31         if (!open_temporary_file(&fff, file_name)) return;
32
33         C_MAKE(who, max_r_idx, MONRACE_IDX);
34         int n = 0;
35         for (IDX i = 1; i < max_r_idx; i++)
36         {
37                 monster_race *r_ptr = &r_info[i];
38                 if (!r_ptr->name) continue;
39                 if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
40                 if (!cheat_know && !r_ptr->r_sights) continue;
41                 if (!r_ptr->rarity || ((r_ptr->rarity > 100) && !(r_ptr->flags1 & RF1_QUESTOR))) continue;
42                 if (r_ptr->max_num == 0) continue;
43
44                 if (r_ptr->level)
45                 {
46                         int lev = (r_ptr->level - 1) / 10;
47                         if (lev < 10)
48                         {
49                                 n_alive[lev]++;
50                                 if (max_lev < lev) max_lev = lev;
51                         }
52                         else
53                                 n_alive_over100++;
54                 }
55                 else
56                         n_alive_surface++;
57
58                 who[n++] = i;
59         }
60
61         ang_sort(who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook);
62         if (n_alive_surface)
63         {
64                 fprintf(fff, _("     地上  生存: %3d体\n", "      Surface  alive: %3d\n"), n_alive_surface);
65                 n_alive_total += n_alive_surface;
66         }
67
68         for (IDX i = 0; i <= max_lev; i++)
69         {
70                 fprintf(fff, _("%3d-%3d階  生存: %3d体\n", "Level %3d-%3d  alive: %3d\n"), 1 + i * 10, 10 + i * 10, n_alive[i]);
71                 n_alive_total += n_alive[i];
72         }
73
74         if (n_alive_over100)
75         {
76                 fprintf(fff, _("101-   階  生存: %3d体\n", "Level 101-     alive: %3d\n"), n_alive_over100);
77                 n_alive_total += n_alive_over100;
78         }
79
80         if (n_alive_total)
81         {
82                 fputs(_("---------  -----------\n", "-------------  ----------\n"), fff);
83                 fprintf(fff, _("     合計  生存: %3d体\n\n", "        Total  alive: %3d\n\n"), n_alive_total);
84         }
85         else
86         {
87                 fputs(_("現在は既知の生存ユニークはいません。\n", "No known uniques alive.\n"), fff);
88         }
89
90         for (int k = 0; k < n; k++)
91         {
92                 monster_race *r_ptr = &r_info[who[k]];
93                 fprintf(fff, _("     %s (レベル%d)\n", "     %s (level %d)\n"), r_name + r_ptr->name, (int)r_ptr->level);
94         }
95
96         C_KILL(who, max_r_idx, s16b);
97         my_fclose(fff);
98         (void)show_file(creature_ptr, TRUE, file_name, _("まだ生きているユニーク・モンスター", "Alive Uniques"), 0, 0);
99         fd_kill(file_name);
100 }