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

  1. #include "top.h"
  2.  
  3. char poker_checkturn(char ctstage, XINT ctnode, poker_game_typ *ctgame)
  4.     {
  5.     XINT ctpl = -1;
  6.  
  7.     ctpl = poker_getplayernum(POKPL_PLAYING, ctnode, ctgame);
  8.     if (ctpl == -1)
  9.         {
  10.         return 0;
  11.         }
  12.  
  13.     if (ctgame->cycle >= 0 && ctgame->turn == ctpl)
  14.         {
  15.         if (ctstage == POKSTG_ANYTURN)
  16.             {
  17.             return 1;
  18.             }
  19.         if (ctstage == POKSTG_ANYBET)
  20.             {
  21.             if (ctgame->stage == POKSTG_BET ||
  22.                 ctgame->stage == POKSTG_FINALBET)
  23.                 {
  24.                 return 1;
  25.                 }
  26.             }
  27.         else
  28.             {
  29.             if (ctgame->stage == ctstage)
  30.                 {
  31.                 return 1;
  32.                 }
  33.             }
  34.         }
  35.  
  36.     return 0;
  37.     }
  38.  
  39. void poker_advanceturn(XINT atnum, poker_game_typ *atgame)
  40.     {
  41.     XINT atpl;
  42.     unsigned long dchk;
  43.  
  44.     atpl = poker_gethighplayer(POKPL_PLAYING, atgame);
  45.  
  46.     if (atgame->cycle == -1)
  47.         {
  48.         atgame->numcalls = 0;
  49.         atgame->cycle = 0;
  50.         atgame->stage = 0;
  51.         atgame->round = 0;
  52.         atgame->turn = -1;
  53.         }
  54.  
  55.     dchk = 0;
  56.  
  57.     TurnAdvance:
  58.  
  59.     dchk++;
  60.     while(atgame->player[++atgame->turn].node == -1 && atgame->turn <= atpl)
  61.         {
  62.         atgame->turn++;
  63.         dchk++;
  64.         }
  65.  
  66.     if (dchk > cfg.maxnodes)
  67.         {
  68.         /* While this should never happen, it's here for safety. */
  69.         // Bail out some how.  Easiest way is probably to totally deinitialize
  70.         // the game (inuse=0) and get this player out of it (globals=0).
  71.         return;
  72.         }
  73.  
  74.     if (atgame->turn > atpl)
  75.         {
  76.         atgame->turn = -1;
  77.         atgame->round++;
  78.         goto TurnAdvance;
  79.         }
  80.     if (atgame->numcalls >= atgame->plcount ||
  81.         atgame->cycle >= atgame->maxcycles ||
  82.         atgame->plcount < atgame->minpl)
  83.         {
  84.         if (++atgame->stage == POKSTG_ENDCYCLE)
  85.             {
  86.             atgame->cycle++;
  87.             atgame->stage = 0;
  88.             }
  89.         atgame->round = 0;
  90.         atgame->turn = 0;
  91.         atgame->numcalls = 0;
  92.         if (atgame->cycle >= atgame->maxcycles ||
  93.             atgame->plcount < atgame->minpl)
  94.             {
  95.             poker_sendmessage(MSG_POKER, 1, atnum, 0, "GameOver", atgame);
  96.             return;
  97.             }
  98.         }
  99.     itoa(atnum, outnum[0], 10);
  100.     dispatch_message(MSG_GENERIC,
  101.                      top_output(OUT_STRINGNF,
  102.                                 getlang("PokerMsgYourTurn"),
  103.                                 getlang(atgame->stage == 1 ?
  104.                                         "Discard" : "Bet"),
  105.                                 outnum[0], atgame),
  106.                      atgame->player[atgame->turn].node, 1, 0);
  107.  
  108.     }
  109.