OSDN Git Service

[Refactor] #1766 Changed ItemPrimaryType from enum to enum class
[hengbandforosx/hengbandosx.git] / src / market / bounty.cpp
1 #include "market/bounty.h"
2 #include "autopick/autopick.h"
3 #include "avatar/avatar.h"
4 #include "cmd-building/cmd-building.h"
5 #include "core/asking-player.h"
6 #include "core/player-redraw-types.h"
7 #include "core/stuff-handler.h"
8 #include "dungeon/dungeon.h"
9 #include "flavor/flavor-describer.h"
10 #include "game-option/cheat-options.h"
11 #include "inventory/inventory-object.h"
12 #include "inventory/inventory-slot-types.h"
13 #include "io/input-key-acceptor.h"
14 #include "market/bounty-prize-table.h"
15 #include "market/building-util.h"
16 #include "monster-race/monster-race-hook.h"
17 #include "monster-race/monster-race.h"
18 #include "monster-race/race-flags1.h"
19 #include "monster-race/race-flags2.h"
20 #include "monster-race/race-flags7.h"
21 #include "monster-race/race-flags9.h"
22 #include "monster-race/race-indice-types.h"
23 #include "monster/monster-list.h"
24 #include "monster/monster-util.h"
25 #include "object-enchant/apply-magic.h"
26 #include "object-enchant/item-apply-magic.h"
27 #include "object/object-info.h"
28 #include "object/object-kind-hook.h"
29 #include "perception/object-perception.h"
30 #include "sv-definition/sv-other-types.h"
31 #include "system/floor-type-definition.h"
32 #include "system/monster-race-definition.h"
33 #include "system/object-type-definition.h"
34 #include "system/player-type-definition.h"
35 #include "term/screen-processor.h"
36 #include "term/term-color-types.h"
37 #include "view/display-messages.h"
38 #include "world/world.h"
39
40 /*!
41  * @brief 賞金首の引き換え処理 / Get prize
42  * @param player_ptr プレイヤーへの参照ポインタ
43  * @return 各種賞金首のいずれかでも換金が行われたか否か。
44  */
45 bool exchange_cash(player_type *player_ptr)
46 {
47     bool change = false;
48     GAME_TEXT o_name[MAX_NLEN];
49     object_type *o_ptr;
50
51     for (INVENTORY_IDX i = 0; i <= INVEN_SUB_HAND; i++) {
52         o_ptr = &player_ptr->inventory_list[i];
53         if ((o_ptr->tval == ItemPrimaryType::TV_CAPTURE) && (o_ptr->pval == MON_TSUCHINOKO)) {
54             char buf[MAX_NLEN + 32];
55             describe_flavor(player_ptr, o_name, o_ptr, 0);
56             sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
57             if (get_check(buf)) {
58                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)(1000000L * o_ptr->number));
59                 player_ptr->au += 1000000L * o_ptr->number;
60                 player_ptr->redraw |= (PR_GOLD);
61                 vary_item(player_ptr, i, -o_ptr->number);
62             }
63
64             change = true;
65         }
66     }
67
68     for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
69         o_ptr = &player_ptr->inventory_list[i];
70         if ((o_ptr->tval == ItemPrimaryType::TV_CORPSE) && (o_ptr->sval == SV_CORPSE) && (o_ptr->pval == MON_TSUCHINOKO)) {
71             char buf[MAX_NLEN + 32];
72             describe_flavor(player_ptr, o_name, o_ptr, 0);
73             sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
74             if (get_check(buf)) {
75                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)(200000L * o_ptr->number));
76                 player_ptr->au += 200000L * o_ptr->number;
77                 player_ptr->redraw |= (PR_GOLD);
78                 vary_item(player_ptr, i, -o_ptr->number);
79             }
80
81             change = true;
82         }
83     }
84
85     for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
86         o_ptr = &player_ptr->inventory_list[i];
87         if ((o_ptr->tval == ItemPrimaryType::TV_CORPSE) && (o_ptr->sval == SV_SKELETON) && (o_ptr->pval == MON_TSUCHINOKO)) {
88             char buf[MAX_NLEN + 32];
89             describe_flavor(player_ptr, o_name, o_ptr, 0);
90             sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
91             if (get_check(buf)) {
92                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)(100000L * o_ptr->number));
93                 player_ptr->au += 100000L * o_ptr->number;
94                 player_ptr->redraw |= (PR_GOLD);
95                 vary_item(player_ptr, i, -o_ptr->number);
96             }
97
98             change = true;
99         }
100     }
101
102     for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
103         o_ptr = &player_ptr->inventory_list[i];
104         if ((o_ptr->tval == ItemPrimaryType::TV_CORPSE) && (o_ptr->sval == SV_CORPSE)
105             && (streq(r_info[o_ptr->pval].name.c_str(), r_info[w_ptr->today_mon].name.c_str()))) {
106             char buf[MAX_NLEN + 32];
107             describe_flavor(player_ptr, o_name, o_ptr, 0);
108             sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
109             if (get_check(buf)) {
110                 msg_format(
111                     _("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)((r_info[w_ptr->today_mon].level * 50 + 100) * o_ptr->number));
112                 player_ptr->au += (r_info[w_ptr->today_mon].level * 50 + 100) * o_ptr->number;
113                 player_ptr->redraw |= (PR_GOLD);
114                 vary_item(player_ptr, i, -o_ptr->number);
115             }
116
117             change = true;
118         }
119     }
120
121     for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
122         o_ptr = &player_ptr->inventory_list[i];
123
124         if ((o_ptr->tval == ItemPrimaryType::TV_CORPSE) && (o_ptr->sval == SV_SKELETON)
125             && (streq(r_info[o_ptr->pval].name.c_str(), r_info[w_ptr->today_mon].name.c_str()))) {
126             char buf[MAX_NLEN + 32];
127             describe_flavor(player_ptr, o_name, o_ptr, 0);
128             sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
129             if (get_check(buf)) {
130                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)((r_info[w_ptr->today_mon].level * 30 + 60) * o_ptr->number));
131                 player_ptr->au += (r_info[w_ptr->today_mon].level * 30 + 60) * o_ptr->number;
132                 player_ptr->redraw |= (PR_GOLD);
133                 vary_item(player_ptr, i, -o_ptr->number);
134             }
135
136             change = true;
137         }
138     }
139
140     for (int j = 0; j < MAX_BOUNTY; j++) {
141         for (INVENTORY_IDX i = INVEN_PACK - 1; i >= 0; i--) {
142             o_ptr = &player_ptr->inventory_list[i];
143             if ((o_ptr->tval != ItemPrimaryType::TV_CORPSE) || (o_ptr->pval != w_ptr->bounty_r_idx[j]))
144                 continue;
145
146             char buf[MAX_NLEN + 20];
147             int num, k;
148             INVENTORY_IDX item_new;
149             object_type forge;
150
151             describe_flavor(player_ptr, o_name, o_ptr, 0);
152             sprintf(buf, _("%sを渡しますか?", "Hand %s over? "), o_name);
153             if (!get_check(buf))
154                 continue;
155
156             vary_item(player_ptr, i, -o_ptr->number);
157             chg_virtue(player_ptr, V_JUSTICE, 5);
158             w_ptr->bounty_r_idx[j] += 10000;
159
160             for (num = 0, k = 0; k < MAX_BOUNTY; k++) {
161                 if (w_ptr->bounty_r_idx[k] >= 10000)
162                     num++;
163             }
164
165             msg_format(_("これで合計 %d ポイント獲得しました。", "You earned %d point%s total."), num, (num > 1 ? "s" : ""));
166
167             (&forge)->prep(lookup_kind(prize_list[num - 1].tval, prize_list[num - 1].sval));
168             apply_magic_to_object(player_ptr, &forge, player_ptr->current_floor_ptr->object_level, AM_NO_FIXED_ART);
169
170             object_aware(player_ptr, &forge);
171             object_known(&forge);
172
173             /*
174              * Hand it --- Assume there is an empty slot.
175              * Since a corpse is handed at first,
176              * there is at least one empty slot.
177              */
178             item_new = store_item_to_inventory(player_ptr, &forge);
179             describe_flavor(player_ptr, o_name, &forge, 0);
180             msg_format(_("%s(%c)を貰った。", "You get %s (%c). "), o_name, index_to_label(item_new));
181
182             autopick_alter_item(player_ptr, item_new, false);
183             handle_stuff(player_ptr);
184             change = true;
185         }
186     }
187
188     if (change)
189         return true;
190
191     msg_print(_("賞金を得られそうなものは持っていなかった。", "You have nothing."));
192     msg_print(nullptr);
193     return false;
194 }
195
196 /*!
197  * @brief 本日の賞金首情報を表示する。
198  * @param player_ptr プレイヤーへの参照ポインタ
199  */
200 void today_target(player_type *player_ptr)
201 {
202     char buf[160];
203     monster_race *r_ptr = &r_info[w_ptr->today_mon];
204
205     clear_bldg(4, 18);
206     c_put_str(TERM_YELLOW, _("本日の賞金首", "Wanted monster that changes from day to day"), 5, 10);
207     sprintf(buf, _("ターゲット: %s", "target: %s"), r_ptr->name.c_str());
208     c_put_str(TERM_YELLOW, buf, 6, 10);
209     sprintf(buf, _("死体 ---- $%d", "corpse   ---- $%d"), (int)r_ptr->level * 50 + 100);
210     prt(buf, 8, 10);
211     sprintf(buf, _("骨   ---- $%d", "skeleton ---- $%d"), (int)r_ptr->level * 30 + 60);
212     prt(buf, 9, 10);
213     player_ptr->today_mon = w_ptr->today_mon;
214 }
215
216 /*!
217  * @brief ツチノコの賞金首情報を表示する。
218  */
219 void tsuchinoko(void)
220 {
221     clear_bldg(4, 18);
222     c_put_str(TERM_YELLOW, _("一獲千金の大チャンス!!!", "Big chance for quick money!!!"), 5, 10);
223     c_put_str(TERM_YELLOW, _("ターゲット:幻の珍獣「ツチノコ」", "target: the rarest animal 'Tsuchinoko'"), 6, 10);
224     c_put_str(TERM_WHITE, _("生け捕り ---- $1,000,000", "catch alive ---- $1,000,000"), 8, 10);
225     c_put_str(TERM_WHITE, _("死体     ----   $200,000", "corpse      ----   $200,000"), 9, 10);
226     c_put_str(TERM_WHITE, _("骨       ----   $100,000", "bones       ----   $100,000"), 10, 10);
227 }
228
229 /*!
230  * @brief 通常の賞金首情報を表示する。
231  */
232 void show_bounty(void)
233 {
234     TERM_LEN y = 0;
235
236     clear_bldg(4, 18);
237     prt(_("死体を持ち帰れば報酬を差し上げます。", "Offer a prize when you bring a wanted monster's corpse"), 4, 10);
238     c_put_str(TERM_YELLOW, _("現在の賞金首", "Wanted monsters"), 6, 10);
239
240     for (int i = 0; i < MAX_BOUNTY; i++) {
241         byte color;
242         concptr done_mark;
243         monster_race *r_ptr
244             = &r_info[(w_ptr->bounty_r_idx[i] > 10000 ? w_ptr->bounty_r_idx[i] - 10000 : w_ptr->bounty_r_idx[i])];
245
246         if (w_ptr->bounty_r_idx[i] > 10000) {
247             color = TERM_RED;
248             done_mark = _("(済)", "(done)");
249         } else {
250             color = TERM_WHITE;
251             done_mark = "";
252         }
253
254         c_prt(color, format("%s %s", r_ptr->name.c_str(), done_mark), y + 7, 10);
255
256         y = (y + 1) % 10;
257         if (!y && (i < MAX_BOUNTY - 1)) {
258             prt(_("何かキーを押してください", "Hit any key."), 0, 0);
259             (void)inkey();
260             prt("", 0, 0);
261             clear_bldg(7, 18);
262         }
263     }
264 }
265
266 /*!
267  * @brief 今日の賞金首を確定する / Determine today's bounty monster
268  * @param player_type プレイヤーへの参照ポインタ
269  * @note conv_old is used if loaded 0.0.3 or older save file
270  */
271 void determine_daily_bounty(player_type *player_ptr, bool conv_old)
272 {
273     int max_dl = 3;
274     if (!conv_old) {
275         for (const auto &d_ref : d_info) {
276             if (max_dlv[d_ref.idx] < d_ref.mindepth)
277                 continue;
278             if (max_dl < max_dlv[d_ref.idx])
279                 max_dl = max_dlv[d_ref.idx];
280         }
281     } else {
282         max_dl = MAX(max_dlv[DUNGEON_ANGBAND], 3);
283     }
284
285     get_mon_num_prep_bounty(player_ptr);
286
287     while (true) {
288         w_ptr->today_mon = get_mon_num(player_ptr, MIN(max_dl / 2, 40), max_dl, GMN_ARENA);
289         monster_race *r_ptr;
290         r_ptr = &r_info[w_ptr->today_mon];
291
292         if (cheat_hear) {
293             msg_format("日替わり候補: %s ", r_ptr->name.c_str());
294         }
295
296         if (r_ptr->flags1 & RF1_UNIQUE)
297             continue;
298         if (r_ptr->flags7 & (RF7_NAZGUL | RF7_UNIQUE2))
299             continue;
300         if (r_ptr->flags2 & RF2_MULTIPLY)
301             continue;
302         if ((r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != (RF9_DROP_CORPSE | RF9_DROP_SKELETON))
303             continue;
304         if (r_ptr->rarity > 10)
305             continue;
306         break;
307     }
308
309     // プレイヤーは日替わり賞金首に関する知識を失う。
310     player_ptr->today_mon = 0;
311 }
312
313 /*!
314  * @brief 賞金首となるユニークを確定する / Determine bounty uniques
315  * @param player_ptr プレイヤーへの参照ポインタ
316  */
317 void determine_bounty_uniques(player_type *player_ptr)
318 {
319     get_mon_num_prep_bounty(player_ptr);
320
321     for (int i = 0; i < MAX_BOUNTY; i++) {
322         while (true) {
323             w_ptr->bounty_r_idx[i] = get_mon_num(player_ptr, 0, MAX_DEPTH - 1, GMN_ARENA);
324             monster_race *r_ptr;
325             r_ptr = &r_info[w_ptr->bounty_r_idx[i]];
326
327             if (!(r_ptr->flags1 & RF1_UNIQUE))
328                 continue;
329
330             if (!(r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)))
331                 continue;
332
333             if (r_ptr->rarity > 100)
334                 continue;
335
336             if (no_questor_or_bounty_uniques(w_ptr->bounty_r_idx[i]))
337                 continue;
338
339             int j;
340             for (j = 0; j < i; j++) {
341                 if (w_ptr->bounty_r_idx[i] == w_ptr->bounty_r_idx[j])
342                     break;
343             }
344
345             if (j == i)
346                 break;
347         }
348     }
349
350     for (int i = 0; i < MAX_BOUNTY - 1; i++) {
351         for (int j = i; j < MAX_BOUNTY; j++) {
352             MONRACE_IDX tmp;
353             if (r_info[w_ptr->bounty_r_idx[i]].level > r_info[w_ptr->bounty_r_idx[j]].level) {
354                 tmp = w_ptr->bounty_r_idx[i];
355                 w_ptr->bounty_r_idx[i] = w_ptr->bounty_r_idx[j];
356                 w_ptr->bounty_r_idx[j] = tmp;
357             }
358         }
359     }
360 }