OSDN Git Service

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