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

  1. #include "top.h"
  2.  
  3. XINT poker_lownode(XINT startnode, char *intable)
  4. {
  5. XINT pld, ret = -1;
  6.  
  7. for (pld = startnode + 1; pld < MAXNODES; pld++)
  8.     {
  9.     if (intable[pld])
  10.         {
  11.         ret = pld;
  12.         break;
  13.         }
  14.     }
  15.  
  16. return ret;
  17. }
  18.  
  19. XINT poker_count(char *intable)
  20. {
  21. XINT pcd, ret = 0;
  22.  
  23. for (pcd = 0; pcd < MAXNODES; pcd++)
  24.     {
  25.     if (intable[pcd])
  26.         {
  27.         ret++;
  28.         }
  29.     }
  30.  
  31. return ret;
  32. }
  33.  
  34. void poker_shuffle(char *cardz)
  35. {
  36. XINT psd, psc;
  37.  
  38. for (psd = 0, psc = 0; psd < 52; psd++)  // 52 = gamecardsused
  39.     {
  40.     if (cardz[psd])
  41.         {
  42.         psc++;
  43.         }
  44.     }
  45. if (psc > 47)
  46.     {
  47.     for (psd = 0; psd < 52; psd++) // 52 = gamecardsused
  48.         {
  49.         if (cardz[psd] == 2)
  50.             {
  51.             cardz[psd] = 0;
  52.             }
  53.         }
  54.     }
  55.  
  56. return;
  57. }
  58.  
  59. void poker_advanceturn(XINT mini, char *whobuf, poker_game_typ *gamebuf)
  60. {
  61. char *whowant;
  62.  
  63. whowant = farmalloc(MAXNODES);
  64. if (!whowant)
  65.     {
  66.     dispatch_message(MSG_GENERIC, "^I^mNot enough memory to play Poker!^A^p",
  67.                      od_control.od_node, 0, 0);
  68.     return;
  69.     }
  70.  
  71. if (poker_count(whobuf) == 1)
  72.     {
  73.     gamebuf->gameprogress = -1;
  74.     }
  75.  
  76. if (mini == -1)
  77.     {
  78.     mini = poker_lownode(0, whobuf);
  79.     }
  80.  
  81. if (gamebuf->roundprogress >= poker_count(whobuf))
  82.     {
  83.     if (gamebuf->gameprogress == 100)
  84.         {
  85.         gamebuf->gameprogress = -1;
  86.         }
  87.     if (gamebuf->gameprogress == 50)
  88.         {
  89.         gamebuf->gameprogress = 100;
  90.         }
  91.     if (gamebuf->gameprogress == 0)
  92.         {
  93.         gamebuf->gameprogress = 50;
  94.         }
  95.     mini = poker_lownode(0, whobuf);
  96.     gamebuf->roundprogress = 0;
  97.     }
  98.  
  99. if (gamebuf->gameprogress == 0 || gamebuf->gameprogress == 100)
  100.     {
  101.     dispatch_message(MSG_POKER, "YourBet", mini, 1, 0);
  102.     }
  103. if (gamebuf->gameprogress == 50)
  104.     {
  105.     dispatch_message(MSG_POKER, "YourDiscard", mini, 1, 0);
  106.     }
  107. if (gamebuf->gameprogress == -1)
  108.     {
  109.     XINT god;
  110.     char *whowas;
  111.  
  112.     whowas = farmalloc(MAXNODES);
  113.     if (!whowas)
  114.         {
  115.         dispatch_message(MSG_GENERIC, "^I^mNot enough memory to play Poker!^A^p",
  116.                          od_control.od_node, 0, 0);
  117.         dofree(whowant);
  118.         return;
  119.         }
  120.  
  121.     poker_findwinners(whobuf, gamebuf);
  122.     poker_loadintable(0, 0, whowant);
  123.     poker_loadintable(0, 2, whowas);
  124.     for (god = 0; god < MAXNODES; god++)
  125.         {
  126.         XINT gdw;
  127.  
  128.         if (whowant[god])
  129.             {
  130.             whowant[god] = 1;
  131.             if (whowas[god])
  132.                 {
  133.                 whowant[god] = 2;
  134.                 }
  135.             for (gdw = 0; gdw < 10; gdw++)
  136.                 {
  137.                 if (gamebuf->winners[gdw] == god)
  138.                     {
  139.                     whowant[god] = 3;
  140.                     }
  141.                 }
  142.             }
  143.         }
  144.     poker_saveintable(0, 0, whowant);
  145.     memset(whowas, 0, MAXNODES);
  146.     poker_saveintable(0, 2, whowas);
  147.     gamebuf->gameprogress = -1;
  148.     gamebuf->gameon = 0;
  149.     mini = -1;
  150.     poker_savegamedata(gamebuf);
  151.  
  152.     for (god = 0; god < MAXNODES; god++)
  153.         {
  154.         if (whowant[god])
  155.             {
  156.             dispatch_message(MSG_POKER, "GameOver", god, 1, 0);
  157.             }
  158.         }
  159.  
  160.     dofree(whowant);
  161.     }
  162.  
  163. gamebuf->currentturn = mini;
  164. time(&gamebuf->eventstarttime);
  165.  
  166. dofree(whowant);
  167.  
  168. return;
  169. }
  170.  
  171.