OSDN Git Service

[Refactor] #40413 Separated asking-player.c/h from util.c/h
[hengband/hengband.git] / src / market / play-gamble.c
1 #include "play-gamble.h"
2 #include "core/asking-player.h"
3 #include "core/show-file.h"
4 #include "io/input-key-acceptor.h"
5 #include "market/building-actions-table.h"
6 #include "market/building-util.h"
7 #include "market/poker.h"
8 #include "player/avatar.h"
9 #include "term/term-color-types.h"
10 #include "view/display-fruit.h"
11 #include "view/display-messages.h"
12
13 /*!
14  * @brief カジノ1プレイごとのメインルーチン / gamble_comm
15  * @param player_ptr プレーヤーへの参照ポインタ
16  * @param cmd プレイするゲームID
17  * @return プレイ成立やルール説明のみ等ならTRUE、賭け金不足で不成立ならFALSE
18  */
19 bool gamble_comm(player_type *player_ptr, int cmd)
20 {
21         int i;
22         int roll1, roll2, roll3, choice, odds, win;
23         s32b wager;
24         s32b maxbet;
25         s32b oldgold;
26
27         char out_val[160], tmp_str[80], again;
28         concptr p;
29
30         screen_save();
31
32         if (cmd == BACT_GAMBLE_RULES)
33         {
34                 (void)show_file(player_ptr, TRUE, _("jgambling.txt", "gambling.txt"), NULL, 0, 0);
35                 screen_load();
36                 return TRUE;
37         }
38
39         if (player_ptr->au < 1)
40         {
41                 msg_print(_("おい!おまえ一文なしじゃないか!こっから出ていけ!",
42                         "Hey! You don't have gold - get out of here!"));
43                 msg_print(NULL);
44                 screen_load();
45                 return FALSE;
46         }
47
48         clear_bldg(5, 23);
49         maxbet = player_ptr->lev * 200;
50         maxbet = MIN(maxbet, player_ptr->au);
51
52         strcpy(out_val, "");
53         sprintf(tmp_str, _("賭け金 (1-%ld)?", "Your wager (1-%ld) ? "), (long int)maxbet);
54
55
56         /*
57          * Use get_string() because we may need more than
58          * the s16b value returned by get_quantity().
59          */
60         if (!get_string(tmp_str, out_val, 32))
61         {
62                 msg_print(NULL);
63                 screen_load();
64                 return TRUE;
65         }
66
67         for (p = out_val; *p == ' '; p++);
68
69         wager = atol(p);
70         if (wager > player_ptr->au)
71         {
72                 msg_print(_("おい!金が足りないじゃないか!出ていけ!", "Hey! You don't have the gold - get out of here!"));
73                 msg_print(NULL);
74                 screen_load();
75                 return FALSE;
76         }
77         else if (wager > maxbet)
78         {
79                 msg_format(_("%ldゴールドだけ受けよう。残りは取っときな。",
80                         "I'll take %ld gold of that. Keep the rest."), (long int)maxbet);
81                 wager = maxbet;
82         }
83         else if (wager < 1)
84         {
85                 msg_print(_("OK、1ゴールドからはじめよう。", "Ok, we'll start with 1 gold."));
86                 wager = 1;
87         }
88         msg_print(NULL);
89         win = FALSE;
90         odds = 0;
91         oldgold = player_ptr->au;
92
93         sprintf(tmp_str, _("ゲーム前の所持金: %9ld", "Gold before game: %9ld"), (long int)oldgold);
94         prt(tmp_str, 20, 2);
95         sprintf(tmp_str, _("現在の掛け金:     %9ld", "Current Wager:    %9ld"), (long int)wager);
96         prt(tmp_str, 21, 2);
97
98         do
99         {
100                 player_ptr->au -= wager;
101                 switch (cmd)
102                 {
103                 case BACT_IN_BETWEEN: /* Game of In-Between */
104                         c_put_str(TERM_GREEN, _("イン・ビトイーン", "In Between"), 5, 2);
105
106                         odds = 4;
107                         win = FALSE;
108                         roll1 = randint1(10);
109                         roll2 = randint1(10);
110                         choice = randint1(10);
111                         sprintf(tmp_str, _("黒ダイス: %d        黒ダイス: %d", "Black die: %d       Black Die: %d"), roll1, roll2);
112
113                         prt(tmp_str, 8, 3);
114                         sprintf(tmp_str, _("赤ダイス: %d", "Red die: %d"), choice);
115
116                         prt(tmp_str, 11, 14);
117                         if (((choice > roll1) && (choice < roll2)) ||
118                                 ((choice < roll1) && (choice > roll2)))
119                                 win = TRUE;
120                         break;
121                 case BACT_CRAPS:  /* Game of Craps */
122                         c_put_str(TERM_GREEN, _("クラップス", "Craps"), 5, 2);
123
124                         win = 3;
125                         odds = 2;
126                         roll1 = randint1(6);
127                         roll2 = randint1(6);
128                         roll3 = roll1 + roll2;
129                         choice = roll3;
130                         sprintf(tmp_str, _("1振りめ: %d %d      Total: %d",
131                                 "First roll: %d %d    Total: %d"), roll1, roll2, roll3);
132                         prt(tmp_str, 7, 5);
133                         if ((roll3 == 7) || (roll3 == 11))
134                                 win = TRUE;
135                         else if ((roll3 == 2) || (roll3 == 3) || (roll3 == 12))
136                                 win = FALSE;
137                         else
138                         {
139                                 do
140                                 {
141                                         msg_print(_("なにかキーを押すともう一回振ります。", "Hit any key to roll again"));
142
143                                         msg_print(NULL);
144                                         roll1 = randint1(6);
145                                         roll2 = randint1(6);
146                                         roll3 = roll1 + roll2;
147                                         sprintf(tmp_str, _("出目: %d %d          合計:      %d",
148                                                 "Roll result: %d %d   Total:     %d"), roll1, roll2, roll3);
149                                         prt(tmp_str, 8, 5);
150                                         if (roll3 == choice)
151                                                 win = TRUE;
152                                         else if (roll3 == 7)
153                                                 win = FALSE;
154                                 } while ((win != TRUE) && (win != FALSE));
155                         }
156                         
157                         break;
158
159                 case BACT_SPIN_WHEEL:  /* Spin the Wheel Game */
160                         win = FALSE;
161                         odds = 9;
162                         c_put_str(TERM_GREEN, _("ルーレット", "Wheel"), 5, 2);
163
164                         prt("0  1  2  3  4  5  6  7  8  9", 7, 5);
165                         prt("--------------------------------", 8, 3);
166                         strcpy(out_val, "");
167                         get_string(_("何番? (0-9): ", "Pick a number (0-9): "), out_val, 32);
168
169                         for (p = out_val; iswspace(*p); p++);
170                         choice = atol(p);
171                         if (choice < 0)
172                         {
173                                 msg_print(_("0番にしとくぜ。", "I'll put you down for 0."));
174                                 choice = 0;
175                         }
176                         else if (choice > 9)
177                         {
178                                 msg_print(_("OK、9番にしとくぜ。", "Ok, I'll put you down for 9."));
179                                 choice = 9;
180                         }
181                         msg_print(NULL);
182                         roll1 = randint0(10);
183                         sprintf(tmp_str, _("ルーレットは回り、止まった。勝者は %d番だ。",
184                                 "The wheel spins to a stop and the winner is %d"), roll1);
185                         prt(tmp_str, 13, 3);
186                         prt("", 9, 0);
187                         prt("*", 9, (3 * roll1 + 5));
188                         if (roll1 == choice)
189                                 win = TRUE;
190                         break;
191
192                 case BACT_DICE_SLOTS: /* The Dice Slots */
193                         c_put_str(TERM_GREEN, _("ダイス・スロット", "Dice Slots"), 5, 2);
194                         c_put_str(TERM_YELLOW, _("レモン   レモン            2", ""), 6, 37);
195                         c_put_str(TERM_YELLOW, _("レモン   レモン   レモン   5", ""), 7, 37);
196                         c_put_str(TERM_ORANGE, _("オレンジ オレンジ オレンジ 10", ""), 8, 37);
197                         c_put_str(TERM_UMBER, _("剣       剣       剣       20", ""), 9, 37);
198                         c_put_str(TERM_SLATE, _("盾       盾       盾       50", ""), 10, 37);
199                         c_put_str(TERM_VIOLET, _("プラム   プラム   プラム   200", ""), 11, 37);
200                         c_put_str(TERM_RED, _("チェリー チェリー チェリー 1000", ""), 12, 37);
201
202                         win = FALSE;
203                         roll1 = randint1(21);
204                         for (i = 6; i > 0; i--)
205                         {
206                                 if ((roll1 - i) < 1)
207                                 {
208                                         roll1 = 7 - i;
209                                         break;
210                                 }
211                                 roll1 -= i;
212                         }
213                         roll2 = randint1(21);
214                         for (i = 6; i > 0; i--)
215                         {
216                                 if ((roll2 - i) < 1)
217                                 {
218                                         roll2 = 7 - i;
219                                         break;
220                                 }
221                                 roll2 -= i;
222                         }
223                         choice = randint1(21);
224                         for (i = 6; i > 0; i--)
225                         {
226                                 if ((choice - i) < 1)
227                                 {
228                                         choice = 7 - i;
229                                         break;
230                                 }
231                                 choice -= i;
232                         }
233                         put_str("/--------------------------\\", 7, 2);
234                         prt("\\--------------------------/", 17, 2);
235                         display_fruit(8, 3, roll1 - 1);
236                         display_fruit(8, 12, roll2 - 1);
237                         display_fruit(8, 21, choice - 1);
238                         if ((roll1 == roll2) && (roll2 == choice))
239                         {
240                                 win = TRUE;
241                                 switch (roll1)
242                                 {
243                                 case 1:
244                                         odds = 5; break;
245                                 case 2:
246                                         odds = 10; break;
247                                 case 3:
248                                         odds = 20; break;
249                                 case 4:
250                                         odds = 50; break;
251                                 case 5:
252                                         odds = 200; break;
253                                 case 6:
254                                         odds = 1000; break;
255                                 }
256                         }
257                         else if ((roll1 == 1) && (roll2 == 1))
258                         {
259                                 win = TRUE;
260                                 odds = 2;
261                         }
262                         break;
263                 case BACT_POKER:
264                         win = FALSE;
265                         odds = do_poker();
266                         if (odds) win = TRUE;
267                         break;
268                 }
269
270                 if (win)
271                 {
272                         prt(_("あなたの勝ち", "YOU WON"), 16, 37);
273
274                         player_ptr->au += odds * wager;
275                         sprintf(tmp_str, _("倍率: %d", "Payoff: %d"), odds);
276
277                         prt(tmp_str, 17, 37);
278                 }
279                 else
280                 {
281                         prt(_("あなたの負け", "You Lost"), 16, 37);
282                         prt("", 17, 37);
283                 }
284
285                 sprintf(tmp_str, _("現在の所持金:     %9ld", "Current Gold:     %9ld"), (long int)player_ptr->au);
286
287                 prt(tmp_str, 22, 2);
288                 prt(_("もう一度(Y/N)?", "Again(Y/N)?"), 18, 37);
289
290                 move_cursor(18, 52);
291                 again = inkey();
292                 prt("", 16, 37);
293                 prt("", 17, 37);
294                 prt("", 18, 37);
295                 if (wager > player_ptr->au)
296                 {
297                         msg_print(_("おい!金が足りないじゃないか!ここから出て行け!",
298                                 "Hey! You don't have the gold - get out of here!"));
299                         msg_print(NULL);
300
301                         /* Get out here */
302                         break;
303                 }
304         } while ((again == 'y') || (again == 'Y'));
305
306         prt("", 18, 37);
307         if (player_ptr->au >= oldgold)
308         {
309                 msg_print(_("「今回は儲けたな!でも次はこっちが勝ってやるからな、絶対に!」",
310                         "You came out a winner! We'll win next time, I'm sure."));
311                 chg_virtue(player_ptr, V_CHANCE, 3);
312         }
313         else
314         {
315                 msg_print(_("「金をスッてしまったな、わはは!うちに帰った方がいいぜ。」", "You lost gold! Haha, better head home."));
316                 chg_virtue(player_ptr, V_CHANCE, -3);
317         }
318
319         msg_print(NULL);
320         screen_load();
321         return TRUE;
322 }