OSDN Git Service

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