home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / GAMES.ZIP / OLDPOKER.ZIP / OLDPK.C < prev    next >
C/C++ Source or Header  |  1995-04-02  |  13KB  |  360 lines

  1. #include "top.h"
  2.  
  3. void poker_game(void)//////!!!!!!!!!!!Entire series of modules
  4. {
  5. char wasused = 0;
  6. poker_game_typ tgame;
  7. poker_player_typ tplyr; ////proc
  8. unsigned long tmpbet;
  9.  
  10. if (!stricmp(get_word(1), "BET") || !stricmp(get_word(1), "RAISE") ||
  11.     !stricmp(get_word(1), "CALL"))
  12.     {
  13.     poker_loadgamedata(&tgame);
  14.     if (tgame.currentturn != od_control.od_node ||
  15.         tgame.gameprogress == 50)
  16.         {
  17.         top_output(OUT_SCREEN, getlang("PokerNotYourTurn"));
  18.         }
  19.     else
  20.         {
  21.         poker_loadplyrdata(od_control.od_node, &tplyr);
  22.         if (!get_word_char(2, 0) && stricmp(get_word(1), "CALL"))
  23.             {
  24.             top_output(OUT_SCREEN, getlang("PokerNoBet"),  ///!!! below
  25.                        !stricmp(get_word(1), "RAISE") ? "RAISE" : "BET");
  26.             }
  27.         else
  28.             {
  29.             if (!stricmp(get_word(1), "CALL"))
  30.                 {
  31.                 tmpbet = tgame.highbet - tplyr.totalbet;
  32.                 }
  33.             else
  34.                 {
  35.                 tmpbet = 0;
  36.                 if (!stricmp(get_word(1), "RAISE"))
  37.                     {
  38.                     tmpbet = tgame.highbet - tplyr.totalbet;
  39.                     }
  40.                 tmpbet += strtoul(get_word(2), NULL, 10);
  41.                 }
  42.  
  43.             if (tmpbet > user.cybercash)
  44.                 {
  45.                 ultoa(tmpbet, outnum[0], 10);
  46.                 ultoa(user.cybercash, outnum[1], 10);
  47.                 top_output(OUT_SCREEN, getlang("PokerNotEnoughCash"),
  48.                            outnum[0], outnum[1]);
  49.                 }
  50.             else
  51.                 {
  52.                 if (tplyr.totalbet + tmpbet < tgame.highbet)
  53.                     {
  54.                     ultoa(tmpbet, outnum[0], 10);
  55.                     ultoa(tgame.highbet - tplyr.totalbet, outnum[1], 10);
  56.                     top_output(OUT_SCREEN, getlang("PokerBetTooLow",
  57.                                outnum[0], outnum[1]);
  58.                     }
  59.                 else
  60.                     {
  61.                     if ((((tplyr.totalbet + tmpbet) - tgame.highbet <
  62.                         cfg.pokerminbet) || ((tplyr.totalbet + tmpbet) -
  63.                         tgame.highbet > cfg.pokermaxbet)) && ((tplyr.totalbet
  64.                         + tmpbet) - tgame.highbet != 0))
  65.                         {
  66.                         ultoa(cfg.pokerminbet, outnum[0], 10);
  67.                         ultoa(cfg.pokermaxbet, outnum[1], 10);
  68.                         top_output(OUT_SCREEN, getlang("PokerInvalidBet"),
  69.                                    outnum[0], outnum[1]);
  70.                         }
  71.                     else
  72.                         {
  73.                         if (tmpbet == tgame.highbet - tplyr.totalbet)
  74.                             {
  75.                             ultoa(tmpbet, outnum[0], 10);
  76.                             top_output(OUT_SCREEN, getlang("PokerCall"),
  77.                                        outnum[0],
  78.                                        getlang(tmpbet == 1 ? "CDSingular" :
  79.                                                "CDPlural"));
  80.                             }
  81.                         else
  82.                             {
  83.                             ultoa(tgame.highbet - tplyr.totalbet,
  84.                                   outnum[0], 10);
  85.                             ultoa(tmpbet - (tgame.highbet - tplyr.totalbet),
  86.                                   outnum[1], 10);
  87.                             top_output(OUT_SCREEN, getlang("PokerRaise"),
  88.                                        outnum[0],
  89.                                        getlang((tgame.highbet -
  90.                                                 tplyr.totalbet) == 1 ?
  91.                                                "CDSingular" : "CDPlural"),
  92.                                        outnum[1],
  93.                                        getlang((tmpbet - (tgame.highbet -
  94.                                                 tplyr.totalbet)) == 1 ?
  95.                                                 "CDSingular" : "CDPlural"));
  96.                             }
  97.                         tplyr.thisbet = tmpbet;
  98.                         poker_saveplyrdata(od_control.od_node,
  99.                                            &tplyr);
  100.                         check_nodes_used(1);
  101.                         dispatch_message(MSG_POKER, "Bet", lowestnode,
  102.                                          1, 0);
  103.                         user.cybercash -= tmpbet;
  104.                         save_user_data(user_rec_num, &user);
  105.                         }
  106.                     }
  107.                 }
  108.             }
  109.         }
  110.     wasused = 1;
  111.     }
  112. if (!stricmp(get_word(1), "DISCARD") || !stricmp(get_word(1), "STAND"))
  113.     {
  114.     XINT dd, disd;
  115.  
  116.     poker_loadgamedata(&tgame);
  117.     if (tgame.currentturn != od_control.od_node ||
  118.         tgame.gameprogress != 50)
  119.         {
  120.         top_output(OUT_SCREEN, "PokerNoDiscardYet");
  121.         }
  122.     else
  123.         {
  124.         poker_loadplyrdata(od_control.od_node, &tplyr);
  125.         for (dd = 0, disd = 0; dd < 5; dd++)
  126.             {
  127.             tplyr.discards[dd] = 0;
  128.             if (!stricmp(get_word(1), "DISCARD") &&
  129.                 strchr(word_str, dd + '1'))
  130.                 {
  131.                 tplyr.discards[dd] = 1;
  132.                 disd++;
  133.                 }
  134.             }
  135.         poker_saveplyrdata(od_control.od_node, &tplyr);
  136.         check_nodes_used(1);
  137.         dispatch_message(MSG_POKER, "Discard", lowestnode, 1, 0);
  138.         itoa(disd, outnum[0], 10);
  139.         top_output(OUT_SCREEN, getlang("PokerYouDiscard"),
  140.                    outnum[0],
  141.                    getlang(disd == 1 ? "CDSingular" : "CDPlural"));
  142.         }
  143.     wasused = 1;
  144.     }
  145. if (!stricmp(get_word(1), "FOLD"))
  146.     {
  147.     char tbit;
  148.  
  149.     poker_loadintable(od_control.od_node, 3, &tbit);
  150.     if (!tbit)
  151.         {
  152.         top_output(OUT_SCREEN, getlang("PokerNotPlaying"));
  153.         }
  154.     else
  155.         {
  156.         check_nodes_used(1);
  157.         dispatch_message(MSG_POKER, "Fold", lowestnode, 1, 0);
  158.         top_output(OUT_SCREEN, getlang("PokerYouFold"));
  159.         }
  160.     wasused = 1;
  161.     }
  162. if (!stricmp(get_word(1), "HAND"))
  163.     {
  164.     XINT hsd;
  165.  
  166.     char tbit;
  167.  
  168.     poker_loadintable(od_control.od_node, 3, &tbit);
  169.     if (!tbit)
  170.         {
  171.         top_output(OUT_SCREEN, getlang("PokerNotPlaying"));
  172.         }
  173.     else
  174.         {
  175.         poker_loadplyrdata(od_control.od_node, &tplyr);
  176.         poker_sorthand(&tplyr);
  177.         poker_saveplyrdata(od_control.od_node, &tplyr);
  178.         // Need to enhance to show big fancy cards, etc.
  179.         top_output(OUT_SCREEN, getlang("PokerYourHand")); ///~~
  180.         for (hsd = 0; hsd < 5; hsd++) // 5 = numcards
  181.             {
  182.             // Line below needs mods to display low ascii suit if ibmchars on
  183.             sprintf(outbuf, "^H^%c%c%c%s",
  184.                     (tplyr.cards[hsd] % 4) > 1 ? 'm' : 'a',
  185.                     card_symbols[tplyr.cards[hsd] % 13],
  186.                     card_suits[tplyr.cards[hsd] % 4],
  187.                     hsd == 4 ? "^A\r\n" : "^A ");
  188.             top_output(OUT_SCREEN, outbuf);
  189.             }
  190.         sprintf(outbuf, "%s^p\r\n", poker_gethandname(&tplyr));
  191.         top_output(OUT_SCREEN, outbuf);
  192.         }
  193.     wasused = 1;
  194.     }
  195. if (!stricmp(get_word(1), "POT"))
  196.     {
  197.     poker_loadgamedata(&tgame);
  198.     sprintf(outbuf, "\r\n^nThe current Poker pot is ^l%lu^n "
  199.             "CyberDollar%s.\r\n", tgame.pot, tgame.pot == 1 ? "" : "s");
  200.     top_output(OUT_SCREEN, outbuf);
  201.     wasused = 1;
  202.     }
  203. if (!stricmp(get_word(1), "TURN"))
  204.     {
  205.     poker_loadgamedata(&tgame);
  206.     if (tgame.gameon)
  207.         {
  208.         sprintf(outbuf, "\r\n^nIt is currently ^l%s^n's turn to "
  209.                 "^k%s^n in Poker.\r\n", handles[tgame.currentturn].string,
  210.                 tgame.gameprogress == 50 ? "discard" : "bet");
  211.         top_output(OUT_SCREEN, outbuf);
  212.         if (tgame.gameprogress != 50 &&
  213.             tgame.currentturn == od_control.od_node)
  214.             {
  215.             poker_loadplyrdata(od_control.od_node, &tplyr);
  216.             sprintf(outbuf, "^nYou must bet at least ^l%lu^n "
  217.                     "CyberDollar%s to stay in.\r\n",
  218.                     tgame.highbet - tplyr.totalbet,
  219.                     (tgame.highbet - tplyr.totalbet) == 1 ? "" : "s");
  220.             top_output(OUT_SCREEN, outbuf);
  221.             }
  222.         }
  223.     else
  224.         {
  225.         top_output(OUT_SCREEN, "\r\n^mThere is no ^pPoker^m game currently "
  226.                    "underway!\r\n");
  227.         }
  228.     wasused = 1;
  229.     }
  230. if (!stricmp(get_word(1), "SCAN") || !stricmp(get_word(1), "WHO"))
  231.     {
  232.     char *tmpin1, *tmpin2;
  233.     XINT whod;
  234.  
  235.     tmpin1 = farmalloc(MAXNODES);
  236.     if (!tmpin1)
  237.         {
  238.         top_output(OUT_SCREEN, "\r\n^I^mCan't SCAN Poker!^A^p\r\n");
  239.         return;
  240.         }
  241.     tmpin2 = farmalloc(MAXNODES);
  242.     if (!tmpin2)
  243.         {
  244.         top_output(OUT_SCREEN, "\r\n^I^mCan't SCAN Poker!^A^p\r\n");
  245.         dofree(tmpin1);
  246.         return;
  247.         }
  248.  
  249.     poker_loadintable(0, 0, tmpin1);
  250.     poker_loadintable(0, 2, tmpin2);
  251.  
  252.     if (poker_count(tmpin1) == 0)
  253.         {
  254.         top_output(OUT_SCREEN, "\r\n^mNobody is currently playing ^pPoker^m!\r\n");
  255.         }
  256.     else
  257.          {
  258.         top_output(OUT_SCREEN, "\r\n\r\n             ^pPeople Playing Poker\r\n");
  259.         top_output(OUT_SCREEN, "^c+--------------------------------+----------+\r\n");
  260.         top_output(OUT_SCREEN, "| ^mHandle                         ^c| ^mPlaying? ^c|\r\n");
  261.         top_output(OUT_SCREEN, "+--------------------------------+----------+\r\n");
  262.         for (whod = 0; whod < MAXNODES; whod++)
  263.             {
  264.             if (tmpin1[whod])
  265.                 {
  266.                 sprintf(outbuf, "| ^n%-30s ^c|   %s    ^c|\r\n",
  267.                         handles[whod].string,
  268.                         tmpin2[whod] ? "^kYes" : "^h No");
  269.                 top_output(OUT_SCREEN, outbuf);
  270.                 }
  271.             }
  272.         top_output(OUT_SCREEN, "+--------------------------------+----------+\r\n\r\n");
  273.         }
  274.     dofree(tmpin1); dofree(tmpin2);
  275.     wasused = 1;
  276.     }
  277. // View      - Load cards of other player, show upcards (Stud only).
  278. if (!stricmp(get_word(1), "ON"))
  279.     {
  280.     if (user.cybercash < cfg.pokerante)
  281.         {
  282.         ultoa(cfg.pokerante, outnum[0], 10);
  283.         ultoa(user.cybercash, outnum[1], 10);
  284.         top_output(OUT_SCREEN, "@c^mYou don't have enough CyberCash to play "
  285.                    "Poker!  (Needed = ^l@1^m, CyberCash = ^l@2^m)@c",
  286.                    outnum[0], outnum[1]);
  287.         return;
  288.         }
  289.  
  290.     check_nodes_used(1);
  291.     dispatch_message(MSG_POKER, "WantIn", lowestnode, 1, 0);
  292.     top_output(OUT_SCREEN, "\r\n^kProcessing ^pPoker^k request.\r\n");
  293.     wasused = 1;
  294.     }
  295. if (!stricmp(get_word(1), "OFF"))
  296.     {
  297.     check_nodes_used(1);
  298.     dispatch_message(MSG_POKER, "WantOut", lowestnode, 1, 0);
  299.     top_output(OUT_SCREEN, "\r\n^kOkay, you will no longer be playing in any "
  300.                "^pPoker^k games.\r\n");
  301.     wasused = 1;
  302.     }
  303. if (!stricmp(get_word(1), "CHEAT!"))
  304.     {
  305.     poker_loadgamedata(&tgame);
  306.     if (atoi(get_word(2)) < 0 || atoi(get_word(2)) > 51)
  307.         {
  308.         top_output(OUT_SCREEN, "\r\nBad physical card number (should be 0-51)!\r\n");
  309.         }
  310.     else
  311.         {
  312.         if (atoi(get_word(3)) < 0 || atoi(get_word(3)) > 4)
  313.             {
  314.             top_output(OUT_SCREEN, "\r\n^mBad hand card number (should be 0-4)!\r\n");
  315.             }
  316.         else
  317.             {
  318.             if (tgame.cardsused[atoi(get_word(2))])
  319.                 {
  320.                 top_output(OUT_SCREEN, "\r\n^mCard is in use!\r\n");
  321.                 }
  322.             else
  323.                 {
  324.                 poker_loadplyrdata(od_control.od_node, &tplyr);
  325.                 tgame.cardsused[tplyr.cards[atoi(get_word(3))]] = 0;
  326.                 tgame.cardsused[atoi(get_word(2))] = 1;
  327.                 tplyr.cards[atoi(get_word(3))] = atoi(get_word(2));
  328.                 poker_saveplyrdata(od_control.od_node, &tplyr);
  329.                 poker_savegamedata(&tgame);
  330.                 top_output(OUT_SCREEN, "\r\n^I^mOooo, sneaky!^A \r\n");
  331.                 }
  332.             }
  333.         }
  334.     wasused = 1;
  335.     }
  336.  
  337. if (!wasused)
  338.     {
  339.     top_output(OUT_SCREEN, "\r\n\r\n^oTOP Poker ^h- ^pCommands\r\n");
  340.     top_output(OUT_SCREEN, "^c--------------------\r\n\r\n");
  341.     top_output(OUT_SCREEN, "^lHELP          ^g- ^mThis help screen.\r\n");
  342.     top_output(OUT_SCREEN, "^lBET xxxxx     ^g- ^mMake a bet of xxxxx CyberDollars.\r\n");
  343.     top_output(OUT_SCREEN, "^lCALL          ^g- ^mCall the current bet.\r\n");
  344.     top_output(OUT_SCREEN, "^lRAISE xxxxx   ^g- ^mRaise the bet by xxxxx CyberDollars.\r\n");
  345.     top_output(OUT_SCREEN, "^lDISCARD 12345 ^g- ^mDiscard card numbers.  Omit a number to keep that card.\r\n");
  346.     top_output(OUT_SCREEN, "^lSTAND         ^g- ^mStand (discard no cards).\r\n");
  347.     top_output(OUT_SCREEN, "^lFOLD          ^g- ^mFold your hand.\r\n");
  348.     top_output(OUT_SCREEN, "^lHAND          ^g- ^mView your hand.\r\n");
  349.     top_output(OUT_SCREEN, "^lPOT           ^g- ^mView the current pot.\r\n");
  350.     top_output(OUT_SCREEN, "^lTURN          ^g- ^mSee who's turn it is.\r\n");
  351.     top_output(OUT_SCREEN, "^lWHO           ^g- ^mSee who is playing.\r\n");
  352.     top_output(OUT_SCREEN, "^lSCAN          ^g- ^mSee who is playing.\r\n");
  353. //    top_output(OUT_SCREEN, "^lVIEW player   ^g- ^mView player's upcards (Stud Poker only).\r\n");
  354.     top_output(OUT_SCREEN, "^lON            ^g- ^mTurn Poker on!\r\n");
  355.     top_output(OUT_SCREEN, "^lOFF           ^g- ^mTurn Poker off.\r\n");
  356.     top_output(OUT_SCREEN, "\r\n");
  357.     }
  358.  
  359. }
  360.