OSDN Git Service

[Refactor] #39970 Moved dungeon*.c/h to dungeon/
[hengband/hengband.git] / src / rumor.c
1 #include "angband.h"
2 #include "util.h"
3
4 #include "io/tokenizer.h"
5 #include "files.h"
6 #include "object-flavor.h"
7 #include "artifact.h"
8 #include "dungeon/dungeon.h"
9 #include "monsterrace.h"
10 #include "floor-town.h"
11 #include "wild.h"
12 #include "world/world.h"
13
14 /*
15  * Display a rumor and apply its effects
16  */
17
18 IDX rumor_num(char *zz, IDX max_idx)
19 {
20         if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
21         return (IDX)atoi(zz);
22 }
23
24 concptr rumor_bind_name(char *base, concptr fullname)
25 {
26         char *s, *v;
27         s = strstr(base, "{Name}");
28         if (s)
29         {
30                 s[0] = '\0';
31                 v = format("%s%s%s", base, fullname, (s + 6));
32                 return v;
33         }
34
35         v = base;
36         return v;
37 }
38
39 void display_rumor(player_type *player_ptr, bool ex)
40 {
41         char rumor[1024];
42         int section = (ex && (randint0(3) == 0)) ? 1 : 0;
43         errr err = _(get_rnd_line_jonly("rumors_j.txt", section, rumor, 10),
44                 get_rnd_line("rumors.txt", section, rumor));
45         if (err) strcpy(rumor, _("嘘の噂もある。", "Some rumors are wrong."));
46
47         if (strncmp(rumor, "R:", 2) != 0)
48         {
49                 msg_format("%s", rumor);
50                 return;
51         }
52
53         char *zz[4];
54         if (tokenize(rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) != 3)
55         {
56                 msg_print(_("この情報は間違っている。", "This information is wrong."));
57                 return;
58         }
59
60         concptr rumor_eff_format = NULL;
61         char fullname[1024] = "";
62         if (strcmp(zz[0], "ARTIFACT") == 0)
63         {
64                 ARTIFACT_IDX a_idx;
65                 artifact_type *a_ptr;
66                 while (TRUE)
67                 {
68                         a_idx = rumor_num(zz[1], max_a_idx);
69
70                         a_ptr = &a_info[a_idx];
71                         if (a_ptr->name) break;
72                 }
73
74                 KIND_OBJECT_IDX k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
75                 object_type forge;
76                 object_type *q_ptr = &forge;
77                 object_prep(q_ptr, k_idx);
78                 q_ptr->name1 = a_idx;
79                 q_ptr->ident = IDENT_STORE;
80                 object_desc(player_ptr, fullname, q_ptr, OD_NAME_ONLY);
81         }
82         else if (strcmp(zz[0], "MONSTER") == 0)
83         {
84                 monster_race *r_ptr;
85                 while (TRUE)
86                 {
87                         MONRACE_IDX r_idx = rumor_num(zz[1], max_r_idx);
88                         r_ptr = &r_info[r_idx];
89                         if (r_ptr->name) break;
90                 }
91
92                 strcpy(fullname, r_name + r_ptr->name);
93
94                 if (!r_ptr->r_sights)
95                 {
96                         r_ptr->r_sights++;
97                 }
98         }
99         else if (strcmp(zz[0], "DUNGEON") == 0)
100         {
101                 DUNGEON_IDX d_idx;
102                 dungeon_type *d_ptr;
103                 while (TRUE)
104                 {
105                         d_idx = rumor_num(zz[1], current_world_ptr->max_d_idx);
106                         d_ptr = &d_info[d_idx];
107                         if (d_ptr->name) break;
108                 }
109
110                 strcpy(fullname, d_name + d_ptr->name);
111
112                 if (!max_dlv[d_idx])
113                 {
114                         max_dlv[d_idx] = d_ptr->mindepth;
115                         rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
116                 }
117         }
118         else if (strcmp(zz[0], "TOWN") == 0)
119         {
120                 IDX t_idx;
121                 while (TRUE)
122                 {
123                         t_idx = rumor_num(zz[1], NO_TOWN);
124                         if (town_info[t_idx].name) break;
125                 }
126
127                 strcpy(fullname, town_info[t_idx].name);
128
129                 s32b visit = (1L << (t_idx - 1));
130                 if ((t_idx != SECRET_TOWN) && !(player_ptr->visit & visit))
131                 {
132                         player_ptr->visit |= visit;
133                         rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
134                 }
135         }
136
137         concptr rumor_msg = rumor_bind_name(zz[2], fullname);
138         msg_print(rumor_msg);
139         if (rumor_eff_format)
140         {
141                 msg_print(NULL);
142                 msg_format(rumor_eff_format, fullname);
143         }
144 }