OSDN Git Service

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