OSDN Git Service

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