home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / GAMES.ZIP / OLDPOKER.ZIP / OLDPKCOR.C < prev    next >
C/C++ Source or Header  |  1995-03-09  |  9KB  |  280 lines

  1. #include "top.h"
  2.  
  3. void poker_core(XINT task, XINT fromnode)
  4. {
  5. XINT pd, pcc;
  6. char tcards[10], tmpbit, *whos_in;
  7. poker_game_typ tgame;
  8. poker_player_typ tplyr;
  9.  
  10. whos_in = farmalloc(MAXNODES);
  11. if (!whos_in)
  12.     {
  13.     dispatch_message(MSG_GENERIC, "^I^mNot enough memory to play Poker!^A^p",
  14.                      od_control.od_node, 0, 0);
  15.     return;
  16.     }
  17.  
  18. poker_loadgamedata(&tgame);
  19. switch(task)
  20.     {
  21.     case POKER_START:
  22.         poker_loadintable(0, 0, whos_in);
  23.         poker_saveintable(0, 2, whos_in);
  24.  
  25.         memset(&tgame, 0, sizeof(poker_game_typ));
  26. //        tgame.gametype = POKGAME_5DRAW;
  27.  
  28.         for (pd = 0; pd < MAXNODES; pd++)
  29.             {
  30.             if (!whos_in[pd])
  31.                 {
  32.                 continue;
  33.                 }
  34.  
  35.             for (pcc = 0; pcc < 5; pcc++)
  36.                 {
  37.                 do
  38.                     {
  39.                     tcards[pcc] = random(52);
  40.                     }
  41.                 while(tgame.cardsused[tcards[pcc]]);
  42.                 tgame.cardsused[tcards[pcc]] = 1;
  43.                 }
  44.  
  45.             memset(&tplyr, 0, sizeof(poker_player_typ));
  46.             memcpy(tplyr.cards, tcards, 10L);
  47.             poker_sorthand(&tplyr);
  48.             poker_saveplyrdata(pd, &tplyr);
  49.             }
  50.  
  51.         for (pd = 0; pd < MAXNODES; pd++)
  52.             {
  53.             if (whos_in[pd])
  54.                 {
  55.                 dispatch_message(MSG_POKER, "GameOn", pd, 1, 0);
  56.                 }
  57.             }
  58.         tgame.roundprogress = 0;
  59.         poker_advanceturn(-1, whos_in, &tgame);
  60.         tgame.acehigh = 1;
  61.         tgame.pot += ((long) poker_count(whos_in) * cfg.pokerante);
  62.         tgame.gameon = 1;
  63.         break;
  64.     case POKER_BETIN:
  65.         poker_loadplyrdata(fromnode, &tplyr);
  66.         if (tplyr.totalbet + tplyr.thisbet == tgame.highbet)
  67.             {
  68.             tgame.roundprogress++;
  69.             sprintf(outbuf, "^l%s^n calls the ^kPoker^n bet.  "
  70.                     "(^l%lu^n CyberDollar%s)", handles[fromnode].string,
  71.                     tplyr.thisbet, tplyr.thisbet == 1 ? "" : "s");
  72.             }
  73.         else
  74.             {
  75.             tgame.roundprogress = 1;
  76.             sprintf(outbuf, "^l%s^n calls the ^kPoker^n bet "
  77.                     "(^l%lu^n CyberDollar%s), and raises by ^l%lu^n "
  78.                     "CyberDollar%s!", handles[fromnode].string,
  79.                     tgame.highbet - tplyr.totalbet,
  80.                     (tgame.highbet - tplyr.totalbet) == 1 ? "" : "s",
  81.                     tplyr.thisbet - (tgame.highbet - tplyr.totalbet),
  82.                     (tplyr.thisbet - (tgame.highbet - tplyr.totalbet)) == 1 ?
  83.                         "" : "s");
  84.             }
  85.  
  86.         poker_loadintable(0, 0, whos_in);
  87.         for (pcc = 0; pcc < MAXNODES; pcc++)
  88.             {
  89.             if (whos_in[pcc] && pcc != fromnode)
  90.                 {
  91.                 dispatch_message(MSG_GENERIC, outbuf, pcc, 1, 0);
  92.                 }
  93.             }
  94.  
  95.         tplyr.totalbet += tplyr.thisbet;
  96.         tgame.highbet = tplyr.totalbet;
  97.         tgame.pot += tplyr.thisbet;
  98.         tplyr.numnags = 0;
  99.         poker_saveplyrdata(fromnode, &tplyr);
  100.         poker_loadintable(0, 2, whos_in);
  101.         pcc = poker_lownode(fromnode, whos_in);
  102.         poker_advanceturn(pcc, whos_in, &tgame);
  103.         break;
  104.     case POKER_DISCIN:
  105.         poker_loadplyrdata(fromnode, &tplyr);
  106.         memcpy(&tcards[0], &tplyr.cards[0], 10L);
  107.  
  108.         poker_shuffle(tcards);
  109.  
  110.         for (pd = 0; pd < 5; pd++) // 5---> numcards
  111.             {
  112.             if (tplyr.discards[pd])
  113.                 {
  114.                 tgame.cardsused[tcards[pd]] = 2;
  115.                 do
  116.                     {
  117.                     tcards[pd] = random(52);
  118.                     }
  119.                 while(tgame.cardsused[tcards[pd]]);
  120.                 tgame.cardsused[tcards[pd]] = 1;
  121.                 sprintf(outbuf, "^pYou draw a%s ^k%s^p of "
  122.                         "^k%ss^p!", (tcards[pd] % 13 == 0) ||
  123.                         (tcards[pd] % 13 == 7) ? "n" : "",
  124.                         card_names[tcards[pd] % 13],
  125.                         card_suitnames[tcards[pd] % 4]);
  126.                 dispatch_message(MSG_GENERIC, outbuf, fromnode, 1, 0);
  127.                 }
  128.             }
  129.  
  130.             {
  131.             XINT ddis;
  132.  
  133.             for (pcc = 0, ddis = 0; pcc < 5; pcc++)
  134.                 {
  135.                 if (tplyr.discards[pcc])
  136.                     {
  137.                     ddis++;
  138.                     }
  139.                 }
  140.  
  141.             sprintf(outbuf, "^l%s^n discards ^l%i^n card%s.",
  142.                     handles[fromnode].string, ddis, ddis == 1 ? "" : "s");
  143.             }
  144.         poker_loadintable(0, 0, whos_in);
  145.         for (pcc = 0; pcc < MAXNODES; pcc++)
  146.             {
  147.             if (whos_in[pcc] && pcc != fromnode)
  148.                 {
  149.                 dispatch_message(MSG_GENERIC, outbuf, pcc, 1, 0);
  150.                 }
  151.             }
  152.  
  153.         memcpy(tplyr.cards, tcards, 10L);
  154.         poker_sorthand(&tplyr);
  155.         tplyr.numnags = 0;
  156.         poker_saveplyrdata(fromnode, &tplyr);
  157.         poker_loadintable(0, 2, whos_in);
  158.         tgame.roundprogress++;
  159.         pcc = poker_lownode(fromnode, whos_in);
  160.         poker_advanceturn(pcc, whos_in, &tgame);
  161.         break;
  162.     case POKER_FOLDIN:
  163.         poker_loadplyrdata(fromnode, &tplyr);
  164.         tmpbit = 0;
  165.         poker_saveintable(fromnode, 3, &tmpbit);
  166.         for (pd = 0; pd < 5; pd++)
  167.             {
  168.             tgame.cardsused[tplyr.cards[pd]] = 2;
  169.             }
  170.  
  171.             {
  172.             node_idx_typ tnidx;
  173.  
  174.             get_node_data(fromnode, &tnidx);
  175.             sprintf(outbuf, "^l%s^n folds %s ^kPoker^n hand.",
  176.                     handles[fromnode].string,
  177.                     tnidx.gender == 0 ? "his" : "her");
  178.             }
  179.         poker_loadintable(0, 0, whos_in);
  180.         for (pcc = 0; pcc < MAXNODES; pcc++)
  181.             {
  182.             if (whos_in[pcc] && pcc != fromnode)
  183.                 {
  184.                 dispatch_message(MSG_GENERIC, outbuf, pcc, 1, 0);
  185.                 }
  186.             }
  187.  
  188.         poker_loadintable(0, 2, whos_in);
  189.         if (fromnode == tgame.currentturn)
  190.             {
  191.             pcc = poker_lownode(fromnode, whos_in);
  192.             poker_advanceturn(pcc, whos_in, &tgame);
  193.             }
  194.         if (poker_count(whos_in) <= 1 && tgame.gameon)
  195.             {
  196.             poker_advanceturn(-1, whos_in, &tgame);
  197.             }
  198.         break;
  199.     case POKER_WANTIN:
  200.         poker_loadintable(0, 0, whos_in);
  201.         if (poker_count(whos_in) < 9)
  202.             {
  203.             tmpbit = 1;
  204.             poker_saveintable(fromnode, 1, &tmpbit);
  205.             dispatch_message(MSG_POKER, "You'reIn", fromnode, 1, 0);
  206.  
  207.             sprintf(outbuf, "^l%s^n asks to be dealt into the next "
  208.                     "^kPoker^n game!", handles[fromnode].string);
  209.             poker_loadintable(0, 0, whos_in);
  210.             for (pcc = 0; pcc < MAXNODES; pcc++)
  211.                 {
  212.                 if (whos_in[pcc] && pcc != fromnode)
  213.                     {
  214.                     dispatch_message(MSG_GENERIC, outbuf, pcc, 1, 0);
  215.                     }
  216.                 }
  217.             }
  218.         else
  219.             {
  220.             dispatch_message(MSG_POKER, "TooManyPeople", fromnode, 1, 0);
  221.             }
  222.         break;
  223.     case POKER_WANTOUT:
  224.         sprintf(outbuf, "^l%s^n asks to be dealt out of the next "
  225.                 "^kPoker^n game.", handles[fromnode].string);
  226.         poker_loadintable(0, 0, whos_in);
  227.         for (pcc = 0; pcc < MAXNODES; pcc++)
  228.             {
  229.             if (whos_in[pcc] && pcc != fromnode)
  230.                  {
  231.                 dispatch_message(MSG_GENERIC, outbuf, pcc, 1, 0);
  232.                 }
  233.             }
  234.         poker_loadintable(fromnode, 3, &tmpbit);
  235.         if (tmpbit)
  236.             {
  237.             for (pd = 0; pd < 5; pd++)
  238.                 {
  239.                 tgame.cardsused[tplyr.cards[pd]] = 2;
  240.                 }
  241.  
  242.                 {
  243.                 node_idx_typ tnidx;
  244.  
  245.                 get_node_data(fromnode, &tnidx);
  246.                 sprintf(outbuf, "^l%s^n folds %s ^kPoker^n hand.",
  247.                         handles[fromnode].string,
  248.                         tnidx.gender == 0 ? "his" : "her");
  249.                 }
  250.             poker_loadintable(0, 0, whos_in);
  251.             for (pcc = 0; pcc < MAXNODES; pcc++)
  252.                 {
  253.                 if (whos_in[pcc] && pcc != fromnode)
  254.                     {
  255.                     dispatch_message(MSG_GENERIC, outbuf, pcc, 1, 0);
  256.                     }
  257.                 }
  258.             }
  259.         tmpbit = 0;
  260.         poker_saveintable(fromnode, 1, &tmpbit);
  261.         poker_saveintable(fromnode, 3, &tmpbit);
  262.         poker_loadintable(0, 2, whos_in);
  263.         if (fromnode == tgame.currentturn)
  264.             {
  265.             pcc = poker_lownode(fromnode, whos_in);
  266.             poker_advanceturn(pcc, whos_in, &tgame);
  267.             }
  268.         if (poker_count(whos_in) <= 1 && tgame.gameon)
  269.             {
  270.             poker_advanceturn(-1, whos_in, &tgame);
  271.             }
  272.         break;
  273.     }
  274. poker_savegamedata(&tgame);
  275.  
  276. dofree(whos_in);
  277.  
  278. return;
  279. }
  280.