home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / GAMES.ZIP / POKER.C < prev    next >
C/C++ Source or Header  |  1995-05-23  |  16KB  |  467 lines

  1. #include "top.h"
  2.  
  3. void poker_game(XINT pgwords) //!! cmd words need lang
  4.     { ////proc
  5.     poker_game_typ tgame;
  6.     XINT tgnum;
  7.     char override = 0;
  8.     XINT pgd;
  9.     char bettype = 0;
  10.     unsigned long tmpbet;
  11.     XINT plnum;
  12.  
  13.     if (!stricmp(get_word(1), "START"))
  14.         {
  15.         tgnum = poker_startnewgame(&tgame);
  16.         itoa(tgnum, outnum[0], 10);
  17.         top_output(OUT_SCREEN, getlang("PokerYouStartGame"), outnum[0]);
  18.         dispatch_message(MSG_GENERIC, top_output(OUT_STRINGNF,
  19.                                                  getlang("PokerMsgStartGame"),
  20.                                                  user.handle, outnum[0]),
  21.                          -1, 0, 0);
  22.         pokermaingame = tgnum;
  23.         pokeringame[tgnum] = 1;
  24.         return;
  25.         }
  26.     if (!stricmp(get_word(1), "JOIN"))
  27.         {
  28.         tgnum = atoi(get_word(2)); // Maybe take POKER x JOIN as well
  29.         if (tgnum < 0 || !isdigit(get_word_char(2, 0)))
  30.             {
  31.             top_output(OUT_SCREEN, getlang("PokerBadGameNum"));
  32.             return;
  33.             }
  34.         else
  35.             {
  36.             if (!poker_joingame(tgnum, &tgame))
  37.                 {
  38.                 return;
  39.                 }
  40.             }
  41.  
  42.         itoa(tgnum, outnum[0], 10);
  43.         top_output(OUT_SCREEN, getlang("PokerYouJoinGame"), outnum[0]);
  44.         poker_sendmessage(MSG_GENERIC, 0, tgnum, 0,
  45.                           top_output(OUT_STRINGNF,
  46.                                      getlang("PokerMsgJoinGame"),
  47.                                      user.handle, outnum[0]),
  48.                           &tgame);
  49.         pokermaingame = tgnum;
  50.         pokeringame[tgnum] = 1;
  51.         return;
  52.         }
  53.     if (!stricmp(get_word(1), "QUIT"))
  54.         {
  55.         tgnum = atoi(get_word(2)); // Maybe take POKER x QUIT as well
  56.         if (tgnum < 0 || !isdigit(get_word_char(2, 0)))
  57.             {
  58.             top_output(OUT_SCREEN, getlang("PokerBadGameNum"));
  59.             }
  60.         else
  61.             {
  62.             poker_lockgame(tgnum);
  63.             poker_loadgame(tgnum, &tgame);
  64.             if (poker_checkturn(POKSTG_ANYTURN, od_control.od_node, &tgame))
  65.                 {
  66.                 poker_foldplayer(od_control.od_node, tgnum, &tgame);
  67.                 }
  68.  
  69.             plnum = poker_getplayernum(POKPL_WAITING, od_control.od_node,
  70.                                        &tgame);
  71.             tgame.wanttoplay[plnum] = -1;
  72.             if (--tgame.wtpcount < 1)
  73.                 {
  74.                 tgame.inuse = 0;
  75.                 }
  76.             poker_savegame(tgnum, &tgame);
  77.             poker_unlockgame(tgnum);
  78.             pokeringame[tgnum] = 0;
  79.  
  80.             itoa(tgnum, outnum[0], 10);
  81.             top_output(OUT_SCREEN, getlang("PokerYouQuitGame"), outnum[0]);
  82.             poker_sendmessage(MSG_GENERIC, 1, tgnum, 0,
  83.                               top_output(OUT_STRINGNF,
  84.                                          getlang("PokerMsgQuitGame"),
  85.                                          user.handle, outnum[0]),
  86.                               &tgame);
  87.             }
  88.         return;
  89.         }
  90.     if (!stricmp(get_word(1), "MAIN"))
  91.         {
  92.         tgnum = atoi(get_word(2)); // Maybe take POKER x MAIN as well
  93.         if (tgnum < 0 || !isdigit(get_word_char(2, 0)))
  94.             {
  95.             top_output(OUT_SCREEN, getlang("PokerBadGameNum"));
  96.             }
  97.         else
  98.             {
  99.             pokermaingame = tgnum;
  100.             itoa(pokermaingame, outnum[0], 10);
  101.             top_output(OUT_SCREEN, getlang("PokerMainGameSet"), outnum[0]);
  102.             }
  103.         return;
  104.         }
  105.  
  106.     if (!isdigit(get_word_char(1, 0)))
  107.         {
  108.         for (pgd = pgwords; pgd > 1; pgd--)
  109.             {
  110.             word_pos[pgd] = word_pos[pgd - 1];
  111.             word_len[pgd] = word_len[pgd - 1];
  112.             }
  113.         override = 1;
  114.         pgwords++;
  115.         }
  116.  
  117.     if (override && pokermaingame < 0)
  118.         {
  119.         top_output(OUT_SCREEN, getlang("PokerNoMainGame"));
  120.         return;
  121.         }
  122.     if (!override)
  123.         {
  124.         tgnum = atoi(get_word(1));
  125.         }
  126.     else
  127.         {
  128.         tgnum = pokermaingame;
  129.         }
  130.  
  131.     if (!stricmp(get_word(2), "TURN"))
  132.         {
  133.         poker_lockgame(tgnum);
  134.         poker_loadgame(tgnum, &tgame);
  135.         poker_unlockgame(tgnum);
  136.  
  137.         // Add bet/discard show support!!
  138.         if (tgame.turn < 0)
  139.             {
  140.             itoa(tgnum, outnum[0], 10);
  141.             top_output(OUT_SCREEN, getlang("PokerGameNotOn"), outnum[0]);
  142.             }
  143.         else
  144.             {
  145.             top_output(OUT_SCREEN, getlang("PokerWhosTurn"),
  146.                        handles[tgame.player[tgame.turn].node].string,
  147.                        getlang(tgame.stage == 1 ? "Discard" : "Bet"));
  148.             }
  149.         return;
  150.         }
  151.     if (!stricmp(get_word(2), "POT"))
  152.         {
  153.         poker_lockgame(tgnum);
  154.         poker_loadgame(tgnum, &tgame);
  155.         poker_unlockgame(tgnum);
  156.  
  157.         if (tgame.turn < 0)
  158.             {
  159.             itoa(tgnum, outnum[0], 10);
  160.             top_output(OUT_SCREEN, getlang("PokerGameNotOn"), outnum[0]);
  161.             }
  162.         else
  163.             {
  164.             ultoa(tgame.pot, outnum[0], 10);
  165.             top_output(OUT_SCREEN, getlang("PokerShowPot"), outnum[0],
  166.                        getlang(tgame.pot == 1 ? "CDSingular" : "CDPlural"));
  167.             }
  168.         return;
  169.         }
  170.     if (!stricmp(get_word(2), "HAND"))
  171.         {
  172.         poker_lockgame(tgnum);
  173.         poker_loadgame(tgnum, &tgame);
  174.         poker_unlockgame(tgnum);
  175.  
  176.         plnum = poker_getplayernum(POKPL_PLAYING, od_control.od_node,
  177.                                    &tgame);
  178.         if (tgame.turn < 0)
  179.             {
  180.             itoa(tgnum, outnum[0], 10);
  181.             top_output(OUT_SCREEN, getlang("PokerGameNotOn"), outnum[0]);
  182.             return;
  183.             }
  184.         if (plnum == -1)
  185.             {
  186.             itoa(tgnum, outnum[0], 10);
  187.             top_output(OUT_SCREEN, getlang("PokerNotInGame"), outnum[0]);
  188.             }
  189.         else
  190.             {
  191.             top_output(OUT_SCREEN, getlang("PokerHandPrefix"));
  192.             poker_displayhand(&tgame, tgame.player[plnum].cards);
  193.             top_output(OUT_SCREEN, getlang("PokerHandSuffix"));
  194.             top_output(OUT_SCREEN,
  195.                        poker_gethandname(&tgame, tgame.player[plnum].cards));
  196.             top_output(OUT_SCREEN, getlang("PokerHandNameSuf"));
  197.             }
  198.  
  199.         return;
  200.         }
  201.     if (!stricmp(get_word(2), "SCAN"))
  202.         {
  203.         // Add scanning after tests.
  204.         }
  205.  
  206.     if (!stricmp(get_word(2), "BET"))
  207.         {
  208.         bettype = 1;
  209.         }
  210.     if (!stricmp(get_word(2), "CALL"))
  211.         {
  212.         bettype = 2;
  213.         }
  214.     if (!stricmp(get_word(2), "RAISE"))
  215.         {
  216.         bettype = 3;
  217.         }
  218.     if (bettype > 0)
  219.         {
  220.         poker_lockgame(tgnum);
  221.         poker_loadgame(tgnum, &tgame);
  222.  
  223.         if (!get_word_char(3, 0) && bettype != 2)
  224.             {
  225.             poker_unlockgame(tgnum);
  226.             top_output(OUT_SCREEN, getlang("PokerNoBet"),
  227.                        bettype == 1 ? "BET" : "RAISE");
  228.             return;
  229.             }
  230.  
  231.         if (!poker_checkturn(POKSTG_ANYBET, od_control.od_node, &tgame))
  232.             {
  233.             poker_unlockgame(tgnum);
  234.             itoa(tgnum, outnum[0], 10);
  235.             // Add bet/discard show support!!
  236.             top_output(OUT_SCREEN, getlang("PokerNotYourTurn"),
  237.                        getlang("Bet"), outnum[0]);
  238.  
  239.             return;
  240.             }
  241.  
  242.         plnum = poker_getplayernum(POKPL_PLAYING, od_control.od_node,
  243.                                    &tgame);
  244.  
  245.         tmpbet = 0;
  246.         if (bettype == 2 || bettype == 3)
  247.             {
  248.             tmpbet = tgame.highbet - tgame.player[plnum].totalbet;
  249.             }
  250.         if (bettype == 1 || bettype == 3)
  251.             {
  252.             tmpbet += strtoul(get_word(3), NULL, 10);
  253.             }
  254.  
  255.         if (tmpbet > user.cybercash)
  256.             {
  257.             poker_unlockgame(tgnum);
  258.             ultoa(tmpbet, outnum[0], 10);
  259.             ultoa(user.cybercash, outnum[1], 10);
  260.             top_output(OUT_SCREEN, getlang("PokerNotEnoughCash"), outnum[0],
  261.                        outnum[1]);
  262.             return;
  263.             }
  264.  
  265.         if (tgame.player[plnum].totalbet + tmpbet < tgame.highbet)
  266.             {
  267.             poker_unlockgame(tgnum);
  268.             ultoa(tmpbet, outnum[0], 10);
  269.             ultoa(tgame.highbet - tgame.player[plnum].totalbet,
  270.                   outnum[1], 10);
  271.             top_output(OUT_SCREEN, getlang("PokerBetTooLow"), outnum[0],
  272.                        outnum[1]);
  273.             return;
  274.             }
  275.  
  276.         if ((((tgame.player[plnum].totalbet + tmpbet) - tgame.highbet <
  277.             tgame.minbet) || ((tgame.player[plnum].totalbet + tmpbet) -
  278.             tgame.highbet > tgame.maxbet)) &&
  279.             ((tgame.player[plnum].totalbet + tmpbet) - tgame.highbet != 0))
  280.             {
  281.             poker_unlockgame(tgnum);
  282.             ultoa(tmpbet, outnum[0], 10);
  283.             ultoa(tgame.minbet, outnum[1], 10);
  284.             ultoa(tgame.maxbet, outnum[2], 10);
  285.             top_output(OUT_SCREEN, getlang("PokerInvalidBet"), outnum[0],
  286.                        outnum[1], outnum[2]);
  287.             return;
  288.             }
  289.  
  290.         if (tgame.maxrounds > -1 &&
  291.             tmpbet > tgame.highbet - tgame.player[plnum].totalbet &&
  292.             tgame.round >= tgame.maxrounds)
  293.             {
  294.             poker_unlockgame(tgnum);
  295.             top_output(OUT_SCREEN, getlang("PokerNoMoreRaise"));
  296.             return;
  297.             }
  298.  
  299.         ultoa(tgame.highbet - tgame.player[plnum].totalbet, outnum[7], 10);
  300.         ultoa(tmpbet - (tgame.highbet - tgame.player[plnum].totalbet),
  301.                         outnum[8], 10);
  302.  
  303.         if (tmpbet > tgame.highbet - tgame.player[plnum].totalbet)
  304.             {
  305.             tgame.numcalls = 0;
  306.             }
  307.  
  308.         tgame.player[plnum].totalbet += tmpbet;
  309.         tgame.highbet = tgame.player[plnum].totalbet;
  310.         tgame.pot += tmpbet;
  311.         tgame.numcalls++;
  312.  
  313.         poker_advanceturn(tgnum, &tgame);
  314.  
  315.         poker_savegame(tgnum, &tgame);
  316.         poker_unlockgame(tgnum);
  317.  
  318.         if (tmpbet == tgame.highbet - tgame.player[plnum].totalbet)
  319.             {
  320.             top_output(OUT_SCREEN, getlang("PokerYouCall"), outnum[7],
  321.                        getlang(strtoul(outnum[7], NULL, 10) == 1 ?
  322.                        "CDSingular" : "CDPlural"));
  323.             poker_sendmessage(MSG_GENERIC, 0, tgnum, 0,
  324.                               top_output(OUT_STRINGNF,
  325.                                          getlang("PokerMsgCall"),
  326.                                          outnum[0], user.handle, outnum[7],
  327.                                          getlang(strtoul(outnum[7], NULL, 10) == 1 ?
  328.                                          "CDSingular" : "CDPlural")),
  329.                               &tgame);
  330.             }
  331.         else
  332.             {
  333.             top_output(OUT_SCREEN, getlang("PokerYouRaise"), outnum[7],
  334.                        getlang(strtoul(outnum[7], NULL, 10) == 1 ?
  335.                        "CDSingular" : "CDPlural"), outnum[8],
  336.                        getlang(strtoul(outnum[8], NULL, 10) == 1 ?
  337.                        "CDSingular" : "CDPlural"));
  338.             poker_sendmessage(MSG_GENERIC, 0, tgnum, 0,
  339.                               top_output(OUT_STRINGNF,
  340.                                          getlang("PokerMsgRaise"),
  341.                                          outnum[0], user.handle, outnum[7],
  342.                                          getlang(strtoul(outnum[7], NULL, 10) == 1 ?
  343.                                          "CDSingular" : "CDPlural"), outnum[8],
  344.                                          getlang(strtoul(outnum[8], NULL, 10) == 1 ?
  345.                                          "CDSingular" : "CDPlural")),
  346.                               &tgame);
  347.             }
  348.  
  349.         return;
  350.         }
  351.  
  352.     if (!stricmp(get_word(2), "DISCARD"))
  353.         {
  354.         bettype = -1;
  355.         }
  356.     if (!stricmp(get_word(2), "STAND"))
  357.         {
  358.         bettype = -2;
  359.         }
  360.     if (bettype < 0)
  361.         {
  362.         unsigned char tlang1[31], tlang2[31];
  363.         XINT dcount = 0;
  364.  
  365.         poker_lockgame(tgnum);
  366.         poker_loadgame(tgnum, &tgame);
  367.  
  368.         if (!poker_checkturn(POKSTG_DISCARD, od_control.od_node, &tgame))
  369.             {
  370.             poker_unlockgame(tgnum);
  371.             itoa(tgnum, outnum[0], 10);
  372.             // Add bet/discard show support!!
  373.             top_output(OUT_SCREEN, getlang("PokerNotYourTurn"),
  374.                        getlang("Discard"), outnum[0]);
  375.             return;
  376.             }
  377.  
  378.         plnum = poker_getplayernum(POKPL_PLAYING, od_control.od_node,
  379.                                    &tgame);
  380.  
  381.         if (bettype == -1)
  382.             {
  383.             for (pgd = 0; pgd < tgame.numcards; pgd++)
  384.                 { // Max discard limit in future.
  385.                 if (strchr(&word_str[word_pos[3]], pgd + '1'))
  386.                     {
  387.                     if (tgame.player[plnum].cards[pgd] > -1)
  388.                         {
  389.                         tgame.deck[tgame.player[plnum].cards[pgd]] = 2;
  390.                         tgame.player[plnum].cards[pgd] = -1;
  391.                         }
  392.                     poker_dealcard(&tgame,
  393.                                    &tgame.player[plnum].cards[pgd]);
  394.  
  395.                     dcount++;
  396.                     }
  397.                 }
  398.             poker_sorthand(&tgame, tgame.player[plnum].cards);
  399.             }
  400.  
  401.         tgame.numcalls++;
  402.  
  403.         poker_advanceturn(tgnum, &tgame);
  404.  
  405.         poker_savegame(tgnum, &tgame);
  406.         poker_unlockgame(tgnum);
  407.  
  408.         itoa(dcount, outnum[8], 10);
  409.         top_output(OUT_SCREEN, getlang("PokerYouDiscard"), outnum[8],
  410.                    getlang(dcount == 1 ?
  411.                            "PokerDiscSingular" : "PokerDiscPlural")),
  412.         poker_sendmessage(MSG_GENERIC, 0, tgnum, 0,
  413.                           top_output(OUT_STRINGNF, getlang("PokerMsgDiscard"),
  414.                                      outnum[0], user.handle, outnum[8],
  415.                                      getlang(dcount == 1 ?
  416.                                              "PokerDiscSingular" :
  417.                                              "PokerDiscPlural")),
  418.                           &tgame);
  419.  
  420.         if (bettype == -1)
  421.             {
  422.             for (pgd = 0; pgd < tgame.numcards; pgd++)
  423.                 { // Max discard limit in future.
  424.                 if (strchr(&word_str[word_pos[3]], pgd + '1'))
  425.                     {
  426.                     itoa(tgame.cardvals[tgame.player[plnum].cards[pgd]],
  427.                          outnum[0], 10);
  428.                     sprintf(tlang1, "CardLongSingValue%s", outnum[0]);
  429.                     itoa(tgame.cardsuits[tgame.player[plnum].cards[pgd]] + 1,
  430.                          outnum[0], 10);
  431.                     sprintf(tlang2, "CardLongPluSuit%s", outnum[0]);
  432.                     top_output(OUT_SCREEN, getlang("PokerYouAreDealt"),
  433.                                getlang(tlang1), getlang(tlang2));
  434.                     }
  435.                 }
  436.             }
  437.  
  438.         return;
  439.         }
  440.  
  441.      if (!stricmp(get_word(2), "FOLD"))
  442.         {
  443.         poker_lockgame(tgnum);
  444.         poker_loadgame(tgnum, &tgame);
  445.         itoa(tgnum, outnum[0], 10);
  446.         if (poker_getplayernum(POKPL_PLAYING, od_control.od_node,
  447.             &tgame) < 0)
  448.             {
  449.             poker_unlockgame(tgnum);
  450.             top_output(OUT_SCREEN, getlang("PokerNotPlaying"), outnum[0]);
  451.             return;
  452.             }
  453.         poker_foldplayer(od_control.od_node, tgnum, &tgame);
  454.         poker_savegame(tgnum, &tgame);
  455.         poker_unlockgame(tgnum);
  456.         top_output(OUT_SCREEN, getlang("PokerYouFold"));
  457.         poker_sendmessage(MSG_GENERIC, 1, tgnum, 0,
  458.                           top_output(OUT_STRINGNF,
  459.                                      getlang("PokerMsgFold"),
  460.                                      outnum[0], user.handle,
  461.                                      getlang(user.gender == 1 ?
  462.                                              "Her" : "His")),
  463.                           &tgame);
  464.         }
  465.  
  466.     }
  467.