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

  1. #include "top.h"
  2.  
  3. XINT poker_startnewgame(poker_game_typ *sgame)
  4.     {
  5.     XINT std, sgres;
  6.     XINT newgamenum = -1;
  7.  
  8.     for (std = 0; std < cfg.pokermaxgames; std++)
  9.         {
  10.         poker_lockgame(std);
  11.         sgame->inuse = 0;
  12.         sgres = poker_loadgame(std, sgame);
  13.  
  14.         if (!sgame->inuse || !sgres)
  15.             {
  16.             pokermaingame = newgamenum = std;
  17.             poker_initnew(sgame);
  18.             poker_savegame(std, sgame);
  19.             poker_unlockgame(std);
  20.             break;
  21.             }
  22.         poker_unlockgame(std);
  23.         }
  24.  
  25.     return newgamenum;
  26.     }
  27.  
  28. void poker_initnew(poker_game_typ *newgame)
  29.     {
  30.     XINT ind, ine;
  31.  
  32.     memset(newgame, 0, sizeof(poker_game_typ));
  33.  
  34.     for (ind = 0; ind < POKERMAXPLAYERS; ind++)
  35.         {
  36.         newgame->wanttoplay[ind] = -1;
  37.         newgame->started[ind] = 0;
  38.         newgame->finished[ind] = 0;
  39.         newgame->winners[ind] = 0;
  40.         newgame->player[ind].node = -1;
  41.         for (ine = 0; ine < POKERMAXCARDS; ine++)
  42.             {
  43.             newgame->player[ind].cards[ine] = -1;
  44.             }
  45.         }
  46.  
  47.     newgame->inuse = 1;
  48.  
  49.     newgame->dealer = od_control.od_node;
  50.  
  51.     newgame->rules = POKRULE_ACEHIGH;
  52.  
  53.     newgame->minbet = cfg.pokerminbet; // Cfg! (def)
  54.     newgame->maxbet = cfg.pokermaxbet; // Cfg! (def)
  55.     newgame->ante = cfg.pokerante; // Cfg! (def)
  56.  
  57.     newgame->maxrounds = -1; // Cfg!
  58.     newgame->maxcycles = 1; // Cfg! (def)
  59.  
  60.     newgame->minpl = 2; // Cfg!
  61.     newgame->maxpl = 8; // Cfg!
  62.     newgame->minai = 0; // Cfg!
  63.     newgame->maxai = 0; // Cfg!
  64.  
  65.     newgame->wildcards[13] = 1; // Cfg!
  66.     newgame->decksize = 52;
  67.     if (newgame->rules & POKRULE_USEJOKERS)
  68.         {
  69.         newgame->decksize += 2;
  70.         }
  71.     newgame->numcards = 5; // Cfg! (via game type)
  72.  
  73.     newgame->delaytime = 20; // Cfg!
  74.  
  75.     newgame->wanttoplay[0] = od_control.od_node;
  76.     newgame->wtpcount = 1;
  77.  
  78.     newgame->eventtime = time(NULL);
  79.  
  80.     poker_resetgame(newgame);
  81.  
  82.     }
  83.  
  84. void poker_resetgame(poker_game_typ *rgame)
  85.     {
  86.     XINT rgd;
  87.  
  88.     for (rgd = 0; rgd < POKERMAXPLAYERS; rgd++)
  89.         {
  90.         rgame->player[rgd].totalbet = 0;
  91.         }
  92.  
  93.     rgame->highbet = 0;
  94.     rgame->pot = 0;
  95.  
  96.     rgame->cycle = -1;
  97.     rgame->stage = -1;
  98.     rgame->round = -1;
  99.     rgame->turn = -1;
  100.  
  101.     rgame->numcalls = 0;
  102.  
  103.     memset(rgame->started, 0, POKERMAXPLAYERS);
  104.     memset(rgame->finished, 0, POKERMAXPLAYERS);
  105.  
  106.     }
  107.  
  108. void poker_dealhand(poker_game_typ *dhgame, char *cardbuf)
  109.     {
  110.     XINT deald;
  111.  
  112.     for (deald = 0; deald < dhgame->numcards; deald++)
  113.         {
  114.         poker_dealcard(dhgame, &cardbuf[deald]);
  115.         }
  116.  
  117.     poker_sorthand(dhgame, cardbuf);
  118.  
  119.     }
  120.  
  121. void poker_dealcard(poker_game_typ *dgame, char *dcard)
  122.     {
  123.     char dct, dcd;
  124.  
  125.     for (dcd = 0, dct = 0; dcd < dgame->decksize; dcd++)
  126.         {
  127.         if (!dgame->deck[dcd])
  128.             {
  129.             dct++;
  130.             }
  131.         }
  132.  
  133.     if (dct == dgame->decksize)
  134.         {
  135.         poker_shuffle(dgame);
  136.         }
  137.  
  138.     do
  139.         {
  140.         dct = random(dgame->decksize);
  141.         }
  142.     while (dgame->deck[dct]);
  143.  
  144.     *dcard = dct;
  145.     dgame->deck[dct] = 1;
  146.  
  147.     }
  148.  
  149. void poker_shuffle(poker_game_typ *shufgame)
  150.     {
  151.     XINT shd;
  152.  
  153.     for (shd = 0; shd < shufgame->decksize; shd++)
  154.         {
  155.         if (shufgame->deck[shd] == 2)
  156.             {
  157.             shufgame->deck[shd] = 0;
  158.             }
  159.         }
  160.  
  161.     }
  162.  
  163. char poker_joingame(XINT gamenum, poker_game_typ *jgame)
  164.     {
  165.     XINT jgd, newplnum = -1;
  166.  
  167.     poker_lockgame(gamenum);
  168.     poker_loadgame(gamenum, jgame);
  169.  
  170.     for (jgd = 0; jgd < jgame->maxpl; jgd++)
  171.         {
  172.         if (jgame->wanttoplay[jgd] == -1)
  173.             {
  174.             newplnum = jgd;
  175.             break;
  176.             }
  177.         }
  178.  
  179.     if (newplnum == -1)
  180.         {
  181.         poker_unlockgame(gamenum);
  182.         itoa(gamenum, outnum[0], 10);
  183.         top_output(OUT_SCREEN, getlang("PokerTooManyPeople"), outnum[0]);
  184.         return 0;
  185.         }
  186.  
  187.     jgame->wanttoplay[jgd] = od_control.od_node;
  188.     jgame->wtpcount++;
  189.  
  190.     poker_savegame(gamenum, jgame);
  191.     poker_unlockgame(gamenum);
  192.  
  193.     return 1;
  194.     }
  195.  
  196. void poker_foldplayer(XINT fpnode, XINT fpnum, poker_game_typ *fpgame)
  197.     {
  198.     XINT foldd, fppl = -1;
  199.  
  200.     fppl = poker_getplayernum(POKPL_PLAYING, fpnode, fpgame);
  201.     if (fppl == -1)
  202.         {
  203.         return;
  204.         }
  205.  
  206.     for (foldd = 0; foldd < fpgame->numcards; foldd++)
  207.         {
  208.         if (fpgame->player[fppl].cards[foldd] > -1)
  209.             {
  210.             fpgame->deck[fpgame->player[fppl].cards[foldd]] = 2;
  211.             fpgame->player[fppl].cards[foldd] = -1;
  212.             }
  213.         }
  214.     fpgame->player[fppl].node = -1;
  215.  
  216.     (fpgame->plcount)--;
  217.  
  218.     if (fpgame->turn == fppl)
  219.         {
  220.         poker_advanceturn(fpnum, fpgame);
  221.         }
  222.  
  223.     }
  224.  
  225.