OSDN Git Service

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