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 "flavor/flavor-describer.h"
9 #include "game-option/cheat-options.h"
10 #include "inventory/inventory-object.h"
11 #include "inventory/inventory-slot-types.h"
12 #include "io/input-key-acceptor.h"
13 #include "market/bounty-prize-table.h"
14 #include "market/building-util.h"
15 #include "monster-race/monster-race-hook.h"
16 #include "monster-race/monster-race.h"
17 #include "monster-race/race-flags1.h"
18 #include "monster-race/race-flags2.h"
19 #include "monster-race/race-flags7.h"
20 #include "monster-race/race-indice-types.h"
21 #include "monster/monster-list.h"
22 #include "monster/monster-util.h"
23 #include "object-enchant/item-apply-magic.h"
24 #include "object-enchant/item-magic-applier.h"
25 #include "object/object-info.h"
26 #include "object/object-kind-hook.h"
27 #include "perception/object-perception.h"
28 #include "sv-definition/sv-other-types.h"
29 #include "system/baseitem-info-definition.h"
30 #include "system/dungeon-info.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 "util/bit-flags-calculator.h"
38 #include "view/display-messages.h"
39 #include "world/world.h"
43 * @brief 賞金首の引き換え処理 / Get prize
44 * @param player_ptr プレイヤーへの参照ポインタ
45 * @return 各種賞金首のいずれかでも換金が行われたか否か。
47 bool exchange_cash(PlayerType *player_ptr)
50 GAME_TEXT o_name[MAX_NLEN];
53 for (INVENTORY_IDX i = 0; i <= INVEN_SUB_HAND; i++) {
54 o_ptr = &player_ptr->inventory_list[i];
55 const auto r_idx_of_item = static_cast<MonsterRaceId>(o_ptr->pval);
57 if ((o_ptr->tval == ItemKindType::CAPTURE) && (r_idx_of_item == MonsterRaceId::TSUCHINOKO)) {
58 char buf[MAX_NLEN + 32];
59 describe_flavor(player_ptr, o_name, o_ptr, 0);
60 sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
62 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)(1000000L * o_ptr->number));
63 player_ptr->au += 1000000L * o_ptr->number;
64 player_ptr->redraw |= (PR_GOLD);
65 vary_item(player_ptr, i, -o_ptr->number);
72 for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
73 o_ptr = &player_ptr->inventory_list[i];
74 const auto r_idx_of_item = static_cast<MonsterRaceId>(o_ptr->pval);
76 if ((o_ptr->tval == ItemKindType::CORPSE) && (o_ptr->sval == SV_CORPSE) && (r_idx_of_item == MonsterRaceId::TSUCHINOKO)) {
77 char buf[MAX_NLEN + 32];
78 describe_flavor(player_ptr, o_name, o_ptr, 0);
79 sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
81 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)(200000L * o_ptr->number));
82 player_ptr->au += 200000L * o_ptr->number;
83 player_ptr->redraw |= (PR_GOLD);
84 vary_item(player_ptr, i, -o_ptr->number);
91 for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
92 o_ptr = &player_ptr->inventory_list[i];
93 const auto r_idx_of_item = static_cast<MonsterRaceId>(o_ptr->pval);
95 if ((o_ptr->tval == ItemKindType::CORPSE) && (o_ptr->sval == SV_SKELETON) && (r_idx_of_item == MonsterRaceId::TSUCHINOKO)) {
96 char buf[MAX_NLEN + 32];
97 describe_flavor(player_ptr, o_name, o_ptr, 0);
98 sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
100 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)(100000L * o_ptr->number));
101 player_ptr->au += 100000L * o_ptr->number;
102 player_ptr->redraw |= (PR_GOLD);
103 vary_item(player_ptr, i, -o_ptr->number);
110 for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
111 o_ptr = &player_ptr->inventory_list[i];
112 const auto r_idx_of_item = static_cast<MonsterRaceId>(o_ptr->pval);
114 if ((o_ptr->tval == ItemKindType::CORPSE) && (o_ptr->sval == SV_CORPSE) && (streq(monraces_info[r_idx_of_item].name.data(), monraces_info[w_ptr->today_mon].name.data()))) {
115 char buf[MAX_NLEN + 32];
116 describe_flavor(player_ptr, o_name, o_ptr, 0);
117 sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
118 if (get_check(buf)) {
120 _("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)((monraces_info[w_ptr->today_mon].level * 50 + 100) * o_ptr->number));
121 player_ptr->au += (monraces_info[w_ptr->today_mon].level * 50 + 100) * o_ptr->number;
122 player_ptr->redraw |= (PR_GOLD);
123 vary_item(player_ptr, i, -o_ptr->number);
130 for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
131 o_ptr = &player_ptr->inventory_list[i];
132 const auto r_idx_of_item = static_cast<MonsterRaceId>(o_ptr->pval);
134 if ((o_ptr->tval == ItemKindType::CORPSE) && (o_ptr->sval == SV_SKELETON) && (streq(monraces_info[r_idx_of_item].name.data(), monraces_info[w_ptr->today_mon].name.data()))) {
135 char buf[MAX_NLEN + 32];
136 describe_flavor(player_ptr, o_name, o_ptr, 0);
137 sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "), o_name);
138 if (get_check(buf)) {
139 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)((monraces_info[w_ptr->today_mon].level * 30 + 60) * o_ptr->number));
140 player_ptr->au += (monraces_info[w_ptr->today_mon].level * 30 + 60) * o_ptr->number;
141 player_ptr->redraw |= (PR_GOLD);
142 vary_item(player_ptr, i, -o_ptr->number);
149 for (auto &[r_idx, is_achieved] : w_ptr->bounties) {
154 for (INVENTORY_IDX i = INVEN_PACK - 1; i >= 0; i--) {
155 o_ptr = &player_ptr->inventory_list[i];
156 const auto r_idx_of_item = static_cast<MonsterRaceId>(o_ptr->pval);
158 if ((o_ptr->tval != ItemKindType::CORPSE) || (r_idx_of_item != r_idx)) {
162 char buf[MAX_NLEN + 20];
163 INVENTORY_IDX item_new;
166 describe_flavor(player_ptr, o_name, o_ptr, 0);
167 sprintf(buf, _("%sを渡しますか?", "Hand %s over? "), o_name);
168 if (!get_check(buf)) {
172 vary_item(player_ptr, i, -o_ptr->number);
173 chg_virtue(player_ptr, V_JUSTICE, 5);
176 auto num = std::count_if(std::begin(w_ptr->bounties), std::end(w_ptr->bounties),
177 [](const auto &b_ref) { return b_ref.is_achieved; });
179 msg_format(_("これで合計 %d ポイント獲得しました。", "You earned %d point%s total."), num, (num > 1 ? "s" : ""));
181 (&forge)->prep(lookup_baseitem_id(prize_list[num - 1]));
182 ItemMagicApplier(player_ptr, &forge, player_ptr->current_floor_ptr->object_level, AM_NO_FIXED_ART).execute();
184 object_aware(player_ptr, &forge);
185 object_known(&forge);
188 * Hand it --- Assume there is an empty slot.
189 * Since a corpse is handed at first,
190 * there is at least one empty slot.
192 item_new = store_item_to_inventory(player_ptr, &forge);
193 describe_flavor(player_ptr, o_name, &forge, 0);
194 msg_format(_("%s(%c)を貰った。", "You get %s (%c). "), o_name, index_to_label(item_new));
196 autopick_alter_item(player_ptr, item_new, false);
197 handle_stuff(player_ptr);
206 msg_print(_("賞金を得られそうなものは持っていなかった。", "You have nothing."));
212 * @brief 本日の賞金首情報を表示する。
213 * @param player_ptr プレイヤーへの参照ポインタ
215 void today_target(PlayerType *player_ptr)
218 auto *r_ptr = &monraces_info[w_ptr->today_mon];
221 c_put_str(TERM_YELLOW, _("本日の賞金首", "Wanted monster that changes from day to day"), 5, 10);
222 sprintf(buf, _("ターゲット: %s", "target: %s"), r_ptr->name.data());
223 c_put_str(TERM_YELLOW, buf, 6, 10);
224 sprintf(buf, _("死体 ---- $%d", "corpse ---- $%d"), (int)r_ptr->level * 50 + 100);
226 sprintf(buf, _("骨 ---- $%d", "skeleton ---- $%d"), (int)r_ptr->level * 30 + 60);
228 player_ptr->knows_daily_bounty = true;
232 * @brief ツチノコの賞金首情報を表示する。
234 void tsuchinoko(void)
237 c_put_str(TERM_YELLOW, _("一獲千金の大チャンス!!!", "Big chance for quick money!!!"), 5, 10);
238 c_put_str(TERM_YELLOW, _("ターゲット:幻の珍獣「ツチノコ」", "target: the rarest animal 'Tsuchinoko'"), 6, 10);
239 c_put_str(TERM_WHITE, _("生け捕り ---- $1,000,000", "catch alive ---- $1,000,000"), 8, 10);
240 c_put_str(TERM_WHITE, _("死体 ---- $200,000", "corpse ---- $200,000"), 9, 10);
241 c_put_str(TERM_WHITE, _("骨 ---- $100,000", "bones ---- $100,000"), 10, 10);
245 * @brief 通常の賞金首情報を表示する。
247 void show_bounty(void)
252 prt(_("死体を持ち帰れば報酬を差し上げます。", "Offer a prize when you bring a wanted monster's corpse"), 4, 10);
253 c_put_str(TERM_YELLOW, _("現在の賞金首", "Wanted monsters"), 6, 10);
255 for (auto i = 0U; i < std::size(w_ptr->bounties); i++) {
256 const auto &[r_idx, is_achieved] = w_ptr->bounties[i];
257 monster_race *r_ptr = &monraces_info[r_idx];
259 auto color = is_achieved ? TERM_RED : TERM_WHITE;
260 auto done_mark = is_achieved ? _("(済)", "(done)") : "";
262 c_prt(color, format("%s %s", r_ptr->name.data(), done_mark), y + 7, 10);
265 if (!y && (i < std::size(w_ptr->bounties) - 1)) {
266 prt(_("何かキーを押してください", "Hit any key."), 0, 0);
275 * @brief 今日の賞金首を確定する / Determine today's bounty monster
276 * @param PlayerType プレイヤーへの参照ポインタ
277 * @note conv_old is used if loaded 0.0.3 or older save file
279 void determine_daily_bounty(PlayerType *player_ptr, bool conv_old)
283 for (const auto &d_ref : dungeons_info) {
284 if (max_dlv[d_ref.idx] < d_ref.mindepth) {
287 if (max_dl < max_dlv[d_ref.idx]) {
288 max_dl = max_dlv[d_ref.idx];
292 max_dl = std::max(max_dlv[DUNGEON_ANGBAND], 3);
295 get_mon_num_prep_bounty(player_ptr);
298 w_ptr->today_mon = get_mon_num(player_ptr, std::min(max_dl / 2, 40), max_dl, GMN_ARENA);
300 r_ptr = &monraces_info[w_ptr->today_mon];
303 msg_format("日替わり候補: %s ", r_ptr->name.data());
306 if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) {
309 if (r_ptr->population_flags.has(MonsterPopulationType::NAZGUL) || any_bits(r_ptr->flags7, RF7_UNIQUE2)) {
312 if (r_ptr->flags2 & RF2_MULTIPLY) {
315 if (!r_ptr->drop_flags.has_all_of({ MonsterDropType::DROP_CORPSE, MonsterDropType::DROP_SKELETON })) {
318 if (r_ptr->rarity > 10) {
324 player_ptr->knows_daily_bounty = false;
328 * @brief 賞金首となるユニークを確定する / Determine bounty uniques
329 * @param player_ptr プレイヤーへの参照ポインタ
331 void determine_bounty_uniques(PlayerType *player_ptr)
333 get_mon_num_prep_bounty(player_ptr);
335 auto is_suitable_for_bounty = [](MonsterRaceId r_idx) {
336 const auto &r_ref = monraces_info[r_idx];
337 bool is_suitable = r_ref.kind_flags.has(MonsterKindType::UNIQUE);
338 is_suitable &= r_ref.drop_flags.has_any_of({ MonsterDropType::DROP_CORPSE, MonsterDropType::DROP_SKELETON });
339 is_suitable &= r_ref.rarity <= 100;
340 is_suitable &= !no_questor_or_bounty_uniques(r_idx);
344 // 賞金首とするモンスターの種族IDのリストを生成
345 std::vector<MonsterRaceId> bounty_r_idx_list;
346 while (bounty_r_idx_list.size() < std::size(w_ptr->bounties)) {
347 auto r_idx = get_mon_num(player_ptr, 0, MAX_DEPTH - 1, GMN_ARENA);
348 if (!is_suitable_for_bounty(r_idx)) {
352 auto is_already_selected = std::any_of(bounty_r_idx_list.begin(), bounty_r_idx_list.end(),
353 [r_idx](MonsterRaceId bounty_r_idx) { return r_idx == bounty_r_idx; });
354 if (!is_already_selected) {
355 bounty_r_idx_list.push_back(r_idx);
360 std::sort(bounty_r_idx_list.begin(), bounty_r_idx_list.end(),
361 [](MonsterRaceId r_idx1, MonsterRaceId r_idx2) {
362 return monraces_info[r_idx1].level < monraces_info[r_idx2].level;
366 std::transform(bounty_r_idx_list.begin(), bounty_r_idx_list.end(), std::begin(w_ptr->bounties),
367 [](MonsterRaceId r_idx) -> bounty_type {
368 return { r_idx, false };