OSDN Git Service

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